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
|
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
|
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
+
-
-
-
+
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
+
-
+
|
/*
* tkMacOSXColor.c --
* TkMacOSXColor.c --
*
* This file maintains a database of color values for the Tk
* toolkit, in order to avoid round-trips to the server to
* map color names to pixel values.
*
* Copyright (c) 1990-1994 The Regents of the University of California.
* Copyright (c) 1994-1996 Sun Microsystems, Inc.
* Copyright 2001-2009, Apple Inc.
* Copyright (c) 2006-2009 Daniel A. Steffen <[email protected]>
* Copyright (c) 2020 Marc Culler
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#include "tkMacOSXPrivate.h"
#include "tkColor.h"
#include "tkMacOSXColor.h"
/*
* The colorType specifies how the color value should be interpreted. For the
* unique rgbColor entry, the RGB values are generated from the pixel value of
* an XColor. The ttkBackground and semantic types are dynamic, meaning
* that they change when dark mode is enabled on OSX 10.13 and later.
*/
enum colorType {
clearColor, /* There should be only one of these. */
rgbColor, /* There should be only one of these. */
appearance, /* There should be only one of these. */
HIBrush, /* The value is a HITheme brush color table index. */
HIText, /* The value is a HITheme text color table index. */
HIBackground, /* The value is a HITheme background color table index. */
ttkBackground, /* The value can be used as a parameter.*/
semantic, /* The value can be used as a parameter.*/
};
/*
*/
struct SystemColorMapEntry {
const char *name;
enum colorType type;
long value;
}; /* unsigned char pixelCode; */
/*
* Array of system color definitions: the array index is required to equal the
* color's (pixelCode - MIN_PIXELCODE), i.e. the array order needs to be kept
* in sync with the public pixel code values in tkMacOSXPort.h !
*/
#define MIN_PIXELCODE 30
static const struct SystemColorMapEntry systemColorMap[] = {
{ "Transparent", clearColor, 0 }, /* 30: TRANSPARENT_PIXEL */
{ "Highlight", HIBrush, kThemeBrushPrimaryHighlightColor }, /* 31 */
{ "HighlightSecondary", HIBrush, kThemeBrushSecondaryHighlightColor }, /* 32 */
{ "HighlightText", HIBrush, kThemeBrushBlack }, /* 33 */
{ "HighlightAlternate", HIBrush, kThemeBrushAlternatePrimaryHighlightColor }, /* 34 */
{ "ButtonText", HIText, kThemeTextColorPushButtonActive }, /* 35 */
{ "PrimaryHighlightColor", HIBrush, kThemeBrushPrimaryHighlightColor }, /* 36 */
{ "ButtonFace", HIBrush, kThemeBrushButtonFaceActive }, /* 37 */
{ "SecondaryHighlightColor", HIBrush, kThemeBrushSecondaryHighlightColor }, /* 38 */
{ "ButtonFrame", HIBrush, kThemeBrushButtonFrameActive }, /* 39 */
{ "AlternatePrimaryHighlightColor", HIBrush, kThemeBrushAlternatePrimaryHighlightColor }, /* 40 */
{ "WindowBody", HIBrush, kThemeBrushDocumentWindowBackground }, /* 41 */
{ "SheetBackground", HIBrush, kThemeBrushSheetBackground }, /* 42 */
{ "MenuActive", HIBrush, kThemeBrushMenuBackgroundSelected }, /* 43 */
{ "Black", HIBrush, kThemeBrushBlack }, /* 44 */
{ "MenuActiveText", HIText, kThemeTextColorMenuItemSelected }, /* 45 */
{ "White", HIBrush, kThemeBrushWhite }, /* 46 */
{ "Menu", HIBrush, kThemeBrushMenuBackground }, /* 47 */
{ "DialogBackgroundActive", HIBrush, kThemeBrushDialogBackgroundActive }, /* 48 */
{ "MenuDisabled", HIText, kThemeTextColorMenuItemDisabled }, /* 49 */
{ "DialogBackgroundInactive", HIBrush, kThemeBrushDialogBackgroundInactive }, /* 50 */
{ "MenuText", HIText, kThemeTextColorMenuItemActive }, /* 51 */
{ "AppearanceColor", appearance, 0 }, /* 52: APPEARANCE_PIXEL */
{ "AlertBackgroundActive", HIBrush, kThemeBrushAlertBackgroundActive }, /* 53 */
{ "AlertBackgroundInactive", HIBrush, kThemeBrushAlertBackgroundInactive }, /* 54 */
{ "ModelessDialogBackgroundActive", HIBrush, kThemeBrushModelessDialogBackgroundActive }, /* 55 */
{ "ModelessDialogBackgroundInactive", HIBrush, kThemeBrushModelessDialogBackgroundInactive }, /* 56 */
{ "UtilityWindowBackgroundActive", HIBrush, kThemeBrushUtilityWindowBackgroundActive }, /* 57 */
{ "UtilityWindowBackgroundInactive", HIBrush, kThemeBrushUtilityWindowBackgroundInactive }, /* 58 */
{ "ListViewSortColumnBackground", HIBrush, kThemeBrushListViewSortColumnBackground }, /* 59 */
{ "ListViewBackground", HIBrush, kThemeBrushListViewBackground }, /* 60 */
{ "IconLabelBackground", HIBrush, kThemeBrushIconLabelBackground }, /* 61 */
{ "ListViewSeparator", HIBrush, kThemeBrushListViewSeparator }, /* 62 */
{ "ChasingArrows", HIBrush, kThemeBrushChasingArrows }, /* 63 */
{ "DragHilite", HIBrush, kThemeBrushDragHilite }, /* 64 */
{ "DocumentWindowBackground", HIBrush, kThemeBrushDocumentWindowBackground }, /* 65 */
{ "FinderWindowBackground", HIBrush, kThemeBrushFinderWindowBackground }, /* 66 */
{ "ScrollBarDelimiterActive", HIBrush, kThemeBrushScrollBarDelimiterActive }, /* 67 */
{ "ScrollBarDelimiterInactive", HIBrush, kThemeBrushScrollBarDelimiterInactive }, /* 68 */
{ "FocusHighlight", HIBrush, kThemeBrushFocusHighlight }, /* 69 */
{ "PopupArrowActive", HIBrush, kThemeBrushPopupArrowActive }, /* 70 */
{ "PopupArrowPressed", HIBrush, kThemeBrushPopupArrowPressed }, /* 71 */
{ "PopupArrowInactive", HIBrush, kThemeBrushPopupArrowInactive }, /* 72 */
{ "AppleGuideCoachmark", HIBrush, kThemeBrushAppleGuideCoachmark }, /* 73 */
{ "IconLabelBackgroundSelected", HIBrush, kThemeBrushIconLabelBackgroundSelected }, /* 74 */
{ "StaticAreaFill", HIBrush, kThemeBrushStaticAreaFill }, /* 75 */
{ "ActiveAreaFill", HIBrush, kThemeBrushActiveAreaFill }, /* 76 */
{ "ButtonFrameActive", HIBrush, kThemeBrushButtonFrameActive }, /* 77 */
{ "ButtonFrameInactive", HIBrush, kThemeBrushButtonFrameInactive }, /* 78 */
{ "ButtonFaceActive", HIBrush, kThemeBrushButtonFaceActive }, /* 79 */
{ "ButtonFaceInactive", HIBrush, kThemeBrushButtonFaceInactive }, /* 80 */
{ "ButtonFacePressed", HIBrush, kThemeBrushButtonFacePressed }, /* 81 */
{ "ButtonActiveDarkShadow", HIBrush, kThemeBrushButtonActiveDarkShadow }, /* 82 */
{ "ButtonActiveDarkHighlight", HIBrush, kThemeBrushButtonActiveDarkHighlight }, /* 83 */
{ "ButtonActiveLightShadow", HIBrush, kThemeBrushButtonActiveLightShadow }, /* 84 */
{ "ButtonActiveLightHighlight", HIBrush, kThemeBrushButtonActiveLightHighlight }, /* 85 */
{ "ButtonInactiveDarkShadow", HIBrush, kThemeBrushButtonInactiveDarkShadow }, /* 86 */
{ "ButtonInactiveDarkHighlight", HIBrush, kThemeBrushButtonInactiveDarkHighlight }, /* 87 */
{ "ButtonInactiveLightShadow", HIBrush, kThemeBrushButtonInactiveLightShadow }, /* 88 */
{ "ButtonInactiveLightHighlight", HIBrush, kThemeBrushButtonInactiveLightHighlight }, /* 89 */
{ "ButtonPressedDarkShadow", HIBrush, kThemeBrushButtonPressedDarkShadow }, /* 90 */
{ "ButtonPressedDarkHighlight", HIBrush, kThemeBrushButtonPressedDarkHighlight }, /* 91 */
{ "ButtonPressedLightShadow", HIBrush, kThemeBrushButtonPressedLightShadow }, /* 92 */
{ "ButtonPressedLightHighlight", HIBrush, kThemeBrushButtonPressedLightHighlight }, /* 93 */
{ "BevelActiveLight", HIBrush, kThemeBrushBevelActiveLight }, /* 94 */
{ "BevelActiveDark", HIBrush, kThemeBrushBevelActiveDark }, /* 95 */
{ "BevelInactiveLight", HIBrush, kThemeBrushBevelInactiveLight }, /* 96 */
{ "BevelInactiveDark", HIBrush, kThemeBrushBevelInactiveDark }, /* 97 */
{ "NotificationWindowBackground", HIBrush, kThemeBrushNotificationWindowBackground }, /* 98 */
{ "MovableModalBackground", HIBrush, kThemeBrushMovableModalBackground }, /* 99 */
{ "SheetBackgroundOpaque", HIBrush, kThemeBrushSheetBackgroundOpaque }, /* 100 */
{ "DrawerBackground", HIBrush, kThemeBrushDrawerBackground }, /* 101 */
{ "ToolbarBackground", HIBrush, kThemeBrushToolbarBackground }, /* 102 */
{ "SheetBackgroundTransparent", HIBrush, kThemeBrushSheetBackgroundTransparent }, /* 103 */
{ "MenuBackground", HIBrush, kThemeBrushMenuBackground }, /* 104 */
{ "Pixel", rgbColor, 0 }, /* 105: PIXEL_MAGIC */
{ "MenuBackgroundSelected", HIBrush, kThemeBrushMenuBackgroundSelected }, /* 106 */
{ "ListViewOddRowBackground", HIBrush, kThemeBrushListViewOddRowBackground }, /* 107 */
{ "ListViewEvenRowBackground", HIBrush, kThemeBrushListViewEvenRowBackground }, /* 108 */
{ "ListViewColumnDivider", HIBrush, kThemeBrushListViewColumnDivider }, /* 109 */
{ "BlackText", HIText, kThemeTextColorBlack }, /* 110 */
{ "DialogActiveText", HIText, kThemeTextColorDialogActive }, /* 111 */
{ "DialogInactiveText", HIText, kThemeTextColorDialogInactive }, /* 112 */
{ "AlertActiveText", HIText, kThemeTextColorAlertActive }, /* 113 */
{ "AlertInactiveText", HIText, kThemeTextColorAlertInactive }, /* 114 */
{ "ModelessDialogActiveText", HIText, kThemeTextColorModelessDialogActive }, /* 115 */
{ "ModelessDialogInactiveText", HIText, kThemeTextColorModelessDialogInactive }, /* 116 */
{ "WindowHeaderActiveText", HIText, kThemeTextColorWindowHeaderActive }, /* 117 */
{ "WindowHeaderInactiveText", HIText, kThemeTextColorWindowHeaderInactive }, /* 118 */
{ "PlacardActiveText", HIText, kThemeTextColorPlacardActive }, /* 119 */
{ "PlacardInactiveText", HIText, kThemeTextColorPlacardInactive }, /* 120 */
{ "PlacardPressedText", HIText, kThemeTextColorPlacardPressed }, /* 121 */
{ "PushButtonActiveText", HIText, kThemeTextColorPushButtonActive }, /* 122 */
{ "PushButtonInactiveText", HIText, kThemeTextColorPushButtonInactive }, /* 123 */
{ "PushButtonPressedText", HIText, kThemeTextColorPushButtonPressed }, /* 124 */
{ "BevelButtonActiveText", HIText, kThemeTextColorBevelButtonActive }, /* 125 */
{ "BevelButtonInactiveText", HIText, kThemeTextColorBevelButtonInactive }, /* 126 */
{ "BevelButtonPressedText", HIText, kThemeTextColorBevelButtonPressed }, /* 127 */
{ "PopupButtonActiveText", HIText, kThemeTextColorPopupButtonActive }, /* 128 */
{ "PopupButtonInactiveText", HIText, kThemeTextColorPopupButtonInactive }, /* 129 */
{ "PopupButtonPressedText", HIText, kThemeTextColorPopupButtonPressed }, /* 130 */
{ "IconLabelText", HIText, kThemeTextColorIconLabel }, /* 131 */
{ "ListViewText", HIText, kThemeTextColorListView }, /* 132 */
{ "DocumentWindowTitleActiveText", HIText, kThemeTextColorDocumentWindowTitleActive }, /* 133 */
{ "DocumentWindowTitleInactiveText", HIText, kThemeTextColorDocumentWindowTitleInactive }, /* 134 */
{ "MovableModalWindowTitleActiveText", HIText, kThemeTextColorMovableModalWindowTitleActive }, /* 135 */
{ "MovableModalWindowTitleInactiveText",HIText, kThemeTextColorMovableModalWindowTitleInactive }, /* 136 */
{ "UtilityWindowTitleActiveText", HIText, kThemeTextColorUtilityWindowTitleActive }, /* 137 */
{ "UtilityWindowTitleInactiveText", HIText, kThemeTextColorUtilityWindowTitleInactive }, /* 138 */
{ "PopupWindowTitleActiveText", HIText, kThemeTextColorPopupWindowTitleActive }, /* 139 */
{ "PopupWindowTitleInactiveText", HIText, kThemeTextColorPopupWindowTitleInactive }, /* 140 */
{ "RootMenuActiveText", HIText, kThemeTextColorRootMenuActive }, /* 141 */
{ "RootMenuSelectedText", HIText, kThemeTextColorRootMenuSelected }, /* 142 */
{ "RootMenuDisabledText", HIText, kThemeTextColorRootMenuDisabled }, /* 143 */
{ "MenuItemActiveText", HIText, kThemeTextColorMenuItemActive }, /* 144 */
{ "MenuItemSelectedText", HIText, kThemeTextColorMenuItemSelected }, /* 145 */
{ "MenuItemDisabledText", HIText, kThemeTextColorMenuItemDisabled }, /* 146 */
{ "PopupLabelActiveText", HIText, kThemeTextColorPopupLabelActive }, /* 147 */
{ "PopupLabelInactiveText", HIText, kThemeTextColorPopupLabelInactive }, /* 148 */
{ "TabFrontActiveText", HIText, kThemeTextColorTabFrontActive }, /* 149 */
{ "TabNonFrontActiveText", HIText, kThemeTextColorTabNonFrontActive }, /* 150 */
{ "TabNonFrontPressedText", HIText, kThemeTextColorTabNonFrontPressed }, /* 151 */
{ "TabFrontInactiveText", HIText, kThemeTextColorTabFrontInactive }, /* 152 */
{ "TabNonFrontInactiveText", HIText, kThemeTextColorTabNonFrontInactive }, /* 153 */
{ "IconLabelSelectedText", HIText, kThemeTextColorIconLabelSelected }, /* 154 */
{ "BevelButtonStickyActiveText", HIText, kThemeTextColorBevelButtonStickyActive }, /* 155 */
{ "BevelButtonStickyInactiveText", HIText, kThemeTextColorBevelButtonStickyInactive }, /* 156 */
{ "NotificationText", HIText, kThemeTextColorNotification }, /* 157 */
{ "SystemDetailText", HIText, kThemeTextColorSystemDetail }, /* 158 */
{ "WhiteText", HIText, kThemeTextColorWhite }, /* 159 */
{ "TabPaneBackground", HIBackground, kThemeBackgroundTabPane }, /* 160 */
{ "PlacardBackground", HIBackground, kThemeBackgroundPlacard }, /* 161 */
{ "WindowHeaderBackground", HIBackground, kThemeBackgroundWindowHeader }, /* 162 */
{ "ListViewWindowHeaderBackground", HIBackground, kThemeBackgroundListViewWindowHeader }, /* 163 */
{ "SecondaryGroupBoxBackground", HIBackground, kThemeBackgroundSecondaryGroupBox }, /* 164 */
{ "MetalBackground", HIBackground, kThemeBackgroundMetal }, /* 165 */
/*
* Colors based on "semantic" NSColors.
*/
{ "WindowBackgroundColor", ttkBackground, 0 }, /* 166 */
{ "WindowBackgroundColor1", ttkBackground, 1 }, /* 167 */
{ "WindowBackgroundColor2", ttkBackground, 2 }, /* 168 */
{ "WindowBackgroundColor3", ttkBackground, 3 }, /* 169 */
{ "WindowBackgroundColor4", ttkBackground, 4 }, /* 170 */
{ "WindowBackgroundColor5", ttkBackground, 5 }, /* 171 */
{ "WindowBackgroundColor6", ttkBackground, 6 }, /* 172 */
{ "WindowBackgroundColor7", ttkBackground, 7 }, /* 173 */
{ "TextColor", semantic, 0 }, /* 174 */
{ "SelectedTextColor", semantic, 1 }, /* 175 */
{ "LabelColor", semantic, 2 }, /* 176 */
{ "ControlTextColor", semantic, 3 }, /* 177 */
{ "DisabledControlTextColor", semantic, 4 }, /* 178 */
{ "SelectedTabTextColor", semantic, 5 }, /* 179 */
{ "TextBackgroundColor", semantic, 6 }, /* 180 */
{ "SelectedTextBackgroundColor", semantic, 7 }, /* 181 */
{ "ControlAccentColor", semantic, 8 }, /* 182 */
/* Apple's SecondaryLabelColor is the same as their LabelColor so we roll our own. */
{ "SecondaryLabelColor", ttkBackground, 14 }, /* 183 */
{ "LinkColor", semantic, 9 }, /* 184 */
{ NULL, 0, 0 }
};
#define FIRST_SEMANTIC_COLOR 166
#define MAX_PIXELCODE 184
/*
*----------------------------------------------------------------------
*
* GetEntryFromPixelCode --
*
* Extract a SystemColorMapEntry from the table.
static Tcl_HashTable systemColors;
*
* Results:
* Returns false if the code is out of bounds.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static bool
GetEntryFromPixelCode(
static int numSystemColors;
static int rgbColorIndex;
static int controlAccentIndex;
unsigned char code,
struct SystemColorMapEntry *entry)
static Bool useFakeAccentColor = NO;
{
if (code >= MIN_PIXELCODE && code <= MAX_PIXELCODE) {
*entry = systemColorMap[code - MIN_PIXELCODE];
static SystemColorDatum **systemColorIndex;
return true;
} else {
return false;
}
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
/*
*----------------------------------------------------------------------
*
* SetCGColorComponents --
*
* Set the components of a CGColorRef from an XColor pixel value and a
* system color map entry. The pixel value is only used in the case where
* the color is of type rgbColor. In that case the normalized XColor RGB
* values are copied into the CGColorRef.
*
* Results:
* OSStatus
static NSAppearance *lightAqua = nil;
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static NSAppearance *darkAqua = nil;
#endif
static NSColorSpace* sRGB = NULL;
static CGFloat windowBackground[4] =
{236.0 / 255, 236.0 / 255, 236.0 / 255, 1.0};
void initColorTable()
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
Tcl_InitHashTable(&systemColors, TCL_STRING_KEYS);
SystemColorDatum *entry, *oldEntry;
Tcl_HashSearch search;
Tcl_HashEntry *hPtr;
int newPtr, index = 0;
NSColorList *systemColorList = [NSColorList colorListNamed:@"System"];
NSString *key;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
if (@available(macOS 10.14, *)) {
darkAqua = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
lightAqua = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
}
#endif
/*
* Build a hash table for looking up a color by its name.
* First add all of the static entries from tkMacOSXColor.h
*/
for (entry = systemColorData; entry->name != NULL; entry++) {
hPtr = Tcl_CreateHashEntry(&systemColors, entry->name, &newPtr);
if (entry->type == semantic) {
NSString *colorName = [[NSString alloc]
initWithCString:entry->macName
encoding:NSUTF8StringEncoding];
SEL colorSelector = NSSelectorFromString(colorName);
if (![NSColor respondsToSelector:colorSelector]) {
if ([colorName isEqualToString:@"controlAccentColor"]) {
useFakeAccentColor = YES;
} else {
/* Uncomment to print all unsupported colors: */
/* printf("Unsupported color %s\n", colorName.UTF8String); */
continue;
}
}
entry->selector = [colorName retain];
}
if (newPtr == 0) {
oldEntry = (SystemColorDatum *) Tcl_GetHashValue(hPtr);
entry->index = oldEntry->index;
[oldEntry->selector release];
} else {
entry->index = index++;
}
Tcl_SetHashValue(hPtr, entry);
}
/*
* Add all of the colors in the System ColorList.
*/
for (key in [systemColorList allKeys]) {
int length = [key lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
char *name;
entry = ckalloc(sizeof(SystemColorDatum));
bzero(entry, sizeof(SystemColorDatum));
name = ckalloc(length + 1);
strcpy(name, key.UTF8String);
name[0] = toupper(name[0]);
if (!strcmp(name, "WindowBackgroundColor")) {
/*
* Avoid black windows on old systems.
*/
continue;
}
entry->type=semantic;
entry->name = name;
entry->selector = [key retain];
hPtr = Tcl_CreateHashEntry(&systemColors, entry->name, &newPtr);
if (newPtr == 0) {
oldEntry = (SystemColorDatum *) Tcl_GetHashValue(hPtr);
entry->index = oldEntry->index;
[oldEntry->selector release];
} else {
entry->index = index++;
}
Tcl_SetHashValue(hPtr, entry);
}
/*
* Build an array for looking up a color by its index.
*/
numSystemColors = index;
systemColorIndex = ckalloc(numSystemColors * sizeof(SystemColorDatum*));
for (hPtr = Tcl_FirstHashEntry(&systemColors, &search); hPtr != NULL;
hPtr = Tcl_NextHashEntry(&search)) {
entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr);
if (entry == NULL) {
Tcl_Panic("Unsupported semantic color with no supported backup!");
}
systemColorIndex[entry->index] = entry;
}
/*
* Remember the indexes of some special entries.
*/
hPtr = Tcl_FindHashEntry(&systemColors, "Pixel");
entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr);
rgbColorIndex = entry->index;
hPtr = Tcl_FindHashEntry(&systemColors, "ControlAccentColor");
entry = (SystemColorDatum *) Tcl_GetHashValue(hPtr);
controlAccentIndex = entry->index;
[pool drain];
}
/*
*----------------------------------------------------------------------
*
* TkMacOSXRGBPixel --
*
* Return an unsigned long value suitable for use in the pixel
* field of an XColor with the specified red, green and blue
* intensities. The inputs are cast as unsigned longs but are
* expected to have values representable by an unsigned char.
*
* This is called in the TkpGetPixel macro, used in xcolor.c,
* and in ImageGetPixel.
*
* Results:
* An unsigned long that can be used as the pixel field of an XColor.
*
* Side effects:
* None.
*----------------------------------------------------------------------
*/
MODULE_SCOPE
unsigned long
TkMacOSXRGBPixel(
unsigned long red,
unsigned long green,
unsigned long blue)
{
MacPixel p;
p.pixel.colortype = rgbColor;
p.pixel.value = ((red & 0xff) << 16) |
((green & 0xff) << 8) |
(blue & 0xff);
return p.ulong;
}
/*
*----------------------------------------------------------------------
*
* TkMacOSXClearPixel --
*
* Return the unsigned long value that appears in the pixel
* field of the XColor for systemTransparentColor.
*
* This is used in tkMacOSXImage.c.
*
* Results:
* The unsigned long that appears in the pixel field of the XColor
* for systemTransparentPixel.
*
* Side effects:
* None.
*----------------------------------------------------------------------
*/
MODULE_SCOPE
unsigned long TkMacOSXClearPixel(
void)
{
MacPixel p;
p.pixel.value = 0;
p.pixel.colortype = clearColor;
return p.ulong;
}
/*
*----------------------------------------------------------------------
*
* GetEntryFromPixel --
*
* Look up a SystemColorDatum which describes the XColor with
* the specified value as its pixel field.
*
* Results:
* A pointer to a SystemColorDatum, or NULL if the pixel value is
* invalid.
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
SystemColorDatum*
GetEntryFromPixel(
unsigned long pixel)
{
MacPixel p;
int index = rgbColorIndex;
p.ulong = pixel;
if (p.pixel.colortype != rgbColor) {
index = p.pixel.value;
}
if (index < numSystemColors) {
return systemColorIndex[index];
} else {
return NULL;
}
}
/*
*----------------------------------------------------------------------
*
* GetRGBA --
*
* Given a SystemColorDatum and a pointer to an array of 4 CGFloats, store
* the associated RGBA color values in the array. In the case of the
* RGBColor datum, the unsigned long pixel value containing the RGB values
* must also be provided as the pixel parameter. Otherwise the pixel
* parameter is ignored.
*
* Results:
* None
*
* Side effects:
* The array rgba is filled in.
*
*----------------------------------------------------------------------
*/
static OSStatus
SetCGColorComponents(
struct SystemColorMapEntry entry,
static void
GetRGBA(
SystemColorDatum *entry,
unsigned long pixel,
CGColorRef *c)
CGFloat *rgba)
{
OSStatus err = noErr;
NSColor *bgColor, *color = nil;
CGFloat rgba[4] = {0, 0, 0, 1};
if (!sRGB) {
sRGB = [NSColorSpace sRGBColorSpace];
}
/*
* This function is called before our autorelease pool is set up,
* so it needs its own pool.
*/
NSAutoreleasePool *pool = [NSAutoreleasePool new];
switch (entry.type) {
switch (entry->type) {
case HIBrush:
err = ChkErr(HIThemeBrushCreateCGColor, entry.value, c);
return err;
case rgbColor:
rgba[0] = ((pixel >> 16) & 0xff) / 255.0;
rgba[1] = ((pixel >> 8) & 0xff) / 255.0;
rgba[2] = ((pixel ) & 0xff) / 255.0;
break;
case ttkBackground:
/*
* Prior to OSX 10.14, getComponents returns black when applied to
* windowBackGroundColor.
*/
if ([NSApp macOSVersion] < 101400) {
for (int i=0; i<3; i++) {
for (int i = 0; i < 3; i++) {
rgba[i] = windowBackground[i];
}
} else {
bgColor = [[NSColor windowBackgroundColor] colorUsingColorSpace:sRGB];
[bgColor getComponents: rgba];
}
if (rgba[0] + rgba[1] + rgba[2] < 1.5) {
for (int i=0; i<3; i++) {
rgba[i] += entry.value*8.0 / 255.0;
rgba[i] += entry->value*8.0 / 255.0;
}
} else {
for (int i=0; i<3; i++) {
rgba[i] -= entry.value*8.0 / 255.0;
rgba[i] -= entry->value*8.0 / 255.0;
}
}
break;
case semantic:
switch (entry.value) {
if (entry->index == controlAccentIndex && useFakeAccentColor) {
case 0:
color = [[NSColor textColor] colorUsingColorSpace:sRGB];
break;
case 1:
color = [[NSColor selectedTextColor] colorUsingColorSpace:sRGB];
break;
case 2:
if ([NSApp macOSVersion] > 100900) {
#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090
#if MAC_OS_X_VERSION_MAX_ALLOWED < 101500
color = [[NSColor labelColor] colorUsingColorSpace:sRGB];
#endif
} else {
color = [[NSColor textColor] colorUsingColorSpace:sRGB];
}
break;
case 3:
color = [[NSColor controlTextColor] colorUsingColorSpace:sRGB];
break;
case 4:
color = [[NSColor disabledControlTextColor]
colorUsingColorSpace:sRGB];
break;
case 5:
if ([NSApp macOSVersion] > 100600) {
color = [[NSColor whiteColor] colorUsingColorSpace:sRGB];
} else {
color = [[NSColor blackColor] colorUsingColorSpace:sRGB];
}
break;
case 6:
color = [[NSColor textBackgroundColor] colorUsingColorSpace:sRGB];
break;
case 7:
color = [[NSColor selectedTextBackgroundColor]
colorUsingColorSpace:sRGB];
break;
case 8:
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
if (@available(macOS 14, *)) {
color = [[NSColor controlAccentColor] colorUsingColorSpace:sRGB];
#else
if(false) {
#endif
} else {
color = [[NSColor
color = [[NSColor colorForControlTint: [NSColor currentControlTint]]
colorForControlTint:[NSColor currentControlTint]]
colorUsingColorSpace: sRGB];
colorUsingColorSpace:sRGB];
}
break;
case 9:
if ([NSApp macOSVersion] >= 101000) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000
color = [[NSColor linkColor] colorUsingColorSpace:sRGB];
#endif
} else {
color = [[NSColor blueColor] colorUsingColorSpace:sRGB];
} else {
color = [[NSColor valueForKey:entry->selector] colorUsingColorSpace:sRGB];
}
break;
default:
if ([NSApp macOSVersion] >= 101000) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000
color = [[NSColor labelColor] colorUsingColorSpace:sRGB];
#endif
} else {
color = [[NSColor textColor] colorUsingColorSpace:sRGB];
}
break;
}
[color getComponents: rgba];
break;
case clearColor:
rgba[3] = 0.0;
rgba[3] = 0;
default:
break;
/*
* There are no HITheme functions which convert Text or background colors
* to CGColors. (GetThemeTextColor has been removed, and it was never
* possible with backgrounds.) If we get one of these we return black.
}
}
/*
*----------------------------------------------------------------------
*
* SetCGColorComponents --
*
* Set the components of a CGColorRef from an XColor pixel value and a
* SystemColorDatum. The pixel value is only used in the case where
* the color is of type rgbColor. In that case the normalized XColor RGB
* values are copied into the CGColorRef. Otherwise the components are
* computed from the SystemColorDatum.
*
* Results:
* True if the function succeeds, false otherwise.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static Bool
SetCGColorComponents(
SystemColorDatum *entry,
unsigned long pixel,
CGColorRef *c)
{
CGFloat rgba[4] = {0, 0, 0, 1};
/*
* This function is called before our autorelease pool is set up,
* so it needs its own pool.
*/
NSAutoreleasePool *pool = [NSAutoreleasePool new];
case HIText:
case HIBackground:
if (entry->type == HIBrush) {
default:
break;
OSStatus err = ChkErr(HIThemeBrushCreateCGColor, entry->value, c);
return err == noErr;
}
GetRGBA(entry, pixel, rgba);
*c = CGColorCreate(sRGB.CGColorSpace, rgba);
[pool drain];
return err;
return true;
}
/*
*----------------------------------------------------------------------
*
* TkMacOSXInDarkMode --
*
|