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