[Scummvm-cvs-logs] CVS: scummvm/gui browser.cpp,1.17,1.18 browser.h,1.11,1.12

Max Horn fingolfin at users.sourceforge.net
Sat Jan 31 18:05:09 CET 2004


Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5082

Modified Files:
	browser.cpp browser.h 
Log Message:
native directory browser on Mac OS X

Index: browser.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/browser.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- browser.cpp	6 Jan 2004 12:45:28 -0000	1.17
+++ browser.cpp	1 Feb 2004 02:03:01 -0000	1.18
@@ -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 @@
 	draw();
 }
 
+#endif	// MACOSX
+
 } // End of namespace GUI

Index: browser.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/browser.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- browser.h	6 Jan 2004 12:45:28 -0000	1.11
+++ browser.h	1 Feb 2004 02:03:01 -0000	1.12
@@ -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 @@
 	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





More information about the Scummvm-git-logs mailing list