summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorKevin Walzer <kw@codebykevin.com>2019-02-28 03:51:04 (GMT)
committerKevin Walzer <kw@codebykevin.com>2019-02-28 03:51:04 (GMT)
commitc0f932d459554bd8176b87c10cae2a3b1788027b (patch)
treefb54f87bb8a54015ac3f216e7b6b0ec29047d5ba /macosx
parent51183fa34e5f5f2554a87084acf36cc8e14d1b21 (diff)
downloadtk-c0f932d459554bd8176b87c10cae2a3b1788027b.zip
tk-c0f932d459554bd8176b87c10cae2a3b1788027b.tar.gz
tk-c0f932d459554bd8176b87c10cae2a3b1788027b.tar.bz2
Add launcher code, update docs
Diffstat (limited to 'macosx')
-rw-r--r--macosx/Wish-Info.plist.in11
-rw-r--r--macosx/tkMacOSXHLEvents.c24
-rw-r--r--macosx/tkMacOSXLaunchServices.c193
-rw-r--r--macosx/tkMacOSXPrivate.h864
-rw-r--r--macosx/tkMacOSXServices.c394
5 files changed, 858 insertions, 628 deletions
diff --git a/macosx/Wish-Info.plist.in b/macosx/Wish-Info.plist.in
index 9f8c225..ba63ffb 100644
--- a/macosx/Wish-Info.plist.in
+++ b/macosx/Wish-Info.plist.in
@@ -36,6 +36,17 @@
<string>Viewer</string>
</dict>
</array>
+ <key>CFBundleURLTypes</key>
+ <array>
+ <dict>
+ <key>CFBundleURLSchemes</key>
+ <array>
+ <string></string>
+ </array>
+ <key>CFBundleURLName</key>
+ <string></string>
+ </dict>
+ </array>
<key>CFBundleExecutable</key>
<string>Wish</string>
<key>CFBundleGetInfoString</key>
diff --git a/macosx/tkMacOSXHLEvents.c b/macosx/tkMacOSXHLEvents.c
index 9b874a5..474ceaf 100644
--- a/macosx/tkMacOSXHLEvents.c
+++ b/macosx/tkMacOSXHLEvents.c
@@ -246,6 +246,25 @@ static int ReallyKillMe(Tcl_Event *eventPtr, int flags);
}
return;
}
+
+- (void)handleURLEvent:(NSAppleEventDescriptor*)event
+ withReplyEvent:(NSAppleEventDescriptor*)replyEvent
+{
+ NSString* url = [[event paramDescriptorForKeyword:keyDirectObject]
+ stringValue];
+ Tcl_DString launch;
+ Tcl_DStringInit(&launch);
+ if (Tcl_FindCommand(_eventInterp, "::tk::mac::LaunchURL", NULL, 0)){
+ Tcl_DStringAppend(&command, "::tk::mac::LaunchURL", -1);
+ }
+ Tcl_DStringAppendElement(&launch, url);
+ int tclErr = Tcl_EvalEx(_eventInterp, Tcl_DStringValue(&launch),
+ Tcl_DStringLength(&launch), TCL_EVAL_GLOBAL);
+ if (tclErr!= TCL_OK) {
+ Tcl_BackgroundException(_eventInterp, tclErr);
+ }
+ }
+}
@end
#pragma mark -
@@ -415,6 +434,11 @@ TkMacOSXInitAppleEvents(
[aeManager setEventHandler:NSApp
andSelector:@selector(handleDoScriptEvent:withReplyEvent:)
forEventClass:kAEMiscStandards andEventID:kAEDoScript];
+
+ [aeManager setEventHandler:NSApp
+ andSelector:@selector(handleURLEvent:withReplyEvent:)
+ forEventClass:kInternetEventClass andEventID:kAEGetURL];
+
}
}
diff --git a/macosx/tkMacOSXLaunchServices.c b/macosx/tkMacOSXLaunchServices.c
new file mode 100644
index 0000000..6fc6758
--- /dev/null
+++ b/macosx/tkMacOSXLaunchServices.c
@@ -0,0 +1,193 @@
+/*
+ * tkMacOSXLaunchServices.c --
+ * Launches URL's using native API's on OS X without shelling out to "/usr/bin/open". Also gets and sets default app handlers.
+ * Copyright (c) 2015-2019 Kevin Walzer/WordTech Communications LLC.
+ *
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ *
+ */
+
+#include <tcl.h>
+#include <tk.h>
+#undef panic
+#include <CoreFoundation/CoreFoundation.h>
+#include <CoreServices/CoreServices.h>
+#include <Carbon/Carbon.h>
+#include <ApplicationServices/ApplicationServices.h>
+#define panic Tcl_Panic
+
+
+/*Tcl function to launch URL with default app.*/
+int LaunchURL(ClientData cd, Tcl_Interp *ip, int objc, Tcl_Obj *CONST objv[]) {
+
+ if(objc != 2) {
+ Tcl_WrongNumArgs(ip, 1, objv, "url");
+ return TCL_ERROR;
+ }
+
+
+ /* Get url string, convert to CFURL. */
+ CFStringRef url = CFStringCreateWithCString(NULL, Tcl_GetString(objv[1]),
+ kCFStringEncodingUTF8);
+ CFURLRef launchurl = CFURLCreateWithString(kCFAllocatorDefault, url, NULL);
+ CFRelease(url);
+
+ /* Fire url in default app. */
+ LSOpenCFURLRef(launchurl, NULL);
+
+ CFRelease(launchurl);
+
+ return TCL_OK;
+
+}
+
+/*Tcl function to launch file with default app.*/
+int LaunchFile(ClientData cd, Tcl_Interp *ip, int objc, Tcl_Obj *CONST objv[]) {
+
+ if(objc != 2) {
+ Tcl_WrongNumArgs(ip, 1, objv, "file");
+ return TCL_ERROR;
+ }
+
+ /* Get url string, convert to CFURL. */
+ CFStringRef url = CFStringCreateWithCString(NULL, Tcl_GetString(objv[1]),
+ kCFStringEncodingUTF8);
+ CFRelease(url);
+
+ CFURLRef launchurl = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, url, kCFURLPOSIXPathStyle, false);
+
+ /* Fire url in default app. */
+ LSOpenCFURLRef(launchurl, NULL);
+ CFRelease(launchurl);
+
+ return TCL_OK;
+
+}
+
+
+/*Tcl function to get path to app bundle.*/
+int GetAppPath(ClientData cd, Tcl_Interp *ip, int objc, Tcl_Obj *CONST objv[]) {
+
+ CFURLRef mainBundleURL = CFBundleCopyBundleURL(CFBundleGetMainBundle());
+
+
+ /* Convert the URL reference into a string reference. */
+ CFStringRef appPath = CFURLCopyFileSystemPath(mainBundleURL, kCFURLPOSIXPathStyle);
+
+ /* Get the system encoding method. */
+ CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
+
+ /* Convert the string reference into a C string. */
+ char *path = CFStringGetCStringPtr(appPath, encodingMethod);
+
+ Tcl_SetResult(ip, path, NULL);
+
+ CFRelease(mainBundleURL);
+ CFRelease(appPath);
+ return TCL_OK;
+
+}
+
+/*Tcl function to launch file with default app.*/
+int GetDefaultApp(ClientData cd, Tcl_Interp *ip, int objc, Tcl_Obj *CONST objv[]) {
+
+ if(objc != 2) {
+ Tcl_WrongNumArgs(ip, 1, objv, "url");
+ return TCL_ERROR;
+ }
+
+ /* Get url string, convert to CFStringRef. */
+ CFStringRef url = CFStringCreateWithCString(NULL, Tcl_GetString(objv[1]),
+ kCFStringEncodingUTF8);
+
+ CFStringRef defaultApp;
+ defaultApp = LSCopyDefaultHandlerForURLScheme(url);
+
+ OSStatus result;
+ CFURLRef appURL = NULL;
+ result = LSFindApplicationForInfo(kLSUnknownCreator, defaultApp, NULL, NULL, &appURL);
+
+ /* Convert the URL reference into a string reference. */
+ CFStringRef appPath = CFURLCopyFileSystemPath(appURL, kCFURLPOSIXPathStyle);
+
+ /* Get the system encoding method. */
+ CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
+
+ /* Convert the string reference into a C string. */
+ char *path = CFStringGetCStringPtr(appPath, encodingMethod);
+
+ Tcl_SetResult(ip, path, NULL);
+
+ CFRelease(defaultApp);
+ CFRelease(appPath);
+ CFRelease(url);
+
+ return TCL_OK;
+
+}
+
+/*Tcl function to set default app for URL.*/
+int SetDefaultApp(ClientData cd, Tcl_Interp *ip, int objc, Tcl_Obj *CONST objv[]) {
+
+ if(objc != 3) {
+ Tcl_WrongNumArgs(ip, 1, objv, "url path");
+ return TCL_ERROR;
+ }
+
+ /* Get url and path strings, convert to CFStringRef. */
+ CFStringRef url = CFStringCreateWithCString(NULL, Tcl_GetString(objv[1]),
+ kCFStringEncodingUTF8);
+ CFURLRef appURL = NULL;
+ CFBundleRef bundle = NULL;
+
+ CFStringRef apppath = CFStringCreateWithCString(NULL, Tcl_GetString(objv[2]), kCFStringEncodingUTF8);
+
+ /* Convert filepath to URL, create bundle object, get bundle ID. */
+ appURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, apppath, kCFURLPOSIXPathStyle, false);
+ bundle = CFBundleCreate(NULL, appURL);
+
+ CFStringRef bundleID = CFBundleGetIdentifier(bundle);
+
+ /* Finally, set default app. */
+ OSStatus err;
+ err= LSSetDefaultHandlerForURLScheme(url, bundleID);
+
+ /* Free memory. */
+ CFRelease(url);
+ CFRelease(apppath);
+ CFRelease(bundleID);
+
+ return TCL_OK;
+
+}
+
+
+/*Initalize the package in the tcl interpreter, create Tcl commands. */
+int TkMacOSXLauncher_Init (Tcl_Interp *interp) {
+
+
+ if (Tcl_InitStubs(interp, "8.5", 0) == NULL) {
+ return TCL_ERROR;
+ }
+ if (Tk_InitStubs(interp, "8.5", 0) == NULL) {
+ return TCL_ERROR;
+ }
+
+
+ Tcl_CreateObjCommand(interp, "::tk::mac::LaunchURL", LaunchURL,(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
+ Tcl_CreateObjCommand(interp, "::tk::mac::LaunchFile", LaunchFile,(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
+ Tcl_CreateObjCommand(interp, "::tk::mac::GetAppPath", GetAppPath,(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
+ Tcl_CreateObjCommand(interp, "::tk::mac::GetDefaultApp", GetDefaultApp,(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
+ Tcl_CreateObjCommand(interp, "::tk::mac::SetDefaultApp",SetDefaultApp,(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
+
+
+ return TCL_OK;
+
+}
+
+
+
+
+
+
diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h
index 6076261..affb9ea 100644
--- a/macosx/tkMacOSXPrivate.h
+++ b/macosx/tkMacOSXPrivate.h
@@ -1,431 +1,433 @@
-/*
- * tkMacOSXPrivate.h --
- *
- * Macros and declarations that are purely internal & private to TkAqua.
- *
- * 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$
- */
-
-#ifndef _TKMACPRIV
-#define _TKMACPRIV
-
-#if !__OBJC__
-#error Objective-C compiler required
-#endif
-
-#define TextStyle MacTextStyle
-#import <ApplicationServices/ApplicationServices.h>
-#import <Cocoa/Cocoa.h>
-#ifndef NO_CARBON_H
-#import <Carbon/Carbon.h>
-#endif
-#undef TextStyle
-#import <objc/runtime.h> /* for sel_isEqual() */
-
-#ifndef _TKMACINT
-#include "tkMacOSXInt.h"
-#endif
-#ifndef _TKMACDEFAULT
-#include "tkMacOSXDefault.h"
-#endif
-
-/* 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__
-
-/*
- * Macros for DEBUG_ASSERT_MESSAGE et al from Debugging.h.
- */
-
-#undef kComponentSignatureString
-#undef COMPONENT_SIGNATURE
-#define kComponentSignatureString "TkMacOSX"
-#define COMPONENT_SIGNATURE 'Tk '
-
-/*
- * Macros abstracting checks only active in a debug build.
- */
-
-#ifdef TK_MAC_DEBUG
-#define TKLog(f, ...) NSLog(f, ##__VA_ARGS__)
-
-/*
- * Macro to do debug message output.
- */
-#define TkMacOSXDbgMsg(m, ...) \
- do { \
- TKLog(@"%s:%d: %s(): " m, strrchr(__FILE__, '/')+1, \
- __LINE__, __func__, ##__VA_ARGS__); \
- } while (0)
-
-/*
- * Macro to do debug API failure message output.
- */
-#define TkMacOSXDbgOSErr(f, err) \
- do { \
- TkMacOSXDbgMsg("%s failed: %d", #f, (int)(err)); \
- } while (0)
-
-/*
- * 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;})
-
-#else /* TK_MAC_DEBUG */
-#define TKLog(f, ...)
-#define TkMacOSXDbgMsg(m, ...)
-#define TkMacOSXDbgOSErr(f, err)
-#define ChkErr(f, ...) ({f(__VA_ARGS__);})
-#endif /* TK_MAC_DEBUG */
-
-/*
- * 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)); \
- }
-
-/*
- * Structure encapsulating current drawing environment.
- */
-
-typedef struct TkMacOSXDrawingContext {
- CGContextRef context;
- NSView *view;
- HIShapeRef clipRgn;
- CGRect portBounds;
-} TkMacOSXDrawingContext;
-
-/*
- * Variables internal to TkAqua.
- */
-
-MODULE_SCOPE CGFloat tkMacOSXZeroScreenHeight;
-MODULE_SCOPE CGFloat tkMacOSXZeroScreenTop;
-MODULE_SCOPE long tkMacOSXMacOSXVersion;
-
-/*
- * Prototypes for TkMacOSXRegion.c.
- */
-
-#if 0
-MODULE_SCOPE void TkMacOSXEmtpyRegion(TkRegion r);
-MODULE_SCOPE int TkMacOSXIsEmptyRegion(TkRegion r);
-#endif
-MODULE_SCOPE HIShapeRef TkMacOSXGetNativeRegion(TkRegion r);
-MODULE_SCOPE void TkMacOSXSetWithNativeRegion(TkRegion r,
- HIShapeRef rgn);
-MODULE_SCOPE void TkMacOSXOffsetRegion(TkRegion r, short dx, short dy);
-MODULE_SCOPE HIShapeRef TkMacOSXHIShapeCreateEmpty(void);
-MODULE_SCOPE HIMutableShapeRef TkMacOSXHIShapeCreateMutableWithRect(
- const CGRect *inRect);
-MODULE_SCOPE OSStatus TkMacOSXHIShapeSetWithShape(
- HIMutableShapeRef inDestShape,
- HIShapeRef inSrcShape);
-#if 0
-MODULE_SCOPE OSStatus TkMacOSXHIShapeSetWithRect(HIMutableShapeRef inShape,
- const CGRect *inRect);
-#endif
-MODULE_SCOPE OSStatus TkMacOSHIShapeDifferenceWithRect(
- HIMutableShapeRef inShape, const CGRect *inRect);
-MODULE_SCOPE OSStatus TkMacOSHIShapeUnionWithRect(HIMutableShapeRef inShape,
- const CGRect *inRect);
-MODULE_SCOPE OSStatus TkMacOSHIShapeUnion(HIShapeRef inShape1,
- HIShapeRef inShape2, HIMutableShapeRef outResult);
-
-/*
- * Prototypes of TkAqua internal procs.
- */
-
-MODULE_SCOPE void * TkMacOSXGetNamedSymbol(const char *module,
- const char *symbol);
-MODULE_SCOPE void TkMacOSXDisplayChanged(Display *display);
-MODULE_SCOPE int TkMacOSXUseAntialiasedText(Tcl_Interp *interp,
- int enable);
-MODULE_SCOPE int TkMacOSXInitCGDrawing(Tcl_Interp *interp, int enable,
- int antiAlias);
-MODULE_SCOPE int TkMacOSXGenerateFocusEvent(TkWindow *winPtr,
- int activeFlag);
-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 NSBitmapImageRep* TkMacOSXBitmapRepFromDrawableRect(Drawable drawable,
- int x, int y, unsigned int width, unsigned int height);
-MODULE_SCOPE CGImageRef TkMacOSXCreateCGImageWithXImage(XImage *image);
-MODULE_SCOPE void TkMacOSXDrawCGImage(Drawable d, GC gc, CGContextRef context,
- CGImageRef image, unsigned long imageForeground,
- unsigned long imageBackground, CGRect imageBounds,
- CGRect srcBounds, CGRect dstBounds);
-MODULE_SCOPE int TkMacOSXSetupDrawingContext(Drawable d, GC gc,
- int useCG, TkMacOSXDrawingContext *dcPtr);
-MODULE_SCOPE void TkMacOSXRestoreDrawingContext(
- TkMacOSXDrawingContext *dcPtr);
-MODULE_SCOPE void TkMacOSXSetColorInContext(GC gc, unsigned long pixel,
- CGContextRef context);
-MODULE_SCOPE int TkMacOSXMakeFullscreen(TkWindow *winPtr,
- NSWindow *window, int fullscreen,
- Tcl_Interp *interp);
-MODULE_SCOPE void TkMacOSXEnterExitFullscreen(TkWindow *winPtr,
- int active);
-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 CGContextRef TkMacOSXGetCGContextForDrawable(Drawable drawable);
-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[]);
-MODULE_SCOPE int TkMacOSXRegisterServiceWidgetObjCmd(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
-
-@interface TKMenu(TKMenuDelegate) <NSMenuDelegate>
-@end
-
-VISIBILITY_HIDDEN
-@interface TKApplication : NSApplication {
-@private
- Tcl_Interp *_eventInterp;
- NSMenu *_servicesMenu;
- TKMenu *_defaultMainMenu, *_defaultApplicationMenu;
- NSArray *_defaultApplicationMenuItems, *_defaultWindowsMenuItems;
- NSArray *_defaultHelpMenuItems;
- NSWindow *_windowWithMouse;
- NSAutoreleasePool *_mainPool;
-#ifdef __i386__
- /* The Objective C runtime used on i386 requires this. */
- int _poolLock;
- int _macMinorVersion;
- Bool _isDrawing;
-#endif
-}
-@property int poolLock;
-@property int macMinorVersion;
-@property Bool isDrawing;
-
-@end
-@interface TKApplication(TKInit)
-- (NSString *)tkFrameworkImagePath:(NSString*)image;
-- (void)_resetAutoreleasePool;
-- (void)_lockAutoreleasePool;
-- (void)_unlockAutoreleasePool;
-@end
-@interface TKApplication(TKKeyboard)
-- (void) keyboardChanged: (NSNotification *) notification;
-@end
-@interface TKApplication(TKWindowEvent) <NSApplicationDelegate>
-- (void) _setupWindowNotifications;
-@end
-@interface TKApplication(TKMenu)
-- (void)tkSetMainMenu:(TKMenu *)menu;
-@end
-@interface TKApplication(TKMenus)
-- (void) _setupMenus;
-@end
-@interface NSApplication(TKNotify)
-/* We need to declare this hidden method. */
-- (void) _modalSession: (NSModalSession) session sendEvent: (NSEvent *) event;
-@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(TKClipboard)
-- (void)tkProvidePasteboard:(TkDisplay *)dispPtr;
-- (void)tkCheckPasteboard;
-@end
-@interface TKApplication(TKHLEvents)
-- (void) terminate: (id) sender;
-- (void) preferences: (id) sender;
-- (void) handleQuitApplicationEvent: (NSAppleEventDescriptor *)event
- withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
-- (void) handleOpenApplicationEvent: (NSAppleEventDescriptor *)event
- withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
-- (void) handleReopenApplicationEvent: (NSAppleEventDescriptor *)event
- withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
-- (void) handleShowPreferencesEvent: (NSAppleEventDescriptor *)event
- withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
-- (void) handleOpenDocumentsEvent: (NSAppleEventDescriptor *)event
- withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
-- (void) handlePrintDocumentsEvent: (NSAppleEventDescriptor *)event
- withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
-- (void) handleDoScriptEvent: (NSAppleEventDescriptor *)event
- withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
-@end
-
-VISIBILITY_HIDDEN
-@interface TKContentView : NSView <NSTextInput>
-{
- NSString *privateWorkingText;
-}
-@end
-
-@interface TKContentView(TKKeyEvent)
-- (void) deleteWorkingText;
-@end
-
-@interface TKContentView(TKWindowEvent)
-- (void) drawRect: (NSRect) rect;
-- (void) generateExposeEvents: (HIShapeRef) shape;
-- (void) tkToolbarButton: (id) sender;
-- (BOOL) isOpaque;
-- (BOOL) wantsDefaultClipping;
-- (BOOL) acceptsFirstResponder;
-- (void) keyDown: (NSEvent *) theEvent;
-@end
-
-@interface NSWindow(TKWm)
-- (NSPoint) tkConvertPointToScreen:(NSPoint)point;
-- (NSPoint) tkConvertPointFromScreen:(NSPoint)point;
-@end
-
-VISIBILITY_HIDDEN
-@interface TKWindow : NSWindow
-@end
-
-@interface TKWindow(TKWm)
-- (void) tkLayoutChanged;
-@end
-
-@interface NSDrawerWindow : NSWindow
-{
- id _i1, _i2;
-}
-@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
-
-@interface NSColorPanel(TKDialog)
-- (void) _setUseModalAppearance: (BOOL) flag;
-@end
-
-@interface NSFont(TKFont)
-- (NSFont *) bestMatchingFontForCharacters: (const UTF16Char *) characters
- length: (NSUInteger) length attributes: (NSDictionary *) attributes
- actualCoveredLength: (NSUInteger *) coveredLength;
-@end
-
-/*
- * This method of NSApplication is not declared in NSApplication.h so we
- * declare it here to be a method of the TKMenu category.
- */
-
-@interface NSApplication(TKMenu)
-- (void) setAppleMenu: (NSMenu *) menu;
-@end
-
-#endif /* _TKMACPRIV */
-
-/*
- * Local Variables:
- * mode: objc
- * c-basic-offset: 4
- * fill-column: 79
- * coding: utf-8
- * End:
- */
+/*
+ * tkMacOSXPrivate.h --
+ *
+ * Macros and declarations that are purely internal & private to TkAqua.
+ *
+ * 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$
+ */
+
+#ifndef _TKMACPRIV
+#define _TKMACPRIV
+
+#if !__OBJC__
+#error Objective-C compiler required
+#endif
+
+#define TextStyle MacTextStyle
+#import <ApplicationServices/ApplicationServices.h>
+#import <Cocoa/Cocoa.h>
+#ifndef NO_CARBON_H
+#import <Carbon/Carbon.h>
+#endif
+#undef TextStyle
+#import <objc/runtime.h> /* for sel_isEqual() */
+
+#ifndef _TKMACINT
+#include "tkMacOSXInt.h"
+#endif
+#ifndef _TKMACDEFAULT
+#include "tkMacOSXDefault.h"
+#endif
+
+/* 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__
+
+/*
+ * Macros for DEBUG_ASSERT_MESSAGE et al from Debugging.h.
+ */
+
+#undef kComponentSignatureString
+#undef COMPONENT_SIGNATURE
+#define kComponentSignatureString "TkMacOSX"
+#define COMPONENT_SIGNATURE 'Tk '
+
+/*
+ * Macros abstracting checks only active in a debug build.
+ */
+
+#ifdef TK_MAC_DEBUG
+#define TKLog(f, ...) NSLog(f, ##__VA_ARGS__)
+
+/*
+ * Macro to do debug message output.
+ */
+#define TkMacOSXDbgMsg(m, ...) \
+ do { \
+ TKLog(@"%s:%d: %s(): " m, strrchr(__FILE__, '/')+1, \
+ __LINE__, __func__, ##__VA_ARGS__); \
+ } while (0)
+
+/*
+ * Macro to do debug API failure message output.
+ */
+#define TkMacOSXDbgOSErr(f, err) \
+ do { \
+ TkMacOSXDbgMsg("%s failed: %d", #f, (int)(err)); \
+ } while (0)
+
+/*
+ * 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;})
+
+#else /* TK_MAC_DEBUG */
+#define TKLog(f, ...)
+#define TkMacOSXDbgMsg(m, ...)
+#define TkMacOSXDbgOSErr(f, err)
+#define ChkErr(f, ...) ({f(__VA_ARGS__);})
+#endif /* TK_MAC_DEBUG */
+
+/*
+ * 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)); \
+ }
+
+/*
+ * Structure encapsulating current drawing environment.
+ */
+
+typedef struct TkMacOSXDrawingContext {
+ CGContextRef context;
+ NSView *view;
+ HIShapeRef clipRgn;
+ CGRect portBounds;
+} TkMacOSXDrawingContext;
+
+/*
+ * Variables internal to TkAqua.
+ */
+
+MODULE_SCOPE CGFloat tkMacOSXZeroScreenHeight;
+MODULE_SCOPE CGFloat tkMacOSXZeroScreenTop;
+MODULE_SCOPE long tkMacOSXMacOSXVersion;
+
+/*
+ * Prototypes for TkMacOSXRegion.c.
+ */
+
+#if 0
+MODULE_SCOPE void TkMacOSXEmtpyRegion(TkRegion r);
+MODULE_SCOPE int TkMacOSXIsEmptyRegion(TkRegion r);
+#endif
+MODULE_SCOPE HIShapeRef TkMacOSXGetNativeRegion(TkRegion r);
+MODULE_SCOPE void TkMacOSXSetWithNativeRegion(TkRegion r,
+ HIShapeRef rgn);
+MODULE_SCOPE void TkMacOSXOffsetRegion(TkRegion r, short dx, short dy);
+MODULE_SCOPE HIShapeRef TkMacOSXHIShapeCreateEmpty(void);
+MODULE_SCOPE HIMutableShapeRef TkMacOSXHIShapeCreateMutableWithRect(
+ const CGRect *inRect);
+MODULE_SCOPE OSStatus TkMacOSXHIShapeSetWithShape(
+ HIMutableShapeRef inDestShape,
+ HIShapeRef inSrcShape);
+#if 0
+MODULE_SCOPE OSStatus TkMacOSXHIShapeSetWithRect(HIMutableShapeRef inShape,
+ const CGRect *inRect);
+#endif
+MODULE_SCOPE OSStatus TkMacOSHIShapeDifferenceWithRect(
+ HIMutableShapeRef inShape, const CGRect *inRect);
+MODULE_SCOPE OSStatus TkMacOSHIShapeUnionWithRect(HIMutableShapeRef inShape,
+ const CGRect *inRect);
+MODULE_SCOPE OSStatus TkMacOSHIShapeUnion(HIShapeRef inShape1,
+ HIShapeRef inShape2, HIMutableShapeRef outResult);
+
+/*
+ * Prototypes of TkAqua internal procs.
+ */
+
+MODULE_SCOPE void * TkMacOSXGetNamedSymbol(const char *module,
+ const char *symbol);
+MODULE_SCOPE void TkMacOSXDisplayChanged(Display *display);
+MODULE_SCOPE int TkMacOSXUseAntialiasedText(Tcl_Interp *interp,
+ int enable);
+MODULE_SCOPE int TkMacOSXInitCGDrawing(Tcl_Interp *interp, int enable,
+ int antiAlias);
+MODULE_SCOPE int TkMacOSXGenerateFocusEvent(TkWindow *winPtr,
+ int activeFlag);
+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 NSBitmapImageRep* TkMacOSXBitmapRepFromDrawableRect(Drawable drawable,
+ int x, int y, unsigned int width, unsigned int height);
+MODULE_SCOPE CGImageRef TkMacOSXCreateCGImageWithXImage(XImage *image);
+MODULE_SCOPE void TkMacOSXDrawCGImage(Drawable d, GC gc, CGContextRef context,
+ CGImageRef image, unsigned long imageForeground,
+ unsigned long imageBackground, CGRect imageBounds,
+ CGRect srcBounds, CGRect dstBounds);
+MODULE_SCOPE int TkMacOSXSetupDrawingContext(Drawable d, GC gc,
+ int useCG, TkMacOSXDrawingContext *dcPtr);
+MODULE_SCOPE void TkMacOSXRestoreDrawingContext(
+ TkMacOSXDrawingContext *dcPtr);
+MODULE_SCOPE void TkMacOSXSetColorInContext(GC gc, unsigned long pixel,
+ CGContextRef context);
+MODULE_SCOPE int TkMacOSXMakeFullscreen(TkWindow *winPtr,
+ NSWindow *window, int fullscreen,
+ Tcl_Interp *interp);
+MODULE_SCOPE void TkMacOSXEnterExitFullscreen(TkWindow *winPtr,
+ int active);
+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 CGContextRef TkMacOSXGetCGContextForDrawable(Drawable drawable);
+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[]);
+MODULE_SCOPE int TkMacOSXRegisterServiceWidgetObjCmd(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
+
+@interface TKMenu(TKMenuDelegate) <NSMenuDelegate>
+@end
+
+VISIBILITY_HIDDEN
+@interface TKApplication : NSApplication {
+@private
+ Tcl_Interp *_eventInterp;
+ NSMenu *_servicesMenu;
+ TKMenu *_defaultMainMenu, *_defaultApplicationMenu;
+ NSArray *_defaultApplicationMenuItems, *_defaultWindowsMenuItems;
+ NSArray *_defaultHelpMenuItems;
+ NSWindow *_windowWithMouse;
+ NSAutoreleasePool *_mainPool;
+#ifdef __i386__
+ /* The Objective C runtime used on i386 requires this. */
+ int _poolLock;
+ int _macMinorVersion;
+ Bool _isDrawing;
+#endif
+}
+@property int poolLock;
+@property int macMinorVersion;
+@property Bool isDrawing;
+
+@end
+@interface TKApplication(TKInit)
+- (NSString *)tkFrameworkImagePath:(NSString*)image;
+- (void)_resetAutoreleasePool;
+- (void)_lockAutoreleasePool;
+- (void)_unlockAutoreleasePool;
+@end
+@interface TKApplication(TKKeyboard)
+- (void) keyboardChanged: (NSNotification *) notification;
+@end
+@interface TKApplication(TKWindowEvent) <NSApplicationDelegate>
+- (void) _setupWindowNotifications;
+@end
+@interface TKApplication(TKMenu)
+- (void)tkSetMainMenu:(TKMenu *)menu;
+@end
+@interface TKApplication(TKMenus)
+- (void) _setupMenus;
+@end
+@interface NSApplication(TKNotify)
+/* We need to declare this hidden method. */
+- (void) _modalSession: (NSModalSession) session sendEvent: (NSEvent *) event;
+@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(TKClipboard)
+- (void)tkProvidePasteboard:(TkDisplay *)dispPtr;
+- (void)tkCheckPasteboard;
+@end
+@interface TKApplication(TKHLEvents)
+- (void) terminate: (id) sender;
+- (void) preferences: (id) sender;
+- (void) handleQuitApplicationEvent: (NSAppleEventDescriptor *)event
+ withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
+- (void) handleOpenApplicationEvent: (NSAppleEventDescriptor *)event
+ withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
+- (void) handleReopenApplicationEvent: (NSAppleEventDescriptor *)event
+ withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
+- (void) handleShowPreferencesEvent: (NSAppleEventDescriptor *)event
+ withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
+- (void) handleOpenDocumentsEvent: (NSAppleEventDescriptor *)event
+ withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
+- (void) handlePrintDocumentsEvent: (NSAppleEventDescriptor *)event
+ withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
+- (void) handleDoScriptEvent: (NSAppleEventDescriptor *)event
+ withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
+- (void)handleURLEvent: (NSAppleEventDescriptor*)event
+ withReplyEvent:(NSAppleEventDescriptor*)replyEvent
+@end
+
+VISIBILITY_HIDDEN
+@interface TKContentView : NSView <NSTextInput>
+{
+ NSString *privateWorkingText;
+}
+@end
+
+@interface TKContentView(TKKeyEvent)
+- (void) deleteWorkingText;
+@end
+
+@interface TKContentView(TKWindowEvent)
+- (void) drawRect: (NSRect) rect;
+- (void) generateExposeEvents: (HIShapeRef) shape;
+- (void) tkToolbarButton: (id) sender;
+- (BOOL) isOpaque;
+- (BOOL) wantsDefaultClipping;
+- (BOOL) acceptsFirstResponder;
+- (void) keyDown: (NSEvent *) theEvent;
+@end
+
+@interface NSWindow(TKWm)
+- (NSPoint) tkConvertPointToScreen:(NSPoint)point;
+- (NSPoint) tkConvertPointFromScreen:(NSPoint)point;
+@end
+
+VISIBILITY_HIDDEN
+@interface TKWindow : NSWindow
+@end
+
+@interface TKWindow(TKWm)
+- (void) tkLayoutChanged;
+@end
+
+@interface NSDrawerWindow : NSWindow
+{
+ id _i1, _i2;
+}
+@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
+
+@interface NSColorPanel(TKDialog)
+- (void) _setUseModalAppearance: (BOOL) flag;
+@end
+
+@interface NSFont(TKFont)
+- (NSFont *) bestMatchingFontForCharacters: (const UTF16Char *) characters
+ length: (NSUInteger) length attributes: (NSDictionary *) attributes
+ actualCoveredLength: (NSUInteger *) coveredLength;
+@end
+
+/*
+ * This method of NSApplication is not declared in NSApplication.h so we
+ * declare it here to be a method of the TKMenu category.
+ */
+
+@interface NSApplication(TKMenu)
+- (void) setAppleMenu: (NSMenu *) menu;
+@end
+
+#endif /* _TKMACPRIV */
+
+/*
+ * Local Variables:
+ * mode: objc
+ * c-basic-offset: 4
+ * fill-column: 79
+ * coding: utf-8
+ * End:
+ */
diff --git a/macosx/tkMacOSXServices.c b/macosx/tkMacOSXServices.c
index 9d04d14..d622081 100644
--- a/macosx/tkMacOSXServices.c
+++ b/macosx/tkMacOSXServices.c
@@ -1,197 +1,197 @@
-/*
- * tkMacOSXServices.c --
- *
- * This file allows the integration of Tk and the Cocoa NSServices API.
- *
- * Copyright (c) 2010-2018 Kevin Walzer/WordTech Communications LLC.
- * Copyright (c) 2010 Adrian Robert.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- */
-
-
-
-#include <CoreFoundation/CoreFoundation.h>
-#include <CoreServices/CoreServices.h>
-#define Cursor FooFoo
-#include <Carbon/Carbon.h>
-#undef Cursor
-#include <tcl.h>
-#include <tk.h>
-#include <tkInt.h>
-#include <tkMacOSXInt.h>
-#include <Cocoa/Cocoa.h>
-#include <stdio.h>
-#include <string.h>
-
-static Tcl_Interp *ServicesInterp;
-
-
-/* These two assist with asynchronous Tcl proc calling. */
-typedef struct Services_Event {
- Tcl_Event header;
- char script[50000];
-} Services_Event;
-
-int ServicesEventProc(Tcl_Event *event, int flags) {
- Tcl_GlobalEval(ServicesInterp, ((Services_Event *)event)->script);
- return 1;
-}
-
-
-/* Class declarations for TkService class. */
-@interface TkService : NSView {
-
-}
-
-+ (void) initialize;
-- (void)provideService:(NSPasteboard *)pboard userData:(NSString *)data error:(NSString **)error;
-- (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType;
-- (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard types:(NSArray *)types;
-
-@end
-
-/* Class methods. */
-@implementation TkService
-
-+ (void) initialize {
-
- NSArray *sendTypes = [NSArray arrayWithObjects:NSStringPboardType, nil];
- [NSApp registerServicesMenuSendTypes:sendTypes returnTypes:nil];
- NSUpdateDynamicServices();
- return;
-}
-
-
-- (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType {
-
- if ([sendType isEqual:NSStringPboardType]) {
- return self;
- }
- return [super validRequestorForSendType:sendType returnType:returnType];
-}
-
-/* Make sure the view accepts events. */
-- (BOOL)acceptsFirstResponder {
- return YES;
-}
-- (BOOL)becomeFirstResponder {
- return YES;
-}
-
-//get selected text, copy to pasteboard
-- (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard types:(NSArray *)types {
- NSArray *typesDeclared;
- if ([types containsObject:NSStringPboardType] == NO) {
- return NO;
- }
-
- Tcl_Eval(ServicesInterp,"clipboard get");
- char *copystring;
- copystring = Tcl_GetString(Tcl_GetObjResult(ServicesInterp));
-
- NSString *writestring = [NSString stringWithUTF8String:copystring];
- typesDeclared = [NSArray arrayWithObject:NSStringPboardType];
- [pboard declareTypes:typesDeclared owner:nil];
- return [pboard setString:writestring forType:NSStringPboardType];
-}
-
-
-/* This is the method that actually calls the Tk service; this is the method that must be defined in info.plist */
-
-- (void)provideService:(NSPasteboard *)pboard userData:(NSString *)data error:(NSString **)error {
-
- NSString *pboardString;
- NSArray *types = [pboard types];
- Services_Event *event;
-
- /* Get string from private pasteboard, write to general pasteboard to make available to Tcl service. */
- if ([types containsObject:NSStringPboardType] &&
- (pboardString = [pboard stringForType:NSStringPboardType])) {
-
- NSPasteboard *generalpasteboard = [NSPasteboard generalPasteboard];
- [generalpasteboard declareTypes:[NSArray arrayWithObjects:NSStringPboardType, nil] owner:nil];
- [generalpasteboard setString:pboardString forType:NSStringPboardType];
- event = (Services_Event *)ckalloc(sizeof(Services_Event));
- event->header.proc = ServicesEventProc;
- strcpy(event->script, "::tk::mac::PerformService");
- Tcl_QueueEvent((Tcl_Event *)event, TCL_QUEUE_TAIL);
- } else {
- return;
- }
- return;
-}
-
-@end
-
-
-/* Register a specific widget to access the Services menu. */
-int TkMacOSXRegisterServiceWidgetObjCmd (ClientData cd, Tcl_Interp *ip, int objc, Tcl_Obj *CONST objv[]) {
-
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- /* Need proper number of args. */
- if(objc != 2) {
- Tcl_WrongNumArgs(ip, 1, objv, "path?");
- return TCL_ERROR;
- }
-
- /* Get the object that holds this Tk Window... */
- Rect bounds;
- NSRect frame;
- Tk_Window path;
- path = Tk_NameToWindow(ip, Tcl_GetString(objv[1]), Tk_MainWindow(ip));
- if (path == NULL) {
- return TCL_ERROR;
- }
-
- Tk_MakeWindowExist(path);
- Tk_MapWindow(path);
- Drawable d = Tk_WindowId(path);
-
- /* Get NSView from Tk window and add subview. */
- TkService *serviceview = [[TkService alloc] init];
- NSView *view = TkMacOSXGetRootControl(d);
- if ([serviceview superview] != view) {
- [view addSubview:serviceview];
- }
-
- TkMacOSXWinBounds((TkWindow*)path, &bounds);
-
- /* Hack to make sure subview is set to take up entire geometry of window. */
- frame = NSMakeRect(bounds.left, bounds.top, 100000, 100000);
- frame.origin.y = 0;
-
- if (!NSEqualRects(frame, [serviceview frame])) {
- [serviceview setFrame:frame];
- }
-
- [serviceview release];
- [pool release];
-
- return TCL_OK;
-
-}
-
-
-//initalize the package in the tcl interpreter, create tcl commands
-int Tk_MacOSXServices_Init (Tcl_Interp *interp) {
-
- /* Set up an autorelease pool. */
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
-
- /* Initialize instance of TclServices to provide service functionality. */
- TkService *service = [[TkService alloc] init];
- ServicesInterp = interp;
- [NSApp setServicesProvider:service];
-
- [pool release];
-
- return TCL_OK;
-
-}
-
-
-
+/*
+ * tkMacOSXServices.c --
+ *
+ * This file allows the integration of Tk and the Cocoa NSServices API.
+ *
+ * Copyright (c) 2010-2019 Kevin Walzer/WordTech Communications LLC.
+ * Copyright (c) 2010 Adrian Robert.
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ */
+
+
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <CoreServices/CoreServices.h>
+#define Cursor FooFoo
+#include <Carbon/Carbon.h>
+#undef Cursor
+#include <tcl.h>
+#include <tk.h>
+#include <tkInt.h>
+#include <tkMacOSXInt.h>
+#include <Cocoa/Cocoa.h>
+#include <stdio.h>
+#include <string.h>
+
+static Tcl_Interp *ServicesInterp;
+
+
+/* These two assist with asynchronous Tcl proc calling. */
+typedef struct Services_Event {
+ Tcl_Event header;
+ char script[50000];
+} Services_Event;
+
+int ServicesEventProc(Tcl_Event *event, int flags) {
+ Tcl_GlobalEval(ServicesInterp, ((Services_Event *)event)->script);
+ return 1;
+}
+
+
+/* Class declarations for TkService class. */
+@interface TkService : NSView {
+
+}
+
++ (void) initialize;
+- (void)provideService:(NSPasteboard *)pboard userData:(NSString *)data error:(NSString **)error;
+- (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType;
+- (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard types:(NSArray *)types;
+
+@end
+
+/* Class methods. */
+@implementation TkService
+
++ (void) initialize {
+
+ NSArray *sendTypes = [NSArray arrayWithObjects:NSStringPboardType, nil];
+ [NSApp registerServicesMenuSendTypes:sendTypes returnTypes:nil];
+ NSUpdateDynamicServices();
+ return;
+}
+
+
+- (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType {
+
+ if ([sendType isEqual:NSStringPboardType]) {
+ return self;
+ }
+ return [super validRequestorForSendType:sendType returnType:returnType];
+}
+
+/* Make sure the view accepts events. */
+- (BOOL)acceptsFirstResponder {
+ return YES;
+}
+- (BOOL)becomeFirstResponder {
+ return YES;
+}
+
+//get selected text, copy to pasteboard
+- (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard types:(NSArray *)types {
+ NSArray *typesDeclared;
+ if ([types containsObject:NSStringPboardType] == NO) {
+ return NO;
+ }
+
+ Tcl_Eval(ServicesInterp,"clipboard get");
+ char *copystring;
+ copystring = Tcl_GetString(Tcl_GetObjResult(ServicesInterp));
+
+ NSString *writestring = [NSString stringWithUTF8String:copystring];
+ typesDeclared = [NSArray arrayWithObject:NSStringPboardType];
+ [pboard declareTypes:typesDeclared owner:nil];
+ return [pboard setString:writestring forType:NSStringPboardType];
+}
+
+
+/* This is the method that actually calls the Tk service; this is the method that must be defined in info.plist */
+
+- (void)provideService:(NSPasteboard *)pboard userData:(NSString *)data error:(NSString **)error {
+
+ NSString *pboardString;
+ NSArray *types = [pboard types];
+ Services_Event *event;
+
+ /* Get string from private pasteboard, write to general pasteboard to make available to Tcl service. */
+ if ([types containsObject:NSStringPboardType] &&
+ (pboardString = [pboard stringForType:NSStringPboardType])) {
+
+ NSPasteboard *generalpasteboard = [NSPasteboard generalPasteboard];
+ [generalpasteboard declareTypes:[NSArray arrayWithObjects:NSStringPboardType, nil] owner:nil];
+ [generalpasteboard setString:pboardString forType:NSStringPboardType];
+ event = (Services_Event *)ckalloc(sizeof(Services_Event));
+ event->header.proc = ServicesEventProc;
+ strcpy(event->script, "::tk::mac::PerformService");
+ Tcl_QueueEvent((Tcl_Event *)event, TCL_QUEUE_TAIL);
+ } else {
+ return;
+ }
+ return;
+}
+
+@end
+
+
+/* Register a specific widget to access the Services menu. */
+int TkMacOSXRegisterServiceWidgetObjCmd (ClientData cd, Tcl_Interp *ip, int objc, Tcl_Obj *CONST objv[]) {
+
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ /* Need proper number of args. */
+ if(objc != 2) {
+ Tcl_WrongNumArgs(ip, 1, objv, "path?");
+ return TCL_ERROR;
+ }
+
+ /* Get the object that holds this Tk Window... */
+ Rect bounds;
+ NSRect frame;
+ Tk_Window path;
+ path = Tk_NameToWindow(ip, Tcl_GetString(objv[1]), Tk_MainWindow(ip));
+ if (path == NULL) {
+ return TCL_ERROR;
+ }
+
+ Tk_MakeWindowExist(path);
+ Tk_MapWindow(path);
+ Drawable d = Tk_WindowId(path);
+
+ /* Get NSView from Tk window and add subview. */
+ TkService *serviceview = [[TkService alloc] init];
+ NSView *view = TkMacOSXGetRootControl(d);
+ if ([serviceview superview] != view) {
+ [view addSubview:serviceview];
+ }
+
+ TkMacOSXWinBounds((TkWindow*)path, &bounds);
+
+ /* Hack to make sure subview is set to take up entire geometry of window. */
+ frame = NSMakeRect(bounds.left, bounds.top, 100000, 100000);
+ frame.origin.y = 0;
+
+ if (!NSEqualRects(frame, [serviceview frame])) {
+ [serviceview setFrame:frame];
+ }
+
+ [serviceview release];
+ [pool release];
+
+ return TCL_OK;
+
+}
+
+
+//initalize the package in the tcl interpreter, create tcl commands
+int Tk_MacOSXServices_Init (Tcl_Interp *interp) {
+
+ /* Set up an autorelease pool. */
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+
+ /* Initialize instance of TclServices to provide service functionality. */
+ TkService *service = [[TkService alloc] init];
+ ServicesInterp = interp;
+ [NSApp setServicesProvider:service];
+
+ [pool release];
+
+ return TCL_OK;
+
+}
+
+
+