annotate Xcode/TemplatesForXcode/SDL Custom Cocoa Application/SDLMain.m @ 2213:59a667370c57

make indent
author Bob Pendleton <bob@pendleton.com>
date Tue, 24 Jul 2007 18:46:45 +0000
parents d63e9f5944ae
children
rev   line source
2207
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /* SDLMain.m - main entry point for our Cocoa-ized SDL app
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Non-NIB-Code & other changes: Max Horn <max@quendi.de>
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 Feel free to customize this file to suit your needs
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 #import "SDL.h"
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 #import "SDLMain.h"
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 #import "MyController.h"
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 #import <sys/param.h> /* for MAXPATHLEN */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 #import <unistd.h>
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14 /* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 but the method still is there and works. To avoid warnings, we declare
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 it ourselves here. */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 @interface NSApplication(SDL_Missing_Methods)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 - (void)setAppleMenu:(NSMenu *)menu;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 @end
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 /* Use this flag to determine whether we use SDLMain.nib or not */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #define SDL_USE_NIB_FILE 1
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 /* Use this flag to determine whether we use CPS (docking) or not */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 #define SDL_USE_CPS 1
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #ifdef SDL_USE_CPS
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 /* Portions of CPS.h */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 typedef struct CPSProcessSerNum
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 UInt32 lo;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 UInt32 hi;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 } CPSProcessSerNum;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #endif /* SDL_USE_CPS */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 static int gArgc;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 static char **gArgv;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 static BOOL gFinderLaunch;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 static BOOL gCalledAppMainline = FALSE;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 static NSString *getApplicationName(void)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 NSDictionary *dict;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 NSString *appName = 0;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 /* Determine the application name */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 if (dict)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 appName = [dict objectForKey: @"CFBundleName"];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 if (![appName length])
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 appName = [[NSProcessInfo processInfo] processName];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 return appName;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 #if SDL_USE_NIB_FILE
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 /* A helper category for NSString */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 @interface NSString (ReplaceSubString)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 @end
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 #endif
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 @interface SDLApplication : NSApplication
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 @end
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 @implementation SDLApplication
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 /* Invoked from the Quit menu item */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 - (void)terminate:(id)sender
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 /* Post a SDL_QUIT event */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 SDL_Event event;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 event.type = SDL_QUIT;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 SDL_PushEvent(&event);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 @end
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 /* The main class of the application, the application's delegate */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 @implementation SDLMain
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 /* Set the working directory to the .app's parent directory */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 - (void) setupWorkingDirectory:(BOOL)shouldChdir
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 if (shouldChdir)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 char parentdir[MAXPATHLEN];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 CFRelease(url);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 CFRelease(url2);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 #if SDL_USE_NIB_FILE
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 /* Fix menu to contain the real app name instead of "SDL App" */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 NSRange aRange;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 NSEnumerator *enumerator;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 NSMenuItem *menuItem;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 aRange = [[aMenu title] rangeOfString:@"SDL App"];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 if (aRange.length != 0)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 enumerator = [[aMenu itemArray] objectEnumerator];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 while ((menuItem = [enumerator nextObject]))
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 aRange = [[menuItem title] rangeOfString:@"SDL App"];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 if (aRange.length != 0)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 if ([menuItem hasSubmenu])
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 [self fixMenu:[menuItem submenu] withAppName:appName];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 [ aMenu sizeToFit ];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 #else
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 static void setApplicationMenu(void)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 /* warning: this code is very odd */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 NSMenu *appleMenu;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 NSMenuItem *menuItem;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 NSString *title;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 NSString *appName;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 appName = getApplicationName();
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 appleMenu = [[NSMenu alloc] initWithTitle:@""];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 /* Add menu items */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 title = [@"About " stringByAppendingString:appName];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 [appleMenu addItem:[NSMenuItem separatorItem]];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 title = [@"Hide " stringByAppendingString:appName];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 [appleMenu addItem:[NSMenuItem separatorItem]];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 title = [@"Quit " stringByAppendingString:appName];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 /* Put menu into the menubar */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 [menuItem setSubmenu:appleMenu];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 [[NSApp mainMenu] addItem:menuItem];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 /* Tell the application object that this is now the application menu */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 [NSApp setAppleMenu:appleMenu];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 /* Finally give up our references to the objects */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 [appleMenu release];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 [menuItem release];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 /* Create a window menu */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 static void setupWindowMenu(void)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 NSMenu *windowMenu;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 NSMenuItem *windowMenuItem;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 NSMenuItem *menuItem;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 /* "Minimize" item */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 [windowMenu addItem:menuItem];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 [menuItem release];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 /* Put menu into the menubar */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 [windowMenuItem setSubmenu:windowMenu];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 [[NSApp mainMenu] addItem:windowMenuItem];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 /* Tell the application object that this is now the window menu */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 [NSApp setWindowsMenu:windowMenu];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 /* Finally give up our references to the objects */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 [windowMenu release];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 [windowMenuItem release];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 /* Replacement for NSApplicationMain */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 static void CustomApplicationMain (int argc, char **argv)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 SDLMain *sdlMain;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 /* Ensure the application object is initialised */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 [SDLApplication sharedApplication];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 #ifdef SDL_USE_CPS
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 CPSProcessSerNum PSN;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 /* Tell the dock about us */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 if (!CPSGetCurrentProcess(&PSN))
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 if (!CPSSetFrontProcess(&PSN))
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 [SDLApplication sharedApplication];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 #endif /* SDL_USE_CPS */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 /* Set up the menubar */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 [NSApp setMainMenu:[[NSMenu alloc] init]];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 setApplicationMenu();
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 setupWindowMenu();
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 /* Create SDLMain and make it the app delegate */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 sdlMain = [[SDLMain alloc] init];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 [NSApp setDelegate:sdlMain];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 /* Start the main event loop */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 [NSApp run];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 [sdlMain release];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 [pool release];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 #endif
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 /*
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 * Catch document open requests...this lets us notice files when the app
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 * was launched by double-clicking a document, or when a document was
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 * dragged/dropped on the app's icon. You need to have a
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 * CFBundleDocumentsType section in your Info.plist to get this message,
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 * apparently.
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 *
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 * Files are added to gArgv, so to the app, they'll look like command line
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 * arguments. Previously, apps launched from the finder had nothing but
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 * an argv[0].
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 *
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 * This message may be received multiple times to open several docs on launch.
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 *
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 * This message is ignored once the app's mainline has been called.
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 const char *temparg;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 size_t arglen;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 char *arg;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 char **newargv;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 if (!gFinderLaunch) /* MacOS is passing command line args. */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 return FALSE;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 if (gCalledAppMainline) /* app has started, ignore this document. */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 return FALSE;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 temparg = [filename UTF8String];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 arglen = SDL_strlen(temparg) + 1;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 arg = (char *) SDL_malloc(arglen);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 if (arg == NULL)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 return FALSE;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 if (newargv == NULL)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 SDL_free(arg);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 return FALSE;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 gArgv = newargv;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 SDL_strlcpy(arg, temparg, arglen);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 gArgv[gArgc++] = arg;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 gArgv[gArgc] = NULL;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 return TRUE;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 /* Called when the internal event loop has just started running */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 - (void) applicationDidFinishLaunching: (NSNotification *) note
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 int status;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 gController = _controller;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 /* Set the working directory to the .app's parent directory */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 [self setupWorkingDirectory:gFinderLaunch];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 #if SDL_USE_NIB_FILE
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 /* Set the main menu to contain the real app name instead of "SDL App" */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 #endif
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 /* Hand off to main application code */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 gCalledAppMainline = TRUE;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 status = SDL_main (gArgc, gArgv);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 /* We're done, thank you for playing */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 exit(status);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 @end
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 @implementation NSString (ReplaceSubString)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 unsigned int bufferSize;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 unsigned int selfLen = [self length];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 unsigned int aStringLen = [aString length];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 unichar *buffer;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321 NSRange localRange;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322 NSString *result;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 bufferSize = selfLen + aStringLen - aRange.length;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 /* Get first part into buffer */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 localRange.location = 0;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 localRange.length = aRange.location;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 [self getCharacters:buffer range:localRange];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 /* Get middle part into buffer */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 localRange.location = 0;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 localRange.length = aStringLen;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 [aString getCharacters:(buffer+aRange.location) range:localRange];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337 /* Get last part into buffer */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 localRange.location = aRange.location + aRange.length;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 localRange.length = selfLen - localRange.location;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 /* Build output string */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 result = [NSString stringWithCharacters:buffer length:bufferSize];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 NSDeallocateMemoryPages(buffer, bufferSize);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 return result;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350 @end
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 #ifdef main
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 # undef main
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356 #endif
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 /* Main entry point to executable - should *not* be SDL_main! */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 int main (int argc, char **argv)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 /* Copy the arguments into a global variable */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 /* This is passed if we are launched by double-clicking */
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 gArgv[0] = argv[0];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 gArgv[1] = NULL;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 gArgc = 1;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 gFinderLaunch = YES;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 } else {
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 int i;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 gArgc = argc;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 for (i = 0; i <= argc; i++)
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 gArgv[i] = argv[i];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 gFinderLaunch = NO;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 }
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 #if SDL_USE_NIB_FILE
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 [SDLApplication poseAsClass:[NSApplication class]];
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 NSApplicationMain (argc, argv);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 #else
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 CustomApplicationMain (argc, argv);
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 #endif
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 return 0;
d63e9f5944ae Unpacked project archives to get individual file history in subversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 }