]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dirdlg.cpp
Applied [ 1059554 ] patch for [1028659] fixes a couple of bugs with menus
[wxWidgets.git] / src / mac / carbon / dirdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dirdlg.cpp
3 // Purpose: wxDirDialog
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "dirdlg.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #include "wx/utils.h"
19 #include "wx/dialog.h"
20 #include "wx/dirdlg.h"
21
22 #include "wx/cmndata.h"
23
24 #include "wx/mac/private.h"
25
26 #ifdef __DARWIN__
27 #include <Carbon/Carbon.h>
28 #else
29 #include <Navigation.h>
30 #endif
31
32 #if !USE_SHARED_LIBRARY
33 IMPLEMENT_CLASS(wxDirDialog, wxDialog)
34 #endif
35
36 wxDirDialog::wxDirDialog(wxWindow *parent,
37 const wxString& message,
38 const wxString& defaultPath,
39 long style,
40 const wxPoint& WXUNUSED(pos),
41 const wxSize& WXUNUSED(size),
42 const wxString& WXUNUSED(name))
43 {
44 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
45 m_message = message;
46 m_dialogStyle = style;
47 m_parent = parent;
48 m_path = defaultPath;
49 }
50
51 int wxDirDialog::ShowModal()
52 {
53 NavDialogOptions mNavOptions;
54 NavObjectFilterUPP mNavFilterUPP = NULL;
55 NavPreviewUPP mNavPreviewUPP = NULL ;
56 NavReplyRecord mNavReply;
57 AEDesc* mDefaultLocation = NULL ;
58 bool mSelectDefault = false ;
59
60 ::NavGetDefaultDialogOptions(&mNavOptions);
61
62 mNavFilterUPP = nil;
63 mNavPreviewUPP = nil;
64 mSelectDefault = false;
65 mNavReply.validRecord = false;
66 mNavReply.replacing = false;
67 mNavReply.isStationery = false;
68 mNavReply.translationNeeded = false;
69 mNavReply.selection.descriptorType = typeNull;
70 mNavReply.selection.dataHandle = nil;
71 mNavReply.keyScript = smSystemScript;
72 mNavReply.fileTranslation = nil;
73
74 // Set default location, the location
75 // that's displayed when the dialog
76 // first appears
77
78 if ( mDefaultLocation ) {
79
80 if (mSelectDefault) {
81 mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
82 } else {
83 mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
84 }
85 }
86
87 OSErr err = ::NavChooseFolder(
88 mDefaultLocation,
89 &mNavReply,
90 &mNavOptions,
91 NULL,
92 mNavFilterUPP,
93 0L); // User Data
94
95 if ( (err != noErr) && (err != userCanceledErr) ) {
96 m_path = wxT("") ;
97 return wxID_CANCEL ;
98 }
99
100 if (mNavReply.validRecord) { // User chose a folder
101
102 FSRef folderInfo;
103 AEDesc specDesc ;
104
105 OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSRef, &specDesc);
106 if ( err != noErr ) {
107 m_path = wxT("") ;
108 return wxID_CANCEL ;
109 }
110 folderInfo = **(FSRef**) specDesc.dataHandle;
111 if (specDesc.dataHandle != nil) {
112 ::AEDisposeDesc(&specDesc);
113 }
114
115 m_path = wxMacFSRefToPath( &folderInfo ) ;
116 return wxID_OK ;
117 }
118 return wxID_CANCEL;
119 }
120