WIN32: Add DialogManager with system file browser support
This commit is contained in:
parent
2f2555f728
commit
61070f6ce0
6 changed files with 211 additions and 7 deletions
136
backends/dialogs/win32/win32-dialogs.cpp
Normal file
136
backends/dialogs/win32/win32-dialogs.cpp
Normal file
|
@ -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
|
45
backends/dialogs/win32/win32-dialogs.h
Normal file
45
backends/dialogs/win32/win32-dialogs.h
Normal file
|
@ -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
|
|
@ -189,6 +189,7 @@ endif
|
||||||
ifdef WIN32
|
ifdef WIN32
|
||||||
MODULE_OBJS += \
|
MODULE_OBJS += \
|
||||||
audiocd/win32/win32-audiocd.o \
|
audiocd/win32/win32-audiocd.o \
|
||||||
|
dialogs/win32/win32-dialogs.o \
|
||||||
fs/windows/windows-fs.o \
|
fs/windows/windows-fs.o \
|
||||||
fs/windows/windows-fs-factory.o \
|
fs/windows/windows-fs-factory.o \
|
||||||
midi/windows.o \
|
midi/windows.o \
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
#include "backends/fs/windows/windows-fs-factory.h"
|
#include "backends/fs/windows/windows-fs-factory.h"
|
||||||
#include "backends/taskbar/win32/win32-taskbar.h"
|
#include "backends/taskbar/win32/win32-taskbar.h"
|
||||||
#include "backends/updates/win32/win32-updates.h"
|
#include "backends/updates/win32/win32-updates.h"
|
||||||
|
#include "backends/dialogs/win32/win32-dialogs.h"
|
||||||
|
|
||||||
#include "common/memstream.h"
|
#include "common/memstream.h"
|
||||||
|
|
||||||
|
@ -64,6 +65,11 @@ void OSystem_Win32::init() {
|
||||||
_taskbarManager = new Win32TaskbarManager((SdlWindow_Win32*)_window);
|
_taskbarManager = new Win32TaskbarManager((SdlWindow_Win32*)_window);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(USE_SYSDIALOGS)
|
||||||
|
// Initialize dialog manager
|
||||||
|
_dialogManager = new Win32DialogManager((SdlWindow_Win32*)_window);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Invoke parent implementation of this method
|
// Invoke parent implementation of this method
|
||||||
OSystem_SDL::init();
|
OSystem_SDL::init();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,16 +20,10 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Disable symbol overrides so that we can use system headers.
|
|
||||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
|
||||||
|
|
||||||
#include "common/scummsys.h"
|
#include "common/scummsys.h"
|
||||||
// We need certain functions that are excluded by default
|
// We need certain functions that are excluded by default
|
||||||
#undef NONLS
|
#undef NONLS
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#if defined(ARRAYSIZE)
|
|
||||||
#undef ARRAYSIZE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "backends/platform/sdl/win32/win32_wrapper.h"
|
#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);
|
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);
|
DWORD size = MultiByteToWideChar(0, 0, s, -1, NULL, 0);
|
||||||
|
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
|
@ -84,4 +78,16 @@ LPWSTR ansiToUnicode(const char *s) {
|
||||||
return NULL;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,16 @@ bool confirmWindowsVersion(int majorVersion, int minorVersion);
|
||||||
* @note Return value must be freed by the caller.
|
* @note Return value must be freed by the caller.
|
||||||
*/
|
*/
|
||||||
wchar_t *ansiToUnicode(const char *s);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue