]>
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 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
13 | #pragma implementation "dirdlg.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/wxprec.h" | |
17 | ||
18 | #if wxUSE_DIRDLG | |
19 | ||
20 | #include "wx/utils.h" | |
21 | #include "wx/dialog.h" | |
22 | #include "wx/dirdlg.h" | |
23 | ||
24 | #include "wx/cmndata.h" | |
25 | ||
26 | #include "wx/mac/private.h" | |
27 | ||
28 | #ifdef __DARWIN__ | |
29 | #include <Carbon/Carbon.h> | |
30 | #else | |
31 | #include <Navigation.h> | |
32 | #endif | |
33 | ||
34 | IMPLEMENT_CLASS(wxDirDialog, wxDialog) | |
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 | NavDialogRef dialog; | |
54 | NavDialogCreationOptions options; | |
55 | NavReplyRecord reply ; | |
56 | bool disposeReply = false ; | |
57 | OSStatus err = noErr; | |
58 | ||
59 | err = NavGetDefaultDialogCreationOptions(&options); | |
60 | if (err == noErr) | |
61 | { | |
62 | wxMacCFStringHolder message(m_message, m_font.GetEncoding()); | |
63 | options.message = message; | |
64 | err = NavCreateChooseFolderDialog(&options, NULL, NULL, NULL, &dialog); | |
65 | if (err == noErr) | |
66 | { | |
67 | err = NavDialogRun(dialog); | |
68 | if ( err == noErr ) | |
69 | { | |
70 | err = NavDialogGetReply(dialog, &reply); | |
71 | disposeReply = true ; | |
72 | } | |
73 | } | |
74 | } | |
75 | ||
76 | if ( err == noErr ) | |
77 | { | |
78 | if ( reply.validRecord ) | |
79 | { | |
80 | FSRef folderInfo; | |
81 | AEDesc specDesc ; | |
82 | ||
83 | OSErr err = ::AECoerceDesc( &reply.selection , typeFSRef, &specDesc); | |
84 | if ( err != noErr ) | |
85 | { | |
86 | m_path = wxEmptyString ; | |
87 | } | |
88 | else | |
89 | { | |
90 | folderInfo = **(FSRef**) specDesc.dataHandle; | |
91 | m_path = wxMacFSRefToPath( &folderInfo ) ; | |
92 | if (specDesc.dataHandle != nil) | |
93 | { | |
94 | ::AEDisposeDesc(&specDesc); | |
95 | } | |
96 | } | |
97 | } | |
98 | else | |
99 | { | |
100 | err = paramErr ; // could be any error, only used for giving back wxID_CANCEL | |
101 | } | |
102 | } | |
103 | ||
104 | if ( disposeReply ) | |
105 | ::NavDisposeReply(&reply); | |
106 | ||
107 | // apparently cancelling shouldn't change m_path | |
108 | if ( err != noErr && err != userCanceledErr ) | |
109 | m_path = wxEmptyString ; | |
110 | ||
111 | return (err == noErr) ? wxID_OK : wxID_CANCEL ; | |
112 | } | |
113 | ||
114 | #endif |