]>
Commit | Line | Data |
---|---|---|
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 | #include "wx/wxprec.h" | |
13 | ||
14 | #if wxUSE_DIRDLG | |
15 | ||
16 | #include "wx/utils.h" | |
17 | #include "wx/dialog.h" | |
18 | #include "wx/dirdlg.h" | |
19 | ||
20 | #include "wx/cmndata.h" | |
21 | ||
22 | #include "wx/mac/private.h" | |
23 | ||
24 | #ifdef __DARWIN__ | |
25 | #include <Carbon/Carbon.h> | |
26 | #else | |
27 | #include <Navigation.h> | |
28 | #endif | |
29 | ||
30 | IMPLEMENT_CLASS(wxDirDialog, wxDialog) | |
31 | ||
32 | wxDirDialog::wxDirDialog(wxWindow *parent, | |
33 | const wxString& message, | |
34 | const wxString& defaultPath, | |
35 | long style, | |
36 | const wxPoint& WXUNUSED(pos), | |
37 | const wxSize& WXUNUSED(size), | |
38 | const wxString& WXUNUSED(name)) | |
39 | { | |
40 | wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ; | |
41 | m_message = message; | |
42 | m_dialogStyle = style; | |
43 | m_parent = parent; | |
44 | m_path = defaultPath; | |
45 | } | |
46 | ||
47 | int wxDirDialog::ShowModal() | |
48 | { | |
49 | NavDialogRef dialog; | |
50 | NavDialogCreationOptions options; | |
51 | NavReplyRecord reply ; | |
52 | bool disposeReply = false ; | |
53 | OSStatus err = noErr; | |
54 | ||
55 | err = NavGetDefaultDialogCreationOptions(&options); | |
56 | if (err == noErr) | |
57 | { | |
58 | wxMacCFStringHolder message(m_message, m_font.GetEncoding()); | |
59 | options.message = message; | |
60 | err = NavCreateChooseFolderDialog(&options, NULL, NULL, NULL, &dialog); | |
61 | if (err == noErr) | |
62 | { | |
63 | err = NavDialogRun(dialog); | |
64 | if ( err == noErr ) | |
65 | { | |
66 | err = NavDialogGetReply(dialog, &reply); | |
67 | disposeReply = true ; | |
68 | } | |
69 | } | |
70 | } | |
71 | ||
72 | if ( err == noErr ) | |
73 | { | |
74 | if ( reply.validRecord ) | |
75 | { | |
76 | FSRef folderInfo; | |
77 | AEDesc specDesc ; | |
78 | ||
79 | OSErr err = ::AECoerceDesc( &reply.selection , typeFSRef, &specDesc); | |
80 | if ( err != noErr ) | |
81 | { | |
82 | m_path = wxEmptyString ; | |
83 | } | |
84 | else | |
85 | { | |
86 | folderInfo = **(FSRef**) specDesc.dataHandle; | |
87 | m_path = wxMacFSRefToPath( &folderInfo ) ; | |
88 | if (specDesc.dataHandle != nil) | |
89 | { | |
90 | ::AEDisposeDesc(&specDesc); | |
91 | } | |
92 | } | |
93 | } | |
94 | else | |
95 | { | |
96 | err = paramErr ; // could be any error, only used for giving back wxID_CANCEL | |
97 | } | |
98 | } | |
99 | ||
100 | if ( disposeReply ) | |
101 | ::NavDisposeReply(&reply); | |
102 | ||
103 | // apparently cancelling shouldn't change m_path | |
104 | if ( err != noErr && err != userCanceledErr ) | |
105 | m_path = wxEmptyString ; | |
106 | ||
107 | return (err == noErr) ? wxID_OK : wxID_CANCEL ; | |
108 | } | |
109 | ||
110 | #endif |