]>
Commit | Line | Data |
---|---|---|
2646f485 | 1 | ///////////////////////////////////////////////////////////////////////////// |
18f3decb | 2 | // Name: src/mac/classic/dirdlg.cpp |
2646f485 SC |
3 | // Purpose: wxDirDialog |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
18f3decb | 9 | // Licence: wxWindows licence |
2646f485 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
18f3decb WS |
12 | #include "wx/wxprec.h" |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
2646f485 SC |
18 | #include "wx/dirdlg.h" |
19 | ||
de6185e2 WS |
20 | #ifndef WX_PRECOMP |
21 | #include "wx/utils.h" | |
22 | #endif // WX_PRECOMP | |
23 | ||
24 | #include "wx/dialog.h" | |
25 | ||
2646f485 SC |
26 | #include "wx/cmndata.h" |
27 | ||
28 | #include "wx/mac/private.h" | |
29 | ||
30 | #ifdef __DARWIN__ | |
31 | #include <Carbon/Carbon.h> | |
32 | #else | |
33 | #include <Navigation.h> | |
34 | #endif | |
35 | ||
2646f485 | 36 | IMPLEMENT_CLASS(wxDirDialog, wxDialog) |
2646f485 SC |
37 | |
38 | wxDirDialog::wxDirDialog(wxWindow *parent, | |
39 | const wxString& message, | |
40 | const wxString& defaultPath, | |
41 | long style, | |
42 | const wxPoint& WXUNUSED(pos), | |
43 | const wxSize& WXUNUSED(size), | |
44 | const wxString& WXUNUSED(name)) | |
45 | { | |
46 | wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ; | |
47 | m_message = message; | |
48 | m_dialogStyle = style; | |
49 | m_parent = parent; | |
50 | m_path = defaultPath; | |
51 | } | |
52 | ||
53 | int wxDirDialog::ShowModal() | |
54 | { | |
55 | NavDialogOptions mNavOptions; | |
56 | NavObjectFilterUPP mNavFilterUPP = NULL; | |
57 | NavPreviewUPP mNavPreviewUPP = NULL ; | |
58 | NavReplyRecord mNavReply; | |
59 | AEDesc* mDefaultLocation = NULL ; | |
60 | bool mSelectDefault = false ; | |
18f3decb | 61 | |
2646f485 SC |
62 | ::NavGetDefaultDialogOptions(&mNavOptions); |
63 | ||
64 | mNavFilterUPP = nil; | |
65 | mNavPreviewUPP = nil; | |
66 | mSelectDefault = false; | |
67 | mNavReply.validRecord = false; | |
68 | mNavReply.replacing = false; | |
69 | mNavReply.isStationery = false; | |
70 | mNavReply.translationNeeded = false; | |
71 | mNavReply.selection.descriptorType = typeNull; | |
72 | mNavReply.selection.dataHandle = nil; | |
73 | mNavReply.keyScript = smSystemScript; | |
74 | mNavReply.fileTranslation = nil; | |
18f3decb | 75 | |
2646f485 SC |
76 | // Set default location, the location |
77 | // that's displayed when the dialog | |
78 | // first appears | |
18f3decb | 79 | |
2646f485 | 80 | if ( mDefaultLocation ) { |
18f3decb | 81 | |
2646f485 SC |
82 | if (mSelectDefault) { |
83 | mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation; | |
84 | } else { | |
85 | mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation; | |
86 | } | |
87 | } | |
18f3decb | 88 | |
2646f485 SC |
89 | OSErr err = ::NavChooseFolder( |
90 | mDefaultLocation, | |
91 | &mNavReply, | |
92 | &mNavOptions, | |
93 | NULL, | |
94 | mNavFilterUPP, | |
95 | 0L); // User Data | |
18f3decb | 96 | |
2646f485 | 97 | if ( (err != noErr) && (err != userCanceledErr) ) { |
18f3decb | 98 | m_path = wxEmptyString ; |
2646f485 SC |
99 | return wxID_CANCEL ; |
100 | } | |
101 | ||
102 | if (mNavReply.validRecord) { // User chose a folder | |
18f3decb | 103 | |
2646f485 SC |
104 | FSSpec folderInfo; |
105 | FSSpec outFileSpec ; | |
106 | AEDesc specDesc ; | |
18f3decb | 107 | |
2646f485 SC |
108 | OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSS, &specDesc); |
109 | if ( err != noErr ) { | |
18f3decb | 110 | m_path = wxEmptyString ; |
2646f485 | 111 | return wxID_CANCEL ; |
18f3decb | 112 | } |
2646f485 SC |
113 | folderInfo = **(FSSpec**) specDesc.dataHandle; |
114 | if (specDesc.dataHandle != nil) { | |
115 | ::AEDisposeDesc(&specDesc); | |
116 | } | |
117 | ||
118 | // mNavReply.GetFileSpec(folderInfo); | |
18f3decb | 119 | |
2646f485 SC |
120 | // The FSSpec from NavChooseFolder is NOT the file spec |
121 | // for the folder. The parID field is actually the DirID | |
122 | // of the folder itself, not the folder's parent, and | |
123 | // the name field is empty. We must call PBGetCatInfo | |
124 | // to get the parent DirID and folder name | |
18f3decb | 125 | |
2646f485 SC |
126 | Str255 name; |
127 | CInfoPBRec thePB; // Directory Info Parameter Block | |
128 | thePB.dirInfo.ioCompletion = nil; | |
129 | thePB.dirInfo.ioVRefNum = folderInfo.vRefNum; // Volume is right | |
130 | thePB.dirInfo.ioDrDirID = folderInfo.parID; // Folder's DirID | |
131 | thePB.dirInfo.ioNamePtr = name; | |
132 | thePB.dirInfo.ioFDirIndex = -1; // Lookup using Volume and DirID | |
18f3decb | 133 | |
2646f485 SC |
134 | err = ::PBGetCatInfoSync(&thePB); |
135 | if ( err != noErr ) { | |
18f3decb | 136 | m_path = wxEmptyString; |
2646f485 | 137 | return wxID_CANCEL ; |
18f3decb | 138 | } |
2646f485 SC |
139 | // Create cannonical FSSpec |
140 | ::FSMakeFSSpec(thePB.dirInfo.ioVRefNum, thePB.dirInfo.ioDrParID, | |
141 | name, &outFileSpec); | |
18f3decb | 142 | |
2646f485 SC |
143 | // outFolderDirID = thePB.dirInfo.ioDrDirID; |
144 | m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ; | |
145 | return wxID_OK ; | |
146 | } | |
147 | return wxID_CANCEL; | |
148 | } |