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"
16 #include "wx/dirdlg.h"
22 #include "wx/dialog.h"
24 #include "wx/cmndata.h"
25 #include "wx/filename.h"
27 #include "wx/mac/private.h"
30 #include <Carbon/Carbon.h>
32 #include <Navigation.h>
35 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
37 static pascal void NavEventProc(
38 NavEventCallbackMessage inSelector
,
40 NavCallBackUserData ioUserData
);
42 static NavEventUPP sStandardNavEventFilter
= NewNavEventUPP(NavEventProc
);
44 static pascal void NavEventProc(
45 NavEventCallbackMessage inSelector
,
47 NavCallBackUserData ioUserData
)
49 wxDirDialog
* data
= ( wxDirDialog
*) ioUserData
;
50 if ( inSelector
== kNavCBStart
)
52 if (data
&& !data
->GetPath().empty() )
54 // Set default location for the modern Navigation APIs
55 // Apple Technical Q&A 1151
57 wxMacFilename2FSSpec(data
->GetPath(), &theFSSpec
);
58 AEDesc theLocation
= { typeNull
, NULL
};
59 if (noErr
== ::AECreateDesc(typeFSS
, &theFSSpec
, sizeof(FSSpec
), &theLocation
))
60 ::NavCustomControl(ioParams
->context
, kNavCtlSetLocation
, (void *) &theLocation
);
65 wxDirDialog::wxDirDialog(wxWindow
*parent
,
66 const wxString
& message
,
67 const wxString
& defaultPath
,
69 const wxPoint
& WXUNUSED(pos
),
70 const wxSize
& WXUNUSED(size
),
71 const wxString
& WXUNUSED(name
))
73 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
79 int wxDirDialog::ShowModal()
82 NavDialogCreationOptions options
;
83 NavReplyRecord reply
;
84 bool disposeReply
= false ;
87 err
= NavGetDefaultDialogCreationOptions(&options
);
90 wxMacCFStringHolder
message(m_message
, m_font
.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
;
139 return (err
== noErr
) ? wxID_OK
: wxID_CANCEL
;