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"
19 #include "wx/dialog.h"
20 #include "wx/dirdlg.h"
22 #include "wx/cmndata.h"
24 #include "wx/mac/private.h"
27 #include <Carbon/Carbon.h>
29 #include <Navigation.h>
32 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
34 wxDirDialog::wxDirDialog(wxWindow
*parent
,
35 const wxString
& message
,
36 const wxString
& defaultPath
,
38 const wxPoint
& WXUNUSED(pos
),
39 const wxSize
& WXUNUSED(size
),
40 const wxString
& WXUNUSED(name
))
42 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
44 m_dialogStyle
= style
;
49 int wxDirDialog::ShowModal()
51 NavDialogOptions mNavOptions
;
52 NavObjectFilterUPP mNavFilterUPP
= NULL
;
53 NavPreviewUPP mNavPreviewUPP
= NULL
;
54 NavReplyRecord mNavReply
;
55 AEDesc
* mDefaultLocation
= NULL
;
56 bool mSelectDefault
= false ;
58 ::NavGetDefaultDialogOptions(&mNavOptions
);
62 mSelectDefault
= false;
63 mNavReply
.validRecord
= false;
64 mNavReply
.replacing
= false;
65 mNavReply
.isStationery
= false;
66 mNavReply
.translationNeeded
= false;
67 mNavReply
.selection
.descriptorType
= typeNull
;
68 mNavReply
.selection
.dataHandle
= nil
;
69 mNavReply
.keyScript
= smSystemScript
;
70 mNavReply
.fileTranslation
= nil
;
72 // Set default location, the location
73 // that's displayed when the dialog
76 if ( mDefaultLocation
) {
79 mNavOptions
.dialogOptionFlags
|= kNavSelectDefaultLocation
;
81 mNavOptions
.dialogOptionFlags
&= ~kNavSelectDefaultLocation
;
85 OSErr err
= ::NavChooseFolder(
93 if ( (err
!= noErr
) && (err
!= userCanceledErr
) ) {
94 m_path
= wxEmptyString
;
98 if (mNavReply
.validRecord
) { // User chose a folder
104 OSErr err
= ::AECoerceDesc( &mNavReply
.selection
, typeFSS
, &specDesc
);
105 if ( err
!= noErr
) {
106 m_path
= wxEmptyString
;
109 folderInfo
= **(FSSpec
**) specDesc
.dataHandle
;
110 if (specDesc
.dataHandle
!= nil
) {
111 ::AEDisposeDesc(&specDesc
);
114 // mNavReply.GetFileSpec(folderInfo);
116 // The FSSpec from NavChooseFolder is NOT the file spec
117 // for the folder. The parID field is actually the DirID
118 // of the folder itself, not the folder's parent, and
119 // the name field is empty. We must call PBGetCatInfo
120 // to get the parent DirID and folder name
123 CInfoPBRec thePB
; // Directory Info Parameter Block
124 thePB
.dirInfo
.ioCompletion
= nil
;
125 thePB
.dirInfo
.ioVRefNum
= folderInfo
.vRefNum
; // Volume is right
126 thePB
.dirInfo
.ioDrDirID
= folderInfo
.parID
; // Folder's DirID
127 thePB
.dirInfo
.ioNamePtr
= name
;
128 thePB
.dirInfo
.ioFDirIndex
= -1; // Lookup using Volume and DirID
130 err
= ::PBGetCatInfoSync(&thePB
);
131 if ( err
!= noErr
) {
132 m_path
= wxEmptyString
;
135 // Create cannonical FSSpec
136 ::FSMakeFSSpec(thePB
.dirInfo
.ioVRefNum
, thePB
.dirInfo
.ioDrParID
,
139 // outFolderDirID = thePB.dirInfo.ioDrDirID;
140 m_path
= wxMacFSSpec2MacFilename( &outFileSpec
) ;