[Scummvm-cvs-logs] scummvm master -> ef62422e59d691c944838f9da3ac868821d4797c

criezy criezy at scummvm.org
Wed Dec 16 21:44:39 CET 2015


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
ef62422e59 OSX: Fix menus when using SDL2


Commit: ef62422e59d691c944838f9da3ac868821d4797c
    https://github.com/scummvm/scummvm/commit/ef62422e59d691c944838f9da3ac868821d4797c
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2015-12-16T20:42:11Z

Commit Message:
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.

Changed paths:
    backends/platform/sdl/macosx/appmenu_osx.mm



diff --git a/backends/platform/sdl/macosx/appmenu_osx.mm b/backends/platform/sdl/macosx/appmenu_osx.mm
index d083fb8..feea40b 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;
 






More information about the Scummvm-git-logs mailing list