diff options
-rw-r--r-- | gui/browser.cpp | 78 | ||||
-rw-r--r-- | gui/browser.h | 15 |
2 files changed, 93 insertions, 0 deletions
diff --git a/gui/browser.cpp b/gui/browser.cpp index c54e9caeca..baa4088b47 100644 --- a/gui/browser.cpp +++ b/gui/browser.cpp @@ -27,6 +27,82 @@ namespace GUI { +#ifdef MACOSX +/* On Mac OS X, use the native file selector dialog. We could do the same for + * other operating systems. + */ + +BrowserDialog::BrowserDialog(const char *title) + : Dialog(20, 10, 320 -2 * 20, 200 - 2 * 10) { + _choice = NULL; + _titleRef = CFStringCreateWithCString(0, title, CFStringGetSystemEncoding()); +} + +BrowserDialog::~BrowserDialog() { + delete _choice; + CFRelease(_titleRef); +} + +int BrowserDialog::runModal() { + NavDialogRef dialogRef; + NavDialogCreationOptions options; + NavUserAction result; + NavReplyRecord reply; + OSStatus err; + + delete _choice; + _choice = 0; + + // Temporarily show the real mouse + ShowCursor(); + + err = NavGetDefaultDialogCreationOptions(&options); + assert(err == noErr); + options.windowTitle = _titleRef; + options.message = CFSTR("This is a test!"); + options.modality = kWindowModalityAppModal; + + err = NavCreateChooseFolderDialog(&options, 0, 0, 0, &dialogRef); + assert(err == noErr); + + err = NavDialogRun(dialogRef); + assert(err == noErr); + + HideCursor(); + + result = NavDialogGetUserAction(dialogRef); + + if (result == kNavUserActionChoose) { + err = NavDialogGetReply(dialogRef, &reply); + assert(err == noErr); + + if (reply.validRecord && err == noErr) { + SInt32 theCount; + AECountItems(&reply.selection, &theCount); + assert(theCount == 1); + + AEKeyword keyword; + FSRef ref; + char buf[4096]; + err = AEGetNthPtr(&reply.selection, 1, typeFSRef, &keyword, NULL, &ref, sizeof(ref), NULL); + assert(err == noErr); + err = FSRefMakePath(&ref, (UInt8*)buf, sizeof(buf)-1); + assert(err == noErr); + + _choice = FilesystemNode::getNodeForPath(buf); + } + + err = NavDisposeReply(&reply); + assert(err == noErr); + } + + NavDialogDispose(dialogRef); + + return (_choice != 0); +} + +#else + /* We want to use this as a general directory selector at some point... possible uses * - to select the data dir for a game * - to select the place where save games are stored @@ -157,4 +233,6 @@ void BrowserDialog::updateListing() { draw(); } +#endif // MACOSX + } // End of namespace GUI diff --git a/gui/browser.h b/gui/browser.h index be7f0ee3d6..a6dd191764 100644 --- a/gui/browser.h +++ b/gui/browser.h @@ -25,6 +25,10 @@ #include "common/str.h" #include "common/list.h" +#ifdef MACOSX +#include <Carbon/Carbon.h> +#endif + class FilesystemNode; class FSList; @@ -40,20 +44,31 @@ public: BrowserDialog(const char *title); virtual ~BrowserDialog(); +#ifdef MACOSX + virtual int runModal(); +#else virtual void open(); virtual void close(); virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); +#endif FilesystemNode *getResult() { return _choice; }; + protected: +#ifdef MACOSX + CFStringRef _titleRef; +#else ListWidget *_fileList; StaticTextWidget*_currentPath; FilesystemNode *_node; FSList *_nodeContent; +#endif FilesystemNode *_choice; +#ifndef MACOSX void updateListing(); +#endif }; } // End of namespace GUI |