1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDirDialog
8 // Copyright: (c) AUTHOR
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 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
35 wxDirDialog::wxDirDialog(wxWindow
*parent
, const wxString
& message
,
36 const wxString
& defaultPath
,
37 long style
, const wxPoint
& pos
)
39 wxASSERT_MSG( NavServicesAvailable() , "Navigation Services are not running" ) ;
41 m_dialogStyle
= style
;
46 int wxDirDialog::ShowModal()
48 NavDialogOptions mNavOptions
;
49 NavObjectFilterUPP mNavFilterUPP
= NULL
;
50 NavPreviewUPP mNavPreviewUPP
= NULL
;
51 NavReplyRecord mNavReply
;
52 AEDesc
* mDefaultLocation
= NULL
;
53 bool mSelectDefault
= false ;
55 ::NavGetDefaultDialogOptions(&mNavOptions
);
59 mSelectDefault
= false;
60 mNavReply
.validRecord
= false;
61 mNavReply
.replacing
= false;
62 mNavReply
.isStationery
= false;
63 mNavReply
.translationNeeded
= false;
64 mNavReply
.selection
.descriptorType
= typeNull
;
65 mNavReply
.selection
.dataHandle
= nil
;
66 mNavReply
.keyScript
= smSystemScript
;
67 mNavReply
.fileTranslation
= nil
;
69 // Set default location, the location
70 // that's displayed when the dialog
73 if ( mDefaultLocation
) {
76 mNavOptions
.dialogOptionFlags
|= kNavSelectDefaultLocation
;
78 mNavOptions
.dialogOptionFlags
&= ~kNavSelectDefaultLocation
;
82 OSErr err
= ::NavChooseFolder(
90 if ( (err
!= noErr
) && (err
!= userCanceledErr
) ) {
95 if (mNavReply
.validRecord
) { // User chose a folder
101 OSErr err
= ::AECoerceDesc( &mNavReply
.selection
, typeFSS
, &specDesc
);
102 if ( err
!= noErr
) {
106 folderInfo
= **(FSSpec
**) specDesc
.dataHandle
;
107 if (specDesc
.dataHandle
!= nil
) {
108 ::AEDisposeDesc(&specDesc
);
111 // mNavReply.GetFileSpec(folderInfo);
113 // The FSSpec from NavChooseFolder is NOT the file spec
114 // for the folder. The parID field is actually the DirID
115 // of the folder itself, not the folder's parent, and
116 // the name field is empty. We must call PBGetCatInfo
117 // to get the parent DirID and folder name
120 CInfoPBRec thePB
; // Directory Info Parameter Block
121 thePB
.dirInfo
.ioCompletion
= nil
;
122 thePB
.dirInfo
.ioVRefNum
= folderInfo
.vRefNum
; // Volume is right
123 thePB
.dirInfo
.ioDrDirID
= folderInfo
.parID
; // Folder's DirID
124 thePB
.dirInfo
.ioNamePtr
= name
;
125 thePB
.dirInfo
.ioFDirIndex
= -1; // Lookup using Volume and DirID
127 err
= ::PBGetCatInfoSync(&thePB
);
128 if ( err
!= noErr
) {
132 // Create cannonical FSSpec
133 ::FSMakeFSSpec(thePB
.dirInfo
.ioVRefNum
, thePB
.dirInfo
.ioDrParID
,
136 // outFolderDirID = thePB.dirInfo.ioDrDirID;
137 m_path
= wxMacFSSpec2MacFilename( &outFileSpec
) ;