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"
22 #include "wx/dialog.h"
25 #include "wx/cmndata.h"
27 #include "wx/mac/private.h"
30 #include <Carbon/Carbon.h>
32 #include <Navigation.h>
35 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
37 wxDirDialog
::wxDirDialog(wxWindow
*parent
,
38 const wxString
& message
,
39 const wxString
& defaultPath
,
41 const wxPoint
& WXUNUSED(pos
),
42 const wxSize
& WXUNUSED(size
),
43 const wxString
& WXUNUSED(name
))
45 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
47 m_dialogStyle
= style
;
52 int wxDirDialog
::ShowModal()
54 NavDialogOptions mNavOptions
;
55 NavObjectFilterUPP mNavFilterUPP
= NULL
;
56 NavPreviewUPP mNavPreviewUPP
= NULL
;
57 NavReplyRecord mNavReply
;
58 AEDesc
* mDefaultLocation
= NULL
;
59 bool mSelectDefault
= false ;
61 ::NavGetDefaultDialogOptions(&mNavOptions
);
65 mSelectDefault
= false;
66 mNavReply
.validRecord
= false;
67 mNavReply
.replacing
= false;
68 mNavReply
.isStationery
= false;
69 mNavReply
.translationNeeded
= false;
70 mNavReply
.selection
.descriptorType
= typeNull
;
71 mNavReply
.selection
.dataHandle
= nil
;
72 mNavReply
.keyScript
= smSystemScript
;
73 mNavReply
.fileTranslation
= nil
;
75 // Set default location, the location
76 // that's displayed when the dialog
79 if ( mDefaultLocation
) {
82 mNavOptions
.dialogOptionFlags
|= kNavSelectDefaultLocation
;
84 mNavOptions
.dialogOptionFlags
&= ~kNavSelectDefaultLocation
;
88 OSErr err
= ::NavChooseFolder(
96 if ( (err
!= noErr
) && (err
!= userCanceledErr
) ) {
97 m_path
= wxEmptyString
;
101 if (mNavReply
.validRecord
) { // User chose a folder
107 OSErr err
= ::AECoerceDesc( &mNavReply
.selection
, typeFSS
, &specDesc
);
108 if ( err
!= noErr
) {
109 m_path
= wxEmptyString
;
112 folderInfo
= **(FSSpec
**) specDesc
.dataHandle
;
113 if (specDesc
.dataHandle
!= nil
) {
114 ::AEDisposeDesc(&specDesc
);
117 // mNavReply.GetFileSpec(folderInfo);
119 // The FSSpec from NavChooseFolder is NOT the file spec
120 // for the folder. The parID field is actually the DirID
121 // of the folder itself, not the folder's parent, and
122 // the name field is empty. We must call PBGetCatInfo
123 // to get the parent DirID and folder name
126 CInfoPBRec thePB
; // Directory Info Parameter Block
127 thePB
.dirInfo
.ioCompletion
= nil
;
128 thePB
.dirInfo
.ioVRefNum
= folderInfo
.vRefNum
; // Volume is right
129 thePB
.dirInfo
.ioDrDirID
= folderInfo
.parID
; // Folder's DirID
130 thePB
.dirInfo
.ioNamePtr
= name
;
131 thePB
.dirInfo
.ioFDirIndex
= -1; // Lookup using Volume and DirID
133 err
= ::PBGetCatInfoSync(&thePB
);
134 if ( err
!= noErr
) {
135 m_path
= wxEmptyString
;
138 // Create cannonical FSSpec
139 ::FSMakeFSSpec(thePB
.dirInfo
.ioVRefNum
, thePB
.dirInfo
.ioDrParID
,
142 // outFolderDirID = thePB.dirInfo.ioDrDirID;
143 m_path
= wxMacFSSpec2MacFilename( &outFileSpec
) ;