1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/dirdlg.cpp
3 // Purpose: wxDirDialog
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
18 #include "wx/dirdlg.h"
24 #include "wx/dialog.h"
26 #include "wx/cmndata.h"
28 #include "wx/mac/private.h"
31 #include <Carbon/Carbon.h>
33 #include <Navigation.h>
36 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
38 wxDirDialog::wxDirDialog(wxWindow
*parent
,
39 const wxString
& message
,
40 const wxString
& defaultPath
,
42 const wxPoint
& WXUNUSED(pos
),
43 const wxSize
& WXUNUSED(size
),
44 const wxString
& WXUNUSED(name
))
46 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
48 m_dialogStyle
= style
;
53 int wxDirDialog::ShowModal()
55 NavDialogOptions mNavOptions
;
56 NavObjectFilterUPP mNavFilterUPP
= NULL
;
57 NavPreviewUPP mNavPreviewUPP
= NULL
;
58 NavReplyRecord mNavReply
;
59 AEDesc
* mDefaultLocation
= NULL
;
60 bool mSelectDefault
= false ;
62 ::NavGetDefaultDialogOptions(&mNavOptions
);
66 mSelectDefault
= false;
67 mNavReply
.validRecord
= false;
68 mNavReply
.replacing
= false;
69 mNavReply
.isStationery
= false;
70 mNavReply
.translationNeeded
= false;
71 mNavReply
.selection
.descriptorType
= typeNull
;
72 mNavReply
.selection
.dataHandle
= nil
;
73 mNavReply
.keyScript
= smSystemScript
;
74 mNavReply
.fileTranslation
= nil
;
76 // Set default location, the location
77 // that's displayed when the dialog
80 if ( mDefaultLocation
) {
83 mNavOptions
.dialogOptionFlags
|= kNavSelectDefaultLocation
;
85 mNavOptions
.dialogOptionFlags
&= ~kNavSelectDefaultLocation
;
89 OSErr err
= ::NavChooseFolder(
97 if ( (err
!= noErr
) && (err
!= userCanceledErr
) ) {
98 m_path
= wxEmptyString
;
102 if (mNavReply
.validRecord
) { // User chose a folder
108 OSErr err
= ::AECoerceDesc( &mNavReply
.selection
, typeFSS
, &specDesc
);
109 if ( err
!= noErr
) {
110 m_path
= wxEmptyString
;
113 folderInfo
= **(FSSpec
**) specDesc
.dataHandle
;
114 if (specDesc
.dataHandle
!= nil
) {
115 ::AEDisposeDesc(&specDesc
);
118 // mNavReply.GetFileSpec(folderInfo);
120 // The FSSpec from NavChooseFolder is NOT the file spec
121 // for the folder. The parID field is actually the DirID
122 // of the folder itself, not the folder's parent, and
123 // the name field is empty. We must call PBGetCatInfo
124 // to get the parent DirID and folder name
127 CInfoPBRec thePB
; // Directory Info Parameter Block
128 thePB
.dirInfo
.ioCompletion
= nil
;
129 thePB
.dirInfo
.ioVRefNum
= folderInfo
.vRefNum
; // Volume is right
130 thePB
.dirInfo
.ioDrDirID
= folderInfo
.parID
; // Folder's DirID
131 thePB
.dirInfo
.ioNamePtr
= name
;
132 thePB
.dirInfo
.ioFDirIndex
= -1; // Lookup using Volume and DirID
134 err
= ::PBGetCatInfoSync(&thePB
);
135 if ( err
!= noErr
) {
136 m_path
= wxEmptyString
;
139 // Create cannonical FSSpec
140 ::FSMakeFSSpec(thePB
.dirInfo
.ioVRefNum
, thePB
.dirInfo
.ioDrParID
,
143 // outFolderDirID = thePB.dirInfo.ioDrDirID;
144 m_path
= wxMacFSSpec2MacFilename( &outFileSpec
) ;