1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDirDialog
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
17 #include "wx/dialog.h"
18 #include "wx/dirdlg.h"
20 #include "wx/cmndata.h"
21 #include "wx/filename.h"
23 #include "wx/mac/private.h"
26 #include <Carbon/Carbon.h>
28 #include <Navigation.h>
31 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
33 static pascal void NavEventProc(
34 NavEventCallbackMessage inSelector
,
36 NavCallBackUserData ioUserData
);
38 static NavEventUPP sStandardNavEventFilter
= NewNavEventUPP(NavEventProc
);
40 static pascal void NavEventProc(
41 NavEventCallbackMessage inSelector
,
43 NavCallBackUserData ioUserData
)
45 wxDirDialog
* data
= ( wxDirDialog
*) ioUserData
;
46 if ( inSelector
== kNavCBStart
)
48 if (data
&& !data
->GetPath().IsEmpty() )
50 // Set default location for the modern Navigation APIs
51 // Apple Technical Q&A 1151
53 wxMacFilename2FSSpec(data
->GetPath(), &theFSSpec
);
54 AEDesc theLocation
= { typeNull
, NULL
};
55 if (noErr
== ::AECreateDesc(typeFSS
, &theFSSpec
, sizeof(FSSpec
), &theLocation
))
56 ::NavCustomControl(ioParams
->context
, kNavCtlSetLocation
, (void *) &theLocation
);
61 wxDirDialog::wxDirDialog(wxWindow
*parent
,
62 const wxString
& message
,
63 const wxString
& defaultPath
,
65 const wxPoint
& WXUNUSED(pos
),
66 const wxSize
& WXUNUSED(size
),
67 const wxString
& WXUNUSED(name
))
69 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
71 m_dialogStyle
= style
;
76 int wxDirDialog::ShowModal()
79 NavDialogCreationOptions options
;
80 NavReplyRecord reply
;
81 bool disposeReply
= false ;
84 err
= NavGetDefaultDialogCreationOptions(&options
);
87 wxMacCFStringHolder
message(m_message
, m_font
.GetEncoding());
88 options
.message
= message
;
89 err
= NavCreateChooseFolderDialog(&options
, sStandardNavEventFilter
, NULL
, this , &dialog
);
92 err
= NavDialogRun(dialog
);
95 err
= NavDialogGetReply(dialog
, &reply
);
103 if ( reply
.validRecord
)
108 OSErr err
= ::AECoerceDesc( &reply
.selection
, typeFSRef
, &specDesc
);
111 m_path
= wxEmptyString
;
115 folderInfo
= **(FSRef
**) specDesc
.dataHandle
;
116 m_path
= wxMacFSRefToPath( &folderInfo
) ;
117 if (specDesc
.dataHandle
!= nil
)
119 ::AEDisposeDesc(&specDesc
);
125 err
= paramErr
; // could be any error, only used for giving back wxID_CANCEL
130 ::NavDisposeReply(&reply
);
132 // apparently cancelling shouldn't change m_path
133 if ( err
!= noErr
&& err
!= userCanceledErr
)
134 m_path
= wxEmptyString
;
136 return (err
== noErr
) ? wxID_OK
: wxID_CANCEL
;