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
|
/*
* tkMacOSXInt.h --
*
* Declarations of Macintosh specific shared variables and procedures.
*
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
* Copyright 2001, Apple Computer, Inc.
* Copyright (c) 2005-2007 Daniel A. Steffen <das@users.sourceforge.net>
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tkMacOSXInt.h,v 1.27 2007/06/09 17:09:40 das Exp $
*/
#ifndef _TKMACINT
#define _TKMACINT
#ifndef _TKINT
#include "tkInt.h"
#endif
#define kComponentSignatureString "TkMacOSX"
#define COMPONENT_SIGNATURE 'Tk '
#define TextStyle MacTextStyle
#include <Carbon/Carbon.h>
#undef TextStyle
/* Define constants only available on Mac OS X 10.3 or later */
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
#define kEventAppAvailableWindowBoundsChanged 110
#define kEventParamTransactionID 'trns'
#define kEventParamWindowPartCode 'wpar'
#define typeWindowPartCode 'wpar'
#define kMenuAttrDoNotUseUserCommandKeys (1 << 7)
#define kSimpleWindowClass 18
#define kWindowDoesNotCycleAttribute (1L << 15)
#define kWindowAsyncDragAttribute (1L << 23)
#define kThemeBrushAlternatePrimaryHighlightColor -5
#define kThemeResizeUpCursor 19
#define kThemeResizeDownCursor 19
#define kThemeResizeUpDownCursor 19
#define kThemePoofCursor 19
#define kThemeBackgroundMetal 6
#define kThemeIncDecButtonSmall 21
#define kThemeIncDecButtonMini 22
#define kAppearancePartUpButton 20
#define kAppearancePartDownButton 21
#define kAppearancePartPageUpArea 22
#define kAppearancePartPageDownArea 23
#define kAppearancePartIndicator 129
#define kUIModeAllSuppressed 4
#define FixedToInt(a) ((short)(((Fixed)(a) + fixed1/2) >> 16))
#define IntToFixed(a) ((Fixed)(a) << 16)
#endif
/* Define constants only available on Mac OS X 10.4 or later */
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1040
#define kWindowNoTitleBarAttribute (1L << 9)
#define kWindowMetalNoContentSeparatorAttribute (1L << 11)
#define kThemeDisclosureTriangle 6
#define kThemeBrushListViewOddRowBackground 56
#define kThemeBrushListViewEvenRowBackground 57
#define kThemeBrushListViewColumnDivider 58
#define kThemeMetricScrollBarMinThumbHeight 132
#define kThemeMetricSmallScrollBarMinThumbHeight 134
#define kThemeScrollBarMedium kThemeMediumScrollBar
#define kThemeScrollBarSmall kThemeSmallScrollBar
#ifdef __BIG_ENDIAN__
#define kCGBitmapByteOrder32Host (4 << 12)
#else
#define kCGBitmapByteOrder32Host (2 << 12)
#endif
#endif
/* Define constants only available on Mac OS X 10.5 or later */
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050
#define kWindowUnifiedTitleAndToolbarAttribute (1L << 7)
#define kWindowTexturedSquareCornersAttribute (1L << 10)
#endif
/* HIToolbox version constants */
#ifndef kHIToolboxVersionNumber10_3
#define kHIToolboxVersionNumber10_3 (145)
#endif
#ifndef kHIToolboxVersionNumber10_4
#define kHIToolboxVersionNumber10_4 (219)
#endif
#ifndef kHIToolboxVersionNumber10_5
#define kHIToolboxVersionNumber10_5 (303)
#endif
/* Macros for HIToolbox runtime version checking */
MODULE_SCOPE float tkMacOSXToolboxVersionNumber;
#define TK_IF_HI_TOOLBOX(vers, ...) \
tk_if_mac_os_x_min_10_##vers(tkMacOSXToolboxVersionNumber >= \
kHIToolboxVersionNumber10_##vers, 1, __VA_ARGS__)
#define TK_ELSE_HI_TOOLBOX(vers, ...) \
tk_else_mac_os_x_min_10_##vers(__VA_ARGS__)
/* Macros for Mac OS X API availability checking */
#define TK_IF_MAC_OS_X_API(vers, symbol, ...) \
tk_if_mac_os_x_10_##vers(symbol != NULL, 1, __VA_ARGS__)
#define TK_ELSE_MAC_OS_X(vers, ...) \
tk_else_mac_os_x_10_##vers(__VA_ARGS__)
#define TK_IF_MAC_OS_X_API_COND(vers, symbol, cond, ...) \
tk_if_mac_os_x_10_##vers(symbol != NULL, cond, __VA_ARGS__)
#define TK_ELSE(...) \
} else { __VA_ARGS__
#define TK_ENDIF \
}
/* Private macros that implement the checking macros above */
#define tk_if_mac_os_x_yes(chk, cond, ...) \
if (cond) { __VA_ARGS__
#define tk_else_mac_os_x_yes(...) \
} else {
#define tk_if_mac_os_x_chk(chk, cond, ...) \
if ((chk) && (cond)) { __VA_ARGS__
#define tk_else_mac_os_x_chk(...) \
} else { __VA_ARGS__
#define tk_if_mac_os_x_no(chk, cond, ...) \
if (0) {
#define tk_else_mac_os_x_no(...) \
} else { __VA_ARGS__
/* Private mapping macros defined according to Mac OS X version requirements */
/* 10.3 Panther */
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1030
#define tk_if_mac_os_x_min_10_3 tk_if_mac_os_x_yes
#define tk_else_mac_os_x_min_10_3 tk_else_mac_os_x_yes
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
#define tk_if_mac_os_x_10_3 tk_if_mac_os_x_yes
#define tk_else_mac_os_x_10_3 tk_else_mac_os_x_yes
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
#else /* MAC_OS_X_VERSION_MIN_REQUIRED */
#define tk_if_mac_os_x_min_10_3 tk_if_mac_os_x_chk
#define tk_else_mac_os_x_min_10_3 tk_else_mac_os_x_chk
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
#define tk_if_mac_os_x_10_3 tk_if_mac_os_x_chk
#define tk_else_mac_os_x_10_3 tk_else_mac_os_x_chk
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
#endif /* MAC_OS_X_VERSION_MIN_REQUIRED */
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
#define tk_if_mac_os_x_10_3 tk_if_mac_os_x_no
#define tk_else_mac_os_x_10_3 tk_else_mac_os_x_no
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
/* 10.4 Tiger */
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1040
#define tk_if_mac_os_x_min_10_4 tk_if_mac_os_x_yes
#define tk_else_mac_os_x_min_10_4 tk_else_mac_os_x_yes
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
#define tk_if_mac_os_x_10_4 tk_if_mac_os_x_yes
#define tk_else_mac_os_x_10_4 tk_else_mac_os_x_yes
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
#else /* MAC_OS_X_VERSION_MIN_REQUIRED */
#define tk_if_mac_os_x_min_10_4 tk_if_mac_os_x_chk
#define tk_else_mac_os_x_min_10_4 tk_else_mac_os_x_chk
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
#define tk_if_mac_os_x_10_4 tk_if_mac_os_x_chk
#define tk_else_mac_os_x_10_4 tk_else_mac_os_x_chk
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
#endif /* MAC_OS_X_VERSION_MIN_REQUIRED */
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1040
#define tk_if_mac_os_x_10_4 tk_if_mac_os_x_no
#define tk_else_mac_os_x_10_4 tk_else_mac_os_x_no
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
/* 10.5 Leopard */
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
#define tk_if_mac_os_x_min_10_5 tk_if_mac_os_x_yes
#define tk_else_mac_os_x_min_10_5 tk_else_mac_os_x_yes
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
#define tk_if_mac_os_x_10_5 tk_if_mac_os_x_yes
#define tk_else_mac_os_x_10_5 tk_else_mac_os_x_yes
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
#else /* MAC_OS_X_VERSION_MIN_REQUIRED */
#define tk_if_mac_os_x_min_10_5 tk_if_mac_os_x_chk
#define tk_else_mac_os_x_min_10_5 tk_else_mac_os_x_chk
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
#define tk_if_mac_os_x_10_5 tk_if_mac_os_x_chk
#define tk_else_mac_os_x_10_5 tk_else_mac_os_x_chk
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
#endif /* MAC_OS_X_VERSION_MIN_REQUIRED */
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050
#define tk_if_mac_os_x_10_5 tk_if_mac_os_x_no
#define tk_else_mac_os_x_10_5 tk_else_mac_os_x_no
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
/*
* Include platform specific public interfaces.
*/
#ifndef _TKMAC
#include "tkMacOSX.h"
#endif
struct TkWindowPrivate {
TkWindow *winPtr; /* Ptr to tk window or NULL if Pixmap */
CGrafPtr grafPtr;
CGContextRef context;
ControlRef rootControl;
int xOff; /* X offset from toplevel window */
int yOff; /* Y offset from toplevel window */
RgnHandle clipRgn; /* Visible region of window */
RgnHandle aboveClipRgn; /* Visible region of window & its children */
RgnHandle drawRgn; /* Clipped drawing region */
int referenceCount; /* Don't delete toplevel until children are
* gone. */
struct TkWindowPrivate *toplevel;
/* Pointer to the toplevel datastruct. */
int flags; /* Various state see defines below. */
};
typedef struct TkWindowPrivate MacDrawable;
/*
* This list is used to keep track of toplevel windows that have a Mac
* window attached. This is useful for several things, not the least
* of which is maintaining floating windows.
*/
typedef struct TkMacOSXWindowList {
struct TkMacOSXWindowList *nextPtr;
/* The next window in the list. */
TkWindow *winPtr; /* This window */
} TkMacOSXWindowList;
/*
* Defines use for the flags field of the MacDrawable data structure.
*/
#define TK_SCROLLBAR_GROW 0x01
#define TK_CLIP_INVALID 0x02
#define TK_HOST_EXISTS 0x04
#define TK_DRAWN_UNDER_MENU 0x08
#define TK_CLIPPED_DRAW 0x10
/*
* I am reserving TK_EMBEDDED = 0x100 in the MacDrawable flags
* This is defined in tk.h. We need to duplicate the TK_EMBEDDED flag in the
* TkWindow structure for the window, but in the MacWin. This way we can
* still tell what the correct port is after the TKWindow structure has been
* freed. This actually happens when you bind destroy of a toplevel to
* Destroy of a child.
*/
/*
* This structure is for handling Netscape-type in process
* embedding where Tk does not control the top-level. It contains
* various functions that are needed by Mac specific routines, like
* TkMacOSXGetDrawablePort. The definitions of the function types
* are in tkMacOSX.h.
*/
typedef struct {
Tk_MacOSXEmbedRegisterWinProc *registerWinProc;
Tk_MacOSXEmbedGetGrafPortProc *getPortProc;
Tk_MacOSXEmbedMakeContainerExistProc *containerExistProc;
Tk_MacOSXEmbedGetClipProc *getClipProc;
Tk_MacOSXEmbedGetOffsetInParentProc *getOffsetProc;
} TkMacOSXEmbedHandler;
MODULE_SCOPE TkMacOSXEmbedHandler *tkMacOSXEmbedHandler;
/*
* Structure encapsulating current drawing environment.
*/
typedef struct TkMacOSXDrawingContext {
CGContextRef context;
CGrafPtr port, savePort;
ThemeDrawingState saveState;
PixPatHandle penPat;
Rect portBounds;
Boolean portChanged;
} TkMacOSXDrawingContext;
/*
* Defines used for TkMacOSXInvalidateWindow
*/
#define TK_WINDOW_ONLY 0
#define TK_PARENT_WINDOW 1
/*
* Accessor for the privatePtr flags field for the TK_HOST_EXISTS field
*/
#define TkMacOSXHostToplevelExists(tkwin) \
(((TkWindow *) (tkwin))->privatePtr->toplevel->flags & TK_HOST_EXISTS)
/*
* Defines use for the flags argument to TkGenWMConfigureEvent.
*/
#define TK_LOCATION_CHANGED 1
#define TK_SIZE_CHANGED 2
#define TK_BOTH_CHANGED 3
/*
* Defines for tkTextDisp.c
*/
#define TK_LAYOUT_WITH_BASE_CHUNKS 1
#define TK_DRAW_IN_CONTEXT 1
#if !TK_DRAW_IN_CONTEXT
MODULE_SCOPE int TkMacOSXCompareColors(unsigned long c1, unsigned long c2);
#endif
/*
* Macros abstracting checks only active in a debug build.
*/
#ifdef TK_MAC_DEBUG
/*
* Macro to do debug message output.
*/
#define TkMacOSXDbgMsg(m, ...) do { \
fprintf(stderr, "%s:%d: %s(): " m "\n", strrchr(__FILE__, '/')+1, \
__LINE__, __func__, ##__VA_ARGS__); \
} while (0)
/*
* Macro to do debug API failure message output.
*/
#if !defined(DEBUGLEVEL) || !DEBUGLEVEL
#define TkMacOSXDbgOSErr(f, err) do { \
TkMacOSXDbgMsg("%s failed: %ld", #f, err); \
} while (0)
#else
#define TkMacOSXDbgOSErr(f, err) do { \
DEBUG_ASSERT_MESSAGE(kComponentSignatureString, #f " failed:", \
__func__, 0, strrchr(__FILE__, '/')+1, __LINE__, err); \
} while (0)
#endif
/*
* Macro to do very common check for noErr return from given API and output
* debug message in case of failure.
*/
#define ChkErr(f, ...) ({ \
OSStatus err = f(__VA_ARGS__); \
if (err != noErr) { \
TkMacOSXDbgOSErr(f, err); \
} \
err;})
/*
* Macro to check emptyness of shared temp regions before use in debug builds.
*/
#define TkMacOSXCheckTmpRgnEmpty(r) do { \
if (!EmptyRgn(tkMacOSXtmpRgn##r)) { \
Tcl_Panic("tkMacOSXtmpRgn%s nonempty", #r); \
} \
} while(0)
#else /* TK_MAC_DEBUG */
#define TkMacOSXDbgMsg(m, ...)
#define TkMacOSXDbgOSErr(f, err)
#define ChkErr(f, ...) ({f(__VA_ARGS__);})
#define TkMacOSXCheckTmpRgnEmpty(r)
#endif /* TK_MAC_DEBUG */
/*
* Variables shared among various Mac Tk modules but are not
* exported to the outside world.
*/
MODULE_SCOPE RgnHandle tkMacOSXtmpRgn1;
MODULE_SCOPE RgnHandle tkMacOSXtmpRgn2;
/*
* Globals shared among Macintosh Tk
*/
MODULE_SCOPE MenuHandle tkCurrentAppleMenu; /* Handle to current Apple Menu */
MODULE_SCOPE MenuHandle tkAppleMenu; /* Handle to default Apple Menu */
MODULE_SCOPE MenuHandle tkFileMenu; /* Handles to menus */
MODULE_SCOPE MenuHandle tkEditMenu; /* Handles to menus */
MODULE_SCOPE int tkPictureIsOpen; /* If this is 1, we are drawing to a
* picture The clipping should then be
* done relative to the bounds of the
* picture rather than the window. As
* of OS X.0.4, something is seriously
* wrong: The clipping bounds only
* seem to work if the top,left values
* are 0,0 The destination rectangle
* for CopyBits should also have
* top,left values of 0,0
*/
MODULE_SCOPE TkMacOSXWindowList *tkMacOSXWindowListPtr; /* List of toplevels */
MODULE_SCOPE Tcl_Encoding TkMacOSXCarbonEncoding;
/*
* Prototypes of internal procs not in the stubs table.
*/
#if 0
MODULE_SCOPE int XSetClipRectangles(Display *d, GC gc, int clip_x_origin,
int clip_y_origin, XRectangle* rectangles, int n, int ordering);
#endif
MODULE_SCOPE void TkpClipDrawableToRect(Display *display, Drawable d, int x,
int y, int width, int height);
MODULE_SCOPE void TkMacOSXDisplayChanged(Display *display);
MODULE_SCOPE void TkMacOSXInitScrollbarMetrics(void);
MODULE_SCOPE int TkMacOSXUseAntialiasedText(Tcl_Interp *interp, int enable);
MODULE_SCOPE void TkMacOSXInitCarbonEvents(Tcl_Interp *interp);
MODULE_SCOPE int TkMacOSXInitCGDrawing(Tcl_Interp *interp, int enable,
int antiAlias);
MODULE_SCOPE void TkMacOSXInitKeyboard(Tcl_Interp *interp);
MODULE_SCOPE void TkMacOSXDefaultStartupScript(void);
MODULE_SCOPE int TkMacOSXGenerateFocusEvent(Window window, int activeFlag);
MODULE_SCOPE int TkMacOSXGenerateParentMenuSelectEvent(MenuRef menu);
MODULE_SCOPE int TkMacOSXGenerateMenuSelectEvent(MenuRef menu,
MenuItemIndex index);
MODULE_SCOPE void TkMacOSXClearActiveMenu(MenuRef menu);
MODULE_SCOPE WindowClass TkMacOSXWindowClass(TkWindow *winPtr);
MODULE_SCOPE int TkMacOSXIsWindowZoomed(TkWindow *winPtr);
MODULE_SCOPE int TkGenerateButtonEventForXPointer(Window window);
MODULE_SCOPE EventModifiers TkMacOSXModifierState(void);
MODULE_SCOPE int TkMacOSXSetupDrawingContext(Drawable d, GC gc, int useCG,
TkMacOSXDrawingContext *dc);
MODULE_SCOPE void TkMacOSXRestoreDrawingContext(TkMacOSXDrawingContext *dc);
MODULE_SCOPE void TkMacOSXSetColorInPort(unsigned long pixel, int fg,
PixPatHandle penPat);
MODULE_SCOPE void TkMacOSXSetColorInContext(unsigned long pixel,
CGContextRef context);
MODULE_SCOPE int TkMacOSXRunTclEventLoop(void);
MODULE_SCOPE OSStatus TkMacOSXStartTclEventLoopCarbonTimer(void);
MODULE_SCOPE OSStatus TkMacOSXStopTclEventLoopCarbonTimer(void);
MODULE_SCOPE void TkMacOSXTrackingLoop(int tracking);
MODULE_SCOPE OSStatus TkMacOSXReceiveAndDispatchEvent(void);
MODULE_SCOPE void TkMacOSXInstallWindowCarbonEventHandler(Tcl_Interp *interp,
WindowRef window);
MODULE_SCOPE int TkMacOSXMakeFullscreen(TkWindow *winPtr, WindowRef window,
int fullscreen, Tcl_Interp *interp);
MODULE_SCOPE void TkMacOSXEnterExitFullscreen(TkWindow *winPtr, int active);
MODULE_SCOPE void TkMacOSXBringWindowForward(WindowRef wRef);
MODULE_SCOPE void* TkMacOSXGetNamedSymbol(const char* module,
const char* symbol);
/*
* Macro abstracting use of TkMacOSXGetNamedSymbol to init named symbols.
*/
#define TkMacOSXInitNamedSymbol(module, ret, symbol, ...) \
static ret (* symbol)(__VA_ARGS__) = (void*)(-1L); \
if (symbol == (void*)(-1L)) { \
symbol = TkMacOSXGetNamedSymbol(STRINGIFY(module), \
STRINGIFY(_##symbol)); \
}
/*
* Include the stubbed internal platform-specific API.
*/
#include "tkIntPlatDecls.h"
#endif /* _TKMACINT */
|