|
|
1.1 root 1: /* SDLMain.m - main entry point for our Cocoa-ized SDL app
2: Initial Version: Darrell Walisser <[email protected]>
3: Non-NIB-Code & other changes: Max Horn <[email protected]>
4:
5: Feel free to customize this file to suit your needs
6: */
7:
8: #include "SDL.h"
9: #include "SDLMain.h"
10: #include <sys/param.h> /* for MAXPATHLEN */
11: #include <unistd.h>
12:
13: // for Hatari
14:
15: #include "dialog.h"
16: #include "reset.h"
1.1.1.2 root 17: #include "screen.h"
18: #include "PrefsController.h"
19: #include "Shared.h"
1.1 root 20: #include "video.h"
1.1.1.2 root 21: #include "../debug/debugui.h"
1.1 root 22:
23: // for Hatari
24:
25:
26: /* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
27: but the method still is there and works. To avoid warnings, we declare
28: it ourselves here. */
29: @interface NSApplication(SDL_Missing_Methods)
30: - (void)setAppleMenu:(NSMenu *)menu;
31: @end
32:
33: /* Use this flag to determine whether we use SDLMain.nib or not */
34: #define SDL_USE_NIB_FILE 1
35:
36: /* Use this flag to determine whether we use CPS (docking) or not */
37: #define SDL_USE_CPS 1
38: #ifdef SDL_USE_CPS
39: /* Portions of CPS.h */
40: typedef struct CPSProcessSerNum
41: {
42: UInt32 lo;
43: UInt32 hi;
44: } CPSProcessSerNum;
45:
1.1.1.4 ! root 46: OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
! 47: OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
! 48: OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
1.1 root 49:
50: #endif /* SDL_USE_CPS */
51:
52: static int gArgc;
53: static char **gArgv;
54: static BOOL gFinderLaunch;
55: static BOOL gCalledAppMainline = FALSE;
56:
57: static NSString *getApplicationName(void)
58: {
59: const NSDictionary *dict;
60: NSString *appName = 0;
61:
62: /* Determine the application name */
63: dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
64: if (dict)
65: appName = [dict objectForKey: @"CFBundleName"];
66:
67: if (![appName length])
68: appName = [[NSProcessInfo processInfo] processName];
69:
70: return appName;
71: }
72:
73: #if SDL_USE_NIB_FILE
74: /* A helper category for NSString */
75: @interface NSString (ReplaceSubString)
76: - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
77: @end
78: #endif
79:
1.1.1.4 ! root 80: /* The main class of the application, the application's delegate */
! 81: @implementation SDLMain
1.1 root 82: /* Invoked from the Quit menu item */
1.1.1.4 ! root 83: - (void)applicationWillTerminate:(NSNotification *)aNotification {
1.1 root 84: /* Post a SDL_QUIT event */
85: SDL_Event event;
86: event.type = SDL_QUIT;
87: SDL_PushEvent(&event);
88: }
89:
90: /* Set the working directory to the .app's parent directory */
91: - (void) setupWorkingDirectory:(BOOL)shouldChdir
92: {
93: if (shouldChdir)
94: {
95: char parentdir[MAXPATHLEN];
96: CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
97: CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
98: if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) {
99: chdir(parentdir); /* chdir to the binary app's parent */
100: }
101: CFRelease(url);
102: CFRelease(url2);
103: }
104: }
105:
106: #if SDL_USE_NIB_FILE
107:
108: /* Fix menu to contain the real app name instead of "SDL App" */
109: - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
110: {
111: NSRange aRange;
112: NSEnumerator *enumerator;
113: NSMenuItem *menuItem;
114:
115: aRange = [[aMenu title] rangeOfString:@"SDL App"];
116: if (aRange.length != 0)
117: [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
118:
119: enumerator = [[aMenu itemArray] objectEnumerator];
120: while ((menuItem = [enumerator nextObject]))
121: {
122: aRange = [[menuItem title] rangeOfString:@"SDL App"];
123: if (aRange.length != 0)
124: [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
125: if ([menuItem hasSubmenu])
126: [self fixMenu:[menuItem submenu] withAppName:appName];
127: }
128: }
129:
130: #else
131:
132: static void setApplicationMenu(void)
133: {
134: /* warning: this code is very odd */
135: NSMenu *appleMenu;
136: NSMenuItem *menuItem;
137: NSString *title;
138: NSString *appName;
139:
140: appName = getApplicationName();
141: appleMenu = [[NSMenu alloc] initWithTitle:@""];
142:
143: /* Add menu items */
144: title = [@"About " stringByAppendingString:appName];
145: [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
146:
147: [appleMenu addItem:[NSMenuItem separatorItem]];
148:
149: title = [@"Hide " stringByAppendingString:appName];
150: [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
151:
152: menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
153: [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
154:
155: [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
156:
157: [appleMenu addItem:[NSMenuItem separatorItem]];
158:
159: title = [@"Quit " stringByAppendingString:appName];
160: [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
161:
162:
163: /* Put menu into the menubar */
164: menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
165: [menuItem setSubmenu:appleMenu];
166: [[NSApp mainMenu] addItem:menuItem];
167:
168: /* Tell the application object that this is now the application menu */
169: [NSApp setAppleMenu:appleMenu];
170:
171: /* Finally give up our references to the objects */
172: [appleMenu release];
173: [menuItem release];
174: }
175:
176: /* Create a window menu */
177: static void setupWindowMenu(void)
178: {
179: NSMenu *windowMenu;
180: NSMenuItem *windowMenuItem;
181: NSMenuItem *menuItem;
182:
183: windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
184:
185: /* "Minimize" item */
186: menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
187: [windowMenu addItem:menuItem];
188: [menuItem release];
189:
190: /* Put menu into the menubar */
191: windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
192: [windowMenuItem setSubmenu:windowMenu];
193: [[NSApp mainMenu] addItem:windowMenuItem];
194:
195: /* Tell the application object that this is now the window menu */
196: [NSApp setWindowsMenu:windowMenu];
197:
198: /* Finally give up our references to the objects */
199: [windowMenu release];
200: [windowMenuItem release];
201: }
202:
203: /* Replacement for NSApplicationMain */
204: static void CustomApplicationMain (int argc, char **argv)
205: {
206: NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
207: SDLMain *sdlMain;
208:
209: /* Ensure the application object is initialised */
210: [NSApplication sharedApplication];
211:
212: #ifdef SDL_USE_CPS
213: {
214: CPSProcessSerNum PSN;
215: /* Tell the dock about us */
216: if (!CPSGetCurrentProcess(&PSN))
217: if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
218: if (!CPSSetFrontProcess(&PSN))
219: [NSApplication sharedApplication];
220: }
221: #endif /* SDL_USE_CPS */
222:
223: /* Set up the menubar */
224: [NSApp setMainMenu:[[NSMenu alloc] init]];
225: setApplicationMenu();
226: setupWindowMenu();
227:
228: /* Create SDLMain and make it the app delegate */
229: sdlMain = [[SDLMain alloc] init];
230: [NSApp setDelegate:sdlMain];
231:
232: /* Start the main event loop */
233: [NSApp run];
234:
235: [sdlMain release];
236: [pool release];
237: }
238:
239: #endif
240:
241:
242: /*
243: * Catch document open requests...this lets us notice files when the app
244: * was launched by double-clicking a document, or when a document was
245: * dragged/dropped on the app's icon. You need to have a
246: * CFBundleDocumentsType section in your Info.plist to get this message,
247: * apparently.
248: *
249: * Files are added to gArgv, so to the app, they'll look like command line
250: * arguments. Previously, apps launched from the finder had nothing but
251: * an argv[0].
252: *
253: * This message may be received multiple times to open several docs on launch.
254: *
255: * This message is ignored once the app's mainline has been called.
256: */
257: - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
258: {
259: const char *temparg;
260: size_t arglen;
261: char *arg;
262: char **newargv;
263:
264: if (!gFinderLaunch) /* MacOS is passing command line args. */
265: return FALSE;
266:
267: if (gCalledAppMainline) /* app has started, ignore this document. */
268: return FALSE;
269:
270: temparg = [filename UTF8String];
271: arglen = SDL_strlen(temparg) + 1;
272: arg = (char *) SDL_malloc(arglen);
273: if (arg == NULL)
274: return FALSE;
275:
276: newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
277: if (newargv == NULL)
278: {
279: SDL_free(arg);
280: return FALSE;
281: }
282: gArgv = newargv;
283:
284: SDL_strlcpy(arg, temparg, arglen);
285: gArgv[gArgc++] = arg;
286: gArgv[gArgc] = NULL;
287: return TRUE;
288: }
289:
290:
291: /* Called when the internal event loop has just started running */
292: - (void) applicationDidFinishLaunching: (NSNotification *) note
293: {
1.1.1.4 ! root 294: int status = 0;
1.1 root 295:
296: /* Set the working directory to the .app's parent directory */
297: [self setupWorkingDirectory:gFinderLaunch];
298:
299: #if SDL_USE_NIB_FILE
300: /* Set the main menu to contain the real app name instead of "SDL App" */
301: [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
302: #endif
303:
304: /* Hand off to main application code */
305: gCalledAppMainline = TRUE;
1.1.1.3 root 306: //status = SDL_main (gArgc, gArgv);
1.1 root 307:
308: /* We're done, thank you for playing */
309: exit(status);
310: }
311:
312: // Hatari Stuff
313: - (IBAction)prefsMenu:(id)sender
314: {
315: static int in_propdialog = 0;
316:
317: if (in_propdialog)
318: return;
319: ++in_propdialog;
320: Dialog_DoProperty();
321: --in_propdialog;
322: }
323:
324: - (IBAction)debugUI:(id)sender
325: {
326: DebugUI();
327: }
328:
329: - (IBAction)warmReset:(id)sender
330: {
1.1.1.4 ! root 331: /*
1.1 root 332: int b;
333:
334: b = NSRunAlertPanel (
335: NSLocalizedStringFromTable(@"Warm reset",@"Localizable",@"comment"),
336: NSLocalizedStringFromTable(@"Really reset the emulator?",@"Localizable",@"comment"),
337: NSLocalizedStringFromTable(@"OK",@"Localizable",@"comment"),
338: NSLocalizedStringFromTable(@"Cancel",@"Localizable",@"comment"), nil);
339: //printf("b=%i\n",b);
340: if (b == 1)
341: Reset_Warm();
1.1.1.4 ! root 342: */
1.1 root 343: }
344:
345: - (IBAction)coldReset:(id)sender
346: {
1.1.1.4 ! root 347: /*
1.1 root 348: int b;
349:
350: b = NSRunAlertPanel (
351: NSLocalizedStringFromTable(@"Cold reset!",@"Localizable",@"comment"),
352: NSLocalizedStringFromTable(@"Really reset the emulator?",@"Localizable",@"comment") ,
353: NSLocalizedStringFromTable(@"OK",@"Localizable",@"comment"),
354: NSLocalizedStringFromTable(@"Cancel",@"Localizable",@"comment"), nil);
355: //printf("b=%i\n",b);
356: if (b == 1)
357: Reset_Cold();
1.1.1.4 ! root 358: */
1.1 root 359: }
360:
361: - (IBAction)insertDiskA:(id)sender
362: {
1.1.1.4 ! root 363: /*
1.1 root 364: NSString *path = nil;
365: NSOpenPanel *openPanel = [ NSOpenPanel openPanel ];
366:
367: if ( [ openPanel runModalForDirectory:nil
368: file:@"SavedGame" types:nil ] )
369: {
1.1.1.4 ! root 370: path = [[ [ openPanel URLs ] objectAtIndex:0 ] path];
1.1 root 371: }
372:
373: if (path != nil)
374: {
375: // Make a non-const C string out of it
376: const char* constSzPath = [path cStringUsingEncoding:NSASCIIStringEncoding];
377: size_t cbPath = strlen(constSzPath) + 1;
378: char szPath[cbPath];
379: strncpy(szPath, constSzPath, cbPath);
380:
381: // Floppy_SetDiskFileName(0, szPath, NULL);
382: // Floppy_InsertDiskIntoDrive(0);
383: }
1.1.1.4 ! root 384: */
1.1 root 385: }
386:
387: - (IBAction)insertDiskB:(id)sender
388: {
1.1.1.4 ! root 389: /*
1.1 root 390: NSString *path = nil;
391: NSOpenPanel *openPanel = [ NSOpenPanel openPanel ];
392:
393: if ( [ openPanel runModalForDirectory:nil
394: file:@"SavedGame" types:nil ] )
395: {
1.1.1.4 ! root 396: path = [[ [ openPanel URLs ] objectAtIndex:0 ] path];
1.1 root 397: }
398:
399: if (path != nil)
400: {
401: // Make a non-const C string out of it
402: const char* constSzPath = [path cStringUsingEncoding:NSASCIIStringEncoding];
403: size_t cbPath = strlen(constSzPath) + 1;
404: char szPath[cbPath];
405: strncpy(szPath, constSzPath, cbPath);
406:
407: // Floppy_SetDiskFileName(1, szPath, NULL);
408: // Floppy_InsertDiskIntoDrive(1);
409: }
1.1.1.4 ! root 410: */
1.1 root 411: }
412:
413: /*-----------------------------------------------------------------------*/
414: /*
415: Controls the enabled state of the menu items
416: */
417: - (BOOL)validateMenuItem:(NSMenuItem*)item
418: {
419: if (item == beginCaptureAnim)
420: {
421: // return !Avi_AreWeRecording();
422: }
423: if (item == endCaptureAnim)
424: {
425: // return Avi_AreWeRecording();
426: }
427: if (item == beginCaptureSound)
428: {
429: // return !Sound_AreWeRecording();
430: }
431: if (item == endCaptureSound)
432: {
433: // return Sound_AreWeRecording();
434: }
435:
436: return YES;
437: }
438:
1.1.1.2 root 439: - (NSString*)displayFileSelection:(const char*)pathInParams preferredFileName:(NSString*)preferredFileName allowedExtensions:(NSArray*)allowedExtensions
1.1 root 440: {
1.1.1.4 ! root 441: /*
1.1 root 442: // Get the path from the user settings
1.1.1.2 root 443: NSString *preferredPath = [[NSString stringWithCString:(pathInParams) encoding:NSASCIIStringEncoding] stringByAbbreviatingWithTildeInPath];
444:
1.1 root 445: // Determine the directory and filename
446: NSString *directoryToOpen;
447: NSString *fileToPreselect;
448: if ((preferredPath != nil) && ([preferredPath length] > 0))
449: {
450: // There is existing path: we will open its directory with its file pre-selected.
451: directoryToOpen = [preferredPath stringByDeletingLastPathComponent];
452: fileToPreselect = [preferredPath lastPathComponent];
453: }
454: else
455: {
456: // Currently no path: we will open the user's directory with no file selected.
457: directoryToOpen = [@"~" stringByExpandingTildeInPath];
1.1.1.2 root 458: fileToPreselect = preferredFileName;
1.1 root 459: }
1.1.1.2 root 460:
1.1 root 461: // Create and configure a SavePanel for choosing what file to write
462: NSSavePanel *savePanel = [NSSavePanel savePanel];
1.1.1.2 root 463: [savePanel setAllowedFileTypes:allowedExtensions];
1.1 root 464: [savePanel setExtensionHidden:NO];
1.1.1.2 root 465: NSString* extensionList = [allowedExtensions componentsJoinedByString:@" or a ."];
1.1 root 466:
1.1.1.2 root 467: [savePanel setMessage:[NSString stringWithFormat:@"Please specify a .%@ file",extensionList]]; // TODO: Move to localizable resources
1.1 root 468: // Run the SavePanel, then check if the user clicked OK and selected at least one file
469: if (NSFileHandlingPanelOKButton == [savePanel runModalForDirectory:directoryToOpen file:fileToPreselect] )
1.1.1.2 root 470: return [[savePanel URL] path];
1.1.1.4 ! root 471: */
1.1.1.2 root 472: return nil;
473: }
474:
475: - (IBAction)captureScreen:(id)sender
476: {
477: GuiOsx_Pause();
1.1.1.4 ! root 478: // ScreenSnapShot_SaveScreen();
1.1.1.2 root 479: GuiOsx_Resume();
480: }
481:
482: - (IBAction)captureAnimation:(id)sender
483: {
484: // GuiOsx_Pause();
485: // if(!Avi_AreWeRecording()) {
486: // NSString* path = [self displayFileSelection:ConfigureParams.Video.AviRecordFile preferredFileName:@"hatari.avi"
487: // allowedExtensions:[NSArray arrayWithObjects:@"avi", nil]];
1.1 root 488:
1.1.1.2 root 489: // if(path) {
490: // GuiOsx_ExportPathString(path, ConfigureParams.Video.AviRecordFile, sizeof(ConfigureParams.Video.AviRecordFile));
491: // Avi_StartRecording ( ConfigureParams.Video.AviRecordFile , ConfigureParams.Screen.bCrop ,
492: // ConfigureParams.Video.AviRecordFps == 0 ?
493: // ClocksTimings_GetVBLPerSec ( ConfigureParams.System.nMachineType , nScreenRefreshRate ) :
494: // (Uint32)ConfigureParams.Video.AviRecordFps << CLOCKS_TIMINGS_SHIFT_VBL ,
495: // 1 << CLOCKS_TIMINGS_SHIFT_VBL ,
496: // ConfigureParams.Video.AviRecordVcodec );
497: // }
1.1 root 498:
1.1.1.2 root 499: // } else {
500: // Avi_StopRecording();
501: // }
502: // GuiOsx_Resume();
503: }
504:
505: - (IBAction)endCaptureAnimation:(id)sender
506: {
507: //?
508: }
509:
510: - (IBAction)captureSound:(id)sender
511: {
512: GuiOsx_Pause();
1.1.1.3 root 513: // NSString* path = [self displayFileSelection:ConfigureParams.Sound.szYMCaptureFileName preferredFileName:@"hatari.wav"
514: // allowedExtensions:[NSArray arrayWithObjects:@"ym", @"wav", nil]];
515: // if(path) {
516: // GuiOsx_ExportPathString(path, ConfigureParams.Sound.szYMCaptureFileName, sizeof(ConfigureParams.Sound.szYMCaptureFileName));
1.1 root 517: // Sound_BeginRecording(ConfigureParams.Sound.szYMCaptureFileName);
1.1.1.3 root 518: // }
1.1 root 519: GuiOsx_Resume();
520: }
521:
522: - (IBAction)endCaptureSound:(id)sender
523: {
524: GuiOsx_Pause();
525: // Sound_EndRecording();
526: GuiOsx_Resume();
527: }
528:
529: - (IBAction)saveMemorySnap:(id)sender
530: {
1.1.1.4 ! root 531: /*
1.1 root 532: GuiOsx_Pause();
533:
1.1.1.4 ! root 534: NSString* path = [self displayFileSelection:ConfigureParams.Memory.szMemoryCaptureFileName preferredFileName:@"hatari.sav"
1.1.1.2 root 535: allowedExtensions:[NSArray arrayWithObjects:@"sav",nil]];
536: if(path) {
1.1 root 537: GuiOsx_ExportPathString(path, ConfigureParams.Memory.szMemoryCaptureFileName, sizeof(ConfigureParams.Memory.szMemoryCaptureFileName));
538: MemorySnapShot_Capture(ConfigureParams.Memory.szMemoryCaptureFileName, TRUE);
539: }
1.1.1.2 root 540:
1.1 root 541: GuiOsx_Resume();
1.1.1.4 ! root 542: */
1.1 root 543: }
544:
545: - (IBAction)restoreMemorySnap:(id)sender
546: {
1.1.1.4 ! root 547: /*
1.1 root 548: GuiOsx_Pause();
549:
550: // Create and configure an OpenPanel
551: NSOpenPanel *openPanel = [NSOpenPanel openPanel];
552:
553: // Get the path from the user settings
554: NSString *oldPath = [NSString stringWithCString:(ConfigureParams.Memory.szMemoryCaptureFileName) encoding:NSASCIIStringEncoding];
555:
556: // Determine the directory and filename
557: NSString *directoryToOpen;
558: NSString *fileToPreselect;
559: if ((oldPath != nil) && ([oldPath length] > 0))
560: {
561: // There is existing path: we will open its directory with its file pre-selected.
562: directoryToOpen = [oldPath stringByDeletingLastPathComponent];
563: fileToPreselect = [oldPath lastPathComponent];
564: }
565: else
566: {
567: // Currently no path: we will open the user's directory with no file selected.
568: directoryToOpen = [@"~" stringByExpandingTildeInPath];
569: fileToPreselect = nil;
570: }
571:
572: // Run the OpenPanel, then check if the user clicked OK and selected at least one file
1.1.1.4 ! root 573: if ( (NSModalResponseOK == [openPanel runModalForDirectory:directoryToOpen file:fileToPreselect types:nil] )
! 574: && ([[openPanel URLs] count] > 0) )
1.1 root 575: {
576: // Get the path to the selected file
1.1.1.4 ! root 577: NSString *path = [[[openPanel URLs] objectAtIndex:0] path];
1.1 root 578:
579: // Perform the memory snapshot load
580: MemorySnapShot_Restore([path cStringUsingEncoding:NSASCIIStringEncoding], TRUE);
581: }
582:
583: GuiOsx_Resume();
1.1.1.4 ! root 584: */
1.1 root 585: }
586:
587: - (IBAction)doFullScreen:(id)sender
588: {
589: // A call to Screen_EnterFullScreen() would be required, but this causes a crash when using SDL runtime 1.2.11, probably due to conflicts between Cocoa and SDL.
590: // Therefore we simulate the fullscreen key press instead
591:
592: SDL_KeyboardEvent event;
593: event.type = SDL_KEYDOWN;
1.1.1.3 root 594: //event.which = 0;
1.1 root 595: event.state = SDL_PRESSED;
596: event.keysym.sym = SDLK_F11;
597: SDL_PushEvent((SDL_Event*)&event); // Send the F11 key press
598: event.type = SDL_KEYUP;
599: event.state = SDL_RELEASED;
600: SDL_PushEvent((SDL_Event*)&event); // Send the F11 key release
601: }
602:
603: - (IBAction)help:(id)sender
604: {
605: [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://hatari.berlios.de/docs.html"]];
606: }
607:
608:
609: - (IBAction)openConfig:(id)sender {
610: }
611:
612: - (IBAction)saveConfig:(id)sender {
613: }
614:
615: @end
616:
617:
618: @implementation NSString (ReplaceSubString)
619:
620: - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
621: {
622: unsigned int bufferSize;
623: unsigned int selfLen = [self length];
624: unsigned int aStringLen = [aString length];
625: unichar *buffer;
626: NSRange localRange;
627: NSString *result;
628:
629: bufferSize = selfLen + aStringLen - aRange.length;
630: buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar));
631:
632: /* Get first part into buffer */
633: localRange.location = 0;
634: localRange.length = aRange.location;
635: [self getCharacters:buffer range:localRange];
636:
637: /* Get middle part into buffer */
638: localRange.location = 0;
639: localRange.length = aStringLen;
640: [aString getCharacters:(buffer+aRange.location) range:localRange];
641:
642: /* Get last part into buffer */
643: localRange.location = aRange.location + aRange.length;
644: localRange.length = selfLen - localRange.location;
645: [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
646:
647: /* Build output string */
648: result = [NSString stringWithCharacters:buffer length:bufferSize];
649:
650: NSDeallocateMemoryPages(buffer, bufferSize);
651:
652: return result;
653: }
654:
655: @end
656:
657:
658:
659: #ifdef main
660: # undef main
661: #endif
662:
1.1.1.3 root 663: #if 0
1.1 root 664: /* Main entry point to executable - should *not* be SDL_main! */
665: int main (int argc, char **argv)
666: {
667: /* Copy the arguments into a global variable */
668: /* This is passed if we are launched by double-clicking */
669: if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
670: gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
671: gArgv[0] = argv[0];
672: gArgv[1] = NULL;
673: gArgc = 1;
674: gFinderLaunch = YES;
675: } else {
676: int i;
677: gArgc = argc;
678: gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
679: for (i = 0; i <= argc; i++)
680: gArgv[i] = argv[i];
681: gFinderLaunch = NO;
682: }
683:
684: #if SDL_USE_NIB_FILE
1.1.1.2 root 685: NSApplicationMain (argc, (const char**)argv);
1.1 root 686: #else
687: CustomApplicationMain (argc, argv);
688: #endif
689: return 0;
690: }
1.1.1.3 root 691: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.