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