]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dirdlg.cpp
If we have multiple filters in a Save dialog, don't use
[wxWidgets.git] / src / mac / carbon / dirdlg.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: dirdlg.cpp
3// Purpose: wxDirDialog
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
e9576ca5
SC
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{
427ff662 43 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
e9576ca5
SC
44 m_message = message;
45 m_dialogStyle = style;
46 m_parent = parent;
e40298d5 47 m_path = defaultPath;
e9576ca5
SC
48}
49
50int wxDirDialog::ShowModal()
51{
e40298d5
JS
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);
76a5e5d2 60
e40298d5
JS
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 }
85
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) ) {
427ff662 95 m_path = wxT("") ;
e40298d5
JS
96 return wxID_CANCEL ;
97 }
5b781a67 98
e40298d5
JS
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 ) {
427ff662 107 m_path = wxT("") ;
e40298d5
JS
108 return wxID_CANCEL ;
109 }
110 folderInfo = **(FSSpec**) specDesc.dataHandle;
111 if (specDesc.dataHandle != nil) {
112 ::AEDisposeDesc(&specDesc);
113 }
76a5e5d2 114
e40298d5
JS
115// mNavReply.GetFileSpec(folderInfo);
116
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
122
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
130
131 err = ::PBGetCatInfoSync(&thePB);
132 if ( err != noErr ) {
427ff662 133 m_path = wxT("") ;
e40298d5
JS
134 return wxID_CANCEL ;
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 ;
143 }
144 return wxID_CANCEL;
e9576ca5
SC
145}
146