1/*
2 * tkMacOSXPrivate.h --
3 *
4 *	Macros and declarations that are purely internal & private to TkAqua.
5 *
6 * Copyright (c) 2005-2007 Daniel A. Steffen <das@users.sourceforge.net>
7 *
8 * See the file "license.terms" for information on usage and redistribution
9 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10 *
11 * RCS: @(#) $Id: tkMacOSXPrivate.h,v 1.1.2.5 2007/12/18 18:20:34 das Exp $
12 */
13
14#ifndef _TKMACPRIV
15#define _TKMACPRIV
16
17#ifndef _TKMACINT
18#include "tkMacOSXInt.h"
19#endif
20
21/* Define constants only available on Mac OS X 10.3 or later */
22#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
23    #define kEventAppAvailableWindowBoundsChanged 110
24    #define kEventParamTransactionID 'trns'
25    #define kEventParamWindowPartCode 'wpar'
26    #define typeWindowPartCode 'wpar'
27    #define kMenuAttrDoNotUseUserCommandKeys (1 << 7)
28    #define kSimpleWindowClass 18
29    #define kWindowDoesNotCycleAttribute (1L << 15)
30    #define kWindowAsyncDragAttribute (1L << 23)
31    #define kThemeBrushAlternatePrimaryHighlightColor -5
32    #define kThemeResizeUpCursor 19
33    #define kThemeResizeDownCursor 19
34    #define kThemeResizeUpDownCursor 19
35    #define kThemePoofCursor 19
36    #define kThemeBackgroundMetal 6
37    #define kThemeIncDecButtonSmall 21
38    #define kThemeIncDecButtonMini 22
39    #define kThemeMiniSystemFont 109
40    #define kAppearancePartUpButton 20
41    #define kAppearancePartDownButton 21
42    #define kAppearancePartPageUpArea 22
43    #define kAppearancePartPageDownArea 23
44    #define kAppearancePartIndicator 129
45    #define kUIModeAllSuppressed 4
46    #define FixedToInt(a) ((short)(((Fixed)(a) + fixed1/2) >> 16))
47    #define IntToFixed(a) ((Fixed)(a) << 16)
48#endif
49/* Define constants only available on Mac OS X 10.4 or later */
50#if MAC_OS_X_VERSION_MAX_ALLOWED < 1040
51    #define kWindowNoTitleBarAttribute (1L << 9)
52    #define kWindowMetalNoContentSeparatorAttribute (1L << 11)
53    #define kThemeDisclosureTriangle 6
54    #define kThemeBrushListViewOddRowBackground 56
55    #define kThemeBrushListViewEvenRowBackground 57
56    #define kThemeBrushListViewColumnDivider 58
57    #define kThemeMetricScrollBarMinThumbHeight 132
58    #define kThemeMetricSmallScrollBarMinThumbHeight 134
59    #define kThemeScrollBarMedium kThemeMediumScrollBar
60    #define kThemeScrollBarSmall kThemeSmallScrollBar
61    #ifdef __BIG_ENDIAN__
62    #define kCGBitmapByteOrder32Host (4 << 12)
63    #else
64    #define kCGBitmapByteOrder32Host (2 << 12)
65    #endif
66    #endif
67/* Define constants only available on Mac OS X 10.5 or later */
68#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050
69    #define kWindowUnifiedTitleAndToolbarAttribute (1L << 7)
70    #define kWindowTexturedSquareCornersAttribute (1L << 10)
71#endif
72/* HIToolbox version constants */
73#ifndef kHIToolboxVersionNumber10_3
74    #define kHIToolboxVersionNumber10_3 (145)
75#endif
76#ifndef kHIToolboxVersionNumber10_4
77    #define kHIToolboxVersionNumber10_4 (219)
78#endif
79#ifndef kHIToolboxVersionNumber10_5
80    #define kHIToolboxVersionNumber10_5 (343)
81#endif
82/* Macros for HIToolbox runtime version checking */
83MODULE_SCOPE float tkMacOSXToolboxVersionNumber;
84#define TK_IF_HI_TOOLBOX(vers, ...) \
85	tk_if_mac_os_x_min_10_##vers(tkMacOSXToolboxVersionNumber >= \
86	kHIToolboxVersionNumber10_##vers, 1, __VA_ARGS__)
87#define TK_ELSE_HI_TOOLBOX(vers, ...) \
88	tk_else_mac_os_x_min_10_##vers(__VA_ARGS__)
89/* Macros for Mac OS X API availability checking */
90#define TK_IF_MAC_OS_X_API(vers, symbol, ...) \
91	tk_if_mac_os_x_10_##vers(symbol != NULL, 1, __VA_ARGS__)
92#define TK_ELSE_MAC_OS_X(vers, ...) \
93	tk_else_mac_os_x_10_##vers(__VA_ARGS__)
94#define TK_IF_MAC_OS_X_API_COND(vers, symbol, cond, ...) \
95	tk_if_mac_os_x_10_##vers(symbol != NULL, cond, __VA_ARGS__)
96#define TK_ELSE(...) \
97	} else { __VA_ARGS__
98#define TK_ENDIF \
99	}
100/* Private macros that implement the checking macros above */
101#define tk_if_mac_os_x_yes(chk, cond, ...) \
102	if (cond) { __VA_ARGS__
103#define tk_else_mac_os_x_yes(...) \
104	} else {
105#define tk_if_mac_os_x_chk(chk, cond, ...) \
106	if ((chk) && (cond)) { __VA_ARGS__
107#define tk_else_mac_os_x_chk(...) \
108	} else { __VA_ARGS__
109#define tk_if_mac_os_x_no(chk, cond, ...) \
110	if (0) {
111#define tk_else_mac_os_x_no(...) \
112	} else { __VA_ARGS__
113/* Private mapping macros defined according to Mac OS X version requirements */
114/* 10.3 Panther */
115#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1030
116#define tk_if_mac_os_x_min_10_3		tk_if_mac_os_x_yes
117#define tk_else_mac_os_x_min_10_3	tk_else_mac_os_x_yes
118#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
119#define tk_if_mac_os_x_10_3		tk_if_mac_os_x_yes
120#define tk_else_mac_os_x_10_3		tk_else_mac_os_x_yes
121#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
122#else /* MAC_OS_X_VERSION_MIN_REQUIRED */
123#define tk_if_mac_os_x_min_10_3		tk_if_mac_os_x_chk
124#define tk_else_mac_os_x_min_10_3	tk_else_mac_os_x_chk
125#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
126#define tk_if_mac_os_x_10_3		tk_if_mac_os_x_chk
127#define tk_else_mac_os_x_10_3		tk_else_mac_os_x_chk
128#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
129#endif /* MAC_OS_X_VERSION_MIN_REQUIRED */
130#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
131#define tk_if_mac_os_x_10_3		tk_if_mac_os_x_no
132#define tk_else_mac_os_x_10_3		tk_else_mac_os_x_no
133#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
134/* 10.4 Tiger */
135#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1040
136#define tk_if_mac_os_x_min_10_4		tk_if_mac_os_x_yes
137#define tk_else_mac_os_x_min_10_4	tk_else_mac_os_x_yes
138#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
139#define tk_if_mac_os_x_10_4		tk_if_mac_os_x_yes
140#define tk_else_mac_os_x_10_4		tk_else_mac_os_x_yes
141#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
142#else /* MAC_OS_X_VERSION_MIN_REQUIRED */
143#define tk_if_mac_os_x_min_10_4		tk_if_mac_os_x_chk
144#define tk_else_mac_os_x_min_10_4	tk_else_mac_os_x_chk
145#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
146#define tk_if_mac_os_x_10_4		tk_if_mac_os_x_chk
147#define tk_else_mac_os_x_10_4		tk_else_mac_os_x_chk
148#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
149#endif /* MAC_OS_X_VERSION_MIN_REQUIRED */
150#if MAC_OS_X_VERSION_MAX_ALLOWED < 1040
151#define tk_if_mac_os_x_10_4		tk_if_mac_os_x_no
152#define tk_else_mac_os_x_10_4		tk_else_mac_os_x_no
153#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
154/* 10.5 Leopard */
155#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
156#define tk_if_mac_os_x_min_10_5		tk_if_mac_os_x_yes
157#define tk_else_mac_os_x_min_10_5	tk_else_mac_os_x_yes
158#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
159#define tk_if_mac_os_x_10_5		tk_if_mac_os_x_yes
160#define tk_else_mac_os_x_10_5		tk_else_mac_os_x_yes
161#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
162#else /* MAC_OS_X_VERSION_MIN_REQUIRED */
163#define tk_if_mac_os_x_min_10_5		tk_if_mac_os_x_chk
164#define tk_else_mac_os_x_min_10_5	tk_else_mac_os_x_chk
165#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
166#define tk_if_mac_os_x_10_5		tk_if_mac_os_x_chk
167#define tk_else_mac_os_x_10_5		tk_else_mac_os_x_chk
168#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
169#endif /* MAC_OS_X_VERSION_MIN_REQUIRED */
170#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050
171#define tk_if_mac_os_x_10_5		tk_if_mac_os_x_no
172#define tk_else_mac_os_x_10_5		tk_else_mac_os_x_no
173#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */
174
175/*
176 * Macros for DEBUG_ASSERT_MESSAGE et al from Debugging.h.
177 */
178
179#undef kComponentSignatureString
180#undef COMPONENT_SIGNATURE
181#define kComponentSignatureString "TkMacOSX"
182#define COMPONENT_SIGNATURE 'Tk  '
183
184/*
185 * Macros abstracting checks only active in a debug build.
186 */
187
188#ifdef TK_MAC_DEBUG
189/*
190 * Macro to do debug message output.
191 */
192#define TkMacOSXDbgMsg(m, ...) do { \
193	    fprintf(stderr, "%s:%d: %s(): " m "\n", strrchr(__FILE__, '/')+1, \
194	    __LINE__, __func__, ##__VA_ARGS__); \
195	} while (0)
196/*
197 * Macro to do debug API failure message output.
198 */
199#if !defined(DEBUGLEVEL) || !DEBUGLEVEL
200#define TkMacOSXDbgOSErr(f, err) do { \
201	    TkMacOSXDbgMsg("%s failed: %ld", #f, err); \
202	} while (0)
203#else
204#define TkMacOSXDbgOSErr(f, err) do { \
205	    DEBUG_ASSERT_MESSAGE(kComponentSignatureString, #f " failed:", \
206	    __func__, 0, strrchr(__FILE__, '/')+1, __LINE__, err); \
207	} while (0)
208#endif
209/*
210 * Macro to do very common check for noErr return from given API and output
211 * debug message in case of failure.
212 */
213#define ChkErr(f, ...) ({ \
214	OSStatus err = f(__VA_ARGS__); \
215	if (err != noErr) { \
216	    TkMacOSXDbgOSErr(f, err); \
217	} \
218	err;})
219/*
220 * Macro to check emptyness of shared QD tmp region before use in debug builds.
221 */
222#define TkMacOSXCheckTmpQdRgnEmpty() do { \
223	    if (!EmptyRgn(tkMacOSXtmpQdRgn)) { \
224		Tcl_Panic("tkMacOSXtmpQdRgn nonempty"); \
225	    } \
226	} while(0)
227#else /* TK_MAC_DEBUG */
228#define TkMacOSXDbgMsg(m, ...)
229#define TkMacOSXDbgOSErr(f, err)
230#define ChkErr(f, ...) ({f(__VA_ARGS__);})
231#define TkMacOSXCheckTmpQdRgnEmpty()
232#endif /* TK_MAC_DEBUG */
233
234/*
235 * Macro abstracting use of TkMacOSXGetNamedSymbol to init named symbols.
236 */
237
238#define TkMacOSXInitNamedSymbol(module, ret, symbol, ...) \
239    static ret (* symbol)(__VA_ARGS__) = (void*)(-1L); \
240    if (symbol == (void*)(-1L)) { \
241	symbol = TkMacOSXGetNamedSymbol(STRINGIFY(module), \
242		STRINGIFY(_##symbol)); \
243    }
244MODULE_SCOPE void* TkMacOSXGetNamedSymbol(const char* module,
245	const char* symbol);
246
247/*
248 * Structure encapsulating current drawing environment.
249 */
250
251typedef struct TkMacOSXDrawingContext {
252    CGContextRef context;
253    CGrafPtr port, savePort;
254    ThemeDrawingState saveState;
255    RgnHandle saveClip;
256    HIShapeRef clipRgn;
257    PixPatHandle penPat;
258    Rect portBounds;
259    Boolean portChanged;
260} TkMacOSXDrawingContext;
261
262/*
263 * Variables internal to TkAqua.
264 */
265
266MODULE_SCOPE RgnHandle tkMacOSXtmpQdRgn;
267MODULE_SCOPE int tkMacOSXUseCGDrawing;
268
269/*
270 * Prototypes for TkMacOSXRegion.c.
271 */
272
273#if 0
274MODULE_SCOPE void TkMacOSXEmtpyRegion(TkRegion r);
275MODULE_SCOPE int TkMacOSXIsEmptyRegion(TkRegion r);
276#endif
277MODULE_SCOPE HIShapeRef TkMacOSXGetNativeRegion(TkRegion r);
278MODULE_SCOPE void TkMacOSXSetWithNativeRegion(TkRegion r, HIShapeRef rgn);
279MODULE_SCOPE void TkMacOSXOffsetRegion(TkRegion r, short dx, short dy);
280MODULE_SCOPE HIShapeRef TkMacOSXHIShapeCreateEmpty(void);
281MODULE_SCOPE HIMutableShapeRef TkMacOSXHIShapeCreateMutableWithRect(
282	const CGRect *inRect);
283MODULE_SCOPE OSStatus  TkMacOSXHIShapeSetWithShape(
284	HIMutableShapeRef inDestShape, HIShapeRef inSrcShape);
285#if 0
286MODULE_SCOPE OSStatus TkMacOSXHIShapeSetWithRect(HIMutableShapeRef inShape,
287	const CGRect *inRect);
288#endif
289MODULE_SCOPE OSStatus TkMacOSHIShapeDifferenceWithRect(
290	HIMutableShapeRef inShape, const CGRect *inRect);
291MODULE_SCOPE OSStatus TkMacOSHIShapeUnionWithRect(HIMutableShapeRef inShape,
292	const CGRect *inRect);
293MODULE_SCOPE OSStatus TkMacOSHIShapeUnion(HIShapeRef inShape1,
294	HIShapeRef inShape2, HIMutableShapeRef outResult);
295
296/*
297 * Prototypes of TkAqua internal procs.
298 */
299
300MODULE_SCOPE void TkMacOSXDisplayChanged(Display *display);
301MODULE_SCOPE void TkMacOSXInitScrollbarMetrics(void);
302MODULE_SCOPE int TkMacOSXUseAntialiasedText(Tcl_Interp *interp, int enable);
303MODULE_SCOPE void TkMacOSXInitCarbonEvents(Tcl_Interp *interp);
304MODULE_SCOPE int TkMacOSXInitCGDrawing(Tcl_Interp *interp, int enable,
305	int antiAlias);
306MODULE_SCOPE void TkMacOSXInitKeyboard(Tcl_Interp *interp);
307MODULE_SCOPE int TkMacOSXGenerateFocusEvent(Window window, int activeFlag);
308MODULE_SCOPE int TkMacOSXGenerateParentMenuSelectEvent(MenuRef menu);
309MODULE_SCOPE int TkMacOSXGenerateMenuSelectEvent(MenuRef menu,
310	MenuItemIndex index);
311MODULE_SCOPE void TkMacOSXClearActiveMenu(MenuRef menu);
312MODULE_SCOPE WindowClass TkMacOSXWindowClass(TkWindow *winPtr);
313MODULE_SCOPE int TkMacOSXIsWindowZoomed(TkWindow *winPtr);
314MODULE_SCOPE int TkGenerateButtonEventForXPointer(Window window);
315MODULE_SCOPE EventModifiers TkMacOSXModifierState(void);
316MODULE_SCOPE int TkMacOSXSetupDrawingContext(Drawable d, GC gc, int useCG,
317    TkMacOSXDrawingContext *dcPtr);
318MODULE_SCOPE void TkMacOSXRestoreDrawingContext(TkMacOSXDrawingContext *dcPtr);
319MODULE_SCOPE void TkMacOSXSetColorInPort(unsigned long pixel, int fg,
320	PixPatHandle penPat, CGrafPtr port);
321MODULE_SCOPE void TkMacOSXSetColorInContext(unsigned long pixel,
322	CGContextRef context);
323MODULE_SCOPE int TkMacOSXRunTclEventLoop(void);
324MODULE_SCOPE OSStatus TkMacOSXStartTclEventLoopCarbonTimer(void);
325MODULE_SCOPE OSStatus TkMacOSXStopTclEventLoopCarbonTimer(void);
326MODULE_SCOPE void TkMacOSXTrackingLoop(int tracking);
327MODULE_SCOPE OSStatus TkMacOSXReceiveAndDispatchEvent(void);
328MODULE_SCOPE void TkMacOSXInstallWindowCarbonEventHandler(Tcl_Interp *interp,
329	WindowRef window);
330MODULE_SCOPE int TkMacOSXMakeFullscreen(TkWindow *winPtr, WindowRef window,
331	int fullscreen, Tcl_Interp *interp);
332MODULE_SCOPE void TkMacOSXEnterExitFullscreen(TkWindow *winPtr, int active);
333MODULE_SCOPE void TkMacOSXBringWindowForward(WindowRef wRef);
334MODULE_SCOPE WindowRef TkMacOSXDrawableWindow(Drawable drawable);
335MODULE_SCOPE void TkMacOSXWinCGBounds(TkWindow *winPtr, CGRect *bounds);
336MODULE_SCOPE HIShapeRef TkMacOSXGetClipRgn(Drawable drawable);
337
338#endif /* _TKMACPRIV */
339