diff options
-rw-r--r-- | backends/platform/sdl/macosx/appmenu_osx.h | 1 | ||||
-rw-r--r-- | backends/platform/sdl/macosx/appmenu_osx.mm | 169 | ||||
-rw-r--r-- | backends/platform/sdl/macosx/macosx.cpp | 4 | ||||
-rw-r--r-- | backends/platform/sdl/macosx/macosx.h | 1 | ||||
-rw-r--r-- | devtools/create_project/xcode.cpp | 7 | ||||
-rw-r--r-- | ports.mk | 5 |
6 files changed, 119 insertions, 68 deletions
diff --git a/backends/platform/sdl/macosx/appmenu_osx.h b/backends/platform/sdl/macosx/appmenu_osx.h index 22088184fb..15dd76dd96 100644 --- a/backends/platform/sdl/macosx/appmenu_osx.h +++ b/backends/platform/sdl/macosx/appmenu_osx.h @@ -26,6 +26,7 @@ #if defined(MACOSX) void replaceApplicationMenuItems(); +void releaseMenu(); #endif // MACOSX diff --git a/backends/platform/sdl/macosx/appmenu_osx.mm b/backends/platform/sdl/macosx/appmenu_osx.mm index 64b8e2b6d7..c839c20af0 100644 --- a/backends/platform/sdl/macosx/appmenu_osx.mm +++ b/backends/platform/sdl/macosx/appmenu_osx.mm @@ -28,6 +28,7 @@ #include "backends/platform/sdl/macosx/macosx-compat.h" #include <Cocoa/Cocoa.h> +#include <AppKit/NSWorkspace.h> #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12 #define NSEventModifierFlagCommand NSCommandKeyMask @@ -50,17 +51,97 @@ // In SnowLeopard, this workaround is unnecessary and should not be used. Under SnowLeopard, the first menu // is always identified as the application menu. +static void openFromBundle(NSString *file) { + NSString *path = [[NSBundle mainBundle] pathForResource:file ofType:@"rtf"]; + if (!path) { + path = [[NSBundle mainBundle] pathForResource:file ofType:@""]; + } + + if (path) { + [[NSWorkspace sharedWorkspace] openFile:path]; + } +} + +@interface ScummVMMenuHandler : NSObject { +} +- (void) openReadme; +- (void) openLicense; +- (void) openNews; +- (void) openUserManual; +- (void) openCredits; +@end + +@implementation ScummVMMenuHandler : NSObject +- (void)openReadme { + openFromBundle(@"README"); +} + +- (void)openLicense { + openFromBundle(@"COPYING"); +} + +- (void)openNews { + openFromBundle(@"NEWS"); +} + +- (void)openUserManual { + [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.scummvm.org/manual"]]; +} + +- (void)openCredits { + openFromBundle(@"AUTHORS"); +} +@end NSString *constructNSStringFromCString(const char *rawCString, CFStringEncoding stringEncoding) { return (NSString *)CFStringCreateWithCString(NULL, rawCString, stringEncoding); } -void replaceApplicationMenuItems() { +static NSMenu *addMenu(const char *title, CFStringEncoding encoding, NSString *key, SEL setAs) { + NSString *str = constructNSStringFromCString(title, encoding); + NSMenu *menu = [[NSMenu alloc] initWithTitle:str]; - // Code mainly copied and adapted from SDLmain.m - NSMenu *appleMenu; - NSMenu *windowMenu; - NSMenuItem *menuItem; + NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:str action:nil keyEquivalent:key]; + [menuItem setSubmenu:menu]; + [[NSApp mainMenu] addItem:menuItem]; + + if (setAs) { + [NSApp performSelector:setAs withObject:menu]; + } + + [str release]; + [menuItem release]; + + return menu; +} + +static void addMenuItem(const char *title, CFStringEncoding encoding, id target, SEL selector, NSString *key, NSMenu *parent, NSEventModifierFlags flags = 0) { + NSString *nsString = constructNSStringFromCString(title, encoding); + NSMenuItem *menuItem = [[NSMenuItem alloc] + initWithTitle:nsString + action:selector + keyEquivalent:key]; + if (target) { + [menuItem setTarget:target]; + } + if (flags) { + [menuItem setKeyEquivalentModifierMask:flags]; + } + [parent addItem:menuItem]; + [nsString release]; +} + +static ScummVMMenuHandler *delegate = nullptr; + +void releaseMenu() { + [delegate release]; + delegate = nullptr; +} + +void replaceApplicationMenuItems() { + if (!delegate) { + delegate = [[ScummVMMenuHandler alloc] init]; + } // 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. @@ -68,9 +149,6 @@ void replaceApplicationMenuItems() { [[NSApp mainMenu] removeItemAtIndex:0]; } - // Create new application menu - appleMenu = [[NSMenu alloc] initWithTitle:@"ScummVM"]; - NSString *nsString = NULL; // Get current encoding @@ -82,69 +160,28 @@ void replaceApplicationMenuItems() { CFStringEncoding stringEncoding = kCFStringEncodingASCII; #endif - // Add "About ScummVM" menu item - nsString = constructNSStringFromCString(_("About ScummVM"), stringEncoding); - [appleMenu addItemWithTitle:nsString action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; - [nsString release]; - - // Add separator + NSMenu *appleMenu = addMenu("ScummVM", kCFStringEncodingASCII, @"", @selector(setAppleMenu:)); + addMenuItem(_("About ScummVM"), stringEncoding, nil, @selector(orderFrontStandardAboutPanel:), @"", appleMenu); [appleMenu addItem:[NSMenuItem separatorItem]]; - - // Add "Hide ScummVM" menu item - nsString = constructNSStringFromCString(_("Hide ScummVM"), stringEncoding); - [appleMenu addItemWithTitle:nsString action:@selector(hide:) keyEquivalent:@"h"]; - [nsString release]; - - // Add "Hide Others" menu item - nsString = constructNSStringFromCString(_("Hide Others"), stringEncoding); - menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:nsString action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; - [menuItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption|NSEventModifierFlagCommand)]; - - // Add "Show All" menu item - nsString = constructNSStringFromCString(_("Show All"), stringEncoding); - [appleMenu addItemWithTitle:nsString action:@selector(unhideAllApplications:) keyEquivalent:@""]; - [nsString release]; - - // Add separator + addMenuItem(_("Hide ScummVM"), stringEncoding, nil, @selector(hide:), @"h", appleMenu); + addMenuItem(_("Hide Others"), stringEncoding, nil, @selector(hideOtherApplications:), @"h", appleMenu, (NSEventModifierFlagOption|NSEventModifierFlagCommand)); + addMenuItem(_("Show All"), stringEncoding, nil, @selector(unhideAllApplications:), @"", appleMenu); [appleMenu addItem:[NSMenuItem separatorItem]]; + addMenuItem(_("Quit ScummVM"), stringEncoding, nil, @selector(terminate:), @"q", appleMenu); - // Add "Quit ScummVM" menu item - nsString = constructNSStringFromCString(_("Quit ScummVM"), stringEncoding); - [appleMenu addItemWithTitle:nsString action:@selector(terminate:) keyEquivalent:@"q"]; - [nsString release]; - - // Put application menu into the menubar - menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; - [menuItem setSubmenu:appleMenu]; - [[NSApp mainMenu] addItem:menuItem]; - - // Tell the application object that this is now the application menu - [NSApp setAppleMenu:appleMenu]; - - - // Create new "Window" menu - nsString = constructNSStringFromCString(_("Window"), stringEncoding); - windowMenu = [[NSMenu alloc] initWithTitle:nsString]; - [nsString release]; + NSMenu *windowMenu = addMenu(_("Window"), stringEncoding, @"", @selector(setWindowsMenu:)); + addMenuItem(_("Minimize"), stringEncoding, nil, @selector(performMiniaturize:), @"m", windowMenu); - // Add "Minimize" menu item - nsString = constructNSStringFromCString(_("Minimize"), stringEncoding); - menuItem = [[NSMenuItem alloc] initWithTitle:nsString action:@selector(performMiniaturize:) keyEquivalent:@"m"]; - [windowMenu addItem:menuItem]; - [nsString release]; + NSMenu *helpMenu = addMenu(_("Help"), stringEncoding, @"", @selector(setHelpMenu:)); + addMenuItem(_("User Manual"), stringEncoding, delegate, @selector(openUserManual), @"", helpMenu); + [helpMenu addItem:[NSMenuItem separatorItem]]; + addMenuItem(_("General Information"), stringEncoding, delegate, @selector(openReadme), @"", helpMenu); + addMenuItem(_("What's New in ScummVM"), stringEncoding, delegate, @selector(openNews), @"", helpMenu); + [helpMenu addItem:[NSMenuItem separatorItem]]; + addMenuItem(_("Credits"), stringEncoding, delegate, @selector(openCredits), @"", helpMenu); + addMenuItem(_("Licensing Information"), stringEncoding, delegate, @selector(openLicense), @"", helpMenu); - // Put menu into the menubar - nsString = constructNSStringFromCString(_("Window"), stringEncoding); - menuItem = [[NSMenuItem alloc] initWithTitle:nsString action:nil keyEquivalent:@""]; - [menuItem setSubmenu:windowMenu]; - [[NSApp mainMenu] addItem:menuItem]; - [nsString release]; - - // Tell the application object that this is now the window menu. - [NSApp setWindowsMenu:windowMenu]; - - // Finally give up our references to the objects [appleMenu release]; [windowMenu release]; - [menuItem release]; + [helpMenu release]; } diff --git a/backends/platform/sdl/macosx/macosx.cpp b/backends/platform/sdl/macosx/macosx.cpp index 62037200ea..d83a8bc115 100644 --- a/backends/platform/sdl/macosx/macosx.cpp +++ b/backends/platform/sdl/macosx/macosx.cpp @@ -47,6 +47,10 @@ OSystem_MacOSX::OSystem_MacOSX() OSystem_POSIX("Library/Preferences/ScummVM Preferences") { } +OSystem_MacOSX::~OSystem_MacOSX() { + releaseMenu(); +} + void OSystem_MacOSX::init() { // Use an iconless window on OS X, as we use a nicer external icon there. _window = new SdlIconlessWindow(); diff --git a/backends/platform/sdl/macosx/macosx.h b/backends/platform/sdl/macosx/macosx.h index 5ef30baa64..6f960dbdad 100644 --- a/backends/platform/sdl/macosx/macosx.h +++ b/backends/platform/sdl/macosx/macosx.h @@ -28,6 +28,7 @@ class OSystem_MacOSX : public OSystem_POSIX { public: OSystem_MacOSX(); + ~OSystem_MacOSX(); virtual bool hasFeature(Feature f); diff --git a/devtools/create_project/xcode.cpp b/devtools/create_project/xcode.cpp index fb459da55d..e6ba6a8ba1 100644 --- a/devtools/create_project/xcode.cpp +++ b/devtools/create_project/xcode.cpp @@ -767,6 +767,13 @@ XcodeProvider::ValueList& XcodeProvider::getResourceFiles() const { files.push_back("dists/engine-data/xeen.ccs"); files.push_back("dists/pred.dic"); files.push_back("icons/scummvm.icns"); + files.push_back("AUTHORS"); + files.push_back("COPYING"); + files.push_back("COPYING.LGPL"); + files.push_back("COPYING.BSD"); + files.push_back("COPYING.FREEFONT"); + files.push_back("NEWS"); + files.push_back("README"); } return files; } @@ -111,7 +111,7 @@ ifdef USE_SPARKLE cp -R $(SPARKLEPATH)/Sparkle.framework $(bundle_name)/Contents/Frameworks/ endif cp $(srcdir)/icons/scummvm.icns $(bundle_name)/Contents/Resources/ - cp $(DIST_FILES_DOCS) $(bundle_name)/ + cp $(DIST_FILES_DOCS) $(bundle_name)/Contents/Resources/ cp $(DIST_FILES_THEMES) $(bundle_name)/Contents/Resources/ ifdef DIST_FILES_NETWORKING cp $(DIST_FILES_NETWORKING) $(bundle_name)/Contents/Resources/ @@ -119,7 +119,8 @@ endif ifdef DIST_FILES_ENGINEDATA cp $(DIST_FILES_ENGINEDATA) $(bundle_name)/Contents/Resources/ endif - $(srcdir)/devtools/credits.pl --rtf > $(bundle_name)/Contents/Resources/Credits.rtf + $(srcdir)/devtools/credits.pl --rtf > $(bundle_name)/Contents/Resources/AUTHORS.rtf + rm $(bundle_name)/Contents/Resources/AUTHORS chmod 644 $(bundle_name)/Contents/Resources/* cp scummvm-static $(bundle_name)/Contents/MacOS/scummvm chmod 755 $(bundle_name)/Contents/MacOS/scummvm |