]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/dirdlg.cpp
further routing into wxApp
[wxWidgets.git] / src / osx / carbon / dirdlg.cpp
CommitLineData
489468fe 1/////////////////////////////////////////////////////////////////////////////
524c47aa 2// Name: src/osx/carbon/dirdlg.cpp
489468fe
SC
3// Purpose: wxDirDialog
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
b2680ced 14#if wxUSE_DIRDLG && !defined(__WXUNIVERSAL__)
489468fe
SC
15
16#include "wx/dirdlg.h"
17
18#ifndef WX_PRECOMP
19 #include "wx/utils.h"
20 #include "wx/dialog.h"
489468fe
SC
21#endif // WX_PRECOMP
22
23#include "wx/filename.h"
691745ab 24#include "wx/modalhook.h"
489468fe 25
1f0c8f31 26#include "wx/osx/private.h"
489468fe 27
489468fe
SC
28IMPLEMENT_CLASS(wxDirDialog, wxDialog)
29
30static pascal void NavEventProc(
31 NavEventCallbackMessage inSelector,
32 NavCBRecPtr ioParams,
33 NavCallBackUserData ioUserData );
34
35static NavEventUPP sStandardNavEventFilter = NewNavEventUPP(NavEventProc);
36
37static pascal void NavEventProc(
38 NavEventCallbackMessage inSelector,
39 NavCBRecPtr ioParams,
40 NavCallBackUserData ioUserData )
41{
42 wxDirDialog * data = ( wxDirDialog *) ioUserData ;
43 if ( inSelector == kNavCBStart )
44 {
45 if (data && !data->GetPath().empty() )
46 {
47 // Set default location for the modern Navigation APIs
48 // Apple Technical Q&A 1151
49 FSRef theFile;
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);
54 }
55 }
56}
57
aad2997b
VZ
58void wxDirDialog::Init()
59{
60}
61
62void wxDirDialog::Create(wxWindow *parent,
489468fe
SC
63 const wxString& message,
64 const wxString& defaultPath,
524c47aa 65 long style,
489468fe
SC
66 const wxPoint& WXUNUSED(pos),
67 const wxSize& WXUNUSED(size),
68 const wxString& WXUNUSED(name))
69{
70 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
489468fe 71 m_parent = parent;
524c47aa
SC
72
73 SetMessage( message );
74 SetWindowStyle(style);
75 SetPath(defaultPath);
489468fe
SC
76}
77
78int wxDirDialog::ShowModal()
79{
691745ab 80 WX_HOOK_MODAL_DIALOG();
643e9cf9 81
489468fe
SC
82 NavDialogRef dialog = NULL;
83 NavDialogCreationOptions options;
84 NavReplyRecord reply ;
85 bool disposeReply = false ;
86 OSStatus err = noErr;
87
88 err = NavGetDefaultDialogCreationOptions(&options);
89 options.optionFlags &= ~kNavAllowMultipleFiles;
90 if (err == noErr)
91 {
92 wxCFStringRef message(m_message, GetFont().GetEncoding());
93 options.message = message;
94 err = NavCreateChooseFolderDialog(&options, sStandardNavEventFilter , NULL, this , &dialog);
95 if (err == noErr)
96 {
445e564f 97 wxDialog::OSXBeginModalDialog();
489468fe 98 err = NavDialogRun(dialog);
445e564f 99 wxDialog::OSXEndModalDialog();
489468fe
SC
100 if ( err == noErr )
101 {
102 err = NavDialogGetReply(dialog, &reply);
103 disposeReply = true ;
104 }
105 }
106 }
107
108 if ( err == noErr )
109 {
110 if ( reply.validRecord )
111 {
112 FSRef folderInfo;
113 AEDesc specDesc ;
114
115 OSErr err = ::AECoerceDesc( &reply.selection , typeFSRef, &specDesc);
116 if ( err != noErr )
117 {
118 m_path = wxEmptyString ;
119 }
120 else
121 {
122 folderInfo = **(FSRef**) specDesc.dataHandle;
123 m_path = wxMacFSRefToPath( &folderInfo ) ;
124 if (specDesc.dataHandle != nil)
125 {
126 ::AEDisposeDesc(&specDesc);
127 }
128 }
129 }
130 else
131 {
132 err = paramErr ; // could be any error, only used for giving back wxID_CANCEL
133 }
134 }
135
136 if ( disposeReply )
137 ::NavDisposeReply(&reply);
138
139 // apparently cancelling shouldn't change m_path
140 if ( err != noErr && err != userCanceledErr )
141 m_path = wxEmptyString ;
142
03647350
VZ
143 if ( dialog )
144 ::NavDialogDispose(dialog);
489468fe
SC
145
146 return (err == noErr) ? wxID_OK : wxID_CANCEL ;
147}
148
149#endif