annotate SDL 1.2 Mac Application.xctemplate/SDLMain.m @ 0:b0b91cadc484

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