summaryrefslogtreecommitdiff
authorzecke <zecke>2004-02-08 14:24:56 (UTC)
committer zecke <zecke>2004-02-08 14:24:56 (UTC)
commita763515241faab10c9d86c5cb785c714578e9bb0 (patch) (unidiff)
tree35ecc8bd63fdc7a40e26d8fe369b389f21901d5c
parent258a55008dc84c8860f0c851b1da1e6cc921a1cb (diff)
downloadopie-a763515241faab10c9d86c5cb785c714578e9bb0.zip
opie-a763515241faab10c9d86c5cb785c714578e9bb0.tar.gz
opie-a763515241faab10c9d86c5cb785c714578e9bb0.tar.bz2
ReMerge QPEDeco
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpedecoration_qws.cpp147
-rw-r--r--library/qpedecoration_qws.h9
2 files changed, 100 insertions, 56 deletions
diff --git a/library/qpedecoration_qws.cpp b/library/qpedecoration_qws.cpp
index bac1a75..7842ebd 100644
--- a/library/qpedecoration_qws.cpp
+++ b/library/qpedecoration_qws.cpp
@@ -1,926 +1,967 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifdef QWS
20#define QTOPIA_INTERNAL_LANGLIST 21#define QTOPIA_INTERNAL_LANGLIST
21#include <qapplication.h> 22#include <qapplication.h>
22#include <qstyle.h> 23#include <qstyle.h>
23#include <qwidget.h> 24#include <qwidget.h>
24#include <qpainter.h> 25#include <qpainter.h>
25#include <qtimer.h> 26#include <qtimer.h>
26#include <qwhatsthis.h> 27#include <qwhatsthis.h>
28#include <qpopupmenu.h>
27#include "qcopenvelope_qws.h" 29#include "qcopenvelope_qws.h"
28#include "qpedecoration_qws.h" 30#include "qpedecoration_qws.h"
29#include <qdialog.h> 31#include <qdialog.h>
30#include <qdrawutil.h> 32#include <qdrawutil.h>
31#include <qgfx_qws.h> 33#include <qgfx_qws.h>
32#include "qpeapplication.h" 34#include "qpeapplication.h"
33#include "resource.h" 35#include "resource.h"
34#include "global.h" 36#include "global.h"
35#include "qlibrary.h" 37#include "qlibrary.h"
36#include "windowdecorationinterface.h" 38#include "windowdecorationinterface.h"
39#include <qpe/qlibrary.h>
37#include <qfile.h> 40#include <qfile.h>
38#include <qsignal.h> 41#include <qsignal.h>
39 42
40#include <stdlib.h> 43#include <stdlib.h>
41 44
42extern QRect qt_maxWindowRect; 45extern Q_EXPORT QRect qt_maxWindowRect;
43 46
44#define WHATSTHIS_MODE 47#define WHATSTHIS_MODE
45 48
46#ifndef QT_NO_QWS_QPE_WM_STYLE 49#ifndef QT_NO_QWS_QPE_WM_STYLE
47 50
48#ifndef QT_NO_IMAGEIO_XPM 51#ifndef QT_NO_IMAGEIO_XPM
49 52
50/* XPM */ 53/* XPM */
51static const char * const qpe_close_xpm[] = { 54static const char * const qpe_close_xpm[] = {
52"16 16 3 1", 55"16 16 3 1",
53" c None", 56" c None",
54". c #FFFFFF", 57". c #FFFFFF",
55"+ c #000000", 58"+ c #000000",
56" ", 59" ",
57" ", 60" ",
58" ..... ", 61" ..... ",
59" ..+++++.. ", 62" ..+++++.. ",
60" .+++++++++. ", 63" .+++++++++. ",
61" .+..+++..+. ", 64" .+..+++..+. ",
62" .++...+...++. ", 65" .++...+...++. ",
63" .+++.....+++. ", 66" .+++.....+++. ",
64" .++++...++++. ", 67" .++++...++++. ",
65" .+++.....+++. ", 68" .+++.....+++. ",
66" .++...+...++. ", 69" .++...+...++. ",
67" .+..+++..+. ", 70" .+..+++..+. ",
68" .+++++++++. ", 71" .+++++++++. ",
69" ..+++++.. ", 72" ..+++++.. ",
70" ..... ", 73" ..... ",
71" "}; 74" "};
72 75
73/* XPM */ 76/* XPM */
74static const char * const qpe_accept_xpm[] = { 77static const char * const qpe_accept_xpm[] = {
75"16 16 3 1", 78"16 16 3 1",
76" c None", 79" c None",
77". c #FFFFFF", 80". c #FFFFFF",
78"+ c #000000", 81"+ c #000000",
79" ", 82" ",
80" ", 83" ",
81" ..... ", 84" ..... ",
82" ..+++++.. ", 85" ..+++++.. ",
83" .+++++++++. ", 86" .+++++++++. ",
84" .+++++++++. ", 87" .+++++++++. ",
85" .+++++++..++. ", 88" .+++++++..++. ",
86" .++.+++...++. ", 89" .++.+++...++. ",
87" .+...+...+++. ", 90" .+...+...+++. ",
88" .+......++++. ", 91" .+......++++. ",
89" .++....+++++. ", 92" .++....+++++. ",
90" .++..+++++. ", 93" .++..+++++. ",
91" .+++++++++. ", 94" .+++++++++. ",
92" ..+++++.. ", 95" ..+++++.. ",
93" ..... ", 96" ..... ",
94" "}; 97" "};
95 98
96#endif // QT_NO_IMAGEIO_XPM 99#endif // QT_NO_IMAGEIO_XPM
97 100
98class HackWidget : public QWidget 101class DecorHackWidget : public QWidget
99{ 102{
100public: 103public:
101 bool needsOk() { 104 bool needsOk() {
102 return (getWState() & WState_Reserved1 ) || 105 return (getWState() & WState_Reserved1 ) ||
103 (inherits( "QDialog" ) && !inherits( "QMessageBox" ) ); 106 (inherits("QDialog") && !inherits("QMessageBox")
107 && !inherits("QWizard") );
104 } 108 }
105}; 109};
106 110
107static QImage scaleButton( const QImage &img, int height ) 111static QImage scaleButton( const QImage &img, int height )
108{ 112{
109 if ( img.height() != 0 && img.height() != height ) { 113 if ( img.height() != 0 && img.height() != height ) {
110 return img.smoothScale( img.width()*height/img.height(), height ); 114 return img.smoothScale( img.width()*height/img.height(), height );
111 } else { 115 } else {
112 return img; 116 return img;
113 } 117 }
114} 118}
115 119
116class TLWidget : public QWidget 120class TLWidget : public QWidget
117{ 121{
118public: 122public:
119 QWSManager *manager() 123 QWSManager *manager()
120 { 124 {
121 return topData()->qwsManager; 125 return topData()->qwsManager;
122 } 126 }
123 127
124 QTLWExtra *topExtra() 128 QTLWExtra *topExtra()
125 { 129 {
126 return topData(); 130 return topData();
127 } 131 }
128 132
129 void setWState( uint s ) { QWidget::setWState( s ); } 133 void setWState( uint s ) { QWidget::setWState( s ); }
130 void clearWState( uint s ) { QWidget::clearWState( s ); } 134 void clearWState( uint s ) { QWidget::clearWState( s ); }
131}; 135};
132 136
133 137
134QPEManager::QPEManager( QPEDecoration *d, QObject *parent ) 138QPEManager::QPEManager( QPEDecoration *d, QObject *parent )
135 : QObject( parent ), decoration( d ), helpState(0), inWhatsThis(FALSE) 139 : QObject( parent ), decoration( d ), helpState(0), inWhatsThis(FALSE)
136{ 140{
137 wtTimer = new QTimer( this ); 141 wtTimer = new QTimer( this );
138 connect( wtTimer, SIGNAL(timeout()), this, SLOT(whatsThisTimeout()) ); 142 connect( wtTimer, SIGNAL(timeout()), this, SLOT(whatsThisTimeout()) );
139} 143}
140 144
141 145
142void QPEManager::updateActive() 146void QPEManager::updateActive()
143{ 147{
144 QWidget *newActive = qApp->activeWindow(); 148 QWidget *newActive = qApp->activeWindow();
145 if ( newActive && (QWidget*)active == newActive ) 149 if ( newActive && (QWidget*)active == newActive )
146 return; 150 return;
147 151
148 if ( active && (!newActive || ((TLWidget *)newActive)->manager()) ) { 152 if ( active && (!newActive || ((TLWidget *)newActive)->manager()) ) {
149 ((TLWidget *)(QWidget*)active)->manager()->removeEventFilter( this ); 153 ((TLWidget *)(QWidget*)active)->manager()->removeEventFilter( this );
150 } 154 }
151 155
152 if ( newActive && ((TLWidget *)newActive)->manager() ) { 156 if ( newActive && ((TLWidget *)newActive)->manager() ) {
153 active = newActive; 157 active = newActive;
154 ((TLWidget *)(QWidget*)active)->manager()->installEventFilter( this ); 158 ((TLWidget *)(QWidget*)active)->manager()->installEventFilter( this );
155 } else if ( !newActive ) { 159 } else if ( !newActive ) {
156 active = 0; 160 active = 0;
157 } 161 }
158} 162}
159 163
160int QPEManager::pointInQpeRegion( QWidget *w, const QPoint &p ) 164int QPEManager::pointInQpeRegion( QWidget *w, const QPoint &p )
161{ 165{
162 QRect rect(w->geometry()); 166 QRect rect(w->geometry());
163 167
164 if ( decoration->region( w, rect, 168 if ( decoration->region( w, rect,
165 (QWSDecoration::Region)QPEDecoration::Help ).contains(p) ) 169 (QWSDecoration::Region)QPEDecoration::Help ).contains(p) )
166 return QPEDecoration::Help; 170 return QPEDecoration::Help;
167 171
168 for (int i = QWSDecoration::LastRegion; i >= QWSDecoration::Title; i--) { 172 for (int i = QWSDecoration::LastRegion; i >= QWSDecoration::Title; i--) {
169 if (decoration->region(w, rect, (QWSDecoration::Region)i).contains(p)) 173 if (decoration->region(w, rect, (QWSDecoration::Region)i).contains(p))
170 return (QWSDecoration::Region)i; 174 return (QWSDecoration::Region)i;
171 } 175 }
172 176
173 return QWSDecoration::None; 177 return QWSDecoration::None;
174} 178}
175 179
176bool QPEManager::eventFilter( QObject *o, QEvent *e ) 180bool QPEManager::eventFilter( QObject *o, QEvent *e )
177{ 181{
178 QWSManager *mgr = (QWSManager *)o; 182 QWSManager *mgr = (QWSManager *)o;
179 QWidget *w = mgr->widget(); 183 QWidget *w = mgr->widget();
180 switch ( e->type() ) { 184 switch ( e->type() ) {
181 case QEvent::MouseButtonPress: 185 case QEvent::MouseButtonPress:
182 { 186 {
183 pressTime = QTime::currentTime(); 187 pressTime = QTime::currentTime();
184 QPoint p = ((QMouseEvent*)e)->globalPos(); 188 QPoint p = ((QMouseEvent*)e)->globalPos();
185 int inRegion = pointInQpeRegion( w, p ); 189 int inRegion = pointInQpeRegion( w, p );
186#ifdef WHATSTHIS_MODE 190#ifdef WHATSTHIS_MODE
187 if ( !w->geometry().contains(p) && QWhatsThis::inWhatsThisMode() ) { 191 if ( !w->geometry().contains(p) && QWhatsThis::inWhatsThisMode() ) {
188 QString text; 192 QString text;
189 switch ( inRegion ) { 193 switch ( inRegion ) {
190 case QWSDecoration::Close: 194 case QWSDecoration::Close:
191 if ( ((HackWidget*)w)->needsOk() ) 195 if ( ((DecorHackWidget*)w)->needsOk() )
192 text = QObject::tr("Click to close this window, discarding changes."); 196 text = tr("Click to close this window, discarding changes.");
193 else 197 else
194 text = QObject::tr("Click to close this window."); 198 text = tr("Click to close this window.");
195 break; 199 break;
196 case QWSDecoration::Minimize: 200 case QWSDecoration::Minimize:
197 text = QObject::tr("Click to close this window and apply changes."); 201 text = tr("Click to close this window and apply changes.");
198 break; 202 break;
199 case QWSDecoration::Maximize: 203 case QWSDecoration::Maximize:
200 if ( w->isMaximized() ) 204 if ( w->isMaximized() )
201 text = QObject::tr("Click to make this window moveable."); 205 text = tr("Click to make this window movable.");
202 else 206 else
203 text = QObject::tr("Click to make this window use all available screen area."); 207 text = tr("Click to make this window use all available screen area.");
204 break; 208 break;
205 default: 209 default:
206 break; 210 break;
207 } 211 }
208 QWhatsThis::leaveWhatsThisMode( text ); 212 QWhatsThis::leaveWhatsThisMode( text );
209 whatsThisTimeout(); 213 whatsThisTimeout();
210 helpState = 0; 214 helpState = 0;
211 return true; 215 return true;
212 } 216 }
213#endif 217#endif
214 if ( inRegion == QPEDecoration::Help ) { 218 if ( inRegion == QPEDecoration::Help ) {
215#ifdef WHATSTHIS_MODE 219#ifdef WHATSTHIS_MODE
216 wtTimer->start( 400, TRUE ); 220 wtTimer->start( 400, TRUE );
217#endif 221#endif
218 helpState = QWSButton::Clicked|QWSButton::MouseOver; 222 helpState = QWSButton::Clicked|QWSButton::MouseOver;
219 drawButton( w, QPEDecoration::Help, helpState ); 223 drawButton( w, QPEDecoration::Help, helpState );
220 return true; 224 return true;
221 } 225 }
222 } 226 }
223 break; 227 break;
224 case QEvent::MouseButtonRelease: 228 case QEvent::MouseButtonRelease:
225 if ( helpState & QWSButton::Clicked ) { 229 if ( helpState & QWSButton::Clicked ) {
226 wtTimer->stop(); 230 wtTimer->stop();
227 helpState = 0; 231 helpState = 0;
228 drawButton( w, QPEDecoration::Help, helpState ); 232 drawButton( w, QPEDecoration::Help, helpState );
229 QPoint p = ((QMouseEvent*)e)->globalPos(); 233 QPoint p = ((QMouseEvent*)e)->globalPos();
230 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) { 234 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) {
231 decoration->help( w ); 235 decoration->help( w );
232 } 236 }
233 return true; 237 return true;
234 } 238 }
235 break; 239 break;
236 case QEvent::MouseMove: 240 case QEvent::MouseMove:
237 if ( helpState & QWSButton::Clicked ) { 241 if ( helpState & QWSButton::Clicked ) {
238 int oldState = helpState; 242 int oldState = helpState;
239 QPoint p = ((QMouseEvent*)e)->globalPos(); 243 QPoint p = ((QMouseEvent*)e)->globalPos();
240 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) { 244 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) {
241 helpState = QWSButton::Clicked|QWSButton::MouseOver; 245 helpState = QWSButton::Clicked|QWSButton::MouseOver;
242 } else { 246 } else {
243 helpState = 0; 247 helpState = 0;
244 } 248 }
245 if ( helpState != oldState ) 249 if ( helpState != oldState )
246 drawButton( w, QPEDecoration::Help, helpState ); 250 drawButton( w, QPEDecoration::Help, helpState );
247 } 251 }
248 break; 252 break;
249 default: 253 default:
250 break; 254 break;
251 } 255 }
252 return QObject::eventFilter( o, e ); 256 return QObject::eventFilter( o, e );
253} 257}
254 258
255void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state ) 259void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state )
256{ 260{
257 QPainter painter(w); 261 QPainter painter(w);
258 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region; 262 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region;
259 painter.internalGfx()->setWidgetDeviceRegion( rgn ); 263 painter.internalGfx()->setWidgetDeviceRegion( rgn );
260 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All)); 264 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All));
261 decoration->paintButton( &painter, w, (QWSDecoration::Region)r, state ); 265 decoration->paintButton( &painter, w, (QWSDecoration::Region)r, state );
262} 266}
263 267
264void QPEManager::drawTitle( QWidget *w ) 268void QPEManager::drawTitle( QWidget *w )
265{ 269{
266 QPainter painter(w); 270 QPainter painter(w);
267 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region; 271 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region;
268 painter.internalGfx()->setWidgetDeviceRegion( rgn ); 272 painter.internalGfx()->setWidgetDeviceRegion( rgn );
269 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All)); 273 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All));
270 decoration->paint( &painter, w ); 274 decoration->paint( &painter, w );
271 decoration->paintButton(&painter, w, QWSDecoration::Menu, 0); 275 decoration->paintButton(&painter, w, QWSDecoration::Menu, 0);
272 decoration->paintButton(&painter, w, QWSDecoration::Close, 0); 276 decoration->paintButton(&painter, w, QWSDecoration::Close, 0);
273 decoration->paintButton(&painter, w, QWSDecoration::Minimize, 0); 277 decoration->paintButton(&painter, w, QWSDecoration::Minimize, 0);
274 decoration->paintButton(&painter, w, QWSDecoration::Maximize, 0); 278 decoration->paintButton(&painter, w, QWSDecoration::Maximize, 0);
275} 279}
276 280
277void QPEManager::whatsThisTimeout() 281void QPEManager::whatsThisTimeout()
278{ 282{
279 if ( !QWhatsThis::inWhatsThisMode() ) { 283 if ( !QWhatsThis::inWhatsThisMode() ) {
280 if ( inWhatsThis ) { 284 if ( inWhatsThis ) {
281 if ( whatsThis ) { 285 if ( whatsThis ) {
282 QWidget *w = whatsThis; 286 QWidget *w = whatsThis;
283 whatsThis = 0; 287 whatsThis = 0;
284 drawTitle( w ); 288 drawTitle( w );
285 } 289 }
286 wtTimer->stop(); 290 wtTimer->stop();
287 } else { 291 } else {
288 QWhatsThis::enterWhatsThisMode(); 292 QWhatsThis::enterWhatsThisMode();
289 helpState = 0; 293 helpState = 0;
290 updateActive(); 294 updateActive();
291 if ( active ) { 295 if ( active ) {
292 whatsThis = active; 296 whatsThis = active;
293 drawTitle( active ); 297 drawTitle( active );
294 // check periodically to see if we've left whats this mode 298 // check periodically to see if we've left whats this mode
295 wtTimer->start( 250 ); 299 wtTimer->start( 250 );
296 } 300 }
297 } 301 }
298 inWhatsThis = !inWhatsThis; 302 inWhatsThis = !inWhatsThis;
299 } 303 }
300} 304}
301 305
302//=========================================================================== 306//===========================================================================
303 307
304static QImage *okImage( int th ) 308static QImage *okImage( int th )
305{ 309{
306 static QImage *i = 0; 310 static QImage *i = 0;
307 if ( !i || i->height() != th ) { 311 if ( !i || i->height() != th ) {
308 delete i; 312 delete i;
309 i = new QImage(scaleButton(Resource::loadImage("OKButton"),th)); 313 i = new QImage(scaleButton(Resource::loadImage("OKButton"),th));
310 } 314 }
311 return i; 315 return i;
312} 316}
313 317
314static QImage *closeImage( int th ) 318static QImage *closeImage( int th )
315{ 319{
316 static QImage *i = 0; 320 static QImage *i = 0;
317 if ( !i || i->height() != th ) { 321 if ( !i || i->height() != th ) {
318 delete i; 322 delete i;
319 i = new QImage(scaleButton(Resource::loadImage("CloseButton"),th)); 323 i = new QImage(scaleButton(Resource::loadImage("CloseButton"),th));
320 } 324 }
321 return i; 325 return i;
322} 326}
323 327
324static QImage *helpImage( int th ) 328static QImage *helpImage( int th )
325{ 329{
326 static QImage *i = 0; 330 static QImage *i = 0;
327 if ( !i || i->height() != th ) { 331 if ( !i || i->height() != th ) {
328 delete i; 332 delete i;
329 i = new QImage(scaleButton(Resource::loadImage("HelpButton"),th)); 333 i = new QImage(scaleButton(Resource::loadImage("HelpButton"),th));
330 } 334 }
331 return i; 335 return i;
332} 336}
333 337
334static QImage *maximizeImage( int th ) 338static QImage *maximizeImage( int th )
335{ 339{
336 static QImage *i = 0; 340 static QImage *i = 0;
337 if ( !i || i->height() != th ) { 341 if ( !i || i->height() != th ) {
338 delete i; 342 delete i;
339 i = new QImage(scaleButton(Resource::loadImage("MaximizeButton"),th)); 343 i = new QImage(scaleButton(Resource::loadImage("MaximizeButton"),th));
340 } 344 }
341 return i; 345 return i;
342} 346}
343 347
344int WindowDecorationInterface::metric( Metric m, const WindowData *wd ) const 348int WindowDecorationInterface::metric( Metric m, const WindowData *wd ) const
345{ 349{
346 switch ( m ) { 350 switch ( m ) {
347 case TitleHeight: 351 case TitleHeight:
348 if ( QApplication::desktop()->height() > 320 ) 352 if ( QApplication::desktop()->height() > 320 )
349 return 19; 353 return 19;
350 else 354 else
351 return 15; 355 return 15;
352 case LeftBorder: 356 case LeftBorder:
353 case RightBorder: 357 case RightBorder:
354 case TopBorder: 358 case TopBorder:
355 case BottomBorder: 359 case BottomBorder:
356 return 4; 360 return 4;
357 case OKWidth: 361 case OKWidth:
358 return okImage(metric(TitleHeight,wd))->width(); 362 return okImage(metric(TitleHeight,wd))->width();
359 case CloseWidth: 363 case CloseWidth:
360 return closeImage(metric(TitleHeight,wd))->width(); 364 return closeImage(metric(TitleHeight,wd))->width();
361 case HelpWidth: 365 case HelpWidth:
362 return helpImage(metric(TitleHeight,wd))->width(); 366 return helpImage(metric(TitleHeight,wd))->width();
363 case MaximizeWidth: 367 case MaximizeWidth:
364 return maximizeImage(metric(TitleHeight,wd))->width(); 368 return maximizeImage(metric(TitleHeight,wd))->width();
365 case CornerGrabSize: 369 case CornerGrabSize:
366 return 16; 370 return 16;
367 } 371 }
368 372
369 return 0; 373 return 0;
370} 374}
371 375
372void WindowDecorationInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const 376void WindowDecorationInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const
373{ 377{
374 int th = metric( TitleHeight, wd ); 378 int th = metric( TitleHeight, wd );
375 QRect r = wd->rect; 379 QRect r = wd->rect;
376 380
377 switch ( a ) { 381 switch ( a ) {
378 case Border: 382 case Border:
379 { 383 {
380 const QColorGroup &cg = wd->palette.active(); 384 const QColorGroup &cg = wd->palette.active();
381 qDrawWinPanel(p, r.x()-metric(LeftBorder,wd), 385 qDrawWinPanel(p, r.x()-metric(LeftBorder,wd),
382 r.y()-th-metric(TopBorder,wd), 386 r.y()-th-metric(TopBorder,wd),
383 r.width()+metric(LeftBorder,wd)+metric(RightBorder,wd), 387 r.width()+metric(LeftBorder,wd)+metric(RightBorder,wd),
384 r.height()+th+metric(TopBorder,wd)+metric(BottomBorder,wd), 388 r.height()+th+metric(TopBorder,wd)+metric(BottomBorder,wd),
385 cg, FALSE, &cg.brush(QColorGroup::Background)); 389 cg, FALSE, &cg.brush(QColorGroup::Background));
386 } 390 }
387 break; 391 break;
388 case Title: 392 case Title:
389 { 393 {
390 const QColorGroup &cg = wd->palette.active(); 394 const QColorGroup &cg = wd->palette.active();
391 QBrush titleBrush; 395 QBrush titleBrush;
392 QPen titleLines; 396 QPen titleLines;
393 397
394 if ( wd->flags & WindowData::Active ) { 398 if ( wd->flags & WindowData::Active ) {
395 titleBrush = cg.brush(QColorGroup::Highlight); 399 titleBrush = cg.brush(QColorGroup::Highlight);
396 titleLines = titleBrush.color().dark(); 400 titleLines = titleBrush.color().dark();
397 } else { 401 } else {
398 titleBrush = cg.brush(QColorGroup::Background); 402 titleBrush = cg.brush(QColorGroup::Background);
399 titleLines = titleBrush.color(); 403 titleLines = titleBrush.color();
400 } 404 }
401 405
402 p->fillRect( r.x(), r.y()-th, r.width(), th, titleBrush); 406 p->fillRect( r.x(), r.y()-th, r.width(), th, titleBrush);
403 407
404 p->setPen( titleLines ); 408 p->setPen( titleLines );
405 for ( int i = r.y()-th; i < r.y(); i += 2 ) 409 for ( int i = r.y()-th; i < r.y(); i += 2 )
406 p->drawLine( r.left(), i, r.right(), i ); 410 p->drawLine( r.left(), i, r.right(), i );
407 } 411 }
408 break; 412 break;
409 case TitleText: 413 case TitleText:
410 p->drawText( r.x()+3+metric(HelpWidth,wd), r.top()-th, 414 p->drawText( r.x()+3+metric(HelpWidth,wd), r.top()-th,
411 r.width()-metric(OKWidth,wd)-metric(CloseWidth,wd), 415 r.width()-metric(OKWidth,wd)-metric(CloseWidth,wd),
412 th, QPainter::AlignVCenter, wd->caption); 416 th, QPainter::AlignVCenter, wd->caption);
413 break; 417 break;
414 } 418 }
415} 419}
416 420
417void WindowDecorationInterface::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int, int, QWSButton::State state ) const 421void WindowDecorationInterface::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int, int, QWSButton::State state ) const
418{ 422{
419 QImage *img = 0; 423 QImage *img = 0;
420 switch ( b ) { 424 switch ( b ) {
421 case OK: 425 case OK:
422 img = okImage(metric(TitleHeight,wd)); 426 img = okImage(metric(TitleHeight,wd));
423 break; 427 break;
424 case Close: 428 case Close:
425 img = closeImage(metric(TitleHeight,wd)); 429 img = closeImage(metric(TitleHeight,wd));
426 break; 430 break;
427 case Help: 431 case Help:
428 img = helpImage(metric(TitleHeight,wd)); 432 img = helpImage(metric(TitleHeight,wd));
429 break; 433 break;
430 case Maximize: 434 case Maximize:
431 img = maximizeImage(metric(TitleHeight,wd)); 435 img = maximizeImage(metric(TitleHeight,wd));
432 break; 436 break;
433 } 437 }
434 438
435 if ( img ) { 439 if ( img ) {
436 if ((state & QWSButton::MouseOver) && (state & QWSButton::Clicked)) 440 if ((state & QWSButton::MouseOver) && (state & QWSButton::Clicked))
437 p->drawImage(x+2, y+2, *img); 441 p->drawImage(x+2, y+2, *img);
438 else 442 else
439 p->drawImage(x+1, y+1, *img); 443 p->drawImage(x+1, y+1, *img);
440 } 444 }
441} 445}
442 446
443QRegion WindowDecorationInterface::mask( const WindowData *wd ) const 447QRegion WindowDecorationInterface::mask( const WindowData *wd ) const
444{ 448{
445 int th = metric(TitleHeight,wd); 449 int th = metric(TitleHeight,wd);
446 QRect rect( wd->rect ); 450 QRect rect( wd->rect );
447 QRect r(rect.left() - metric(LeftBorder,wd), 451 QRect r(rect.left() - metric(LeftBorder,wd),
448 rect.top() - th - metric(TopBorder,wd), 452 rect.top() - th - metric(TopBorder,wd),
449 rect.width() + metric(LeftBorder,wd) + metric(RightBorder,wd), 453 rect.width() + metric(LeftBorder,wd) + metric(RightBorder,wd),
450 rect.height() + th + metric(TopBorder,wd) + metric(BottomBorder,wd)); 454 rect.height() + th + metric(TopBorder,wd) + metric(BottomBorder,wd));
451 return QRegion(r) - rect; 455 return QRegion(r) - rect;
452} 456}
453 457
454class DefaultWindowDecoration : public WindowDecorationInterface 458class DefaultWindowDecoration : public WindowDecorationInterface
455{ 459{
456public: 460public:
457 DefaultWindowDecoration() : ref(0) {} 461 DefaultWindowDecoration(){}
458 QString name() const { 462 QString name() const {
459 return "Default"; 463 return qApp->translate("WindowDecoration", "Default",
464 "List box text for default window decoration");
460 } 465 }
461 QPixmap icon() const { 466 QPixmap icon() const {
462 return QPixmap(); 467 return QPixmap();
463 } 468 }
464 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { 469 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) {
465 *iface = 0; 470 *iface = 0;
466 if ( uuid == IID_QUnknown ) 471 if ( uuid == IID_QUnknown )
467 *iface = this; 472 *iface = this;
468 else if ( uuid == IID_WindowDecoration ) 473 else if ( uuid == IID_WindowDecoration )
469 *iface = this; 474 *iface = this;
475 else
476 return QS_FALSE;
470 477
471 if ( *iface ) 478 if ( *iface )
472 (*iface)->addRef(); 479 (*iface)->addRef();
473 return QS_OK; 480 return QS_OK;
474 } 481 }
475 Q_REFCOUNT 482 Q_REFCOUNT
476 483
477private:
478 ulong ref;
479}; 484};
480 485
481static WindowDecorationInterface *wdiface = 0; 486static WindowDecorationInterface *wdiface = 0;
482static QLibrary *wdlib = 0; 487static QLibrary* wdlib = 0;
483static QString libname; 488static QString libname;
484 489
485//=========================================================================== 490//===========================================================================
491bool QPEDecoration::helpExists() const
492{
493 if ( helpFile.isNull() ) {
494 QStringList helpPath = Global::helpPath();
495 QString hf = QString(qApp->argv()[0]) + ".html";
496 bool he = FALSE;
497 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !he; ++it)
498 he = QFile::exists( *it + "/" + hf );
499 ((QPEDecoration*)this)->helpFile = hf;
500 ((QPEDecoration*)this)->helpexists = he;
501 return he;
502 }
503 return helpexists;
504}
486 505
487QPEDecoration::QPEDecoration() 506QPEDecoration::QPEDecoration()
488 : QWSDefaultDecoration() 507 : QWSDefaultDecoration()
489{ 508{
490 init ( libname ); 509 if ( wdlib ) {
510 delete wdlib;
511 wdlib = 0;
512 } else {
513 delete wdiface;
514 }
515 wdiface = new DefaultWindowDecoration;
516
517 helpexists = FALSE; // We don't know (flagged by helpFile being null)
518 qpeManager = new QPEManager( this );
519 imageOk = Resource::loadImage( "OKButton" );
520 imageClose = Resource::loadImage( "CloseButton" );
521 imageHelp = Resource::loadImage( "HelpButton" );
491} 522}
492 523
493QPEDecoration::QPEDecoration( const QString &plugin ) 524QPEDecoration::QPEDecoration( const QString &plugin )
494 : QWSDefaultDecoration() 525 : QWSDefaultDecoration()
495{ 526{
496 init ( plugin );
497}
498
499void QPEDecoration::init ( const QString &plugin )
500{
501 libname = plugin; 527 libname = plugin;
502 528
503 if ( wdlib ) { 529 if ( wdlib ) {
504 wdiface->release(); 530 wdiface->release();
505 wdlib->unload(); 531 wdlib->unload();
506 delete wdlib; 532 delete wdlib;
507 wdlib = 0; 533 wdlib = 0;
508 } else { 534 } else {
509 delete wdiface; 535 delete wdiface;
510 } 536 }
511 537
512 WindowDecorationInterface *iface = 0; 538 WindowDecorationInterface *iface = 0;
513 QString path = QPEApplication::qpeDir() + "/plugins/decorations/"; 539 QString path = QPEApplication::qpeDir() + "/plugins/decorations/";
514 540
515#ifdef Q_OS_MACX 541#ifdef Q_OS_MACX
516 if ( plugin.find( ".dylib" ) > 0 ) { 542 if ( plugin.find( ".dylib" ) > 0 ) {
517#else 543#else
518 if ( plugin.find( ".so" ) > 0 ) { 544 if ( plugin.find( ".so" ) > 0 ) {
519#endif 545#endif
520 // full library name supplied 546 // full library name supplied
521 path += plugin; 547 path += plugin;
522 } else { 548 } else {
523#ifdef Q_OS_MACX 549#ifdef Q_OS_MACX
524 path += "lib" + plugin.lower() + ".dylib"; // compatibility 550 path += "lib" + plugin.lower() + ".dylib"; // compatibility
525#else 551#else
526 path += "lib" + plugin.lower() + ".so"; // compatibility 552 path += "lib" + plugin.lower() + ".so"; // compatibility
527#endif 553#endif
528 } 554 }
529 555
530 QLibrary *lib = new QLibrary( path ); 556 QLibrary *lib = new QLibrary( path );
531 if ( lib->queryInterface( IID_WindowDecoration, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 557 if ( lib->queryInterface( IID_WindowDecoration, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
532 wdiface = iface; 558 wdiface = iface;
533 wdlib = lib; 559 wdlib = lib;
534 } else { 560 } else {
535 delete lib; 561 delete lib;
536 wdiface = new DefaultWindowDecoration; 562 wdiface = new DefaultWindowDecoration;
537 } 563 }
538 564
539 helpFile = QString(qApp->argv()[0]) + ".html";
540 QStringList helpPath = Global::helpPath();
541 helpExists = FALSE;
542 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) {
543 helpExists = QFile::exists( *it + "/" + helpFile );
544 //qDebug ( "Checking %s/%s for help: %d", (*it).latin1(), helpFile.latin1(),helpExists);
545 }
546 qpeManager = new QPEManager( this );
547 565
548 // Qtopia 1.5 compatibility 566
549 imageOk = *okImage ( 15 ); 567 helpexists = FALSE; // We don't know (flagged by helpFile being null)
550 imageClose = *closeImage ( 15 ); 568 qpeManager = new QPEManager( this );
551 imageHelp = *helpImage ( 15 );
552} 569}
553 570
554QPEDecoration::~QPEDecoration() 571QPEDecoration::~QPEDecoration()
555{ 572{
556 delete qpeManager; 573 delete qpeManager;
557} 574}
558 575
559const char **QPEDecoration::menuPixmap() 576const char **QPEDecoration::menuPixmap()
560{ 577{
561 return (const char **)0; 578 return (const char **)0;
562} 579}
563 580
564const char **QPEDecoration::closePixmap() 581const char **QPEDecoration::closePixmap()
565{ 582{
566 return (const char **)qpe_close_xpm; 583 return (const char **)qpe_close_xpm;
567} 584}
568 585
569const char **QPEDecoration::minimizePixmap() 586const char **QPEDecoration::minimizePixmap()
570{ 587{
571 return (const char **)qpe_accept_xpm; 588 return (const char **)qpe_accept_xpm;
572} 589}
573 590
574const char **QPEDecoration::maximizePixmap() 591const char **QPEDecoration::maximizePixmap()
575{ 592{
576 return (const char **)0; 593 return (const char **)0;
577} 594}
578 595
579const char **QPEDecoration::normalizePixmap() 596const char **QPEDecoration::normalizePixmap()
580{ 597{
581 return (const char **)0; 598 return (const char **)0;
582} 599}
583 600
584int QPEDecoration::getTitleHeight( const QWidget *w ) 601int QPEDecoration::getTitleHeight( const QWidget *w )
585{ 602{
586 WindowDecorationInterface::WindowData wd; 603 WindowDecorationInterface::WindowData wd;
587 windowData( w, wd ); 604 windowData( w, wd );
588 return wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 605 return wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
589} 606}
590 607
591/* 608/*
592 If rect is empty, no frame is added. (a hack, really) 609 If rect is empty, no frame is added. (a hack, really)
593*/ 610*/
594QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type) 611QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type)
595{ 612{
596 qpeManager->updateActive(); 613 qpeManager->updateActive();
597 614
598 WindowDecorationInterface::WindowData wd; 615 WindowDecorationInterface::WindowData wd;
599 windowData( widget, wd ); 616 windowData( widget, wd );
600 wd.rect = rect; 617 wd.rect = rect;
601 618
602 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 619 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
603 int okWidth = wdiface->metric(WindowDecorationInterface::OKWidth,&wd); 620 int okWidth = wdiface->metric(WindowDecorationInterface::OKWidth,&wd);
604 int closeWidth = wdiface->metric(WindowDecorationInterface::CloseWidth,&wd); 621 int closeWidth = wdiface->metric(WindowDecorationInterface::CloseWidth,&wd);
605 int helpWidth = wdiface->metric(WindowDecorationInterface::HelpWidth,&wd); 622 int helpWidth = wdiface->metric(WindowDecorationInterface::HelpWidth,&wd);
606 int grab = wdiface->metric(WindowDecorationInterface::CornerGrabSize,&wd); 623 int grab = wdiface->metric(WindowDecorationInterface::CornerGrabSize,&wd);
607 624
608 QRegion region; 625 QRegion region;
609 626
610 switch ((int)type) { 627 switch ((int)type) {
611 case Menu: 628 case Menu:
612 break; 629 break;
613 case Maximize: 630 case Maximize:
614 if ( !widget->inherits( "QDialog" ) && qApp->desktop()->width() > 350 ) { 631 if ( !widget->inherits( "QDialog" ) && qApp->desktop()->width() > 350 ) {
615 int maximizeWidth = wdiface->metric(WindowDecorationInterface::MaximizeWidth,&wd); 632 int maximizeWidth = wdiface->metric(WindowDecorationInterface::MaximizeWidth,&wd);
616 int left = rect.right() - maximizeWidth - closeWidth; 633 int left = rect.right() - maximizeWidth - closeWidth;
617 if ( ((HackWidget *)widget)->needsOk() ) 634 if ( ((DecorHackWidget *)widget)->needsOk() )
618 left -= okWidth; 635 left -= okWidth;
619 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); 636 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight);
620 region = r; 637 region = r;
621 } 638 }
622 break; 639 break;
623 case Minimize: 640 case Minimize:
624 if ( ((HackWidget *)widget)->needsOk() ) { 641 if ( ((DecorHackWidget *)widget)->needsOk() ) {
625 QRect r(rect.right() - okWidth, 642 QRect r(rect.right() - okWidth,
626 rect.top() - titleHeight, okWidth, titleHeight); 643 rect.top() - titleHeight, okWidth, titleHeight);
627 if (r.left() > rect.left() + titleHeight) 644 if (r.left() > rect.left() + titleHeight)
628 region = r; 645 region = r;
629 } 646 }
630 break; 647 break;
631 case Close: 648 case Close:
632 { 649 {
633 int left = rect.right() - closeWidth; 650 int left = rect.right() - closeWidth;
634 if ( ((HackWidget *)widget)->needsOk() ) 651 if ( ((DecorHackWidget *)widget)->needsOk() )
635 left -= okWidth; 652 left -= okWidth;
636 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); 653 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight);
637 region = r; 654 region = r;
638 } 655 }
639 break; 656 break;
640 case Title: 657 case Title:
641 if ( !widget->isMaximized() ) { 658 if ( !widget->isMaximized() ) {
642 int width = rect.width() - helpWidth - closeWidth; 659 int width = rect.width() - helpWidth - closeWidth;
643 if ( ((HackWidget *)widget)->needsOk() ) 660 if ( ((DecorHackWidget *)widget)->needsOk() )
644 width -= okWidth; 661 width -= okWidth;
645 QRect r(rect.left()+helpWidth, rect.top() - titleHeight, 662 QRect r(rect.left()+helpWidth, rect.top() - titleHeight,
646 width, titleHeight); 663 width, titleHeight);
647 if (r.width() > 0) 664 if (r.width() > 0)
648 region = r; 665 region = r;
649 } 666 }
650 break; 667 break;
651 case Help: 668 case Help:
652 if ( helpExists || widget->testWFlags(Qt::WStyle_ContextHelp) ) { 669 if ( helpExists() || widget->testWFlags(Qt::WStyle_ContextHelp) ) {
653 QRect r(rect.left(), rect.top() - titleHeight, 670 QRect r(rect.left(), rect.top() - titleHeight,
654 helpWidth, titleHeight); 671 helpWidth, titleHeight);
655 region = r; 672 region = r;
656 } 673 }
657 break; 674 break;
658 case Top: 675 case Top:
659 if ( !widget->isMaximized() ) { 676 if ( !widget->isMaximized() ) {
660 QRegion m = wdiface->mask(&wd); 677 QRegion m = wdiface->mask(&wd);
661 QRect br = m.boundingRect(); 678 QRect br = m.boundingRect();
662 int b = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 679 int b = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
663 region = m & QRect( br.left()+grab, br.top(), 680 region = m & QRect( br.left()+grab, br.top(),
664 br.width()-2*grab, b ); 681 br.width()-2*grab, b );
665 } 682 }
666 break; 683 break;
667 case Left: 684 case Left:
668 if ( !widget->isMaximized() ) { 685 if ( !widget->isMaximized() ) {
669 QRegion m = wdiface->mask(&wd); 686 QRegion m = wdiface->mask(&wd);
670 QRect br = m.boundingRect(); 687 QRect br = m.boundingRect();
671 int b = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); 688 int b = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd);
672 region = m & QRect( br.left(), br.top()+grab, 689 region = m & QRect( br.left(), br.top()+grab,
673 b, br.height()-2*grab ); 690 b, br.height()-2*grab );
674 } 691 }
675 break; 692 break;
676 case Right: 693 case Right:
677 if ( !widget->isMaximized() ) { 694 if ( !widget->isMaximized() ) {
678 QRegion m = wdiface->mask(&wd); 695 QRegion m = wdiface->mask(&wd);
679 QRect br = m.boundingRect(); 696 QRect br = m.boundingRect();
680 int b = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); 697 int b = wdiface->metric(WindowDecorationInterface::RightBorder,&wd);
681 region = m & QRect( rect.right(), br.top()+grab, 698 region = m & QRect( rect.right(), br.top()+grab,
682 b, br.height()-2*grab ); 699 b, br.height()-2*grab );
683 } 700 }
684 break; 701 break;
685 case Bottom: 702 case Bottom:
686 if ( !widget->isMaximized() ) { 703 if ( !widget->isMaximized() ) {
687 QRegion m = wdiface->mask(&wd); 704 QRegion m = wdiface->mask(&wd);
688 QRect br = m.boundingRect(); 705 QRect br = m.boundingRect();
689 int b = wdiface->metric(WindowDecorationInterface::BottomBorder,&wd); 706 int b = wdiface->metric(WindowDecorationInterface::BottomBorder,&wd);
690 region = m & QRect( br.left()+grab, rect.bottom(), 707 region = m & QRect( br.left()+grab, rect.bottom(),
691 br.width()-2*grab, b ); 708 br.width()-2*grab, b );
692 } 709 }
693 break; 710 break;
694 case TopLeft: 711 case TopLeft:
695 if ( !widget->isMaximized() ) { 712 if ( !widget->isMaximized() ) {
696 QRegion m = wdiface->mask(&wd); 713 QRegion m = wdiface->mask(&wd);
697 QRect br = m.boundingRect(); 714 QRect br = m.boundingRect();
698 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 715 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
699 int lb = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); 716 int lb = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd);
700 QRegion crgn( br.left(), br.top(), grab, tb ); 717 QRegion crgn( br.left(), br.top(), grab, tb );
701 crgn |= QRect( br.left(), br.top(), lb, grab ); 718 crgn |= QRect( br.left(), br.top(), lb, grab );
702 region = m & crgn; 719 region = m & crgn;
703 } 720 }
704 break; 721 break;
705 case TopRight: 722 case TopRight:
706 if ( !widget->isMaximized() ) { 723 if ( !widget->isMaximized() ) {
707 QRegion m = wdiface->mask(&wd); 724 QRegion m = wdiface->mask(&wd);
708 QRect br = m.boundingRect(); 725 QRect br = m.boundingRect();
709 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 726 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
710 int rb = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); 727 int rb = wdiface->metric(WindowDecorationInterface::RightBorder,&wd);
711 QRegion crgn( br.right()-grab, br.top(), grab, tb ); 728 QRegion crgn( br.right()-grab, br.top(), grab, tb );
712 crgn |= QRect( br.right()-rb, br.top(), rb, grab ); 729 crgn |= QRect( br.right()-rb, br.top(), rb, grab );
713 region = m & crgn; 730 region = m & crgn;
714 } 731 }
715 break; 732 break;
716 case BottomLeft: 733 case BottomLeft:
717 if ( !widget->isMaximized() ) { 734 if ( !widget->isMaximized() ) {
718 QRegion m = wdiface->mask(&wd); 735 QRegion m = wdiface->mask(&wd);
719 QRect br = m.boundingRect(); 736 QRect br = m.boundingRect();
720 region = m & QRect( br.left(), br.bottom()-grab, grab, grab ); 737 region = m & QRect( br.left(), br.bottom()-grab, grab, grab );
721 } 738 }
722 break; 739 break;
723 case BottomRight: 740 case BottomRight:
724 if ( !widget->isMaximized() ) { 741 if ( !widget->isMaximized() ) {
725 QRegion m = wdiface->mask(&wd); 742 QRegion m = wdiface->mask(&wd);
726 QRect br = m.boundingRect(); 743 QRect br = m.boundingRect();
727 region = m & QRect( br.right()-grab, br.bottom()-grab, grab, grab ); 744 region = m & QRect( br.right()-grab, br.bottom()-grab, grab, grab );
728 } 745 }
729 break; 746 break;
730 case All: 747 case All:
731 if ( widget->isMaximized() ) 748 if ( widget->isMaximized() )
732 region = QWSDefaultDecoration::region(widget, rect, type); 749 region = QWSDefaultDecoration::region(widget, rect, type);
733 else 750 else
734 region = wdiface->mask(&wd) - rect; 751 region = wdiface->mask(&wd) - rect;
735 break; 752 break;
736 default: 753 default:
737 region = QWSDefaultDecoration::region(widget, rect, type); 754 region = QWSDefaultDecoration::region(widget, rect, type);
738 break; 755 break;
739 } 756 }
740 757
741 return region; 758 return region;
742} 759}
743 760
744void QPEDecoration::paint(QPainter *painter, const QWidget *widget) 761void QPEDecoration::paint(QPainter *painter, const QWidget *widget)
745{ 762{
746 WindowDecorationInterface::WindowData wd; 763 WindowDecorationInterface::WindowData wd;
747 windowData( widget, wd ); 764 windowData( widget, wd );
748 765
749 int titleWidth = getTitleWidth(widget); 766 int titleWidth = getTitleWidth(widget);
750 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 767 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
751 768
752 QRect rect(widget->rect()); 769 QRect rect(widget->rect());
753 770
754 // title bar rect 771 // title bar rect
755 QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight ); 772 QRect tbr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight );
756 773
757#ifndef QT_NO_PALETTE 774#ifndef QT_NO_PALETTE
758 QRegion oldClip = painter->clipRegion(); 775 QRegion oldClip = painter->clipRegion();
759 painter->setClipRegion( oldClip - QRegion( tr ) );// reduce flicker 776 painter->setClipRegion( oldClip - QRegion( tbr ) );// reduce flicker
760 wdiface->drawArea( WindowDecorationInterface::Border, painter, &wd ); 777 wdiface->drawArea( WindowDecorationInterface::Border, painter, &wd );
761 painter->setClipRegion( oldClip ); 778 painter->setClipRegion( oldClip );
762 779
763 if (titleWidth > 0) { 780 if (titleWidth > 0) {
764 const QColorGroup &cg = widget->palette().active(); 781 const QColorGroup &cg = widget->palette().active();
765 QBrush titleBrush; 782 QBrush titleBrush;
766 QPen titlePen; 783 QPen titlePen;
767 784
768 if ( wd.flags & WindowDecorationInterface::WindowData::Active ) { 785 if ( wd.flags & WindowDecorationInterface::WindowData::Active ) {
769 titleBrush = cg.brush(QColorGroup::Highlight); 786 titleBrush = cg.brush(QColorGroup::Highlight);
770 titlePen = cg.color(QColorGroup::HighlightedText); 787 titlePen = cg.color(QColorGroup::HighlightedText);
771 } else { 788 } else {
772 titleBrush = cg.brush(QColorGroup::Background); 789 titleBrush = cg.brush(QColorGroup::Background);
773 titlePen = cg.color(QColorGroup::Text); 790 titlePen = cg.color(QColorGroup::Text);
774 } 791 }
775 792
776 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd ); 793 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd );
777 794
778 // Draw caption 795 // Draw caption
779 painter->setPen(titlePen); 796 painter->setPen(titlePen);
780 QFont f( QApplication::font() ); 797 QFont f( QApplication::font() );
781 f.setWeight( QFont::Bold ); 798 f.setWeight( QFont::Bold );
782 painter->setFont(f); 799 painter->setFont(f);
783 wdiface->drawArea( WindowDecorationInterface::TitleText, painter, &wd ); 800 wdiface->drawArea( WindowDecorationInterface::TitleText, painter, &wd );
784 } 801 }
785#endif //QT_NO_PALETTE 802#endif //QT_NO_PALETTE
786 803
787 paintButton( painter, widget, (QWSDecoration::Region)Help, 0 ); 804 paintButton( painter, widget, (QWSDecoration::Region)Help, 0 );
788} 805}
789 806
790void QPEDecoration::paintButton(QPainter *painter, const QWidget *w, 807void QPEDecoration::paintButton(QPainter *painter, const QWidget *w,
791 QWSDecoration::Region type, int state) 808 QWSDecoration::Region type, int state)
792{ 809{
793 WindowDecorationInterface::Button b; 810 WindowDecorationInterface::Button b;
794 switch ((int)type) { 811 switch ((int)type) {
795 case Close: 812 case Close:
796 b = WindowDecorationInterface::Close; 813 b = WindowDecorationInterface::Close;
797 break; 814 break;
798 case Minimize: 815 case Minimize:
799 if ( ((HackWidget *)w)->needsOk() ) 816 if ( ((DecorHackWidget *)w)->needsOk() )
800 b = WindowDecorationInterface::OK; 817 b = WindowDecorationInterface::OK;
801 else if ( helpExists ) 818 else if ( helpExists() )
802 b = WindowDecorationInterface::Help; 819 b = WindowDecorationInterface::Help;
803 else 820 else
804 return; 821 return;
805 break; 822 break;
806 case Help: 823 case Help:
807 b = WindowDecorationInterface::Help; 824 b = WindowDecorationInterface::Help;
808 break; 825 break;
809 case Maximize: 826 case Maximize:
810 b = WindowDecorationInterface::Maximize; 827 b = WindowDecorationInterface::Maximize;
811 break; 828 break;
812 default: 829 default:
813 return; 830 return;
814 } 831 }
815 832
816 WindowDecorationInterface::WindowData wd; 833 WindowDecorationInterface::WindowData wd;
817 windowData( w, wd ); 834 windowData( w, wd );
818 835
819 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 836 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
820 QRect rect(w->rect()); 837 QRect rect(w->rect());
821 QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight ); 838 QRect tbr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight );
822 QRect brect(region(w, w->rect(), type).boundingRect()); 839 QRect brect(region(w, w->rect(), type).boundingRect());
823 840
824 const QColorGroup &cg = w->palette().active(); 841 const QColorGroup &cg = w->palette().active();
825 if ( wd.flags & WindowDecorationInterface::WindowData::Active ) 842 if ( wd.flags & WindowDecorationInterface::WindowData::Active )
826 painter->setPen( cg.color(QColorGroup::HighlightedText) ); 843 painter->setPen( cg.color(QColorGroup::HighlightedText) );
827 else 844 else
828 painter->setPen( cg.color(QColorGroup::Text) ); 845 painter->setPen( cg.color(QColorGroup::Text) );
829 846
830 QRegion oldClip = painter->clipRegion(); 847 QRegion oldClip = painter->clipRegion();
831 painter->setClipRegion( QRect(brect.x(), tr.y(), brect.width(), tr.height()) ); // reduce flicker 848 painter->setClipRegion( QRect(brect.x(), tbr.y(), brect.width(), tbr.height()) ); // reduce flicker
832 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd ); 849 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd );
833 wdiface->drawButton( b, painter, &wd, brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)state ); 850 wdiface->drawButton( b, painter, &wd, brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)state );
834 painter->setClipRegion( oldClip ); 851 painter->setClipRegion( oldClip );
835} 852}
836 853
837//#define QPE_DONT_SHOW_TITLEBAR 854//#define QPE_DONT_SHOW_TITLEBAR
838 855
839void QPEDecoration::maximize( QWidget *widget ) 856void QPEDecoration::maximize( QWidget *widget )
840{ 857{
841#ifdef QPE_DONT_SHOW_TITLEBAR 858#ifdef QPE_DONT_SHOW_TITLEBAR
842 if ( !widget->inherits( "QDialog" ) ) { 859 if ( !widget->inherits( "QDialog" ) ) {
843 widget->setGeometry( qt_maxWindowRect ); 860 widget->setGeometry( qt_maxWindowRect );
844 } else 861 } else
845#endif 862#endif
846 { 863 {
847 QWSDecoration::maximize( widget ); 864 QWSDecoration::maximize( widget );
848 } 865 }
849} 866}
850 867
868QPopupMenu *QPEDecoration::menu( const QWidget *, const QPoint & )
869{
870 QPopupMenu *m = new QPopupMenu();
871
872 m->insertItem(QPEManager::tr("Restore"), (int)Normalize);
873 m->insertItem(QPEManager::tr("Move"), (int)Title);
874 m->insertItem(QPEManager::tr("Size"), (int)BottomRight);
875 m->insertItem(QPEManager::tr("Maximize"), (int)Maximize);
876 m->insertSeparator();
877 m->insertItem(QPEManager::tr("Close"), (int)Close);
878
879 return m;
880}
881
851#ifndef QT_NO_DIALOG 882#ifndef QT_NO_DIALOG
852class HackDialog : public QDialog 883class HackDialog : public QDialog
853{ 884{
854public: 885public:
855 void acceptIt() { 886 void acceptIt() {
856 if ( isA( "QMessageBox" ) ) 887 if ( isA( "QMessageBox" ) )
857 qApp->postEvent( this, new QKeyEvent( QEvent::KeyPress, Key_Enter, '\n', 0, "\n" ) ); 888 qApp->postEvent( this, new QKeyEvent( QEvent::KeyPress, Key_Enter, '\n', 0, "\n" ) );
858 else 889 else
859 accept(); 890 accept();
860 } 891 }
861}; 892};
862#endif 893#endif
863 894
864 895
865void QPEDecoration::minimize( QWidget *widget ) 896void QPEDecoration::minimize( QWidget *widget )
866{ 897{
867#ifndef QT_NO_DIALOG 898#ifndef QT_NO_DIALOG
868 // We use the minimize button as an "accept" button. 899 // We use the minimize button as an "accept" button.
869 if ( widget->inherits( "QDialog" ) ) { 900 if ( widget->inherits( "QDialog" ) ) {
870 HackDialog *d = (HackDialog *)widget; 901 HackDialog *d = (HackDialog *)widget;
871 d->acceptIt(); 902 d->acceptIt();
872 } 903 }
873#endif 904#endif
874 else if ( ((HackWidget *)widget)->needsOk() ) { 905 else if ( ((DecorHackWidget *)widget)->needsOk() ) {
875 QSignal s; 906 QSignal s;
876 s.connect( widget, SLOT( accept() ) ); 907 s.connect( widget, SLOT( accept() ) );
877 s.activate(); 908 s.activate();
878 } else { 909 } else {
879 help( widget ); 910 help( widget );
880 } 911 }
881} 912}
882 913
883void QPEDecoration::help( QWidget *w ) 914void QPEDecoration::help( QWidget *w )
884{ 915{
885 if ( helpExists ) { 916 if ( helpExists() ) {
886 Global::execute( "helpbrowser", helpFile ); 917 QString hf = helpFile;
918 QString localHelpFile = QString(qApp->argv()[0]) + "-" + w->name() + ".html";
919 QStringList helpPath = Global::helpPath();
920 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end(); ++it) {
921 if ( QFile::exists( *it + "/" + localHelpFile ) ) {
922 hf = localHelpFile;
923 break;
924 }
925 }
926 Global::execute( "helpbrowser", hf );
887 } else if ( w && w->testWFlags(Qt::WStyle_ContextHelp) ) { 927 } else if ( w && w->testWFlags(Qt::WStyle_ContextHelp) ) {
888 QWhatsThis::enterWhatsThisMode(); 928 QWhatsThis::enterWhatsThisMode();
889 QWhatsThis::leaveWhatsThisMode( QObject::tr( 929 QWhatsThis::leaveWhatsThisMode( QObject::tr(
890 "<Qt>Comprehensive help is not available for this application, " 930 "<Qt>Comprehensive help is not available for this application, "
891 "however there is context-sensitive help.<p>To use context-sensitive help:<p>" 931 "however there is context-sensitive help.<p>To use context-sensitive help:<p>"
892 "<ol><li>click and hold the help button." 932 "<ol><li>click and hold the help button."
893 "<li>when the title bar shows <b>What's this...</b>, " 933 "<li>when the title bar shows <b>What's this...</b>, "
894 "click on any control.</ol></Qt>" ) ); 934 "click on any control.</ol></Qt>" ) );
895 } 935 }
896} 936}
897 937
898void QPEDecoration::windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const 938void QPEDecoration::windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const
899{ 939{
900 wd.rect = w->rect(); 940 wd.rect = w->rect();
901 if ( qpeManager->whatsThisWidget() == w ) 941 if ( qpeManager->whatsThisWidget() == w )
902 wd.caption = QObject::tr("What's this..." ); 942 wd.caption = QObject::tr( "What's this..." );
903 else 943 else
904 wd.caption = w->caption(); 944 wd.caption = w->caption();
905 wd.palette = qApp->palette(); 945 wd.palette = qApp->palette();
906 wd.flags = 0; 946 wd.flags = 0;
907 wd.flags |= w->isMaximized() ? WindowDecorationInterface::WindowData::Maximized : 0; 947 wd.flags |= w->isMaximized() ? WindowDecorationInterface::WindowData::Maximized : 0;
908 wd.flags |= w->testWFlags(Qt::WStyle_Dialog) ? WindowDecorationInterface::WindowData::Dialog : 0; 948 wd.flags |= w->testWFlags(Qt::WStyle_Dialog) ? WindowDecorationInterface::WindowData::Dialog : 0;
909 const QWidget *active = qpeManager->activeWidget(); 949 const QWidget *active = qpeManager->activeWidget();
910 wd.flags |= w == active ? WindowDecorationInterface::WindowData::Active : 0; 950 wd.flags |= w == active ? WindowDecorationInterface::WindowData::Active : 0;
911 wd.reserved = 1; 951 wd.reserved = 1;
912} 952}
913 953
914/* 954/*
915#ifndef QT_NO_POPUPMENU 955#ifndef QT_NO_POPUPMENU
916QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&) 956QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&)
917{ 957{
918 return 0; 958 return 0;
919} 959}
920#endif 960#endif
921*/ 961*/
922 962
923 963
924 964
925 965
926#endif // QT_NO_QWS_QPE_WM_STYLE 966#endif // QT_NO_QWS_QPE_WM_STYLE
967#endif
diff --git a/library/qpedecoration_qws.h b/library/qpedecoration_qws.h
index d0a2005..ca670cd 100644
--- a/library/qpedecoration_qws.h
+++ b/library/qpedecoration_qws.h
@@ -1,113 +1,116 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef QPE_DECORATION_QWS_H__ 20#ifndef QPE_DECORATION_QWS_H__
21#define QPE_DECORATION_QWS_H__ 21#define QPE_DECORATION_QWS_H__
22 22
23 23
24#ifdef QWS 24#ifdef QWS
25#include <qpe/global.h>
25#include <qwsdefaultdecoration_qws.h> 26#include <qwsdefaultdecoration_qws.h>
26#include <qimage.h> 27#include <qimage.h>
27#include <qdatetime.h> 28#include <qdatetime.h>
28#include <qguardedptr.h> 29#include <qguardedptr.h>
29#include "windowdecorationinterface.h" 30#include "windowdecorationinterface.h"
30 31
31 32
32#ifndef QT_NO_QWS_QPE_WM_STYLE 33#ifndef QT_NO_QWS_QPE_WM_STYLE
33 34
34class QPEManager; 35class QPEManager;
35class QTimer; 36class QTimer;
37#include <qwidget.h>
36 38
37class QPEDecoration : public QWSDefaultDecoration 39class QPEDecoration : public QWSDefaultDecoration
38{ 40{
39public: 41public:
40 QPEDecoration(); 42 QPEDecoration();
41 QPEDecoration( const QString &plugin ); 43 QPEDecoration( const QString &plugin );
42 virtual ~QPEDecoration(); 44 virtual ~QPEDecoration();
43 45
44 virtual QRegion region(const QWidget *, const QRect &rect, Region); 46 virtual QRegion region(const QWidget *, const QRect &rect, Region);
45 virtual void paint(QPainter *, const QWidget *); 47 virtual void paint(QPainter *, const QWidget *);
46 virtual void paintButton(QPainter *, const QWidget *, Region, int state); 48 virtual void paintButton(QPainter *, const QWidget *, Region, int state);
47 49
48 void maximize( QWidget * ); 50 void maximize( QWidget * );
49 void minimize( QWidget * ); 51 void minimize( QWidget * );
52 virtual QPopupMenu *menu( const QWidget *, const QPoint & );
50 virtual void help( QWidget * ); 53 virtual void help( QWidget * );
51 54
52 enum QPERegion { Help=LastRegion+1 }; 55 enum QPERegion { Help=LastRegion+1 };
53 void buttonClicked( QPERegion r ); 56 void buttonClicked( QPERegion r );
54 57
55protected: 58protected:
56 virtual int getTitleHeight(const QWidget *); 59 virtual int getTitleHeight(const QWidget *);
57 virtual const char **menuPixmap(); 60 virtual const char **menuPixmap();
58 virtual const char **closePixmap(); 61 virtual const char **closePixmap();
59 virtual const char **minimizePixmap(); 62 virtual const char **minimizePixmap();
60 virtual const char **maximizePixmap(); 63 virtual const char **maximizePixmap();
61 virtual const char **normalizePixmap(); 64 virtual const char **normalizePixmap();
62 65
63private: 66private:
64 void windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const; 67 void windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const;
65 68
66 void init ( const QString & ); 69 bool helpExists() const;
67 70
68protected: 71protected:
69 QImage imageOk; 72 QImage imageOk;
70 QImage imageClose; 73 QImage imageClose;
71 QImage imageHelp; 74 QImage imageHelp;
72 QString helpFile; 75 QString helpFile;
73 bool helpExists; 76 bool helpexists : 1;
74 QPEManager *qpeManager; 77 QPEManager *qpeManager;
75}; 78};
76 79
77 80
78class QPEManager : public QObject 81class QPEManager : public QObject
79{ 82{
80 Q_OBJECT 83 Q_OBJECT
81 friend class QPEDecoration; 84 friend class QPEDecoration;
82public: 85public:
83 QPEManager( QPEDecoration *d, QObject *parent=0 ); 86 QPEManager( QPEDecoration *d, QObject *parent=0 );
84 87
85 void updateActive(); 88 void updateActive();
86 const QWidget *activeWidget() const { return (const QWidget *)active; } 89 const QWidget *activeWidget() const { return (const QWidget *)active; }
87 const QWidget *whatsThisWidget() const { return (const QWidget *)whatsThis; } 90 const QWidget *whatsThisWidget() const { return (const QWidget *)whatsThis; }
88 91
89protected: 92protected:
90 int pointInQpeRegion( QWidget *w, const QPoint &p ); 93 int pointInQpeRegion( QWidget *w, const QPoint &p );
91 virtual bool eventFilter( QObject *, QEvent * ); 94 virtual bool eventFilter( QObject *, QEvent * );
92 void drawButton( QWidget *w, QPEDecoration::QPERegion r, int state ); 95 void drawButton( QWidget *w, QPEDecoration::QPERegion r, int state );
93 void drawTitle( QWidget *w ); 96 void drawTitle( QWidget *w );
94 97
95protected slots: 98protected slots:
96 void whatsThisTimeout(); 99 void whatsThisTimeout();
97 100
98protected: 101protected:
99 QPEDecoration *decoration; 102 QPEDecoration *decoration;
100 QGuardedPtr<QWidget> active; 103 QGuardedPtr<QWidget> active;
101 int helpState; 104 int helpState;
102 QTime pressTime; 105 QTime pressTime;
103 QTimer *wtTimer; 106 QTimer *wtTimer;
104 bool inWhatsThis; 107 bool inWhatsThis : 1;
105 QGuardedPtr<QWidget> whatsThis; 108 QGuardedPtr<QWidget> whatsThis;
106}; 109};
107 110
108 111
109#endif // QT_NO_QWS_QPE_WM_STYLE 112#endif // QT_NO_QWS_QPE_WM_STYLE
110 113
111 114
112#endif // QPE_DECORATION_QWS_H__ 115#endif // QPE_DECORATION_QWS_H__
113#endif // QWS 116#endif // QWS