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