]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/dirdlg.cpp
remove GetImageList(int)
[wxWidgets.git] / src / mac / classic / 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 #include "wx/defs.h"
13 #include "wx/utils.h"
14 #include "wx/dialog.h"
15 #include "wx/dirdlg.h"
16
17 #include "wx/cmndata.h"
18
19 #include "wx/mac/private.h"
20
21 #ifdef __DARWIN__
22 #include <Carbon/Carbon.h>
23 #else
24 #include <Navigation.h>
25 #endif
26
27 IMPLEMENT_CLASS(wxDirDialog, wxDialog)
28
29 wxDirDialog::wxDirDialog(wxWindow *parent,
30 const wxString& message,
31 const wxString& defaultPath,
32 long style,
33 const wxPoint& WXUNUSED(pos),
34 const wxSize& WXUNUSED(size),
35 const wxString& WXUNUSED(name))
36 {
37 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
38 m_message = message;
39 m_dialogStyle = style;
40 m_parent = parent;
41 m_path = defaultPath;
42 }
43
44 int wxDirDialog::ShowModal()
45 {
46 NavDialogOptions mNavOptions;
47 NavObjectFilterUPP mNavFilterUPP = NULL;
48 NavPreviewUPP mNavPreviewUPP = NULL ;
49 NavReplyRecord mNavReply;
50 AEDesc* mDefaultLocation = NULL ;
51 bool mSelectDefault = false ;
52
53 ::NavGetDefaultDialogOptions(&mNavOptions);
54
55 mNavFilterUPP = nil;
56 mNavPreviewUPP = nil;
57 mSelectDefault = false;
58 mNavReply.validRecord = false;
59 mNavReply.replacing = false;
60 mNavReply.isStationery = false;
61 mNavReply.translationNeeded = false;
62 mNavReply.selection.descriptorType = typeNull;
63 mNavReply.selection.dataHandle = nil;
64 mNavReply.keyScript = smSystemScript;
65 mNavReply.fileTranslation = nil;
66
67 // Set default location, the location
68 // that's displayed when the dialog
69 // first appears
70
71 if ( mDefaultLocation ) {
72
73 if (mSelectDefault) {
74 mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
75 } else {
76 mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
77 }
78 }
79
80 OSErr err = ::NavChooseFolder(
81 mDefaultLocation,
82 &mNavReply,
83 &mNavOptions,
84 NULL,
85 mNavFilterUPP,
86 0L); // User Data
87
88 if ( (err != noErr) && (err != userCanceledErr) ) {
89 m_path = wxT("") ;
90 return wxID_CANCEL ;
91 }
92
93 if (mNavReply.validRecord) { // User chose a folder
94
95 FSSpec folderInfo;
96 FSSpec outFileSpec ;
97 AEDesc specDesc ;
98
99 OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSS, &specDesc);
100 if ( err != noErr ) {
101 m_path = wxT("") ;
102 return wxID_CANCEL ;
103 }
104 folderInfo = **(FSSpec**) specDesc.dataHandle;
105 if (specDesc.dataHandle != nil) {
106 ::AEDisposeDesc(&specDesc);
107 }
108
109 // mNavReply.GetFileSpec(folderInfo);
110
111 // The FSSpec from NavChooseFolder is NOT the file spec
112 // for the folder. The parID field is actually the DirID
113 // of the folder itself, not the folder's parent, and
114 // the name field is empty. We must call PBGetCatInfo
115 // to get the parent DirID and folder name
116
117 Str255 name;
118 CInfoPBRec thePB; // Directory Info Parameter Block
119 thePB.dirInfo.ioCompletion = nil;
120 thePB.dirInfo.ioVRefNum = folderInfo.vRefNum; // Volume is right
121 thePB.dirInfo.ioDrDirID = folderInfo.parID; // Folder's DirID
122 thePB.dirInfo.ioNamePtr = name;
123 thePB.dirInfo.ioFDirIndex = -1; // Lookup using Volume and DirID
124
125 err = ::PBGetCatInfoSync(&thePB);
126 if ( err != noErr ) {
127 m_path = wxT("") ;
128 return wxID_CANCEL ;
129 }
130 // Create cannonical FSSpec
131 ::FSMakeFSSpec(thePB.dirInfo.ioVRefNum, thePB.dirInfo.ioDrParID,
132 name, &outFileSpec);
133
134 // outFolderDirID = thePB.dirInfo.ioDrDirID;
135 m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ;
136 return wxID_OK ;
137 }
138 return wxID_CANCEL;
139 }
140