1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/dirdlg.cpp
3 // Purpose: wxDirDialog
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #if wxUSE_DIRDLG && !defined(__WXUNIVERSAL__)
16 #include "wx/dirdlg.h"
20 #include "wx/dialog.h"
21 #include "wx/cmndata.h"
24 #include "wx/filename.h"
26 #include "wx/osx/private.h"
29 #include <Carbon/Carbon.h>
31 #include <Navigation.h>
34 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
36 static pascal void NavEventProc(
37 NavEventCallbackMessage inSelector
,
39 NavCallBackUserData ioUserData
);
41 static NavEventUPP sStandardNavEventFilter
= NewNavEventUPP(NavEventProc
);
43 static pascal void NavEventProc(
44 NavEventCallbackMessage inSelector
,
46 NavCallBackUserData ioUserData
)
48 wxDirDialog
* data
= ( wxDirDialog
*) ioUserData
;
49 if ( inSelector
== kNavCBStart
)
51 if (data
&& !data
->GetPath().empty() )
53 // Set default location for the modern Navigation APIs
54 // Apple Technical Q&A 1151
56 wxMacPathToFSRef(data
->GetPath(), &theFile
);
57 AEDesc theLocation
= { typeNull
, NULL
};
58 if (noErr
== ::AECreateDesc(typeFSRef
, &theFile
, sizeof(FSRef
), &theLocation
))
59 ::NavCustomControl(ioParams
->context
, kNavCtlSetLocation
, (void *) &theLocation
);
64 wxDirDialog::wxDirDialog(wxWindow
*parent
,
65 const wxString
& message
,
66 const wxString
& defaultPath
,
68 const wxPoint
& WXUNUSED(pos
),
69 const wxSize
& WXUNUSED(size
),
70 const wxString
& WXUNUSED(name
))
72 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
78 int wxDirDialog::ShowModal()
80 NavDialogRef dialog
= NULL
;
81 NavDialogCreationOptions options
;
82 NavReplyRecord reply
;
83 bool disposeReply
= false ;
86 err
= NavGetDefaultDialogCreationOptions(&options
);
87 options
.optionFlags
&= ~kNavAllowMultipleFiles
;
90 wxCFStringRef
message(m_message
, GetFont().GetEncoding());
91 options
.message
= message
;
92 err
= NavCreateChooseFolderDialog(&options
, sStandardNavEventFilter
, NULL
, this , &dialog
);
95 err
= NavDialogRun(dialog
);
98 err
= NavDialogGetReply(dialog
, &reply
);
106 if ( reply
.validRecord
)
111 OSErr err
= ::AECoerceDesc( &reply
.selection
, typeFSRef
, &specDesc
);
114 m_path
= wxEmptyString
;
118 folderInfo
= **(FSRef
**) specDesc
.dataHandle
;
119 m_path
= wxMacFSRefToPath( &folderInfo
) ;
120 if (specDesc
.dataHandle
!= nil
)
122 ::AEDisposeDesc(&specDesc
);
128 err
= paramErr
; // could be any error, only used for giving back wxID_CANCEL
133 ::NavDisposeReply(&reply
);
135 // apparently cancelling shouldn't change m_path
136 if ( err
!= noErr
&& err
!= userCanceledErr
)
137 m_path
= wxEmptyString
;
140 ::NavDialogDispose(dialog
);
142 return (err
== noErr
) ? wxID_OK
: wxID_CANCEL
;