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