diff options
Diffstat (limited to 'macosx/tkMacOSXPrivate.h')
-rw-r--r-- | macosx/tkMacOSXPrivate.h | 335 |
1 files changed, 172 insertions, 163 deletions
diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h index b9c89e8..2f80b4d 100644 --- a/macosx/tkMacOSXPrivate.h +++ b/macosx/tkMacOSXPrivate.h @@ -3,90 +3,38 @@ * * Macros and declarations that are purely internal & private to TkAqua. * - * Copyright (c) 2005-2007 Daniel A. Steffen <das@users.sourceforge.net> + * Copyright (c) 2005-2009 Daniel A. Steffen <das@users.sourceforge.net> + * Copyright 2008-2009, Apple Inc. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXPrivate.h,v 1.10 2009/01/28 20:47:49 nijtmans Exp $ + * RCS: @(#) $Id: tkMacOSXPrivate.h,v 1.11 2009/06/29 14:35:01 das Exp $ */ #ifndef _TKMACPRIV #define _TKMACPRIV -#ifndef _TKMACINT -#include "tkMacOSXInt.h" -#endif - -/* 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 kThemeComboBox 16 -# define kThemeMiniSystemFont 109 -# 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 +#if !__OBJC__ +#error Objective-C compiler required #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) + +#define TextStyle MacTextStyle +#import <ApplicationServices/ApplicationServices.h> +#import <Cocoa/Cocoa.h> +#ifndef NO_CARBON_H +#import <Carbon/Carbon.h> #endif -#ifndef kHIToolboxVersionNumber10_4 -# define kHIToolboxVersionNumber10_4 (219) +#undef TextStyle +#import <objc/runtime.h> /* for sel_isEqual() */ + +#ifndef _TKMACINT +#include "tkMacOSXInt.h" #endif -#ifndef kHIToolboxVersionNumber10_5 -# define kHIToolboxVersionNumber10_5 (343) +#ifndef _TKMACDEFAULT +#include "tkMacOSXDefault.h" #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__) @@ -112,46 +60,6 @@ MODULE_SCOPE float tkMacOSXToolboxVersionNumber; #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 @@ -172,7 +80,7 @@ MODULE_SCOPE float tkMacOSXToolboxVersionNumber; #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 */ - + /* * Macros for DEBUG_ASSERT_MESSAGE et al from Debugging.h. */ @@ -187,30 +95,24 @@ MODULE_SCOPE float tkMacOSXToolboxVersionNumber; */ #ifdef TK_MAC_DEBUG +#define TKLog(f, ...) NSLog(f, ##__VA_ARGS__) + /* * Macro to do debug message output. */ #define TkMacOSXDbgMsg(m, ...) \ do { \ - fprintf(stderr, "%s:%d: %s(): " m "\n", strrchr(__FILE__, '/')+1, \ + TKLog(@"%s:%d: %s(): " m, 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); \ + TkMacOSXDbgMsg("%s failed: %d", #f, (int)(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 @@ -223,20 +125,11 @@ MODULE_SCOPE float tkMacOSXToolboxVersionNumber; } \ err;}) -/* - * Macro to check emptyness of shared QD tmp region before use in debug builds. - */ -#define TkMacOSXCheckTmpQdRgnEmpty() \ - do { \ - if (!EmptyRgn(tkMacOSXtmpQdRgn)) { \ - Tcl_Panic("tkMacOSXtmpQdRgn nonempty"); \ - } \ - } while(0) #else /* TK_MAC_DEBUG */ +#define TKLog(f, ...) #define TkMacOSXDbgMsg(m, ...) #define TkMacOSXDbgOSErr(f, err) #define ChkErr(f, ...) ({f(__VA_ARGS__);}) -#define TkMacOSXCheckTmpQdRgnEmpty() #endif /* TK_MAC_DEBUG */ /* @@ -247,30 +140,49 @@ MODULE_SCOPE float tkMacOSXToolboxVersionNumber; static ret (* symbol)(__VA_ARGS__) = (void*)(-1L); \ if (symbol == (void*)(-1L)) { \ symbol = TkMacOSXGetNamedSymbol(STRINGIFY(module), \ - STRINGIFY(_##symbol)); \ + STRINGIFY(symbol)); \ } - + +/* + * Macros for GC + */ + +#define TkMacOSXMakeUncollectable(x) ({ id o = (id)(x); \ + if (o) { if(tkMacOSXGCEnabled) CFRetain(o); } o; }) +#define TkMacOSXMakeUncollectableAndRetain(x) ({ id o = (id)(x); \ + if (o) { if(tkMacOSXGCEnabled) CFRetain(o); else [o retain]; } o; }) +#define TkMacOSXMakeCollectable(x) ({ id o = (id)(x); \ + if (o) { x = nil; if (tkMacOSXGCEnabled) CFRelease(o); } o; }) +#define TkMacOSXMakeCollectableAndRelease(x) ({ id o = (id)(x); \ + if (o) { x = nil; if (tkMacOSXGCEnabled) CFRelease(o); \ + else [o release]; } o; }) +#define TkMacOSXMakeCollectableAndAutorelease(x) ({ id o = (id)(x); \ + if (o) { x = nil; if (tkMacOSXGCEnabled) CFRelease(o); \ + else [o autorelease]; } o; }) + /* * Structure encapsulating current drawing environment. */ typedef struct TkMacOSXDrawingContext { CGContextRef context; - CGrafPtr port, savePort; - ThemeDrawingState saveState; - RgnHandle saveClip; + NSView *view; HIShapeRef clipRgn; - PixPatHandle penPat; - Rect portBounds; - Boolean portChanged; + CGRect portBounds; + int focusLocked; } TkMacOSXDrawingContext; /* * Variables internal to TkAqua. */ -MODULE_SCOPE RgnHandle tkMacOSXtmpQdRgn; -MODULE_SCOPE int tkMacOSXUseCGDrawing; +MODULE_SCOPE CGFloat tkMacOSXZeroScreenHeight; +MODULE_SCOPE CGFloat tkMacOSXZeroScreenTop; +MODULE_SCOPE int tkMacOSXGCEnabled; +MODULE_SCOPE long tkMacOSXMacOSXVersion; +#if TK_MAC_BUTTON_USE_COMPATIBILITY_METRICS +MODULE_SCOPE int tkMacOSXUseCompatibilityMetrics; +#endif /* * Prototypes for TkMacOSXRegion.c. @@ -308,19 +220,12 @@ MODULE_SCOPE OSStatus TkMacOSHIShapeUnion(HIShapeRef inShape1, MODULE_SCOPE void * TkMacOSXGetNamedSymbol(const char *module, const char *symbol); 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 int TkMacOSXGenerateFocusEvent(Window window, +MODULE_SCOPE int TkMacOSXGenerateFocusEvent(TkWindow *winPtr, 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); @@ -329,26 +234,130 @@ MODULE_SCOPE int TkMacOSXSetupDrawingContext(Drawable d, GC gc, int useCG, TkMacOSXDrawingContext *dcPtr); MODULE_SCOPE void TkMacOSXRestoreDrawingContext( TkMacOSXDrawingContext *dcPtr); -MODULE_SCOPE void TkMacOSXSetColorInPort(unsigned long pixel, int fg, - PixPatHandle penPat, CGrafPtr port); -MODULE_SCOPE void TkMacOSXSetColorInContext(unsigned long pixel, +MODULE_SCOPE void TkMacOSXSetColorInContext(GC gc, 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, + NSWindow *window, int fullscreen, Tcl_Interp *interp); MODULE_SCOPE void TkMacOSXEnterExitFullscreen(TkWindow *winPtr, int active); -MODULE_SCOPE void TkMacOSXBringWindowForward(WindowRef wRef); -MODULE_SCOPE WindowRef TkMacOSXDrawableWindow(Drawable drawable); +MODULE_SCOPE NSWindow* TkMacOSXDrawableWindow(Drawable drawable); +MODULE_SCOPE NSView* TkMacOSXDrawableView(MacDrawable *macWin); MODULE_SCOPE void TkMacOSXWinCGBounds(TkWindow *winPtr, CGRect *bounds); MODULE_SCOPE HIShapeRef TkMacOSXGetClipRgn(Drawable drawable); +MODULE_SCOPE void TkMacOSXInvalidateViewRegion(NSView *view, + HIShapeRef rgn); +MODULE_SCOPE CGImageRef TkMacOSXCreateCGImageWithDrawable(Drawable drawable); +MODULE_SCOPE NSImage* TkMacOSXGetNSImageWithTkImage(Display *display, + Tk_Image image, int width, int height); +MODULE_SCOPE NSImage* TkMacOSXGetNSImageWithBitmap(Display *display, + Pixmap bitmap, GC gc, int width, int height); +MODULE_SCOPE CGColorRef TkMacOSXCreateCGColor(GC gc, unsigned long pixel); +MODULE_SCOPE NSColor* TkMacOSXGetNSColor(GC gc, unsigned long pixel); MODULE_SCOPE Tcl_Obj * TkMacOSXGetStringObjFromCFString(CFStringRef str); +MODULE_SCOPE TkWindow* TkMacOSXGetTkWindow(NSWindow *w); +MODULE_SCOPE NSFont* TkMacOSXNSFontForFont(Tk_Font tkfont); +MODULE_SCOPE NSDictionary* TkMacOSXNSFontAttributesForFont(Tk_Font tkfont); +MODULE_SCOPE NSModalSession TkMacOSXGetModalSession(void); +MODULE_SCOPE void TkMacOSXSelDeadWindow(TkWindow *winPtr); +MODULE_SCOPE void TkMacOSXApplyWindowAttributes(TkWindow *winPtr, + NSWindow *macWindow); +MODULE_SCOPE int TkMacOSXStandardAboutPanelObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +MODULE_SCOPE int TkMacOSXIconBitmapObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); + +#pragma mark Private Objective-C Classes + +#define VISIBILITY_HIDDEN __attribute__((visibility("hidden"))) + +enum { tkMainMenu = 1, tkApplicationMenu, tkWindowsMenu, tkHelpMenu}; + +VISIBILITY_HIDDEN +@interface TKMenu : NSMenu { +@private + void *_tkMenu; + NSUInteger _tkOffset, _tkItemCount, _tkSpecial; +} +- (void)setSpecial:(NSUInteger)special; +- (BOOL)isSpecial:(NSUInteger)special; +@end + +VISIBILITY_HIDDEN +@interface TKApplication : NSApplication { +@private + Tcl_Interp *_eventInterp; + NSMenu *_servicesMenu; + TKMenu *_defaultMainMenu, *_defaultApplicationMenu; + NSArray *_defaultApplicationMenuItems, *_defaultWindowsMenuItems; + NSArray *_defaultHelpMenuItems; +} +@end +@interface TKApplication(TKInit) +- (NSString *)tkFrameworkImagePath:(NSString*)image; +@end +@interface TKApplication(TKEvent) +- (NSEvent *)tkProcessEvent:(NSEvent *)theEvent; +@end +@interface TKApplication(TKMouseEvent) +- (NSEvent *)tkProcessMouseEvent:(NSEvent *)theEvent; +@end +@interface TKApplication(TKKeyEvent) +- (NSEvent *)tkProcessKeyEvent:(NSEvent *)theEvent; +@end +@interface TKApplication(TKMenu) +- (void)tkSetMainMenu:(TKMenu *)menu; +@end +@interface TKApplication(TKClipboard) +- (void)tkProvidePasteboard:(TkDisplay *)dispPtr; +- (void)tkCheckPasteboard; +@end + +VISIBILITY_HIDDEN +@interface TKContentView : NSView { +@private + id _savedSubviews; + BOOL _subviewsSetAside; +} +@end + +VISIBILITY_HIDDEN +@interface TKWindow : NSWindow +@end + +#pragma mark NSMenu & NSMenuItem Utilities + +@interface NSMenu(TKUtils) ++ (id)menuWithTitle:(NSString *)title; ++ (id)menuWithTitle:(NSString *)title menuItems:(NSArray *)items; ++ (id)menuWithTitle:(NSString *)title submenus:(NSArray *)submenus; +- (NSMenuItem *)itemWithSubmenu:(NSMenu *)submenu; +- (NSMenuItem *)itemInSupermenu; +@end + +@interface NSMenuItem(TKUtils) ++ (id)itemWithSubmenu:(NSMenu *)submenu; ++ (id)itemWithTitle:(NSString *)title submenu:(NSMenu *)submenu; ++ (id)itemWithTitle:(NSString *)title action:(SEL)action; ++ (id)itemWithTitle:(NSString *)title action:(SEL)action + target:(id)target; ++ (id)itemWithTitle:(NSString *)title action:(SEL)action + keyEquivalent:(NSString *)keyEquivalent; ++ (id)itemWithTitle:(NSString *)title action:(SEL)action + target:(id)target keyEquivalent:(NSString *)keyEquivalent; ++ (id)itemWithTitle:(NSString *)title action:(SEL)action + keyEquivalent:(NSString *)keyEquivalent + keyEquivalentModifierMask:(NSUInteger)keyEquivalentModifierMask; ++ (id)itemWithTitle:(NSString *)title action:(SEL)action + target:(id)target keyEquivalent:(NSString *)keyEquivalent + keyEquivalentModifierMask:(NSUInteger)keyEquivalentModifierMask; +@end + +/* From WebKit/WebKit/mac/WebCoreSupport/WebChromeClient.mm: */ +@interface NSWindow(TKGrowBoxRect) +- (NSRect)_growBoxRect; +@end #endif /* _TKMACPRIV */ |