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