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
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
|
/*
* Copyright © 2004 Joe English
*
* "clam" theme; inspired by the XFCE family of Gnome themes.
*/
#include "tkInt.h"
#include "ttkTheme.h"
/*
* Under windows, the Tk-provided XDrawLine and XDrawArc have an
* off-by-one error in the end point. This is especially apparent with this
* theme. Defining this macro as true handles this case.
*/
#if defined(_WIN32) && !defined(WIN32_XDRAWLINE_HACK)
#define WIN32_XDRAWLINE_HACK 1
#else
#define WIN32_XDRAWLINE_HACK 0
#endif
#define STR(x) StR(x)
#define StR(x) #x
#define SCROLLBAR_THICKNESS 14
#define FRAME_COLOR "#dcdad5"
#define LIGHT_COLOR "#ffffff"
#define DARK_COLOR "#cfcdc8"
#define DARKER_COLOR "#bab5ab"
#define DARKEST_COLOR "#9e9a91"
/*------------------------------------------------------------------------
* +++ Utilities.
*/
static GC Ttk_GCForColor(Tk_Window tkwin, Tcl_Obj* colorObj, Drawable d)
{
GC gc = Tk_GCForColor(Tk_GetColorFromObj(tkwin, colorObj), d);
#ifdef MAC_OSX_TK
/*
* Workaround for Tk bug under Aqua where the default line width is 0.
*/
Display *display = Tk_Display(tkwin);
unsigned long mask = 0ul;
XGCValues gcValues;
gcValues.line_width = 1;
mask = GCLineWidth;
XChangeGC(display, gc, mask, &gcValues);
#endif
return gc;
}
static void DrawSmoothBorder(
Tk_Window tkwin, Drawable d, Ttk_Box b,
Tcl_Obj *outerColorObj, Tcl_Obj *upperColorObj, Tcl_Obj *lowerColorObj)
{
Display *display = Tk_Display(tkwin);
int x1 = b.x, x2 = b.x + b.width - 1;
int y1 = b.y, y2 = b.y + b.height - 1;
const int w = WIN32_XDRAWLINE_HACK;
GC gc;
if ( outerColorObj
&& (gc=Ttk_GCForColor(tkwin,outerColorObj,d)))
{
XDrawLine(display,d,gc, x1+1,y1, x2-1+w,y1); /* N */
XDrawLine(display,d,gc, x1+1,y2, x2-1+w,y2); /* S */
XDrawLine(display,d,gc, x1,y1+1, x1,y2-1+w); /* W */
XDrawLine(display,d,gc, x2,y1+1, x2,y2-1+w); /* E */
}
if ( upperColorObj
&& (gc=Ttk_GCForColor(tkwin,upperColorObj,d)))
{
XDrawLine(display,d,gc, x1+1,y1+1, x2-1+w,y1+1); /* N */
XDrawLine(display,d,gc, x1+1,y1+1, x1+1,y2-1); /* W */
}
if ( lowerColorObj
&& (gc=Ttk_GCForColor(tkwin,lowerColorObj,d)))
{
XDrawLine(display,d,gc, x2-1,y2-1, x1+1-w,y2-1); /* S */
XDrawLine(display,d,gc, x2-1,y2-1, x2-1,y1+1-w); /* E */
}
}
static GC BackgroundGC(Tk_Window tkwin, Tcl_Obj *backgroundObj)
{
Tk_3DBorder bd = Tk_Get3DBorderFromObj(tkwin, backgroundObj);
return Tk_3DBorderGC(tkwin, bd, TK_3D_FLAT_GC);
}
/*------------------------------------------------------------------------
* +++ Border element.
*/
typedef struct {
Tcl_Obj *borderColorObj;
Tcl_Obj *lightColorObj;
Tcl_Obj *darkColorObj;
Tcl_Obj *reliefObj;
Tcl_Obj *borderWidthObj; /* See <<NOTE-BORDERWIDTH>> */
} BorderElement;
static const Ttk_ElementOptionSpec BorderElementOptions[] = {
{ "-bordercolor", TK_OPTION_COLOR,
offsetof(BorderElement,borderColorObj), DARKEST_COLOR },
{ "-lightcolor", TK_OPTION_COLOR,
offsetof(BorderElement,lightColorObj), LIGHT_COLOR },
{ "-darkcolor", TK_OPTION_COLOR,
offsetof(BorderElement,darkColorObj), DARK_COLOR },
{ "-relief", TK_OPTION_RELIEF,
offsetof(BorderElement,reliefObj), "flat" },
{ "-borderwidth", TK_OPTION_PIXELS,
offsetof(BorderElement,borderWidthObj), "2" },
{ NULL, TK_OPTION_BOOLEAN, 0, NULL }
};
/*
* <<NOTE-BORDERWIDTH>>: -borderwidth is only partially supported:
* in this theme, borders are always exactly 2 pixels thick.
* With -borderwidth 0, border is not drawn at all;
* otherwise a 2-pixel border is used. For -borderwidth > 2,
* the excess is used as padding.
*/
static void BorderElementSize(
TCL_UNUSED(void *), /* clientData */
void *elementRecord,
Tk_Window tkwin,
TCL_UNUSED(int *), /* widthPtr */
TCL_UNUSED(int *), /* heightPtr */
Ttk_Padding *paddingPtr)
{
BorderElement *border = (BorderElement*)elementRecord;
int borderWidth = 2;
Tk_GetPixelsFromObj(NULL, tkwin, border->borderWidthObj, &borderWidth);
if (borderWidth == 1) ++borderWidth;
*paddingPtr = Ttk_UniformPadding((short)borderWidth);
}
static void BorderElementDraw(
TCL_UNUSED(void *), /* clientData */
void *elementRecord,
Tk_Window tkwin,
Drawable d,
Ttk_Box b,
TCL_UNUSED(Ttk_State))
{
BorderElement *border = (BorderElement *)elementRecord;
int relief = TK_RELIEF_FLAT;
int borderWidth = 2;
Tcl_Obj *outer = 0, *upper = 0, *lower = 0;
Tk_GetReliefFromObj(NULL, border->reliefObj, &relief);
Tk_GetPixelsFromObj(NULL, tkwin, border->borderWidthObj, &borderWidth);
if (borderWidth == 0) return;
switch (relief) {
case TK_RELIEF_GROOVE :
case TK_RELIEF_RIDGE :
case TK_RELIEF_RAISED :
outer = border->borderColorObj;
upper = border->lightColorObj;
lower = border->darkColorObj;
break;
case TK_RELIEF_SUNKEN :
outer = border->borderColorObj;
upper = border->darkColorObj;
lower = border->lightColorObj;
break;
case TK_RELIEF_FLAT :
outer = upper = lower = 0;
break;
case TK_RELIEF_SOLID :
outer = upper = lower = border->borderColorObj;
break;
}
DrawSmoothBorder(tkwin, d, b, outer, upper, lower);
}
static const Ttk_ElementSpec BorderElementSpec = {
TK_STYLE_VERSION_2,
sizeof(BorderElement),
BorderElementOptions,
BorderElementSize,
BorderElementDraw
};
/*------------------------------------------------------------------------
* +++ Field element.
*/
typedef struct {
Tcl_Obj *borderColorObj;
Tcl_Obj *lightColorObj;
Tcl_Obj *backgroundObj;
} FieldElement;
static const Ttk_ElementOptionSpec FieldElementOptions[] = {
{ "-bordercolor", TK_OPTION_COLOR,
offsetof(FieldElement,borderColorObj), DARKEST_COLOR },
{ "-lightcolor", TK_OPTION_COLOR,
offsetof(FieldElement,lightColorObj), LIGHT_COLOR },
{ "-fieldbackground", TK_OPTION_BORDER,
offsetof(FieldElement,backgroundObj), "white" },
{ NULL, TK_OPTION_BOOLEAN, 0, NULL }
};
static void FieldElementSize(
TCL_UNUSED(void *), /* clientData */
TCL_UNUSED(void *), /* elementRecord */
TCL_UNUSED(Tk_Window),
TCL_UNUSED(int *), /* widthPtr */
TCL_UNUSED(int *), /* heightPtr */
Ttk_Padding *paddingPtr)
{
*paddingPtr = Ttk_UniformPadding(2);
}
static void FieldElementDraw(
TCL_UNUSED(void *), /* clientData */
void *elementRecord,
Tk_Window tkwin,
Drawable d,
Ttk_Box b,
TCL_UNUSED(Ttk_State))
{
FieldElement *field = (FieldElement *)elementRecord;
Tk_3DBorder bg = Tk_Get3DBorderFromObj(tkwin, field->backgroundObj);
Ttk_Box f = Ttk_PadBox(b, Ttk_UniformPadding(2));
Tcl_Obj *outer = field->borderColorObj,
*inner = field->lightColorObj;
DrawSmoothBorder(tkwin, d, b, outer, inner, inner);
Tk_Fill3DRectangle(
tkwin, d, bg, f.x, f.y, f.width, f.height, 0, TK_RELIEF_SUNKEN);
}
static const Ttk_ElementSpec FieldElementSpec = {
TK_STYLE_VERSION_2,
sizeof(FieldElement),
FieldElementOptions,
FieldElementSize,
FieldElementDraw
};
/*
* Modified field element for comboboxes:
* Right edge is expanded to overlap the dropdown button.
*/
static void ComboboxFieldElementDraw(
void *clientData, void *elementRecord, Tk_Window tkwin,
Drawable d, Ttk_Box b, Ttk_State state)
{
FieldElement *field = (FieldElement *)elementRecord;
GC gc = Ttk_GCForColor(tkwin,field->borderColorObj,d);
++b.width;
FieldElementDraw(clientData, elementRecord, tkwin, d, b, state);
XDrawLine(Tk_Display(tkwin), d, gc,
b.x + b.width - 1, b.y,
b.x + b.width - 1, b.y + b.height - 1 + WIN32_XDRAWLINE_HACK);
}
static const Ttk_ElementSpec ComboboxFieldElementSpec = {
TK_STYLE_VERSION_2,
sizeof(FieldElement),
FieldElementOptions,
FieldElementSize,
ComboboxFieldElementDraw
};
/*------------------------------------------------------------------------
* +++ Indicator elements for check and radio buttons.
*/
/*
* Indicator image descriptor:
*/
typedef struct {
int width; /* unscaled width */
int height; /* unscaled height */
const char *const offDataPtr;
const char *const onDataPtr;
} IndicatorSpec;
static const char checkbtnOffData[] = "\
<svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
<path d='m0 0v16h1v-15h15v-1z' fill='#9e9a91'/>\n\
<path d='m15 1v14h-14v1h15v-15z' fill='#cfcdc8'/>\n\
<rect x='1' y='1' width='14' height='14' fill='#ffffff'/>\n\
</svg>";
static const char checkbtnOnData[] = "\
<svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
<path d='m0 0v16h1v-15h15v-1z' fill='#9e9a91'/>\n\
<path d='m15 1v14h-14v1h15v-15z' fill='#cfcdc8'/>\n\
<rect x='1' y='1' width='14' height='14' fill='#ffffff'/>\n\
<path d='m5 5 6 6m0-6-6 6' fill='none' stroke='#000000' stroke-linecap='round' stroke-width='2'/>\n\
</svg>";
static const IndicatorSpec checkbutton_spec = {
16, 16,
checkbtnOffData,
checkbtnOnData
};
static const char radiobtnOffData[] = "\
<svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
<defs>\n\
<linearGradient id='linearGradient' x1='5' y1='5' x2='11' y2='11' gradientUnits='userSpaceOnUse'>\n\
<stop stop-color='#9e9a91' offset='0'/>\n\
<stop stop-color='#cfcdc8' offset='1'/>\n\
</linearGradient>\n\
</defs>\n\
<circle cx='8' cy='8' r='8' fill='url(#linearGradient)'/>\n\
<circle cx='8' cy='8' r='7' fill='#ffffff'/>\n\
</svg>";
static const char radiobtnOnData[] = "\
<svg width='16' height='16' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n\
<defs>\n\
<linearGradient id='linearGradient' x1='5' y1='5' x2='11' y2='11' gradientUnits='userSpaceOnUse'>\n\
<stop stop-color='#9e9a91' offset='0'/>\n\
<stop stop-color='#cfcdc8' offset='1'/>\n\
</linearGradient>\n\
</defs>\n\
<circle cx='8' cy='8' r='8' fill='url(#linearGradient)'/>\n\
<circle cx='8' cy='8' r='7' fill='#ffffff'/>\n\
<circle cx='8' cy='8' r='4' fill='#000000'/>\n\
</svg>";
static const IndicatorSpec radiobutton_spec = {
16, 16,
radiobtnOffData,
radiobtnOnData
};
typedef struct {
Tcl_Obj *marginObj;
Tcl_Obj *backgroundObj;
Tcl_Obj *foregroundObj;
Tcl_Obj *upperColorObj;
Tcl_Obj *lowerColorObj;
} IndicatorElement;
static const Ttk_ElementOptionSpec IndicatorElementOptions[] = {
{ "-indicatormargin", TK_OPTION_STRING,
offsetof(IndicatorElement,marginObj), "1" },
{ "-indicatorbackground", TK_OPTION_COLOR,
offsetof(IndicatorElement,backgroundObj), "white" },
{ "-indicatorforeground", TK_OPTION_COLOR,
offsetof(IndicatorElement,foregroundObj), "black" },
{ "-upperbordercolor", TK_OPTION_COLOR,
offsetof(IndicatorElement,upperColorObj), DARKEST_COLOR },
{ "-lowerbordercolor", TK_OPTION_COLOR,
offsetof(IndicatorElement,lowerColorObj), DARK_COLOR },
{ NULL, TK_OPTION_BOOLEAN, 0, NULL }
};
static void IndicatorElementSize(
void *clientData, void *elementRecord, Tk_Window tkwin,
int *widthPtr, int *heightPtr,
TCL_UNUSED(Ttk_Padding *))
{
const IndicatorSpec *spec = (const IndicatorSpec *)clientData;
IndicatorElement *indicator = (IndicatorElement *)elementRecord;
Ttk_Padding margins;
double scalingLevel = TkScalingLevel(tkwin);
Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &margins);
*widthPtr = spec->width * scalingLevel + Ttk_PaddingWidth(margins);
*heightPtr = spec->height * scalingLevel + Ttk_PaddingHeight(margins);
}
static void ColorToStr(
const XColor *colorPtr, char *colorStr) /* in the format "RRGGBB" */
{
snprintf(colorStr, 7, "%02x%02x%02x",
colorPtr->red >> 8, colorPtr->green >> 8, colorPtr->blue >> 8);
}
static void ImageChanged( /* to be passed to Tk_GetImage() */
TCL_UNUSED(void *),
TCL_UNUSED(int),
TCL_UNUSED(int),
TCL_UNUSED(int),
TCL_UNUSED(int),
TCL_UNUSED(int),
TCL_UNUSED(int))
{
}
static void IndicatorElementDraw(
void *clientData, void *elementRecord, Tk_Window tkwin,
Drawable d, Ttk_Box b, Ttk_State state)
{
IndicatorElement *indicator = (IndicatorElement *)elementRecord;
Ttk_Padding padding;
const IndicatorSpec *spec = (const IndicatorSpec *)clientData;
double scalingLevel = TkScalingLevel(tkwin);
int width = spec->width * scalingLevel;
int height = spec->height * scalingLevel;
char upperBdColorStr[7], lowerBdColorStr[7], bgColorStr[7], fgColorStr[7];
unsigned int selected = (state & TTK_STATE_SELECTED);
Tcl_Interp *interp = Tk_Interp(tkwin);
char imgName[60];
Tk_Image img;
const char *svgDataPtr;
size_t svgDataLen;
char *svgDataCopy;
char *upperBdColorPtr, *lowerBdColorPtr, *bgColorPtr, *fgColorPtr;
const char *cmdFmt;
size_t scriptSize;
char *script;
int code;
Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &padding);
b = Ttk_PadBox(b, padding);
/*
* Sanity check
*/
if ( b.x < 0
|| b.y < 0
|| Tk_Width(tkwin) < b.x + width
|| Tk_Height(tkwin) < b.y + height)
{
/* Oops! Not enough room to display the image.
* Don't draw anything.
*/
return;
}
/*
* Construct the color strings upperBdColorStr, lowerBdColorStr,
* bgColorStr, and fgColorStr
*/
ColorToStr(Tk_GetColorFromObj(tkwin, indicator->upperColorObj),
upperBdColorStr);
ColorToStr(Tk_GetColorFromObj(tkwin, indicator->lowerColorObj),
lowerBdColorStr);
ColorToStr(Tk_GetColorFromObj(tkwin, indicator->backgroundObj),
bgColorStr);
ColorToStr(Tk_GetColorFromObj(tkwin, indicator->foregroundObj),
fgColorStr);
/*
* Check whether there is an SVG image of this size for the indicator's
* type (0 = checkbtn, 1 = radiobtn) and these color strings
*/
snprintf(imgName, sizeof(imgName),
"::tk::icons::indicator_clam%d_%d_%s_%s_%s_%s",
width, spec->offDataPtr == radiobtnOffData,
upperBdColorStr, lowerBdColorStr, bgColorStr,
selected ? fgColorStr : "XXXXXX");
img = Tk_GetImage(interp, tkwin, imgName, ImageChanged, NULL);
if (img == NULL) {
/*
* Determine the SVG data to use for the photo image
*/
svgDataPtr = (selected ? spec->onDataPtr : spec->offDataPtr);
/*
* Copy the string pointed to by svgDataPtr to
* a newly allocated memory area svgDataCopy
*/
svgDataLen = strlen(svgDataPtr);
svgDataCopy = (char *)attemptckalloc(svgDataLen + 1);
if (svgDataCopy == NULL) {
return;
}
memcpy(svgDataCopy, svgDataPtr, svgDataLen);
svgDataCopy[svgDataLen] = '\0';
/*
* Update the colors within svgDataCopy
*/
upperBdColorPtr = strstr(svgDataCopy, "9e9a91");
lowerBdColorPtr = strstr(svgDataCopy, "cfcdc8");
bgColorPtr = strstr(svgDataCopy, "ffffff");
fgColorPtr = strstr(svgDataCopy, "000000");
assert(upperBdColorPtr);
assert(lowerBdColorPtr);
assert(bgColorPtr);
memcpy(upperBdColorPtr, upperBdColorStr, 6);
memcpy(lowerBdColorPtr, lowerBdColorStr, 6);
memcpy(bgColorPtr, bgColorStr, 6);
if (fgColorPtr != NULL) {
memcpy(fgColorPtr, fgColorStr, 6);
}
/*
* Create an SVG photo image from svgDataCopy
*/
cmdFmt = "image create photo %s -format $::tk::svgFmt -data {%s}";
scriptSize = strlen(cmdFmt) + strlen(imgName) + svgDataLen;
script = (char *)attemptckalloc(scriptSize);
if (script == NULL) {
ckfree(svgDataCopy);
return;
}
snprintf(script, scriptSize, cmdFmt, imgName, svgDataCopy);
ckfree(svgDataCopy);
code = Tcl_EvalEx(interp, script, -1, TCL_EVAL_GLOBAL);
ckfree(script);
if (code != TCL_OK) {
Tcl_BackgroundException(interp, code);
return;
}
img = Tk_GetImage(interp, tkwin, imgName, ImageChanged, NULL);
}
/*
* Display the image
*/
Tk_RedrawImage(img, 0, 0, width, height, d, b.x, b.y);
Tk_FreeImage(img);
}
static const Ttk_ElementSpec IndicatorElementSpec = {
TK_STYLE_VERSION_2,
sizeof(IndicatorElement),
IndicatorElementOptions,
IndicatorElementSize,
IndicatorElementDraw
};
/*------------------------------------------------------------------------
* +++ Grips.
*
* TODO: factor this with ThumbElementDraw
*/
typedef struct {
Tcl_Obj *lightColorObj;
Tcl_Obj *borderColorObj;
Tcl_Obj *gripCountObj;
} GripElement;
static const Ttk_ElementOptionSpec GripElementOptions[] = {
{ "-lightcolor", TK_OPTION_COLOR,
offsetof(GripElement,lightColorObj), LIGHT_COLOR },
{ "-bordercolor", TK_OPTION_COLOR,
offsetof(GripElement,borderColorObj), DARKEST_COLOR },
{ "-gripcount", TK_OPTION_PIXELS,
offsetof(GripElement,gripCountObj), "5" },
{ NULL, TK_OPTION_BOOLEAN, 0, NULL }
};
static void GripElementSize(
void *clientData, void *elementRecord, Tk_Window tkwin,
int *widthPtr, int *heightPtr,
TCL_UNUSED(Ttk_Padding *))
{
Ttk_Orient orient = (Ttk_Orient)PTR2INT(clientData);
GripElement *grip = (GripElement *)elementRecord;
int gripSize = 0;
Tk_GetPixelsFromObj(NULL, tkwin, grip->gripCountObj, &gripSize);
gripSize *= 2;
if (orient == TTK_ORIENT_HORIZONTAL) {
*widthPtr = gripSize;
} else {
*heightPtr = gripSize;
}
}
static void GripElementDraw(
void *clientData, void *elementRecord, Tk_Window tkwin,
Drawable d, Ttk_Box b,
TCL_UNUSED(Ttk_State))
{
const int w = WIN32_XDRAWLINE_HACK;
Ttk_Orient orient = (Ttk_Orient)PTR2INT(clientData);
GripElement *grip = (GripElement *)elementRecord;
GC lightGC = Ttk_GCForColor(tkwin,grip->lightColorObj,d);
GC darkGC = Ttk_GCForColor(tkwin,grip->borderColorObj,d);
int gripPad = 1, gripSize = 0;
int i;
Tk_GetPixelsFromObj(NULL, tkwin, grip->gripCountObj, &gripSize);
gripSize *= 2;
if (orient == TTK_ORIENT_HORIZONTAL) {
int x = b.x + (b.width - gripSize) / 2;
int y1 = b.y + gripPad, y2 = b.y + b.height - gripPad - 1 + w;
for (i=0; i<gripSize; ++i) {
XDrawLine(Tk_Display(tkwin), d, (i&1)?lightGC:darkGC, x,y1, x,y2);
++x;
}
} else {
int y = b.y + (b.height - gripSize) / 2;
int x1 = b.x + gripPad, x2 = b.x + b.width - gripPad - 1 + w;
for (i=0; i<gripSize; ++i) {
XDrawLine(Tk_Display(tkwin), d, (i&1)?lightGC:darkGC, x1,y, x2,y);
++y;
}
}
}
static const Ttk_ElementSpec GripElementSpec = {
TK_STYLE_VERSION_2,
sizeof(GripElement),
GripElementOptions,
GripElementSize,
GripElementDraw
};
/*------------------------------------------------------------------------
* +++ Scrollbar elements: trough, arrows, thumb.
*
* Notice that the trough element has 0 internal padding;
* that way the thumb and arrow borders overlap the trough.
*/
typedef struct { /* Common element record for scrollbar elements */
Tcl_Obj *orientObj;
Tcl_Obj *backgroundObj;
Tcl_Obj *borderColorObj;
Tcl_Obj *troughColorObj;
Tcl_Obj *lightColorObj;
Tcl_Obj *darkColorObj;
Tcl_Obj *arrowColorObj;
Tcl_Obj *arrowSizeObj;
Tcl_Obj *gripCountObj;
Tcl_Obj *sliderlengthObj;
} ScrollbarElement;
static const Ttk_ElementOptionSpec ScrollbarElementOptions[] = {
{ "-orient", TK_OPTION_ANY,
offsetof(ScrollbarElement, orientObj), "horizontal" },
{ "-background", TK_OPTION_BORDER,
offsetof(ScrollbarElement,backgroundObj), FRAME_COLOR },
{ "-bordercolor", TK_OPTION_COLOR,
offsetof(ScrollbarElement,borderColorObj), DARKEST_COLOR },
{ "-troughcolor", TK_OPTION_COLOR,
offsetof(ScrollbarElement,troughColorObj), DARKER_COLOR },
{ "-lightcolor", TK_OPTION_COLOR,
offsetof(ScrollbarElement,lightColorObj), LIGHT_COLOR },
{ "-darkcolor", TK_OPTION_COLOR,
offsetof(ScrollbarElement,darkColorObj), DARK_COLOR },
{ "-arrowcolor", TK_OPTION_COLOR,
offsetof(ScrollbarElement,arrowColorObj), "#000000" },
{ "-arrowsize", TK_OPTION_PIXELS,
offsetof(ScrollbarElement,arrowSizeObj), STR(SCROLLBAR_THICKNESS) },
{ "-gripcount", TK_OPTION_PIXELS,
offsetof(ScrollbarElement,gripCountObj), "5" },
{ "-sliderlength", TK_OPTION_PIXELS,
offsetof(ScrollbarElement,sliderlengthObj), "30" },
{ NULL, TK_OPTION_BOOLEAN, 0, NULL }
};
static void TroughElementDraw(
TCL_UNUSED(void *), /* clientData */
void *elementRecord,
Tk_Window tkwin,
Drawable d,
Ttk_Box b,
TCL_UNUSED(Ttk_State))
{
ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
GC gcb = Ttk_GCForColor(tkwin,sb->borderColorObj,d);
GC gct = Ttk_GCForColor(tkwin,sb->troughColorObj,d);
XFillRectangle(Tk_Display(tkwin), d, gct, b.x, b.y, b.width-1, b.height-1);
XDrawRectangle(Tk_Display(tkwin), d, gcb, b.x, b.y, b.width-1, b.height-1);
}
static const Ttk_ElementSpec TroughElementSpec = {
TK_STYLE_VERSION_2,
sizeof(ScrollbarElement),
ScrollbarElementOptions,
TtkNullElementSize,
TroughElementDraw
};
static void ThumbElementSize(
TCL_UNUSED(void *), /* clientData */
void *elementRecord,
Tk_Window tkwin,
int *widthPtr,
int *heightPtr,
TCL_UNUSED(Ttk_Padding *))
{
ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
int size = SCROLLBAR_THICKNESS;
Tk_GetPixelsFromObj(NULL, tkwin, sb->arrowSizeObj, &size);
*widthPtr = *heightPtr = size;
}
static void ThumbElementDraw(
TCL_UNUSED(void *), /* clientData */
void *elementRecord,
Tk_Window tkwin,
Drawable d,
Ttk_Box b,
TCL_UNUSED(Ttk_State))
{
ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
int gripSize = 0;
Ttk_Orient orient = TTK_ORIENT_HORIZONTAL;
GC lightGC, darkGC;
int x1, y1, x2, y2, dx, dy, i;
const int w = WIN32_XDRAWLINE_HACK;
DrawSmoothBorder(tkwin, d, b,
sb->borderColorObj, sb->lightColorObj, sb->darkColorObj);
XFillRectangle(
Tk_Display(tkwin), d, BackgroundGC(tkwin, sb->backgroundObj),
b.x+2, b.y+2, b.width-4, b.height-4);
/*
* Draw grip:
*/
TtkGetOrientFromObj(NULL, sb->orientObj, &orient);
Tk_GetPixelsFromObj(NULL, tkwin, sb->gripCountObj, &gripSize);
gripSize *= 2;
lightGC = Ttk_GCForColor(tkwin,sb->lightColorObj,d);
darkGC = Ttk_GCForColor(tkwin,sb->borderColorObj,d);
if (orient == TTK_ORIENT_HORIZONTAL) {
dx = 1; dy = 0;
x1 = x2 = b.x + (b.width - gripSize) / 2;
y1 = b.y + 2;
y2 = b.y + b.height - 3 + w;
} else {
dx = 0; dy = 1;
y1 = y2 = b.y + (b.height - gripSize) / 2;
x1 = b.x + 2;
x2 = b.x + b.width - 3 + w;
}
for (i=0; i<gripSize; ++i) {
XDrawLine(Tk_Display(tkwin), d, (i&1)?lightGC:darkGC, x1,y1, x2,y2);
x1 += dx; x2 += dx; y1 += dy; y2 += dy;
}
}
static const Ttk_ElementSpec ThumbElementSpec = {
TK_STYLE_VERSION_2,
sizeof(ScrollbarElement),
ScrollbarElementOptions,
ThumbElementSize,
ThumbElementDraw
};
/*------------------------------------------------------------------------
* +++ Slider element.
*/
static void SliderElementSize(
TCL_UNUSED(void *), /* clientData */
void *elementRecord,
Tk_Window tkwin,
int *widthPtr,
int *heightPtr,
TCL_UNUSED(Ttk_Padding *))
{
ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
int length, thickness;
Ttk_Orient orient;
length = thickness = SCROLLBAR_THICKNESS;
TtkGetOrientFromObj(NULL, sb->orientObj, &orient);
Tk_GetPixelsFromObj(NULL, tkwin, sb->arrowSizeObj, &thickness);
Tk_GetPixelsFromObj(NULL, tkwin, sb->sliderlengthObj, &length);
if (orient == TTK_ORIENT_VERTICAL) {
*heightPtr = length;
*widthPtr = thickness;
} else {
*heightPtr = thickness;
*widthPtr = length;
}
}
static const Ttk_ElementSpec SliderElementSpec = {
TK_STYLE_VERSION_2,
sizeof(ScrollbarElement),
ScrollbarElementOptions,
SliderElementSize,
ThumbElementDraw
};
/*------------------------------------------------------------------------
* +++ Progress bar element
*/
static void PbarElementSize(
void *clientData, void *elementRecord, Tk_Window tkwin,
int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
SliderElementSize(clientData, elementRecord, tkwin,
widthPtr, heightPtr, paddingPtr);
*paddingPtr = Ttk_UniformPadding(2);
*widthPtr += 4;
*heightPtr += 4;
}
static void PbarElementDraw(
TCL_UNUSED(void *), /* clientData */
void *elementRecord,
Tk_Window tkwin,
Drawable d,
Ttk_Box b,
TCL_UNUSED(Ttk_State))
{
ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
b = Ttk_PadBox(b, Ttk_UniformPadding(2));
if (b.width > 4 && b.height > 4) {
DrawSmoothBorder(tkwin, d, b,
sb->borderColorObj, sb->lightColorObj, sb->darkColorObj);
XFillRectangle(Tk_Display(tkwin), d,
BackgroundGC(tkwin, sb->backgroundObj),
b.x+2, b.y+2, b.width-4, b.height-4);
}
}
static const Ttk_ElementSpec PbarElementSpec = {
TK_STYLE_VERSION_2,
sizeof(ScrollbarElement),
ScrollbarElementOptions,
PbarElementSize,
PbarElementDraw
};
/*------------------------------------------------------------------------
* +++ Scrollbar arrows.
*/
static void ArrowElementSize(
void *clientData, void *elementRecord, Tk_Window tkwin,
int *widthPtr, int *heightPtr,
TCL_UNUSED(Ttk_Padding *))
{
ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
ArrowDirection direction = (ArrowDirection)PTR2INT(clientData);
double scalingLevel = TkScalingLevel(tkwin);
Ttk_Padding padding = Ttk_UniformPadding(round(3 * scalingLevel));
int size = SCROLLBAR_THICKNESS;
Tk_GetPixelsFromObj(NULL, tkwin, sb->arrowSizeObj, &size);
size -= Ttk_PaddingWidth(padding);
TtkArrowSize(size/2, direction, widthPtr, heightPtr);
*widthPtr += Ttk_PaddingWidth(padding);
*heightPtr += Ttk_PaddingHeight(padding);
if (*widthPtr < *heightPtr) {
*widthPtr = *heightPtr;
} else {
*heightPtr = *widthPtr;
}
}
static void ArrowElementDraw(
void *clientData, void *elementRecord, Tk_Window tkwin,
Drawable d, Ttk_Box b,
TCL_UNUSED(Ttk_State))
{
ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
ArrowDirection direction = (ArrowDirection)PTR2INT(clientData);
double scalingLevel = TkScalingLevel(tkwin);
Ttk_Padding padding = Ttk_UniformPadding(round(3 * scalingLevel));
int cx, cy;
GC gc = Ttk_GCForColor(tkwin, sb->arrowColorObj, d);
DrawSmoothBorder(tkwin, d, b,
sb->borderColorObj, sb->lightColorObj, sb->darkColorObj);
XFillRectangle(
Tk_Display(tkwin), d, BackgroundGC(tkwin, sb->backgroundObj),
b.x+2, b.y+2, b.width-4, b.height-4);
b = Ttk_PadBox(b, padding);
switch (direction) {
case ARROW_UP:
case ARROW_DOWN:
TtkArrowSize(b.width/2, direction, &cx, &cy);
if ((b.height - cy) % 2 == 1) {
++cy;
}
break;
case ARROW_LEFT:
case ARROW_RIGHT:
TtkArrowSize(b.height/2, direction, &cx, &cy);
if ((b.width - cx) % 2 == 1) {
++cx;
}
break;
}
b = Ttk_AnchorBox(b, cx, cy, TK_ANCHOR_CENTER);
TtkFillArrow(Tk_Display(tkwin), d, gc, b, direction);
}
static const Ttk_ElementSpec ArrowElementSpec = {
TK_STYLE_VERSION_2,
sizeof(ScrollbarElement),
ScrollbarElementOptions,
ArrowElementSize,
ArrowElementDraw
};
/*
* Modified arrow element for spinboxes:
* The width and height are different.
*/
static void SpinboxArrowElementSize(
void *clientData, void *elementRecord, Tk_Window tkwin,
int *widthPtr, int *heightPtr,
TCL_UNUSED(Ttk_Padding *))
{
ScrollbarElement *sb = (ScrollbarElement *)elementRecord;
ArrowDirection direction = (ArrowDirection)PTR2INT(clientData);
double scalingLevel = TkScalingLevel(tkwin);
Ttk_Padding padding = Ttk_UniformPadding(round(3 * scalingLevel));
int size = 10;
Tk_GetPixelsFromObj(NULL, tkwin, sb->arrowSizeObj, &size);
size -= Ttk_PaddingWidth(padding);
TtkArrowSize(size/2, direction, widthPtr, heightPtr);
*widthPtr += Ttk_PaddingWidth(padding);
*heightPtr += Ttk_PaddingHeight(padding);
}
static const Ttk_ElementSpec SpinboxArrowElementSpec = {
TK_STYLE_VERSION_2,
sizeof(ScrollbarElement),
ScrollbarElementOptions,
SpinboxArrowElementSize,
ArrowElementDraw
};
/*------------------------------------------------------------------------
* +++ Notebook elements.
*
* Note: Tabs, except for the rightmost, overlap the neighbor to
* their right by one pixel.
*/
typedef struct {
Tcl_Obj *backgroundObj;
Tcl_Obj *borderColorObj;
Tcl_Obj *lightColorObj;
Tcl_Obj *darkColorObj;
} NotebookElement;
static const Ttk_ElementOptionSpec NotebookElementOptions[] = {
{ "-background", TK_OPTION_BORDER,
offsetof(NotebookElement,backgroundObj), FRAME_COLOR },
{ "-bordercolor", TK_OPTION_COLOR,
offsetof(NotebookElement,borderColorObj), DARKEST_COLOR },
{ "-lightcolor", TK_OPTION_COLOR,
offsetof(NotebookElement,lightColorObj), LIGHT_COLOR },
{ "-darkcolor", TK_OPTION_COLOR,
offsetof(NotebookElement,darkColorObj), DARK_COLOR },
{ NULL, TK_OPTION_BOOLEAN, 0, NULL }
};
static void TabElementSize(
TCL_UNUSED(void *), /* clientData */
TCL_UNUSED(void *), /* elementRecord */
Tk_Window tkwin,
TCL_UNUSED(int *), /* widthPtr */
TCL_UNUSED(int *), /* heightPtr */
Ttk_Padding *paddingPtr)
{
Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S;
TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;
int borderWidth = 2;
if (mainInfoPtr != NULL) {
nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit;
}
*paddingPtr = Ttk_UniformPadding((short)borderWidth);
switch (nbTabsStickBit) {
default:
case TTK_STICK_S:
paddingPtr->bottom = 0;
break;
case TTK_STICK_N:
paddingPtr->top = 0;
break;
case TTK_STICK_E:
paddingPtr->right = 0;
break;
case TTK_STICK_W:
paddingPtr->left = 0;
break;
}
}
static void TabElementDraw(
TCL_UNUSED(void *), /* clientData */
void *elementRecord,
Tk_Window tkwin,
Drawable d,
Ttk_Box b,
Ttk_State state)
{
Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S;
TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;
int borderWidth = 2, delta = 0;
NotebookElement *tab = (NotebookElement *)elementRecord;
Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, tab->backgroundObj);
Display *display = Tk_Display(tkwin);
int x1, y1, x2, y2;
GC gc;
const int w = WIN32_XDRAWLINE_HACK;
if (mainInfoPtr != NULL) {
nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit;
}
if (state & TTK_STATE_SELECTED) {
delta = borderWidth;
}
switch (nbTabsStickBit) {
default:
case TTK_STICK_S:
if (state & TTK_STATE_USER2) { /* rightmost tab */
--b.width;
}
Tk_Fill3DRectangle(tkwin, d, border,
b.x+2, b.y+2, b.width-1, b.height-2+delta,
borderWidth, TK_RELIEF_FLAT);
x1 = b.x; y1 = b.y; /* top left */
x2 = b.x + b.width; y2 = b.y + b.height-1; /* bottom right */
gc = Ttk_GCForColor(tkwin, tab->borderColorObj, d);
XDrawLine(display, d, gc, x1, y1+1, x1, y2+1+w);
XDrawLine(display, d, gc, x2, y1+1, x2, y2+1+w);
XDrawLine(display, d, gc, x1+1, y1, x2-1+w, y1);
gc = Ttk_GCForColor(tkwin, tab->lightColorObj, d);
XDrawLine(display, d, gc, x1+1, y1+1, x1+1, y2+delta+w);
XDrawLine(display, d, gc, x1+1, y1+1, x2-1+w, y1+1);
break;
case TTK_STICK_N:
if (state & TTK_STATE_USER2) { /* rightmost tab */
--b.width;
}
Tk_Fill3DRectangle(tkwin, d, border,
b.x+2, b.y-delta, b.width-1, b.height-2+delta,
borderWidth, TK_RELIEF_FLAT);
x1 = b.x; y1 = b.y + b.height-1; /* bottom left */
x2 = b.x + b.width; y2 = b.y; /* top right */
gc = Ttk_GCForColor(tkwin, tab->borderColorObj, d);
XDrawLine(display, d, gc, x1, y1-1, x1, y2-1-w);
XDrawLine(display, d, gc, x2, y1-1, x2, y2-1-w);
XDrawLine(display, d, gc, x1+1, y1, x2-1+w, y1);
gc = Ttk_GCForColor(tkwin, tab->lightColorObj, d);
XDrawLine(display, d, gc, x1+1, y1-1, x1+1, y2-delta-w);
XDrawLine(display, d, gc, x1+1, y1-1, x2-1+w, y1-1);
break;
case TTK_STICK_E:
if (state & TTK_STATE_USER2) { /* bottommost tab */
--b.height;
}
Tk_Fill3DRectangle(tkwin, d, border,
b.x+2, b.y+2, b.width-2+delta, b.height-1,
borderWidth, TK_RELIEF_FLAT);
x1 = b.x; y1 = b.y; /* top left */
x2 = b.x + b.width-1; y2 = b.y + b.height; /* bottom right */
gc = Ttk_GCForColor(tkwin, tab->borderColorObj, d);
XDrawLine(display, d, gc, x1, y1+1, x1, y2-1+w);
XDrawLine(display, d, gc, x1+1, y1, x2+1+w, y1);
XDrawLine(display, d, gc, x1+1, y2, x2+1+w, y2);
gc = Ttk_GCForColor(tkwin, tab->lightColorObj, d);
XDrawLine(display, d, gc, x1+1, y1+1, x1+1, y2-1+w);
XDrawLine(display, d, gc, x1+1, y1+1, x2+delta+w, y1+1);
break;
case TTK_STICK_W:
if (state & TTK_STATE_USER2) { /* bottommost tab */
--b.height;
}
Tk_Fill3DRectangle(tkwin, d, border,
b.x-delta, b.y+2, b.width-2+delta, b.height-1,
borderWidth, TK_RELIEF_FLAT);
x1 = b.x + b.width-1; y1 = b.y; /* top right */
x2 = b.x; y2 = b.y + b.height; /* bottom left */
gc = Ttk_GCForColor(tkwin, tab->borderColorObj, d);
XDrawLine(display, d, gc, x1, y1+1, x1, y2-1+w);
XDrawLine(display, d, gc, x1-1, y1, x2-1-w, y1);
XDrawLine(display, d, gc, x1-1, y2, x2-1-w, y2);
gc = Ttk_GCForColor(tkwin, tab->lightColorObj, d);
XDrawLine(display, d, gc, x1-1, y1+1, x1-1, y2-1+w);
XDrawLine(display, d, gc, x1-1, y1+1, x2-delta-w, y1+1);
break;
}
}
static const Ttk_ElementSpec TabElementSpec =
{
TK_STYLE_VERSION_2,
sizeof(NotebookElement),
NotebookElementOptions,
TabElementSize,
TabElementDraw
};
static void ClientElementSize(
TCL_UNUSED(void *), /* clientData */
TCL_UNUSED(void *), /* elementRecord */
TCL_UNUSED(Tk_Window),
TCL_UNUSED(int *), /* widthPtr */
TCL_UNUSED(int *), /* heightPtr */
Ttk_Padding *paddingPtr)
{
int borderWidth = 2;
*paddingPtr = Ttk_UniformPadding((short)borderWidth);
}
static void ClientElementDraw(
TCL_UNUSED(void *), /* clientData */
void *elementRecord,
Tk_Window tkwin,
Drawable d,
Ttk_Box b,
TCL_UNUSED(Ttk_State))
{
NotebookElement *ce = (NotebookElement *)elementRecord;
Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, ce->backgroundObj);
int borderWidth = 2;
Tk_Fill3DRectangle(tkwin, d, border,
b.x, b.y, b.width, b.height, borderWidth,TK_RELIEF_FLAT);
DrawSmoothBorder(tkwin, d, b,
ce->borderColorObj, ce->lightColorObj, ce->darkColorObj);
}
static const Ttk_ElementSpec ClientElementSpec =
{
TK_STYLE_VERSION_2,
sizeof(NotebookElement),
NotebookElementOptions,
ClientElementSize,
ClientElementDraw
};
/*------------------------------------------------------------------------
* +++ Modified widget layouts.
*/
TTK_BEGIN_LAYOUT_TABLE(LayoutTable)
TTK_LAYOUT("TCombobox",
TTK_NODE("Combobox.downarrow", TTK_PACK_RIGHT|TTK_FILL_Y)
TTK_GROUP("Combobox.field", TTK_FILL_BOTH,
TTK_GROUP("Combobox.padding", TTK_FILL_BOTH,
TTK_NODE("Combobox.textarea", TTK_FILL_BOTH))))
TTK_LAYOUT("Horizontal.Sash",
TTK_GROUP("Sash.hsash", TTK_FILL_BOTH,
TTK_NODE("Sash.hgrip", TTK_FILL_BOTH)))
TTK_LAYOUT("Vertical.Sash",
TTK_GROUP("Sash.vsash", TTK_FILL_BOTH,
TTK_NODE("Sash.vgrip", TTK_FILL_BOTH)))
TTK_END_LAYOUT_TABLE
/*------------------------------------------------------------------------
* +++ Initialization.
*/
MODULE_SCOPE int TtkClamTheme_Init(Tcl_Interp *);
MODULE_SCOPE int
TtkClamTheme_Init(Tcl_Interp *interp)
{
Ttk_Theme theme = Ttk_CreateTheme(interp, "clam", 0);
if (!theme) {
return TCL_ERROR;
}
Ttk_RegisterElement(interp, theme, "border",
&BorderElementSpec, NULL);
Ttk_RegisterElement(interp, theme, "field",
&FieldElementSpec, NULL);
Ttk_RegisterElement(interp, theme, "Combobox.field",
&ComboboxFieldElementSpec, NULL);
Ttk_RegisterElement(interp, theme, "trough",
&TroughElementSpec, NULL);
Ttk_RegisterElement(interp, theme, "thumb",
&ThumbElementSpec, NULL);
Ttk_RegisterElement(interp, theme, "uparrow",
&ArrowElementSpec, INT2PTR(ARROW_UP));
Ttk_RegisterElement(interp, theme, "Spinbox.uparrow",
&SpinboxArrowElementSpec, INT2PTR(ARROW_UP));
Ttk_RegisterElement(interp, theme, "downarrow",
&ArrowElementSpec, INT2PTR(ARROW_DOWN));
Ttk_RegisterElement(interp, theme, "Spinbox.downarrow",
&SpinboxArrowElementSpec, INT2PTR(ARROW_DOWN));
Ttk_RegisterElement(interp, theme, "leftarrow",
&ArrowElementSpec, INT2PTR(ARROW_LEFT));
Ttk_RegisterElement(interp, theme, "rightarrow",
&ArrowElementSpec, INT2PTR(ARROW_RIGHT));
Ttk_RegisterElement(interp, theme, "arrow",
&ArrowElementSpec, INT2PTR(ARROW_UP));
Ttk_RegisterElement(interp, theme, "Checkbutton.indicator",
&IndicatorElementSpec, (void *)&checkbutton_spec);
Ttk_RegisterElement(interp, theme, "Radiobutton.indicator",
&IndicatorElementSpec, (void *)&radiobutton_spec);
Ttk_RegisterElement(interp, theme, "tab", &TabElementSpec, NULL);
Ttk_RegisterElement(interp, theme, "client", &ClientElementSpec, NULL);
Ttk_RegisterElement(interp, theme, "slider", &SliderElementSpec, NULL);
Ttk_RegisterElement(interp, theme, "bar", &PbarElementSpec, NULL);
Ttk_RegisterElement(interp, theme, "pbar", &PbarElementSpec, NULL);
Ttk_RegisterElement(interp, theme, "hgrip",
&GripElementSpec, INT2PTR(TTK_ORIENT_HORIZONTAL));
Ttk_RegisterElement(interp, theme, "vgrip",
&GripElementSpec, INT2PTR(TTK_ORIENT_VERTICAL));
Ttk_RegisterLayouts(theme, LayoutTable);
Tcl_PkgProvide(interp, "ttk::theme::clam", TTK_VERSION);
return TCL_OK;
}
|