/[adonthell]/adonthell/src/main/sdl/osx.m
ViewVC logotype

Diff of /adonthell/src/main/sdl/osx.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by ksterker, Mon Aug 23 06:33:47 2004 UTC revision 1.4 by ksterker, Mon Oct 18 07:40:23 2004 UTC
# Line 54  extern "C" { Line 54  extern "C" {
54      Application = theApp;      Application = theApp;
55  }  }
56    
57  void setupAppleMenu(void)  static NSString *getApplicationName(void)
58    {
59        NSDictionary *dict;
60        NSString *appName = 0;
61    
62        /* Determine the application name */
63        dict = (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    static void setApplicationMenu(void)
74  {  {
75      /* warning: this code is very odd */      /* warning: this code is very odd */
     NSAppleMenuController *appleMenuController;  
76      NSMenu *appleMenu;      NSMenu *appleMenu;
77      NSMenuItem *appleMenuItem;      NSMenuItem *menuItem;
78        NSString *title;
79      appleMenuController = [[NSAppleMenuController alloc] init];      NSString *appName;
80        
81        appName = getApplicationName();
82      appleMenu = [[NSMenu alloc] initWithTitle:@""];      appleMenu = [[NSMenu alloc] initWithTitle:@""];
     appleMenuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];  
83            
84      [appleMenuItem setSubmenu:appleMenu];      /* Add menu items */
85        title = [@"About " stringByAppendingString:appName];
86        [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
87    
88        [appleMenu addItem:[NSMenuItem separatorItem]];
89    
90        title = [@"Hide " stringByAppendingString:appName];
91        [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
92    
93        menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
94        [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
95    
96        [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
97    
98        [appleMenu addItem:[NSMenuItem separatorItem]];
99    
100        title = [@"Quit " stringByAppendingString:appName];
101        [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
102    
103        
104        /* Put menu into the menubar */
105        menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
106        [menuItem setSubmenu:appleMenu];
107        [[NSApp mainMenu] addItem:menuItem];
108    
109      /* yes, we do need to add it and then remove it --      /* Tell the application object that this is now the application menu */
110         if you don't add it, it doesn't get displayed      [NSApp setAppleMenu:appleMenu];
111         if you don't remove it, you have an extra, titleless item in the menubar  
112         when you remove it, it appears to stick around      /* Finally give up our references to the objects */
        very, very odd */  
     [[NSApp mainMenu] addItem:appleMenuItem];  
     [appleMenuController controlMenu:appleMenu];  
     [[NSApp mainMenu] removeItem:appleMenuItem];  
113      [appleMenu release];      [appleMenu release];
114      [appleMenuItem release];      [menuItem release];
115  }  }
116    
117  /* Create a window menu */  /* Create a window menu */
118  void setupWindowMenu(void)  static void setupWindowMenu(void)
119  {  {
120      NSMenu              *windowMenu;      NSMenu      *windowMenu;
121      NSMenuItem  *windowMenuItem;      NSMenuItem  *windowMenuItem;
122      NSMenuItem  *menuItem;      NSMenuItem  *menuItem;
123    
124      windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];      windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
125            
# Line 126  void CustomApplicationMain (const adonth Line 161  void CustomApplicationMain (const adonth
161    
162      /* Set up the menubar */      /* Set up the menubar */
163      [NSApp setMainMenu:[[NSMenu alloc] init]];      [NSApp setMainMenu:[[NSMenu alloc] init]];
164      setupAppleMenu();      setApplicationMenu();
165      setupWindowMenu();      setupWindowMenu();
166            
167      /* Create SDLMain and make it the app delegate */      /* Create SDLMain and make it the app delegate */
# Line 147  void CustomApplicationMain (const adonth Line 182  void CustomApplicationMain (const adonth
182      Application->cleanup ();      Application->cleanup ();
183      exit (status);      exit (status);
184  }  }
   
 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication  
 {  
     printf ("applicationShouldTerminateAfterLastWindowClosed\n");  
     fflush (stdout);  
     return YES;  
 }  
   
 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender  
 {  
     printf ("NSApplicationTerminateReply\n");  
     fflush (stdout);  
     return NSTerminateNow;  
 }  
   
 - (void)applicationWillTerminate:(NSNotification *)aNotification  
 {  
     printf ("applicationWillTerminate\n");  
     fflush (stdout);  
     Application->cleanup ();  
 }  
185  @end  @end
186    
187  extern "C" {  extern "C" {

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26