diff options
author | Thierry Crozat | 2015-12-16 20:41:52 +0000 |
---|---|---|
committer | Thierry Crozat | 2015-12-16 20:42:11 +0000 |
commit | ef62422e59d691c944838f9da3ac868821d4797c (patch) | |
tree | a29fbf9fca0e58c2e0a167743b3ad2cfabd01ec6 /backends | |
parent | 3fab9056296fbf491372f66f7fbb23d6312ad2ad (diff) | |
download | scummvm-rg350-ef62422e59d691c944838f9da3ac868821d4797c.tar.gz scummvm-rg350-ef62422e59d691c944838f9da3ac868821d4797c.tar.bz2 scummvm-rg350-ef62422e59d691c944838f9da3ac868821d4797c.zip |
OSX: Fix menus when using SDL2
We remove the menus added by SDL before inserting our own menus,
but the code assumed that there were two SDL generated menus. SDL2
actually adds three menus. So the new code makes no assumptions on
the number of menus so that it works with both SDL1.2 and SDL2.
Also fix an issue on OS X 10.4 and earlier that caused the app menu
to be nameless.
Diffstat (limited to 'backends')
-rw-r--r-- | backends/platform/sdl/macosx/appmenu_osx.mm | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/backends/platform/sdl/macosx/appmenu_osx.mm b/backends/platform/sdl/macosx/appmenu_osx.mm index d083fb8483..feea40bc06 100644 --- a/backends/platform/sdl/macosx/appmenu_osx.mm +++ b/backends/platform/sdl/macosx/appmenu_osx.mm @@ -28,12 +28,22 @@ #include <Cocoa/Cocoa.h> -// Apple removed setAppleMenu from the header files in 10.4, -// but as the method still exists we declare it ourselves here. +// Apple added setAppleMenu in 10.5 and removed it in 10.6. +// But as the method still exists we declare it ourselves here. // Yes, this works :) @interface NSApplication(MissingFunction) - (void)setAppleMenu:(NSMenu *)menu; @end +// However maybe we should conditionally use it depending on the system on which we run ScummVM (and not +// the one on which we compile) to only do it on OS X 10.5. +// Here is the relevant bit from the release notes for 10.6: +// In Leopard and earlier, apps that tried to construct a menu bar without a nib would get an undesirable +// stubby application menu that could not be removed. To work around this problem on Leopard, you can call +// the undocumented setAppleMenu: method and pass it the application menu, like so: +// [NSApp setAppleMenu:[[[NSApp mainMenu] itemAtIndex:0] submenu]]; +// In SnowLeopard, this workaround is unnecessary and should not be used. Under SnowLeopard, the first menu +// is always identified as the application menu. + NSString *constructNSStringFromCString(const char *rawCString, CFStringEncoding stringEncoding) { return (NSString *)CFStringCreateWithCString(NULL, rawCString, stringEncoding); @@ -46,13 +56,14 @@ void replaceApplicationMenuItems() { NSMenu *windowMenu; NSMenuItem *menuItem; - // For some reason [[NSApp mainMenu] removeAllItems] doesn't work and crashes, so we need - // to remove the SDL generated menus one by one - [[NSApp mainMenu] removeItemAtIndex:0]; // Remove application menu - [[NSApp mainMenu] removeItemAtIndex:0]; // Remove "Windows" menu + // We cannot use [[NSApp mainMenu] removeAllItems] as removeAllItems was added in OS X 10.6 + // So remove the SDL generated menus one by one instead. + while ([[NSApp mainMenu] numberOfItems] > 0) { + [[NSApp mainMenu] removeItemAtIndex:0]; + } // Create new application menu - appleMenu = [[NSMenu alloc] initWithTitle:@""]; + appleMenu = [[NSMenu alloc] initWithTitle:@"ScummVM"]; NSString *nsString = NULL; |