diff options
Diffstat (limited to 'macosx/tkMacOSXInit.c')
-rw-r--r-- | macosx/tkMacOSXInit.c | 122 |
1 files changed, 86 insertions, 36 deletions
diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index e6a6835..03a05fc 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -33,8 +33,8 @@ static char scriptPath[PATH_MAX + 1] = ""; * Forward declarations... */ -static int TkMacOSXGetAppPathCmd(ClientData cd, Tcl_Interp *ip, - int objc, Tcl_Obj *const objv[]); +static Tcl_ObjCmdProc TkMacOSXGetAppPathObjCmd; +static Tcl_ObjCmdProc TkMacOSVersionObjCmd; #pragma mark TKApplication(TKInit) @@ -42,7 +42,7 @@ static int TkMacOSXGetAppPathCmd(ClientData cd, Tcl_Interp *ip, @synthesize poolLock = _poolLock; @synthesize macOSVersion = _macOSVersion; @synthesize isDrawing = _isDrawing; -@synthesize needsToDraw = _needsToDraw; +@synthesize isSigned = _isSigned; @synthesize tkLiveResizeEnded = _tkLiveResizeEnded; @synthesize tkPointerWindow = _tkPointerWindow; - (void) setTkPointerWindow: (TkWindow *)winPtr @@ -200,6 +200,12 @@ static int TkMacOSXGetAppPathCmd(ClientData cd, Tcl_Interp *ip, [self _setupMenus]; /* + * Run initialization routines that depend on the OS version. + */ + + Ttk_MacOSXInit(); + + /* * It is not safe to force activation of the NSApp until this method is * called. Activating too early can cause the menu bar to be unresponsive. * The call to activateIgnoringOtherApps was moved here to avoid this. @@ -607,12 +613,13 @@ TkpInit( } /* - * Initialize the NSServices object here. Apple's docs say to do this - * in applicationDidFinishLaunching, but the Tcl interpreter is not - * initialized until this function call. + * Now we can run initialization routines which require that both the + * NSApplication and the Tcl interpreter have been created and + * initialized. */ TkMacOSXServices_Init(interp); + TkMacOSXNSImage_Init(interp); /* * The root window has been created and mapped, but XMapWindow deferred its @@ -648,7 +655,6 @@ TkpInit( signal(SIGHUP, TkMacOSXSignalHandler); signal(SIGTERM, TkMacOSXSignalHandler); } - /* * Initialization steps that are needed for all interpreters. */ @@ -660,12 +666,67 @@ TkpInit( Tcl_SetVar2(interp, "auto_path", NULL, scriptPath, TCL_GLOBAL_ONLY|TCL_LIST_ELEMENT|TCL_APPEND_VALUE); } + Tcl_CreateObjCommand(interp, "nsimage", + TkMacOSXNSImageObjCmd, NULL, NULL); Tcl_CreateObjCommand(interp, "::tk::mac::standardAboutPanel", TkMacOSXStandardAboutPanelObjCmd, NULL, NULL); Tcl_CreateObjCommand(interp, "::tk::mac::iconBitmap", TkMacOSXIconBitmapObjCmd, NULL, NULL); Tcl_CreateObjCommand(interp, "::tk::mac::GetAppPath", - TkMacOSXGetAppPathCmd, NULL, NULL); + TkMacOSXGetAppPathObjCmd, NULL, NULL); + Tcl_CreateObjCommand(interp, "::tk::mac::macOSVersion", + TkMacOSVersionObjCmd, NULL, NULL); + MacSystrayInit(interp); + MacPrint_Init(interp); + + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * TkMacOSXGetAppPathObjCmd -- + * + * Returns the path of the Wish application bundle. + * + * Results: + * Returns the application path. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +static int +TkMacOSXGetAppPathObjCmd( + TCL_UNUSED(void *), + Tcl_Interp *interp, + int objc, + Tcl_Obj *const objv[]) +{ + if (objc != 1) { + Tcl_WrongNumArgs(interp, 1, objv, NULL); + return TCL_ERROR; + } + + /* + * Get the application path URL and convert it to a string path reference. + */ + + CFURLRef mainBundleURL = CFBundleCopyBundleURL(CFBundleGetMainBundle()); + CFStringRef appPath = + CFURLCopyFileSystemPath(mainBundleURL, kCFURLPOSIXPathStyle); + + /* + * Convert (and copy) the string reference into a Tcl result. + */ + + Tcl_SetObjResult(interp, Tcl_NewStringObj( + CFStringGetCStringPtr(appPath, CFStringGetSystemEncoding()), TCL_INDEX_NONE)); + + CFRelease(mainBundleURL); + CFRelease(appPath); return TCL_OK; } @@ -704,54 +765,43 @@ TkpGetAppName( name = p+1; } } - Tcl_DStringAppend(namePtr, name, -1); + Tcl_DStringAppend(namePtr, name, TCL_INDEX_NONE); } /* *---------------------------------------------------------------------- * - * TkMacOSXGetAppPathCmd -- + * TkMacOSVersionObjCmd -- * - * Returns the path of the Wish application bundle. + * Tcl command which returns an integer encoding the major and minor + * version numbers of the currently running operating system in the + * form 10000*majorVersion + 100*minorVersion. * * Results: - * Returns the application path. + * Returns the OS version. * * Side effects: * None. * *---------------------------------------------------------------------- */ - + static int -TkMacOSXGetAppPathCmd( +TkMacOSVersionObjCmd( TCL_UNUSED(void *), Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { - if (objc != 1) { + static char version[16] = ""; + if (objc > 1) { Tcl_WrongNumArgs(interp, 1, objv, NULL); return TCL_ERROR; } - - /* - * Get the application path URL and convert it to a string path reference. - */ - - CFURLRef mainBundleURL = CFBundleCopyBundleURL(CFBundleGetMainBundle()); - CFStringRef appPath = - CFURLCopyFileSystemPath(mainBundleURL, kCFURLPOSIXPathStyle); - - /* - * Convert (and copy) the string reference into a Tcl result. - */ - - Tcl_SetObjResult(interp, Tcl_NewStringObj( - CFStringGetCStringPtr(appPath, CFStringGetSystemEncoding()), -1)); - - CFRelease(mainBundleURL); - CFRelease(appPath); + if (version[0] == '\0') { + snprintf(version, 16, "%d", [NSApp macOSVersion]); + } + Tcl_SetResult(interp, version, NULL); return TCL_OK; } @@ -780,9 +830,9 @@ TkpDisplayWarning( Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR); if (errChannel) { - Tcl_WriteChars(errChannel, title, -1); + Tcl_WriteChars(errChannel, title, TCL_INDEX_NONE); Tcl_WriteChars(errChannel, ": ", 2); - Tcl_WriteChars(errChannel, msg, -1); + Tcl_WriteChars(errChannel, msg, TCL_INDEX_NONE); Tcl_WriteChars(errChannel, "\n", 1); } } @@ -823,7 +873,7 @@ TkMacOSXDefaultStartupScript(void) if (CFURLGetFileSystemRepresentation(appMainURL, true, (unsigned char *) startupScript, PATH_MAX)) { - Tcl_SetStartupScript(Tcl_NewStringObj(startupScript,-1), NULL); + Tcl_SetStartupScript(Tcl_NewStringObj(startupScript, TCL_INDEX_NONE), NULL); scriptFldrURL = CFURLCreateCopyDeletingLastPathComponent(NULL, appMainURL); if (scriptFldrURL != NULL) { |