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