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