]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dirdlg.cpp
bring XBM in line with MSW
[wxWidgets.git] / src / mac / carbon / dirdlg.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: dirdlg.cpp
3// Purpose: wxDirDialog
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878
SC
12#include "wx/wxprec.h"
13
179e085f
RN
14#if wxUSE_DIRDLG
15
e9576ca5
SC
16#include "wx/utils.h"
17#include "wx/dialog.h"
18#include "wx/dirdlg.h"
19
20#include "wx/cmndata.h"
a4e3cdf0 21#include "wx/filename.h"
e9576ca5 22
76a5e5d2
SC
23#include "wx/mac/private.h"
24
f5c6eb5c 25#ifdef __DARWIN__
5fde6fcc 26 #include <Carbon/Carbon.h>
03e11df5
GD
27#else
28 #include <Navigation.h>
29#endif
5b781a67 30
e9576ca5 31IMPLEMENT_CLASS(wxDirDialog, wxDialog)
519cb848 32
a4e3cdf0
SC
33static pascal void NavEventProc(
34 NavEventCallbackMessage inSelector,
35 NavCBRecPtr ioParams,
36 NavCallBackUserData ioUserData );
37
38static NavEventUPP sStandardNavEventFilter = NewNavEventUPP(NavEventProc);
39
40static pascal void NavEventProc(
41 NavEventCallbackMessage inSelector,
42 NavCBRecPtr ioParams,
43 NavCallBackUserData ioUserData )
44{
45 wxDirDialog * data = ( wxDirDialog *) ioUserData ;
46 if ( inSelector == kNavCBStart )
47 {
48 if (data && !data->GetPath().IsEmpty() )
49 {
50 // Set default location for the modern Navigation APIs
51 // Apple Technical Q&A 1151
52 FSSpec theFSSpec;
53 wxMacFilename2FSSpec(data->GetPath(), &theFSSpec);
54 AEDesc theLocation = { typeNull, NULL };
55 if (noErr == ::AECreateDesc(typeFSS, &theFSSpec, sizeof(FSSpec), &theLocation))
56 ::NavCustomControl(ioParams->context, kNavCtlSetLocation, (void *) &theLocation);
57 }
58 }
59}
60
e78d4a23
VZ
61wxDirDialog::wxDirDialog(wxWindow *parent,
62 const wxString& message,
63 const wxString& defaultPath,
64 long style,
65 const wxPoint& WXUNUSED(pos),
66 const wxSize& WXUNUSED(size),
67 const wxString& WXUNUSED(name))
e9576ca5 68{
427ff662 69 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
e9576ca5
SC
70 m_message = message;
71 m_dialogStyle = style;
72 m_parent = parent;
e40298d5 73 m_path = defaultPath;
e9576ca5
SC
74}
75
76int wxDirDialog::ShowModal()
77{
516d38cd
SC
78 NavDialogRef dialog;
79 NavDialogCreationOptions options;
80 NavReplyRecord reply ;
81 bool disposeReply = false ;
82 OSStatus err = noErr;
83
84 err = NavGetDefaultDialogCreationOptions(&options);
85 if (err == noErr)
86 {
87 wxMacCFStringHolder message(m_message, m_font.GetEncoding());
88 options.message = message;
a4e3cdf0 89 err = NavCreateChooseFolderDialog(&options, sStandardNavEventFilter , NULL, this , &dialog);
516d38cd
SC
90 if (err == noErr)
91 {
92 err = NavDialogRun(dialog);
93 if ( err == noErr )
94 {
95 err = NavDialogGetReply(dialog, &reply);
96 disposeReply = true ;
97 }
98 }
e40298d5 99 }
516d38cd
SC
100
101 if ( err == noErr )
102 {
103 if ( reply.validRecord )
104 {
105 FSRef folderInfo;
106 AEDesc specDesc ;
107
108 OSErr err = ::AECoerceDesc( &reply.selection , typeFSRef, &specDesc);
109 if ( err != noErr )
110 {
111 m_path = wxEmptyString ;
112 }
113 else
114 {
115 folderInfo = **(FSRef**) specDesc.dataHandle;
116 m_path = wxMacFSRefToPath( &folderInfo ) ;
117 if (specDesc.dataHandle != nil)
118 {
119 ::AEDisposeDesc(&specDesc);
120 }
121 }
902725ee 122 }
516d38cd
SC
123 else
124 {
125 err = paramErr ; // could be any error, only used for giving back wxID_CANCEL
e40298d5 126 }
e40298d5 127 }
516d38cd
SC
128
129 if ( disposeReply )
130 ::NavDisposeReply(&reply);
131
132 // apparently cancelling shouldn't change m_path
133 if ( err != noErr && err != userCanceledErr )
134 m_path = wxEmptyString ;
135
136 return (err == noErr) ? wxID_OK : wxID_CANCEL ;
e9576ca5
SC
137}
138
179e085f 139#endif