]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dirdlg.cpp
Don't copy the NULL char into the clipboard. Most Mac apps will
[wxWidgets.git] / src / mac / carbon / dirdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dirdlg.cpp
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "dirdlg.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #if wxUSE_DIRDLG
19
20 #include "wx/utils.h"
21 #include "wx/dialog.h"
22 #include "wx/dirdlg.h"
23
24 #include "wx/cmndata.h"
25
26 #include "wx/mac/private.h"
27
28 #ifdef __DARWIN__
29 #include <Carbon/Carbon.h>
30 #else
31 #include <Navigation.h>
32 #endif
33
34 #if !USE_SHARED_LIBRARY
35 IMPLEMENT_CLASS(wxDirDialog, wxDialog)
36 #endif
37
38 wxDirDialog::wxDirDialog(wxWindow *parent,
39 const wxString& message,
40 const wxString& defaultPath,
41 long style,
42 const wxPoint& WXUNUSED(pos),
43 const wxSize& WXUNUSED(size),
44 const wxString& WXUNUSED(name))
45 {
46 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
47 m_message = message;
48 m_dialogStyle = style;
49 m_parent = parent;
50 m_path = defaultPath;
51 }
52
53 int wxDirDialog::ShowModal()
54 {
55 NavDialogOptions mNavOptions;
56 NavObjectFilterUPP mNavFilterUPP = NULL;
57 NavPreviewUPP mNavPreviewUPP = NULL ;
58 NavReplyRecord mNavReply;
59 AEDesc* mDefaultLocation = NULL ;
60 bool mSelectDefault = false ;
61
62 ::NavGetDefaultDialogOptions(&mNavOptions);
63
64 mNavFilterUPP = nil;
65 mNavPreviewUPP = nil;
66 mSelectDefault = false;
67 mNavReply.validRecord = false;
68 mNavReply.replacing = false;
69 mNavReply.isStationery = false;
70 mNavReply.translationNeeded = false;
71 mNavReply.selection.descriptorType = typeNull;
72 mNavReply.selection.dataHandle = nil;
73 mNavReply.keyScript = smSystemScript;
74 mNavReply.fileTranslation = nil;
75
76 // Set default location, the location
77 // that's displayed when the dialog
78 // first appears
79
80 if ( mDefaultLocation ) {
81
82 if (mSelectDefault) {
83 mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
84 } else {
85 mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
86 }
87 }
88
89 OSErr err = ::NavChooseFolder(
90 mDefaultLocation,
91 &mNavReply,
92 &mNavOptions,
93 NULL,
94 mNavFilterUPP,
95 0L); // User Data
96
97 if ( (err != noErr) && (err != userCanceledErr) ) {
98 m_path = wxT("") ;
99 return wxID_CANCEL ;
100 }
101
102 if (mNavReply.validRecord) { // User chose a folder
103
104 FSRef folderInfo;
105 AEDesc specDesc ;
106
107 OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSRef, &specDesc);
108 if ( err != noErr ) {
109 m_path = wxT("") ;
110 return wxID_CANCEL ;
111 }
112 folderInfo = **(FSRef**) specDesc.dataHandle;
113 if (specDesc.dataHandle != nil) {
114 ::AEDisposeDesc(&specDesc);
115 }
116
117 m_path = wxMacFSRefToPath( &folderInfo ) ;
118 return wxID_OK ;
119 }
120 return wxID_CANCEL;
121 }
122
123 #endif