]> git.saurik.com Git - wxWidgets.git/blame - 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
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/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
2646f485 32IMPLEMENT_CLASS(wxDirDialog, wxDialog)
2646f485
SC
33
34wxDirDialog::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
49int 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 ;
18f3decb 57
2646f485
SC
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;
18f3decb 71
2646f485
SC
72 // Set default location, the location
73 // that's displayed when the dialog
74 // first appears
18f3decb 75
2646f485 76 if ( mDefaultLocation ) {
18f3decb 77
2646f485
SC
78 if (mSelectDefault) {
79 mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
80 } else {
81 mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
82 }
83 }
18f3decb 84
2646f485
SC
85 OSErr err = ::NavChooseFolder(
86 mDefaultLocation,
87 &mNavReply,
88 &mNavOptions,
89 NULL,
90 mNavFilterUPP,
91 0L); // User Data
18f3decb 92
2646f485 93 if ( (err != noErr) && (err != userCanceledErr) ) {
18f3decb 94 m_path = wxEmptyString ;
2646f485
SC
95 return wxID_CANCEL ;
96 }
97
98 if (mNavReply.validRecord) { // User chose a folder
18f3decb 99
2646f485
SC
100 FSSpec folderInfo;
101 FSSpec outFileSpec ;
102 AEDesc specDesc ;
18f3decb 103
2646f485
SC
104 OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSS, &specDesc);
105 if ( err != noErr ) {
18f3decb 106 m_path = wxEmptyString ;
2646f485 107 return wxID_CANCEL ;
18f3decb 108 }
2646f485
SC
109 folderInfo = **(FSSpec**) specDesc.dataHandle;
110 if (specDesc.dataHandle != nil) {
111 ::AEDisposeDesc(&specDesc);
112 }
113
114// mNavReply.GetFileSpec(folderInfo);
18f3decb 115
2646f485
SC
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
18f3decb 121
2646f485
SC
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
18f3decb 129
2646f485
SC
130 err = ::PBGetCatInfoSync(&thePB);
131 if ( err != noErr ) {
18f3decb 132 m_path = wxEmptyString;
2646f485 133 return wxID_CANCEL ;
18f3decb 134 }
2646f485
SC
135 // Create cannonical FSSpec
136 ::FSMakeFSSpec(thePB.dirInfo.ioVRefNum, thePB.dirInfo.ioDrParID,
137 name, &outFileSpec);
18f3decb 138
2646f485
SC
139 // outFolderDirID = thePB.dirInfo.ioDrDirID;
140 m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ;
141 return wxID_OK ;
142 }
143 return wxID_CANCEL;
144}