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