summaryrefslogtreecommitdiffstats
path: root/src/widgets/qtitlebar.cpp
blob: 553811d274a52a1c142699f2740284afbdf9337c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
/****************************************************************************
**
** Implementation of some TQt private functions.
**
** Created : 001101
**
** Copyright (C) 2000-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of the widgets module of the TQt GUI Toolkit.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
** included in the packaging of this file.  Licensees holding valid TQt
** Commercial licenses may use this file in accordance with the TQt
** Commercial License Agreement provided with the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/

#include "qplatformdefs.h"

#include "qtitlebar_p.h"

#ifndef TQT_NO_TITLEBAR

#include <ntqcursor.h>
#include "ntqapplication.h"
#include "tqstyle.h"
#include "tqdatetime.h"
#include "private/qapplication_p.h"
#include "ntqtooltip.h"
#include "tqimage.h"
#include "tqtimer.h"
#include "ntqpainter.h"
#include "tqstyle.h"
#include "private/qinternal_p.h"
#ifndef TQT_NO_WORKSPACE
#include "ntqworkspace.h"
#endif
#if defined(TQ_WS_WIN)
#include "qt_windows.h"
#endif

#ifndef TQT_NO_TOOLTIP
class TQTitleBarTip : public TQToolTip
{
public:
    TQTitleBarTip( TQWidget * parent ) : TQToolTip( parent ) { }

    void maybeTip( const TQPoint &pos )
    {
	if ( !::tqt_cast<TQTitleBar*>(parentWidget()) )
	    return;
	TQTitleBar *t = (TQTitleBar *)parentWidget();

	TQString tipstring;
	TQStyle::SubControl ctrl = t->style().querySubControl(TQStyle::CC_TitleBar, t, pos);
	TQSize controlSize = t->style().querySubControlMetrics(TQStyle::CC_TitleBar, t, ctrl).size();

	TQWidget *window = t->window();
	if ( window ) {
	    switch(ctrl) {
	    case TQStyle::SC_TitleBarSysMenu:
		if ( t->testWFlags( WStyle_SysMenu ) )
		    tipstring = TQTitleBar::tr( "System Menu" );
		break;

	    case TQStyle::SC_TitleBarShadeButton:
		if ( t->testWFlags( WStyle_Tool ) && t->testWFlags( WStyle_MinMax ) )
		    tipstring = TQTitleBar::tr( "Shade" );
		break;

	    case TQStyle::SC_TitleBarUnshadeButton:
		if ( t->testWFlags( WStyle_Tool ) && t->testWFlags( WStyle_MinMax ) )
		    tipstring = TQTitleBar::tr( "Unshade" );
		break;

	    case TQStyle::SC_TitleBarNormalButton:
	    case TQStyle::SC_TitleBarMinButton:
		if ( !t->testWFlags( WStyle_Tool ) && t->testWFlags( WStyle_Minimize ) ) {
		    if( window->isMinimized() )
			tipstring = TQTitleBar::tr( "Normalize" );
		    else
			tipstring = TQTitleBar::tr( "Minimize" );
		}
		break;

	    case TQStyle::SC_TitleBarMaxButton:
		if ( !t->testWFlags( WStyle_Tool ) && t->testWFlags( WStyle_Maximize ) )
		    tipstring = TQTitleBar::tr( "Maximize" );
		break;

	    case TQStyle::SC_TitleBarCloseButton:
		if ( t->testWFlags( WStyle_SysMenu ) )
		    tipstring = TQTitleBar::tr( "Close" );
		break;

	    default:
		break;
	    }
	}
#ifndef TQT_NO_WIDGET_TOPEXTRA
	if ( tipstring.isEmpty() ) {
	    if ( t->visibleText() != t->caption() )
		tipstring = t->caption();
	}
#endif
	if(!tipstring.isEmpty())
	    tip( TQRect(pos, controlSize), tipstring );
    }
};
#endif

class TQTitleBarPrivate
{
public:
    TQTitleBarPrivate()
	: toolTip( 0 ), act( 0 ), window( 0 ), movable( 1 ), pressed( 0 ), autoraise(0)
    {
    }

    TQStyle::SCFlags buttonDown;
    TQPoint moveOffset;
    TQToolTip *toolTip;
    bool act		    :1;
    TQWidget* window;
    bool movable            :1;
    bool pressed            :1;
    bool autoraise          :1;
    TQString cuttext;
#ifdef TQT_NO_WIDGET_TOPEXTRA
    TQString cap;
#endif
};

TQTitleBar::TQTitleBar(TQWidget* w, TQWidget* parent, const char* name)
    : TQWidget( parent, name, WStyle_Customize | WStyle_NoBorder | WNoAutoErase )
{
    d = new TQTitleBarPrivate();

#ifndef TQT_NO_TOOLTIP
    d->toolTip = new TQTitleBarTip( this );
#endif
    d->window = w;
    d->buttonDown = TQStyle::SC_None;
    d->act = 0;
    if ( w ) {
	setWFlags( ((TQTitleBar*)w)->getWFlags() | WNoAutoErase );
	if ( w->minimumSize() == w->maximumSize() )
	    clearWFlags( WStyle_Maximize );
#ifndef TQT_NO_WIDGET_TOPEXTRA
    	setCaption( w->caption() );
#endif
    } else {
	setWFlags( WStyle_Customize | WNoAutoErase );
    }

    readColors();
    setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ) );
    setMouseTracking(TRUE);
}

TQTitleBar::~TQTitleBar()
{
#ifndef TQT_NO_TOOLTIP
    delete d->toolTip;
#endif

    delete d;
    d = 0;
}

#ifdef TQ_WS_WIN
extern TQRgb qt_colorref2qrgb(COLORREF col);
#endif

void TQTitleBar::readColors()
{
    TQPalette pal = palette();

    bool colorsInitialized = FALSE;

#ifdef TQ_WS_WIN // ask system properties on windows
#ifndef SPI_GETGRADIENTCAPTIONS
#define SPI_GETGRADIENTCAPTIONS 0x1008
#endif
#ifndef COLOR_GRADIENTACTIVECAPTION
#define COLOR_GRADIENTACTIVECAPTION 27
#endif
#ifndef COLOR_GRADIENTINACTIVECAPTION
#define COLOR_GRADIENTINACTIVECAPTION 28
#endif
    if ( TQApplication::desktopSettingsAware() ) {
	pal.setColor( TQPalette::Active, TQColorGroup::Highlight, qt_colorref2qrgb(GetSysColor(COLOR_ACTIVECAPTION)) );
	pal.setColor( TQPalette::Inactive, TQColorGroup::Highlight, qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTION)) );
	pal.setColor( TQPalette::Active, TQColorGroup::HighlightedText, qt_colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT)) );
	pal.setColor( TQPalette::Inactive, TQColorGroup::HighlightedText, qt_colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT)) );
	if ( qt_winver != TQt::WV_95 && qt_winver != WV_NT ) {
	    colorsInitialized = TRUE;
	    BOOL gradient;
	    QT_WA( {
		SystemParametersInfo( SPI_GETGRADIENTCAPTIONS, 0, &gradient, 0 );
	    } , {
		SystemParametersInfoA( SPI_GETGRADIENTCAPTIONS, 0, &gradient, 0 );
	    } );
	    if ( gradient ) {
		pal.setColor( TQPalette::Active, TQColorGroup::Base, qt_colorref2qrgb(GetSysColor(COLOR_GRADIENTACTIVECAPTION)) );
		pal.setColor( TQPalette::Inactive, TQColorGroup::Base, qt_colorref2qrgb(GetSysColor(COLOR_GRADIENTINACTIVECAPTION)) );
	    } else {
		pal.setColor( TQPalette::Active, TQColorGroup::Base, palette().active().highlight() );
		pal.setColor( TQPalette::Inactive, TQColorGroup::Base, palette().inactive().highlight() );
	    }
	}
    }
#endif // TQ_WS_WIN
    if ( !colorsInitialized ) {
	pal.setColor( TQPalette::Active, TQColorGroup::Highlight, palette().active().highlight() );
	pal.setColor( TQPalette::Active, TQColorGroup::Base, palette().active().highlight() );
	pal.setColor( TQPalette::Inactive, TQColorGroup::Highlight, palette().inactive().dark() );
	pal.setColor( TQPalette::Inactive, TQColorGroup::Base, palette().inactive().dark() );
	pal.setColor( TQPalette::Inactive, TQColorGroup::HighlightedText, palette().inactive().background() );
    }

    setPalette( pal );
    setActive( d->act );
}

void TQTitleBar::mousePressEvent( TQMouseEvent * e)
{
    if ( !d->act )
	emit doActivate();
    if ( e->button() == LeftButton ) {
	d->pressed = TRUE;
	TQStyle::SCFlags ctrl = style().querySubControl(TQStyle::CC_TitleBar, this, e->pos());
	switch (ctrl) {
	case TQStyle::SC_TitleBarSysMenu:
	    if ( testWFlags( WStyle_SysMenu ) && !testWFlags( WStyle_Tool ) ) {
		d->buttonDown = TQStyle::SC_None;
		static TQTime* t = 0;
		static TQTitleBar* tc = 0;
		if ( !t )
		    t = new TQTime;
		if ( tc != this || t->elapsed() > TQApplication::doubleClickInterval() ) {
		    emit showOperationMenu();
		    t->start();
		    tc = this;
		} else {
		    tc = 0;
		    emit doClose();
		    return;
		}
	    }
	    break;

	case TQStyle::SC_TitleBarShadeButton:
	case TQStyle::SC_TitleBarUnshadeButton:
	    if ( testWFlags( WStyle_MinMax ) && testWFlags( WStyle_Tool ) )
		d->buttonDown = ctrl;
	    break;

	case TQStyle::SC_TitleBarNormalButton:
	    if( testWFlags( WStyle_Minimize ) && !testWFlags( WStyle_Tool ) )
		d->buttonDown = ctrl;
	    break;

	case TQStyle::SC_TitleBarMinButton:
	    if( testWFlags( WStyle_Minimize ) && !testWFlags( WStyle_Tool ) )
		d->buttonDown = ctrl;
	    break;

	case TQStyle::SC_TitleBarMaxButton:
	    if ( testWFlags( WStyle_Maximize ) && !testWFlags( WStyle_Tool ) )
		d->buttonDown = ctrl;
	    break;

	case TQStyle::SC_TitleBarCloseButton:
	    if ( testWFlags( WStyle_SysMenu ) )
		d->buttonDown = ctrl;
	    break;

	case TQStyle::SC_TitleBarLabel:
	    d->buttonDown = ctrl;
	    d->moveOffset = mapToParent( e->pos() );
	    break;

	default:
	    break;
	}
	repaint( FALSE );
    } else {
	d->pressed = FALSE;
    }
}

void TQTitleBar::contextMenuEvent( TQContextMenuEvent *e )
{
    TQStyle::SCFlags ctrl = style().querySubControl(TQStyle::CC_TitleBar, this, e->pos());
    if( ctrl == TQStyle::SC_TitleBarLabel || ctrl == TQStyle::SC_TitleBarSysMenu )
	emit popupOperationMenu(e->globalPos());
    else
	e->ignore();
}

void TQTitleBar::mouseReleaseEvent( TQMouseEvent * e)
{
    if ( e->button() == LeftButton && d->pressed) {
	TQStyle::SCFlags ctrl = style().querySubControl(TQStyle::CC_TitleBar, this, e->pos());

	if (ctrl == d->buttonDown) {
	    switch(ctrl) {
	    case TQStyle::SC_TitleBarShadeButton:
	    case TQStyle::SC_TitleBarUnshadeButton:
		if( testWFlags( WStyle_MinMax ) && testWFlags( WStyle_Tool ) )
		    emit doShade();
		break;

	    case TQStyle::SC_TitleBarNormalButton:
		if( testWFlags( WStyle_MinMax ) && !testWFlags( WStyle_Tool ) )
		    emit doNormal();
		break;

	    case TQStyle::SC_TitleBarMinButton:
		if( testWFlags( WStyle_Minimize ) && !testWFlags( WStyle_Tool ) )
		    emit doMinimize();
		break;

	    case TQStyle::SC_TitleBarMaxButton:
		if( d->window && testWFlags( WStyle_Maximize ) && !testWFlags( WStyle_Tool ) ) {
		    if(d->window->isMaximized())
			emit doNormal();
		    else
			emit doMaximize();
		}
		break;

	    case TQStyle::SC_TitleBarCloseButton:
		if( testWFlags( WStyle_SysMenu ) ) {
		    d->buttonDown = TQStyle::SC_None;
		    repaint(FALSE);
		    emit doClose();
		    return;
		}
		break;

	    default:
		break;
	    }
	}
	d->buttonDown = TQStyle::SC_None;
	repaint(FALSE);
	d->pressed = FALSE;
    }
}

void TQTitleBar::mouseMoveEvent( TQMouseEvent * e)
{
    switch (d->buttonDown) {
    case TQStyle::SC_None:
	if(autoRaise())
	    repaint( FALSE );
	break;
    case TQStyle::SC_TitleBarSysMenu:
	break;
    case TQStyle::SC_TitleBarShadeButton:
    case TQStyle::SC_TitleBarUnshadeButton:
    case TQStyle::SC_TitleBarNormalButton:
    case TQStyle::SC_TitleBarMinButton:
    case TQStyle::SC_TitleBarMaxButton:
    case TQStyle::SC_TitleBarCloseButton:
	{
	    TQStyle::SCFlags last_ctrl = d->buttonDown;
	    d->buttonDown = style().querySubControl(TQStyle::CC_TitleBar, this, e->pos());
	    if( d->buttonDown != last_ctrl)
		d->buttonDown = TQStyle::SC_None;
	    repaint(FALSE);
	    d->buttonDown = last_ctrl;
	}
	break;

    case TQStyle::SC_TitleBarLabel:
	if ( d->buttonDown == TQStyle::SC_TitleBarLabel && d->movable && d->pressed ) {
	    if ( (d->moveOffset - mapToParent( e->pos() ) ).manhattanLength() >= 4 ) {
		TQPoint p = mapFromGlobal(e->globalPos());
#ifndef TQT_NO_WORKSPACE
		if(d->window && d->window->parentWidget()->inherits("TQWorkspaceChild")) {
		    TQWorkspace *workspace = ::tqt_cast<TQWorkspace*>(d->window->parentWidget()->parentWidget());
		    if(workspace) {
			p = workspace->mapFromGlobal( e->globalPos() );
			if ( !workspace->rect().contains(p) ) {
			    if ( p.x() < 0 )
				p.rx() = 0;
			    if ( p.y() < 0 )
				p.ry() = 0;
			    if ( p.x() > workspace->width() )
				p.rx() = workspace->width();
			    if ( p.y() > workspace->height() )
				p.ry() = workspace->height();
			}
		    }
		}
#endif
		TQPoint pp = p - d->moveOffset;
		if (!parentWidget()->isMaximized())
		    parentWidget()->move( pp );
	    }
	} else {
	    TQStyle::SCFlags last_ctrl = d->buttonDown;
	    d->buttonDown = TQStyle::SC_None;
	    if( d->buttonDown != last_ctrl)
		repaint(FALSE);
	}
	break;
    }
}

void TQTitleBar::resizeEvent( TQResizeEvent *r)
{
    TQWidget::resizeEvent(r);
    cutText();
}

void TQTitleBar::paintEvent(TQPaintEvent *)
{
    TQStyle::SCFlags ctrls = TQStyle::SC_TitleBarLabel;
    if ( testWFlags( WStyle_SysMenu) ) {
	if ( testWFlags( WStyle_Tool ) ) {
	    ctrls |= TQStyle::SC_TitleBarCloseButton;
	    if ( d->window && testWFlags( WStyle_MinMax ) ) {
		if ( d->window->isMinimized() )
		    ctrls |= TQStyle::SC_TitleBarUnshadeButton;
		else
		    ctrls |= TQStyle::SC_TitleBarShadeButton;
	    }
	} else {
	    ctrls |= TQStyle::SC_TitleBarSysMenu | TQStyle::SC_TitleBarCloseButton;
	    if ( d->window && testWFlags( WStyle_Minimize ) ) {
		if( d->window && d->window->isMinimized() )
		    ctrls |= TQStyle::SC_TitleBarNormalButton;
		else
		    ctrls |= TQStyle::SC_TitleBarMinButton;
	    }
	    if ( d->window && testWFlags( WStyle_Maximize ) && !d->window->isMaximized() )
		ctrls |= TQStyle::SC_TitleBarMaxButton;
	}
    }

    TQStyle::SCFlags under_mouse = TQStyle::SC_None;
    if( autoRaise() && hasMouse() ) {
	TQPoint p(mapFromGlobal(TQCursor::pos()));
	under_mouse = style().querySubControl(TQStyle::CC_TitleBar, this, p);
	ctrls ^= under_mouse;
    }

    TQSharedDoubleBuffer buffer( this, rect() );
    style().drawComplexControl(TQStyle::CC_TitleBar, buffer.painter(), this, rect(),
			       colorGroup(),
			       isEnabled() ? TQStyle::Style_Enabled :
			       TQStyle::Style_Default, ctrls, d->buttonDown);
    if(under_mouse != TQStyle::SC_None)
	style().drawComplexControl(TQStyle::CC_TitleBar, buffer.painter(), this, rect(),
				   colorGroup(),
				   TQStyle::Style_MouseOver |
				   (isEnabled() ? TQStyle::Style_Enabled : 0),
				   under_mouse, d->buttonDown);
}

void TQTitleBar::mouseDoubleClickEvent( TQMouseEvent *e )
{
    if ( e->button() != LeftButton )
	return;

    switch(style().querySubControl(TQStyle::CC_TitleBar, this, e->pos())) {
    case TQStyle::SC_TitleBarLabel:
	emit doubleClicked();
	break;

    case TQStyle::SC_TitleBarSysMenu:
	if ( testWFlags( WStyle_SysMenu ) )
	    emit doClose();
	break;

    default:
	break;
    }
}

#ifdef TQT_NO_WIDGET_TOPEXTRA
// We provide one, since titlebar is useless otherwise.
TQString TQTitleBar::caption() const
{
    return d->cap;
}
#endif

void TQTitleBar::cutText()
{
    TQFontMetrics fm( font() );

    int maxw = style().querySubControlMetrics(TQStyle::CC_TitleBar, this,
					      TQStyle::SC_TitleBarLabel).width();
    if ( !d->window )
	maxw = width() - 20;
    const TQString txt = caption();
    d->cuttext = txt;
    if ( fm.width( txt + "m" ) > maxw ) {
	int i = txt.length();
	int dotlength = fm.width( "..." );
	while ( i>0 && fm.width(txt.left( i )) + dotlength > maxw )
	    i--;
	if(i != (int)txt.length())
	    d->cuttext = txt.left( i ) + "...";
    }
}

void TQTitleBar::setCaption( const TQString& title )
{
    if( caption() == title)
	return;
#ifndef TQT_NO_WIDGET_TOPEXTRA
    TQWidget::setCaption( title );
#else
    d->cap = title;
#endif
    cutText();

    update();
}


void TQTitleBar::setIcon( const TQPixmap& icon )
{
#ifndef TQT_NO_WIDGET_TOPEXTRA
#ifndef TQT_NO_IMAGE_SMOOTHSCALE
    TQRect menur = style().querySubControlMetrics(TQStyle::CC_TitleBar, this,
						  TQStyle::SC_TitleBarSysMenu);

    TQPixmap theIcon;
    if (icon.width() > menur.width()) {
	// try to keep something close to the same aspect
	int aspect = (icon.height() * 100) / icon.width();
	int newh = (aspect * menur.width()) / 100;
	theIcon.convertFromImage( icon.convertToImage().smoothScale(menur.width(),
								   newh) );
    } else if (icon.height() > menur.height()) {
	// try to keep something close to the same aspect
	int aspect = (icon.width() * 100) / icon.height();
	int neww = (aspect * menur.height()) / 100;
	theIcon.convertFromImage( icon.convertToImage().smoothScale(neww,
								   menur.height()) );
    } else
	theIcon = icon;

    TQWidget::setIcon( theIcon );
#else
    TQWidget::setIcon( icon );
#endif

    update();
#endif
}

void TQTitleBar::leaveEvent( TQEvent * )
{
    if(autoRaise() && !d->pressed)
	repaint( FALSE );
}

void TQTitleBar::enterEvent( TQEvent * )
{
    if(autoRaise() && !d->pressed)
	repaint( FALSE );
    TQEvent e( TQEvent::Leave );
    TQApplication::sendEvent( parentWidget(), &e );
}

void TQTitleBar::setActive( bool active )
{
    if ( d->act == active )
	return ;

    d->act = active;
    update();
}

bool TQTitleBar::isActive() const
{
    return d->act;
}

bool TQTitleBar::usesActiveColor() const
{
    return ( isActive() && isActiveWindow() ) ||
	   ( !window() && topLevelWidget()->isActiveWindow() );
}

TQString TQTitleBar::visibleText() const
{
    return d->cuttext;
}

TQWidget *TQTitleBar::window() const
{
    return d->window;
}

bool TQTitleBar::event( TQEvent* e )
{
    if ( e->type() == TQEvent::ApplicationPaletteChange ) {
	readColors();
	return TRUE;
    } else if ( e->type() == TQEvent::WindowActivate ) {
	setActive( d->act );
    } else if ( e->type() == TQEvent::WindowDeactivate ) {
	bool wasActive = d->act;
	setActive( FALSE );
	d->act = wasActive;
    }

    return TQWidget::event( e );
}

void TQTitleBar::setMovable(bool b)
{
    d->movable = b;
}

bool TQTitleBar::isMovable() const
{
    return d->movable;
}

void TQTitleBar::setAutoRaise(bool b)
{
    d->autoraise = b;
}

bool TQTitleBar::autoRaise() const
{
    return d->autoraise;
}

TQSize TQTitleBar::sizeHint() const
{
    constPolish();
    TQRect menur = style().querySubControlMetrics(TQStyle::CC_TitleBar, this,
						 TQStyle::SC_TitleBarSysMenu);
    return TQSize( menur.width(), style().pixelMetric( TQStyle::PM_TitleBarHeight, this ) );
}

#endif //TQT_NO_TITLEBAR