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