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