1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/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"
23 #include "wx/filename.h"
24 #include "wx/modalhook.h"
26 #include "wx/osx/private.h"
28 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
30 static pascal void NavEventProc(
31 NavEventCallbackMessage inSelector
,
33 NavCallBackUserData ioUserData
);
35 static NavEventUPP sStandardNavEventFilter
= NewNavEventUPP(NavEventProc
);
37 static pascal void NavEventProc(
38 NavEventCallbackMessage inSelector
,
40 NavCallBackUserData ioUserData
)
42 wxDirDialog
* data
= ( wxDirDialog
*) ioUserData
;
43 if ( inSelector
== kNavCBStart
)
45 if (data
&& !data
->GetPath().empty() )
47 // Set default location for the modern Navigation APIs
48 // Apple Technical Q&A 1151
50 wxMacPathToFSRef(data
->GetPath(), &theFile
);
51 AEDesc theLocation
= { typeNull
, NULL
};
52 if (noErr
== ::AECreateDesc(typeFSRef
, &theFile
, sizeof(FSRef
), &theLocation
))
53 ::NavCustomControl(ioParams
->context
, kNavCtlSetLocation
, (void *) &theLocation
);
58 void wxDirDialog::Init()
62 void wxDirDialog::Create(wxWindow
*parent
,
63 const wxString
& message
,
64 const wxString
& defaultPath
,
66 const wxPoint
& WXUNUSED(pos
),
67 const wxSize
& WXUNUSED(size
),
68 const wxString
& WXUNUSED(name
))
70 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
73 SetMessage( message
);
74 SetWindowStyle(style
);
78 int wxDirDialog::ShowModal()
80 WX_HOOK_MODAL_DIALOG();
82 NavDialogRef dialog
= NULL
;
83 NavDialogCreationOptions options
;
84 NavReplyRecord reply
;
85 bool disposeReply
= false ;
88 err
= NavGetDefaultDialogCreationOptions(&options
);
89 options
.optionFlags
&= ~kNavAllowMultipleFiles
;
92 wxCFStringRef
message(m_message
, GetFont().GetEncoding());
93 options
.message
= message
;
94 err
= NavCreateChooseFolderDialog(&options
, sStandardNavEventFilter
, NULL
, this , &dialog
);
97 wxDialog::OSXBeginModalDialog();
98 err
= NavDialogRun(dialog
);
99 wxDialog::OSXEndModalDialog();
102 err
= NavDialogGetReply(dialog
, &reply
);
103 disposeReply
= true ;
110 if ( reply
.validRecord
)
115 OSErr err
= ::AECoerceDesc( &reply
.selection
, typeFSRef
, &specDesc
);
118 m_path
= wxEmptyString
;
122 folderInfo
= **(FSRef
**) specDesc
.dataHandle
;
123 m_path
= wxMacFSRefToPath( &folderInfo
) ;
124 if (specDesc
.dataHandle
!= nil
)
126 ::AEDisposeDesc(&specDesc
);
132 err
= paramErr
; // could be any error, only used for giving back wxID_CANCEL
137 ::NavDisposeReply(&reply
);
139 // apparently cancelling shouldn't change m_path
140 if ( err
!= noErr
&& err
!= userCanceledErr
)
141 m_path
= wxEmptyString
;
144 ::NavDialogDispose(dialog
);
146 return (err
== noErr
) ? wxID_OK
: wxID_CANCEL
;