]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dirdlg.cpp | |
3 | // Purpose: wxDirDialog | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
e9576ca5 SC |
13 | #pragma implementation "dirdlg.h" |
14 | #endif | |
15 | ||
3d1a4878 SC |
16 | #include "wx/wxprec.h" |
17 | ||
e9576ca5 SC |
18 | #include "wx/utils.h" |
19 | #include "wx/dialog.h" | |
20 | #include "wx/dirdlg.h" | |
21 | ||
22 | #include "wx/cmndata.h" | |
23 | ||
76a5e5d2 SC |
24 | #include "wx/mac/private.h" |
25 | ||
f5c6eb5c | 26 | #ifdef __DARWIN__ |
5fde6fcc | 27 | #include <Carbon/Carbon.h> |
03e11df5 GD |
28 | #else |
29 | #include <Navigation.h> | |
30 | #endif | |
5b781a67 | 31 | |
2f1ae414 | 32 | #if !USE_SHARED_LIBRARY |
e9576ca5 | 33 | IMPLEMENT_CLASS(wxDirDialog, wxDialog) |
2f1ae414 | 34 | #endif |
519cb848 | 35 | |
e78d4a23 VZ |
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)) | |
e9576ca5 | 43 | { |
427ff662 | 44 | wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ; |
e9576ca5 SC |
45 | m_message = message; |
46 | m_dialogStyle = style; | |
47 | m_parent = parent; | |
e40298d5 | 48 | m_path = defaultPath; |
e9576ca5 SC |
49 | } |
50 | ||
51 | int wxDirDialog::ShowModal() | |
52 | { | |
e40298d5 JS |
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); | |
76a5e5d2 | 61 | |
e40298d5 JS |
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) ) { | |
427ff662 | 96 | m_path = wxT("") ; |
e40298d5 JS |
97 | return wxID_CANCEL ; |
98 | } | |
5b781a67 | 99 | |
e40298d5 JS |
100 | if (mNavReply.validRecord) { // User chose a folder |
101 | ||
a2b77260 | 102 | FSRef folderInfo; |
e40298d5 JS |
103 | AEDesc specDesc ; |
104 | ||
a2b77260 | 105 | OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSRef, &specDesc); |
e40298d5 | 106 | if ( err != noErr ) { |
427ff662 | 107 | m_path = wxT("") ; |
e40298d5 JS |
108 | return wxID_CANCEL ; |
109 | } | |
a2b77260 | 110 | folderInfo = **(FSRef**) specDesc.dataHandle; |
e40298d5 JS |
111 | if (specDesc.dataHandle != nil) { |
112 | ::AEDisposeDesc(&specDesc); | |
113 | } | |
76a5e5d2 | 114 | |
a2b77260 | 115 | m_path = wxMacFSRefToPath( &folderInfo ) ; |
e40298d5 JS |
116 | return wxID_OK ; |
117 | } | |
118 | return wxID_CANCEL; | |
e9576ca5 SC |
119 | } |
120 |