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
,
36 const wxString
& message
,
37 const wxString
& defaultPath
,
39 const wxPoint
& WXUNUSED(pos
),
40 const wxSize
& WXUNUSED(size
),
41 const wxString
& WXUNUSED(name
))
43 wxASSERT_MSG( NavServicesAvailable() , "Navigation Services are not running" ) ;
45 m_dialogStyle
= style
;
50 int wxDirDialog::ShowModal()
52 NavDialogOptions mNavOptions
;
53 NavObjectFilterUPP mNavFilterUPP
= NULL
;
54 NavPreviewUPP mNavPreviewUPP
= NULL
;
55 NavReplyRecord mNavReply
;
56 AEDesc
* mDefaultLocation
= NULL
;
57 bool mSelectDefault
= false ;
59 ::NavGetDefaultDialogOptions(&mNavOptions
);
63 mSelectDefault
= false;
64 mNavReply
.validRecord
= false;
65 mNavReply
.replacing
= false;
66 mNavReply
.isStationery
= false;
67 mNavReply
.translationNeeded
= false;
68 mNavReply
.selection
.descriptorType
= typeNull
;
69 mNavReply
.selection
.dataHandle
= nil
;
70 mNavReply
.keyScript
= smSystemScript
;
71 mNavReply
.fileTranslation
= nil
;
73 // Set default location, the location
74 // that's displayed when the dialog
77 if ( mDefaultLocation
) {
80 mNavOptions
.dialogOptionFlags
|= kNavSelectDefaultLocation
;
82 mNavOptions
.dialogOptionFlags
&= ~kNavSelectDefaultLocation
;
86 OSErr err
= ::NavChooseFolder(
94 if ( (err
!= noErr
) && (err
!= userCanceledErr
) ) {
99 if (mNavReply
.validRecord
) { // User chose a folder
105 OSErr err
= ::AECoerceDesc( &mNavReply
.selection
, typeFSS
, &specDesc
);
106 if ( err
!= noErr
) {
110 folderInfo
= **(FSSpec
**) specDesc
.dataHandle
;
111 if (specDesc
.dataHandle
!= nil
) {
112 ::AEDisposeDesc(&specDesc
);
115 // mNavReply.GetFileSpec(folderInfo);
117 // The FSSpec from NavChooseFolder is NOT the file spec
118 // for the folder. The parID field is actually the DirID
119 // of the folder itself, not the folder's parent, and
120 // the name field is empty. We must call PBGetCatInfo
121 // to get the parent DirID and folder name
124 CInfoPBRec thePB
; // Directory Info Parameter Block
125 thePB
.dirInfo
.ioCompletion
= nil
;
126 thePB
.dirInfo
.ioVRefNum
= folderInfo
.vRefNum
; // Volume is right
127 thePB
.dirInfo
.ioDrDirID
= folderInfo
.parID
; // Folder's DirID
128 thePB
.dirInfo
.ioNamePtr
= name
;
129 thePB
.dirInfo
.ioFDirIndex
= -1; // Lookup using Volume and DirID
131 err
= ::PBGetCatInfoSync(&thePB
);
132 if ( err
!= noErr
) {
136 // Create cannonical FSSpec
137 ::FSMakeFSSpec(thePB
.dirInfo
.ioVRefNum
, thePB
.dirInfo
.ioDrParID
,
140 // outFolderDirID = thePB.dirInfo.ioDrDirID;
141 m_path
= wxMacFSSpec2MacFilename( &outFileSpec
) ;