Mercurial > sdl-ios-xcode
annotate src/main/macos/SDL_main.c @ 1348:40d0975c1769
Date: Mon, 6 Feb 2006 11:41:04 -0500
From: "mystml@adinet.com.uy"
Subject: [SDL] ALT-F4 using DirectX
My game isn't getting SDL_QUIT when I press ALT-F4 using the DirectX
driver; it does get SDL_QUIT when I press the red X in the window.
I tracked this down to DX5_HandleMessage() in SDL_dx5events.c;
WM_SYSKEYDOWN is being trapped and ignored which causes Windows not to post
a WM_CLOSE, hence no SDL_QUIT is being generated.
The relevant code is this :
/* The keyboard is handled via DirectInput */
case WM_SYSKEYUP:
case WM_SYSKEYDOWN:
case WM_KEYUP:
case WM_KEYDOWN: {
/* Ignore windows keyboard messages */;
}
return(0);
If I comment the WM_SYSKEYDOWN case, it falls through DefWindowProc() and
ALT-F4 starts working again.
I'm not sure about the best way to fix this. One option is handling ALT-F4
as a particular case somehow, but doesn't sound good. Another option would
be to handle WM_SYSKEYDOWN separately and breaking instead of returning 0,
so processing falls through and goes to DefWindowProc which does The Right
Thing (TM). This seems to be the minimal change that makes ALT-F4 work and
normal keyboard input continues to work.
Does this sound reasonable? Am I overlooking anything? Do I submit a patch?
--Gabriel
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 08 Feb 2006 17:19:43 +0000 |
parents | 604d73db6802 |
children | 7a610f25c12f |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 /* This file takes care of command line argument parsing, and stdio redirection | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
24 in the MacOS environment. (stdio/stderr is *not* directed for Mach-O builds) |
0 | 25 */ |
26 | |
27 #include <stdio.h> | |
28 #include <stdlib.h> | |
29 #include <string.h> | |
30 #include <ctype.h> | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
31 #if defined(__APPLE__) && defined(__MACH__) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
32 #include <Carbon/Carbon.h> |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
33 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) |
0 | 34 #include <Carbon.h> |
35 #else | |
36 #include <Dialogs.h> | |
37 #include <Fonts.h> | |
38 #include <Events.h> | |
39 #include <Resources.h> | |
40 #include <Folders.h> | |
41 #endif | |
42 | |
43 /* Include the SDL main definition header */ | |
44 #include "SDL.h" | |
45 #include "SDL_main.h" | |
46 #ifdef main | |
47 #undef main | |
48 #endif | |
49 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
50 #if !(defined(__APPLE__) && defined(__MACH__)) |
0 | 51 /* The standard output files */ |
52 #define STDOUT_FILE "stdout.txt" | |
53 #define STDERR_FILE "stderr.txt" | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
54 #endif |
0 | 55 |
56 #if !defined(__MWERKS__) && !TARGET_API_MAC_CARBON | |
57 /* In MPW, the qd global has been removed from the libraries */ | |
58 QDGlobals qd; | |
59 #endif | |
60 | |
61 /* Structure for keeping prefs in 1 variable */ | |
62 typedef struct { | |
63 Str255 command_line; | |
64 Str255 video_driver_name; | |
65 Boolean output_to_file; | |
66 } PrefsRecord; | |
67 | |
68 /* See if the command key is held down at startup */ | |
69 static Boolean CommandKeyIsDown(void) | |
70 { | |
71 KeyMap theKeyMap; | |
72 | |
73 GetKeys(theKeyMap); | |
74 | |
75 if (((unsigned char *) theKeyMap)[6] & 0x80) { | |
76 return(true); | |
77 } | |
78 return(false); | |
79 } | |
80 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
81 #if !(defined(__APPLE__) && defined(__MACH__)) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
82 |
0 | 83 /* Parse a command line buffer into arguments */ |
84 static int ParseCommandLine(char *cmdline, char **argv) | |
85 { | |
86 char *bufp; | |
87 int argc; | |
88 | |
89 argc = 0; | |
90 for ( bufp = cmdline; *bufp; ) { | |
91 /* Skip leading whitespace */ | |
92 while ( isspace(*bufp) ) { | |
93 ++bufp; | |
94 } | |
95 /* Skip over argument */ | |
96 if ( *bufp == '"' ) { | |
97 ++bufp; | |
98 if ( *bufp ) { | |
99 if ( argv ) { | |
100 argv[argc] = bufp; | |
101 } | |
102 ++argc; | |
103 } | |
104 /* Skip over word */ | |
105 while ( *bufp && (*bufp != '"') ) { | |
106 ++bufp; | |
107 } | |
108 } else { | |
109 if ( *bufp ) { | |
110 if ( argv ) { | |
111 argv[argc] = bufp; | |
112 } | |
113 ++argc; | |
114 } | |
115 /* Skip over word */ | |
116 while ( *bufp && ! isspace(*bufp) ) { | |
117 ++bufp; | |
118 } | |
119 } | |
120 if ( *bufp ) { | |
121 if ( argv ) { | |
122 *bufp = '\0'; | |
123 } | |
124 ++bufp; | |
125 } | |
126 } | |
127 if ( argv ) { | |
128 argv[argc] = NULL; | |
129 } | |
130 return(argc); | |
131 } | |
132 | |
133 /* Remove the output files if there was no output written */ | |
134 static void cleanup_output(void) | |
135 { | |
136 FILE *file; | |
137 int empty; | |
138 | |
139 /* Flush the output in case anything is queued */ | |
140 fclose(stdout); | |
141 fclose(stderr); | |
142 | |
143 /* See if the files have any output in them */ | |
144 file = fopen(STDOUT_FILE, "rb"); | |
145 if ( file ) { | |
146 empty = (fgetc(file) == EOF) ? 1 : 0; | |
147 fclose(file); | |
148 if ( empty ) { | |
149 remove(STDOUT_FILE); | |
150 } | |
151 } | |
152 file = fopen(STDERR_FILE, "rb"); | |
153 if ( file ) { | |
154 empty = (fgetc(file) == EOF) ? 1 : 0; | |
155 fclose(file); | |
156 if ( empty ) { | |
157 remove(STDERR_FILE); | |
158 } | |
159 } | |
160 } | |
161 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
162 #endif //!(defined(__APPLE__) && defined(__MACH__)) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
163 |
0 | 164 static int getCurrentAppName (StrFileName name) { |
165 | |
166 ProcessSerialNumber process; | |
167 ProcessInfoRec process_info; | |
168 FSSpec process_fsp; | |
169 | |
170 process.highLongOfPSN = 0; | |
171 process.lowLongOfPSN = kCurrentProcess; | |
172 process_info.processInfoLength = sizeof (process_info); | |
173 process_info.processName = NULL; | |
174 process_info.processAppSpec = &process_fsp; | |
175 | |
176 if ( noErr != GetProcessInformation (&process, &process_info) ) | |
177 return 0; | |
178 | |
179 memcpy (name, process_fsp.name, process_fsp.name[0] + 1); | |
180 return 1; | |
181 } | |
182 | |
183 static int getPrefsFile (FSSpec *prefs_fsp, int create) { | |
184 | |
185 /* The prefs file name is the application name, possibly truncated, */ | |
186 /* plus " Preferences */ | |
187 | |
188 #define SUFFIX " Preferences" | |
189 #define MAX_NAME 19 /* 31 - strlen (SUFFIX) */ | |
190 | |
191 short volume_ref_number; | |
192 long directory_id; | |
193 StrFileName prefs_name; | |
194 StrFileName app_name; | |
195 | |
196 /* Get Preferences folder - works with Multiple Users */ | |
197 if ( noErr != FindFolder ( kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, | |
198 &volume_ref_number, &directory_id) ) | |
199 exit (-1); | |
200 | |
201 if ( ! getCurrentAppName (app_name) ) | |
202 exit (-1); | |
203 | |
204 /* Truncate if name is too long */ | |
205 if (app_name[0] > MAX_NAME ) | |
206 app_name[0] = MAX_NAME; | |
207 | |
208 memcpy (prefs_name + 1, app_name + 1, app_name[0]); | |
209 memcpy (prefs_name + app_name[0] + 1, SUFFIX, strlen (SUFFIX)); | |
210 prefs_name[0] = app_name[0] + strlen (SUFFIX); | |
211 | |
212 /* Make the file spec for prefs file */ | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
213 if ( noErr != FSMakeFSSpec (volume_ref_number, directory_id, prefs_name, prefs_fsp) ) { |
0 | 214 if ( !create ) |
215 return 0; | |
216 else { | |
217 /* Create the prefs file */ | |
218 memcpy (prefs_fsp->name, prefs_name, prefs_name[0] + 1); | |
219 prefs_fsp->parID = directory_id; | |
220 prefs_fsp->vRefNum = volume_ref_number; | |
221 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
222 FSpCreateResFile (prefs_fsp, 0x3f3f3f3f, 'pref', 0); // '????' parsed as trigraph |
0 | 223 |
224 if ( noErr != ResError () ) | |
225 return 0; | |
226 } | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
227 } |
0 | 228 return 1; |
229 } | |
230 | |
231 static int readPrefsResource (PrefsRecord *prefs) { | |
232 | |
233 Handle prefs_handle; | |
234 | |
235 prefs_handle = Get1Resource( 'CLne', 128 ); | |
236 | |
237 if (prefs_handle != NULL) { | |
238 int offset = 0; | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
239 // int j = 0; |
0 | 240 |
241 HLock(prefs_handle); | |
242 | |
243 /* Get command line string */ | |
244 memcpy (prefs->command_line, *prefs_handle, (*prefs_handle)[0]+1); | |
245 | |
246 /* Get video driver name */ | |
247 offset += (*prefs_handle)[0] + 1; | |
248 memcpy (prefs->video_driver_name, *prefs_handle + offset, (*prefs_handle)[offset] + 1); | |
249 | |
250 /* Get save-to-file option (1 or 0) */ | |
251 offset += (*prefs_handle)[offset] + 1; | |
252 prefs->output_to_file = (*prefs_handle)[offset]; | |
253 | |
254 ReleaseResource( prefs_handle ); | |
255 | |
256 return ResError() == noErr; | |
257 } | |
258 | |
259 return 0; | |
260 } | |
261 | |
262 static int writePrefsResource (PrefsRecord *prefs, short resource_file) { | |
263 | |
264 Handle prefs_handle; | |
265 | |
266 UseResFile (resource_file); | |
267 | |
268 prefs_handle = Get1Resource ( 'CLne', 128 ); | |
269 if (prefs_handle != NULL) | |
270 RemoveResource (prefs_handle); | |
271 | |
272 prefs_handle = NewHandle ( prefs->command_line[0] + prefs->video_driver_name[0] + 4 ); | |
273 if (prefs_handle != NULL) { | |
274 | |
275 int offset; | |
276 | |
277 HLock (prefs_handle); | |
278 | |
279 /* Command line text */ | |
280 offset = 0; | |
281 memcpy (*prefs_handle, prefs->command_line, prefs->command_line[0] + 1); | |
282 | |
283 /* Video driver name */ | |
284 offset += prefs->command_line[0] + 1; | |
285 memcpy (*prefs_handle + offset, prefs->video_driver_name, prefs->video_driver_name[0] + 1); | |
286 | |
287 /* Output-to-file option */ | |
288 offset += prefs->video_driver_name[0] + 1; | |
289 *( *((char**)prefs_handle) + offset) = (char)prefs->output_to_file; | |
290 *( *((char**)prefs_handle) + offset + 1) = 0; | |
291 | |
292 AddResource (prefs_handle, 'CLne', 128, "\pCommand Line"); | |
293 WriteResource (prefs_handle); | |
294 UpdateResFile (resource_file); | |
295 DisposeHandle (prefs_handle); | |
296 | |
297 return ResError() == noErr; | |
298 } | |
299 | |
300 return 0; | |
301 } | |
302 | |
303 static int readPreferences (PrefsRecord *prefs) { | |
304 | |
305 int no_error = 1; | |
306 FSSpec prefs_fsp; | |
307 | |
308 /* Check for prefs file first */ | |
309 if ( getPrefsFile (&prefs_fsp, 0) ) { | |
310 | |
311 short prefs_resource; | |
312 | |
313 prefs_resource = FSpOpenResFile (&prefs_fsp, fsRdPerm); | |
314 if ( prefs_resource == -1 ) /* this shouldn't happen, but... */ | |
315 return 0; | |
316 | |
317 UseResFile (prefs_resource); | |
318 no_error = readPrefsResource (prefs); | |
319 CloseResFile (prefs_resource); | |
320 } | |
321 | |
322 /* Fall back to application's resource fork (reading only, so this is safe) */ | |
323 else { | |
324 | |
325 no_error = readPrefsResource (prefs); | |
326 } | |
327 | |
328 return no_error; | |
329 } | |
330 | |
331 static int writePreferences (PrefsRecord *prefs) { | |
332 | |
333 int no_error = 1; | |
334 FSSpec prefs_fsp; | |
335 | |
336 /* Get prefs file, create if it doesn't exist */ | |
337 if ( getPrefsFile (&prefs_fsp, 1) ) { | |
338 | |
339 short prefs_resource; | |
340 | |
341 prefs_resource = FSpOpenResFile (&prefs_fsp, fsRdWrPerm); | |
342 if (prefs_resource == -1) | |
343 return 0; | |
344 no_error = writePrefsResource (prefs, prefs_resource); | |
345 CloseResFile (prefs_resource); | |
346 } | |
347 | |
348 return no_error; | |
349 } | |
350 | |
351 /* This is where execution begins */ | |
352 int main(int argc, char *argv[]) | |
353 { | |
354 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
355 #if !(defined(__APPLE__) && defined(__MACH__)) |
0 | 356 #pragma unused(argc, argv) |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
357 #endif |
0 | 358 |
359 #define DEFAULT_ARGS "\p" /* pascal string for default args */ | |
360 #define DEFAULT_VIDEO_DRIVER "\ptoolbox" /* pascal string for default video driver name */ | |
361 #define DEFAULT_OUTPUT_TO_FILE 1 /* 1 == output to file, 0 == no output */ | |
362 | |
363 #define VIDEO_ID_DRAWSPROCKET 1 /* these correspond to popup menu choices */ | |
364 #define VIDEO_ID_TOOLBOX 2 | |
365 | |
366 PrefsRecord prefs = { DEFAULT_ARGS, DEFAULT_VIDEO_DRIVER, DEFAULT_OUTPUT_TO_FILE }; | |
367 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
368 #if !(defined(__APPLE__) && defined(__MACH__)) |
0 | 369 int nargs; |
370 char **args; | |
371 char *commandLine; | |
372 | |
373 StrFileName appNameText; | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
374 #endif |
0 | 375 int videodriver = VIDEO_ID_TOOLBOX; |
376 int settingsChanged = 0; | |
377 | |
378 long i; | |
379 | |
380 /* Kyle's SDL command-line dialog code ... */ | |
381 #if !TARGET_API_MAC_CARBON | |
382 InitGraf (&qd.thePort); | |
383 InitFonts (); | |
384 InitWindows (); | |
385 InitMenus (); | |
386 InitDialogs (nil); | |
387 #endif | |
388 InitCursor (); | |
389 FlushEvents(everyEvent,0); | |
390 #if !TARGET_API_MAC_CARBON | |
391 MaxApplZone (); | |
392 #endif | |
393 MoreMasters (); | |
394 MoreMasters (); | |
395 #if 0 | |
396 /* Intialize SDL, and put up a dialog if we fail */ | |
397 if ( SDL_Init (0) < 0 ) { | |
398 | |
399 #define kErr_OK 1 | |
400 #define kErr_Text 2 | |
401 | |
402 DialogPtr errorDialog; | |
403 short dummyType; | |
404 Rect dummyRect; | |
405 Handle dummyHandle; | |
406 short itemHit; | |
407 | |
408 errorDialog = GetNewDialog (1001, nil, (WindowPtr)-1); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
409 if (errorDialog == NULL) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
410 return -1; |
0 | 411 DrawDialog (errorDialog); |
412 | |
413 GetDialogItem (errorDialog, kErr_Text, &dummyType, &dummyHandle, &dummyRect); | |
414 SetDialogItemText (dummyHandle, "\pError Initializing SDL"); | |
415 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
416 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
417 SetPort (GetDialogPort(errorDialog)); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
418 #else |
0 | 419 SetPort (errorDialog); |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
420 #endif |
0 | 421 do { |
422 ModalDialog (nil, &itemHit); | |
423 } while (itemHit != kErr_OK); | |
424 | |
425 DisposeDialog (errorDialog); | |
426 exit (-1); | |
427 } | |
428 atexit(cleanup_output); | |
429 atexit(SDL_Quit); | |
430 #endif | |
431 | |
432 /* Set up SDL's QuickDraw environment */ | |
433 #if !TARGET_API_MAC_CARBON | |
434 SDL_InitQuickDraw(&qd); | |
435 #endif | |
436 | |
437 if ( readPreferences (&prefs) ) { | |
438 | |
439 if (memcmp (prefs.video_driver_name+1, "DSp", 3) == 0) | |
440 videodriver = 1; | |
441 else if (memcmp (prefs.video_driver_name+1, "toolbox", 7) == 0) | |
442 videodriver = 2; | |
443 } | |
444 | |
445 if ( CommandKeyIsDown() ) { | |
446 | |
447 #define kCL_OK 1 | |
448 #define kCL_Cancel 2 | |
449 #define kCL_Text 3 | |
450 #define kCL_File 4 | |
451 #define kCL_Video 6 | |
452 | |
453 DialogPtr commandDialog; | |
454 short dummyType; | |
455 Rect dummyRect; | |
456 Handle dummyHandle; | |
457 short itemHit; | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
458 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
459 ControlRef control; |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
460 #endif |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
461 |
0 | 462 /* Assume that they will change settings, rather than do exhaustive check */ |
463 settingsChanged = 1; | |
464 | |
465 /* Create dialog and display it */ | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
466 commandDialog = GetNewDialog (1000, nil, (WindowPtr)-1); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
467 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
468 SetPort ( GetDialogPort(commandDialog) ); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
469 #else |
0 | 470 SetPort (commandDialog); |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
471 #endif |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
472 |
0 | 473 /* Setup controls */ |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
474 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
475 GetDialogItemAsControl(commandDialog, kCL_File, &control); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
476 SetControlValue (control, prefs.output_to_file); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
477 #else |
0 | 478 GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ |
479 SetControlValue ((ControlHandle)dummyHandle, prefs.output_to_file ); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
480 #endif |
0 | 481 |
482 GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); | |
483 SetDialogItemText (dummyHandle, prefs.command_line); | |
484 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
485 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
486 GetDialogItemAsControl(commandDialog, kCL_Video, &control); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
487 SetControlValue (control, videodriver); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
488 #else |
0 | 489 GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect); |
490 SetControlValue ((ControlRef)dummyHandle, videodriver); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
491 #endif |
0 | 492 |
493 SetDialogDefaultItem (commandDialog, kCL_OK); | |
494 SetDialogCancelItem (commandDialog, kCL_Cancel); | |
495 | |
496 do { | |
497 | |
498 ModalDialog(nil, &itemHit); /* wait for user response */ | |
499 | |
500 /* Toggle command-line output checkbox */ | |
501 if ( itemHit == kCL_File ) { | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
502 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
503 GetDialogItemAsControl(commandDialog, kCL_File, &control); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
504 SetControlValue (control, !GetControlValue(control)); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
505 #else |
0 | 506 GetDialogItem(commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ |
507 SetControlValue((ControlHandle)dummyHandle, !GetControlValue((ControlHandle)dummyHandle) ); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
508 #endif |
0 | 509 } |
510 | |
511 } while (itemHit != kCL_OK && itemHit != kCL_Cancel); | |
512 | |
513 /* Get control values, even if they did not change */ | |
514 GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); /* MJS */ | |
515 GetDialogItemText (dummyHandle, prefs.command_line); | |
516 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
517 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
518 GetDialogItemAsControl(commandDialog, kCL_File, &control); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
519 prefs.output_to_file = GetControlValue(control); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
520 #else |
0 | 521 GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ |
522 prefs.output_to_file = GetControlValue ((ControlHandle)dummyHandle); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
523 #endif |
0 | 524 |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
525 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
526 GetDialogItemAsControl(commandDialog, kCL_Video, &control); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
527 videodriver = GetControlValue(control); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
528 #else |
0 | 529 GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect); |
530 videodriver = GetControlValue ((ControlRef)dummyHandle); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
531 #endif |
0 | 532 |
533 DisposeDialog (commandDialog); | |
534 | |
535 if (itemHit == kCL_Cancel ) { | |
536 exit (0); | |
537 } | |
538 } | |
539 | |
540 /* Set pseudo-environment variables for video driver, update prefs */ | |
541 switch ( videodriver ) { | |
542 case VIDEO_ID_DRAWSPROCKET: | |
543 putenv ("SDL_VIDEODRIVER=DSp"); | |
544 memcpy (prefs.video_driver_name, "\pDSp", 4); | |
545 break; | |
546 case VIDEO_ID_TOOLBOX: | |
547 putenv ("SDL_VIDEODRIVER=toolbox"); | |
548 memcpy (prefs.video_driver_name, "\ptoolbox", 8); | |
549 break; | |
550 } | |
551 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
552 #if !(defined(__APPLE__) && defined(__MACH__)) |
0 | 553 /* Redirect standard I/O to files */ |
554 if ( prefs.output_to_file ) { | |
555 freopen (STDOUT_FILE, "w", stdout); | |
556 freopen (STDERR_FILE, "w", stderr); | |
557 } else { | |
558 fclose (stdout); | |
559 fclose (stderr); | |
560 } | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
561 #endif |
0 | 562 |
563 if (settingsChanged) { | |
564 /* Save the prefs, even if they might not have changed (but probably did) */ | |
565 if ( ! writePreferences (&prefs) ) | |
566 fprintf (stderr, "WARNING: Could not save preferences!\n"); | |
567 } | |
568 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
569 #if !(defined(__APPLE__) && defined(__MACH__)) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
570 appNameText[0] = 0; |
0 | 571 getCurrentAppName (appNameText); /* check for error here ? */ |
572 | |
573 commandLine = (char*) malloc (appNameText[0] + prefs.command_line[0] + 2); | |
574 if ( commandLine == NULL ) { | |
575 exit(-1); | |
576 } | |
577 | |
578 /* Rather than rewrite ParseCommandLine method, let's replace */ | |
579 /* any spaces in application name with underscores, */ | |
580 /* so that the app name is only 1 argument */ | |
581 for (i = 1; i < 1+appNameText[0]; i++) | |
582 if ( appNameText[i] == ' ' ) appNameText[i] = '_'; | |
583 | |
584 /* Copy app name & full command text to command-line C-string */ | |
585 memcpy (commandLine, appNameText + 1, appNameText[0]); | |
586 commandLine[appNameText[0]] = ' '; | |
587 memcpy (commandLine + appNameText[0] + 1, prefs.command_line + 1, prefs.command_line[0]); | |
588 commandLine[ appNameText[0] + 1 + prefs.command_line[0] ] = '\0'; | |
589 | |
590 /* Parse C-string into argv and argc */ | |
591 nargs = ParseCommandLine (commandLine, NULL); | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
592 args = (char **)malloc((nargs+1)*(sizeof *args)); |
0 | 593 if ( args == NULL ) { |
594 exit(-1); | |
595 } | |
596 ParseCommandLine (commandLine, args); | |
597 | |
598 /* Run the main application code */ | |
599 SDL_main(nargs, args); | |
600 free (args); | |
601 free (commandLine); | |
602 | |
603 /* Remove useless stdout.txt and stderr.txt */ | |
604 cleanup_output (); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
605 #else // defined(__APPLE__) && defined(__MACH__) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
606 SDL_main(argc, argv); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
607 #endif |
0 | 608 |
609 /* Exit cleanly, calling atexit() functions */ | |
610 exit (0); | |
611 | |
612 /* Never reached, but keeps the compiler quiet */ | |
613 return (0); | |
614 } |