1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDirDialog
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
14 #include "wx/dialog.h"
15 #include "wx/dirdlg.h"
17 #include "wx/cmndata.h"
19 #include "wx/mac/private.h"
22 #include <Carbon/Carbon.h>
24 #include <Navigation.h>
27 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
29 wxDirDialog::wxDirDialog(wxWindow
*parent
,
30 const wxString
& message
,
31 const wxString
& defaultPath
,
33 const wxPoint
& WXUNUSED(pos
),
34 const wxSize
& WXUNUSED(size
),
35 const wxString
& WXUNUSED(name
))
37 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
39 m_dialogStyle
= style
;
44 int wxDirDialog::ShowModal()
46 NavDialogOptions mNavOptions
;
47 NavObjectFilterUPP mNavFilterUPP
= NULL
;
48 NavPreviewUPP mNavPreviewUPP
= NULL
;
49 NavReplyRecord mNavReply
;
50 AEDesc
* mDefaultLocation
= NULL
;
51 bool mSelectDefault
= false ;
53 ::NavGetDefaultDialogOptions(&mNavOptions
);
57 mSelectDefault
= false;
58 mNavReply
.validRecord
= false;
59 mNavReply
.replacing
= false;
60 mNavReply
.isStationery
= false;
61 mNavReply
.translationNeeded
= false;
62 mNavReply
.selection
.descriptorType
= typeNull
;
63 mNavReply
.selection
.dataHandle
= nil
;
64 mNavReply
.keyScript
= smSystemScript
;
65 mNavReply
.fileTranslation
= nil
;
67 // Set default location, the location
68 // that's displayed when the dialog
71 if ( mDefaultLocation
) {
74 mNavOptions
.dialogOptionFlags
|= kNavSelectDefaultLocation
;
76 mNavOptions
.dialogOptionFlags
&= ~kNavSelectDefaultLocation
;
80 OSErr err
= ::NavChooseFolder(
88 if ( (err
!= noErr
) && (err
!= userCanceledErr
) ) {
93 if (mNavReply
.validRecord
) { // User chose a folder
99 OSErr err
= ::AECoerceDesc( &mNavReply
.selection
, typeFSS
, &specDesc
);
100 if ( err
!= noErr
) {
104 folderInfo
= **(FSSpec
**) specDesc
.dataHandle
;
105 if (specDesc
.dataHandle
!= nil
) {
106 ::AEDisposeDesc(&specDesc
);
109 // mNavReply.GetFileSpec(folderInfo);
111 // The FSSpec from NavChooseFolder is NOT the file spec
112 // for the folder. The parID field is actually the DirID
113 // of the folder itself, not the folder's parent, and
114 // the name field is empty. We must call PBGetCatInfo
115 // to get the parent DirID and folder name
118 CInfoPBRec thePB
; // Directory Info Parameter Block
119 thePB
.dirInfo
.ioCompletion
= nil
;
120 thePB
.dirInfo
.ioVRefNum
= folderInfo
.vRefNum
; // Volume is right
121 thePB
.dirInfo
.ioDrDirID
= folderInfo
.parID
; // Folder's DirID
122 thePB
.dirInfo
.ioNamePtr
= name
;
123 thePB
.dirInfo
.ioFDirIndex
= -1; // Lookup using Volume and DirID
125 err
= ::PBGetCatInfoSync(&thePB
);
126 if ( err
!= noErr
) {
130 // Create cannonical FSSpec
131 ::FSMakeFSSpec(thePB
.dirInfo
.ioVRefNum
, thePB
.dirInfo
.ioDrParID
,
134 // outFolderDirID = thePB.dirInfo.ioDrDirID;
135 m_path
= wxMacFSSpec2MacFilename( &outFileSpec
) ;