2011-07-03 22:34:20 +02:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-02-18 02:34:24 +01:00
|
|
|
*
|
2011-07-03 22:34:20 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-02-18 02:34:24 +01:00
|
|
|
*
|
2011-07-03 22:34:20 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-07-12 00:47:02 +02:00
|
|
|
// Disable symbol overrides so that we can use system headers.
|
|
|
|
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
|
|
|
|
2011-07-13 09:26:50 -04:00
|
|
|
#include "backends/platform/sdl/macosx/appmenu_osx.h"
|
2011-07-03 22:34:20 +02:00
|
|
|
#include "common/translation.h"
|
|
|
|
|
2017-09-10 21:03:18 -05:00
|
|
|
#include "backends/platform/sdl/macosx/macosx-compat.h"
|
2017-09-10 23:30:15 -05:00
|
|
|
#include <Cocoa/Cocoa.h>
|
2018-03-25 16:54:43 -05:00
|
|
|
#include <AppKit/NSWorkspace.h>
|
2017-09-10 17:26:25 -05:00
|
|
|
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
|
|
|
|
#define NSEventModifierFlagCommand NSCommandKeyMask
|
|
|
|
#define NSEventModifierFlagOption NSAlternateKeyMask
|
|
|
|
#endif
|
|
|
|
|
2018-08-19 21:12:29 +01:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_10
|
|
|
|
#define NSEventModifierFlags NSUInteger
|
|
|
|
#endif
|
|
|
|
|
2015-12-16 20:41:52 +00:00
|
|
|
// Apple added setAppleMenu in 10.5 and removed it in 10.6.
|
|
|
|
// But as the method still exists we declare it ourselves here.
|
2011-07-12 00:47:02 +02:00
|
|
|
// Yes, this works :)
|
|
|
|
@interface NSApplication(MissingFunction)
|
|
|
|
- (void)setAppleMenu:(NSMenu *)menu;
|
|
|
|
@end
|
2015-12-16 20:41:52 +00:00
|
|
|
// 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.
|
|
|
|
|
2018-03-25 16:54:43 -05:00
|
|
|
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;
|
2018-08-21 15:37:08 +02:00
|
|
|
- (void) openLicenseGPL;
|
|
|
|
- (void) openLicenseLGPL;
|
|
|
|
- (void) openLicenseFreefont;
|
|
|
|
- (void) openLicenseBSD;
|
2018-03-25 16:54:43 -05:00
|
|
|
- (void) openNews;
|
|
|
|
- (void) openUserManual;
|
|
|
|
- (void) openCredits;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation ScummVMMenuHandler : NSObject
|
|
|
|
- (void)openReadme {
|
|
|
|
openFromBundle(@"README");
|
|
|
|
}
|
|
|
|
|
2018-08-21 15:37:08 +02:00
|
|
|
- (void)openLicenseGPL {
|
|
|
|
openFromBundle(@"COPYING");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)openLicenseLGPL {
|
|
|
|
openFromBundle(@"COPYING-LGPL");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)openLicenseFreefont {
|
|
|
|
openFromBundle(@"COPYING-FREEFONT");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)openLicenseBSD {
|
|
|
|
openFromBundle(@"COPYING-BSD");
|
2018-03-25 16:54:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)openNews {
|
|
|
|
openFromBundle(@"NEWS");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)openUserManual {
|
2018-08-24 18:26:41 +01:00
|
|
|
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.scummvm.org/documentation"]];
|
2018-03-25 16:54:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)openCredits {
|
|
|
|
openFromBundle(@"AUTHORS");
|
|
|
|
}
|
|
|
|
@end
|
2011-07-12 00:47:02 +02:00
|
|
|
|
2012-10-15 14:30:18 +02:00
|
|
|
NSString *constructNSStringFromCString(const char *rawCString, CFStringEncoding stringEncoding) {
|
|
|
|
return (NSString *)CFStringCreateWithCString(NULL, rawCString, stringEncoding);
|
2012-01-14 10:44:11 -05:00
|
|
|
}
|
|
|
|
|
2018-03-25 16:54:43 -05:00
|
|
|
static NSMenu *addMenu(const char *title, CFStringEncoding encoding, NSString *key, SEL setAs) {
|
|
|
|
NSString *str = constructNSStringFromCString(title, encoding);
|
|
|
|
NSMenu *menu = [[NSMenu alloc] initWithTitle:str];
|
2011-07-03 22:34:20 +02:00
|
|
|
|
2018-03-25 16:54:43 -05:00
|
|
|
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];
|
|
|
|
}
|
2011-07-03 22:34:20 +02:00
|
|
|
|
2015-12-16 20:41:52 +00:00
|
|
|
// 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];
|
|
|
|
}
|
2011-07-03 22:34:20 +02:00
|
|
|
|
2012-01-14 10:44:11 -05:00
|
|
|
NSString *nsString = NULL;
|
|
|
|
|
2011-07-03 22:34:20 +02:00
|
|
|
// Get current encoding
|
2011-07-13 09:20:34 -04:00
|
|
|
#ifdef USE_TRANSLATION
|
2012-10-15 14:30:18 +02:00
|
|
|
nsString = constructNSStringFromCString(TransMan.getCurrentCharset().c_str(), NSASCIIStringEncoding);
|
|
|
|
CFStringEncoding stringEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)nsString);
|
2012-01-14 10:44:11 -05:00
|
|
|
[nsString release];
|
2011-07-13 09:20:34 -04:00
|
|
|
#else
|
2012-10-15 14:30:18 +02:00
|
|
|
CFStringEncoding stringEncoding = kCFStringEncodingASCII;
|
2011-07-13 09:20:34 -04:00
|
|
|
#endif
|
2012-01-14 10:44:11 -05:00
|
|
|
|
2018-03-25 16:54:43 -05:00
|
|
|
NSMenu *appleMenu = addMenu("ScummVM", kCFStringEncodingASCII, @"", @selector(setAppleMenu:));
|
|
|
|
addMenuItem(_("About ScummVM"), stringEncoding, nil, @selector(orderFrontStandardAboutPanel:), @"", appleMenu);
|
2011-07-03 22:34:20 +02:00
|
|
|
[appleMenu addItem:[NSMenuItem separatorItem]];
|
2018-03-25 16:54:43 -05:00
|
|
|
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);
|
2011-07-03 22:34:20 +02:00
|
|
|
[appleMenu addItem:[NSMenuItem separatorItem]];
|
2018-03-25 16:54:43 -05:00
|
|
|
addMenuItem(_("Quit ScummVM"), stringEncoding, nil, @selector(terminate:), @"q", appleMenu);
|
2011-07-03 22:34:20 +02:00
|
|
|
|
2018-03-25 16:54:43 -05:00
|
|
|
NSMenu *windowMenu = addMenu(_("Window"), stringEncoding, @"", @selector(setWindowsMenu:));
|
|
|
|
addMenuItem(_("Minimize"), stringEncoding, nil, @selector(performMiniaturize:), @"m", windowMenu);
|
2011-07-03 22:34:20 +02:00
|
|
|
|
2018-03-25 16:54:43 -05:00
|
|
|
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);
|
2018-08-21 15:37:08 +02:00
|
|
|
addMenuItem(_("GPL License"), stringEncoding, delegate, @selector(openLicenseGPL), @"", helpMenu);
|
|
|
|
addMenuItem(_("LGPL License"), stringEncoding, delegate, @selector(openLicenseLGPL), @"", helpMenu);
|
|
|
|
addMenuItem(_("Freefont License"), stringEncoding, delegate, @selector(openLicenseFreefont), @"", helpMenu);
|
|
|
|
addMenuItem(_("BSD License"), stringEncoding, delegate, @selector(openLicenseBSD), @"", helpMenu);
|
|
|
|
|
2011-07-03 22:34:20 +02:00
|
|
|
|
|
|
|
[appleMenu release];
|
|
|
|
[windowMenu release];
|
2018-03-25 16:54:43 -05:00
|
|
|
[helpMenu release];
|
2011-07-03 22:34:20 +02:00
|
|
|
}
|