ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

macosx.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 // Disable symbol overrides so that we can use system headers.
00024 #define FORBIDDEN_SYMBOL_ALLOW_ALL
00025 
00026 #include "common/scummsys.h"
00027 
00028 #ifdef MACOSX
00029 
00030 #include "backends/audiocd/macosx/macosx-audiocd.h"
00031 #include "backends/platform/sdl/macosx/appmenu_osx.h"
00032 #include "backends/platform/sdl/macosx/macosx.h"
00033 #include "backends/updates/macosx/macosx-updates.h"
00034 #include "backends/taskbar/macosx/macosx-taskbar.h"
00035 #include "backends/dialogs/macosx/macosx-dialogs.h"
00036 #include "backends/platform/sdl/macosx/macosx_wrapper.h"
00037 
00038 #include "common/archive.h"
00039 #include "common/config-manager.h"
00040 #include "common/fs.h"
00041 #include "common/translation.h"
00042 
00043 #include "ApplicationServices/ApplicationServices.h"    // for LSOpenFSRef
00044 #include "CoreFoundation/CoreFoundation.h"  // for CF* stuff
00045 
00046 OSystem_MacOSX::OSystem_MacOSX()
00047     :
00048     OSystem_POSIX("Library/Preferences/ResidualVM Preferences") {
00049 }
00050 
00051 OSystem_MacOSX::~OSystem_MacOSX() {
00052     releaseMenu();
00053 }
00054 
00055 void OSystem_MacOSX::init() {
00056     // Use an iconless window on OS X, as we use a nicer external icon there.
00057     _window = new SdlIconlessWindow();
00058 
00059 #if defined(USE_TASKBAR)
00060     // Initialize taskbar manager
00061     _taskbarManager = new MacOSXTaskbarManager();
00062 #endif
00063 
00064 #if defined(USE_SYSDIALOGS)
00065     // Initialize dialog manager
00066     _dialogManager = new MacOSXDialogManager();
00067 #endif
00068 
00069     // Invoke parent implementation of this method
00070     OSystem_POSIX::init();
00071 }
00072 
00073 void OSystem_MacOSX::initBackend() {
00074 #ifdef USE_TRANSLATION
00075     // We need to initialize the translataion manager here for the following
00076     // call to replaceApplicationMenuItems() work correctly
00077     TransMan.setLanguage(ConfMan.get("gui_language").c_str());
00078 #endif // USE_TRANSLATION
00079 
00080     // Replace the SDL generated menu items with our own translated ones on Mac OS X
00081     replaceApplicationMenuItems();
00082 
00083 #ifdef USE_SPARKLE
00084     // Initialize updates manager
00085     _updateManager = new MacOSXUpdateManager();
00086 #endif
00087 
00088     // Invoke parent implementation of this method
00089     OSystem_POSIX::initBackend();
00090 }
00091 
00092 void OSystem_MacOSX::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
00093     // Invoke parent implementation of this method
00094     OSystem_POSIX::addSysArchivesToSearchSet(s, priority);
00095 
00096     // Get URL of the Resource directory of the .app bundle
00097     CFURLRef fileUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
00098     if (fileUrl) {
00099         // Try to convert the URL to an absolute path
00100         UInt8 buf[MAXPATHLEN];
00101         if (CFURLGetFileSystemRepresentation(fileUrl, true, buf, sizeof(buf))) {
00102             // Success: Add it to the search path
00103             Common::String bundlePath((const char *)buf);
00104             // ResidualVM: Search with a depth of 2 so the shaders are found
00105             s.add("__OSX_BUNDLE__", new Common::FSDirectory(bundlePath, 2), priority);
00106         }
00107         CFRelease(fileUrl);
00108     }
00109 }
00110 
00111 bool OSystem_MacOSX::hasFeature(Feature f) {
00112     if (f == kFeatureDisplayLogFile || f == kFeatureClipboardSupport || f == kFeatureOpenUrl)
00113         return true;
00114 
00115 #ifdef USE_SYSDIALOGS
00116     if (f == kFeatureSystemBrowserDialog)
00117         return true;
00118 #endif
00119 
00120     return OSystem_POSIX::hasFeature(f);
00121 }
00122 
00123 bool OSystem_MacOSX::displayLogFile() {
00124     // Use LaunchServices to open the log file, if possible.
00125 
00126     if (_logFilePath.empty())
00127         return false;
00128 
00129     CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)_logFilePath.c_str(), _logFilePath.size(), false);
00130     OSStatus err = LSOpenCFURLRef(url, NULL);
00131     CFRelease(url);
00132 
00133     return err != noErr;
00134 }
00135 
00136 bool OSystem_MacOSX::hasTextInClipboard() {
00137     return hasTextInClipboardMacOSX();
00138 }
00139 
00140 Common::String OSystem_MacOSX::getTextFromClipboard() {
00141     return getTextFromClipboardMacOSX();
00142 }
00143 
00144 bool OSystem_MacOSX::setTextInClipboard(const Common::String &text) {
00145     return setTextInClipboardMacOSX(text);
00146 }
00147 
00148 bool OSystem_MacOSX::openUrl(const Common::String &url) {
00149     CFURLRef urlRef = CFURLCreateWithBytes (NULL, (UInt8*)url.c_str(), url.size(), kCFStringEncodingASCII, NULL);
00150     OSStatus err = LSOpenCFURLRef(urlRef, NULL);
00151     CFRelease(urlRef);
00152     return err == noErr;
00153 }
00154 
00155 Common::String OSystem_MacOSX::getSystemLanguage() const {
00156 #if defined(USE_DETECTLANG) && defined(USE_TRANSLATION)
00157     CFArrayRef availableLocalizations = CFBundleCopyBundleLocalizations(CFBundleGetMainBundle());
00158     if (availableLocalizations) {
00159         CFArrayRef preferredLocalizations = CFBundleCopyPreferredLocalizationsFromArray(availableLocalizations);
00160         CFRelease(availableLocalizations);
00161         if (preferredLocalizations) {
00162             CFIndex localizationsSize = CFArrayGetCount(preferredLocalizations);
00163             // Since we have a list of sorted preferred localization, I would like here to
00164             // check that they are supported by the TranslationManager and take the first
00165             // one that is supported. The listed localizations are taken from the Bundle
00166             // plist file, so they should all be supported, unless the plist file is not
00167             // synchronized with the translations.dat file. So this is not really a big
00168             // issue. And because getSystemLanguage() is called from the constructor of
00169             // TranslationManager (therefore before the instance pointer is set), calling
00170             // TransMan here results in an infinite loop and creation of a lot of TransMan
00171             // instances.
00172             /*
00173             for (CFIndex i = 0 ; i < localizationsSize ; ++i) {
00174                 CFStringRef language = (CFStringRef)CFArrayGetValueAtIndex(preferredLocalizations, i);
00175                 char buffer[10];
00176                 CFStringGetCString(language, buffer, sizeof(buffer), kCFStringEncodingASCII);
00177                 int32 languageId = TransMan.findMatchingLanguage(buffer);
00178                 if (languageId != -1) {
00179                     CFRelease(preferredLocalizations);
00180                     return TransMan.getLangById(languageId);
00181                 }
00182             }
00183             */
00184             if (localizationsSize > 0) {
00185                 CFStringRef language = (CFStringRef)CFArrayGetValueAtIndex(preferredLocalizations, 0);
00186                 char buffer[10];
00187                 CFStringGetCString(language, buffer, sizeof(buffer), kCFStringEncodingASCII);
00188                 CFRelease(preferredLocalizations);
00189                 return buffer;
00190             }
00191             CFRelease(preferredLocalizations);
00192         }
00193 
00194     }
00195     // Falback to POSIX implementation
00196     return OSystem_POSIX::getSystemLanguage();
00197 #else // USE_DETECTLANG
00198     return OSystem_POSIX::getSystemLanguage();
00199 #endif // USE_DETECTLANG
00200 }
00201 
00202 Common::String OSystem_MacOSX::getScreenshotsPath() {
00203     Common::String path = ConfMan.get("screenshotpath");
00204     if (path.empty())
00205         path = getDesktopPathMacOSX();
00206     if (!path.empty() && !path.hasSuffix("/"))
00207         path += "/";
00208     return path;
00209 }
00210 
00211 AudioCDManager *OSystem_MacOSX::createAudioCDManager() {
00212     return createMacOSXAudioCDManager();
00213 }
00214 
00215 #endif


Generated on Sat May 18 2019 05:01:08 for ResidualVM by doxygen 1.7.1
curved edge   curved edge