]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dirdlg.cpp
avoid system pop-up menu commands being handled by wxApp, bug was shown in printing...
[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"
21
76a5e5d2
SC
22#include "wx/mac/private.h"
23
f5c6eb5c 24#ifdef __DARWIN__
5fde6fcc 25 #include <Carbon/Carbon.h>
03e11df5
GD
26#else
27 #include <Navigation.h>
28#endif
5b781a67 29
e9576ca5 30IMPLEMENT_CLASS(wxDirDialog, wxDialog)
519cb848 31
e78d4a23
VZ
32wxDirDialog::wxDirDialog(wxWindow *parent,
33 const wxString& message,
34 const wxString& defaultPath,
35 long style,
36 const wxPoint& WXUNUSED(pos),
37 const wxSize& WXUNUSED(size),
38 const wxString& WXUNUSED(name))
e9576ca5 39{
427ff662 40 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
e9576ca5
SC
41 m_message = message;
42 m_dialogStyle = style;
43 m_parent = parent;
e40298d5 44 m_path = defaultPath;
e9576ca5
SC
45}
46
47int wxDirDialog::ShowModal()
48{
516d38cd
SC
49 NavDialogRef dialog;
50 NavDialogCreationOptions options;
51 NavReplyRecord reply ;
52 bool disposeReply = false ;
53 OSStatus err = noErr;
54
55 err = NavGetDefaultDialogCreationOptions(&options);
56 if (err == noErr)
57 {
58 wxMacCFStringHolder message(m_message, m_font.GetEncoding());
59 options.message = message;
60 err = NavCreateChooseFolderDialog(&options, NULL, NULL, NULL, &dialog);
61 if (err == noErr)
62 {
63 err = NavDialogRun(dialog);
64 if ( err == noErr )
65 {
66 err = NavDialogGetReply(dialog, &reply);
67 disposeReply = true ;
68 }
69 }
e40298d5 70 }
516d38cd
SC
71
72 if ( err == noErr )
73 {
74 if ( reply.validRecord )
75 {
76 FSRef folderInfo;
77 AEDesc specDesc ;
78
79 OSErr err = ::AECoerceDesc( &reply.selection , typeFSRef, &specDesc);
80 if ( err != noErr )
81 {
82 m_path = wxEmptyString ;
83 }
84 else
85 {
86 folderInfo = **(FSRef**) specDesc.dataHandle;
87 m_path = wxMacFSRefToPath( &folderInfo ) ;
88 if (specDesc.dataHandle != nil)
89 {
90 ::AEDisposeDesc(&specDesc);
91 }
92 }
902725ee 93 }
516d38cd
SC
94 else
95 {
96 err = paramErr ; // could be any error, only used for giving back wxID_CANCEL
e40298d5 97 }
e40298d5 98 }
516d38cd
SC
99
100 if ( disposeReply )
101 ::NavDisposeReply(&reply);
102
103 // apparently cancelling shouldn't change m_path
104 if ( err != noErr && err != userCanceledErr )
105 m_path = wxEmptyString ;
106
107 return (err == noErr) ? wxID_OK : wxID_CANCEL ;
e9576ca5
SC
108}
109
179e085f 110#endif