annotate src/main/macosx/SDLMain.m @ 1666:6e7ec5cb83c3 SDL-1.3

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