aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/sdl/macosx
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2013-04-18 23:34:29 +0200
committerWillem Jan Palenstijn2013-05-08 20:39:44 +0200
commit01f3f3a8dd0ad2891939d03b0ce47cbf36ea9bc6 (patch)
tree544b07f3aa41abe7907bcd2040cdad11ebc324bb /backends/platform/sdl/macosx
parent9cf2c83e5e5a35816ab153bf8443dac691829ea8 (diff)
parenta41d72a44a660c72fdadbc3a8ef580e5e03cb890 (diff)
downloadscummvm-rg350-01f3f3a8dd0ad2891939d03b0ce47cbf36ea9bc6.tar.gz
scummvm-rg350-01f3f3a8dd0ad2891939d03b0ce47cbf36ea9bc6.tar.bz2
scummvm-rg350-01f3f3a8dd0ad2891939d03b0ce47cbf36ea9bc6.zip
Merge branch 'master'
Diffstat (limited to 'backends/platform/sdl/macosx')
-rwxr-xr-xbackends/platform/sdl/macosx/appmenu_osx.h32
-rwxr-xr-xbackends/platform/sdl/macosx/appmenu_osx.mm110
-rw-r--r--backends/platform/sdl/macosx/macosx.cpp65
-rw-r--r--backends/platform/sdl/macosx/macosx.h2
4 files changed, 209 insertions, 0 deletions
diff --git a/backends/platform/sdl/macosx/appmenu_osx.h b/backends/platform/sdl/macosx/appmenu_osx.h
new file mode 100755
index 0000000000..005414b789
--- /dev/null
+++ b/backends/platform/sdl/macosx/appmenu_osx.h
@@ -0,0 +1,32 @@
+/* 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.
+
+ * 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.
+
+ * 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.
+ *
+ */
+
+#ifndef APPMENU_OSX_H
+#define APPMENU_OSX_H
+
+#if defined(MACOSX)
+
+void replaceApplicationMenuItems();
+
+#endif // MACOSX
+
+#endif
diff --git a/backends/platform/sdl/macosx/appmenu_osx.mm b/backends/platform/sdl/macosx/appmenu_osx.mm
new file mode 100755
index 0000000000..bb089a6b61
--- /dev/null
+++ b/backends/platform/sdl/macosx/appmenu_osx.mm
@@ -0,0 +1,110 @@
+/* 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.
+
+ * 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.
+
+ * 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.
+ *
+ */
+
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
+#include "backends/platform/sdl/macosx/appmenu_osx.h"
+#include "common/translation.h"
+
+#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.
+// Yes, this works :)
+@interface NSApplication(MissingFunction)
+- (void)setAppleMenu:(NSMenu *)menu;
+@end
+
+void replaceApplicationMenuItems() {
+
+ // Code mainly copied and adapted from SDLmain.m
+ NSMenu *appleMenu;
+ 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
+
+ // Create new application menu
+ appleMenu = [[NSMenu alloc] initWithTitle:@""];
+
+ // Get current encoding
+#ifdef USE_TRANSLATION
+ NSStringEncoding stringEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)[NSString stringWithCString:(TransMan.getCurrentCharset()).c_str() encoding:NSASCIIStringEncoding]));
+#else
+ NSStringEncoding stringEncoding = NSASCIIStringEncoding;
+#endif
+
+ // Add "About ScummVM" menu item
+ [appleMenu addItemWithTitle:[NSString stringWithCString:_("About ScummVM") encoding:stringEncoding] action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
+
+ // Add separator
+ [appleMenu addItem:[NSMenuItem separatorItem]];
+
+ // Add "Hide ScummVM" menu item
+ [appleMenu addItemWithTitle:[NSString stringWithCString:_("Hide ScummVM") encoding:stringEncoding] action:@selector(hide:) keyEquivalent:@"h"];
+
+ // Add "Hide Others" menu item
+ menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:[NSString stringWithCString:_("Hide Others") encoding:stringEncoding] action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
+ [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
+
+ // Add "Show All" menu item
+ [appleMenu addItemWithTitle:[NSString stringWithCString:_("Show All") encoding:stringEncoding] action:@selector(unhideAllApplications:) keyEquivalent:@""];
+
+ // Add separator
+ [appleMenu addItem:[NSMenuItem separatorItem]];
+
+ // Add "Quit ScummVM" menu item
+ [appleMenu addItemWithTitle:[NSString stringWithCString:_("Quit ScummVM") encoding:stringEncoding] action:@selector(terminate:) keyEquivalent:@"q"];
+
+ // 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
+ windowMenu = [[NSMenu alloc] initWithTitle:[NSString stringWithCString:_("Window") encoding:stringEncoding]];
+
+ // Add "Minimize" menu item
+ menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithCString:_("Minimize") encoding:stringEncoding] action:@selector(performMiniaturize:) keyEquivalent:@"m"];
+ [windowMenu addItem:menuItem];
+
+ // Put menu into the menubar
+ menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithCString:_("Window") encoding:stringEncoding] action:nil keyEquivalent:@""];
+ [menuItem setSubmenu:windowMenu];
+ [[NSApp mainMenu] addItem:menuItem];
+
+ // 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];
+}
diff --git a/backends/platform/sdl/macosx/macosx.cpp b/backends/platform/sdl/macosx/macosx.cpp
index 817f61e864..639bd980f6 100644
--- a/backends/platform/sdl/macosx/macosx.cpp
+++ b/backends/platform/sdl/macosx/macosx.cpp
@@ -29,9 +29,13 @@
#include "backends/platform/sdl/macosx/macosx.h"
#include "backends/mixer/doublebuffersdl/doublebuffersdl-mixer.h"
+#include "backends/platform/sdl/macosx/appmenu_osx.h"
+#include "backends/updates/macosx/macosx-updates.h"
#include "common/archive.h"
+#include "common/config-manager.h"
#include "common/fs.h"
+#include "common/translation.h"
#include "ApplicationServices/ApplicationServices.h" // for LSOpenFSRef
#include "CoreFoundation/CoreFoundation.h" // for CF* stuff
@@ -51,6 +55,20 @@ void OSystem_MacOSX::initBackend() {
_mixerManager->init();
}
+#ifdef USE_TRANSLATION
+ // We need to initialize the translataion manager here for the following
+ // call to replaceApplicationMenuItems() work correctly
+ TransMan.setLanguage(ConfMan.get("gui_language").c_str());
+#endif // USE_TRANSLATION
+
+ // Replace the SDL generated menu items with our own translated ones on Mac OS X
+ replaceApplicationMenuItems();
+
+#ifdef USE_SPARKLE
+ // Initialize updates manager
+ _updateManager = new MacOSXUpdateManager();
+#endif
+
// Invoke parent implementation of this method
OSystem_POSIX::initBackend();
}
@@ -100,4 +118,51 @@ bool OSystem_MacOSX::displayLogFile() {
return err != noErr;
}
+Common::String OSystem_MacOSX::getSystemLanguage() const {
+#if defined(USE_DETECTLANG) && defined(USE_TRANSLATION)
+ CFArrayRef availableLocalizations = CFBundleCopyBundleLocalizations(CFBundleGetMainBundle());
+ if (availableLocalizations) {
+ CFArrayRef preferredLocalizations = CFBundleCopyPreferredLocalizationsFromArray(availableLocalizations);
+ CFRelease(availableLocalizations);
+ if (preferredLocalizations) {
+ CFIndex localizationsSize = CFArrayGetCount(preferredLocalizations);
+ // Since we have a list of sorted preferred localization, I would like here to
+ // check that they are supported by the TranslationManager and take the first
+ // one that is supported. The listed localizations are taken from the Bundle
+ // plist file, so they should all be supported, unless the plist file is not
+ // synchronized with the translations.dat file. So this is not really a big
+ // issue. And because getSystemLanguage() is called from the constructor of
+ // TranslationManager (therefore before the instance pointer is set), calling
+ // TransMan here results in an infinite loop and creation of a lot of TransMan
+ // instances.
+ /*
+ for (CFIndex i = 0 ; i < localizationsSize ; ++i) {
+ CFStringRef language = (CFStringRef)CFArrayGetValueAtIndex(preferredLocalizations, i);
+ char buffer[10];
+ CFStringGetCString(language, buffer, 50, kCFStringEncodingASCII);
+ int32 languageId = TransMan.findMatchingLanguage(buffer);
+ if (languageId != -1) {
+ CFRelease(preferredLocalizations);
+ return TransMan.getLangById(languageId);
+ }
+ }
+ */
+ if (localizationsSize > 0) {
+ CFStringRef language = (CFStringRef)CFArrayGetValueAtIndex(preferredLocalizations, 0);
+ char buffer[10];
+ CFStringGetCString(language, buffer, 50, kCFStringEncodingASCII);
+ CFRelease(preferredLocalizations);
+ return buffer;
+ }
+ CFRelease(preferredLocalizations);
+ }
+
+ }
+ // Falback to POSIX implementation
+ return OSystem_POSIX::getSystemLanguage();
+#else // USE_DETECTLANG
+ return OSystem_POSIX::getSystemLanguage();
+#endif // USE_DETECTLANG
+}
+
#endif
diff --git a/backends/platform/sdl/macosx/macosx.h b/backends/platform/sdl/macosx/macosx.h
index 86c70297ec..4837e643b3 100644
--- a/backends/platform/sdl/macosx/macosx.h
+++ b/backends/platform/sdl/macosx/macosx.h
@@ -32,6 +32,8 @@ public:
virtual bool hasFeature(Feature f);
virtual bool displayLogFile();
+
+ virtual Common::String getSystemLanguage() const;
virtual void initBackend();
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0);