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
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
|
/*
*
* KDE2 Default KWin client
*
* Copyright (C) 1999, 2001 Daniel Duley <mosfet@kde.org>
* Matthias Ettrich <ettrich@kde.org>
* Karol Szwed <gallium@kde.org>
*
* Draws mini titlebars for tool windows.
* Many features are now customizable.
*/
#include "kdedefault.h"
#include <kconfig.h>
#include <kglobal.h>
#include <kpixmapeffect.h>
#include <kimageeffect.h>
#include <kdrawutil.h>
#include <klocale.h>
#include <tqlayout.h>
#include <tqdrawutil.h>
#include <tqbitmap.h>
#include <tqimage.h>
#include <tqtooltip.h>
#include <tqapplication.h>
#include <tqlabel.h>
#include <kdebug.h>
namespace Default
{
static const unsigned char iconify_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x78, 0x00, 0x78, 0x00,
0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char close_bits[] = {
0x00, 0x00, 0x84, 0x00, 0xce, 0x01, 0xfc, 0x00, 0x78, 0x00, 0x78, 0x00,
0xfc, 0x00, 0xce, 0x01, 0x84, 0x00, 0x00, 0x00};
static const unsigned char maximize_bits[] = {
0x00, 0x00, 0xfe, 0x01, 0xfe, 0x01, 0x86, 0x01, 0x86, 0x01, 0x86, 0x01,
0x86, 0x01, 0xfe, 0x01, 0xfe, 0x01, 0x00, 0x00};
static const unsigned char minmax_bits[] = {
0x7f, 0x00, 0x7f, 0x00, 0x63, 0x00, 0xfb, 0x03, 0xfb, 0x03, 0x1f, 0x03,
0x1f, 0x03, 0x18, 0x03, 0xf8, 0x03, 0xf8, 0x03};
static const unsigned char question_bits[] = {
0x00, 0x00, 0x78, 0x00, 0xcc, 0x00, 0xc0, 0x00, 0x60, 0x00, 0x30, 0x00,
0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00};
static const unsigned char above_on_bits[] = {
0x00, 0x00, 0xfe, 0x01, 0xfe, 0x01, 0x30, 0x00, 0xfc, 0x00, 0x78, 0x00,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static const unsigned char above_off_bits[] = {
0x30, 0x00, 0x78, 0x00, 0xfc, 0x00, 0x30, 0x00, 0xfe, 0x01, 0xfe, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static const unsigned char below_on_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x78, 0x00, 0xfc, 0x00,
0x30, 0x00, 0xfe, 0x01, 0xfe, 0x01, 0x00, 0x00 };
static const unsigned char below_off_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x01, 0xfe, 0x01,
0x30, 0x00, 0xfc, 0x00, 0x78, 0x00, 0x30, 0x00 };
static const unsigned char shade_on_bits[] = {
0x00, 0x00, 0xfe, 0x01, 0xfe, 0x01, 0xfe, 0x01, 0x02, 0x01, 0x02, 0x01,
0x02, 0x01, 0x02, 0x01, 0xfe, 0x01, 0x00, 0x00 };
static const unsigned char shade_off_bits[] = {
0x00, 0x00, 0xfe, 0x01, 0xfe, 0x01, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static const unsigned char pindown_white_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x1f, 0xa0, 0x03,
0xb0, 0x01, 0x30, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x20, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char pindown_gray_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c,
0x00, 0x0e, 0x00, 0x06, 0x00, 0x00, 0x80, 0x07, 0xc0, 0x03, 0xe0, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char pindown_dgray_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x10, 0x70, 0x20, 0x50, 0x20,
0x48, 0x30, 0xc8, 0x38, 0x08, 0x1f, 0x08, 0x18, 0x10, 0x1c, 0x10, 0x0e,
0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char pindown_tqmask_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x1f, 0xf0, 0x3f, 0xf0, 0x3f,
0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf0, 0x1f, 0xf0, 0x0f,
0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char pinup_white_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x11,
0x3f, 0x15, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char pinup_gray_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x0a, 0xbf, 0x0a, 0x80, 0x15, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char pinup_dgray_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x20, 0x40, 0x31, 0x40, 0x2e,
0x40, 0x20, 0x40, 0x20, 0x7f, 0x2a, 0x40, 0x3f, 0xc0, 0x31, 0xc0, 0x20,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char pinup_tqmask_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x20, 0xc0, 0x31, 0xc0, 0x3f,
0xff, 0x3f, 0xff, 0x3f, 0xff, 0x3f, 0xc0, 0x3f, 0xc0, 0x31, 0xc0, 0x20,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
// ===========================================================================
static TQPixmap* titlePix;
static KPixmap* titleBuffer;
static KPixmap* aUpperGradient;
static KPixmap* iUpperGradient;
static KPixmap* pinDownPix;
static KPixmap* pinUpPix;
static KPixmap* ipinDownPix;
static KPixmap* ipinUpPix;
static KPixmap* rightBtnUpPix[2];
static KPixmap* rightBtnDownPix[2];
static KPixmap* irightBtnUpPix[2];
static KPixmap* irightBtnDownPix[2];
static KPixmap* leftBtnUpPix[2];
static KPixmap* leftBtnDownPix[2];
static KPixmap* ileftBtnUpPix[2];
static KPixmap* ileftBtnDownPix[2];
static KDEDefaultHandler* clientHandler;
static int toolTitleHeight;
static int normalTitleHeight;
static int borderWidth;
static int grabBorderWidth;
static bool KDEDefault_initialized = false;
static bool useGradients;
static bool showGrabBar;
static bool showTitleBarStipple;
// ===========================================================================
KDEDefaultHandler::KDEDefaultHandler()
{
clientHandler = this;
readConfig( false );
createPixmaps();
KDEDefault_initialized = true;
}
KDEDefaultHandler::~KDEDefaultHandler()
{
KDEDefault_initialized = false;
freePixmaps();
clientHandler = NULL;
}
KDecoration* KDEDefaultHandler::createDecoration( KDecorationBridge* b )
{
return new KDEDefaultClient( b, this );
}
bool KDEDefaultHandler::reset( unsigned long changed )
{
KDEDefault_initialized = false;
changed |= readConfig( true );
if( changed & SettingColors )
{ // pixmaps need to be recreated
freePixmaps();
createPixmaps();
}
KDEDefault_initialized = true;
// SettingButtons is handled by KCommonDecoration
bool need_recreate = ( changed & ( SettingDecoration | SettingFont | SettingBorder )) != 0;
if( need_recreate ) // something else than colors changed
return true;
resetDecorations( changed );
return false;
}
unsigned long KDEDefaultHandler::readConfig( bool update )
{
unsigned long changed = 0;
KConfig* conf = KGlobal::config();
conf->setGroup("KDEDefault");
bool new_showGrabBar = conf->readBoolEntry("ShowGrabBar", true);
bool new_showTitleBarStipple = conf->readBoolEntry("ShowTitleBarStipple", true);
bool new_useGradients = conf->readBoolEntry("UseGradients", true);
int new_titleHeight = TQFontMetrics(options()->font(true)).height();
int new_toolTitleHeight = TQFontMetrics(options()->font(true, true)).height()-2;
int new_borderWidth;
switch(options()->preferredBorderSize(this)) {
case BorderLarge:
new_borderWidth = 8;
break;
case BorderVeryLarge:
new_borderWidth = 12;
break;
case BorderHuge:
new_borderWidth = 18;
break;
case BorderVeryHuge:
new_borderWidth = 27;
break;
case BorderOversized:
new_borderWidth = 40;
break;
case BorderTiny:
case BorderNormal:
default:
new_borderWidth = 4;
}
if (new_titleHeight < 16) new_titleHeight = 16;
if (new_titleHeight < new_borderWidth) new_titleHeight = new_borderWidth;
if (new_toolTitleHeight < 12) new_toolTitleHeight = 12;
if (new_toolTitleHeight < new_borderWidth) new_toolTitleHeight = new_borderWidth;
if( update )
{
if( new_showGrabBar != showGrabBar
|| new_titleHeight != normalTitleHeight
|| new_toolTitleHeight != toolTitleHeight
|| new_borderWidth != borderWidth )
changed |= SettingDecoration; // need recreating the decoration
if( new_showTitleBarStipple != showTitleBarStipple
|| new_useGradients != useGradients
|| new_titleHeight != normalTitleHeight
|| new_toolTitleHeight != toolTitleHeight )
changed |= SettingColors; // just recreate the pixmaps and tqrepaint
}
showGrabBar = new_showGrabBar;
showTitleBarStipple = new_showTitleBarStipple;
useGradients = new_useGradients;
normalTitleHeight = new_titleHeight;
toolTitleHeight = new_toolTitleHeight;
borderWidth = new_borderWidth;
grabBorderWidth = (borderWidth > 15) ? borderWidth + 15 : 2*borderWidth;
return changed;
}
// This paints the button pixmaps upon loading the style.
void KDEDefaultHandler::createPixmaps()
{
bool highcolor = useGradients && (TQPixmap::defaultDepth() > 8);
// Make the titlebar stipple optional
if (showTitleBarStipple)
{
TQPainter p;
TQPainter tqmaskPainter;
int i, x, y;
titlePix = new TQPixmap(132, normalTitleHeight+2);
TQBitmap tqmask(132, normalTitleHeight+2);
tqmask.fill(Qt::color0);
p.begin(titlePix);
tqmaskPainter.begin(&tqmask);
tqmaskPainter.setPen(Qt::color1);
for(i=0, y=2; i < 9; ++i, y+=4)
for(x=1; x <= 132; x+=3)
{
p.setPen(options()->color(ColorTitleBar, true).light(150));
p.drawPoint(x, y);
tqmaskPainter.drawPoint(x, y);
p.setPen(options()->color(ColorTitleBar, true).dark(150));
p.drawPoint(x+1, y+1);
tqmaskPainter.drawPoint(x+1, y+1);
}
tqmaskPainter.end();
p.end();
titlePix->setMask(tqmask);
} else
titlePix = NULL;
TQColor activeTitleColor1(options()->color(ColorTitleBar, true));
TQColor activeTitleColor2(options()->color(ColorTitleBlend, true));
TQColor inactiveTitleColor1(options()->color(ColorTitleBar, false));
TQColor inactiveTitleColor2(options()->color(ColorTitleBlend, false));
// Create titlebar gradient images if required
aUpperGradient = NULL;
iUpperGradient = NULL;
if(highcolor)
{
// Create the titlebar gradients
if (activeTitleColor1 != activeTitleColor2)
{
aUpperGradient = new KPixmap;
aUpperGradient->resize(128, normalTitleHeight+2);
KPixmapEffect::gradient(*aUpperGradient,
activeTitleColor1,
activeTitleColor2,
KPixmapEffect::VerticalGradient);
}
if (inactiveTitleColor1 != inactiveTitleColor2)
{
iUpperGradient = new KPixmap;
iUpperGradient->resize(128, normalTitleHeight+2);
KPixmapEffect::gradient(*iUpperGradient,
inactiveTitleColor1,
inactiveTitleColor2,
KPixmapEffect::VerticalGradient);
}
}
// Set the sticky pin pixmaps;
TQColorGroup g;
TQPainter p;
// Active pins
g = options()->tqcolorGroup( ColorButtonBg, true );
pinUpPix = new KPixmap();
pinUpPix->resize(16, 16);
p.begin( pinUpPix );
kColorBitmaps( &p, g, 0, 0, 16, 16, true, pinup_white_bits,
pinup_gray_bits, NULL, NULL, pinup_dgray_bits, NULL );
p.end();
pinUpPix->setMask( TQBitmap(16, 16, pinup_tqmask_bits, true) );
pinDownPix = new KPixmap();
pinDownPix->resize(16, 16);
p.begin( pinDownPix );
kColorBitmaps( &p, g, 0, 0, 16, 16, true, pindown_white_bits,
pindown_gray_bits, NULL, NULL, pindown_dgray_bits, NULL );
p.end();
pinDownPix->setMask( TQBitmap(16, 16, pindown_tqmask_bits, true) );
// Inactive pins
g = options()->tqcolorGroup( ColorButtonBg, false );
ipinUpPix = new KPixmap();
ipinUpPix->resize(16, 16);
p.begin( ipinUpPix );
kColorBitmaps( &p, g, 0, 0, 16, 16, true, pinup_white_bits,
pinup_gray_bits, NULL, NULL, pinup_dgray_bits, NULL );
p.end();
ipinUpPix->setMask( TQBitmap(16, 16, pinup_tqmask_bits, true) );
ipinDownPix = new KPixmap();
ipinDownPix->resize(16, 16);
p.begin( ipinDownPix );
kColorBitmaps( &p, g, 0, 0, 16, 16, true, pindown_white_bits,
pindown_gray_bits, NULL, NULL, pindown_dgray_bits, NULL );
p.end();
ipinDownPix->setMask( TQBitmap(16, 16, pindown_tqmask_bits, true) );
// Create a title buffer for flicker-free painting
titleBuffer = new KPixmap();
// Cache all possible button states
leftBtnUpPix[true] = new KPixmap();
leftBtnUpPix[true]->resize(normalTitleHeight, normalTitleHeight);
leftBtnDownPix[true] = new KPixmap();
leftBtnDownPix[true]->resize(normalTitleHeight, normalTitleHeight);
ileftBtnUpPix[true] = new KPixmap();
ileftBtnUpPix[true]->resize(normalTitleHeight, normalTitleHeight);
ileftBtnDownPix[true] = new KPixmap();
ileftBtnDownPix[true]->resize(normalTitleHeight, normalTitleHeight);
rightBtnUpPix[true] = new KPixmap();
rightBtnUpPix[true]->resize(normalTitleHeight, normalTitleHeight);
rightBtnDownPix[true] = new KPixmap();
rightBtnDownPix[true]->resize(normalTitleHeight, normalTitleHeight);
irightBtnUpPix[true] = new KPixmap();
irightBtnUpPix[true]->resize(normalTitleHeight, normalTitleHeight);
irightBtnDownPix[true] = new KPixmap();
irightBtnDownPix[true]->resize(normalTitleHeight, normalTitleHeight);
leftBtnUpPix[false] = new KPixmap();
leftBtnUpPix[false]->resize(toolTitleHeight, normalTitleHeight);
leftBtnDownPix[false] = new KPixmap();
leftBtnDownPix[false]->resize(toolTitleHeight, normalTitleHeight);
ileftBtnUpPix[false] = new KPixmap();
ileftBtnUpPix[false]->resize(normalTitleHeight, normalTitleHeight);
ileftBtnDownPix[false] = new KPixmap();
ileftBtnDownPix[false]->resize(normalTitleHeight, normalTitleHeight);
rightBtnUpPix[false] = new KPixmap();
rightBtnUpPix[false]->resize(toolTitleHeight, toolTitleHeight);
rightBtnDownPix[false] = new KPixmap();
rightBtnDownPix[false]->resize(toolTitleHeight, toolTitleHeight);
irightBtnUpPix[false] = new KPixmap();
irightBtnUpPix[false]->resize(toolTitleHeight, toolTitleHeight);
irightBtnDownPix[false] = new KPixmap();
irightBtnDownPix[false]->resize(toolTitleHeight, toolTitleHeight);
// Draw the button state pixmaps
g = options()->tqcolorGroup( ColorTitleBar, true );
drawButtonBackground( leftBtnUpPix[true], g, false );
drawButtonBackground( leftBtnDownPix[true], g, true );
drawButtonBackground( leftBtnUpPix[false], g, false );
drawButtonBackground( leftBtnDownPix[false], g, true );
g = options()->tqcolorGroup( ColorButtonBg, true );
drawButtonBackground( rightBtnUpPix[true], g, false );
drawButtonBackground( rightBtnDownPix[true], g, true );
drawButtonBackground( rightBtnUpPix[false], g, false );
drawButtonBackground( rightBtnDownPix[false], g, true );
g = options()->tqcolorGroup( ColorTitleBar, false );
drawButtonBackground( ileftBtnUpPix[true], g, false );
drawButtonBackground( ileftBtnDownPix[true], g, true );
drawButtonBackground( ileftBtnUpPix[false], g, false );
drawButtonBackground( ileftBtnDownPix[false], g, true );
g = options()->tqcolorGroup( ColorButtonBg, false );
drawButtonBackground( irightBtnUpPix[true], g, false );
drawButtonBackground( irightBtnDownPix[true], g, true );
drawButtonBackground( irightBtnUpPix[false], g, false );
drawButtonBackground( irightBtnDownPix[false], g, true );
}
void KDEDefaultHandler::freePixmaps()
{
// Free button pixmaps
if (rightBtnUpPix[true])
delete rightBtnUpPix[true];
if(rightBtnDownPix[true])
delete rightBtnDownPix[true];
if (irightBtnUpPix[true])
delete irightBtnUpPix[true];
if (irightBtnDownPix[true])
delete irightBtnDownPix[true];
if (leftBtnUpPix[true])
delete leftBtnUpPix[true];
if(leftBtnDownPix[true])
delete leftBtnDownPix[true];
if (ileftBtnUpPix[true])
delete ileftBtnUpPix[true];
if (ileftBtnDownPix[true])
delete ileftBtnDownPix[true];
if (rightBtnUpPix[false])
delete rightBtnUpPix[false];
if(rightBtnDownPix[false])
delete rightBtnDownPix[false];
if (irightBtnUpPix[false])
delete irightBtnUpPix[false];
if (irightBtnDownPix[false])
delete irightBtnDownPix[false];
if (leftBtnUpPix[false])
delete leftBtnUpPix[false];
if(leftBtnDownPix[false])
delete leftBtnDownPix[false];
if (ileftBtnUpPix[false])
delete ileftBtnUpPix[false];
if (ileftBtnDownPix[false])
delete ileftBtnDownPix[false];
// Title images
if (titleBuffer)
delete titleBuffer;
if (titlePix)
delete titlePix;
if (aUpperGradient)
delete aUpperGradient;
if (iUpperGradient)
delete iUpperGradient;
// Sticky pin images
if (pinUpPix)
delete pinUpPix;
if (ipinUpPix)
delete ipinUpPix;
if (pinDownPix)
delete pinDownPix;
if (ipinDownPix)
delete ipinDownPix;
}
void KDEDefaultHandler::drawButtonBackground(KPixmap *pix,
const TQColorGroup &g, bool sunken)
{
TQPainter p;
int w = pix->width();
int h = pix->height();
int x2 = w-1;
int y2 = h-1;
bool highcolor = useGradients && (TQPixmap::defaultDepth() > 8);
TQColor c = g.background();
// Fill the background with a gradient if possible
if (highcolor)
KPixmapEffect::gradient(*pix, c.light(130), c.dark(130),
KPixmapEffect::VerticalGradient);
else
pix->fill(c);
p.begin(pix);
// outer frame
p.setPen(g.mid());
p.drawLine(0, 0, x2, 0);
p.drawLine(0, 0, 0, y2);
p.setPen(g.light());
p.drawLine(x2, 0, x2, y2);
p.drawLine(0, x2, y2, x2);
p.setPen(g.dark());
p.drawRect(1, 1, w-2, h-2);
p.setPen(sunken ? g.mid() : g.light());
p.drawLine(2, 2, x2-2, 2);
p.drawLine(2, 2, 2, y2-2);
p.setPen(sunken ? g.light() : g.mid());
p.drawLine(x2-2, 2, x2-2, y2-2);
p.drawLine(2, x2-2, y2-2, x2-2);
}
TQValueList< KDEDefaultHandler::BorderSize > KDEDefaultHandler::borderSizes() const
{ // the list must be sorted
return TQValueList< BorderSize >() << BorderNormal << BorderLarge <<
BorderVeryLarge << BorderHuge << BorderVeryHuge << BorderOversized;
}
bool KDEDefaultHandler::supports( Ability ability )
{
switch( ability )
{
case AbilityAnnounceButtons:
case AbilityButtonMenu:
case AbilityButtonOnAllDesktops:
case AbilityButtonSpacer:
case AbilityButtonHelp:
case AbilityButtonMinimize:
case AbilityButtonMaximize:
case AbilityButtonClose:
case AbilityButtonAboveOthers:
case AbilityButtonBelowOthers:
case AbilityButtonShade:
return true;
default:
return false;
};
}
// ===========================================================================
KDEDefaultButton::KDEDefaultButton(ButtonType type, KDEDefaultClient *parent, const char *name)
: KCommonDecorationButton(type, parent, name)
{
setBackgroundMode( TQWidget::NoBackground );
isMouseOver = false;
deco = NULL;
large = !decoration()->isToolWindow();
}
KDEDefaultButton::~KDEDefaultButton()
{
if (deco)
delete deco;
}
void KDEDefaultButton::reset(unsigned long changed)
{
if (changed&DecorationReset || changed&ManualReset || changed&SizeChange || changed&StateChange) {
switch (type() ) {
case CloseButton:
setBitmap(close_bits);
break;
case HelpButton:
setBitmap(question_bits);
break;
case MinButton:
setBitmap(iconify_bits);
break;
case MaxButton:
setBitmap( isOn() ? minmax_bits : maximize_bits );
break;
case OnAllDesktopsButton:
setBitmap(0);
break;
case ShadeButton:
setBitmap( isOn() ? shade_on_bits : shade_off_bits );
break;
case AboveButton:
setBitmap( isOn() ? above_on_bits : above_off_bits );
break;
case BelowButton:
setBitmap( isOn() ? below_on_bits : below_off_bits );
break;
default:
setBitmap(0);
break;
}
this->update();
}
}
void KDEDefaultButton::setBitmap(const unsigned char *bitmap)
{
delete deco;
deco = 0;
if (bitmap) {
deco = new TQBitmap(10, 10, bitmap, true);
deco->setMask( *deco );
}
}
void KDEDefaultButton::drawButton(TQPainter *p)
{
if (!KDEDefault_initialized)
return;
const bool active = decoration()->isActive();
if (deco) {
// Fill the button background with an appropriate button image
KPixmap btnbg;
if (isLeft() ) {
if (isDown())
btnbg = active ?
*leftBtnDownPix[large] : *ileftBtnDownPix[large];
else
btnbg = active ?
*leftBtnUpPix[large] : *ileftBtnUpPix[large];
} else {
if (isDown())
btnbg = active ?
*rightBtnDownPix[large] : *irightBtnDownPix[large];
else
btnbg = active ?
*rightBtnUpPix[large] : *irightBtnUpPix[large];
}
p->drawPixmap( 0, 0, btnbg );
} else if ( isLeft() ) {
// Fill the button background with an appropriate color/gradient
// This is for sticky and menu buttons
KPixmap* grad = active ? aUpperGradient : iUpperGradient;
if (!grad) {
TQColor c = KDecoration::options()->color(KDecoration::ColorTitleBar, active);
p->fillRect(0, 0, width(), height(), c );
} else
p->drawPixmap( 0, 0, *grad, 0,1, width(), height() );
} else {
// Draw a plain background for menus or sticky buttons on RHS
TQColor c = KDecoration::options()->color(KDecoration::ColorFrame, active);
p->fillRect(0, 0, width(), height(), c);
}
// If we have a decoration bitmap, then draw that
// otherwise we paint a menu button (with mini icon), or a sticky button.
if( deco ) {
// Select the appropriate button decoration color
bool darkDeco = tqGray( KDecoration::options()->color(
isLeft() ? KDecoration::ColorTitleBar : KDecoration::ColorButtonBg,
active).rgb() ) > 127;
if (isMouseOver)
p->setPen( darkDeco ? Qt::darkGray : Qt::lightGray );
else
p->setPen( darkDeco ? Qt::black : Qt::white );
int xOff = (width()-10)/2;
int yOff = (height()-10)/2;
p->drawPixmap(isDown() ? xOff+1: xOff, isDown() ? yOff+1 : yOff, *deco);
} else {
KPixmap btnpix;
if (type()==OnAllDesktopsButton) {
if (active)
btnpix = isOn() ? *pinDownPix : *pinUpPix;
else
btnpix = isOn() ? *ipinDownPix : *ipinUpPix;
} else
btnpix = decoration()->icon().pixmap( TQIconSet::Small, TQIconSet::Normal );
// Intensify the image if required
if (isMouseOver) {
btnpix = KPixmapEffect::intensity(btnpix, 0.8);
}
// Smooth scale the pixmap for small titlebars
// This is slow, but we assume this isn't done too often
if ( width() < 16 ) {
btnpix.convertFromImage(btnpix.convertToImage().smoothScale(12, 12));
p->drawPixmap( 0, 0, btnpix );
}
else
p->drawPixmap( width()/2-8, height()/2-8, btnpix );
}
}
void KDEDefaultButton::enterEvent(TQEvent *e)
{
isMouseOver=true;
tqrepaint(false);
TQButton::enterEvent(e);
}
void KDEDefaultButton::leaveEvent(TQEvent *e)
{
isMouseOver=false;
tqrepaint(false);
TQButton::leaveEvent(e);
}
// ===========================================================================
KDEDefaultClient::KDEDefaultClient( KDecorationBridge* b, KDecorationFactory* f )
: KCommonDecoration( b, f )/*,
m_closing(false)*/
{
}
TQString KDEDefaultClient::visibleName() const
{
return i18n("KDE2");
}
TQString KDEDefaultClient::defaultButtonsLeft() const
{
return "MS";
}
TQString KDEDefaultClient::defaultButtonsRight() const
{
return "HIAX";
}
bool KDEDefaultClient::decorationBehaviour(DecorationBehaviour behaviour) const
{
switch (behaviour) {
case DB_MenuClose:
return true;
case DB_WindowMask:
return true;
case DB_ButtonHide:
return true;
default:
return KCommonDecoration::decorationBehaviour(behaviour);
}
}
int KDEDefaultClient::tqlayoutMetric(LayoutMetric lm, bool respectWindowState, const KCommonDecorationButton *btn) const
{
switch (lm) {
case LM_BorderLeft:
case LM_BorderRight:
return borderWidth;
case LM_BorderBottom:
return mustDrawHandle() ? grabBorderWidth : borderWidth;
case LM_TitleEdgeLeft:
case LM_TitleEdgeRight:
return borderWidth;
case LM_TitleEdgeTop:
return 3;
case LM_TitleEdgeBottom:
return 1;
case LM_TitleBorderLeft:
case LM_TitleBorderRight:
return 1;
case LM_TitleHeight:
return titleHeight;
case LM_ButtonWidth:
case LM_ButtonHeight:
return titleHeight;
case LM_ButtonSpacing:
return 0;
case LM_ExplicitButtonSpacer:
if ( !isToolWindow() )
return borderWidth/2;
// fall though
default:
return KCommonDecoration::tqlayoutMetric(lm, respectWindowState, btn);
}
}
KCommonDecorationButton *KDEDefaultClient::createButton(ButtonType type)
{
switch (type) {
case MenuButton:
return new KDEDefaultButton(MenuButton, this, "menu");
case OnAllDesktopsButton:
return new KDEDefaultButton(OnAllDesktopsButton, this, "on_all_desktops");
case HelpButton:
return new KDEDefaultButton(HelpButton, this, "help");
case MinButton:
return new KDEDefaultButton(MinButton, this, "minimize");
case MaxButton:
return new KDEDefaultButton(MaxButton, this, "maximize");
case CloseButton:
return new KDEDefaultButton(CloseButton, this, "close");
case AboveButton:
return new KDEDefaultButton(AboveButton, this, "above");
case BelowButton:
return new KDEDefaultButton(BelowButton, this, "below");
case ShadeButton:
return new KDEDefaultButton(ShadeButton, this, "shade");
default:
return 0;
}
}
void KDEDefaultClient::init()
{
// Finally, toolWindows look small
if ( isToolWindow() ) {
titleHeight = toolTitleHeight;
}
else {
titleHeight = normalTitleHeight;
}
KCommonDecoration::init();
}
void KDEDefaultClient::reset( unsigned long changed)
{
widget()->tqrepaint();
KCommonDecoration::reset(changed);
}
bool KDEDefaultClient::mustDrawHandle() const
{
bool drawSmallBorders = !options()->moveResizeMaximizedWindows();
if (drawSmallBorders && (maximizeMode() & MaximizeVertical)) {
return false;
} else {
return showGrabBar && isResizable();
}
}
void KDEDefaultClient::paintEvent( TQPaintEvent* )
{
if (!KDEDefault_initialized)
return;
TQColorGroup g;
int offset;
KPixmap* upperGradient = isActive() ? aUpperGradient : iUpperGradient;
TQPainter p(widget());
// Obtain widget bounds.
TQRect r(widget()->rect());
int x = r.x();
int y = r.y();
int x2 = r.width() - 1;
int y2 = r.height() - 1;
int w = r.width();
int h = r.height();
// Determine where to place the extended left titlebar
int leftFrameStart = (h > 42) ? y+titleHeight+26: y+titleHeight;
// Determine where to make the titlebar color transition
r = titleRect();
int rightOffset = r.x()+r.width()+1;
// Create a disposable pixmap buffer for the titlebar
// very early before drawing begins so there is no lag
// during painting pixels.
titleBuffer->resize( rightOffset-3, titleHeight+1 );
// Draw an outer black frame
p.setPen(Qt::black);
p.drawRect(x,y,w,h);
// Draw part of the frame that is the titlebar color
g = options()->tqcolorGroup(ColorTitleBar, isActive());
p.setPen(g.light());
p.drawLine(x+1, y+1, rightOffset-1, y+1);
p.drawLine(x+1, y+1, x+1, leftFrameStart+borderWidth-4);
// Draw titlebar colour separator line
p.setPen(g.dark());
p.drawLine(rightOffset-1, y+1, rightOffset-1, titleHeight+2);
p.fillRect(x+2, y+titleHeight+3,
borderWidth-4, leftFrameStart+borderWidth-y-titleHeight-8,
options()->color(ColorTitleBar, isActive() ));
// Finish drawing the titlebar extension
p.setPen(Qt::black);
p.drawLine(x+1, leftFrameStart+borderWidth-4, x+borderWidth-2, leftFrameStart-1);
p.setPen(g.mid());
p.drawLine(x+borderWidth-2, y+titleHeight+3, x+borderWidth-2, leftFrameStart-2);
// Fill out the border edges
g = options()->tqcolorGroup(ColorFrame, isActive());
p.setPen(g.light());
p.drawLine(rightOffset, y+1, x2-1, y+1);
p.drawLine(x+1, leftFrameStart+borderWidth-3, x+1, y2-1);
p.setPen(g.dark());
p.drawLine(x2-1, y+1, x2-1, y2-1);
p.drawLine(x+1, y2-1, x2-1, y2-1);
p.setPen(options()->color(ColorFrame, isActive()));
TQPointArray a;
TQBrush brush( options()->color(ColorFrame, isActive()), Qt::SolidPattern );
p.setBrush( brush ); // use solid, yellow brush
a.setPoints( 4, x+2, leftFrameStart+borderWidth-4,
x+borderWidth-2, leftFrameStart,
x+borderWidth-2, y2-2,
x+2, y2-2);
p.drawPolygon( a );
p.fillRect(x2-borderWidth+2, y+titleHeight+3,
borderWidth-3, y2-y-titleHeight-4,
options()->color(ColorFrame, isActive() ));
// Draw the bottom handle if required
if (mustDrawHandle())
{
if(w > 50)
{
qDrawShadePanel(&p, x+1, y2-grabBorderWidth+2, 2*borderWidth+12, grabBorderWidth-2,
g, false, 1, &g.brush(TQColorGroup::Mid));
qDrawShadePanel(&p, x+2*borderWidth+13, y2-grabBorderWidth+2, w-4*borderWidth-26, grabBorderWidth-2,
g, false, 1, isActive() ?
&g.brush(TQColorGroup::Background) :
&g.brush(TQColorGroup::Mid));
qDrawShadePanel(&p, x2-2*borderWidth-12, y2-grabBorderWidth+2, 2*borderWidth+12, grabBorderWidth-2,
g, false, 1, &g.brush(TQColorGroup::Mid));
} else
qDrawShadePanel(&p, x+1, y2-grabBorderWidth+2, w-2, grabBorderWidth-2,
g, false, 1, isActive() ?
&g.brush(TQColorGroup::Background) :
&g.brush(TQColorGroup::Mid));
offset = grabBorderWidth;
} else
{
p.fillRect(x+2, y2-borderWidth+2, w-4, borderWidth-3,
options()->color(ColorFrame, isActive() ));
offset = borderWidth;
}
// Draw a frame around the wrapped widget.
p.setPen( g.dark() );
p.drawRect( x+borderWidth-1, y+titleHeight+3, w-2*borderWidth+2, h-titleHeight-offset-2 );
// Draw the title bar.
r = titleRect();
// Obtain titlebar blend colours
TQColor c1 = options()->color(ColorTitleBar, isActive() );
TQColor c2 = options()->color(ColorFrame, isActive() );
// Fill with frame color behind RHS buttons
p.fillRect( rightOffset, y+2, x2-rightOffset-1, titleHeight+1, c2);
TQPainter p2( titleBuffer, this );
// Draw the titlebar gradient
if (upperGradient)
p2.drawTiledPixmap(0, 0, rightOffset-3, titleHeight+1, *upperGradient);
else
p2.fillRect(0, 0, rightOffset-3, titleHeight+1, c1);
// Draw the title text on the pixmap, and with a smaller font
// for toolwindows than the default.
TQFont fnt = options()->font(true);
if ( isToolWindow() )
fnt.setPointSize( fnt.pointSize()-2 ); // Shrink font by 2pt
p2.setFont( fnt );
// Draw the titlebar stipple if active and available
if (isActive() && titlePix)
{
TQFontMetrics fm(fnt);
int captionWidth = fm.width(caption());
if (caption().isRightToLeft())
p2.drawTiledPixmap( r.x(), 0, r.width()-captionWidth-4,
titleHeight+1, *titlePix );
else
p2.drawTiledPixmap( r.x()+captionWidth+3, 0, r.width()-captionWidth-4,
titleHeight+1, *titlePix );
}
p2.setPen( options()->color(ColorFont, isActive()) );
p2.drawText(r.x(), 1, r.width()-1, r.height(),
(caption().isRightToLeft() ? AlignRight : AlignLeft) | AlignVCenter,
caption() );
bitBlt( widget(), 2, 2, titleBuffer );
p2.end();
// Ensure a shaded window has no unpainted areas
// Is this still needed?
#if 1
p.setPen(c2);
p.drawLine(x+borderWidth, y+titleHeight+4, x2-borderWidth, y+titleHeight+4);
#endif
}
TQRegion KDEDefaultClient::cornerShape(WindowCorner corner)
{
switch (corner) {
case WC_TopLeft:
return TQRect(0, 0, 1, 1);
case WC_TopRight:
return TQRect(width()-1, 0, 1, 1);
case WC_BottomLeft:
return TQRect(0, height()-1, 1, 1);
case WC_BottomRight:
return TQRect(width()-1, height()-1, 1, 1);
default:
return TQRegion();
}
}
} // namespace
// Extended KWin plugin interface
extern "C" KDE_EXPORT KDecorationFactory* create_factory()
{
return new Default::KDEDefaultHandler();
}
// vim: ts=4
// kate: space-indent off; tab-width 4;
|