Mercurial > sdl-ios-xcode
annotate src/main/macosx/SDLMain.m @ 1022:3d4f1930ed02
*** empty log message ***
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 04 Jan 2005 19:04:14 +0000 |
parents | d390f9bd6b1c |
children | 39408f59a0f7 |
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 |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
36 static NSString *getApplicationName(void) |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
37 { |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
38 NSDictionary *dict; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
39 NSString *appName = 0; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
40 |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
41 /* Determine the application name */ |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
42 dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
43 if (dict) |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
44 appName = [dict objectForKey: @"CFBundleName"]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
45 |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
46 if (![appName length]) |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
47 appName = [[NSProcessInfo processInfo] processName]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
48 |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
49 return appName; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
50 } |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
51 |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
52 #if SDL_USE_NIB_FILE |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
53 /* A helper category for NSString */ |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 @interface NSString (ReplaceSubString) |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 @end |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
57 #endif |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
58 |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
59 @interface SDLApplication : NSApplication |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
60 @end |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
61 |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
62 @implementation SDLApplication |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
63 /* Invoked from the Quit menu item */ |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
64 - (void)terminate:(id)sender |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
65 { |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
66 /* Post a SDL_QUIT event */ |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
67 SDL_Event event; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
68 event.type = SDL_QUIT; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
69 SDL_PushEvent(&event); |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
70 } |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
71 @end |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 /* 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
|
74 @implementation SDLMain |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 /* 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
|
77 - (void) setupWorkingDirectory:(BOOL)shouldChdir |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 { |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 if (shouldChdir) |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 { |
390
19e73568a75c
Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
389
diff
changeset
|
81 char parentdir[MAXPATHLEN]; |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
82 CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
83 CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
84 if (CFURLGetFileSystemRepresentation(url2, true, parentdir, MAXPATHLEN)) { |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
85 assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */ |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
86 } |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
87 CFRelease(url); |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
88 CFRelease(url2); |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
89 } |
390
19e73568a75c
Date: Sat, 1 Jun 2002 17:56:45 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
389
diff
changeset
|
90 |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 } |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
93 #if SDL_USE_NIB_FILE |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
94 |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 /* 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
|
96 - (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
|
97 { |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 NSRange aRange; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 NSEnumerator *enumerator; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 NSMenuItem *menuItem; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 aRange = [[aMenu title] rangeOfString:@"SDL App"]; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 if (aRange.length != 0) |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
104 [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
|
105 |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 enumerator = [[aMenu itemArray] objectEnumerator]; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 while ((menuItem = [enumerator nextObject])) |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 { |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 aRange = [[menuItem title] rangeOfString:@"SDL App"]; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 if (aRange.length != 0) |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
111 [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
|
112 if ([menuItem hasSubmenu]) |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
113 [self fixMenu:[menuItem submenu] withAppName:appName]; |
194
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 [ aMenu sizeToFit ]; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 } |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
118 #else |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
119 |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
120 static void setApplicationMenu(void) |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
121 { |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
122 /* warning: this code is very odd */ |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
123 NSMenu *appleMenu; |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
124 NSMenuItem *menuItem; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
125 NSString *title; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
126 NSString *appName; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
127 |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
128 appName = getApplicationName(); |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
129 appleMenu = [[NSMenu alloc] initWithTitle:@""]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
130 |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
131 /* Add menu items */ |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
132 title = [@"About " stringByAppendingString:appName]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
133 [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
134 |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
135 [appleMenu addItem:[NSMenuItem separatorItem]]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
136 |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
137 title = [@"Hide " stringByAppendingString:appName]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
138 [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
139 |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
140 menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
141 [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
142 |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
143 [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
144 |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
145 [appleMenu addItem:[NSMenuItem separatorItem]]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
146 |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
147 title = [@"Quit " stringByAppendingString:appName]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
148 [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
149 |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
150 |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
151 /* Put menu into the menubar */ |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
152 menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
153 [menuItem setSubmenu:appleMenu]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
154 [[NSApp mainMenu] addItem:menuItem]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
155 |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
156 /* Tell the application object that this is now the application menu */ |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
157 [NSApp setAppleMenu:appleMenu]; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
158 |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
159 /* Finally give up our references to the objects */ |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
160 [appleMenu release]; |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
161 [menuItem release]; |
221
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 |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
164 /* Create a window menu */ |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
165 static void setupWindowMenu(void) |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
166 { |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
167 NSMenu *windowMenu; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
168 NSMenuItem *windowMenuItem; |
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
169 NSMenuItem *menuItem; |
221
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 windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
172 |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
173 /* "Minimize" item */ |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
174 menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
175 [windowMenu addItem:menuItem]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
176 [menuItem release]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
177 |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
178 /* Put menu into the menubar */ |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
179 windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
180 [windowMenuItem setSubmenu:windowMenu]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
181 [[NSApp mainMenu] addItem:windowMenuItem]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
182 |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
183 /* Tell the application object that this is now the window menu */ |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
184 [NSApp setWindowsMenu:windowMenu]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
185 |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
186 /* Finally give up our references to the objects */ |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
187 [windowMenu release]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
188 [windowMenuItem release]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
189 } |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
190 |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
191 /* Replacement for NSApplicationMain */ |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
192 static void CustomApplicationMain (argc, argv) |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
193 { |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
194 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
195 SDLMain *sdlMain; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
196 |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
197 /* Ensure the application object is initialised */ |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
198 [SDLApplication sharedApplication]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
199 |
476
a7129c0083f4
Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents:
390
diff
changeset
|
200 #ifdef SDL_USE_CPS |
a7129c0083f4
Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents:
390
diff
changeset
|
201 { |
a7129c0083f4
Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents:
390
diff
changeset
|
202 CPSProcessSerNum PSN; |
a7129c0083f4
Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents:
390
diff
changeset
|
203 /* Tell the dock about us */ |
a7129c0083f4
Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents:
390
diff
changeset
|
204 if (!CPSGetCurrentProcess(&PSN)) |
a7129c0083f4
Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents:
390
diff
changeset
|
205 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
|
206 if (!CPSSetFrontProcess(&PSN)) |
a7129c0083f4
Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents:
390
diff
changeset
|
207 [SDLApplication sharedApplication]; |
a7129c0083f4
Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents:
390
diff
changeset
|
208 } |
a7129c0083f4
Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents:
390
diff
changeset
|
209 #endif /* SDL_USE_CPS */ |
a7129c0083f4
Tell the dock about command-line launched applications
Sam Lantinga <slouken@libsdl.org>
parents:
390
diff
changeset
|
210 |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
211 /* Set up the menubar */ |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
212 [NSApp setMainMenu:[[NSMenu alloc] init]]; |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
213 setApplicationMenu(); |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
214 setupWindowMenu(); |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
215 |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
216 /* Create SDLMain and make it the app delegate */ |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
217 sdlMain = [[SDLMain alloc] init]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
218 [NSApp setDelegate:sdlMain]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
219 |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
220 /* Start the main event loop */ |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
221 [NSApp run]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
222 |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
223 [sdlMain release]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
224 [pool release]; |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
225 } |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
226 |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
227 #endif |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
228 |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 /* 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
|
230 - (void) applicationDidFinishLaunching: (NSNotification *) note |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 { |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 int status; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 /* Set the working directory to the .app's parent directory */ |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
235 [self setupWorkingDirectory:gFinderLaunch]; |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
237 #if SDL_USE_NIB_FILE |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 /* Set the main menu to contain the real app name instead of "SDL App" */ |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
239 [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()]; |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
240 #endif |
194
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 /* Hand off to main application code */ |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 status = SDL_main (gArgc, gArgv); |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 /* We're done, thank you for playing */ |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 exit(status); |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 } |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 @end |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 @implementation NSString (ReplaceSubString) |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 { |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 unsigned int bufferSize; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 unsigned int selfLen = [self length]; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
257 unsigned int aStringLen = [aString length]; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
258 unichar *buffer; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
259 NSRange localRange; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
260 NSString *result; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 bufferSize = selfLen + aStringLen - aRange.length; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar)); |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
264 |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
265 /* Get first part into buffer */ |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 localRange.location = 0; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 localRange.length = aRange.location; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 [self getCharacters:buffer range:localRange]; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
270 /* Get middle part into buffer */ |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 localRange.location = 0; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 localRange.length = aStringLen; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
273 [aString getCharacters:(buffer+aRange.location) range:localRange]; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
274 |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
275 /* Get last part into buffer */ |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 localRange.location = aRange.location + aRange.length; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 localRange.length = selfLen - localRange.location; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 [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
|
279 |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
280 /* Build output string */ |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 result = [NSString stringWithCharacters:buffer length:bufferSize]; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 NSDeallocateMemoryPages(buffer, bufferSize); |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 return result; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 } |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 @end |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
291 |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 #ifdef main |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 # undef main |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 #endif |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
295 |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
296 |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
297 /* Main entry point to executable - should *not* be SDL_main! */ |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
298 int main (int argc, char **argv) |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
299 { |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 /* Copy the arguments into a global variable */ |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 /* 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
|
302 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
|
303 gArgc = 1; |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
304 gFinderLaunch = YES; |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 } else { |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 gArgc = argc; |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
307 gFinderLaunch = NO; |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 } |
957
217f119a19a0
Date: Thu, 2 Sep 2004 19:35:51 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
476
diff
changeset
|
309 gArgv = argv; |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
311 #if SDL_USE_NIB_FILE |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
312 [SDLApplication poseAsClass:[NSApplication class]]; |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 NSApplicationMain (argc, argv); |
221
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
314 #else |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
315 CustomApplicationMain (argc, argv); |
50620ec9c86a
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
194
diff
changeset
|
316 #endif |
194
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 return 0; |
ba9e0fcc2ae2
Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 } |