Include wx/utils.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / mac / classic / dirdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/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 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #include "wx/dirdlg.h"
19
20 #ifndef WX_PRECOMP
21 #include "wx/utils.h"
22 #endif // WX_PRECOMP
23
24 #include "wx/dialog.h"
25
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
36 IMPLEMENT_CLASS(wxDirDialog, wxDialog)
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 ;
61
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;
75
76 // Set default location, the location
77 // that's displayed when the dialog
78 // first appears
79
80 if ( mDefaultLocation ) {
81
82 if (mSelectDefault) {
83 mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
84 } else {
85 mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
86 }
87 }
88
89 OSErr err = ::NavChooseFolder(
90 mDefaultLocation,
91 &mNavReply,
92 &mNavOptions,
93 NULL,
94 mNavFilterUPP,
95 0L); // User Data
96
97 if ( (err != noErr) && (err != userCanceledErr) ) {
98 m_path = wxEmptyString ;
99 return wxID_CANCEL ;
100 }
101
102 if (mNavReply.validRecord) { // User chose a folder
103
104 FSSpec folderInfo;
105 FSSpec outFileSpec ;
106 AEDesc specDesc ;
107
108 OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSS, &specDesc);
109 if ( err != noErr ) {
110 m_path = wxEmptyString ;
111 return wxID_CANCEL ;
112 }
113 folderInfo = **(FSSpec**) specDesc.dataHandle;
114 if (specDesc.dataHandle != nil) {
115 ::AEDisposeDesc(&specDesc);
116 }
117
118 // mNavReply.GetFileSpec(folderInfo);
119
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
125
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
133
134 err = ::PBGetCatInfoSync(&thePB);
135 if ( err != noErr ) {
136 m_path = wxEmptyString;
137 return wxID_CANCEL ;
138 }
139 // Create cannonical FSSpec
140 ::FSMakeFSSpec(thePB.dirInfo.ioVRefNum, thePB.dirInfo.ioDrParID,
141 name, &outFileSpec);
142
143 // outFolderDirID = thePB.dirInfo.ioDrDirID;
144 m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ;
145 return wxID_OK ;
146 }
147 return wxID_CANCEL;
148 }