]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/dirdlg.cpp
fixes for mouse handling on 10.2 systems
[wxWidgets.git] / src / mac / classic / dirdlg.cpp
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
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
23 #include "wx/mac/private.h"
24
25 #ifdef __DARWIN__
26 #include <Carbon/Carbon.h>
27 #else
28 #include <Navigation.h>
29 #endif
30
31 #if !USE_SHARED_LIBRARY
32 IMPLEMENT_CLASS(wxDirDialog, wxDialog)
33 #endif
34
35 wxDirDialog::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))
42 {
43 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
44 m_message = message;
45 m_dialogStyle = style;
46 m_parent = parent;
47 m_path = defaultPath;
48 }
49
50 int wxDirDialog::ShowModal()
51 {
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 }
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) ) {
95 m_path = wxT("") ;
96 return wxID_CANCEL ;
97 }
98
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 ) {
107 m_path = wxT("") ;
108 return wxID_CANCEL ;
109 }
110 folderInfo = **(FSSpec**) specDesc.dataHandle;
111 if (specDesc.dataHandle != nil) {
112 ::AEDisposeDesc(&specDesc);
113 }
114
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 ) {
133 m_path = wxT("") ;
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;
145 }
146