summaryrefslogtreecommitdiff
path: root/library
Unidiff
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpedecoration_qws.cpp55
1 files changed, 15 insertions, 40 deletions
diff --git a/library/qpedecoration_qws.cpp b/library/qpedecoration_qws.cpp
index fb47c14..1afae88 100644
--- a/library/qpedecoration_qws.cpp
+++ b/library/qpedecoration_qws.cpp
@@ -1,731 +1,706 @@
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#define IMAGE_METHOD( methodName, imageName ) \
309static QImage *okImage( int th ) 309static QImage* methodName( int th ) { \
310{ 310 static QImage *i = 0; \
311 static QImage *i = 0; 311 if ( !i || ::abs( i->height()-th ) > 4 ) { \
312 if ( !i || ::abs( i->height()-th ) > 4 ) { 312 delete i; \
313 delete i; 313 i = new QImage(scaleButton(Resource::loadImage(#imageName),th)); \
314 i = new QImage(scaleButton(Resource::loadImage("OKButton"),th)); 314 } \
315 } 315 \
316 return i; 316 return i; \
317} 317}
318 318
319static QImage *closeImage( int th ) 319IMAGE_METHOD(okImage, OKButton );
320{ 320IMAGE_METHOD(closeImage, CloseButton );
321 static QImage *i = 0; 321IMAGE_METHOD(helpImage, HelpButton );
322 if ( !i || ::abs( i->height()-th ) > 4 ) { 322IMAGE_METHOD(maximizeImage,MaximizeButton );
323 delete i;
324 i = new QImage(scaleButton(Resource::loadImage("CloseButton"),th));
325 }
326 return i;
327}
328
329static QImage *helpImage( int th )
330{
331 static QImage *i = 0;
332 if ( !i || ::abs( i->height()-th ) > 4 ) {
333 delete i;
334 i = new QImage(scaleButton(Resource::loadImage("HelpButton"),th));
335 }
336 return i;
337}
338
339static QImage *maximizeImage( int th )
340{
341 static QImage *i = 0;
342 if ( !i || ::abs( i->height()-th ) > 4 ) {
343 delete i;
344 i = new QImage(scaleButton(Resource::loadImage("MaximizeButton"),th));
345 }
346 return i;
347}
348 323
349int WindowDecorationInterface::metric( Metric m, const WindowData *wd ) const 324int WindowDecorationInterface::metric( Metric m, const WindowData *wd ) const
350{ 325{
351 switch ( m ) { 326 switch ( m ) {
352 case TitleHeight: 327 case TitleHeight:
353 if ( QApplication::desktop()->height() > 320 ) 328 if ( QApplication::desktop()->height() > 320 )
354 return 19; 329 return 19;
355 else 330 else
356 return 15; 331 return 15;
357 case LeftBorder: 332 case LeftBorder:
358 case RightBorder: 333 case RightBorder:
359 case TopBorder: 334 case TopBorder:
360 case BottomBorder: 335 case BottomBorder:
361 return 4; 336 return 4;
362 case OKWidth: 337 case OKWidth:
363 return okImage(metric(TitleHeight,wd))->width(); 338 return okImage(metric(TitleHeight,wd))->width();
364 case CloseWidth: 339 case CloseWidth:
365 return closeImage(metric(TitleHeight,wd))->width(); 340 return closeImage(metric(TitleHeight,wd))->width();
366 case HelpWidth: 341 case HelpWidth:
367 return helpImage(metric(TitleHeight,wd))->width(); 342 return helpImage(metric(TitleHeight,wd))->width();
368 case MaximizeWidth: 343 case MaximizeWidth:
369 return maximizeImage(metric(TitleHeight,wd))->width(); 344 return maximizeImage(metric(TitleHeight,wd))->width();
370 case CornerGrabSize: 345 case CornerGrabSize:
371 return 16; 346 return 16;
372 } 347 }
373 348
374 return 0; 349 return 0;
375} 350}
376 351
377void WindowDecorationInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const 352void WindowDecorationInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const
378{ 353{
379 int th = metric( TitleHeight, wd ); 354 int th = metric( TitleHeight, wd );
380 QRect r = wd->rect; 355 QRect r = wd->rect;
381 356
382 switch ( a ) { 357 switch ( a ) {
383 case Border: 358 case Border:
384 { 359 {
385 const QColorGroup &cg = wd->palette.active(); 360 const QColorGroup &cg = wd->palette.active();
386 qDrawWinPanel(p, r.x()-metric(LeftBorder,wd), 361 qDrawWinPanel(p, r.x()-metric(LeftBorder,wd),
387 r.y()-th-metric(TopBorder,wd), 362 r.y()-th-metric(TopBorder,wd),
388 r.width()+metric(LeftBorder,wd)+metric(RightBorder,wd), 363 r.width()+metric(LeftBorder,wd)+metric(RightBorder,wd),
389 r.height()+th+metric(TopBorder,wd)+metric(BottomBorder,wd), 364 r.height()+th+metric(TopBorder,wd)+metric(BottomBorder,wd),
390 cg, FALSE, &cg.brush(QColorGroup::Background)); 365 cg, FALSE, &cg.brush(QColorGroup::Background));
391 } 366 }
392 break; 367 break;
393 case Title: 368 case Title:
394 { 369 {
395 const QColorGroup &cg = wd->palette.active(); 370 const QColorGroup &cg = wd->palette.active();
396 QBrush titleBrush; 371 QBrush titleBrush;
397 QPen titleLines; 372 QPen titleLines;
398 373
399 if ( wd->flags & WindowData::Active ) { 374 if ( wd->flags & WindowData::Active ) {
400 titleBrush = cg.brush(QColorGroup::Highlight); 375 titleBrush = cg.brush(QColorGroup::Highlight);
401 titleLines = titleBrush.color().dark(); 376 titleLines = titleBrush.color().dark();
402 } else { 377 } else {
403 titleBrush = cg.brush(QColorGroup::Background); 378 titleBrush = cg.brush(QColorGroup::Background);
404 titleLines = titleBrush.color(); 379 titleLines = titleBrush.color();
405 } 380 }
406 381
407 p->fillRect( r.x(), r.y()-th, r.width(), th, titleBrush); 382 p->fillRect( r.x(), r.y()-th, r.width(), th, titleBrush);
408 383
409 p->setPen( titleLines ); 384 p->setPen( titleLines );
410 for ( int i = r.y()-th; i < r.y(); i += 2 ) 385 for ( int i = r.y()-th; i < r.y(); i += 2 )
411 p->drawLine( r.left(), i, r.right(), i ); 386 p->drawLine( r.left(), i, r.right(), i );
412 } 387 }
413 break; 388 break;
414 case TitleText: 389 case TitleText:
415 p->drawText( r.x()+3+metric(HelpWidth,wd), r.top()-th, 390 p->drawText( r.x()+3+metric(HelpWidth,wd), r.top()-th,
416 r.width()-metric(OKWidth,wd)-metric(CloseWidth,wd), 391 r.width()-metric(OKWidth,wd)-metric(CloseWidth,wd),
417 th, QPainter::AlignVCenter, wd->caption); 392 th, QPainter::AlignVCenter, wd->caption);
418 break; 393 break;
419 } 394 }
420} 395}
421 396
422void WindowDecorationInterface::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int, int, QWSButton::State state ) const 397void WindowDecorationInterface::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int, int, QWSButton::State state ) const
423{ 398{
424 QImage *img = 0; 399 QImage *img = 0;
425 switch ( b ) { 400 switch ( b ) {
426 case OK: 401 case OK:
427 img = okImage(metric(TitleHeight,wd)); 402 img = okImage(metric(TitleHeight,wd));
428 break; 403 break;
429 case Close: 404 case Close:
430 img = closeImage(metric(TitleHeight,wd)); 405 img = closeImage(metric(TitleHeight,wd));
431 break; 406 break;
432 case Help: 407 case Help:
433 img = helpImage(metric(TitleHeight,wd)); 408 img = helpImage(metric(TitleHeight,wd));
434 break; 409 break;
435 case Maximize: 410 case Maximize:
436 img = maximizeImage(metric(TitleHeight,wd)); 411 img = maximizeImage(metric(TitleHeight,wd));
437 break; 412 break;
438 } 413 }
439 414
440 if ( img ) { 415 if ( img ) {
441 if ((state & QWSButton::MouseOver) && (state & QWSButton::Clicked)) 416 if ((state & QWSButton::MouseOver) && (state & QWSButton::Clicked))
442 p->drawImage(x+2, y+2, *img); 417 p->drawImage(x+2, y+2, *img);
443 else 418 else
444 p->drawImage(x+1, y+1, *img); 419 p->drawImage(x+1, y+1, *img);
445 } 420 }
446} 421}
447 422
448QRegion WindowDecorationInterface::mask( const WindowData *wd ) const 423QRegion WindowDecorationInterface::mask( const WindowData *wd ) const
449{ 424{
450 int th = metric(TitleHeight,wd); 425 int th = metric(TitleHeight,wd);
451 QRect rect( wd->rect ); 426 QRect rect( wd->rect );
452 QRect r(rect.left() - metric(LeftBorder,wd), 427 QRect r(rect.left() - metric(LeftBorder,wd),
453 rect.top() - th - metric(TopBorder,wd), 428 rect.top() - th - metric(TopBorder,wd),
454 rect.width() + metric(LeftBorder,wd) + metric(RightBorder,wd), 429 rect.width() + metric(LeftBorder,wd) + metric(RightBorder,wd),
455 rect.height() + th + metric(TopBorder,wd) + metric(BottomBorder,wd)); 430 rect.height() + th + metric(TopBorder,wd) + metric(BottomBorder,wd));
456 return QRegion(r) - rect; 431 return QRegion(r) - rect;
457} 432}
458 433
459class DefaultWindowDecoration : public WindowDecorationInterface 434class DefaultWindowDecoration : public WindowDecorationInterface
460{ 435{
461public: 436public:
462 DefaultWindowDecoration(){} 437 DefaultWindowDecoration(){}
463 QString name() const { 438 QString name() const {
464 return qApp->translate("WindowDecoration", "Default", 439 return qApp->translate("WindowDecoration", "Default",
465 "List box text for default window decoration"); 440 "List box text for default window decoration");
466 } 441 }
467 QPixmap icon() const { 442 QPixmap icon() const {
468 return QPixmap(); 443 return QPixmap();
469 } 444 }
470 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { 445 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) {
471 *iface = 0; 446 *iface = 0;
472 if ( uuid == IID_QUnknown ) 447 if ( uuid == IID_QUnknown )
473 *iface = this; 448 *iface = this;
474 else if ( uuid == IID_WindowDecoration ) 449 else if ( uuid == IID_WindowDecoration )
475 *iface = this; 450 *iface = this;
476 else 451 else
477 return QS_FALSE; 452 return QS_FALSE;
478 453
479 if ( *iface ) 454 if ( *iface )
480 (*iface)->addRef(); 455 (*iface)->addRef();
481 return QS_OK; 456 return QS_OK;
482 } 457 }
483 Q_REFCOUNT 458 Q_REFCOUNT
484 459
485}; 460};
486 461
487static WindowDecorationInterface *wdiface = 0; 462static WindowDecorationInterface *wdiface = 0;
488static QLibrary* wdlib = 0; 463static QLibrary* wdlib = 0;
489static QString libname; 464static QString libname;
490 465
491//=========================================================================== 466//===========================================================================
492bool QPEDecoration::helpExists() const 467bool QPEDecoration::helpExists() const
493{ 468{
494 if ( helpFile.isNull() ) { 469 if ( helpFile.isNull() ) {
495 QStringList helpPath = Global::helpPath(); 470 QStringList helpPath = Global::helpPath();
496 QString hf = QString(qApp->argv()[0]) + ".html"; 471 QString hf = QString(qApp->argv()[0]) + ".html";
497 bool he = FALSE; 472 bool he = FALSE;
498 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !he; ++it) 473 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !he; ++it)
499 he = QFile::exists( *it + "/" + hf ); 474 he = QFile::exists( *it + "/" + hf );
500 ((QPEDecoration*)this)->helpFile = hf; 475 ((QPEDecoration*)this)->helpFile = hf;
501 ((QPEDecoration*)this)->helpexists = he; 476 ((QPEDecoration*)this)->helpexists = he;
502 return he; 477 return he;
503 } 478 }
504 return helpexists; 479 return helpexists;
505} 480}
506 481
507QPEDecoration::QPEDecoration() 482QPEDecoration::QPEDecoration()
508 : QWSDefaultDecoration() 483 : QWSDefaultDecoration()
509{ 484{
510 if ( wdlib ) { 485 if ( wdlib ) {
511 delete wdlib; 486 delete wdlib;
512 wdlib = 0; 487 wdlib = 0;
513 } else { 488 } else {
514 delete wdiface; 489 delete wdiface;
515 } 490 }
516 wdiface = new DefaultWindowDecoration; 491 wdiface = new DefaultWindowDecoration;
517 492
518 helpexists = FALSE; // We don't know (flagged by helpFile being null) 493 helpexists = FALSE; // We don't know (flagged by helpFile being null)
519 qpeManager = new QPEManager( this ); 494 qpeManager = new QPEManager( this );
520 imageOk = Resource::loadImage( "OKButton" ); 495 imageOk = Resource::loadImage( "OKButton" );
521 imageClose = Resource::loadImage( "CloseButton" ); 496 imageClose = Resource::loadImage( "CloseButton" );
522 imageHelp = Resource::loadImage( "HelpButton" ); 497 imageHelp = Resource::loadImage( "HelpButton" );
523} 498}
524 499
525QPEDecoration::QPEDecoration( const QString &plugin ) 500QPEDecoration::QPEDecoration( const QString &plugin )
526 : QWSDefaultDecoration() 501 : QWSDefaultDecoration()
527{ 502{
528 libname = plugin; 503 libname = plugin;
529 504
530 if ( wdlib ) { 505 if ( wdlib ) {
531 wdiface->release(); 506 wdiface->release();
532 wdlib->unload(); 507 wdlib->unload();
533 delete wdlib; 508 delete wdlib;
534 wdlib = 0; 509 wdlib = 0;
535 } else { 510 } else {
536 delete wdiface; 511 delete wdiface;
537 } 512 }
538 513
539 WindowDecorationInterface *iface = 0; 514 WindowDecorationInterface *iface = 0;
540 QString path = QPEApplication::qpeDir() + "plugins/decorations/"; 515 QString path = QPEApplication::qpeDir() + "plugins/decorations/";
541 516
542#ifdef Q_OS_MACX 517#ifdef Q_OS_MACX
543 if ( plugin.find( ".dylib" ) > 0 ) { 518 if ( plugin.find( ".dylib" ) > 0 ) {
544#else 519#else
545 if ( plugin.find( ".so" ) > 0 ) { 520 if ( plugin.find( ".so" ) > 0 ) {
546#endif 521#endif
547 // full library name supplied 522 // full library name supplied
548 path += plugin; 523 path += plugin;
549 } else { 524 } else {
550#ifdef Q_OS_MACX 525#ifdef Q_OS_MACX
551 path += "lib" + plugin.lower() + ".dylib"; // compatibility 526 path += "lib" + plugin.lower() + ".dylib"; // compatibility
552#else 527#else
553 path += "lib" + plugin.lower() + ".so"; // compatibility 528 path += "lib" + plugin.lower() + ".so"; // compatibility
554#endif 529#endif
555 } 530 }
556 531
557 QLibrary *lib = new QLibrary( path ); 532 QLibrary *lib = new QLibrary( path );
558 if ( lib->queryInterface( IID_WindowDecoration, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 533 if ( lib->queryInterface( IID_WindowDecoration, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
559 wdiface = iface; 534 wdiface = iface;
560 wdlib = lib; 535 wdlib = lib;
561 } else { 536 } else {
562 delete lib; 537 delete lib;
563 wdiface = new DefaultWindowDecoration; 538 wdiface = new DefaultWindowDecoration;
564 } 539 }
565 540
566 541
567 542
568 helpexists = FALSE; // We don't know (flagged by helpFile being null) 543 helpexists = FALSE; // We don't know (flagged by helpFile being null)
569 qpeManager = new QPEManager( this ); 544 qpeManager = new QPEManager( this );
570} 545}
571 546
572QPEDecoration::~QPEDecoration() 547QPEDecoration::~QPEDecoration()
573{ 548{
574 delete qpeManager; 549 delete qpeManager;
575} 550}
576 551
577const char **QPEDecoration::menuPixmap() 552const char **QPEDecoration::menuPixmap()
578{ 553{
579 return (const char **)0; 554 return (const char **)0;
580} 555}
581 556
582const char **QPEDecoration::closePixmap() 557const char **QPEDecoration::closePixmap()
583{ 558{
584 return (const char **)qpe_close_xpm; 559 return (const char **)qpe_close_xpm;
585} 560}
586 561
587const char **QPEDecoration::minimizePixmap() 562const char **QPEDecoration::minimizePixmap()
588{ 563{
589 return (const char **)qpe_accept_xpm; 564 return (const char **)qpe_accept_xpm;
590} 565}
591 566
592const char **QPEDecoration::maximizePixmap() 567const char **QPEDecoration::maximizePixmap()
593{ 568{
594 return (const char **)0; 569 return (const char **)0;
595} 570}
596 571
597const char **QPEDecoration::normalizePixmap() 572const char **QPEDecoration::normalizePixmap()
598{ 573{
599 return (const char **)0; 574 return (const char **)0;
600} 575}
601 576
602int QPEDecoration::getTitleHeight( const QWidget *w ) 577int QPEDecoration::getTitleHeight( const QWidget *w )
603{ 578{
604 WindowDecorationInterface::WindowData wd; 579 WindowDecorationInterface::WindowData wd;
605 windowData( w, wd ); 580 windowData( w, wd );
606 return wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 581 return wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
607} 582}
608 583
609/* 584/*
610 If rect is empty, no frame is added. (a hack, really) 585 If rect is empty, no frame is added. (a hack, really)
611*/ 586*/
612QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type) 587QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type)
613{ 588{
614 qpeManager->updateActive(); 589 qpeManager->updateActive();
615 590
616 WindowDecorationInterface::WindowData wd; 591 WindowDecorationInterface::WindowData wd;
617 windowData( widget, wd ); 592 windowData( widget, wd );
618 wd.rect = rect; 593 wd.rect = rect;
619 594
620 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 595 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
621 int okWidth = wdiface->metric(WindowDecorationInterface::OKWidth,&wd); 596 int okWidth = wdiface->metric(WindowDecorationInterface::OKWidth,&wd);
622 int closeWidth = wdiface->metric(WindowDecorationInterface::CloseWidth,&wd); 597 int closeWidth = wdiface->metric(WindowDecorationInterface::CloseWidth,&wd);
623 int helpWidth = wdiface->metric(WindowDecorationInterface::HelpWidth,&wd); 598 int helpWidth = wdiface->metric(WindowDecorationInterface::HelpWidth,&wd);
624 int grab = wdiface->metric(WindowDecorationInterface::CornerGrabSize,&wd); 599 int grab = wdiface->metric(WindowDecorationInterface::CornerGrabSize,&wd);
625 600
626 QRegion region; 601 QRegion region;
627 602
628 switch ((int)type) { 603 switch ((int)type) {
629 case Menu: 604 case Menu:
630 break; 605 break;
631 case Maximize: 606 case Maximize:
632 if ( !widget->inherits( "QDialog" ) && qApp->desktop()->width() > 350 ) { 607 if ( !widget->inherits( "QDialog" ) && qApp->desktop()->width() > 350 ) {
633 int maximizeWidth = wdiface->metric(WindowDecorationInterface::MaximizeWidth,&wd); 608 int maximizeWidth = wdiface->metric(WindowDecorationInterface::MaximizeWidth,&wd);
634 int left = rect.right() - maximizeWidth - closeWidth; 609 int left = rect.right() - maximizeWidth - closeWidth;
635 if ( ((DecorHackWidget *)widget)->needsOk() ) 610 if ( ((DecorHackWidget *)widget)->needsOk() )
636 left -= okWidth; 611 left -= okWidth;
637 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); 612 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight);
638 region = r; 613 region = r;
639 } 614 }
640 break; 615 break;
641 case Minimize: 616 case Minimize:
642 if ( ((DecorHackWidget *)widget)->needsOk() ) { 617 if ( ((DecorHackWidget *)widget)->needsOk() ) {
643 QRect r(rect.right() - okWidth, 618 QRect r(rect.right() - okWidth,
644 rect.top() - titleHeight, okWidth, titleHeight); 619 rect.top() - titleHeight, okWidth, titleHeight);
645 if (r.left() > rect.left() + titleHeight) 620 if (r.left() > rect.left() + titleHeight)
646 region = r; 621 region = r;
647 } 622 }
648 break; 623 break;
649 case Close: 624 case Close:
650 { 625 {
651 int left = rect.right() - closeWidth; 626 int left = rect.right() - closeWidth;
652 if ( ((DecorHackWidget *)widget)->needsOk() ) 627 if ( ((DecorHackWidget *)widget)->needsOk() )
653 left -= okWidth; 628 left -= okWidth;
654 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); 629 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight);
655 region = r; 630 region = r;
656 } 631 }
657 break; 632 break;
658 case Title: 633 case Title:
659 if ( !widget->isMaximized() ) { 634 if ( !widget->isMaximized() ) {
660 int width = rect.width() - helpWidth - closeWidth; 635 int width = rect.width() - helpWidth - closeWidth;
661 if ( ((DecorHackWidget *)widget)->needsOk() ) 636 if ( ((DecorHackWidget *)widget)->needsOk() )
662 width -= okWidth; 637 width -= okWidth;
663 QRect r(rect.left()+helpWidth, rect.top() - titleHeight, 638 QRect r(rect.left()+helpWidth, rect.top() - titleHeight,
664 width, titleHeight); 639 width, titleHeight);
665 if (r.width() > 0) 640 if (r.width() > 0)
666 region = r; 641 region = r;
667 } 642 }
668 break; 643 break;
669 case Help: 644 case Help:
670 if ( helpExists() || widget->testWFlags(Qt::WStyle_ContextHelp) ) { 645 if ( helpExists() || widget->testWFlags(Qt::WStyle_ContextHelp) ) {
671 QRect r(rect.left(), rect.top() - titleHeight, 646 QRect r(rect.left(), rect.top() - titleHeight,
672 helpWidth, titleHeight); 647 helpWidth, titleHeight);
673 region = r; 648 region = r;
674 } 649 }
675 break; 650 break;
676 case Top: 651 case Top:
677 if ( !widget->isMaximized() ) { 652 if ( !widget->isMaximized() ) {
678 QRegion m = wdiface->mask(&wd); 653 QRegion m = wdiface->mask(&wd);
679 QRect br = m.boundingRect(); 654 QRect br = m.boundingRect();
680 int b = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 655 int b = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
681 region = m & QRect( br.left()+grab, br.top(), 656 region = m & QRect( br.left()+grab, br.top(),
682 br.width()-2*grab, b ); 657 br.width()-2*grab, b );
683 } 658 }
684 break; 659 break;
685 case Left: 660 case Left:
686 if ( !widget->isMaximized() ) { 661 if ( !widget->isMaximized() ) {
687 QRegion m = wdiface->mask(&wd); 662 QRegion m = wdiface->mask(&wd);
688 QRect br = m.boundingRect(); 663 QRect br = m.boundingRect();
689 int b = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); 664 int b = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd);
690 region = m & QRect( br.left(), br.top()+grab, 665 region = m & QRect( br.left(), br.top()+grab,
691 b, br.height()-2*grab ); 666 b, br.height()-2*grab );
692 } 667 }
693 break; 668 break;
694 case Right: 669 case Right:
695 if ( !widget->isMaximized() ) { 670 if ( !widget->isMaximized() ) {
696 QRegion m = wdiface->mask(&wd); 671 QRegion m = wdiface->mask(&wd);
697 QRect br = m.boundingRect(); 672 QRect br = m.boundingRect();
698 int b = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); 673 int b = wdiface->metric(WindowDecorationInterface::RightBorder,&wd);
699 region = m & QRect( rect.right(), br.top()+grab, 674 region = m & QRect( rect.right(), br.top()+grab,
700 b, br.height()-2*grab ); 675 b, br.height()-2*grab );
701 } 676 }
702 break; 677 break;
703 case Bottom: 678 case Bottom:
704 if ( !widget->isMaximized() ) { 679 if ( !widget->isMaximized() ) {
705 QRegion m = wdiface->mask(&wd); 680 QRegion m = wdiface->mask(&wd);
706 QRect br = m.boundingRect(); 681 QRect br = m.boundingRect();
707 int b = wdiface->metric(WindowDecorationInterface::BottomBorder,&wd); 682 int b = wdiface->metric(WindowDecorationInterface::BottomBorder,&wd);
708 region = m & QRect( br.left()+grab, rect.bottom(), 683 region = m & QRect( br.left()+grab, rect.bottom(),
709 br.width()-2*grab, b ); 684 br.width()-2*grab, b );
710 } 685 }
711 break; 686 break;
712 case TopLeft: 687 case TopLeft:
713 if ( !widget->isMaximized() ) { 688 if ( !widget->isMaximized() ) {
714 QRegion m = wdiface->mask(&wd); 689 QRegion m = wdiface->mask(&wd);
715 QRect br = m.boundingRect(); 690 QRect br = m.boundingRect();
716 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 691 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
717 int lb = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); 692 int lb = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd);
718 QRegion crgn( br.left(), br.top(), grab, tb ); 693 QRegion crgn( br.left(), br.top(), grab, tb );
719 crgn |= QRect( br.left(), br.top(), lb, grab ); 694 crgn |= QRect( br.left(), br.top(), lb, grab );
720 region = m & crgn; 695 region = m & crgn;
721 } 696 }
722 break; 697 break;
723 case TopRight: 698 case TopRight:
724 if ( !widget->isMaximized() ) { 699 if ( !widget->isMaximized() ) {
725 QRegion m = wdiface->mask(&wd); 700 QRegion m = wdiface->mask(&wd);
726 QRect br = m.boundingRect(); 701 QRect br = m.boundingRect();
727 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 702 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
728 int rb = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); 703 int rb = wdiface->metric(WindowDecorationInterface::RightBorder,&wd);
729 QRegion crgn( br.right()-grab, br.top(), grab, tb ); 704 QRegion crgn( br.right()-grab, br.top(), grab, tb );
730 crgn |= QRect( br.right()-rb, br.top(), rb, grab ); 705 crgn |= QRect( br.right()-rb, br.top(), rb, grab );
731 region = m & crgn; 706 region = m & crgn;