Changeset 97 for abuse/trunk/osx
- Timestamp:
- Mar 9, 2008, 7:22:52 PM (15 years ago)
- Location:
- abuse/trunk/osx
- Files:
-
- 6 added
- 3 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/osx/SDLMain.m
r2 r97 7 7 8 8 #import "SDL.h" 9 #import <Cocoa/Cocoa.h> 10 11 @interface SDLMain : NSObject 12 @end 13 9 #import "SDLMain.h" 14 10 #import <sys/param.h> /* for MAXPATHLEN */ 15 11 #import <unistd.h> 16 12 17 13 /* Use this flag to determine whether we use SDLMain.nib or not */ 18 #define SDL_USE_NIB_FILE 114 #define SDL_USE_NIB_FILE 0 19 15 20 16 … … 27 23 @interface NSString (ReplaceSubString) 28 24 - (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; 29 30 @end 30 31 #endif … … 47 48 /* The main class of the application, the application's delegate */ 48 49 @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 56 51 /* Set the working directory to the .app's parent directory */ 57 52 - (void) setupWorkingDirectory:(BOOL)shouldChdir … … 101 96 } 102 97 [ aMenu sizeToFit ]; 98 } 99 100 #else 101 102 void 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 */ 128 void 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 */ 156 void 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]; 103 178 } 104 179 … … 197 272 [SDLApplication poseAsClass:[NSApplication class]]; 198 273 NSApplicationMain (argc, argv); 274 #else 275 CustomApplicationMain (argc, argv); 199 276 #endif 200 277 return 0;
Note: See TracChangeset
for help on using the changeset viewer.