Ignore:
Timestamp:
Mar 9, 2008, 7:22:52 PM (12 years ago)
Author:
Sam Hocevar
Message:
  • Updated the Mac OS X port, thanks to Julian Mayer.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/osx/SDLMain.m

    r2 r97  
    77
    88#import "SDL.h"
    9 #import <Cocoa/Cocoa.h>
    10 
    11 @interface SDLMain : NSObject
    12 @end
    13 
     9#import "SDLMain.h"
    1410#import <sys/param.h> /* for MAXPATHLEN */
    1511#import <unistd.h>
    1612
    1713/* Use this flag to determine whether we use SDLMain.nib or not */
    18 #define         SDL_USE_NIB_FILE        1
     14#define         SDL_USE_NIB_FILE        0
    1915
    2016
     
    2723@interface NSString (ReplaceSubString)
    2824- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
     25@end
     26#else
     27/* An internal Apple class used to setup Apple menus */
     28@interface NSAppleMenuController:NSObject {}
     29- (void)controlMenu:(NSMenu *)aMenu;
    2930@end
    3031#endif
     
    4748/* The main class of the application, the application's delegate */
    4849@implementation SDLMain
    49 - (void)quit:(id)sender
    50 {
    51     /* Post a SDL_QUIT event */
    52     SDL_Event event;
    53     event.type = SDL_QUIT;
    54     SDL_PushEvent(&event);
    55 }
     50
    5651/* Set the working directory to the .app's parent directory */
    5752- (void) setupWorkingDirectory:(BOOL)shouldChdir
     
    10196    }
    10297    [ aMenu sizeToFit ];
     98}
     99
     100#else
     101
     102void setupAppleMenu(void)
     103{
     104    /* warning: this code is very odd */
     105    NSAppleMenuController *appleMenuController;
     106    NSMenu *appleMenu;
     107    NSMenuItem *appleMenuItem;
     108
     109    appleMenuController = [[NSAppleMenuController alloc] init];
     110    appleMenu = [[NSMenu alloc] initWithTitle:@""];
     111    appleMenuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
     112   
     113    [appleMenuItem setSubmenu:appleMenu];
     114
     115    /* yes, we do need to add it and then remove it --
     116       if you don't add it, it doesn't get displayed
     117       if you don't remove it, you have an extra, titleless item in the menubar
     118       when you remove it, it appears to stick around
     119       very, very odd */
     120    [[NSApp mainMenu] addItem:appleMenuItem];
     121    [appleMenuController controlMenu:appleMenu];
     122    [[NSApp mainMenu] removeItem:appleMenuItem];
     123    [appleMenu release];
     124    [appleMenuItem release];
     125}
     126
     127/* Create a window menu */
     128void setupWindowMenu(void)
     129{
     130    NSMenu              *windowMenu;
     131    NSMenuItem  *windowMenuItem;
     132    NSMenuItem  *menuItem;
     133
     134
     135    windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
     136   
     137    /* "Minimize" item */
     138    menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
     139    [windowMenu addItem:menuItem];
     140    [menuItem release];
     141   
     142    /* Put menu into the menubar */
     143    windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
     144    [windowMenuItem setSubmenu:windowMenu];
     145    [[NSApp mainMenu] addItem:windowMenuItem];
     146   
     147    /* Tell the application object that this is now the window menu */
     148    [NSApp setWindowsMenu:windowMenu];
     149
     150    /* Finally give up our references to the objects */
     151    [windowMenu release];
     152    [windowMenuItem release];
     153}
     154
     155/* Replacement for NSApplicationMain */
     156void CustomApplicationMain (argc, argv)
     157{
     158    NSAutoreleasePool   *pool = [[NSAutoreleasePool alloc] init];
     159    SDLMain                             *sdlMain;
     160
     161    /* Ensure the application object is initialised */
     162    [SDLApplication sharedApplication];
     163   
     164    /* Set up the menubar */
     165    [NSApp setMainMenu:[[NSMenu alloc] init]];
     166    setupAppleMenu();
     167    setupWindowMenu();
     168   
     169    /* Create SDLMain and make it the app delegate */
     170    sdlMain = [[SDLMain alloc] init];
     171    [NSApp setDelegate:sdlMain];
     172   
     173    /* Start the main event loop */
     174    [NSApp run];
     175   
     176    [sdlMain release];
     177    [pool release];
    103178}
    104179
     
    197272    [SDLApplication poseAsClass:[NSApplication class]];
    198273    NSApplicationMain (argc, argv);
     274#else
     275    CustomApplicationMain (argc, argv);
    199276#endif
    200277    return 0;
Note: See TracChangeset for help on using the changeset viewer.