]> git.saurik.com Git - wxWidgets.git/blob - src/mac/dirdlg.cpp
removing dependancy on mac headers from public wx headers (eventually adding wx/mac...
[wxWidgets.git] / src / mac / dirdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dirdlg.cpp
3 // Purpose: wxDirDialog
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
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, const wxString& message,
36 const wxString& defaultPath,
37 long style, const wxPoint& pos)
38 {
39 wxASSERT_MSG( NavServicesAvailable() , "Navigation Services are not running" ) ;
40 m_message = message;
41 m_dialogStyle = style;
42 m_parent = parent;
43 m_path = defaultPath;
44 }
45
46 int wxDirDialog::ShowModal()
47 {
48 NavDialogOptions mNavOptions;
49 NavObjectFilterUPP mNavFilterUPP = NULL;
50 NavPreviewUPP mNavPreviewUPP = NULL ;
51 NavReplyRecord mNavReply;
52 AEDesc* mDefaultLocation = NULL ;
53 bool mSelectDefault = false ;
54
55 ::NavGetDefaultDialogOptions(&mNavOptions);
56
57 mNavFilterUPP = nil;
58 mNavPreviewUPP = nil;
59 mSelectDefault = false;
60 mNavReply.validRecord = false;
61 mNavReply.replacing = false;
62 mNavReply.isStationery = false;
63 mNavReply.translationNeeded = false;
64 mNavReply.selection.descriptorType = typeNull;
65 mNavReply.selection.dataHandle = nil;
66 mNavReply.keyScript = smSystemScript;
67 mNavReply.fileTranslation = nil;
68
69 // Set default location, the location
70 // that's displayed when the dialog
71 // first appears
72
73 if ( mDefaultLocation ) {
74
75 if (mSelectDefault) {
76 mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
77 } else {
78 mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
79 }
80 }
81
82 OSErr err = ::NavChooseFolder(
83 mDefaultLocation,
84 &mNavReply,
85 &mNavOptions,
86 NULL,
87 mNavFilterUPP,
88 0L); // User Data
89
90 if ( (err != noErr) && (err != userCanceledErr) ) {
91 m_path = "" ;
92 return wxID_CANCEL ;
93 }
94
95 if (mNavReply.validRecord) { // User chose a folder
96
97 FSSpec folderInfo;
98 FSSpec outFileSpec ;
99 AEDesc specDesc ;
100
101 OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSS, &specDesc);
102 if ( err != noErr ) {
103 m_path = "" ;
104 return wxID_CANCEL ;
105 }
106 folderInfo = **(FSSpec**) specDesc.dataHandle;
107 if (specDesc.dataHandle != nil) {
108 ::AEDisposeDesc(&specDesc);
109 }
110
111 // mNavReply.GetFileSpec(folderInfo);
112
113 // The FSSpec from NavChooseFolder is NOT the file spec
114 // for the folder. The parID field is actually the DirID
115 // of the folder itself, not the folder's parent, and
116 // the name field is empty. We must call PBGetCatInfo
117 // to get the parent DirID and folder name
118
119 Str255 name;
120 CInfoPBRec thePB; // Directory Info Parameter Block
121 thePB.dirInfo.ioCompletion = nil;
122 thePB.dirInfo.ioVRefNum = folderInfo.vRefNum; // Volume is right
123 thePB.dirInfo.ioDrDirID = folderInfo.parID; // Folder's DirID
124 thePB.dirInfo.ioNamePtr = name;
125 thePB.dirInfo.ioFDirIndex = -1; // Lookup using Volume and DirID
126
127 err = ::PBGetCatInfoSync(&thePB);
128 if ( err != noErr ) {
129 m_path = "" ;
130 return wxID_CANCEL ;
131 }
132 // Create cannonical FSSpec
133 ::FSMakeFSSpec(thePB.dirInfo.ioVRefNum, thePB.dirInfo.ioDrParID,
134 name, &outFileSpec);
135
136 // outFolderDirID = thePB.dirInfo.ioDrDirID;
137 m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ;
138 return wxID_OK ;
139 }
140 return wxID_CANCEL;
141 }
142