• R/O
  • SSH
  • HTTPS

marathon: コミット


コミットメタ情報

リビジョン498 (tree)
日時2011-07-30 21:36:20
作者logue

ログメッセージ

AlephOneJP-20110730リリース

変更サマリ

差分

--- marathon/trunk/docs/MML.html (revision 497)
+++ marathon/trunk/docs/MML.html (revision 498)
@@ -389,7 +389,7 @@
389389 <ol type=1 start=1000>
390390 <li>Wall (solid)
391391 <li>Elevation (not solid; floor on one side higher than on the other side)
392-<li>Control panel
392+<li>Control panel (unused)
393393 </ol>
394394 <li>scale: 0 is minimum map scale and 3 is maximum map scale
395395 <li>width: width value in pixels
@@ -409,7 +409,7 @@
409409 <li>Hill
410410 <li>Solid Line
411411 <li>Elevation Line
412-<li>Control Panel
412+<li>Control Panel (unused)
413413 <li>Bob Display
414414 <li>Monster Display
415415 <li>Item Display
--- marathon/trunk/PBProjects/SDLMain.m (revision 497)
+++ marathon/trunk/PBProjects/SDLMain.m (revision 498)
@@ -1,465 +1,465 @@
1-/* SDLMain.m - main entry point for our Cocoa-ized SDL app
2- Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
3- Non-NIB-Code & other changes: Max Horn <max@quendi.de>
4-
5- Feel free to customize this file to suit your needs
6-*/
7-
8-#import "SDL.h"
9-#import "SDLMain.h"
10-#import <sys/param.h> /* for MAXPATHLEN */
11-#import <unistd.h>
12-
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
15- it ourselves here. */
16-@interface NSApplication(SDL_Missing_Methods)
17-- (void)setAppleMenu:(NSMenu *)menu;
18-@end
19-
20-/* Use this flag to determine whether we use SDLMain.nib or not */
21-#define SDL_USE_NIB_FILE 0
22-
23-/* Use this flag to determine whether we use CPS (docking) or not */
24-#define SDL_USE_CPS 0
25-#if SDL_USE_CPS
26-/* Portions of CPS.h */
27-typedef struct CPSProcessSerNum
28-{
29- UInt32 lo;
30- UInt32 hi;
31-} CPSProcessSerNum;
32-
33-extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
34-extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
35-extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
36-
37-#endif /* SDL_USE_CPS */
38-
39-/* The name of our bundle (such as AlephOneSDL.app") which we determine at run-time */
40-char *bundle_name = NULL;
41-
42-static int gArgc;
43-static char **gArgv;
44-static BOOL gFinderLaunch;
45-static BOOL gCalledAppMainline = FALSE;
46-
47-static NSString *getApplicationName(void)
48-{
49- NSDictionary *dict;
50- NSString *appName = 0;
51-
52- /* Determine the application name */
53- dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
54- if (dict)
55- appName = [dict objectForKey: @"CFBundleName"];
56-
57- if (![appName length])
58- appName = [[NSProcessInfo processInfo] processName];
59-
60- return appName;
61-}
62-
63-#if SDL_USE_NIB_FILE
64-/* A helper category for NSString */
65-@interface NSString (ReplaceSubString)
66-- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
67-@end
68-#endif
69-
70-@interface SDLApplication : NSApplication
71-@end
72-
73-@implementation SDLApplication
74-/* Invoked from the Quit menu item */
75-- (void)terminate:(id)sender
76-{
77- /* Post a SDL_QUIT event */
78- SDL_Event event;
79- event.type = SDL_QUIT;
80- SDL_PushEvent(&event);
81-}
82-@end
83-
84-/* The main class of the application, the application's delegate */
85-@implementation SDLMain
86-
87-- (IBAction)prefsMenu:(id)sender
88-{
89- printf ("prefs menu\n");
90-}
91-
92-- (IBAction)newGame:(id)sender
93-{
94- printf ("new game\n");
95-
96- NSRunAlertPanel (@"Get ready to blow up some... stuff!",
97- @"Click OK to begin total carnage. Click Cancel to prevent total carnage.", @"OK", @"Cancel", nil);
98-}
99-
100-- (IBAction)openGame:(id)sender
101-{
102- NSString *path = nil;
103- NSOpenPanel *openPanel = [ NSOpenPanel openPanel ];
104-
105- if ( [ openPanel runModalForDirectory:nil
106- file:@"SavedGame" types:nil ] ) {
107-
108- path = [ [ openPanel filenames ] objectAtIndex:0 ];
109- }
110-
111- printf ("open game: %s\n", [ path UTF8String ]);
112-}
113-
114-- (IBAction)saveGame:(id)sender
115-{
116- NSString *path = nil;
117- NSSavePanel *savePanel = [ NSSavePanel savePanel ];
118-
119- if ( [ savePanel runModalForDirectory:nil
120- file:@"SaveGameFile" ] ) {
121-
122- path = [ savePanel filename ];
123- }
124-
125- printf ("save game: %s\n", [ path UTF8String ]);
126-}
127-
128-- (IBAction)saveGameAs:(id)sender
129-{
130- printf ("save game as\n");
131-}
132-
133-- (IBAction)help:(id)sender
134-{
135- NSRunAlertPanel (@"Oh help, where have ye gone?",
136- @"Sorry, there is no help available.\n\nThis message brought to you by We Don't Document, Inc.\n\n", @"Rats", @"Good, I never read it anyway", nil);
137-}
138-
139-/* Find the name of our bundle, as we'll need this later for finding files. */
140-- (void) findBundleName
141-{
142- int i;
143- char buf[MAXPATHLEN];
144-
145- strlcpy(buf, gArgv[0], sizeof(buf));
146- for (i = strlen(buf) - 14; i >= 0; i--) {
147- /* Assumption: the bundle is named *.app and has a 'Contents' directory inside it. */
148- if (!strncmp(buf + i, ".app/Contents/", 14)) {
149- int old_i = i;
150- buf[i + 4] = '\0'; // truncate end
151- for (; i >= 0; i--) // and beginning
152- if (buf[i] == '/') {
153- bundle_name = (char *) malloc(old_i - i + 4);
154- strlcpy(bundle_name, buf + i + 1, old_i - i + 4);
155- break;
156- }
157- break;
158- }
159- }
160-}
161-
162-/* Set the working directory to the .app's parent directory */
163-- (void) setupWorkingDirectory:(BOOL)shouldChdir
164-{
165- if (shouldChdir)
166- {
167- char parentdir[MAXPATHLEN];
168- CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
169- CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
170- if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) {
171- assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
172- }
173- CFRelease(url);
174- CFRelease(url2);
175- }
176-
177-}
178-
179-#if SDL_USE_NIB_FILE
180-
181-/* Fix menu to contain the real app name instead of "SDL App" */
182-- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
183-{
184- NSRange aRange;
185- NSEnumerator *enumerator;
186- NSMenuItem *menuItem;
187-
188- aRange = [[aMenu title] rangeOfString:@"SDL App"];
189- if (aRange.length != 0)
190- [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
191-
192- enumerator = [[aMenu itemArray] objectEnumerator];
193- while ((menuItem = [enumerator nextObject]))
194- {
195- aRange = [[menuItem title] rangeOfString:@"SDL App"];
196- if (aRange.length != 0)
197- [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
198- if ([menuItem hasSubmenu])
199- [self fixMenu:[menuItem submenu] withAppName:appName];
200- }
201- [ aMenu sizeToFit ];
202-}
203-
204-#else
205-
206-static void setApplicationMenu(void)
207-{
208- /* warning: this code is very odd */
209- NSMenu *appleMenu;
210- NSMenuItem *menuItem;
211- NSString *title;
212- NSString *appName;
213-
214- appName = getApplicationName();
215- appleMenu = [[NSMenu alloc] initWithTitle:@""];
216-
217- /* Add menu items */
218- title = [@"About " stringByAppendingString:appName];
219- [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
220-
221- [appleMenu addItem:[NSMenuItem separatorItem]];
222-
223- title = [@"Hide " stringByAppendingString:appName];
224- [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
225-
226- menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
227- [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
228-
229- [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
230-
231- [appleMenu addItem:[NSMenuItem separatorItem]];
232-
233- title = [@"Quit " stringByAppendingString:appName];
234- [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
235-
236-
237- /* Put menu into the menubar */
238- menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
239- [menuItem setSubmenu:appleMenu];
240- [[NSApp mainMenu] addItem:menuItem];
241-
242- /* Tell the application object that this is now the application menu */
243- [NSApp setAppleMenu:appleMenu];
244-
245- /* Finally give up our references to the objects */
246- [appleMenu release];
247- [menuItem release];
248-}
249-
250-/* Create a window menu */
251-static void setupWindowMenu(void)
252-{
253- NSMenu *windowMenu;
254- NSMenuItem *windowMenuItem;
255- NSMenuItem *menuItem;
256-
257- windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
258-
259- /* "Minimize" item */
260- menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
261- [windowMenu addItem:menuItem];
262- [menuItem release];
263-
264- /* Put menu into the menubar */
265- windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
266- [windowMenuItem setSubmenu:windowMenu];
267- [[NSApp mainMenu] addItem:windowMenuItem];
268-
269- /* Tell the application object that this is now the window menu */
270- [NSApp setWindowsMenu:windowMenu];
271-
272- /* Finally give up our references to the objects */
273- [windowMenu release];
274- [windowMenuItem release];
275-}
276-
277-/* Replacement for NSApplicationMain */
278-static void CustomApplicationMain (int argc, char **argv)
279-{
280- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
281- SDLMain *sdlMain;
282-
283- /* Ensure the application object is initialised */
284- [SDLApplication sharedApplication];
285-
286-#if SDL_USE_CPS
287- {
288- CPSProcessSerNum PSN;
289- /* Tell the dock about us */
290- if (!CPSGetCurrentProcess(&PSN))
291- if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
292- if (!CPSSetFrontProcess(&PSN))
293- [SDLApplication sharedApplication];
294- }
295-#endif /* SDL_USE_CPS */
296-
297- /* Set up the menubar */
298- [NSApp setMainMenu:[[NSMenu alloc] init]];
299- setApplicationMenu();
300- setupWindowMenu();
301-
302- /* Create SDLMain and make it the app delegate */
303- sdlMain = [[SDLMain alloc] init];
304- [NSApp setDelegate:sdlMain];
305-
306- /* Start the main event loop */
307- [NSApp run];
308-
309- [sdlMain release];
310- [pool release];
311-}
312-
313-#endif
314-
315-
316-/*
317- * Catch document open requests...this lets us notice files when the app
318- * was launched by double-clicking a document, or when a document was
319- * dragged/dropped on the app's icon. You need to have a
320- * CFBundleDocumentsType section in your Info.plist to get this message,
321- * apparently.
322- *
323- * Files are added to gArgv, so to the app, they'll look like command line
324- * arguments. Previously, apps launched from the finder had nothing but
325- * an argv[0].
326- *
327- * This message may be received multiple times to open several docs on launch.
328- *
329- * This message is ignored once the app's mainline has been called.
330- */
331-- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
332-{
333- const char *temparg;
334- size_t arglen;
335- char *arg;
336- char **newargv;
337-
338- if (!gFinderLaunch) /* MacOS is passing command line args. */
339- return FALSE;
340-
341- if (gCalledAppMainline) /* app has started, ignore this document. */
342- return FALSE;
343-
344- temparg = [filename UTF8String];
345- arglen = SDL_strlen(temparg) + 1;
346- arg = (char *) SDL_malloc(arglen);
347- if (arg == NULL)
348- return FALSE;
349-
350- newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
351- if (newargv == NULL)
352- {
353- SDL_free(arg);
354- return FALSE;
355- }
356- gArgv = newargv;
357-
358- SDL_strlcpy(arg, temparg, arglen);
359- gArgv[gArgc++] = arg;
360- gArgv[gArgc] = NULL;
361- return TRUE;
362-}
363-
364-
365-/* Called when the internal event loop has just started running */
366-- (void) applicationDidFinishLaunching: (NSNotification *) note
367-{
368- int status;
369-
370-/* Find the bundle name from where we were launched and save for later use */
371- [self findBundleName];
372-
373- /* Set the working directory to the .app's parent directory */
374- [self setupWorkingDirectory:gFinderLaunch];
375-
376-#if SDL_USE_NIB_FILE
377- /* Set the main menu to contain the real app name instead of "SDL App" */
378- [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
379-#endif
380-
381- /* Hand off to main application code */
382- gCalledAppMainline = TRUE;
383- status = SDL_main (gArgc, gArgv);
384-
385- /* We're done, thank you for playing */
386- free(bundle_name);
387- exit(status);
388-}
389-@end
390-
391-
392-@implementation NSString (ReplaceSubString)
393-
394-- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
395-{
396- unsigned int bufferSize;
397- unsigned int selfLen = [self length];
398- unsigned int aStringLen = [aString length];
399- unichar *buffer;
400- NSRange localRange;
401- NSString *result;
402-
403- bufferSize = selfLen + aStringLen - aRange.length;
404- buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
405-
406- /* Get first part into buffer */
407- localRange.location = 0;
408- localRange.length = aRange.location;
409- [self getCharacters:buffer range:localRange];
410-
411- /* Get middle part into buffer */
412- localRange.location = 0;
413- localRange.length = aStringLen;
414- [aString getCharacters:(buffer+aRange.location) range:localRange];
415-
416- /* Get last part into buffer */
417- localRange.location = aRange.location + aRange.length;
418- localRange.length = selfLen - localRange.location;
419- [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
420-
421- /* Build output string */
422- result = [NSString stringWithCharacters:buffer length:bufferSize];
423-
424- NSDeallocateMemoryPages(buffer, bufferSize);
425-
426- return result;
427-}
428-
429-@end
430-
431-
432-
433-#ifdef main
434-# undef main
435-#endif
436-
437-
438-/* Main entry point to executable - should *not* be SDL_main! */
439-int main (int argc, char **argv)
440-{
441- /* Copy the arguments into a global variable */
442- /* This is passed if we are launched by double-clicking */
443- if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
444- gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
445- gArgv[0] = argv[0];
446- gArgv[1] = NULL;
447- gArgc = 1;
448- gFinderLaunch = YES;
449- } else {
450- int i;
451- gArgc = argc;
452- gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
453- for (i = 0; i <= argc; i++)
454- gArgv[i] = argv[i];
455- gFinderLaunch = NO;
456- }
457-
458-#if SDL_USE_NIB_FILE
459- [SDLApplication poseAsClass:[NSApplication class]];
460- NSApplicationMain (argc, argv);
461-#else
462- CustomApplicationMain (argc, argv);
463-#endif
464- return 0;
465-}
1+/* SDLMain.m - main entry point for our Cocoa-ized SDL app
2+ Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
3+ Non-NIB-Code & other changes: Max Horn <max@quendi.de>
4+
5+ Feel free to customize this file to suit your needs
6+*/
7+
8+#import "SDL.h"
9+#import "SDLMain.h"
10+#import <sys/param.h> /* for MAXPATHLEN */
11+#import <unistd.h>
12+
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
15+ it ourselves here. */
16+@interface NSApplication(SDL_Missing_Methods)
17+- (void)setAppleMenu:(NSMenu *)menu;
18+@end
19+
20+/* Use this flag to determine whether we use SDLMain.nib or not */
21+#define SDL_USE_NIB_FILE 0
22+
23+/* Use this flag to determine whether we use CPS (docking) or not */
24+#define SDL_USE_CPS 0
25+#if SDL_USE_CPS
26+/* Portions of CPS.h */
27+typedef struct CPSProcessSerNum
28+{
29+ UInt32 lo;
30+ UInt32 hi;
31+} CPSProcessSerNum;
32+
33+extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
34+extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
35+extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
36+
37+#endif /* SDL_USE_CPS */
38+
39+/* The name of our bundle (such as AlephOneSDL.app") which we determine at run-time */
40+char *bundle_name = NULL;
41+
42+static int gArgc;
43+static char **gArgv;
44+static BOOL gFinderLaunch;
45+static BOOL gCalledAppMainline = FALSE;
46+
47+static NSString *getApplicationName(void)
48+{
49+ NSDictionary *dict;
50+ NSString *appName = 0;
51+
52+ /* Determine the application name */
53+ dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
54+ if (dict)
55+ appName = [dict objectForKey: @"CFBundleName"];
56+
57+ if (![appName length])
58+ appName = [[NSProcessInfo processInfo] processName];
59+
60+ return appName;
61+}
62+
63+#if SDL_USE_NIB_FILE
64+/* A helper category for NSString */
65+@interface NSString (ReplaceSubString)
66+- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
67+@end
68+#endif
69+
70+@interface SDLApplication : NSApplication
71+@end
72+
73+@implementation SDLApplication
74+/* Invoked from the Quit menu item */
75+- (void)terminate:(id)sender
76+{
77+ /* Post a SDL_QUIT event */
78+ SDL_Event event;
79+ event.type = SDL_QUIT;
80+ SDL_PushEvent(&event);
81+}
82+@end
83+
84+/* The main class of the application, the application's delegate */
85+@implementation SDLMain
86+
87+- (IBAction)prefsMenu:(id)sender
88+{
89+ printf ("prefs menu\n");
90+}
91+
92+- (IBAction)newGame:(id)sender
93+{
94+ printf ("new game\n");
95+
96+ NSRunAlertPanel (@"Get ready to blow up some... stuff!",
97+ @"Click OK to begin total carnage. Click Cancel to prevent total carnage.", @"OK", @"Cancel", nil);
98+}
99+
100+- (IBAction)openGame:(id)sender
101+{
102+ NSString *path = nil;
103+ NSOpenPanel *openPanel = [ NSOpenPanel openPanel ];
104+
105+ if ( [ openPanel runModalForDirectory:nil
106+ file:@"SavedGame" types:nil ] ) {
107+
108+ path = [ [ openPanel filenames ] objectAtIndex:0 ];
109+ }
110+
111+ printf ("open game: %s\n", [ path UTF8String ]);
112+}
113+
114+- (IBAction)saveGame:(id)sender
115+{
116+ NSString *path = nil;
117+ NSSavePanel *savePanel = [ NSSavePanel savePanel ];
118+
119+ if ( [ savePanel runModalForDirectory:nil
120+ file:@"SaveGameFile" ] ) {
121+
122+ path = [ savePanel filename ];
123+ }
124+
125+ printf ("save game: %s\n", [ path UTF8String ]);
126+}
127+
128+- (IBAction)saveGameAs:(id)sender
129+{
130+ printf ("save game as\n");
131+}
132+
133+- (IBAction)help:(id)sender
134+{
135+ NSRunAlertPanel (@"Oh help, where have ye gone?",
136+ @"Sorry, there is no help available.\n\nThis message brought to you by We Don't Document, Inc.\n\n", @"Rats", @"Good, I never read it anyway", nil);
137+}
138+
139+/* Find the name of our bundle, as we'll need this later for finding files. */
140+- (void) findBundleName
141+{
142+ int i;
143+ char buf[MAXPATHLEN];
144+
145+ strlcpy(buf, gArgv[0], sizeof(buf));
146+ for (i = strlen(buf) - 14; i >= 0; i--) {
147+ /* Assumption: the bundle is named *.app and has a 'Contents' directory inside it. */
148+ if (!strncmp(buf + i, ".app/Contents/", 14)) {
149+ int old_i = i;
150+ buf[i + 4] = '\0'; // truncate end
151+ for (; i >= 0; i--) // and beginning
152+ if (buf[i] == '/') {
153+ bundle_name = (char *) malloc(old_i - i + 4);
154+ strlcpy(bundle_name, buf + i + 1, old_i - i + 4);
155+ break;
156+ }
157+ break;
158+ }
159+ }
160+}
161+
162+/* Set the working directory to the .app's parent directory */
163+- (void) setupWorkingDirectory:(BOOL)shouldChdir
164+{
165+ if (shouldChdir)
166+ {
167+ char parentdir[MAXPATHLEN];
168+ CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
169+ CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
170+ if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) {
171+ assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
172+ }
173+ CFRelease(url);
174+ CFRelease(url2);
175+ }
176+
177+}
178+
179+#if SDL_USE_NIB_FILE
180+
181+/* Fix menu to contain the real app name instead of "SDL App" */
182+- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
183+{
184+ NSRange aRange;
185+ NSEnumerator *enumerator;
186+ NSMenuItem *menuItem;
187+
188+ aRange = [[aMenu title] rangeOfString:@"SDL App"];
189+ if (aRange.length != 0)
190+ [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
191+
192+ enumerator = [[aMenu itemArray] objectEnumerator];
193+ while ((menuItem = [enumerator nextObject]))
194+ {
195+ aRange = [[menuItem title] rangeOfString:@"SDL App"];
196+ if (aRange.length != 0)
197+ [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
198+ if ([menuItem hasSubmenu])
199+ [self fixMenu:[menuItem submenu] withAppName:appName];
200+ }
201+ [ aMenu sizeToFit ];
202+}
203+
204+#else
205+
206+static void setApplicationMenu(void)
207+{
208+ /* warning: this code is very odd */
209+ NSMenu *appleMenu;
210+ NSMenuItem *menuItem;
211+ NSString *title;
212+ NSString *appName;
213+
214+ appName = getApplicationName();
215+ appleMenu = [[NSMenu alloc] initWithTitle:@""];
216+
217+ /* Add menu items */
218+ title = [@"About " stringByAppendingString:appName];
219+ [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
220+
221+ [appleMenu addItem:[NSMenuItem separatorItem]];
222+
223+ title = [@"Hide " stringByAppendingString:appName];
224+ [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
225+
226+ menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
227+ [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
228+
229+ [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
230+
231+ [appleMenu addItem:[NSMenuItem separatorItem]];
232+
233+ title = [@"Quit " stringByAppendingString:appName];
234+ [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
235+
236+
237+ /* Put menu into the menubar */
238+ menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
239+ [menuItem setSubmenu:appleMenu];
240+ [[NSApp mainMenu] addItem:menuItem];
241+
242+ /* Tell the application object that this is now the application menu */
243+ [NSApp setAppleMenu:appleMenu];
244+
245+ /* Finally give up our references to the objects */
246+ [appleMenu release];
247+ [menuItem release];
248+}
249+
250+/* Create a window menu */
251+static void setupWindowMenu(void)
252+{
253+ NSMenu *windowMenu;
254+ NSMenuItem *windowMenuItem;
255+ NSMenuItem *menuItem;
256+
257+ windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
258+
259+ /* "Minimize" item */
260+ menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
261+ [windowMenu addItem:menuItem];
262+ [menuItem release];
263+
264+ /* Put menu into the menubar */
265+ windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
266+ [windowMenuItem setSubmenu:windowMenu];
267+ [[NSApp mainMenu] addItem:windowMenuItem];
268+
269+ /* Tell the application object that this is now the window menu */
270+ [NSApp setWindowsMenu:windowMenu];
271+
272+ /* Finally give up our references to the objects */
273+ [windowMenu release];
274+ [windowMenuItem release];
275+}
276+
277+/* Replacement for NSApplicationMain */
278+static void CustomApplicationMain (int argc, char **argv)
279+{
280+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
281+ SDLMain *sdlMain;
282+
283+ /* Ensure the application object is initialised */
284+ [SDLApplication sharedApplication];
285+
286+#if SDL_USE_CPS
287+ {
288+ CPSProcessSerNum PSN;
289+ /* Tell the dock about us */
290+ if (!CPSGetCurrentProcess(&PSN))
291+ if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
292+ if (!CPSSetFrontProcess(&PSN))
293+ [SDLApplication sharedApplication];
294+ }
295+#endif /* SDL_USE_CPS */
296+
297+ /* Set up the menubar */
298+ [NSApp setMainMenu:[[NSMenu alloc] init]];
299+ setApplicationMenu();
300+ setupWindowMenu();
301+
302+ /* Create SDLMain and make it the app delegate */
303+ sdlMain = [[SDLMain alloc] init];
304+ [NSApp setDelegate:sdlMain];
305+
306+ /* Start the main event loop */
307+ [NSApp run];
308+
309+ [sdlMain release];
310+ [pool release];
311+}
312+
313+#endif
314+
315+
316+/*
317+ * Catch document open requests...this lets us notice files when the app
318+ * was launched by double-clicking a document, or when a document was
319+ * dragged/dropped on the app's icon. You need to have a
320+ * CFBundleDocumentsType section in your Info.plist to get this message,
321+ * apparently.
322+ *
323+ * Files are added to gArgv, so to the app, they'll look like command line
324+ * arguments. Previously, apps launched from the finder had nothing but
325+ * an argv[0].
326+ *
327+ * This message may be received multiple times to open several docs on launch.
328+ *
329+ * This message is ignored once the app's mainline has been called.
330+ */
331+- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
332+{
333+ const char *temparg;
334+ size_t arglen;
335+ char *arg;
336+ char **newargv;
337+
338+ if (!gFinderLaunch) /* MacOS is passing command line args. */
339+ return TRUE; /* We'll handle this in usage() instead. */
340+
341+ if (gCalledAppMainline) /* app has started, ignore this document. */
342+ return FALSE;
343+
344+ temparg = [filename UTF8String];
345+ arglen = SDL_strlen(temparg) + 1;
346+ arg = (char *) SDL_malloc(arglen);
347+ if (arg == NULL)
348+ return FALSE;
349+
350+ newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
351+ if (newargv == NULL)
352+ {
353+ SDL_free(arg);
354+ return FALSE;
355+ }
356+ gArgv = newargv;
357+
358+ SDL_strlcpy(arg, temparg, arglen);
359+ gArgv[gArgc++] = arg;
360+ gArgv[gArgc] = NULL;
361+ return TRUE;
362+}
363+
364+
365+/* Called when the internal event loop has just started running */
366+- (void) applicationDidFinishLaunching: (NSNotification *) note
367+{
368+ int status;
369+
370+/* Find the bundle name from where we were launched and save for later use */
371+ [self findBundleName];
372+
373+ /* Set the working directory to the .app's parent directory */
374+ [self setupWorkingDirectory:gFinderLaunch];
375+
376+#if SDL_USE_NIB_FILE
377+ /* Set the main menu to contain the real app name instead of "SDL App" */
378+ [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
379+#endif
380+
381+ /* Hand off to main application code */
382+ gCalledAppMainline = TRUE;
383+ status = SDL_main (gArgc, gArgv);
384+
385+ /* We're done, thank you for playing */
386+ free(bundle_name);
387+ exit(status);
388+}
389+@end
390+
391+
392+@implementation NSString (ReplaceSubString)
393+
394+- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
395+{
396+ unsigned int bufferSize;
397+ unsigned int selfLen = [self length];
398+ unsigned int aStringLen = [aString length];
399+ unichar *buffer;
400+ NSRange localRange;
401+ NSString *result;
402+
403+ bufferSize = selfLen + aStringLen - aRange.length;
404+ buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
405+
406+ /* Get first part into buffer */
407+ localRange.location = 0;
408+ localRange.length = aRange.location;
409+ [self getCharacters:buffer range:localRange];
410+
411+ /* Get middle part into buffer */
412+ localRange.location = 0;
413+ localRange.length = aStringLen;
414+ [aString getCharacters:(buffer+aRange.location) range:localRange];
415+
416+ /* Get last part into buffer */
417+ localRange.location = aRange.location + aRange.length;
418+ localRange.length = selfLen - localRange.location;
419+ [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
420+
421+ /* Build output string */
422+ result = [NSString stringWithCharacters:buffer length:bufferSize];
423+
424+ NSDeallocateMemoryPages(buffer, bufferSize);
425+
426+ return result;
427+}
428+
429+@end
430+
431+
432+
433+#ifdef main
434+# undef main
435+#endif
436+
437+
438+/* Main entry point to executable - should *not* be SDL_main! */
439+int main (int argc, char **argv)
440+{
441+ /* Copy the arguments into a global variable */
442+ /* This is passed if we are launched by double-clicking */
443+ if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
444+ gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
445+ gArgv[0] = argv[0];
446+ gArgv[1] = NULL;
447+ gArgc = 1;
448+ gFinderLaunch = YES;
449+ } else {
450+ int i;
451+ gArgc = argc;
452+ gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
453+ for (i = 0; i <= argc; i++)
454+ gArgv[i] = argv[i];
455+ gFinderLaunch = NO;
456+ }
457+
458+#if SDL_USE_NIB_FILE
459+ [SDLApplication poseAsClass:[NSApplication class]];
460+ NSApplicationMain (argc, argv);
461+#else
462+ CustomApplicationMain (argc, argv);
463+#endif
464+ return 0;
465+}
旧リポジトリブラウザで表示