1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/dirdlg.cpp
3 // Purpose: wxDirDialog
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
13 #if wxUSE_DIRDLG && !defined(__WXUNIVERSAL__)
15 #include "wx/dirdlg.h"
19 #include "wx/dialog.h"
22 #include "wx/filename.h"
23 #include "wx/modalhook.h"
25 #include "wx/osx/private.h"
27 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
29 static pascal void NavEventProc(
30 NavEventCallbackMessage inSelector
,
32 NavCallBackUserData ioUserData
);
34 static NavEventUPP sStandardNavEventFilter
= NewNavEventUPP(NavEventProc
);
36 static pascal void NavEventProc(
37 NavEventCallbackMessage inSelector
,
39 NavCallBackUserData ioUserData
)
41 wxDirDialog
* data
= ( wxDirDialog
*) ioUserData
;
42 if ( inSelector
== kNavCBStart
)
44 if (data
&& !data
->GetPath().empty() )
46 // Set default location for the modern Navigation APIs
47 // Apple Technical Q&A 1151
49 wxMacPathToFSRef(data
->GetPath(), &theFile
);
50 AEDesc theLocation
= { typeNull
, NULL
};
51 if (noErr
== ::AECreateDesc(typeFSRef
, &theFile
, sizeof(FSRef
), &theLocation
))
52 ::NavCustomControl(ioParams
->context
, kNavCtlSetLocation
, (void *) &theLocation
);
57 void wxDirDialog::Init()
61 void wxDirDialog::Create(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") ) ;
72 SetMessage( message
);
73 SetWindowStyle(style
);
77 int wxDirDialog::ShowModal()
79 WX_HOOK_MODAL_DIALOG();
81 NavDialogRef dialog
= NULL
;
82 NavDialogCreationOptions options
;
83 NavReplyRecord reply
;
84 bool disposeReply
= false ;
87 err
= NavGetDefaultDialogCreationOptions(&options
);
88 options
.optionFlags
&= ~kNavAllowMultipleFiles
;
91 wxCFStringRef
message(m_message
, GetFont().GetEncoding());
92 options
.message
= message
;
93 err
= NavCreateChooseFolderDialog(&options
, sStandardNavEventFilter
, NULL
, this , &dialog
);
96 wxDialog::OSXBeginModalDialog();
97 err
= NavDialogRun(dialog
);
98 wxDialog::OSXEndModalDialog();
101 err
= NavDialogGetReply(dialog
, &reply
);
102 disposeReply
= true ;
109 if ( reply
.validRecord
)
114 OSErr err
= ::AECoerceDesc( &reply
.selection
, typeFSRef
, &specDesc
);
117 m_path
= wxEmptyString
;
121 folderInfo
= **(FSRef
**) specDesc
.dataHandle
;
122 m_path
= wxMacFSRefToPath( &folderInfo
) ;
123 if (specDesc
.dataHandle
!= nil
)
125 ::AEDisposeDesc(&specDesc
);
131 err
= paramErr
; // could be any error, only used for giving back wxID_CANCEL
136 ::NavDisposeReply(&reply
);
138 // apparently cancelling shouldn't change m_path
139 if ( err
!= noErr
&& err
!= userCanceledErr
)
140 m_path
= wxEmptyString
;
143 ::NavDialogDispose(dialog
);
145 return (err
== noErr
) ? wxID_OK
: wxID_CANCEL
;