︙ | | |
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
+
+
+
|
{"note", kAlertNoteIcon},
{"caution", kAlertCautionIcon},
{NULL}
};
#define builtInIconSize 32
#define OSTYPE_TO_UTI(x) (NSString *)UTTypeCreatePreferredIdentifierForTag( \
kUTTagClassOSType, UTCreateStringForOSType(x), nil)
static Tcl_HashTable iconBitmapTable = {};
typedef struct {
int kind, width, height;
char *value;
} IconBitmap;
static const char *const iconBitmapOptionStrings[] = {
|
︙ | | |
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
|
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
|
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
-
+
+
+
+
+
|
}
}
}
/*
*----------------------------------------------------------------------
*
* GetBitmapForIcon --
* PixmapFromImage --
*
* Results:
* Bitmap for the given IconRef.
* Returns a Pixmap with an NSImage drawn into it.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static Pixmap
GetBitmapForIcon(
PixmapFromImage(
Display *display,
IconRef icon,
NSImage* image,
CGSize size)
{
TkMacOSXDrawingContext dc;
Pixmap pixmap;
pixmap = Tk_GetPixmap(display, None, size.width, size.height, 0);
if (TkMacOSXSetupDrawingContext(pixmap, NULL, 1, &dc)) {
if (dc.context) {
const CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1,
CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1,
.tx = 0, .ty = size.height };
const CGRect r = { .origin = { .x = 0, .y = 0 }, .size = size };
CGContextConcatCTM(dc.context, t);
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext
PlotIconRefInContext(dc.context, &r, kAlignAbsoluteCenter,
kTransformNone, NULL, kPlotIconRefNormalFlags, icon);
graphicsContextWithGraphicsPort:dc.context
flipped:NO]];
[image drawAtPoint:NSZeroPoint fromRect:NSZeroRect
operation:NSCompositeCopy fraction:1.0];
[NSGraphicsContext restoreGraphicsState];
}
TkMacOSXRestoreDrawingContext(&dc);
}
return pixmap;
}
/*
|
︙ | | |
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
|
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
-
-
-
-
+
-
-
+
-
-
-
+
+
-
-
-
+
-
-
|
*/
Pixmap
TkpCreateNativeBitmap(
Display *display,
const void *source) /* Info about the icon to build. */
{
Pixmap pixmap;
IconRef icon;
OSErr err;
NSString *iconUTI = OSTYPE_TO_UTI(PTR2UINT(source));
err = ChkErr(GetIconRef, kOnSystemDisk, kSystemIconsCreator,
PTR2UINT(source), &icon);
NSImage *iconImage = [[NSWorkspace sharedWorkspace]
if (err == noErr) {
pixmap = GetBitmapForIcon(display, icon, CGSizeMake(builtInIconSize,
builtInIconSize));
iconForFileType: iconUTI];
CGSize size = CGSizeMake(builtInIconSize, builtInIconSize);
ReleaseIconRef(icon);
} else {
pixmap = Tk_GetPixmap(display, None, builtInIconSize,
Pixmap pixmap = PixmapFromImage(display, iconImage, NSSizeToCGSize(size));
builtInIconSize, 0);
}
return pixmap;
}
/*
*----------------------------------------------------------------------
*
* OSTypeFromString --
|
︙ | | |
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
|
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
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
+
-
-
+
-
-
-
-
|
}
}
if (image) {
size = [image size];
}
}
if (image) {
TkMacOSXDrawingContext dc;
int depth = 0;
#ifdef MAC_OSX_TK_TODO
for (NSImageRep *r in [image representations]) {
NSInteger bitsPerSample = [r bitsPerSample];
if (bitsPerSample && bitsPerSample > depth) {
depth = bitsPerSample;
};
}
if (depth == 1) {
/* TODO: convert BW NSImage to CGImageMask */
}
#endif
pixmap = Tk_GetPixmap(display, None, size.width, size.height, depth);
*width = size.width;
*height = size.height;
if (TkMacOSXSetupDrawingContext(pixmap, NULL, 1, &dc)) {
if (dc.context) {
CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1,
.tx = 0, .ty = size.height};
pixmap = PixmapFromImage(display, image, NSSizeToCGSize(size));
CGContextConcatCTM(dc.context, t);
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext
graphicsContextWithGraphicsPort:dc.context flipped:NO]];
[image drawAtPoint:NSZeroPoint fromRect:NSZeroRect
operation:NSCompositeCopy fraction:1.0];
[NSGraphicsContext restoreGraphicsState];
}
TkMacOSXRestoreDrawingContext(&dc);
}
} else if (name) {
OSType iconType;
if (OSTypeFromString(name, &iconType) == TCL_OK) {
NSString *iconUTI = OSTYPE_TO_UTI(iconType);
printf("Found image for UTI %s\n", iconUTI.UTF8String);
IconRef icon;
NSImage *iconImage = [[NSWorkspace sharedWorkspace]
OSErr err = ChkErr(GetIconRef, kOnSystemDisk, kSystemIconsCreator,
iconType, &icon);
iconForFileType: iconUTI];
if (err == noErr) {
pixmap = GetBitmapForIcon(display, icon, NSSizeToCGSize(size));
pixmap = PixmapFromImage(display, iconImage, NSSizeToCGSize(size));
*width = size.width;
*height = size.height;
ReleaseIconRef(icon);
}
}
}
return pixmap;
}
/*
*----------------------------------------------------------------------
|
︙ | | |
︙ | | |
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
|
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
|
-
+
-
|
if ([NSApp macMinorVersion] < 9) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
"Window appearances did not exist until OSX 10.9.", -1));
Tcl_SetErrorCode(interp, "TK", "WINDOWSTYLE", "APPEARANCE", NULL);
return TCL_ERROR;
}
if ((objc < 3) || (objc > 4)) {
Tcl_WrongNumArgs(interp, 2, objv,
Tcl_WrongNumArgs(interp, 2, objv, "window ?appearancename?");
"appearance window ?appearancename?");
return TCL_ERROR;
}
if (objc == 4 && [NSApp macMinorVersion] < 14) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
"Window appearances cannot be changed before OSX 10.14.",
-1));
Tcl_SetErrorCode(interp, "TK", "WINDOWSTYLE", "APPEARANCE", NULL);
|
︙ | | |