1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDirDialog
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dirdlg.h"
18 #include "wx/dialog.h"
19 #include "wx/dirdlg.h"
21 #include "wx/cmndata.h"
23 #include "wx/mac/private.h"
26 #include <Carbon/Carbon.h>
28 #include <Navigation.h>
31 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
33 wxDirDialog::wxDirDialog(wxWindow
*parent
,
34 const wxString
& message
,
35 const wxString
& defaultPath
,
37 const wxPoint
& WXUNUSED(pos
),
38 const wxSize
& WXUNUSED(size
),
39 const wxString
& WXUNUSED(name
))
41 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
43 m_dialogStyle
= style
;
48 int wxDirDialog::ShowModal()
50 NavDialogOptions mNavOptions
;
51 NavObjectFilterUPP mNavFilterUPP
= NULL
;
52 NavPreviewUPP mNavPreviewUPP
= NULL
;
53 NavReplyRecord mNavReply
;
54 AEDesc
* mDefaultLocation
= NULL
;
55 bool mSelectDefault
= false ;
57 ::NavGetDefaultDialogOptions(&mNavOptions
);
61 mSelectDefault
= false;
62 mNavReply
.validRecord
= false;
63 mNavReply
.replacing
= false;
64 mNavReply
.isStationery
= false;
65 mNavReply
.translationNeeded
= false;
66 mNavReply
.selection
.descriptorType
= typeNull
;
67 mNavReply
.selection
.dataHandle
= nil
;
68 mNavReply
.keyScript
= smSystemScript
;
69 mNavReply
.fileTranslation
= nil
;
71 // Set default location, the location
72 // that's displayed when the dialog
75 if ( mDefaultLocation
) {
78 mNavOptions
.dialogOptionFlags
|= kNavSelectDefaultLocation
;
80 mNavOptions
.dialogOptionFlags
&= ~kNavSelectDefaultLocation
;
84 OSErr err
= ::NavChooseFolder(
92 if ( (err
!= noErr
) && (err
!= userCanceledErr
) ) {
97 if (mNavReply
.validRecord
) { // User chose a folder
103 OSErr err
= ::AECoerceDesc( &mNavReply
.selection
, typeFSS
, &specDesc
);
104 if ( err
!= noErr
) {
108 folderInfo
= **(FSSpec
**) specDesc
.dataHandle
;
109 if (specDesc
.dataHandle
!= nil
) {
110 ::AEDisposeDesc(&specDesc
);
113 // mNavReply.GetFileSpec(folderInfo);
115 // The FSSpec from NavChooseFolder is NOT the file spec
116 // for the folder. The parID field is actually the DirID
117 // of the folder itself, not the folder's parent, and
118 // the name field is empty. We must call PBGetCatInfo
119 // to get the parent DirID and folder name
122 CInfoPBRec thePB
; // Directory Info Parameter Block
123 thePB
.dirInfo
.ioCompletion
= nil
;
124 thePB
.dirInfo
.ioVRefNum
= folderInfo
.vRefNum
; // Volume is right
125 thePB
.dirInfo
.ioDrDirID
= folderInfo
.parID
; // Folder's DirID
126 thePB
.dirInfo
.ioNamePtr
= name
;
127 thePB
.dirInfo
.ioFDirIndex
= -1; // Lookup using Volume and DirID
129 err
= ::PBGetCatInfoSync(&thePB
);
130 if ( err
!= noErr
) {
134 // Create cannonical FSSpec
135 ::FSMakeFSSpec(thePB
.dirInfo
.ioVRefNum
, thePB
.dirInfo
.ioDrParID
,
138 // outFolderDirID = thePB.dirInfo.ioDrDirID;
139 m_path
= wxMacFSSpec2MacFilename( &outFileSpec
) ;