]> git.saurik.com Git - wxWidgets.git/blame - src/mac/dirdlg.cpp
This weeks interface and compile catchup
[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
e9576ca5
SC
35wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
36 const wxString& defaultPath,
37 long style, const wxPoint& pos)
38{
76a5e5d2 39 wxASSERT_MSG( NavServicesAvailable() , "Navigation Services are not running" ) ;
e9576ca5
SC
40 m_message = message;
41 m_dialogStyle = style;
42 m_parent = parent;
43 m_path = defaultPath;
44}
45
46int wxDirDialog::ShowModal()
47{
76a5e5d2
SC
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 }
519cb848 81
76a5e5d2
SC
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 }
5b781a67 94
76a5e5d2
SC
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 ) {
519cb848
SC
103 m_path = "" ;
104 return wxID_CANCEL ;
76a5e5d2
SC
105 }
106 folderInfo = **(FSSpec**) specDesc.dataHandle;
107 if (specDesc.dataHandle != nil) {
108 ::AEDisposeDesc(&specDesc);
519cb848 109 }
76a5e5d2
SC
110
111// mNavReply.GetFileSpec(folderInfo);
5b781a67 112
76a5e5d2
SC
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
5b781a67 118
76a5e5d2
SC
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
5b781a67 126
76a5e5d2
SC
127 err = ::PBGetCatInfoSync(&thePB);
128 if ( err != noErr ) {
5b781a67
SC
129 m_path = "" ;
130 return wxID_CANCEL ;
76a5e5d2
SC
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 ;
519cb848 139 }
76a5e5d2 140 return wxID_CANCEL;
e9576ca5
SC
141}
142