summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXInit.c
diff options
context:
space:
mode:
authorculler <culler>2017-11-24 20:35:13 (GMT)
committerculler <culler>2017-11-24 20:35:13 (GMT)
commit85708596b600b95ccec076d13a7a3f19448c9d6f (patch)
treefa983de16697b73f98f246640047cb1a6c4a072f /macosx/tkMacOSXInit.c
parent4d93c39841fcb541bd4bbb61c731c0444fabb2de (diff)
downloadtk-85708596b600b95ccec076d13a7a3f19448c9d6f.zip
tk-85708596b600b95ccec076d13a7a3f19448c9d6f.tar.gz
tk-85708596b600b95ccec076d13a7a3f19448c9d6f.tar.bz2
Simplify and reorganize the initialization code.
Diffstat (limited to 'macosx/tkMacOSXInit.c')
-rw-r--r--macosx/tkMacOSXInit.c143
1 files changed, 73 insertions, 70 deletions
diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c
index 29d68b2..2559611 100644
--- a/macosx/tkMacOSXInit.c
+++ b/macosx/tkMacOSXInit.c
@@ -7,6 +7,7 @@
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
* Copyright 2001-2009, Apple Inc.
* Copyright (c) 2005-2009 Daniel A. Steffen <das@users.sourceforge.net>
+ * Copyright (c) 2017 Marc Culler
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
@@ -112,7 +113,46 @@ static void keyboardChanged(CFNotificationCenterRef center, void *observer, CFSt
-(void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
- /* Much of the NSApplication initialization should be moved here.*/
+
+ /*
+ * Initialize notifications.
+ */
+#ifdef TK_MAC_DEBUG_NOTIFICATIONS
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(_postedNotification:) name:nil object:nil];
+#endif
+ [self _setupWindowNotifications];
+ [self _setupApplicationNotifications];
+
+ /*
+ * Construct the menu bar.
+ */
+ _defaultMainMenu = nil;
+ [self _setupMenus];
+
+ /*
+ * Set the application icon. This is unnecessary when running Wish.app
+ * but it is easier than testing for that situation to just do it.
+ */
+ NSString *path = [NSApp tkFrameworkImagePath:@"Tk.icns"];
+ if (path) {
+ NSImage *image = [[NSImage alloc] initWithContentsOfFile:path];
+ if (image) {
+ [NSApp setApplicationIconImage:image];
+ [image release];
+ }
+ }
+
+ /*
+ * Initialize event processing.
+ */
+ TkMacOSXInitAppleEvents(_eventInterp);
+
+ /*
+ * Initialize the graphics context.
+ */
+ TkMacOSXUseAntialiasedText(_eventInterp, -1);
+ TkMacOSXInitCGDrawing(_eventInterp, TRUE, 0);
}
-(void)applicationDidFinishLaunching:(NSNotification *)notification
@@ -127,19 +167,26 @@ static void keyboardChanged(CFNotificationCenterRef center, void *observer, CFSt
- (void) _setup: (Tcl_Interp *) interp
{
+ /*
+ * Remember our interpreter.
+ */
_eventInterp = interp;
+
+ /*
+ * Install the global autoreleasePool.
+ */
_mainPool = [NSAutoreleasePool new];
[NSApp setPoolLock:0];
- _defaultMainMenu = nil;
- [self _setupMenus];
+
+ /*
+ * Be our own delegate.
+ */
[self setDelegate:self];
+
+ /*
+ * Make sure we are allowed to open windows.
+ */
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
-#ifdef TK_MAC_DEBUG_NOTIFICATIONS
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(_postedNotification:) name:nil object:nil];
-#endif
- [self _setupWindowNotifications];
- [self _setupApplicationNotifications];
}
- (NSString *) tkFrameworkImagePath: (NSString *) image
@@ -293,67 +340,6 @@ TkpInit(
}
#endif
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
- [[NSUserDefaults standardUserDefaults] registerDefaults:
- [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithBool:YES],
- @"_NSCanWrapButtonTitles",
- [NSNumber numberWithInt:-1],
- @"NSStringDrawingTypesetterBehavior",
- nil]];
- [TKApplication sharedApplication];
- [pool drain];
- [NSApp _setup:interp];
-
-
- /* Check whether we are a bundled executable: */
- bundleRef = CFBundleGetMainBundle();
- if (bundleRef) {
- bundleUrl = CFBundleCopyBundleURL(bundleRef);
- }
- if (bundleUrl) {
- /*
- * A bundled executable is two levels down from its main bundle
- * directory (e.g. Wish.app/Contents/MacOS/Wish), whereas an
- * unbundled executable's main bundle directory is just the
- * directory containing the executable. So to check whether we are
- * bundled, we delete the last three path components of the
- * executable's url and compare the resulting url with the main
- * bundle url.
- */
-
- int j = 3;
- CFURLRef url = CFBundleCopyExecutableURL(bundleRef);
-
- while (url && j--) {
- CFURLRef parent =
- CFURLCreateCopyDeletingLastPathComponent(NULL, url);
-
- CFRelease(url);
- url = parent;
- }
- if (url) {
- bundledExecutable = CFEqual(bundleUrl, url);
- CFRelease(url);
- }
- CFRelease(bundleUrl);
- }
-
- if (!bundledExecutable) {
- /*
- * Set application icon to generic Tk icon, do it at idle time
- * instead of now to ensure tk_library is setup.
- */
- Tcl_DoWhenIdle(SetApplicationIcon, NULL);
- }
-
- pool = [NSAutoreleasePool new];
- [NSApp finishLaunching];
- TkMacOSXInitAppleEvents(interp);
- TkMacOSXUseAntialiasedText(interp, -1);
- TkMacOSXInitCGDrawing(interp, TRUE, 0);
- [pool drain];
-
/*
* FIXME: Close stdin & stdout for remote debugging otherwise we will
* fight with gdb for stdin & stdout
@@ -396,6 +382,23 @@ TkpInit(
return TCL_ERROR;
}
}
+
+ /*
+ * Instantiate our NSApplication object.
+ */
+
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ [[NSUserDefaults standardUserDefaults] registerDefaults:
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithBool:YES],
+ @"_NSCanWrapButtonTitles",
+ [NSNumber numberWithInt:-1],
+ @"NSStringDrawingTypesetterBehavior",
+ nil]];
+ [TKApplication sharedApplication];
+ [pool drain];
+ [NSApp _setup:interp];
+ [NSApp finishLaunching];
}
Tk_MacOSXSetupTkNotifier();