]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/dirdlg.cpp
Add wxEventLoop::ScheduleExit().
[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
58wxDirDialog::wxDirDialog(wxWindow *parent,
59 const wxString& message,
60 const wxString& defaultPath,
524c47aa 61 long style,
489468fe
SC
62 const wxPoint& WXUNUSED(pos),
63 const wxSize& WXUNUSED(size),
64 const wxString& WXUNUSED(name))
65{
66 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
489468fe 67 m_parent = parent;
524c47aa
SC
68
69 SetMessage( message );
70 SetWindowStyle(style);
71 SetPath(defaultPath);
489468fe
SC
72}
73
74int wxDirDialog::ShowModal()
75{
691745ab 76 WX_HOOK_MODAL_DIALOG();
643e9cf9 77
489468fe
SC
78 NavDialogRef dialog = NULL;
79 NavDialogCreationOptions options;
80 NavReplyRecord reply ;
81 bool disposeReply = false ;
82 OSStatus err = noErr;
83
84 err = NavGetDefaultDialogCreationOptions(&options);
85 options.optionFlags &= ~kNavAllowMultipleFiles;
86 if (err == noErr)
87 {
88 wxCFStringRef message(m_message, GetFont().GetEncoding());
89 options.message = message;
90 err = NavCreateChooseFolderDialog(&options, sStandardNavEventFilter , NULL, this , &dialog);
91 if (err == noErr)
92 {
445e564f 93 wxDialog::OSXBeginModalDialog();
489468fe 94 err = NavDialogRun(dialog);
445e564f 95 wxDialog::OSXEndModalDialog();
489468fe
SC
96 if ( err == noErr )
97 {
98 err = NavDialogGetReply(dialog, &reply);
99 disposeReply = true ;
100 }
101 }
102 }
103
104 if ( err == noErr )
105 {
106 if ( reply.validRecord )
107 {
108 FSRef folderInfo;
109 AEDesc specDesc ;
110
111 OSErr err = ::AECoerceDesc( &reply.selection , typeFSRef, &specDesc);
112 if ( err != noErr )
113 {
114 m_path = wxEmptyString ;
115 }
116 else
117 {
118 folderInfo = **(FSRef**) specDesc.dataHandle;
119 m_path = wxMacFSRefToPath( &folderInfo ) ;
120 if (specDesc.dataHandle != nil)
121 {
122 ::AEDisposeDesc(&specDesc);
123 }
124 }
125 }
126 else
127 {
128 err = paramErr ; // could be any error, only used for giving back wxID_CANCEL
129 }
130 }
131
132 if ( disposeReply )
133 ::NavDisposeReply(&reply);
134
135 // apparently cancelling shouldn't change m_path
136 if ( err != noErr && err != userCanceledErr )
137 m_path = wxEmptyString ;
138
03647350
VZ
139 if ( dialog )
140 ::NavDialogDispose(dialog);
489468fe
SC
141
142 return (err == noErr) ? wxID_OK : wxID_CANCEL ;
143}
144
145#endif