annotate src/main/macosx/SDLMain.m @ 1662:782fd950bd46 SDL-1.3

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