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"
21 #include "wx/cmndata.h"
24 #include "wx/filename.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 wxDirDialog::wxDirDialog(wxWindow
*parent
,
59 const wxString
& message
,
60 const wxString
& defaultPath
,
62 const wxPoint
& WXUNUSED(pos
),
63 const wxSize
& WXUNUSED(size
),
64 const wxString
& WXUNUSED(name
))
66 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
69 SetMessage( message
);
70 SetWindowStyle(style
);
74 int wxDirDialog::ShowModal()
76 NavDialogRef dialog
= NULL
;
77 NavDialogCreationOptions options
;
78 NavReplyRecord reply
;
79 bool disposeReply
= false ;
82 err
= NavGetDefaultDialogCreationOptions(&options
);
83 options
.optionFlags
&= ~kNavAllowMultipleFiles
;
86 wxCFStringRef
message(m_message
, GetFont().GetEncoding());
87 options
.message
= message
;
88 err
= NavCreateChooseFolderDialog(&options
, sStandardNavEventFilter
, NULL
, this , &dialog
);
91 err
= NavDialogRun(dialog
);
94 err
= NavDialogGetReply(dialog
, &reply
);
102 if ( reply
.validRecord
)
107 OSErr err
= ::AECoerceDesc( &reply
.selection
, typeFSRef
, &specDesc
);
110 m_path
= wxEmptyString
;
114 folderInfo
= **(FSRef
**) specDesc
.dataHandle
;
115 m_path
= wxMacFSRefToPath( &folderInfo
) ;
116 if (specDesc
.dataHandle
!= nil
)
118 ::AEDisposeDesc(&specDesc
);
124 err
= paramErr
; // could be any error, only used for giving back wxID_CANCEL
129 ::NavDisposeReply(&reply
);
131 // apparently cancelling shouldn't change m_path
132 if ( err
!= noErr
&& err
!= userCanceledErr
)
133 m_path
= wxEmptyString
;
136 ::NavDialogDispose(dialog
);
138 return (err
== noErr
) ? wxID_OK
: wxID_CANCEL
;