Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
#include "common/scummsys.h"
#if defined(__amigaos4__) && defined(USE_SYSDIALOGS)
#include "backends/dialogs/amigaos/amigaos-dialogs.h"
#include "common/config-manager.h"
#include <proto/asl.h>
#include <proto/dos.h>
#include <proto/exec.h>
struct AslIFace *IAsl;
struct Library *AslBase;
Common::DialogManager::DialogResult AmigaOSDialogManager::showFileBrowser(const Common::U32String &title, Common::FSNode &choice, bool isDirBrowser) {
char pathBuffer[MAXPATHLEN];
Common::strcpy_s(pathBuffer, "SYS:");
Common::String newTitle = title.encode(Common::kISO8859_1);
DialogResult result = kDialogCancel;
AslBase = IExec->OpenLibrary(AslName, 50);
if (AslBase) {
IAsl = (struct AslIFace*)IExec->GetInterface(AslBase, "main", 1, nullptr);
struct FileRequester *fr = nullptr;
if (ConfMan.hasKey("browser_lastpath")) {
strncpy(pathBuffer, ConfMan.getPath("browser_lastpath").toString(Common::Path::kNativeSeparator).c_str(), sizeof(pathBuffer) - 1);
}
fr = (struct FileRequester *)IAsl->AllocAslRequestTags(ASL_FileRequest, TAG_DONE);
if (!fr)
return result;
if (IAsl->AslRequestTags(fr, ASLFR_TitleText, newTitle.c_str(), ASLFR_RejectIcons, TRUE, ASLFR_InitialDrawer, pathBuffer, (isDirBrowser ? TRUE : FALSE), TAG_DONE)) {
if (strlen(fr->fr_Drawer) < sizeof(pathBuffer)) {
strncpy(pathBuffer, fr->fr_Drawer, sizeof(pathBuffer));
if (!isDirBrowser) {
IDOS->AddPart(pathBuffer, fr->fr_File, sizeof(pathBuffer));
}
Common::Path path(pathBuffer);
choice = Common::FSNode(path);
ConfMan.setPath("browser_lastpath", path);
result = kDialogOk;
}
IAsl->FreeAslRequest((APTR)fr);
}
AslBase = nullptr;
IAsl = nullptr;
IExec->CloseLibrary(AslBase);
IExec->DropInterface((struct Interface*)IAsl);
}
return result;
}
#endif

View File

@@ -0,0 +1,37 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef BACKEND_AMIGAOS_DIALOGS_H
#define BACKEND_AMIGAOS_DIALOGS_H
#if defined(__amigaos4__) && defined(USE_SYSDIALOGS)
#include "common/dialogs.h"
#include "common/fs.h"
class AmigaOSDialogManager : public Common::DialogManager {
public:
virtual DialogResult showFileBrowser(const Common::U32String &title, Common::FSNode &choice, bool isDirBrowser);
};
#endif
#endif // BACKEND_AMIGAOS_DIALOGS_H

View File

@@ -0,0 +1,129 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
#define FORBIDDEN_SYMBOL_EXCEPTION_setlocale
#include "common/scummsys.h"
#if defined(POSIX) && defined(USE_SYSDIALOGS) && defined(USE_GTK)
#include "backends/dialogs/gtk/gtk-dialogs.h"
#include "common/config-manager.h"
#include "common/events.h"
#include "common/translation.h"
#include <locale.h>
#include <gtk/gtk.h>
// TODO: Move this into the class? Probably possible, but I've been told that
// this might not necessarily work properly with all compilers.
static gboolean _inDialog;
static uint32 _lastUpdateTick = 0;
static gboolean idleCallback(gpointer data) {
uint32 currentTick = g_system->getMillis();
if (g_system->getMillis() - _lastUpdateTick > 10) {
Common::Event dummy;
while (g_system->getEventManager()->pollEvent(dummy)) {}
g_system->updateScreen();
_lastUpdateTick = currentTick;
}
return _inDialog;
}
Common::DialogManager::DialogResult GtkDialogManager::showFileBrowser(const Common::U32String &title, Common::FSNode &choice, bool isDirBrowser) {
if (!gtk_init_check(NULL, NULL))
return kDialogError;
DialogResult result = kDialogCancel;
// Convert labels to UTF-8
Common::String utf8Title = title.encode();
Common::String utf8Choose = _("Choose").encode();
Common::String utf8Cancel = _("Cancel").encode();
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
if (isDirBrowser) {
action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
}
// Set locale to environment one to let user have its localized folders in the browser
setlocale(LC_ALL, "");
#if GTK_CHECK_VERSION(3,20,0)
GtkFileChooserNative *native = gtk_file_chooser_native_new(utf8Title.c_str(), NULL, action, utf8Choose.c_str(), utf8Cancel.c_str());
GtkFileChooser *chooser = GTK_FILE_CHOOSER(native);
#else
GtkWidget *dialog = gtk_file_chooser_dialog_new(utf8Title.c_str(), NULL, action, utf8Choose.c_str(), GTK_RESPONSE_ACCEPT, utf8Cancel.c_str(), GTK_RESPONSE_CANCEL, NULL);
GtkFileChooser *chooser = GTK_FILE_CHOOSER(dialog);
#endif
// Customize dialog
gtk_file_chooser_set_show_hidden(chooser, ConfMan.getBool("gui_browser_show_hidden", Common::ConfigManager::kApplicationDomain));
if (ConfMan.hasKey("browser_lastpath")) {
gtk_file_chooser_set_current_folder(chooser, ConfMan.getPath("browser_lastpath").toString(Common::Path::kNativeSeparator).c_str());
}
// Show dialog
beginDialog();
_inDialog = TRUE;
g_idle_add(idleCallback, NULL);
#if GTK_CHECK_VERSION(3,20,0)
int res = gtk_native_dialog_run(GTK_NATIVE_DIALOG(native));
#else
int res = gtk_dialog_run(GTK_DIALOG(dialog));
#endif
if (res == GTK_RESPONSE_ACCEPT) {
// Get the selection from the user
char *pathS = gtk_file_chooser_get_filename(chooser);
Common::Path path(pathS, Common::Path::kNativeSeparator);
choice = Common::FSNode(path);
ConfMan.setPath("browser_lastpath", path);
result = kDialogOk;
g_free(pathS);
}
_inDialog = FALSE;
// Restore default C locale to prevent issues with
// portability of sscanf(), atof(), etc.
// See bugs #6434 and #14196
setlocale(LC_ALL, "C");
#if GTK_CHECK_VERSION(3,20,0)
g_object_unref(native);
#else
gtk_widget_destroy(dialog);
#endif
while (gtk_events_pending())
gtk_main_iteration();
endDialog();
return result;
}
#endif

View File

@@ -0,0 +1,37 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef BACKEND_GTK_DIALOGS_H
#define BACKEND_GTK_DIALOGS_H
#if defined(POSIX) && defined(USE_SYSDIALOGS) && defined(USE_GTK)
#include "common/fs.h"
#include "common/dialogs.h"
class GtkDialogManager : public Common::DialogManager {
public:
virtual DialogResult showFileBrowser(const Common::U32String &title, Common::FSNode &choice, bool isDirBrowser);
};
#endif
#endif // BACKEND_GTK_DIALOGS_H

View File

@@ -0,0 +1,38 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef BACKEND_MACOSX_DIALOGS_H
#define BACKEND_MACOSX_DIALOGS_H
#if defined(MACOSX) && defined(USE_SYSDIALOGS)
#include "common/fs.h"
#include "common/dialogs.h"
#include "common/ustr.h"
class MacOSXDialogManager : public Common::DialogManager {
public:
virtual DialogResult showFileBrowser(const Common::U32String &title, Common::FSNode &choice, bool isDirBrowser);
};
#endif
#endif // BACKEND_MACOSX_DIALOGS_H

View File

@@ -0,0 +1,201 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
// Disable symbol overrides so that we can use system headers
#define FORBIDDEN_SYMBOL_ALLOW_ALL
#include "common/scummsys.h"
#if defined(MACOSX) && defined(USE_SYSDIALOGS)
#include "backends/dialogs/macosx/macosx-dialogs.h"
#include "common/config-manager.h"
#include "common/algorithm.h"
#include "common/translation.h"
#include <AvailabilityMacros.h>
#include <AppKit/NSNibDeclarations.h>
#include <AppKit/NSOpenPanel.h>
#include <AppKit/NSApplication.h>
#include <AppKit/NSButton.h>
#include <Foundation/NSString.h>
#include <Foundation/NSURL.h>
#include <Foundation/NSThread.h>
#include <Foundation/NSAutoreleasePool.h>
// From the 10.6 SDK:
// "This method was published in 10.6, but has existed since 10.4."
//
// This means that the feature works on 10.4/10.5 as well, but their SDK
// headers didn't expose it at all. I've checked that it does work at runtime,
// but we stil keep some respondsToSelector safety calls below, in case its
// symbols were only added in some later 10.4 update or something.
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
@interface NSSavePanel(Undocumented)
- (BOOL)showsHiddenFiles;
- (void)setShowsHiddenFiles:(BOOL)flag;
@end
#endif
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101400
#ifndef NSControlStateValueOff
#define NSControlStateValueOff NSOffState
#endif
#ifndef NSControlStateValueOn
#define NSControlStateValueOn NSOnState
#endif
#define NSButtonTypeSwitch NSSwitchButton
#endif
@interface BrowserDialogPresenter : NSObject {
@public
NSURL *_url;
@private
NSOpenPanel *_panel;
}
- (id) init;
- (void) dealloc;
- (void) showOpenPanel: (NSOpenPanel*) panel;
- (IBAction) showHiddenFiles : (id) sender;
@end
@implementation BrowserDialogPresenter
- (id) init {
self = [super init];
_url = 0;
_panel = 0;
return self;
}
- (void) dealloc {
[_url release];
[super dealloc];
}
- (void) showOpenPanel: (NSOpenPanel*) panel {
_panel = panel;
NSButton *showHiddenFilesButton = 0;
// note: still doing some respondsToSelector tests, because on Tiger/Leopard
// the API was undocumented.
if ([panel respondsToSelector:@selector(showsHiddenFiles)] && [panel respondsToSelector:@selector(setShowsHiddenFiles:)]) {
showHiddenFilesButton = [[NSButton alloc] init];
[showHiddenFilesButton setButtonType:NSButtonTypeSwitch];
CFStringRef hiddenFilesString = CFStringCreateWithCString(0, _("Show hidden files").encode().c_str(), kCFStringEncodingUTF8);
[showHiddenFilesButton setTitle:(NSString*)hiddenFilesString];
CFRelease(hiddenFilesString);
[showHiddenFilesButton sizeToFit];
if (ConfMan.getBool("gui_browser_show_hidden", Common::ConfigManager::kApplicationDomain)) {
[showHiddenFilesButton setState:NSControlStateValueOn];
[panel setShowsHiddenFiles: YES];
} else {
[showHiddenFilesButton setState:NSControlStateValueOff];
[panel setShowsHiddenFiles: NO];
}
[panel setAccessoryView:showHiddenFilesButton];
[showHiddenFilesButton setTarget:self];
[showHiddenFilesButton setAction:@selector(showHiddenFiles:)];
}
#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1090
if ([panel runModal] == NSOKButton) {
#else
if ([panel runModal] == NSModalResponseOK) {
#endif
NSURL *url = [panel URL];
if ([url isFileURL]) {
_url = url;
[_url retain];
}
}
[showHiddenFilesButton release];
_panel = 0;
}
- (IBAction) showHiddenFiles : (id) sender {
if ([sender state] == NSControlStateValueOn) {
[_panel setShowsHiddenFiles: YES];
ConfMan.setBool("gui_browser_show_hidden", true, Common::ConfigManager::kApplicationDomain);
} else {
[_panel setShowsHiddenFiles: NO];
ConfMan.setBool("gui_browser_show_hidden", false, Common::ConfigManager::kApplicationDomain);
}
}
@end
Common::DialogManager::DialogResult MacOSXDialogManager::showFileBrowser(const Common::U32String &title, Common::FSNode &choice, bool isDirBrowser) {
DialogResult result = kDialogCancel;
// Get current encoding
CFStringEncoding stringEncoding = kCFStringEncodingUTF8;
// Convert labels to NSString
CFStringRef titleRef = CFStringCreateWithCString(0, title.encode().c_str(), stringEncoding);
CFStringRef chooseRef = CFStringCreateWithCString(0, _("Choose").encode().c_str(), stringEncoding);
beginDialog();
// Temporarily show the real mouse
CGDisplayShowCursor(kCGDirectMainDisplay);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setCanChooseFiles:!isDirBrowser];
[panel setCanChooseDirectories:isDirBrowser];
if (isDirBrowser)
[panel setTreatsFilePackagesAsDirectories:true];
[panel setTitle:(NSString *)titleRef];
[panel setPrompt:(NSString *)chooseRef];
BrowserDialogPresenter* presenter = [[BrowserDialogPresenter alloc] init];
[presenter performSelectorOnMainThread:@selector(showOpenPanel:) withObject:panel waitUntilDone:YES];
if (presenter->_url) {
Common::Path filename([[presenter->_url path] UTF8String]);
choice = Common::FSNode(filename);
result = kDialogOk;
}
[presenter release];
[pool release];
[keyWindow makeKeyAndOrderFront:nil];
CFRelease(titleRef);
CFRelease(chooseRef);
endDialog();
return result;
}
#endif

View File

@@ -0,0 +1,71 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
#define FORBIDDEN_SYMBOL_EXCEPTION_strdup
#include "common/scummsys.h"
#if defined(__MORPHOS__) && defined(USE_SYSDIALOGS)
#include "backends/dialogs/morphos/morphos-dialogs.h"
#include "common/config-manager.h"
#include <proto/exec.h>
#include <proto/dos.h>
#define __NOLIBBASE__
#include <proto/asl.h>
Common::DialogManager::DialogResult MorphosDialogManager::showFileBrowser(const Common::U32String &title, Common::FSNode &choice, bool isDirBrowser) {
DialogResult result = kDialogCancel;
char pathBuffer[PATH_MAX];
Common::String newTitle = title.encode(Common::kISO8859_1);
struct Library *AslBase = OpenLibrary(AslName, 39);
if (AslBase) {
struct FileRequester *fr = NULL;
if (ConfMan.hasKey("browser_lastpath")) {
strncpy(pathBuffer, ConfMan.getPath("browser_lastpath").toString(Common::Path::kNativeSeparator).c_str(), sizeof(pathBuffer) - 1);
}
fr = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest, TAG_DONE);
if (!fr)
return result;
if (AslRequestTags(fr, ASLFR_TitleText, (IPTR)newTitle.c_str(), ASLFR_RejectIcons, TRUE, ASLFR_InitialDrawer, (IPTR)pathBuffer, ASLFR_DrawersOnly, (isDirBrowser ? TRUE : FALSE), TAG_DONE)) {
if (strlen(fr->fr_Drawer) < sizeof(pathBuffer)) {
strncpy(pathBuffer, fr->fr_Drawer, sizeof(pathBuffer));
ConfMan.setPath("browser_lastpath", pathBuffer); // only path
if (!isDirBrowser) {
AddPart(pathBuffer, fr->fr_File, sizeof(pathBuffer));
}
choice = Common::FSNode(pathBuffer);
result = kDialogOk;
}
}
FreeAslRequest((APTR)fr);
CloseLibrary(AslBase);
}
return result;
}
#endif

View File

@@ -0,0 +1,40 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef BACKEND_MORPHOS_DIALOGS_H
#define BACKEND_MORPHOS_DIALOGS_H
#if defined(__MORPHOS__) && defined(USE_SYSDIALOGS)
#include "common/fs.h"
#include "common/dialogs.h"
class MorphosDialogManager : public Common::DialogManager {
public:
virtual DialogResult showFileBrowser(const Common::U32String &title, Common::FSNode &choice, bool isDirBrowser);
private:
char *utf8ToLocal(char *in);
};
#endif
#endif // BACKEND_MORPHOS_DIALOGS_H

View File

@@ -0,0 +1,169 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
// TODO: Remove header when the latest changes to the Windows SDK have been integrated into MingW
// For reference, the interface definitions here are imported from the SDK headers and MingW-w64
#ifndef BACKEND_WIN32_DIALOGS_MINGW_H
#define BACKEND_WIN32_DIALOGS_MINGW_H
#if defined(WIN32)
#if defined(__GNUC__)
#ifdef __MINGW32__
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <commctrl.h>
#include <initguid.h>
#include <shlwapi.h>
#include <shlguid.h>
// MinGW does not understand COM interfaces
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
// Dialog GUID definitions
DEFINE_GUID(CLSID_FileOpenDialog, 0xdc1c5a9c, 0xe88a, 0x4dde, 0xa5,0xa1, 0x60,0xf8,0x2a,0x20,0xae,0xf7);
DEFINE_GUID(IID_IFileOpenDialog, 0xd57c7288, 0xd4ad, 0x4768, 0xbe,0x02, 0x9d,0x96,0x95,0x32,0xd9,0x60);
DEFINE_GUID(IID_IShellItem, 0x43826d1e, 0xe718, 0x42ee, 0xbc,0x55, 0xa1,0xe2,0x61,0xc3,0x7b,0xfe);
typedef enum _SIGDN {
SIGDN_NORMALDISPLAY = 0,
SIGDN_PARENTRELATIVEPARSING = 0x80018001,
SIGDN_DESKTOPABSOLUTEPARSING = 0x80028000,
SIGDN_PARENTRELATIVEEDITING = 0x80031001,
SIGDN_DESKTOPABSOLUTEEDITING = 0x8004c000,
SIGDN_FILESYSPATH = 0x80058000,
SIGDN_URL = 0x80068000,
SIGDN_PARENTRELATIVEFORADDRESSBAR = 0x8007c001,
SIGDN_PARENTRELATIVE = 0x80080001,
SIGDN_PARENTRELATIVEFORUI = 0x80094001
} SIGDN;
enum _SICHINTF {
SICHINT_DISPLAY = 0,
SICHINT_ALLFIELDS = 0x80000000,
SICHINT_CANONICAL = 0x10000000,
SICHINT_TEST_FILESYSPATH_IF_NOT_EQUAL = 0x20000000
} ;
typedef DWORD SICHINTF;
// Shell item
#define INTERFACE IShellItem
DECLARE_INTERFACE_(IShellItem, IUnknown) {
STDMETHOD(QueryInterface) (THIS_ REFIID riid, void **ppv) PURE;
STDMETHOD_(ULONG,AddRef) (THIS) PURE;
STDMETHOD_(ULONG,Release) (THIS) PURE;
STDMETHOD (BindToHandler) (IBindCtx *pbc, REFGUID bhid, REFIID riid, void **ppv) PURE;
STDMETHOD (GetParent) (IShellItem **ppsi) PURE;
STDMETHOD (GetDisplayName) (SIGDN sigdnName, LPWSTR *ppszName) PURE;
STDMETHOD (GetAttributes) (SFGAOF sfgaoMask, SFGAOF *psfgaoAttribs) PURE;
STDMETHOD (Compare) (IShellItem *psi, SICHINTF hint, int *piOrder) PURE;
};
#undef INTERFACE
// Mingw-specific defines for dialog integration
typedef struct _COMDLG_FILTERSPEC {
LPCWSTR pszName;
LPCWSTR pszSpec;
} COMDLG_FILTERSPEC;
typedef enum FDAP {
FDAP_BOTTOM = 0,
FDAP_TOP = 1
} FDAP;
enum _FILEOPENDIALOGOPTIONS {
FOS_OVERWRITEPROMPT = 0x2,
FOS_STRICTFILETYPES = 0x4,
FOS_NOCHANGEDIR = 0x8,
FOS_PICKFOLDERS = 0x20,
FOS_FORCEFILESYSTEM = 0x40,
FOS_ALLNONSTORAGEITEMS = 0x80,
FOS_NOVALIDATE = 0x100,
FOS_ALLOWMULTISELECT = 0x200,
FOS_PATHMUSTEXIST = 0x800,
FOS_FILEMUSTEXIST = 0x1000,
FOS_CREATEPROMPT = 0x2000,
FOS_SHAREAWARE = 0x4000,
FOS_NOREADONLYRETURN = 0x8000,
FOS_NOTESTFILECREATE = 0x10000,
FOS_HIDEMRUPLACES = 0x20000,
FOS_HIDEPINNEDPLACES = 0x40000,
FOS_NODEREFERENCELINKS = 0x100000,
FOS_DONTADDTORECENT = 0x2000000,
FOS_FORCESHOWHIDDEN = 0x10000000,
FOS_DEFAULTNOMINIMODE = 0x20000000,
FOS_FORCEPREVIEWPANEON = 0x40000000,
FOS_SUPPORTSTREAMABLEITEMS = 0x80000000
};
typedef DWORD FILEOPENDIALOGOPTIONS;
// TODO: Need to implement these if they ever get used
typedef interface IFileDialogEvents IFileDialogEvents;
typedef interface IShellItemFilter IShellItemFilter;
typedef interface IShellItemArray IShellItemArray;
// Open dialog interface
#define INTERFACE IFileOpenDialog
DECLARE_INTERFACE_(IFileOpenDialog, IUnknown) {
// IUnknown
STDMETHOD(QueryInterface) (THIS_ REFIID riid, void **ppv) PURE;
STDMETHOD_(ULONG,AddRef) (THIS) PURE;
STDMETHOD_(ULONG,Release) (THIS) PURE;
// IModalWindow
STDMETHOD (Show) (THIS_ HWND hwndOwner) PURE;
// IFileDialog
STDMETHOD (SetFileTypes) (THIS_ UINT cFileTypes, const COMDLG_FILTERSPEC *rgFilterSpec) PURE;
STDMETHOD (SetFileTypeIndex) (THIS_ UINT iFileType) PURE;
STDMETHOD (GetFileTypeIndex) (THIS_ UINT *piFileType) PURE;
STDMETHOD (Advise) (THIS_ IFileDialogEvents *pfde, DWORD *pdwCookie) PURE;
STDMETHOD (Unadvise) (THIS_ DWORD dwCookie) PURE;
STDMETHOD (SetOptions) (THIS_ FILEOPENDIALOGOPTIONS fos) PURE;
STDMETHOD (GetOptions) (THIS_ FILEOPENDIALOGOPTIONS *pfos) PURE;
STDMETHOD (SetDefaultFolder) (THIS_ IShellItem *psi) PURE;
STDMETHOD (SetFolder) (THIS_ IShellItem *psi) PURE;
STDMETHOD (GetFolder) (THIS_ IShellItem **ppsi) PURE;
STDMETHOD (GetCurrentSelection) (THIS_ IShellItem **ppsi) PURE;
STDMETHOD (SetFileName) (THIS_ LPCWSTR pszName) PURE;
STDMETHOD (GetFileName) (THIS_ LPWSTR *pszName) PURE;
STDMETHOD (SetTitle) (THIS_ LPCWSTR pszTitle) PURE;
STDMETHOD (SetOkButtonLabel) (THIS_ LPCWSTR pszText) PURE;
STDMETHOD (SetFileNameLabel) (THIS_ LPCWSTR pszLabel) PURE;
STDMETHOD (GetResult) (THIS_ IShellItem **ppsi) PURE;
STDMETHOD (AddPlace) (THIS_ IShellItem *psi, FDAP fdap) PURE;
STDMETHOD (SetDefaultExtension) (THIS_ LPCWSTR pszDefaultExtension) PURE;
STDMETHOD (Close) (THIS_ HRESULT hr) PURE;
STDMETHOD (SetClientGuid) (THIS_ REFGUID guid) PURE;
STDMETHOD (ClearClientData) (THIS) PURE;
STDMETHOD (SetFilter) (THIS_ IShellItemFilter *pFilter) PURE;
// IFileOpenDialog
STDMETHOD (GetResults) (THIS_ IShellItemArray **ppenum) PURE;
STDMETHOD (GetSelectedItems) (THIS_ IShellItemArray **ppsai) PURE;
};
#undef INTERFACE
#endif // __MINGW32__
#endif // __GNUC__
#endif // WIN32
#endif // BACKEND_WIN32_DIALOGS_MINGW_H

View File

@@ -0,0 +1,192 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
// We cannot use common/scummsys.h directly as it will include
// windows.h and we need to do it by hand to allow excluded functions
#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif
#if defined(WIN32) && defined(USE_SYSDIALOGS)
// HACK: To get __MINGW64_VERSION_foo defines we need to manually include
// _mingw.h in this file because we do not include any system headers at this
// point on purpose. The defines are required to detect whether this is a
// classic MinGW toolchain or a MinGW-w64 based one.
#if defined(__MINGW32__)
#include <_mingw.h>
#endif
// Needed for dialog functions
// HACK: MinGW-w64 based toolchains include the symbols we require in their
// headers. The 32 bit incarnation only defines __MINGW32__. This leads to
// build breakage due to clashes with our compat header. Luckily MinGW-w64
// based toolchains define __MINGW64_VERSION_foo macros inside _mingw.h,
// which is included from all system headers. Thus we abuse that to detect
// them.
#if defined(__GNUC__) && defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
#include "backends/dialogs/win32/mingw-compat.h"
#else
// We use functionality introduced with Vista in this file.
// To assure that including the respective system headers gives us all
// required definitions we set Vista as minimum version we target.
// See: https://docs.microsoft.com/en-us/windows/win32/winprog/using-the-windows-headers#macros-for-conditional-declarations
#include <sdkddkver.h>
#undef _WIN32_WINNT
#define _WIN32_WINNT _WIN32_WINNT_VISTA
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include <shlobj.h>
#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/translation.h"
Win32DialogManager::Win32DialogManager(SdlWindow_Win32 *window) : _window(window) {
CoInitialize(nullptr);
}
Win32DialogManager::~Win32DialogManager() {
CoUninitialize();
}
// Wrapper for old Windows versions
HRESULT winCreateItemFromParsingName(PCWSTR pszPath, IBindCtx *pbc, REFIID riid, void **ppv) {
typedef HRESULT(WINAPI *SHFunc)(PCWSTR, IBindCtx *, REFIID, void **);
SHFunc func = (SHFunc)(void *)GetProcAddress(GetModuleHandle(TEXT("shell32.dll")), "SHCreateItemFromParsingName");
if (func == nullptr)
return E_NOTIMPL;
return func(pszPath, pbc, riid, ppv);
}
HRESULT getShellPath(IShellItem *item, Common::Path &path) {
LPWSTR name = nullptr;
HRESULT hr = item->GetDisplayName(SIGDN_FILESYSPATH, &name);
if (SUCCEEDED(hr)) {
char *str = Win32::unicodeToAnsi(name);
path = Common::Path(str, Common::Path::kNativeSeparator);
CoTaskMemFree(name);
free(str);
}
return hr;
}
Common::DialogManager::DialogResult Win32DialogManager::showFileBrowser(const Common::U32String &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 = nullptr;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog,
nullptr,
CLSCTX_INPROC_SERVER,
IID_IFileOpenDialog,
reinterpret_cast<void **> (&(dialog)));
if (SUCCEEDED(hr)) {
beginDialog();
// 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 dialogTitle = (LPWSTR)title.encodeUTF16Native();
hr = dialog->SetTitle(dialogTitle);
free(dialogTitle);
LPWSTR okTitle = (LPWSTR)_("Choose").encodeUTF16Native();
hr = dialog->SetOkButtonLabel(okTitle);
free(okTitle);
LPWSTR str;
if (ConfMan.hasKey("browser_lastpath")) {
str = Win32::ansiToUnicode(ConfMan.getPath("browser_lastpath").toString(Common::Path::kNativeSeparator).c_str());
IShellItem *item = nullptr;
hr = winCreateItemFromParsingName(str, nullptr, IID_IShellItem, reinterpret_cast<void **> (&(item)));
if (SUCCEEDED(hr)) {
hr = dialog->SetDefaultFolder(item);
}
free(str);
}
// Show dialog
hr = dialog->Show(_window->getHwnd());
if (SUCCEEDED(hr)) {
// Get the selection from the user
IShellItem *selectedItem = nullptr;
hr = dialog->GetResult(&selectedItem);
if (SUCCEEDED(hr)) {
Common::Path path;
hr = getShellPath(selectedItem, path);
if (SUCCEEDED(hr)) {
choice = Common::FSNode(path);
result = kDialogOk;
}
selectedItem->Release();
}
// Save last path
IShellItem *lastFolder = nullptr;
hr = dialog->GetFolder(&lastFolder);
if (SUCCEEDED(hr)) {
Common::Path path;
hr = getShellPath(lastFolder, path);
if (SUCCEEDED(hr)) {
ConfMan.setPath("browser_lastpath", path);
}
lastFolder->Release();
}
}
else if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) {
result = kDialogCancel;
}
dialog->Release();
endDialog();
}
return result;
}
#endif

View 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef BACKEND_WIN32_DIALOGS_H
#define BACKEND_WIN32_DIALOGS_H
#if defined(WIN32) && defined(USE_SYSDIALOGS)
#include "common/fs.h"
#include "common/dialogs.h"
#include "common/ustr.h"
class SdlWindow_Win32;
class Win32DialogManager final : public Common::DialogManager {
public:
Win32DialogManager(SdlWindow_Win32 *window);
virtual ~Win32DialogManager();
DialogResult showFileBrowser(const Common::U32String &title, Common::FSNode &choice, bool isDirBrowser) override;
private:
SdlWindow_Win32 *_window;
};
#endif
#endif // BACKEND_WIN32_DIALOGS_H