summaryrefslogtreecommitdiffstats
path: root/twin-styles/kde1/kde1client.cpp
blob: e45313f3ce04b66691072118b81e6d19b89d2077 (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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
/*****************************************************************
twin - the KDE window manager
								
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
******************************************************************/
#include "kde1client.h"
#include <tqcursor.h>
#include <tqlayout.h>
#include <tqtoolbutton.h>
#include <tqlabel.h>
#include <tqdrawutil.h>
#include <tqbitmap.h>
#include <kdrawutil.h>
#include <tdelocale.h>
#include <kpixmap.h>
#include <tqdatetime.h>
#include <tqimage.h>
#include <tqtooltip.h>

#include "kde1client_bitmaps.h"

// Default button layout
const char default_left[]  = "MS";
const char default_right[] = "H_IAX";

namespace KDE1
{

TQPixmap* close_pix = 0;
TQPixmap* maximize_pix = 0;
TQPixmap* minimize_pix = 0;
TQPixmap* normalize_pix = 0;
TQPixmap* pinup_pix = 0;
TQPixmap* pindown_pix = 0;
TQPixmap* menu_pix = 0;
TQPixmap* question_mark_pix = 0;

TQPixmap* dis_close_pix = 0;
TQPixmap* dis_maximize_pix = 0;
TQPixmap* dis_minimize_pix = 0;
TQPixmap* dis_normalize_pix = 0;
TQPixmap* dis_pinup_pix = 0;
TQPixmap* dis_pindown_pix = 0;
TQPixmap* dis_menu_pix = 0;
TQPixmap* dis_question_mark_pix = 0;

TQPixmap* titleBuffer = 0;

bool pixmaps_created = FALSE;

inline const KDecorationOptions* options() { return KDecoration::options(); }

void create_pixmaps()
{
    if ( pixmaps_created )
        return;
    pixmaps_created = true;
    TQColorGroup aGrp = options()->colorGroup(KDecorationOptions::ColorButtonBg, true);
    TQColorGroup iGrp = options()->colorGroup(KDecorationOptions::ColorButtonBg, false);

    TQPainter aPainter, iPainter;
    close_pix = new TQPixmap(16, 16);
    dis_close_pix = new TQPixmap(16, 16);
    aPainter.begin(close_pix); iPainter.begin(dis_close_pix);
    kColorBitmaps(&aPainter, aGrp, 0, 0, 16, 16, true, close_white_bits,
                  NULL, NULL, close_dgray_bits, NULL, NULL);
    kColorBitmaps(&iPainter, iGrp, 0, 0, 16, 16, true, close_white_bits,
                  NULL, NULL, close_dgray_bits, NULL, NULL);
    aPainter.end(); iPainter.end();
    close_pix->setMask(TQBitmap(16, 16, close_mask_bits, true));
    dis_close_pix->setMask(*close_pix->mask());

    minimize_pix = new TQPixmap(16, 16);
    dis_minimize_pix = new TQPixmap(16, 16);
    aPainter.begin(minimize_pix); iPainter.begin(dis_minimize_pix);
    kColorBitmaps(&aPainter, aGrp, 0, 0, 16, 16, true, iconify_white_bits,
                  NULL, NULL, iconify_dgray_bits, NULL, NULL);
    kColorBitmaps(&iPainter, iGrp, 0, 0, 16, 16, true, iconify_white_bits,
                  NULL, NULL, iconify_dgray_bits, NULL, NULL);
    aPainter.end(); iPainter.end();
    minimize_pix->setMask(TQBitmap(16, 16, iconify_mask_bits, true));
    dis_minimize_pix->setMask(*minimize_pix->mask());

    maximize_pix = new TQPixmap(16, 16);
    dis_maximize_pix = new TQPixmap(16, 16);
    aPainter.begin(maximize_pix); iPainter.begin(dis_maximize_pix);
    kColorBitmaps(&aPainter, aGrp, 0, 0, 16, 16, true, maximize_white_bits,
                  NULL, NULL, maximize_dgray_bits, NULL, NULL);
    kColorBitmaps(&iPainter, iGrp, 0, 0, 16, 16, true, maximize_white_bits,
                  NULL, NULL, maximize_dgray_bits, NULL, NULL);
    aPainter.end(); iPainter.end();
    maximize_pix->setMask(TQBitmap(16, 16, maximize_mask_bits, true));
    dis_maximize_pix->setMask(*maximize_pix->mask());

    normalize_pix = new TQPixmap(16, 16);
    dis_normalize_pix = new TQPixmap(16, 16);
    aPainter.begin(normalize_pix); iPainter.begin(dis_normalize_pix);
    kColorBitmaps(&aPainter, aGrp, 0, 0, 16, 16, true, maximizedown_white_bits,
                  NULL, NULL, maximizedown_dgray_bits, NULL, NULL);
    kColorBitmaps(&iPainter, iGrp, 0, 0, 16, 16, true, maximizedown_white_bits,
                  NULL, NULL, maximizedown_dgray_bits, NULL, NULL);
    aPainter.end(); iPainter.end();
    normalize_pix->setMask(TQBitmap(16, 16, maximizedown_mask_bits, true));
    dis_normalize_pix->setMask(*normalize_pix->mask());

    menu_pix = new TQPixmap(16, 16);
    dis_menu_pix = new TQPixmap(16, 16);
    aPainter.begin(menu_pix); iPainter.begin(dis_menu_pix);
    kColorBitmaps(&aPainter, aGrp, 0, 0, 16, 16, true, menu_white_bits,
                  NULL, NULL, menu_dgray_bits, NULL, NULL);
    kColorBitmaps(&iPainter, iGrp, 0, 0, 16, 16, true, menu_white_bits,
                  NULL, NULL, menu_dgray_bits, NULL, NULL);
    aPainter.end(); iPainter.end();
    menu_pix->setMask(TQBitmap(16, 16, menu_mask_bits, true));
    dis_menu_pix->setMask(*menu_pix->mask());

    pinup_pix = new TQPixmap(16, 16);
    dis_pinup_pix = new TQPixmap(16, 16);
    aPainter.begin(pinup_pix); iPainter.begin(dis_pinup_pix);
    kColorBitmaps(&aPainter, aGrp, 0, 0, 16, 16, true, pinup_white_bits,
                  pinup_gray_bits, NULL, pinup_dgray_bits, NULL, NULL);
    kColorBitmaps(&iPainter, iGrp, 0, 0, 16, 16, true, pinup_white_bits,
                  pinup_gray_bits, NULL, pinup_dgray_bits, NULL, NULL);
    aPainter.end(); iPainter.end();
    pinup_pix->setMask(TQBitmap(16, 16, pinup_mask_bits, true));
    dis_pinup_pix->setMask(*pinup_pix->mask());

    pindown_pix = new TQPixmap(16, 16);
    dis_pindown_pix = new TQPixmap(16, 16);
    aPainter.begin(pindown_pix); iPainter.begin(dis_pindown_pix);
    kColorBitmaps(&aPainter, aGrp, 0, 0, 16, 16, true, pindown_white_bits,
                  pindown_gray_bits, NULL, pindown_dgray_bits, NULL, NULL);
    kColorBitmaps(&iPainter, iGrp, 0, 0, 16, 16, true, pindown_white_bits,
                  pindown_gray_bits, NULL, pindown_dgray_bits, NULL, NULL);
    aPainter.end(); iPainter.end();
    pindown_pix->setMask(TQBitmap(16, 16, pindown_mask_bits, true));
    dis_pindown_pix->setMask(*pindown_pix->mask());

    question_mark_pix = new TQPixmap(16, 16);
    dis_question_mark_pix = new TQPixmap(16, 16);
    aPainter.begin(question_mark_pix); iPainter.begin(dis_question_mark_pix);
    kColorBitmaps(&aPainter, aGrp, 0, 0, 16, 16, true, help_light_bits,
                  NULL, NULL, help_dark_bits, NULL, NULL);
    kColorBitmaps(&iPainter, iGrp, 0, 0, 16, 16, true, help_light_bits,
                  NULL, NULL, help_dark_bits, NULL, NULL);
    aPainter.end(); iPainter.end();
    question_mark_pix->setMask(TQBitmap(16, 16, help_mask_bits, true));
    dis_question_mark_pix->setMask(*question_mark_pix->mask());

    titleBuffer = new KPixmap;
}

void delete_pixmaps()
{
    delete close_pix;
    delete maximize_pix;
    delete minimize_pix;
    delete normalize_pix;
    delete pinup_pix;
    delete pindown_pix;
    delete menu_pix;
    delete question_mark_pix;
    delete dis_close_pix;
    delete dis_maximize_pix;
    delete dis_minimize_pix;
    delete dis_normalize_pix;
    delete dis_pinup_pix;
    delete dis_pindown_pix;
    delete dis_menu_pix;
    delete dis_question_mark_pix;
    delete titleBuffer;
    pixmaps_created = false;
}

void drawGradient
(
  TQPainter & p,
  const TQRect & t,
  const TQColor & c1,
  const TQColor & c2
)
{
  // Don't draw a million vertical lines if we don't need to.

  if (c1 == c2  || TQPixmap::defaultDepth() <= 8)
  {
    p.fillRect(t, c1);
    return;
  }

  // rikkus: Adapted from KPixmapEffect::gradient().

  int rca = c1.red();
  int gca = c1.green();
  int bca = c1.blue();

  int rDiff = c2.red()   - rca;
  int gDiff = c2.green() - gca;
  int bDiff = c2.blue()  - bca;

  int rl = rca << 16;
  int gl = gca << 16;
  int bl = bca << 16;

  int rcdelta = ((1 << 16) / t.width()) * rDiff;
  int gcdelta = ((1 << 16) / t.width()) * gDiff;
  int bcdelta = ((1 << 16) / t.width()) * bDiff;

  for (int x = 0; x < t.width(); x++)
  {
    rl += rcdelta;
    gl += gcdelta;
    bl += bcdelta;

    p.setPen(TQColor(rl >> 16, gl >> 16, bl >> 16));

    p.drawLine(t.x() + x, 0, t.x() + x, t.y() + t.height() - 1);
  }
}


void StdClient::reset( unsigned long )
{
    if (button[ButtonMenu] && (icon().pixmap( TQIconSet::Small, TQIconSet::Normal ).isNull()))
        button[ButtonMenu]->setIconSet(isActive() ? *menu_pix : *dis_menu_pix);
    if (button[ButtonSticky])
        button[ButtonSticky]->setIconSet(isOnAllDesktops() ? isActive() ? *pindown_pix : *dis_pindown_pix :
                                         isActive() ? *pinup_pix : *dis_pinup_pix );
    if (button[ButtonMinimize])
        button[ButtonMinimize]->setIconSet(isActive() ? *minimize_pix : *dis_minimize_pix);
    if (button[ButtonMaximize])
        button[ButtonMaximize]->setIconSet(isActive() ? *maximize_pix : *dis_maximize_pix);
    if (button[ButtonClose])
        button[ButtonClose]->setIconSet(isActive() ? *close_pix : *dis_close_pix);
    if (button[ButtonHelp])
        button[ButtonHelp]->setIconSet(isActive() ? *question_mark_pix : *dis_question_mark_pix);

    widget()->setFont(options()->font(true));
}


StdClient::StdClient( KDecorationBridge* b, KDecorationFactory* f )
    : KDecoration( b, f )
{
}

void StdClient::init()
{
    createMainWidget();
    widget()->installEventFilter( this );

    widget()->setFont(options()->font(isActive() ));

    TQGridLayout* g = new TQGridLayout( widget(), 0, 0, 3, 2 );
    g->setRowStretch( 1, 10 );
    if( isPreview())
        g->addWidget( new TQLabel( i18n( "<center><b>KDE 1 preview</b></center>" ), widget()), 1, 1 );
    else
        g->addItem( new TQSpacerItem( 0, 0 ), 1, 1 ); //no widget in the middle
    g->addItem( new TQSpacerItem( 0, 0, TQSizePolicy::Fixed, TQSizePolicy::Expanding ) );

    g->addColSpacing(0, 1);
    g->addColSpacing(2, 1);
    g->addRowSpacing(2, 1);

    int fh = widget()->fontMetrics().lineSpacing();
    titlebar = new TQSpacerItem(10, fh, TQSizePolicy::Expanding,
			       TQSizePolicy::Minimum );

    TQBoxLayout* hb = new TQBoxLayout(0, TQBoxLayout::LeftToRight, 0, 0, 0);
    g->addLayout( hb, 0, 1 );

    // setup titlebar buttons
    for (int n=0; n<ButtonTypeCount; n++) button[n] = 0;
    addButtons(hb, options()->customButtonPositions() ? options()->titleButtonsLeft() : TQString(default_left));
    hb->addItem(titlebar);
    addButtons(hb, options()->customButtonPositions() ? options()->titleButtonsRight() : TQString(default_right));

    for (int n=0; n<ButtonTypeCount; n++) {
	if ( !button[n] )
	    continue;
	button[n]->setBackgroundMode( PaletteBackground );
	button[n]->setMouseTracking( FALSE );
	button[n]->setAutoRaise( TRUE );
	button[n]->setFocusPolicy( TQ_NoFocus );
	button[n]->setFixedSize( 20, 20 );
    }

#if 0 // not sure what this is supposed to mean (and why)
    if ( isTransient() ) {
	// lighter decoration for transient windows
	button[1]->hide();
//	button[2]->hide();
	button[3]->hide();
	button[4]->hide();
    }
#endif
}

void StdClient::addButtons(TQBoxLayout *hb, const TQString& s)
{
    if (s.length() > 0) {
        for (unsigned n=0; n < s.length(); n++) {
            switch (s[n]) {
              case 'M': // Menu button
                  if (!button[ButtonMenu]) {
                      button[ButtonMenu] = new TQToolButton( widget(), 0 );
                      TQToolTip::add( button[ButtonMenu], i18n("Menu") );
                      button[ButtonMenu]->setCursor(ArrowCursor);
                      if( icon().pixmap( TQIconSet::Small, TQIconSet::Normal ).isNull())
                          button[ButtonMenu]->setIconSet(isActive() ? *menu_pix : *dis_menu_pix);
                      else
                          button[ButtonMenu]->setIconSet( icon().pixmap( TQIconSet::Small, TQIconSet::Normal ));
                      connect( button[0], TQT_SIGNAL( pressed() ), this, TQT_SLOT( menuButtonPressed() ) );
                      hb->addWidget(button[ButtonMenu]);
                  }
                  break;

              case 'S': // Sticky button
                  if (!button[ButtonSticky]) {
                     button[ButtonSticky] = new TQToolButton( widget(), 0 );
                     button[ButtonSticky]->setIconSet( isOnAllDesktops()?*pindown_pix:*pinup_pix );
                     TQToolTip::add( button[ButtonSticky], isOnAllDesktops()?i18n("Not On All Desktops"):i18n("On All Desktops")  );
                     button[ButtonSticky]->setCursor(ArrowCursor);
                     button[ButtonSticky]->setIconSet(isOnAllDesktops() ? isActive() ? *pindown_pix : *dis_pindown_pix :
                                                      isActive() ? *pinup_pix : *dis_pinup_pix );
                     connect( button[ButtonSticky], TQT_SIGNAL( clicked() ), this, ( TQT_SLOT( toggleOnAllDesktops() ) ) );
                     hb->addWidget(button[ButtonSticky]);
                  }
                  break;

              case 'H': // Help button
                  if ((!button[ButtonHelp]) && providesContextHelp()) {
                      button[ButtonHelp] = new TQToolButton( widget(), 0 );
                      TQToolTip::add( button[ButtonHelp], i18n("Help") );
                      button[ButtonHelp]->setIconSet( isActive() ? *question_mark_pix : *dis_question_mark_pix);
                      connect( button[ButtonHelp], TQT_SIGNAL( clicked() ), this, ( TQT_SLOT( showContextHelp() ) ) );
                      button[ButtonHelp]->setCursor(ArrowCursor);
                      hb->addWidget(button[ButtonHelp]);
                  }
                  break;

              case 'I': // Minimize button
                  if ((!button[ButtonMinimize]) && isMinimizable())  {
                      button[ButtonMinimize] = new TQToolButton( widget(), 0 );
                      TQToolTip::add( button[ButtonMinimize], i18n("Minimize") );
                      button[ButtonMinimize]->setCursor(ArrowCursor);
                      button[ButtonMinimize]->setIconSet(isActive() ? *minimize_pix : *dis_minimize_pix);
                      connect( button[ButtonMinimize], TQT_SIGNAL( clicked() ), this, ( TQT_SLOT( minimize() ) ) );
                      hb->addWidget(button[ButtonMinimize]);
                  }
                  break;

              case 'A': // Maximize button
                  if ((!button[ButtonMaximize]) && isMaximizable()) {
                      const bool max = maximizeMode()!=MaximizeRestore;
                      button[ButtonMaximize] = new ThreeButtonButton( widget(), 0 );
                      TQToolTip::add( button[ButtonMaximize], max?i18n("Restore"):i18n("Maximize") );
                      button[ButtonMaximize]->setCursor(ArrowCursor);
                      button[ButtonMaximize]->setIconSet( max?(isActive() ? *normalize_pix : *dis_normalize_pix):(isActive() ? *maximize_pix : *dis_maximize_pix) );
                      connect( button[ButtonMaximize], TQT_SIGNAL( clicked(ButtonState) ),
                               this, ( TQT_SLOT( maxButtonClicked(ButtonState) ) ) );
                      hb->addWidget(button[ButtonMaximize]);
                  }
                  break;

              case 'X': // Close button
                  if ((!button[ButtonClose]) && isCloseable()) {
                      button[ButtonClose] = new TQToolButton( widget(), 0 );
                      TQToolTip::add( button[ButtonClose], i18n("Close") );
                      button[ButtonClose]->setCursor(ArrowCursor);
                      button[ButtonClose]->setIconSet(isActive() ? *close_pix : *dis_close_pix);
                      connect( button[ButtonClose], TQT_SIGNAL( clicked() ), this, ( TQT_SLOT( closeWindow() ) ) );
                      hb->addWidget(button[ButtonClose]);
                  }
                  break;

              case '_': // Spacer item
	          hb->addItem( new TQSpacerItem( 5, 0, TQSizePolicy::Fixed, TQSizePolicy::Expanding ) );
            }
        }
    }
}

void StdClient::activeChange()
{
    bool on = isActive();
    if (button[ButtonMenu] && (icon().pixmap( TQIconSet::Small, TQIconSet::Normal ).isNull()))
        button[ButtonMenu]->setIconSet(on ? *menu_pix : *dis_menu_pix);
    if (button[ButtonSticky])
        button[ButtonSticky]->setIconSet(isOnAllDesktops() ? on ? *pindown_pix : *dis_pindown_pix :
                          on ? *pinup_pix : *dis_pinup_pix );
    if (button[ButtonMinimize])
        button[ButtonMinimize]->setIconSet(on ? *minimize_pix : *dis_minimize_pix);
    if (button[ButtonMaximize])
        button[ButtonMaximize]->setIconSet(on ? *maximize_pix : *dis_maximize_pix);
    if (button[ButtonClose])
        button[ButtonClose]->setIconSet(on ? *close_pix : *dis_close_pix);
    if (button[ButtonHelp])
        button[ButtonHelp]->setIconSet(on ? *question_mark_pix : *dis_question_mark_pix);
    widget()->repaint( titlebar->geometry(), false );
}


StdClient::~StdClient()
{
    for (int n=0; n<ButtonTypeCount; n++) {
        if (button[n]) delete button[n];
    }
}


void StdClient::resizeEvent( TQResizeEvent* )
{
    TQRegion rr = widget()->rect();
    TQRect t = titlebar->geometry();
//     t.setTop( 0 );
//     TQRegion r = rr.subtract( TQRect( t.x()+1, 0, t.width()-2, 1 ) );
//     setMask( r );

    if ( widget()->isVisibleToTLW() && !widget()->testWFlags( WStaticContents )) {
	// manual clearing without the titlebar (we selected WResizeNoErase )
	TQRect cr( 2, 2, width()-4, height()- 4 );
	widget()->erase( TQRegion( cr ).subtract( t ) );
    }
}

/*!\reimp
 */
void StdClient::captionChange()
{
    widget()->repaint( titlebar->geometry(), FALSE );
}


/*!\reimp
 */
void StdClient::maximizeChange()
{
    bool m = maximizeMode() == MaximizeFull;
    if (button[ButtonMaximize]) {
        button[ButtonMaximize]->setIconSet( m?*normalize_pix:*maximize_pix  );
        TQToolTip::remove( button[ButtonMaximize] );
        TQToolTip::add( button[ButtonMaximize], m ? i18n("Restore") : i18n("Maximize") );
    }
}


/*!\reimp
 */
void StdClient::desktopChange()
{
    bool s = isOnAllDesktops();
    if (button[ButtonSticky]) {
        button[ButtonSticky]->setIconSet( s?*pindown_pix:*pinup_pix );
        TQToolTip::remove( button[ButtonSticky] );
        TQToolTip::add( button[ButtonSticky], s ? i18n("Not On All Desktops") : i18n("On All Desktops") );
    }
}

void StdClient::paintEvent( TQPaintEvent* )
{
    TQPainter p( widget() );
    TQRect t = titlebar->geometry();
    TQRegion r = widget()->rect();
    r = r.subtract( t );
    p.setClipRegion( r );
    qDrawWinPanel( &p, widget()->rect(), widget()->colorGroup() );
//     t.setTop( 1 );
//     p.setClipRegion( t );
//     t.setTop( 0 );

    TQRect titleRect( 0, 0, t.width(), t.height() );
    titleBuffer->resize( titleRect.width(), titleRect.height() );
    TQPainter p2( titleBuffer );

    drawGradient(p2, titleRect, options()->color(KDecorationOptions::ColorTitleBar, isActive()),
        options()->color(KDecorationOptions::ColorTitleBlend, isActive()));
//     p.setPen( options()->color(KDecorationOptions::ColorTitleBar, isActive()).light() );
//     p.drawLine(t.left(), t.top()+1,  t.right(), t.top()+1);
    if ( isActive() )
	qDrawShadePanel( &p2, 0, 0, titleRect.width(), titleRect.height(),
			 widget()->colorGroup(), true, 1 );
    titleRect.setLeft( 4 );
    titleRect.setWidth( titleRect.width() - 2 );
    p2.setPen(options()->color(KDecorationOptions::ColorFont, isActive()));
    p2.setFont(options()->font(isActive()));
    p2.drawText( titleRect, AlignLeft|AlignVCenter|SingleLine, caption() );
    p2.end();
    p.end();
    bitBlt( widget(), t.topLeft(), titleBuffer );
}


void StdClient::mouseDoubleClickEvent( TQMouseEvent * e )
{
    if ( e->button() == Qt::LeftButton && titlebar->geometry().contains( e->pos() ) )
	titlebarDblClickOperation();
}


void StdClient::wheelEvent( TQWheelEvent * e )
{
    if (isSetShade() || TQRect( 0, 0, width(), titlebar->geometry().height() ).contains( e->pos() ) )
        titlebarMouseWheelOperation( e->delta());
}


void StdClient::iconChange()
{
    if (button[ButtonMenu]) {
        if ( icon().pixmap( TQIconSet::Small, TQIconSet::Normal ).isNull())
            button[ButtonMenu]->setIconSet(isActive() ? *menu_pix : *dis_menu_pix);
        else
            button[ButtonMenu]->setIconSet( icon().pixmap( TQIconSet::Small, TQIconSet::Normal ) );
        button[ButtonMenu]->repaint( FALSE );
    }
}


/*!
  Indicates that the menu button has been clicked. One press shows
  the window operation menu, a double click closes the window.
 */
void StdClient::menuButtonPressed()
{
    TQRect menuRect = button[ButtonMenu]->rect();
    menuRect.addCoords(-1, 0, +1, +2);
    TQPoint menuTop = button[ButtonMenu]->mapToGlobal(menuRect.topLeft());
    TQPoint menuBottom = button[ButtonMenu]->mapToGlobal(menuRect.bottomRight());
    KDecorationFactory* f = factory(); // needs to be saved before
    showWindowMenu( TQRect(menuTop, menuBottom) );
    if( !f->exists( this )) // destroyed, return immediately
        return;
    button[ButtonMenu]->setDown(false);
}


void StdClient::maxButtonClicked( ButtonState button )
{
    maximize( button );
}

bool StdClient::eventFilter( TQObject* o, TQEvent* e )
{
    if ( TQT_BASE_OBJECT(o) != TQT_BASE_OBJECT(widget()) )
	return false;

    switch ( e->type() ) {
    case TQEvent::Resize:
	resizeEvent( TQT_TQRESIZEEVENT( e ) );
	return true;

    case TQEvent::Paint:
	paintEvent( TQT_TQPAINTEVENT( e ) );
	return true;

    case TQEvent::MouseButtonDblClick:
	mouseDoubleClickEvent( TQT_TQMOUSEEVENT( e ) );
	return true;

    case TQEvent::MouseButtonPress:
	processMousePressEvent( TQT_TQMOUSEEVENT( e ) );
	return true;

    case TQEvent::Wheel:
	wheelEvent( TQT_TQWHEELEVENT( e ));
	return true;

    default:
	return false;
    }
}

TQSize StdClient::minimumSize() const
{
    return widget()->minimumSize().expandedTo( TQSize( 100, 50 ));
}

void StdClient::borders( int& left, int& right, int& top, int& bottom ) const
{
    left = right = bottom = 6;
    top = 6 + widget()->fontMetrics().lineSpacing()+2;
}

void StdClient::resize( const TQSize& s )
{
    widget()->resize( s );
}

StdToolClient::StdToolClient( KDecorationBridge* b, KDecorationFactory* f )
    : KDecoration( b, f )
{
}

void StdToolClient::init()
{
    createMainWidget();
    widget()->installEventFilter( this );

    widget()->setFont(options()->font(isActive(), true ));

    TQGridLayout* g = new TQGridLayout( widget(), 0, 0, 2 );
    g->setRowStretch( 1, 10 );
    if( isPreview())
        g->addWidget( new TQLabel( i18n( "<center><b>KDE 1 decoration</b></center>" ), widget()), 1, 1 );
    else
        g->addItem( new TQSpacerItem( 0, 0 ), 1, 1 ); //no widget in the middle
    g->addItem( new TQSpacerItem( 0, 0, TQSizePolicy::Fixed, TQSizePolicy::Expanding ) );

    g->addColSpacing(0, 1);
    g->addColSpacing(2, 1);
    g->addRowSpacing(2, 1);

    closeBtn = new TQToolButton( widget(), 0 );
    TQToolTip::add( closeBtn, i18n("Close") );
    connect( closeBtn, TQT_SIGNAL( clicked() ), this, ( TQT_SLOT( closeWindow() ) ) );
    closeBtn->setFixedSize( 13, 13);
    reset( -1U );

    TQHBoxLayout* hb = new TQHBoxLayout;
    g->addLayout( hb, 0, 1 );

    int fh = widget()->fontMetrics().lineSpacing()+2;

    titlebar = new TQSpacerItem(10, fh, TQSizePolicy::Expanding,
			       TQSizePolicy::Minimum );
    hb->addItem( titlebar );
    hb->addWidget( closeBtn );
}

StdToolClient::~StdToolClient()
{
}

void StdToolClient::resizeEvent( TQResizeEvent* )
{
//     TQRegion r = rect();
//     TQRect t = titlebar->geometry();
//     t.setTop( 0 );
//     r = r.subtract( TQRect(0, 0, width(), 1) );
//     r = r.subtract (TQRect( 0, 0, 1, t.height() ) );
//     r = r.subtract (TQRect( width()-1, 0, 1, t.height() ) );
//     setMask( r );
}

void StdToolClient::paintEvent( TQPaintEvent* )
{
    TQPainter p( widget() );
    TQRect t = titlebar->geometry();
    TQRect r = widget()->rect();
    qDrawWinPanel( &p, r, widget()->colorGroup() );
    r.setTop( t.bottom()+1 );
    qDrawWinPanel( &p, r, widget()->colorGroup() );
    p.fillRect( TQRect( TQPoint(t.topLeft() ), TQPoint( width() - t.left(), t.bottom() ) ),
		options()->color(KDecorationOptions::ColorTitleBar, isActive()));
    p.setPen( options()->color(KDecorationOptions::ColorTitleBar, isActive()).light() );
    t.setLeft( t.left() + 4 );
    t.setRight( t.right() - 2 );
    p.setPen(options()->color(KDecorationOptions::ColorFont, isActive()));
    p.setFont(options()->font(isActive(), true));
    p.drawText( t, AlignLeft|AlignVCenter|SingleLine, caption() );
}


void StdToolClient::mouseDoubleClickEvent( TQMouseEvent * e )
{
    if ( e->button() == Qt::LeftButton && titlebar->geometry().contains( e->pos() ) )
        titlebarDblClickOperation();
}

void StdToolClient::wheelEvent( TQWheelEvent * e )
{
    if (isSetShade() || TQRect( 0, 0, width(), titlebar->geometry().height() ).contains( e->pos() ) )
        titlebarMouseWheelOperation( e->delta());
}

void StdToolClient::captionChange()
{
    widget()->repaint( titlebar->geometry(), FALSE );
}

void StdToolClient::reset( unsigned long )
{
    TQImage img = close_pix->convertToImage();
    img = img.smoothScale( 12, 12 );
    TQPixmap pm;
    pm.convertFromImage( img );
    closeBtn->setPixmap( pm );
    widget()->setFont(options()->font(isActive(), true ));
}

bool StdToolClient::eventFilter( TQObject* o, TQEvent* e )
{
    if ( TQT_BASE_OBJECT(o) != TQT_BASE_OBJECT(widget()) )
	return false;

    switch ( e->type() ) {
    case TQEvent::Resize:
	resizeEvent( TQT_TQRESIZEEVENT( e ) );
	return true;

    case TQEvent::Paint:
	paintEvent( TQT_TQPAINTEVENT( e ) );
	return true;

    case TQEvent::MouseButtonDblClick:
	mouseDoubleClickEvent( TQT_TQMOUSEEVENT( e ) );
	return true;

    case TQEvent::MouseButtonPress:
	processMousePressEvent( TQT_TQMOUSEEVENT( e ) );
	return true;

    case TQEvent::Wheel:
	wheelEvent( TQT_TQWHEELEVENT( e ));
	return true;

    default:
	return false;
    }
}

TQSize StdToolClient::minimumSize() const
{
    return widget()->minimumSize().expandedTo( TQSize( 100, 50 ));
}

void StdToolClient::borders( int& left, int& right, int& top, int& bottom ) const
{
    left = right = bottom = 6;
    top = 6 + widget()->fontMetrics().lineSpacing();
}

void StdToolClient::resize( const TQSize& s )
{
    widget()->resize( s );
}

StdFactory::StdFactory()
{
    create_pixmaps();
}

StdFactory::~StdFactory()
{
    delete_pixmaps();
}

const int SUPPORTED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
    | NET::ToolbarMask | NET::MenuMask | NET::DialogMask | NET::OverrideMask | NET::TopMenuMask
    | NET::UtilityMask | NET::SplashMask;

KDecoration* StdFactory::createDecoration( KDecorationBridge* b )
{
    NET::WindowType type = windowType( SUPPORTED_WINDOW_TYPES_MASK, b );
    if( type == NET::Utility || type == NET::Menu || type == NET::Toolbar )
	return new StdToolClient( b, this );
    return new StdClient( b, this );
}

bool StdFactory::reset( unsigned long mask )
{
    bool needHardReset = false;

    // doesn't obey the Border size setting
    if( mask & ( SettingFont | SettingButtons ))
        needHardReset = true;

    if( mask & ( SettingFont | SettingColors )) {
        KDE1::delete_pixmaps();
        KDE1::create_pixmaps();
    }

    if( !needHardReset )
        resetDecorations( mask );
    return needHardReset;
}

bool StdFactory::supports( Ability ability )
{
    switch( ability )
    {
        case AbilityAnnounceButtons:
        case AbilityButtonMenu:
        case AbilityButtonOnAllDesktops:
        case AbilityButtonHelp:
        case AbilityButtonMinimize:
        case AbilityButtonMaximize:
        case AbilityButtonClose:
        case AbilityButtonSpacer:
            return true;
        default:
            return false;
    };
}


}

extern "C"
{
	KDE_EXPORT KDecorationFactory *create_factory()
	{
                return new KDE1::StdFactory();
	}
}

#include "kde1client.moc"