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"
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 wxDirDialog::wxDirDialog(wxWindow
*parent
,
58 const wxString
& message
,
59 const wxString
& defaultPath
,
61 const wxPoint
& WXUNUSED(pos
),
62 const wxSize
& WXUNUSED(size
),
63 const wxString
& WXUNUSED(name
))
65 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
68 SetMessage( message
);
69 SetWindowStyle(style
);
73 int wxDirDialog::ShowModal()
75 NavDialogRef dialog
= NULL
;
76 NavDialogCreationOptions options
;
77 NavReplyRecord reply
;
78 bool disposeReply
= false ;
81 err
= NavGetDefaultDialogCreationOptions(&options
);
82 options
.optionFlags
&= ~kNavAllowMultipleFiles
;
85 wxCFStringRef
message(m_message
, GetFont().GetEncoding());
86 options
.message
= message
;
87 err
= NavCreateChooseFolderDialog(&options
, sStandardNavEventFilter
, NULL
, this , &dialog
);
90 wxDialog::OSXBeginModalDialog();
91 err
= NavDialogRun(dialog
);
92 wxDialog::OSXEndModalDialog();
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
;
137 ::NavDialogDispose(dialog
);
139 return (err
== noErr
) ? wxID_OK
: wxID_CANCEL
;