diff options
| -rw-r--r-- | backends/dialogs/win32/win32-dialogs.cpp | 136 | ||||
| -rw-r--r-- | backends/dialogs/win32/win32-dialogs.h | 45 | ||||
| -rw-r--r-- | backends/module.mk | 1 | ||||
| -rw-r--r-- | backends/platform/sdl/win32/win32.cpp | 6 | ||||
| -rw-r--r-- | backends/platform/sdl/win32/win32_wrapper.cpp | 20 | ||||
| -rw-r--r-- | backends/platform/sdl/win32/win32_wrapper.h | 10 | 
6 files changed, 211 insertions, 7 deletions
diff --git a/backends/dialogs/win32/win32-dialogs.cpp b/backends/dialogs/win32/win32-dialogs.cpp new file mode 100644 index 0000000000..b7d41cfa01 --- /dev/null +++ b/backends/dialogs/win32/win32-dialogs.cpp @@ -0,0 +1,136 @@ +/* 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. + * + */ + +#if defined(WIN32) && defined(USE_SYSDIALOGS) + +// Disable symbol overrides so that we can use system headers. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + +#include <windows.h> +#include <shlobj.h> +#if defined(ARRAYSIZE) +#undef ARRAYSIZE +#endif + +#include "common/scummsys.h" + +#include "backends/dialogs/win32/win32-dialogs.h" +#include "backends/platform/sdl/win32/win32_wrapper.h" +#include "backends/platform/sdl/win32/win32-window.h" + +#include "common/config-manager.h" +#include "common/system.h" +#include "common/events.h" +#include "common/translation.h" + +Win32DialogManager::Win32DialogManager(SdlWindow_Win32 *window) : _window(window) { +	CoInitialize(NULL); +} + +Win32DialogManager::~Win32DialogManager() { +	CoUninitialize(); +} + +Common::DialogManager::DialogResult Win32DialogManager::showFileBrowser(const char *title, Common::FSNode &choice, bool isDirBrowser) { +	DialogResult result = kDialogError; + +	// Do nothing if not running on Windows Vista or later +	if (!Win32::confirmWindowsVersion(6, 0)) +		return result; + +	IFileOpenDialog *dialog = NULL; +	HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, +	                              NULL, +	                              CLSCTX_INPROC_SERVER, +	                              IID_PPV_ARGS(&dialog)); + +	if (SUCCEEDED(hr)) { +		// If in fullscreen mode, switch to windowed mode +		bool wasFullscreen = g_system->getFeatureState(OSystem::kFeatureFullscreenMode); +		if (wasFullscreen) { +			g_system->beginGFXTransaction(); +			g_system->setFeatureState(OSystem::kFeatureFullscreenMode, false); +			g_system->endGFXTransaction(); +		} + +		// Customize dialog +		bool showHidden = ConfMan.getBool("gui_browser_show_hidden", Common::ConfigManager::kApplicationDomain); + +		DWORD dwOptions; +		hr = dialog->GetOptions(&dwOptions); +		if (SUCCEEDED(hr)) { +			if (isDirBrowser) +				dwOptions |= FOS_PICKFOLDERS; +			if (showHidden) +				dwOptions |= FOS_FORCESHOWHIDDEN; +			hr = dialog->SetOptions(dwOptions); +		} + +		LPWSTR str = Win32::ansiToUnicode(title); +		hr = dialog->SetTitle(str); +		delete[] str; + +		str = Win32::ansiToUnicode(_("Choose")); +		hr = dialog->SetOkButtonLabel(str); +		delete[] str; + +		// Show dialog +		hr = dialog->Show(_window->getHwnd()); + +		if (SUCCEEDED(hr)) { +			IShellItem *selectedItem = NULL; +			LPWSTR path = NULL; + +			// Get the selection from the user +			hr = dialog->GetResult(&selectedItem); + +			if (SUCCEEDED(hr)) { +				hr = selectedItem->GetDisplayName(SIGDN_FILESYSPATH, &path); + +				if (SUCCEEDED(hr)) { +					char *str = Win32::unicodeToAnsi(path); +					choice = Common::FSNode(str); +					result = kDialogOk; +					CoTaskMemFree(path); +					delete[] str; +				} + +				selectedItem->Release(); +			} +		} else if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) { +			result = kDialogCancel; +		} + +		dialog->Release(); + +		// If we were in fullscreen mode, switch back +		if (wasFullscreen) { +			g_system->beginGFXTransaction(); +			g_system->setFeatureState(OSystem::kFeatureFullscreenMode, true); +			g_system->endGFXTransaction(); +		} +	} + +	return result; +} + +#endif diff --git a/backends/dialogs/win32/win32-dialogs.h b/backends/dialogs/win32/win32-dialogs.h new file mode 100644 index 0000000000..32454bd67f --- /dev/null +++ b/backends/dialogs/win32/win32-dialogs.h @@ -0,0 +1,45 @@ +/* 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 BACKEND_WIN32_DIALOGS_H +#define BACKEND_WIN32_DIALOGS_H + +#if defined(WIN32) && defined(USE_SYSDIALOGS) + +#include "common/fs.h" +#include "common/dialogs.h" + +class SdlWindow_Win32; + +class Win32DialogManager : public Common::DialogManager { +public: +	Win32DialogManager(SdlWindow_Win32 *window); +	virtual ~Win32DialogManager(); +	virtual DialogResult showFileBrowser(const char *title, Common::FSNode &choice, bool isDirBrowser); + +private: +	SdlWindow_Win32 *_window; +}; + +#endif + +#endif // BACKEND_WIN32_DIALOGS_H diff --git a/backends/module.mk b/backends/module.mk index ad02481bfa..4d2bdc1c08 100644 --- a/backends/module.mk +++ b/backends/module.mk @@ -189,6 +189,7 @@ endif  ifdef WIN32  MODULE_OBJS += \  	audiocd/win32/win32-audiocd.o \ +	dialogs/win32/win32-dialogs.o \  	fs/windows/windows-fs.o \  	fs/windows/windows-fs-factory.o \  	midi/windows.o \ diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp index 936662e7fe..b94c6bb742 100644 --- a/backends/platform/sdl/win32/win32.cpp +++ b/backends/platform/sdl/win32/win32.cpp @@ -47,6 +47,7 @@  #include "backends/fs/windows/windows-fs-factory.h"  #include "backends/taskbar/win32/win32-taskbar.h"  #include "backends/updates/win32/win32-updates.h" +#include "backends/dialogs/win32/win32-dialogs.h"  #include "common/memstream.h" @@ -64,6 +65,11 @@ void OSystem_Win32::init() {  	_taskbarManager = new Win32TaskbarManager((SdlWindow_Win32*)_window);  #endif +#if defined(USE_SYSDIALOGS) +	// Initialize dialog manager +	_dialogManager = new Win32DialogManager((SdlWindow_Win32*)_window); +#endif +  	// Invoke parent implementation of this method  	OSystem_SDL::init();  } diff --git a/backends/platform/sdl/win32/win32_wrapper.cpp b/backends/platform/sdl/win32/win32_wrapper.cpp index 3ff00b6f2d..d199ce8994 100644 --- a/backends/platform/sdl/win32/win32_wrapper.cpp +++ b/backends/platform/sdl/win32/win32_wrapper.cpp @@ -20,16 +20,10 @@   *   */ -// Disable symbol overrides so that we can use system headers. -#define FORBIDDEN_SYMBOL_ALLOW_ALL -  #include "common/scummsys.h"  // We need certain functions that are excluded by default  #undef NONLS  #include <windows.h> -#if defined(ARRAYSIZE) -#undef ARRAYSIZE -#endif  #include "backends/platform/sdl/win32/win32_wrapper.h" @@ -72,7 +66,7 @@ bool confirmWindowsVersion(int majorVersion, int minorVersion) {  	return VerifyVersionInfoFunc(&versionInfo, VER_MAJORVERSION | VER_MINORVERSION, conditionMask);  } -LPWSTR ansiToUnicode(const char *s) { +wchar_t *ansiToUnicode(const char *s) {  	DWORD size = MultiByteToWideChar(0, 0, s, -1, NULL, 0);  	if (size > 0) { @@ -84,4 +78,16 @@ LPWSTR ansiToUnicode(const char *s) {  	return NULL;  } +char *unicodeToAnsi(const wchar_t *s) { +	DWORD size = WideCharToMultiByte(0, 0, s, -1, NULL, 0, 0, 0); + +	if (size > 0) { +		char *result = new char[size]; +		if (WideCharToMultiByte(0, 0, s, -1, result, size, 0, 0) != 0) +			return result; +	} + +	return NULL; +} +  } diff --git a/backends/platform/sdl/win32/win32_wrapper.h b/backends/platform/sdl/win32/win32_wrapper.h index 5722d8844f..91cbe3a891 100644 --- a/backends/platform/sdl/win32/win32_wrapper.h +++ b/backends/platform/sdl/win32/win32_wrapper.h @@ -44,6 +44,16 @@ bool confirmWindowsVersion(int majorVersion, int minorVersion);   * @note Return value must be freed by the caller.   */  wchar_t *ansiToUnicode(const char *s); +/** + * Converts a Windows wide-character string into a C string. + * Used to interact with Win32 Unicode APIs with no ANSI fallback. + * + * @param s Source string + * @return Converted string + * + * @note Return value must be freed by the caller. + */ +char *unicodeToAnsi(const wchar_t *s);  }  | 
