diff options
author | Matthew Hoops | 2011-07-20 09:27:39 -0400 |
---|---|---|
committer | Matthew Hoops | 2011-07-20 09:27:39 -0400 |
commit | ad293b249e74dd1cfbdbd721d02145efbdaf9eca (patch) | |
tree | e568d96f6d7f64c5e58b4c7cd1c4fda7e649bfc7 /backends/platform/sdl | |
parent | d7411acc2b1c7702280dbff1c3e1bafee528184b (diff) | |
parent | e25e85fbb047fef895ede97c3c2c73451631052c (diff) | |
download | scummvm-rg350-ad293b249e74dd1cfbdbd721d02145efbdaf9eca.tar.gz scummvm-rg350-ad293b249e74dd1cfbdbd721d02145efbdaf9eca.tar.bz2 scummvm-rg350-ad293b249e74dd1cfbdbd721d02145efbdaf9eca.zip |
Merge remote branch 'upstream/master' into pegasus
Diffstat (limited to 'backends/platform/sdl')
-rwxr-xr-x | backends/platform/sdl/macosx/appmenu_osx.h | 32 | ||||
-rwxr-xr-x | backends/platform/sdl/macosx/appmenu_osx.mm | 110 | ||||
-rw-r--r-- | backends/platform/sdl/macosx/macosx.cpp | 14 | ||||
-rw-r--r-- | backends/platform/sdl/main.cpp | 1 | ||||
-rw-r--r-- | backends/platform/sdl/module.mk | 9 | ||||
-rw-r--r-- | backends/platform/sdl/posix/posix-main.cpp | 2 | ||||
-rw-r--r-- | backends/platform/sdl/posix/posix.cpp | 11 | ||||
-rw-r--r-- | backends/platform/sdl/ps3/ps3-main.cpp | 49 | ||||
-rw-r--r-- | backends/platform/sdl/ps3/ps3.cpp | 94 | ||||
-rw-r--r-- | backends/platform/sdl/ps3/ps3.h | 47 | ||||
-rw-r--r-- | backends/platform/sdl/sdl-sys.h | 25 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.cpp | 96 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.h | 8 | ||||
-rw-r--r-- | backends/platform/sdl/win32/win32.cpp | 118 | ||||
-rw-r--r-- | backends/platform/sdl/win32/win32.h | 2 |
15 files changed, 540 insertions, 78 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 9b11eb2c09..ddfc99570a 100644 --- a/backends/platform/sdl/macosx/macosx.cpp +++ b/backends/platform/sdl/macosx/macosx.cpp @@ -29,9 +29,12 @@ #include "backends/platform/sdl/macosx/macosx.h" #include "backends/mixer/doublebuffersdl/doublebuffersdl-mixer.h" +#include "backends/platform/sdl/macosx/appmenu_osx.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 +54,15 @@ 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(); + // Invoke parent implementation of this method OSystem_POSIX::initBackend(); } @@ -74,7 +86,7 @@ void OSystem_MacOSX::addSysArchivesToSearchSet(Common::SearchSet &s, int priorit } void OSystem_MacOSX::setupIcon() { - // Don't set icon on OS X, as we use a nicer external icon there. + // Don't set icon on OS X, as we use a nicer external icon there. } bool OSystem_MacOSX::hasFeature(Feature f) { diff --git a/backends/platform/sdl/main.cpp b/backends/platform/sdl/main.cpp index 1992bdd3f2..3947d010c4 100644 --- a/backends/platform/sdl/main.cpp +++ b/backends/platform/sdl/main.cpp @@ -34,6 +34,7 @@ !defined(CAANOO) && \ !defined(LINUXMOTO) && \ !defined(SAMSUNGTV) && \ + !defined(PLAYSTATION3) && \ !defined(OPENPANDORA) #include "backends/platform/sdl/sdl.h" diff --git a/backends/platform/sdl/module.mk b/backends/platform/sdl/module.mk index efc5168d5b..f1afe37349 100644 --- a/backends/platform/sdl/module.mk +++ b/backends/platform/sdl/module.mk @@ -14,7 +14,8 @@ endif ifdef MACOSX MODULE_OBJS += \ macosx/macosx-main.o \ - macosx/macosx.o + macosx/macosx.o \ + macosx/appmenu_osx.o endif ifdef WIN32 @@ -29,6 +30,12 @@ MODULE_OBJS += \ amigaos/amigaos.o endif +ifdef PLAYSTATION3 +MODULE_OBJS += \ + ps3/ps3-main.o \ + ps3/ps3.o +endif + # We don't use rules.mk but rather manually update OBJS and MODULE_DIRS. MODULE_OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS)) OBJS := $(MODULE_OBJS) $(OBJS) diff --git a/backends/platform/sdl/posix/posix-main.cpp b/backends/platform/sdl/posix/posix-main.cpp index f78e001398..3bf7a5138a 100644 --- a/backends/platform/sdl/posix/posix-main.cpp +++ b/backends/platform/sdl/posix/posix-main.cpp @@ -22,7 +22,7 @@ #include "common/scummsys.h" -#if defined(POSIX) && !defined(MACOSX) && !defined(SAMSUNGTV) && !defined(WEBOS) && !defined(LINUXMOTO) && !defined(GPH_DEVICE) && !defined(GP2X) && !defined(DINGUX) && !defined(OPENPANDORA) +#if defined(POSIX) && !defined(MACOSX) && !defined(SAMSUNGTV) && !defined(WEBOS) && !defined(LINUXMOTO) && !defined(GPH_DEVICE) && !defined(GP2X) && !defined(DINGUX) && !defined(OPENPANDORA) && !defined(PLAYSTATION3) #include "backends/platform/sdl/posix/posix.h" #include "backends/plugins/sdl/sdl-provider.h" diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp index d757186134..05c779a4e0 100644 --- a/backends/platform/sdl/posix/posix.cpp +++ b/backends/platform/sdl/posix/posix.cpp @@ -33,6 +33,7 @@ #include "backends/platform/sdl/posix/posix.h" #include "backends/saves/posix/posix-saves.h" #include "backends/fs/posix/posix-fs-factory.h" +#include "backends/taskbar/unity/unity-taskbar.h" #include <errno.h> #include <sys/stat.h> @@ -49,6 +50,11 @@ void OSystem_POSIX::init() { // Initialze File System Factory _fsFactory = new POSIXFilesystemFactory(); +#if defined(USE_TASKBAR) && defined(USE_TASKBAR_UNITY) + // Initialize taskbar manager + _taskbarManager = new UnityTaskbarManager(); +#endif + // Invoke parent implementation of this method OSystem_SDL::init(); } @@ -60,6 +66,11 @@ void OSystem_POSIX::initBackend() { // Invoke parent implementation of this method OSystem_SDL::initBackend(); + +#if defined(USE_TASKBAR) && defined(USE_TASKBAR_UNITY) + // Register the taskbar manager as an event source (this is necessary for the glib event loop to be run) + _eventManager->getEventDispatcher()->registerSource((UnityTaskbarManager *)_taskbarManager, false); +#endif } bool OSystem_POSIX::hasFeature(Feature f) { diff --git a/backends/platform/sdl/ps3/ps3-main.cpp b/backends/platform/sdl/ps3/ps3-main.cpp new file mode 100644 index 0000000000..ba548a3749 --- /dev/null +++ b/backends/platform/sdl/ps3/ps3-main.cpp @@ -0,0 +1,49 @@ +/* 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. + * + */ + +#include "common/scummsys.h" + +#include "backends/platform/sdl/ps3/ps3.h" +#include "backends/plugins/sdl/sdl-provider.h" +#include "base/main.h" + +int main(int argc, char *argv[]) { + + // Create our OSystem instance + g_system = new OSystem_PS3(); + assert(g_system); + + // Pre initialize the backend + ((OSystem_PS3 *)g_system)->init(); + +#ifdef DYNAMIC_MODULES + PluginManager::instance().addPluginProvider(new SDLPluginProvider()); +#endif + + // Invoke the actual ScummVM main entry point: + int res = scummvm_main(argc, argv); + + // Free OSystem + delete (OSystem_PS3 *)g_system; + + return res; +} diff --git a/backends/platform/sdl/ps3/ps3.cpp b/backends/platform/sdl/ps3/ps3.cpp new file mode 100644 index 0000000000..33586ce693 --- /dev/null +++ b/backends/platform/sdl/ps3/ps3.cpp @@ -0,0 +1,94 @@ +/* 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. + * + */ + +#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir +#define FORBIDDEN_SYMBOL_EXCEPTION_time_h // sys/stat.h includes sys/time.h +#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h + +#include "common/scummsys.h" +#include "common/config-manager.h" +#include "backends/platform/sdl/ps3/ps3.h" +#include "backends/graphics/surfacesdl/surfacesdl-graphics.h" +#include "backends/saves/default/default-saves.h" +#include "backends/fs/ps3/ps3-fs-factory.h" +#include "backends/events/ps3sdl/ps3sdl-events.h" +#include "backends/mixer/sdl13/sdl13-mixer.h" + +#include <dirent.h> +#include <sys/stat.h> + +int access(const char *pathname, int mode) { + struct stat sb; + + if (stat(pathname, &sb) == -1) { + return -1; + } + + return 0; +} + +OSystem_PS3::OSystem_PS3(Common::String baseConfigName) + : _baseConfigName(baseConfigName) { +} + +void OSystem_PS3::init() { + // Initialze File System Factory + _fsFactory = new PS3FilesystemFactory(); + + // Invoke parent implementation of this method + OSystem_SDL::init(); +} + +void OSystem_PS3::initBackend() { + ConfMan.set("joystick_num", 0); + ConfMan.set("vkeybdpath", PREFIX "/data"); + ConfMan.registerDefault("fullscreen", true); + ConfMan.registerDefault("aspect_ratio", true); + + // Create the savefile manager + if (_savefileManager == 0) + _savefileManager = new DefaultSaveFileManager(PREFIX "/saves"); + + // Create the mixer manager + if (_mixer == 0) { + _mixerManager = new Sdl13MixerManager(); + + // Setup and start mixer + _mixerManager->init(); + } + + // Event source + if (_eventSource == 0) + _eventSource = new PS3SdlEventSource(); + + // Invoke parent implementation of this method + OSystem_SDL::initBackend(); +} + +Common::String OSystem_PS3::getDefaultConfigFileName() { + return PREFIX "/" + _baseConfigName; +} + +Common::WriteStream *OSystem_PS3::createLogFile() { + Common::FSNode file(PREFIX "/scummvm.log"); + return file.createWriteStream(); +} diff --git a/backends/platform/sdl/ps3/ps3.h b/backends/platform/sdl/ps3/ps3.h new file mode 100644 index 0000000000..daed7599a9 --- /dev/null +++ b/backends/platform/sdl/ps3/ps3.h @@ -0,0 +1,47 @@ +/* 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 PLATFORM_SDL_PS3_H +#define PLATFORM_SDL_PS3_H + +#include "backends/platform/sdl/sdl.h" + +class OSystem_PS3 : public OSystem_SDL { +public: + // Let the subclasses be able to change _baseConfigName in the constructor + OSystem_PS3(Common::String baseConfigName = "scummvm.ini"); + virtual ~OSystem_PS3() {} + + virtual void init(); + virtual void initBackend(); + +protected: + // Base string for creating the default path and filename + // for the configuration file + Common::String _baseConfigName; + + virtual Common::String getDefaultConfigFileName(); + + virtual Common::WriteStream *createLogFile(); +}; + +#endif diff --git a/backends/platform/sdl/sdl-sys.h b/backends/platform/sdl/sdl-sys.h index 77515ff4e5..ca3c586e03 100644 --- a/backends/platform/sdl/sdl-sys.h +++ b/backends/platform/sdl/sdl-sys.h @@ -27,7 +27,7 @@ // fashion, even on the Symbian port. // Moreover, it contains a workaround for the fact that SDL_rwops.h uses // a FILE pointer in one place, which conflicts with common/forbidden.h. - +// The SDL 1.3 headers also include strings.h #include "common/scummsys.h" @@ -39,6 +39,16 @@ typedef struct { int FAKE; } FAKE_FILE; #define FILE FAKE_FILE #endif +#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strcasecmp) +#undef strcasecmp +#define strcasecmp FAKE_strcasecmp +#endif + +#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strncasecmp) +#undef strncasecmp +#define strncasecmp FAKE_strncasecmp +#endif + #if defined(__SYMBIAN32__) #include <esdl\SDL.h> #else @@ -47,8 +57,19 @@ typedef struct { int FAKE; } FAKE_FILE; // Finally forbid FILE again (if it was forbidden to start with) #if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_FILE) -#undef FILE +#undef FILE #define FILE FORBIDDEN_SYMBOL_REPLACEMENT #endif +#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strcasecmp) +#undef strcasecmp +#define strcasecmp FORBIDDEN_SYMBOL_REPLACEMENT +#endif + +#if !defined(FORBIDDEN_SYMBOL_ALLOW_ALL) && !defined(FORBIDDEN_SYMBOL_EXCEPTION_strncasecmp) +#undef strncasecmp +#define strncasecmp FORBIDDEN_SYMBOL_REPLACEMENT +#endif + + #endif diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index afc6c850d9..d05cca4d1f 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -31,14 +31,22 @@ #include "backends/platform/sdl/sdl.h" #include "common/config-manager.h" #include "common/EventRecorder.h" +#include "common/taskbar.h" #include "common/textconsole.h" #include "backends/saves/default/default-saves.h" + +// Audio CD support was removed with SDL 1.3 +#if SDL_VERSION_ATLEAST(1, 3, 0) +#include "backends/audiocd/default/default-audiocd.h" +#else #include "backends/audiocd/sdl/sdl-audiocd.h" +#endif + #include "backends/events/sdl/sdl-events.h" #include "backends/mutex/sdl/sdl-mutex.h" #include "backends/timer/sdl/sdl-timer.h" -#include "backends/graphics/sdl/sdl-graphics.h" +#include "backends/graphics/surfacesdl/surfacesdl-graphics.h" #ifdef USE_OPENGL #include "backends/graphics/openglsdl/openglsdl-graphics.h" #endif @@ -125,6 +133,11 @@ void OSystem_SDL::init() { if (_timerManager == 0) _timerManager = new SdlTimerManager(); +#if defined(USE_TASKBAR) + if (_taskbarManager == 0) + _taskbarManager = new Common::TaskbarManager(); +#endif + #ifdef USE_OPENGL // Setup a list with both SDL and OpenGL graphics modes setupGraphicsModes(); @@ -167,27 +180,11 @@ void OSystem_SDL::initBackend() { } #endif if (_graphicsManager == 0) { - _graphicsManager = new SdlGraphicsManager(_eventSource); + _graphicsManager = new SurfaceSdlGraphicsManager(_eventSource); graphicsManagerType = 0; } } - // Creates the backend managers, if they don't exist yet (we check - // for this to allow subclasses to provide their own). - if (_eventManager == 0) - _eventManager = new DefaultEventManager(_eventSource); - - // We have to initialize the graphics manager before the event manager - // so the virtual keyboard can be initialized, but we have to add the - // graphics manager as an event observer after initializing the event - // manager. - if (graphicsManagerType == 0) - ((SdlGraphicsManager *)_graphicsManager)->initEventObserver(); -#ifdef USE_OPENGL - else if (graphicsManagerType == 1) - ((OpenGLSdlGraphicsManager *)_graphicsManager)->initEventObserver(); -#endif - if (_savefileManager == 0) _savefileManager = new DefaultSaveFileManager(); @@ -198,8 +195,15 @@ void OSystem_SDL::initBackend() { _mixerManager->init(); } - if (_audiocdManager == 0) + if (_audiocdManager == 0) { + // Audio CD support was removed with SDL 1.3 +#if SDL_VERSION_ATLEAST(1, 3, 0) + _audiocdManager = new DefaultAudioCDManager(); +#else _audiocdManager = new SdlAudioCDManager(); +#endif + + } // Setup a custom program icon. setupIcon(); @@ -207,7 +211,34 @@ void OSystem_SDL::initBackend() { _inited = true; ModularBackend::initBackend(); + + // We have to initialize the graphics manager before the event manager + // so the virtual keyboard can be initialized, but we have to add the + // graphics manager as an event observer after initializing the event + // manager. + if (graphicsManagerType == 0) + ((SurfaceSdlGraphicsManager *)_graphicsManager)->initEventObserver(); +#ifdef USE_OPENGL + else if (graphicsManagerType == 1) + ((OpenGLSdlGraphicsManager *)_graphicsManager)->initEventObserver(); +#endif + +} + +#if defined(USE_TASKBAR) +void OSystem_SDL::engineInit() { + // Add the started engine to the list of recent tasks + _taskbarManager->addRecent(ConfMan.getActiveDomainName(), ConfMan.get("description")); + + // Set the overlay icon the current running engine + _taskbarManager->setOverlayIcon(ConfMan.getActiveDomainName(), ConfMan.get("description")); +} + +void OSystem_SDL::engineDone() { + // Remove overlay icon + _taskbarManager->setOverlayIcon("", ""); } +#endif void OSystem_SDL::initSDL() { // Check if SDL has not been initialized @@ -275,10 +306,22 @@ void OSystem_SDL::fatalError() { void OSystem_SDL::logMessage(LogMessageType::Type type, const char *message) { - ModularBackend::logMessage(type, message); + // First log to stdout/stderr + FILE *output = 0; + + if (type == LogMessageType::kInfo || type == LogMessageType::kDebug) + output = stdout; + else + output = stderr; + + fputs(message, output); + fflush(output); + + // Then log into file (via the logger) if (_logger) _logger->print(message); + // Finally, some Windows / WinCE specific logging code. #if defined( USE_WINDBG ) #if defined( _WIN32_WCE ) TCHAR buf_unicode[1024]; @@ -301,7 +344,7 @@ void OSystem_SDL::logMessage(LogMessageType::Type type, const char *message) { } Common::String OSystem_SDL::getSystemLanguage() const { -#ifdef USE_DETECTLANG +#if defined(USE_DETECTLANG) && !defined(_WIN32_WCE) #ifdef WIN32 // We can not use "setlocale" (at least not for MSVC builds), since it // will return locales like: "English_USA.1252", thus we need a special @@ -368,7 +411,7 @@ void OSystem_SDL::setupIcon() { if (sscanf(scummvm_icon[0], "%d %d %d %d", &w, &h, &ncols, &nbytes) != 4) { warning("Wrong format of scummvm_icon[0] (%s)", scummvm_icon[0]); - + return; } if ((w > 512) || (h > 512) || (ncols > 255) || (nbytes > 1)) { @@ -384,6 +427,7 @@ void OSystem_SDL::setupIcon() { for (i = 0; i < ncols; i++) { unsigned char code; char color[32]; + memset(color, 0, sizeof(color)); unsigned int col; if (sscanf(scummvm_icon[1 + i], "%c c %s", &code, color) != 2) { warning("Wrong format of scummvm_icon[%d] (%s)", 1 + i, scummvm_icon[1 + i]); @@ -472,7 +516,7 @@ bool OSystem_SDL::setGraphicsMode(int mode) { // Check if mode is from SDL or OpenGL if (mode < _sdlModesCount) { - srcMode = SdlGraphicsManager::supportedGraphicsModes(); + srcMode = SurfaceSdlGraphicsManager::supportedGraphicsModes(); i = 0; } else { srcMode = OpenGLSdlGraphicsManager::supportedGraphicsModes(); @@ -487,8 +531,8 @@ bool OSystem_SDL::setGraphicsMode(int mode) { if (_graphicsMode >= _sdlModesCount && mode < _sdlModesCount) { debug(1, "switching to plain SDL graphics"); delete _graphicsManager; - _graphicsManager = new SdlGraphicsManager(_eventSource); - ((SdlGraphicsManager *)_graphicsManager)->initEventObserver(); + _graphicsManager = new SurfaceSdlGraphicsManager(_eventSource); + ((SurfaceSdlGraphicsManager *)_graphicsManager)->initEventObserver(); _graphicsManager->beginGFXTransaction(); } else if (_graphicsMode < _sdlModesCount && mode >= _sdlModesCount) { debug(1, "switching to OpenGL graphics"); @@ -514,7 +558,7 @@ int OSystem_SDL::getGraphicsMode() const { } void OSystem_SDL::setupGraphicsModes() { - const OSystem::GraphicsMode *sdlGraphicsModes = SdlGraphicsManager::supportedGraphicsModes(); + const OSystem::GraphicsMode *sdlGraphicsModes = SurfaceSdlGraphicsManager::supportedGraphicsModes(); const OSystem::GraphicsMode *openglGraphicsModes = OpenGLSdlGraphicsManager::supportedGraphicsModes(); _sdlModesCount = 0; _glModesCount = 0; diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 9c08752054..395b2b3aac 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -30,7 +30,7 @@ #include "backends/events/sdl/sdl-events.h" #include "backends/log/log.h" -/** +/** * Base OSystem class for all SDL ports. */ class OSystem_SDL : public ModularBackend { @@ -38,7 +38,7 @@ public: OSystem_SDL(); virtual ~OSystem_SDL(); - /** + /** * Pre-initialize backend. It should be called after * instantiating the backend. Early needed managers are * created here. @@ -54,6 +54,10 @@ public: // Override functions from ModularBackend and OSystem virtual void initBackend(); +#if defined(USE_TASKBAR) + virtual void engineInit(); + virtual void engineDone(); +#endif virtual Common::HardwareKeySet *getHardwareKeySet(); virtual void quit(); virtual void fatalError(); diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp index 5b14be4417..a2c8e43424 100644 --- a/backends/platform/sdl/win32/win32.cpp +++ b/backends/platform/sdl/win32/win32.cpp @@ -23,10 +23,6 @@ // Disable symbol overrides so that we can use system headers. #define FORBIDDEN_SYMBOL_ALLOW_ALL -#include "common/scummsys.h" -#include "common/error.h" -#include "common/textconsole.h" - #ifdef WIN32 #define WIN32_LEAN_AND_MEAN @@ -34,58 +30,52 @@ #undef ARRAYSIZE // winnt.h defines ARRAYSIZE, but we want our own one... #include <shellapi.h> +#include "common/scummsys.h" +#include "common/config-manager.h" +#include "common/error.h" +#include "common/textconsole.h" + +#include <SDL_syswm.h> // For setting the icon + #include "backends/platform/sdl/win32/win32.h" #include "backends/fs/windows/windows-fs-factory.h" +#include "backends/taskbar/win32/win32-taskbar.h" #include "common/memstream.h" #define DEFAULT_CONFIG_FILE "scummvm.ini" -//#define HIDE_CONSOLE +void OSystem_Win32::init() { + // Initialize File System Factory + _fsFactory = new WindowsFilesystemFactory(); -#ifdef HIDE_CONSOLE -struct SdlConsoleHidingWin32 { - DWORD myPid; - DWORD myTid; - HWND consoleHandle; -}; +#if defined(USE_TASKBAR) + // Initialize taskbar manager + _taskbarManager = new Win32TaskbarManager(); +#endif -// console hiding for win32 -static BOOL CALLBACK initBackendFindConsoleWin32Proc(HWND hWnd, LPARAM lParam) { - DWORD pid, tid; - SdlConsoleHidingWin32 *variables = (SdlConsoleHidingWin32 *)lParam; - tid = GetWindowThreadProcessId(hWnd, &pid); - if ((tid == variables->myTid) && (pid == variables->myPid)) { - variables->consoleHandle = hWnd; - return FALSE; - } - return TRUE; + // Invoke parent implementation of this method + OSystem_SDL::init(); } -#endif +void OSystem_Win32::initBackend() { + // Console window is enabled by default on Windows + ConfMan.registerDefault("console", true); -void OSystem_Win32::init() { -#ifdef HIDE_CONSOLE - // console hiding for win32 - SdlConsoleHidingWin32 consoleHidingWin32; - consoleHidingWin32.consoleHandle = 0; - consoleHidingWin32.myPid = GetCurrentProcessId(); - consoleHidingWin32.myTid = GetCurrentThreadId(); - EnumWindows (initBackendFindConsoleWin32Proc, (LPARAM)&consoleHidingWin32); - - if (!ConfMan.getBool("show_console")) { - if (consoleHidingWin32.consoleHandle) { - // We won't find a window with our TID/PID in case we were started from command-line - ShowWindow(consoleHidingWin32.consoleHandle, SW_HIDE); + // Enable or disable the window console window + if (ConfMan.getBool("console")) { + if (AllocConsole()) { + freopen("CONIN$","r",stdin); + freopen("CONOUT$","w",stdout); + freopen("CONOUT$","w",stderr); } + SetConsoleTitle("ScummVM Status Window"); + } else { + FreeConsole(); } -#endif - - // Initialze File System Factory - _fsFactory = new WindowsFilesystemFactory(); // Invoke parent implementation of this method - OSystem_SDL::init(); + OSystem_SDL::initBackend(); } @@ -131,6 +121,28 @@ bool OSystem_Win32::displayLogFile() { return false; } +void OSystem_Win32::setupIcon() { + HMODULE handle = GetModuleHandle(NULL); + HICON ico = LoadIcon(handle, MAKEINTRESOURCE(1001 /* IDI_ICON */)); + if (ico) { + SDL_SysWMinfo wminfo; + SDL_VERSION(&wminfo.version); + if (SDL_GetWMInfo(&wminfo)) { + // Replace the handle to the icon associated with the window class by our custom icon + SetClassLongPtr(wminfo.window, GCLP_HICON, (ULONG_PTR)ico); + + // Since there wasn't any default icon, we can't use the return value from SetClassLong + // to check for errors (it would be 0 in both cases: error or no previous value for the + // icon handle). Instead we check for the last-error code value. + if (GetLastError() == ERROR_SUCCESS) + return; + } + } + + // If no icon has been set, fallback to default path + OSystem_SDL::setupIcon(); +} + Common::String OSystem_Win32::getDefaultConfigFileName() { char configFile[MAXPATHLEN]; @@ -149,18 +161,31 @@ Common::String OSystem_Win32::getDefaultConfigFileName() { error("Unable to access user profile directory"); strcat(configFile, "\\Application Data"); - CreateDirectory(configFile, NULL); + + // If the directory already exists (as it should in most cases), + // we don't want to fail, but we need to stop on other errors (such as ERROR_PATH_NOT_FOUND) + if (!CreateDirectory(configFile, NULL)) { + if (GetLastError() != ERROR_ALREADY_EXISTS) + error("Cannot create Application data folder"); + } } strcat(configFile, "\\ScummVM"); - CreateDirectory(configFile, NULL); + if (!CreateDirectory(configFile, NULL)) { + if (GetLastError() != ERROR_ALREADY_EXISTS) + error("Cannot create ScummVM application data folder"); + } + strcat(configFile, "\\" DEFAULT_CONFIG_FILE); FILE *tmp = NULL; if ((tmp = fopen(configFile, "r")) == NULL) { // Check windows directory char oldConfigFile[MAXPATHLEN]; - GetWindowsDirectory(oldConfigFile, MAXPATHLEN); + uint ret = GetWindowsDirectory(oldConfigFile, MAXPATHLEN); + if (ret == 0 || ret > MAXPATHLEN) + error("Cannot retrieve the path of the Windows directory"); + strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE); if ((tmp = fopen(oldConfigFile, "r"))) { strcpy(configFile, oldConfigFile); @@ -172,7 +197,10 @@ Common::String OSystem_Win32::getDefaultConfigFileName() { } } else { // Check windows directory - GetWindowsDirectory(configFile, MAXPATHLEN); + uint ret = GetWindowsDirectory(configFile, MAXPATHLEN); + if (ret == 0 || ret > MAXPATHLEN) + error("Cannot retrieve the path of the Windows directory"); + strcat(configFile, "\\" DEFAULT_CONFIG_FILE); } @@ -300,7 +328,7 @@ Common::SeekableReadStream *Win32ResourceArchive::createReadStreamForMember(cons } // End of anonymous namespace void OSystem_Win32::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { - s.add("Win32Res", new Win32ResourceArchive()); + s.add("Win32Res", new Win32ResourceArchive(), priority); OSystem_SDL::addSysArchivesToSearchSet(s, priority); } diff --git a/backends/platform/sdl/win32/win32.h b/backends/platform/sdl/win32/win32.h index ef7b6af3f1..b56997a63b 100644 --- a/backends/platform/sdl/win32/win32.h +++ b/backends/platform/sdl/win32/win32.h @@ -28,6 +28,7 @@ class OSystem_Win32 : public OSystem_SDL { public: virtual void init(); + virtual void initBackend(); virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0); @@ -46,6 +47,7 @@ protected: */ Common::String _logFilePath; + virtual void setupIcon(); virtual Common::String getDefaultConfigFileName(); virtual Common::WriteStream *createLogFile(); }; |