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