aboutsummaryrefslogtreecommitdiff
path: root/backends/dialogs/macosx
diff options
context:
space:
mode:
authorSupSuper2018-11-20 02:13:23 +0000
committerThierry Crozat2018-12-16 10:48:13 +0000
commit28e4d7bb438d75526f700cd954da6f28ebc45a29 (patch)
tree9fe19d44da34d3193b8ed5860546e0276cf7211e /backends/dialogs/macosx
parentfbc9c7d371a4a123f3180ed54f26dfb5799fcc36 (diff)
downloadscummvm-rg350-28e4d7bb438d75526f700cd954da6f28ebc45a29.tar.gz
scummvm-rg350-28e4d7bb438d75526f700cd954da6f28ebc45a29.tar.bz2
scummvm-rg350-28e4d7bb438d75526f700cd954da6f28ebc45a29.zip
OSX: Integrate system file browser into DialogManager
Diffstat (limited to 'backends/dialogs/macosx')
-rw-r--r--backends/dialogs/macosx/macosx-dialogs.h38
-rw-r--r--backends/dialogs/macosx/macosx-dialogs.mm51
2 files changed, 59 insertions, 30 deletions
diff --git a/backends/dialogs/macosx/macosx-dialogs.h b/backends/dialogs/macosx/macosx-dialogs.h
new file mode 100644
index 0000000000..351563e665
--- /dev/null
+++ b/backends/dialogs/macosx/macosx-dialogs.h
@@ -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 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_MACOSX_DIALOGS_H
+#define BACKEND_MACOSX_DIALOGS_H
+
+#if defined(MACOSX) && defined(USE_SYSDIALOGS)
+
+#include "common/fs.h"
+#include "common/dialogs.h"
+
+class MacOSXDialogManager : public Common::DialogManager {
+public:
+ virtual DialogResult showFileBrowser(const char *title, Common::FSNode &choice, bool isDirBrowser);
+};
+
+#endif
+
+#endif // BACKEND_MACOSX_DIALOGS_H
diff --git a/backends/dialogs/macosx/macosx-dialogs.mm b/backends/dialogs/macosx/macosx-dialogs.mm
index ffb64ee96a..f308d4c78d 100644
--- a/backends/dialogs/macosx/macosx-dialogs.mm
+++ b/backends/dialogs/macosx/macosx-dialogs.mm
@@ -22,8 +22,11 @@
// Disable symbol overrides so that we can use system headers
#define FORBIDDEN_SYMBOL_ALLOW_ALL
+#include "common/scummsys.h"
-#include "gui/browser.h"
+#if defined(MACOSX) && defined(USE_SYSDIALOGS)
+
+#include "backends/dialogs/macosx/macosx-dialogs.h"
#include "common/config-manager.h"
#include "common/system.h"
@@ -127,13 +130,9 @@
@end
-namespace GUI {
-
-BrowserDialog::BrowserDialog(const char *title, bool dirBrowser)
- : Dialog("Browser") {
+Common::DialogManager::DialogResult MacOSXDialogManager::showFileBrowser(const char *title, Common::FSNode &choice, bool isDirBrowser) {
- // remember whether this is a file browser or a directory browser.
- _isDirBrowser = dirBrowser;
+ DialogResult result = kDialogCancel;
// Get current encoding
#ifdef USE_TRANSLATION
@@ -144,20 +143,9 @@ BrowserDialog::BrowserDialog(const char *title, bool dirBrowser)
CFStringEncoding stringEncoding = kCFStringEncodingASCII;
#endif
- // Convert title to NSString
- _titleRef = CFStringCreateWithCString(0, title, stringEncoding);
-
- // Convert button text to NSString
- _chooseRef = CFStringCreateWithCString(0, _("Choose"), stringEncoding);
-}
-
-BrowserDialog::~BrowserDialog() {
- CFRelease(_titleRef);
- CFRelease(_chooseRef);
-}
-
-int BrowserDialog::runModal() {
- bool choiceMade = false;
+ // Convert labels to NSString
+ CFStringRef titleRef = CFStringCreateWithCString(0, title, stringEncoding);
+ CFStringRef chooseRef = CFStringCreateWithCString(0, _("Choose"), stringEncoding);
// If in fullscreen mode, switch to windowed mode
bool wasFullscreen = g_system->getFeatureState(OSystem::kFeatureFullscreenMode);
@@ -175,25 +163,28 @@ int BrowserDialog::runModal() {
NSOpenPanel *panel = [NSOpenPanel openPanel];
- [panel setCanChooseFiles:!_isDirBrowser];
- [panel setCanChooseDirectories:_isDirBrowser];
- if (_isDirBrowser)
+ [panel setCanChooseFiles:!isDirBrowser];
+ [panel setCanChooseDirectories:isDirBrowser];
+ if (isDirBrowser)
[panel setTreatsFilePackagesAsDirectories:true];
- [panel setTitle:(NSString *)_titleRef];
- [panel setPrompt:(NSString *)_chooseRef];
+ [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::String filename = [[presenter->_url path] UTF8String];
- _choice = Common::FSNode(filename);
- choiceMade = true;
+ choice = Common::FSNode(filename);
+ result = kDialogOk;
}
[presenter release];
[pool release];
[keyWindow makeKeyAndOrderFront:nil];
+ CFRelease(titleRef);
+ CFRelease(chooseRef);
+
// While the native macOS file browser is open, any input events (e.g. keypresses) are
// still received by the NSApplication. With SDL backend for example this results in the
// events beeing queued and processed after we return, thus dispatching events that were
@@ -209,7 +200,7 @@ int BrowserDialog::runModal() {
g_system->endGFXTransaction();
}
- return choiceMade;
+ return result;
}
-} // End of namespace GUI
+#endif