2010-06-24 19:05:59 +00: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
|
|
|
*
|
2010-06-24 19:05:59 +00: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
|
|
|
*
|
2010-06-24 19:05:59 +00: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-28 14:56:31 +00:00
|
|
|
// Disable symbol overrides so that we can use system headers.
|
|
|
|
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
|
|
|
|
2010-11-29 16:18:43 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
|
|
|
|
#ifdef MACOSX
|
|
|
|
|
2012-12-30 13:38:56 -05:00
|
|
|
#include "backends/audiocd/macosx/macosx-audiocd.h"
|
2011-07-13 09:43:16 -04:00
|
|
|
#include "backends/platform/sdl/macosx/appmenu_osx.h"
|
2012-12-30 13:38:56 -05:00
|
|
|
#include "backends/platform/sdl/macosx/macosx.h"
|
2011-07-03 23:01:17 +02:00
|
|
|
#include "backends/updates/macosx/macosx-updates.h"
|
2014-01-26 20:40:36 +00:00
|
|
|
#include "backends/taskbar/macosx/macosx-taskbar.h"
|
2019-07-28 14:56:38 +01:00
|
|
|
#include "backends/text-to-speech/macosx/macosx-text-to-speech.h"
|
2018-11-20 02:13:23 +00:00
|
|
|
#include "backends/dialogs/macosx/macosx-dialogs.h"
|
2016-07-28 00:20:33 +01:00
|
|
|
#include "backends/platform/sdl/macosx/macosx_wrapper.h"
|
2019-08-04 21:45:17 +01:00
|
|
|
#include "backends/fs/posix/posix-fs.h"
|
2010-06-24 19:05:59 +00:00
|
|
|
|
2010-06-24 23:41:27 +00:00
|
|
|
#include "common/archive.h"
|
2011-07-03 22:34:20 +02:00
|
|
|
#include "common/config-manager.h"
|
2010-06-24 23:51:02 +00:00
|
|
|
#include "common/fs.h"
|
2011-07-03 22:34:20 +02:00
|
|
|
#include "common/translation.h"
|
2010-06-24 23:41:27 +00:00
|
|
|
|
2011-06-03 18:30:01 +02:00
|
|
|
#include "ApplicationServices/ApplicationServices.h" // for LSOpenFSRef
|
|
|
|
#include "CoreFoundation/CoreFoundation.h" // for CF* stuff
|
2010-06-24 19:05:59 +00:00
|
|
|
|
2021-03-29 20:19:49 +02:00
|
|
|
// For querying number of MIDI devices
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <CoreMIDI/CoreMIDI.h>
|
|
|
|
|
|
|
|
void *coreMIDIthread(void *threadarg) {
|
|
|
|
(void)MIDIGetNumberOfDestinations();
|
|
|
|
|
|
|
|
pthread_exit(NULL);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-03-25 16:54:43 -05:00
|
|
|
OSystem_MacOSX::~OSystem_MacOSX() {
|
|
|
|
releaseMenu();
|
|
|
|
}
|
|
|
|
|
2014-01-26 20:40:36 +00:00
|
|
|
void OSystem_MacOSX::init() {
|
2015-02-16 01:24:42 +01:00
|
|
|
// Use an iconless window on OS X, as we use a nicer external icon there.
|
2020-10-10 18:11:29 +01:00
|
|
|
initSDL();
|
2015-02-16 01:24:42 +01:00
|
|
|
_window = new SdlIconlessWindow();
|
|
|
|
|
2014-01-26 20:40:36 +00:00
|
|
|
#if defined(USE_TASKBAR)
|
|
|
|
// Initialize taskbar manager
|
|
|
|
_taskbarManager = new MacOSXTaskbarManager();
|
|
|
|
#endif
|
2016-10-09 15:02:02 +02:00
|
|
|
|
2018-11-20 02:13:23 +00:00
|
|
|
#if defined(USE_SYSDIALOGS)
|
|
|
|
// Initialize dialog manager
|
|
|
|
_dialogManager = new MacOSXDialogManager();
|
|
|
|
#endif
|
|
|
|
|
2021-03-29 20:19:49 +02:00
|
|
|
// The call to query the number of MIDI devices is ubiquitously slow
|
|
|
|
// on the first run. This is apparent when opening Options in GUI,
|
|
|
|
// which takes 2-3 secs.
|
|
|
|
//
|
|
|
|
// Thus, we are launching it now, in a separate thread, so
|
|
|
|
// the subsequent calls are instantaneous
|
|
|
|
pthread_t thread;
|
|
|
|
pthread_create(&thread, NULL, coreMIDIthread, NULL);
|
|
|
|
|
2014-01-26 20:40:36 +00:00
|
|
|
// Invoke parent implementation of this method
|
|
|
|
OSystem_POSIX::init();
|
|
|
|
}
|
|
|
|
|
2010-06-24 19:05:59 +00:00
|
|
|
void OSystem_MacOSX::initBackend() {
|
2011-07-03 22:34:20 +02:00
|
|
|
#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
|
|
|
|
|
2011-07-13 09:47:03 -04:00
|
|
|
// Replace the SDL generated menu items with our own translated ones on Mac OS X
|
2011-07-03 22:34:20 +02:00
|
|
|
replaceApplicationMenuItems();
|
|
|
|
|
2011-08-02 21:00:57 -04:00
|
|
|
#ifdef USE_SPARKLE
|
2011-07-03 23:01:17 +02:00
|
|
|
// Initialize updates manager
|
|
|
|
_updateManager = new MacOSXUpdateManager();
|
|
|
|
#endif
|
|
|
|
|
2019-08-15 15:30:30 +02:00
|
|
|
#ifdef USE_TTS
|
2019-07-28 14:56:38 +01:00
|
|
|
// Initialize Text to Speech manager
|
|
|
|
_textToSpeechManager = new MacOSXTextToSpeechManager();
|
|
|
|
#endif
|
|
|
|
|
2010-06-24 19:05:59 +00:00
|
|
|
// Invoke parent implementation of this method
|
|
|
|
OSystem_POSIX::initBackend();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSystem_MacOSX::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
|
|
|
|
// Invoke parent implementation of this method
|
|
|
|
OSystem_POSIX::addSysArchivesToSearchSet(s, priority);
|
|
|
|
|
|
|
|
// Get URL of the Resource directory of the .app bundle
|
|
|
|
CFURLRef fileUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
|
|
|
|
if (fileUrl) {
|
|
|
|
// Try to convert the URL to an absolute path
|
|
|
|
UInt8 buf[MAXPATHLEN];
|
|
|
|
if (CFURLGetFileSystemRepresentation(fileUrl, true, buf, sizeof(buf))) {
|
|
|
|
// Success: Add it to the search path
|
|
|
|
Common::String bundlePath((const char *)buf);
|
2020-10-09 19:04:07 +02:00
|
|
|
// Search with a depth of 2 so the shaders are found
|
2018-07-18 19:54:38 +02:00
|
|
|
s.add("__OSX_BUNDLE__", new Common::FSDirectory(bundlePath, 2), priority);
|
2010-06-24 19:05:59 +00:00
|
|
|
}
|
|
|
|
CFRelease(fileUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-03 12:08:37 +02:00
|
|
|
bool OSystem_MacOSX::hasFeature(Feature f) {
|
2016-09-09 23:51:40 +01:00
|
|
|
if (f == kFeatureDisplayLogFile || f == kFeatureClipboardSupport || f == kFeatureOpenUrl)
|
2011-06-03 12:08:37 +02:00
|
|
|
return true;
|
2018-12-16 15:03:27 +00:00
|
|
|
|
|
|
|
#ifdef USE_SYSDIALOGS
|
2018-12-17 23:04:22 +00:00
|
|
|
if (f == kFeatureSystemBrowserDialog)
|
2018-12-16 15:03:27 +00:00
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
2011-06-03 12:08:37 +02:00
|
|
|
return OSystem_POSIX::hasFeature(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OSystem_MacOSX::displayLogFile() {
|
|
|
|
// Use LaunchServices to open the log file, if possible.
|
|
|
|
|
|
|
|
if (_logFilePath.empty())
|
|
|
|
return false;
|
|
|
|
|
2021-04-15 21:20:04 +02:00
|
|
|
CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)_logFilePath.c_str(), _logFilePath.size(), false);
|
|
|
|
OSStatus err = LSOpenCFURLRef(url, NULL);
|
|
|
|
CFRelease(url);
|
2011-06-03 12:08:37 +02:00
|
|
|
|
2011-06-03 18:25:40 +02:00
|
|
|
return err != noErr;
|
2011-06-03 12:08:37 +02:00
|
|
|
}
|
|
|
|
|
2016-07-28 00:20:33 +01:00
|
|
|
bool OSystem_MacOSX::hasTextInClipboard() {
|
|
|
|
return hasTextInClipboardMacOSX();
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:25:43 +05:30
|
|
|
Common::U32String OSystem_MacOSX::getTextFromClipboard() {
|
2016-07-28 00:20:33 +01:00
|
|
|
return getTextFromClipboardMacOSX();
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:25:43 +05:30
|
|
|
bool OSystem_MacOSX::setTextInClipboard(const Common::U32String &text) {
|
2018-04-10 23:41:10 +01:00
|
|
|
return setTextInClipboardMacOSX(text);
|
|
|
|
}
|
|
|
|
|
2016-09-09 23:51:40 +01:00
|
|
|
bool OSystem_MacOSX::openUrl(const Common::String &url) {
|
2020-04-17 02:42:39 +02:00
|
|
|
CFURLRef urlRef = CFURLCreateWithBytes (NULL, (const UInt8*)url.c_str(), url.size(), kCFStringEncodingASCII, NULL);
|
2016-09-09 23:51:40 +01:00
|
|
|
OSStatus err = LSOpenCFURLRef(urlRef, NULL);
|
|
|
|
CFRelease(urlRef);
|
2017-05-21 19:26:01 -05:00
|
|
|
return err == noErr;
|
2016-09-09 23:51:40 +01:00
|
|
|
}
|
|
|
|
|
2011-10-03 23:53:22 +01:00
|
|
|
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];
|
2014-06-01 17:01:57 -04:00
|
|
|
CFStringGetCString(language, buffer, sizeof(buffer), kCFStringEncodingASCII);
|
2011-10-03 23:53:22 +01:00
|
|
|
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];
|
2014-06-01 17:01:57 -04:00
|
|
|
CFStringGetCString(language, buffer, sizeof(buffer), kCFStringEncodingASCII);
|
2011-10-03 23:53:22 +01:00
|
|
|
CFRelease(preferredLocalizations);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
CFRelease(preferredLocalizations);
|
|
|
|
}
|
2012-09-26 04:17:31 +02:00
|
|
|
|
2011-10-03 23:53:22 +01:00
|
|
|
}
|
|
|
|
// Falback to POSIX implementation
|
|
|
|
return OSystem_POSIX::getSystemLanguage();
|
|
|
|
#else // USE_DETECTLANG
|
|
|
|
return OSystem_POSIX::getSystemLanguage();
|
|
|
|
#endif // USE_DETECTLANG
|
|
|
|
}
|
|
|
|
|
2019-12-07 14:08:33 +00:00
|
|
|
Common::String OSystem_MacOSX::getDefaultConfigFileName() {
|
|
|
|
const Common::String baseConfigName = "Library/Preferences/ScummVM Preferences";
|
|
|
|
|
|
|
|
Common::String configFile;
|
|
|
|
|
|
|
|
Common::String prefix = getenv("HOME");
|
|
|
|
|
|
|
|
if (!prefix.empty() && (prefix.size() + 1 + baseConfigName.size()) < MAXPATHLEN) {
|
|
|
|
configFile = prefix;
|
|
|
|
configFile += '/';
|
|
|
|
configFile += baseConfigName;
|
|
|
|
} else {
|
|
|
|
configFile = baseConfigName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return configFile;
|
|
|
|
}
|
|
|
|
|
2019-08-04 21:45:17 +01:00
|
|
|
Common::String OSystem_MacOSX::getDefaultLogFileName() {
|
|
|
|
const char *prefix = getenv("HOME");
|
|
|
|
if (prefix == nullptr) {
|
|
|
|
return Common::String();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Posix::assureDirectoryExists("Library/Logs", prefix)) {
|
|
|
|
return Common::String();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Common::String(prefix) + "/Library/Logs/scummvm.log";
|
|
|
|
}
|
|
|
|
|
2017-04-24 00:30:28 +01:00
|
|
|
Common::String OSystem_MacOSX::getScreenshotsPath() {
|
2017-04-24 00:51:57 +01:00
|
|
|
Common::String path = ConfMan.get("screenshotpath");
|
|
|
|
if (path.empty())
|
|
|
|
path = getDesktopPathMacOSX();
|
2017-04-24 00:30:28 +01:00
|
|
|
if (!path.empty() && !path.hasSuffix("/"))
|
|
|
|
path += "/";
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2012-12-30 13:38:56 -05:00
|
|
|
AudioCDManager *OSystem_MacOSX::createAudioCDManager() {
|
|
|
|
return createMacOSXAudioCDManager();
|
|
|
|
}
|
|
|
|
|
2010-06-24 19:05:59 +00:00
|
|
|
#endif
|