annotate src/main/macosx/SDLMain.m @ 491:da6a7e859616

Applied John Popplewell's fix for left-handed mice under Windows.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 16 Sep 2002 06:14:46 +0000
parents a7129c0083f4
children 217f119a19a0
rev   line source
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /* SDLMain.m - main entry point for our Cocoa-ized SDL app
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
2 Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
3 Non-NIB-Code & other changes: Max Horn <max@quendi.de>
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 Feel free to customize this file to suit your needs
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 #import "SDL.h"
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 #import "SDLMain.h"
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 #import <sys/param.h> /* for MAXPATHLEN */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 #import <unistd.h>
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
13 /* Use this flag to determine whether we use SDLMain.nib or not */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
14 #define SDL_USE_NIB_FILE 0
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
15
476
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
16 /* Use this flag to determine whether we use CPS (docking) or not */
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
17 #define SDL_USE_CPS 1
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
18 #ifdef SDL_USE_CPS
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
19 /* Portions of CPS.h */
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
20 typedef struct CPSProcessSerNum
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
21 {
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
22 UInt32 lo;
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
23 UInt32 hi;
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
24 } CPSProcessSerNum;
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
25
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
26 extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
27 extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
28 extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
29
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
30 #endif /* SDL_USE_CPS */
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
31
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 static int gArgc;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 static char **gArgv;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 static BOOL gFinderLaunch;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
36 #if SDL_USE_NIB_FILE
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
37 /* A helper category for NSString */
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 @interface NSString (ReplaceSubString)
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 @end
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
41 #else
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
42 /* An internal Apple class used to setup Apple menus */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
43 @interface NSAppleMenuController:NSObject {}
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
44 - (void)controlMenu:(NSMenu *)aMenu;
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
45 @end
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
46 #endif
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
47
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
48 @interface SDLApplication : NSApplication
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
49 @end
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
50
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
51 @implementation SDLApplication
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
52 /* Invoked from the Quit menu item */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
53 - (void)terminate:(id)sender
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
54 {
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
55 /* Post a SDL_QUIT event */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
56 SDL_Event event;
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
57 event.type = SDL_QUIT;
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
58 SDL_PushEvent(&event);
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
59 }
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
60 @end
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 /* The main class of the application, the application's delegate */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 @implementation SDLMain
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 /* Set the working directory to the .app's parent directory */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 - (void) setupWorkingDirectory:(BOOL)shouldChdir
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 {
389
ca655a7a9d80 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 388
diff changeset
69
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 if (shouldChdir)
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 {
390
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
72 char parentdir[MAXPATHLEN];
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
73 char *c;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
74
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
75 strncpy ( parentdir, gArgv[0], sizeof(parentdir) );
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
76 c = (char*) parentdir;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
77
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
78 while (*c != '\0') /* go to end */
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
79 c++;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
80
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
81 while (*c != '/') /* back up to parent */
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
82 c--;
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
83
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
84 *c++ = '\0'; /* cut off last part (binary name) */
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
85
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
86 assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
19e73568a75c Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents: 389
diff changeset
87 assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
91 #if SDL_USE_NIB_FILE
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
92
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 /* Fix menu to contain the real app name instead of "SDL App" */
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
94 - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 NSRange aRange;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 NSEnumerator *enumerator;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 NSMenuItem *menuItem;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 aRange = [[aMenu title] rangeOfString:@"SDL App"];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 if (aRange.length != 0)
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
102 [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 enumerator = [[aMenu itemArray] objectEnumerator];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 while ((menuItem = [enumerator nextObject]))
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 aRange = [[menuItem title] rangeOfString:@"SDL App"];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 if (aRange.length != 0)
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
109 [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 if ([menuItem hasSubmenu])
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
111 [self fixMenu:[menuItem submenu] withAppName:appName];
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 [ aMenu sizeToFit ];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
116 #else
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
117
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
118 void setupAppleMenu(void)
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
119 {
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
120 /* warning: this code is very odd */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
121 NSAppleMenuController *appleMenuController;
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
122 NSMenu *appleMenu;
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
123 NSMenuItem *appleMenuItem;
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
124
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
125 appleMenuController = [[NSAppleMenuController alloc] init];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
126 appleMenu = [[NSMenu alloc] initWithTitle:@""];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
127 appleMenuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
128
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
129 [appleMenuItem setSubmenu:appleMenu];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
130
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
131 /* yes, we do need to add it and then remove it --
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
132 if you don't add it, it doesn't get displayed
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
133 if you don't remove it, you have an extra, titleless item in the menubar
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
134 when you remove it, it appears to stick around
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
135 very, very odd */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
136 [[NSApp mainMenu] addItem:appleMenuItem];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
137 [appleMenuController controlMenu:appleMenu];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
138 [[NSApp mainMenu] removeItem:appleMenuItem];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
139 [appleMenu release];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
140 [appleMenuItem release];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
141 }
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
142
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
143 /* Create a window menu */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
144 void setupWindowMenu(void)
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
145 {
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
146 NSMenu *windowMenu;
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
147 NSMenuItem *windowMenuItem;
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
148 NSMenuItem *menuItem;
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
149
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
150
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
151 windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
152
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
153 /* "Minimize" item */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
154 menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
155 [windowMenu addItem:menuItem];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
156 [menuItem release];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
157
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
158 /* Put menu into the menubar */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
159 windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
160 [windowMenuItem setSubmenu:windowMenu];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
161 [[NSApp mainMenu] addItem:windowMenuItem];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
162
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
163 /* Tell the application object that this is now the window menu */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
164 [NSApp setWindowsMenu:windowMenu];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
165
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
166 /* Finally give up our references to the objects */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
167 [windowMenu release];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
168 [windowMenuItem release];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
169 }
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
170
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
171 /* Replacement for NSApplicationMain */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
172 void CustomApplicationMain (argc, argv)
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
173 {
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
174 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
175 SDLMain *sdlMain;
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
176
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
177 /* Ensure the application object is initialised */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
178 [SDLApplication sharedApplication];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
179
476
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
180 #ifdef SDL_USE_CPS
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
181 {
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
182 CPSProcessSerNum PSN;
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
183 /* Tell the dock about us */
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
184 if (!CPSGetCurrentProcess(&PSN))
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
185 if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
186 if (!CPSSetFrontProcess(&PSN))
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
187 [SDLApplication sharedApplication];
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
188 }
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
189 #endif /* SDL_USE_CPS */
a7129c0083f4 Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents: 390
diff changeset
190
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
191 /* Set up the menubar */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
192 [NSApp setMainMenu:[[NSMenu alloc] init]];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
193 setupAppleMenu();
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
194 setupWindowMenu();
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
195
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
196 /* Create SDLMain and make it the app delegate */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
197 sdlMain = [[SDLMain alloc] init];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
198 [NSApp setDelegate:sdlMain];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
199
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
200 /* Start the main event loop */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
201 [NSApp run];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
202
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
203 [sdlMain release];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
204 [pool release];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
205 }
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
206
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
207 #endif
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
208
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 /* Called when the internal event loop has just started running */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 - (void) applicationDidFinishLaunching: (NSNotification *) note
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 int status;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 /* Set the working directory to the .app's parent directory */
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
215 [self setupWorkingDirectory:gFinderLaunch];
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
217 #if SDL_USE_NIB_FILE
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 /* Set the main menu to contain the real app name instead of "SDL App" */
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
219 [self fixMenu:[NSApp mainMenu] withAppName:[[NSProcessInfo processInfo] processName]];
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
220 #endif
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 /* Hand off to main application code */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 status = SDL_main (gArgc, gArgv);
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 /* We're done, thank you for playing */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 exit(status);
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 @end
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 @implementation NSString (ReplaceSubString)
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 unsigned int bufferSize;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 unsigned int selfLen = [self length];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 unsigned int aStringLen = [aString length];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 unichar *buffer;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 NSRange localRange;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 NSString *result;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 bufferSize = selfLen + aStringLen - aRange.length;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
245 /* Get first part into buffer */
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 localRange.location = 0;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 localRange.length = aRange.location;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 [self getCharacters:buffer range:localRange];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
250 /* Get middle part into buffer */
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 localRange.location = 0;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 localRange.length = aStringLen;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 [aString getCharacters:(buffer+aRange.location) range:localRange];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
255 /* Get last part into buffer */
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 localRange.location = aRange.location + aRange.length;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 localRange.length = selfLen - localRange.location;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
260 /* Build output string */
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 result = [NSString stringWithCharacters:buffer length:bufferSize];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 NSDeallocateMemoryPages(buffer, bufferSize);
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 return result;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 @end
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
271
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 #ifdef main
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 # undef main
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 #endif
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
276
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
277 /* Main entry point to executable - should *not* be SDL_main! */
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
278 int main (int argc, char **argv)
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
279 {
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 /* Copy the arguments into a global variable */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 int i;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 /* This is passed if we are launched by double-clicking */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 gArgc = 1;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 gFinderLaunch = YES;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 } else {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 gArgc = argc;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 gFinderLaunch = NO;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292 gArgv = (char**) malloc (sizeof(*gArgv) * (gArgc+1));
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 assert (gArgv != NULL);
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
294 for (i = 0; i < gArgc; i++)
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 gArgv[i] = argv[i];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 gArgv[i] = NULL;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
298 #if SDL_USE_NIB_FILE
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
299 [SDLApplication poseAsClass:[NSApplication class]];
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 NSApplicationMain (argc, argv);
221
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
301 #else
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
302 CustomApplicationMain (argc, argv);
50620ec9c86a *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 194
diff changeset
303 #endif
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 return 0;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 }