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