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