]>
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 | NavDialogOptions mNavOptions; | |
54 | NavObjectFilterUPP mNavFilterUPP = NULL; | |
55 | NavReplyRecord mNavReply; | |
56 | ||
57 | ::NavGetDefaultDialogOptions(&mNavOptions); | |
58 | ||
59 | mNavReply.validRecord = false; | |
60 | mNavReply.replacing = false; | |
61 | mNavReply.isStationery = false; | |
62 | mNavReply.translationNeeded = false; | |
63 | mNavReply.selection.descriptorType = typeNull; | |
64 | mNavReply.selection.dataHandle = nil; | |
65 | mNavReply.keyScript = smSystemScript; | |
66 | mNavReply.fileTranslation = nil; | |
67 | ||
68 | // Set default location, the location | |
69 | // that's displayed when the dialog | |
70 | // first appears | |
71 | ||
72 | OSErr err = ::NavChooseFolder( | |
73 | NULL, | |
74 | &mNavReply, | |
75 | &mNavOptions, | |
76 | NULL, | |
77 | mNavFilterUPP, | |
78 | 0L); // User Data | |
79 | ||
80 | if ( (err != noErr) && (err != userCanceledErr) ) { | |
81 | m_path = wxEmptyString ; | |
82 | return wxID_CANCEL ; | |
83 | } | |
84 | ||
85 | if (mNavReply.validRecord) { // User chose a folder | |
86 | ||
87 | FSRef folderInfo; | |
88 | AEDesc specDesc ; | |
89 | ||
90 | OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSRef, &specDesc); | |
91 | if ( err != noErr ) { | |
92 | m_path = wxEmptyString ; | |
93 | return wxID_CANCEL ; | |
94 | } | |
95 | folderInfo = **(FSRef**) specDesc.dataHandle; | |
96 | if (specDesc.dataHandle != nil) { | |
97 | ::AEDisposeDesc(&specDesc); | |
98 | } | |
99 | ||
100 | m_path = wxMacFSRefToPath( &folderInfo ) ; | |
101 | return wxID_OK ; | |
102 | } | |
103 | return wxID_CANCEL; | |
104 | } | |
105 | ||
106 | #endif |