]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dirdlg.cpp
Include wx/dcscreen.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / mac / carbon / dirdlg.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
de6185e2 2// Name: src/mac/carbon/dirdlg.cpp
e9576ca5 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
de6185e2 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/dirdlg.h"
17
de6185e2
WS
18#ifndef WX_PRECOMP
19 #include "wx/utils.h"
20#endif // WX_PRECOMP
21
22#include "wx/dialog.h"
23
e9576ca5 24#include "wx/cmndata.h"
a4e3cdf0 25#include "wx/filename.h"
e9576ca5 26
76a5e5d2
SC
27#include "wx/mac/private.h"
28
f5c6eb5c 29#ifdef __DARWIN__
de6185e2 30 #include <Carbon/Carbon.h>
03e11df5 31#else
de6185e2 32 #include <Navigation.h>
03e11df5 33#endif
5b781a67 34
e9576ca5 35IMPLEMENT_CLASS(wxDirDialog, wxDialog)
519cb848 36
a4e3cdf0
SC
37static pascal void NavEventProc(
38 NavEventCallbackMessage inSelector,
39 NavCBRecPtr ioParams,
40 NavCallBackUserData ioUserData );
41
42static NavEventUPP sStandardNavEventFilter = NewNavEventUPP(NavEventProc);
43
44static pascal void NavEventProc(
45 NavEventCallbackMessage inSelector,
46 NavCBRecPtr ioParams,
47 NavCallBackUserData ioUserData )
48{
49 wxDirDialog * data = ( wxDirDialog *) ioUserData ;
50 if ( inSelector == kNavCBStart )
51 {
de6185e2 52 if (data && !data->GetPath().empty() )
a4e3cdf0
SC
53 {
54 // Set default location for the modern Navigation APIs
55 // Apple Technical Q&A 1151
56 FSSpec theFSSpec;
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);
61 }
62 }
63}
64
e78d4a23
VZ
65wxDirDialog::wxDirDialog(wxWindow *parent,
66 const wxString& message,
67 const wxString& defaultPath,
68 long style,
69 const wxPoint& WXUNUSED(pos),
70 const wxSize& WXUNUSED(size),
71 const wxString& WXUNUSED(name))
e9576ca5 72{
427ff662 73 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
e9576ca5
SC
74 m_message = message;
75 m_dialogStyle = style;
76 m_parent = parent;
e40298d5 77 m_path = defaultPath;
e9576ca5
SC
78}
79
80int wxDirDialog::ShowModal()
81{
516d38cd
SC
82 NavDialogRef dialog;
83 NavDialogCreationOptions options;
84 NavReplyRecord reply ;
85 bool disposeReply = false ;
86 OSStatus err = noErr;
de6185e2 87
516d38cd 88 err = NavGetDefaultDialogCreationOptions(&options);
de6185e2 89 if (err == noErr)
516d38cd
SC
90 {
91 wxMacCFStringHolder message(m_message, m_font.GetEncoding());
92 options.message = message;
a4e3cdf0 93 err = NavCreateChooseFolderDialog(&options, sStandardNavEventFilter , NULL, this , &dialog);
de6185e2
WS
94 if (err == noErr)
95 {
516d38cd
SC
96 err = NavDialogRun(dialog);
97 if ( err == noErr )
98 {
99 err = NavDialogGetReply(dialog, &reply);
100 disposeReply = true ;
101 }
102 }
e40298d5 103 }
de6185e2
WS
104
105 if ( err == noErr )
106 {
516d38cd
SC
107 if ( reply.validRecord )
108 {
109 FSRef folderInfo;
110 AEDesc specDesc ;
de6185e2 111
516d38cd 112 OSErr err = ::AECoerceDesc( &reply.selection , typeFSRef, &specDesc);
de6185e2 113 if ( err != noErr )
516d38cd
SC
114 {
115 m_path = wxEmptyString ;
116 }
117 else
118 {
119 folderInfo = **(FSRef**) specDesc.dataHandle;
120 m_path = wxMacFSRefToPath( &folderInfo ) ;
de6185e2 121 if (specDesc.dataHandle != nil)
516d38cd
SC
122 {
123 ::AEDisposeDesc(&specDesc);
de6185e2 124 }
516d38cd 125 }
902725ee 126 }
516d38cd
SC
127 else
128 {
129 err = paramErr ; // could be any error, only used for giving back wxID_CANCEL
e40298d5 130 }
e40298d5 131 }
de6185e2 132
516d38cd
SC
133 if ( disposeReply )
134 ::NavDisposeReply(&reply);
de6185e2 135
516d38cd
SC
136 // apparently cancelling shouldn't change m_path
137 if ( err != noErr && err != userCanceledErr )
138 m_path = wxEmptyString ;
de6185e2 139
516d38cd 140 return (err == noErr) ? wxID_OK : wxID_CANCEL ;
e9576ca5
SC
141}
142
179e085f 143#endif