]>
Commit | Line | Data |
---|---|---|
489468fe | 1 | ///////////////////////////////////////////////////////////////////////////// |
524c47aa | 2 | // Name: src/osx/carbon/filedlg.cpp |
489468fe SC |
3 | // Purpose: wxFileDialog |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
489468fe SC |
7 | // Copyright: (c) Stefan Csomor |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #if wxUSE_FILEDLG | |
14 | ||
15 | #include "wx/filedlg.h" | |
16 | ||
17 | #ifndef WX_PRECOMP | |
18 | #include "wx/intl.h" | |
19 | #include "wx/app.h" | |
20 | #include "wx/utils.h" | |
21 | #include "wx/dialog.h" | |
22 | #endif | |
23 | ||
24 | #include "wx/tokenzr.h" | |
25 | #include "wx/filename.h" | |
26 | ||
1f0c8f31 | 27 | #include "wx/osx/private.h" |
691745ab | 28 | #include "wx/modalhook.h" |
489468fe SC |
29 | |
30 | #ifndef __DARWIN__ | |
31 | #include <Navigation.h> | |
32 | #include "PLStringFuncs.h" | |
33 | #endif | |
34 | ||
35 | IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase) | |
36 | ||
37 | // the data we need to pass to our standard file hook routine | |
38 | // includes a pointer to the dialog, a pointer to the standard | |
39 | // file reply record (so we can inspect the current selection) | |
40 | // and a copy of the "previous" file spec of the reply record | |
41 | // so we can see if the selection has changed | |
42 | ||
61ad44c7 | 43 | class OpenUserDataRec |
489468fe | 44 | { |
61ad44c7 SC |
45 | public: |
46 | OpenUserDataRec( wxFileDialog* dialog ); | |
ce00f59b | 47 | |
61ad44c7 SC |
48 | bool FilterCallback( AEDesc *theItem, void *info, NavFilterModes filterMode ); |
49 | void EventProc( NavEventCallbackMessage inSelector, NavCBRecPtr ioParams ); | |
489468fe | 50 | |
98daf410 SC |
51 | int GetCurrentFilter() const {return m_currentfilter;} |
52 | CFArrayRef GetMenuItems() const { return m_menuitems;} | |
ce00f59b VZ |
53 | |
54 | ||
61ad44c7 SC |
55 | private: |
56 | void EventProcCBEvent( NavCBRecPtr ioParams ); | |
57 | void EventProcCBEventMouseDown( NavCBRecPtr ioParams); | |
58 | void EventProcCBStart( NavCBRecPtr ioParams ); | |
59 | void EventProcCBPopupMenuSelect( NavCBRecPtr ioParams ); | |
60 | void EventProcCBCustomize( NavCBRecPtr ioParams ); | |
61 | void EventProcCBAdjustRect( NavCBRecPtr ioParams ); | |
62 | bool CheckFile( const wxString &filename , OSType type); | |
63 | void MakeUserDataRec( const wxString& filter); | |
ce00f59b | 64 | |
98daf410 SC |
65 | wxFileDialog* m_dialog; |
66 | int m_currentfilter; | |
67 | wxString m_defaultLocation; | |
68 | wxArrayString m_extensions; | |
69 | wxArrayLong m_filtermactypes; | |
70 | CFMutableArrayRef m_menuitems; | |
71 | wxArrayString m_name; | |
72 | bool m_saveMode; | |
73 | SInt16 m_lastRight; | |
74 | SInt16 m_lastBottom; | |
2f30930a | 75 | bool m_controlAdded; |
61ad44c7 | 76 | }; |
489468fe | 77 | |
61ad44c7 SC |
78 | OpenUserDataRec::OpenUserDataRec( wxFileDialog* d) |
79 | { | |
98daf410 | 80 | m_dialog = d; |
2f30930a | 81 | m_controlAdded = false; |
98daf410 | 82 | m_saveMode = m_dialog->HasFdFlag(wxFD_SAVE); |
ce00f59b | 83 | |
98daf410 SC |
84 | m_defaultLocation = m_dialog->GetDirectory(); |
85 | MakeUserDataRec(m_dialog->GetWildcard()); | |
86 | m_currentfilter = m_dialog->GetFilterIndex(); | |
ce00f59b | 87 | |
98daf410 | 88 | m_menuitems = NULL; |
ce00f59b | 89 | |
98daf410 | 90 | size_t numFilters = m_extensions.GetCount(); |
61ad44c7 SC |
91 | if (numFilters) |
92 | { | |
98daf410 | 93 | m_menuitems = CFArrayCreateMutable( kCFAllocatorDefault , |
61ad44c7 SC |
94 | numFilters , &kCFTypeArrayCallBacks ) ; |
95 | for ( size_t i = 0 ; i < numFilters ; ++i ) | |
96 | { | |
98daf410 | 97 | CFArrayAppendValue( m_menuitems , (CFStringRef) wxCFStringRef( m_name[i] ) ) ; |
61ad44c7 SC |
98 | } |
99 | } | |
98daf410 | 100 | m_lastRight = m_lastBottom = 0; |
61ad44c7 | 101 | } |
489468fe | 102 | |
61ad44c7 | 103 | void OpenUserDataRec::EventProc(NavEventCallbackMessage inSelector,NavCBRecPtr ioParams) |
489468fe | 104 | { |
61ad44c7 | 105 | switch (inSelector) |
489468fe | 106 | { |
61ad44c7 SC |
107 | case kNavCBEvent: |
108 | EventProcCBEvent(ioParams); | |
109 | break; | |
110 | case kNavCBStart: | |
111 | EventProcCBStart(ioParams); | |
112 | break; | |
113 | case kNavCBPopupMenuSelect: | |
114 | EventProcCBPopupMenuSelect(ioParams); | |
115 | break; | |
116 | case kNavCBCustomize: | |
117 | EventProcCBCustomize(ioParams); | |
118 | break; | |
119 | case kNavCBAdjustRect: | |
120 | EventProcCBAdjustRect(ioParams); | |
121 | break; | |
122 | default: | |
123 | break; | |
489468fe | 124 | } |
61ad44c7 SC |
125 | } |
126 | ||
127 | void OpenUserDataRec::EventProcCBEvent(NavCBRecPtr callBackParms) | |
128 | { | |
129 | switch (callBackParms->eventData.eventDataParms.event->what) | |
489468fe | 130 | { |
61ad44c7 | 131 | case mouseDown: |
489468fe | 132 | { |
61ad44c7 SC |
133 | EventProcCBEventMouseDown(callBackParms); |
134 | break; | |
489468fe | 135 | } |
ce00f59b | 136 | } |
61ad44c7 | 137 | } |
489468fe | 138 | |
61ad44c7 SC |
139 | void OpenUserDataRec::EventProcCBEventMouseDown(NavCBRecPtr callBackParms) |
140 | { | |
141 | EventRecord *evt = callBackParms->eventData.eventDataParms.event; | |
142 | Point where = evt->where; | |
98daf410 | 143 | QDGlobalToLocalPoint(GetWindowPort(callBackParms->window), &where); |
ce00f59b | 144 | |
61ad44c7 SC |
145 | ControlRef whichControl = FindControlUnderMouse(where, callBackParms->window, NULL); |
146 | if (whichControl != NULL) | |
147 | { | |
148 | ControlKind theKind; | |
149 | GetControlKind(whichControl, &theKind); | |
ce00f59b | 150 | |
98daf410 | 151 | // Moving the focus if we clicked in an focusable control |
ce00f59b VZ |
152 | if ((theKind.kind == kControlKindEditUnicodeText) || |
153 | (theKind.kind == kControlKindEditText) || | |
154 | (theKind.kind == kControlKindDataBrowser) || | |
98daf410 | 155 | (theKind.kind == kControlKindListBox)) |
489468fe | 156 | { |
61ad44c7 SC |
157 | ControlRef currentlyFocusedControl; |
158 | GetKeyboardFocus(callBackParms->window, ¤tlyFocusedControl); | |
159 | if (currentlyFocusedControl != whichControl) | |
160 | SetKeyboardFocus(callBackParms->window, whichControl, kControlFocusNextPart); | |
489468fe | 161 | } |
61ad44c7 | 162 | HandleControlClick(whichControl, where, evt->modifiers, NULL); |
489468fe | 163 | } |
61ad44c7 SC |
164 | } |
165 | ||
166 | void OpenUserDataRec::EventProcCBStart(NavCBRecPtr ioParams) | |
167 | { | |
98daf410 | 168 | if (!m_defaultLocation.empty()) |
61ad44c7 SC |
169 | { |
170 | // Set default location for the modern Navigation APIs | |
171 | // Apple Technical Q&A 1151 | |
172 | FSRef theFile; | |
98daf410 | 173 | wxMacPathToFSRef(m_defaultLocation, &theFile); |
61ad44c7 SC |
174 | AEDesc theLocation = { typeNull, NULL }; |
175 | if (noErr == ::AECreateDesc(typeFSRef, &theFile, sizeof(FSRef), &theLocation)) | |
176 | ::NavCustomControl(ioParams->context, kNavCtlSetLocation, (void *) &theLocation); | |
177 | } | |
ce00f59b | 178 | |
98daf410 | 179 | if( m_extensions.GetCount() > 0 ) |
489468fe | 180 | { |
61ad44c7 SC |
181 | NavMenuItemSpec menuItem; |
182 | memset( &menuItem, 0, sizeof(menuItem) ); | |
183 | menuItem.version = kNavMenuItemSpecVersion; | |
98daf410 | 184 | menuItem.menuType = m_currentfilter; |
61ad44c7 SC |
185 | ::NavCustomControl(ioParams->context, kNavCtlSelectCustomType, &menuItem); |
186 | } | |
ce00f59b | 187 | |
98daf410 | 188 | if (m_dialog->GetExtraControl()) |
61ad44c7 | 189 | { |
2f30930a | 190 | m_controlAdded = true; |
98daf410 | 191 | ControlRef ref = m_dialog->GetExtraControl()->GetPeer()->GetControlRef(); |
61ad44c7 SC |
192 | NavCustomControl(ioParams->context, kNavCtlAddControl, ref); |
193 | } | |
ce00f59b | 194 | |
61ad44c7 | 195 | } |
489468fe | 196 | |
61ad44c7 SC |
197 | void OpenUserDataRec::EventProcCBPopupMenuSelect(NavCBRecPtr ioParams) |
198 | { | |
199 | NavMenuItemSpec * menu = (NavMenuItemSpec *) ioParams->eventData.eventDataParms.param ; | |
98daf410 | 200 | const size_t numFilters = m_extensions.GetCount(); |
ce00f59b | 201 | |
61ad44c7 SC |
202 | if ( menu->menuType < numFilters ) |
203 | { | |
98daf410 SC |
204 | m_currentfilter = menu->menuType ; |
205 | if ( m_saveMode ) | |
489468fe | 206 | { |
61ad44c7 | 207 | int i = menu->menuType ; |
ce00f59b | 208 | |
61ad44c7 | 209 | // isolate the first extension string |
98daf410 | 210 | wxString firstExtension = m_extensions[i].BeforeFirst('|').BeforeFirst(';'); |
ce00f59b | 211 | |
61ad44c7 SC |
212 | wxString extension = firstExtension.AfterLast('.') ; |
213 | wxString sfilename ; | |
ce00f59b | 214 | |
61ad44c7 SC |
215 | wxCFStringRef cfString( wxCFRetain( NavDialogGetSaveFileName( ioParams->context ) ) ); |
216 | sfilename = cfString.AsString() ; | |
ce00f59b | 217 | |
61ad44c7 SC |
218 | int pos = sfilename.Find('.', true) ; |
219 | if ( pos != wxNOT_FOUND && extension != wxT("*") ) | |
489468fe | 220 | { |
61ad44c7 SC |
221 | sfilename = sfilename.Left(pos+1)+extension ; |
222 | cfString = wxCFStringRef( sfilename , wxFONTENCODING_DEFAULT ) ; | |
223 | NavDialogSetSaveFileName( ioParams->context , cfString ) ; | |
489468fe SC |
224 | } |
225 | } | |
226 | } | |
227 | } | |
228 | ||
61ad44c7 | 229 | void OpenUserDataRec::EventProcCBCustomize(NavCBRecPtr ioParams) |
489468fe | 230 | { |
98daf410 | 231 | wxWindow* control = m_dialog->GetExtraControl(); |
ce00f59b | 232 | |
98daf410 | 233 | if ( control ) |
61ad44c7 | 234 | { |
98daf410 | 235 | SInt16 neededRight, neededBottom; |
ce00f59b | 236 | |
98daf410 SC |
237 | wxSize size = m_dialog->GetExtraControl()->GetSize(); |
238 | neededRight = ioParams->customRect.left + size.x; | |
239 | neededBottom = ioParams->customRect.top + size.y; | |
ce00f59b | 240 | |
98daf410 SC |
241 | if (ioParams->customRect.right == 0 && ioParams->customRect.bottom == 0) |
242 | { | |
243 | ioParams->customRect.right = neededRight; | |
244 | ioParams->customRect.bottom = neededBottom; | |
245 | } | |
ce00f59b | 246 | else |
98daf410 SC |
247 | { |
248 | if ( ioParams->customRect.right != m_lastRight ) | |
249 | { | |
250 | if ( ioParams->customRect.right < neededRight ) | |
251 | ioParams->customRect.right = neededRight; | |
252 | } | |
253 | if ( ioParams->customRect.bottom != m_lastBottom ) | |
254 | { | |
255 | if ( ioParams->customRect.bottom < neededBottom ) | |
256 | ioParams->customRect.bottom = neededBottom; | |
257 | } | |
258 | } | |
259 | m_lastRight = ioParams->customRect.right; | |
260 | m_lastBottom = ioParams->customRect.bottom; | |
61ad44c7 SC |
261 | } |
262 | } | |
263 | ||
264 | void OpenUserDataRec::EventProcCBAdjustRect(NavCBRecPtr ioParams) | |
265 | { | |
98daf410 | 266 | wxWindow* control = m_dialog->GetExtraControl(); |
ce00f59b | 267 | |
2f30930a | 268 | if ( control && m_controlAdded) |
98daf410 | 269 | { |
ce00f59b | 270 | control->SetSize(ioParams->customRect.left , ioParams->customRect.top, |
2f30930a SC |
271 | ioParams->customRect.right - ioParams->customRect.left, |
272 | ioParams->customRect.bottom - ioParams->customRect.top); | |
98daf410 | 273 | } |
61ad44c7 SC |
274 | } |
275 | ||
276 | void OpenUserDataRec::MakeUserDataRec( const wxString& filter ) | |
277 | { | |
489468fe SC |
278 | if ( !filter.empty() ) |
279 | { | |
280 | wxString filter2(filter) ; | |
281 | int filterIndex = 0; | |
282 | bool isName = true ; | |
283 | wxString current ; | |
284 | ||
285 | for ( unsigned int i = 0; i < filter2.length() ; i++ ) | |
286 | { | |
287 | if ( filter2.GetChar(i) == wxT('|') ) | |
288 | { | |
289 | if ( isName ) | |
290 | { | |
98daf410 | 291 | m_name.Add( current ) ; |
489468fe SC |
292 | } |
293 | else | |
294 | { | |
98daf410 | 295 | m_extensions.Add( current ) ; |
489468fe SC |
296 | ++filterIndex ; |
297 | } | |
298 | ||
299 | isName = !isName ; | |
300 | current = wxEmptyString ; | |
301 | } | |
302 | else | |
303 | { | |
304 | current += filter2.GetChar(i) ; | |
305 | } | |
306 | } | |
307 | // we allow for compatibility reason to have a single filter expression (like *.*) without | |
308 | // an explanatory text, in that case the first part is name and extension at the same time | |
309 | ||
310 | wxASSERT_MSG( filterIndex == 0 || !isName , wxT("incorrect format of format string") ) ; | |
311 | if ( current.empty() ) | |
98daf410 | 312 | m_extensions.Add( m_name[filterIndex] ) ; |
489468fe | 313 | else |
98daf410 | 314 | m_extensions.Add( current ) ; |
489468fe | 315 | if ( filterIndex == 0 || isName ) |
98daf410 | 316 | m_name.Add( current ) ; |
489468fe SC |
317 | |
318 | ++filterIndex ; | |
319 | ||
98daf410 | 320 | const size_t extCount = m_extensions.GetCount(); |
489468fe SC |
321 | for ( size_t i = 0 ; i < extCount; i++ ) |
322 | { | |
323 | wxUint32 fileType, creator; | |
98daf410 | 324 | wxString extension = m_extensions[i]; |
489468fe SC |
325 | |
326 | // Remove leading '*' | |
6636ef8d | 327 | if ( !extension.empty() && (extension.GetChar(0) == '*') ) |
489468fe SC |
328 | extension = extension.Mid( 1 ); |
329 | ||
330 | // Remove leading '.' | |
6636ef8d | 331 | if ( !extension.empty() && (extension.GetChar(0) == '.') ) |
489468fe SC |
332 | extension = extension.Mid( 1 ); |
333 | ||
334 | if (wxFileName::MacFindDefaultTypeAndCreator( extension, &fileType, &creator )) | |
98daf410 | 335 | m_filtermactypes.Add( (OSType)fileType ); |
489468fe | 336 | else |
98daf410 | 337 | m_filtermactypes.Add( '****' ); // We'll fail safe if it's not recognized |
489468fe SC |
338 | } |
339 | } | |
340 | } | |
341 | ||
61ad44c7 | 342 | bool OpenUserDataRec::CheckFile( const wxString &filename , OSType type) |
489468fe SC |
343 | { |
344 | wxString file(filename) ; | |
345 | file.MakeUpper() ; | |
346 | ||
98daf410 | 347 | if ( m_extensions.GetCount() > 0 ) |
489468fe SC |
348 | { |
349 | //for ( int i = 0 ; i < data->numfilters ; ++i ) | |
98daf410 SC |
350 | int i = m_currentfilter ; |
351 | if ( m_extensions[i].Right(2) == wxT(".*") ) | |
489468fe SC |
352 | return true ; |
353 | ||
354 | { | |
98daf410 | 355 | if ( type == (OSType)m_filtermactypes[i] ) |
489468fe SC |
356 | return true ; |
357 | ||
98daf410 | 358 | wxStringTokenizer tokenizer( m_extensions[i] , wxT(";") ) ; |
489468fe SC |
359 | while ( tokenizer.HasMoreTokens() ) |
360 | { | |
361 | wxString extension = tokenizer.GetNextToken() ; | |
362 | if ( extension.GetChar(0) == '*' ) | |
363 | extension = extension.Mid(1) ; | |
364 | extension.MakeUpper(); | |
365 | ||
366 | if ( file.length() >= extension.length() && extension == file.Right(extension.length() ) ) | |
367 | return true ; | |
368 | } | |
369 | } | |
370 | ||
371 | return false ; | |
372 | } | |
373 | ||
374 | return true ; | |
375 | } | |
376 | ||
61ad44c7 SC |
377 | bool OpenUserDataRec::FilterCallback( |
378 | AEDesc *theItem, | |
379 | void *info, | |
380 | NavFilterModes filterMode ) | |
489468fe | 381 | { |
489468fe SC |
382 | if (filterMode == kNavFilteringBrowserList) |
383 | { | |
384 | // We allow navigation to all folders. For files, we check against the current | |
385 | // filter string. | |
386 | // However, packages should be dealt with like files and not like folders. So | |
387 | // check if a folder is a package before deciding what to do. | |
388 | NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo*) info ; | |
389 | FSRef fsref; | |
ce00f59b | 390 | |
489468fe SC |
391 | if ( theInfo->isFolder ) |
392 | { | |
393 | // check bundle bit (using Finder Services - used by OS9 on some bundles) | |
394 | FSCatalogInfo catalogInfo; | |
395 | if (FSGetCatalogInfo (&fsref, kFSCatInfoFinderInfo, &catalogInfo, NULL, NULL, NULL) != noErr) | |
396 | return true; | |
ce00f59b | 397 | |
489468fe SC |
398 | // Check bundle item (using Launch Services - used by OS-X through info.plist or APP) |
399 | LSItemInfoRecord lsInfo; | |
400 | if (LSCopyItemInfoForRef(&fsref, kLSRequestBasicFlagsOnly, &lsInfo ) != noErr) | |
401 | return true; | |
ce00f59b | 402 | |
489468fe SC |
403 | // If it's not a bundle, then it's a normal folder and it passes our filter |
404 | FileInfo *fileInfo = (FileInfo *) catalogInfo.finderInfo; | |
405 | if ( !(fileInfo->finderFlags & kHasBundle) && | |
61ad44c7 | 406 | !(lsInfo.flags & (kLSItemInfoIsApplication | kLSItemInfoIsPackage)) ) |
489468fe SC |
407 | return true; |
408 | } | |
409 | else | |
410 | { | |
411 | AECoerceDesc (theItem, typeFSRef, theItem); | |
412 | if ( AEGetDescData (theItem, &fsref, sizeof (FSRef)) == noErr) | |
413 | { | |
414 | wxString file = wxMacFSRefToPath( &fsref ) ; | |
61ad44c7 | 415 | return CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType ) ; |
489468fe SC |
416 | } |
417 | } | |
418 | } | |
ce00f59b | 419 | |
489468fe SC |
420 | return true; |
421 | } | |
422 | ||
61ad44c7 SC |
423 | // end wxmac |
424 | ||
425 | pascal Boolean CrossPlatformFilterCallback( | |
426 | AEDesc *theItem, | |
427 | void *info, | |
428 | void *callBackUD, | |
429 | NavFilterModes filterMode ); | |
430 | ||
431 | pascal Boolean CrossPlatformFilterCallback( | |
432 | AEDesc *theItem, | |
433 | void *info, | |
434 | void *callBackUD, | |
435 | NavFilterModes filterMode ) | |
436 | { | |
437 | OpenUserDataRec* data = (OpenUserDataRec*) callBackUD ; | |
438 | return data->FilterCallback(theItem,info,filterMode); | |
439 | } | |
440 | ||
441 | static pascal void NavEventProc( | |
442 | NavEventCallbackMessage inSelector, | |
443 | NavCBRecPtr ioParams, | |
444 | NavCallBackUserData ioUserData ); | |
445 | ||
446 | static NavEventUPP sStandardNavEventFilter = NewNavEventUPP(NavEventProc); | |
447 | ||
448 | static pascal void NavEventProc( | |
449 | NavEventCallbackMessage inSelector, | |
450 | NavCBRecPtr ioParams, | |
451 | NavCallBackUserData ioUserData ) | |
452 | { | |
453 | OpenUserDataRec * data = ( OpenUserDataRec *) ioUserData ; | |
454 | data->EventProc(inSelector, ioParams); | |
455 | } | |
456 | ||
457 | ||
aad2997b VZ |
458 | void wxFileDialog::Init() |
459 | { | |
460 | } | |
461 | ||
462 | void wxFileDialog::Create( | |
61ad44c7 SC |
463 | wxWindow *parent, const wxString& message, |
464 | const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard, | |
465 | long style, const wxPoint& pos, const wxSize& sz, const wxString& name) | |
61ad44c7 | 466 | { |
aad2997b VZ |
467 | wxFileDialogBase::Create(parent, message, defaultDir, defaultFileName, wildCard, style, pos, sz, name); |
468 | ||
61ad44c7 SC |
469 | wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ; |
470 | } | |
471 | ||
2f30930a SC |
472 | void wxFileDialog::SetupExtraControls(WXWindow nativeWindow) |
473 | { | |
0e05b13c | 474 | wxTopLevelWindow::Create( GetParent(), nativeWindow ); |
ce00f59b | 475 | |
2f30930a SC |
476 | if (HasExtraControlCreator()) |
477 | { | |
478 | CreateExtraControl(); | |
479 | } | |
480 | } | |
481 | ||
489468fe SC |
482 | int wxFileDialog::ShowModal() |
483 | { | |
691745ab | 484 | WX_HOOK_MODAL_DIALOG(); |
643e9cf9 | 485 | |
8b558f12 JS |
486 | m_paths.Empty(); |
487 | m_fileNames.Empty(); | |
ce00f59b | 488 | |
489468fe SC |
489 | OSErr err; |
490 | NavDialogCreationOptions dialogCreateOptions; | |
491 | ||
492 | // set default options | |
493 | ::NavGetDefaultDialogCreationOptions(&dialogCreateOptions); | |
494 | ||
495 | // this was always unset in the old code | |
496 | dialogCreateOptions.optionFlags &= ~kNavSelectDefaultLocation; | |
497 | ||
498 | wxCFStringRef message(m_message, GetFont().GetEncoding()); | |
499 | dialogCreateOptions.windowTitle = message; | |
500 | ||
501 | wxCFStringRef defaultFileName(m_fileName, GetFont().GetEncoding()); | |
502 | dialogCreateOptions.saveFileName = defaultFileName; | |
503 | ||
489468fe SC |
504 | NavDialogRef dialog; |
505 | NavObjectFilterUPP navFilterUPP = NULL; | |
61ad44c7 | 506 | OpenUserDataRec myData( this ); |
ce00f59b | 507 | |
61ad44c7 | 508 | dialogCreateOptions.popupExtension = myData.GetMenuItems(); |
ce00f59b | 509 | |
489468fe SC |
510 | if (HasFdFlag(wxFD_SAVE)) |
511 | { | |
489468fe SC |
512 | dialogCreateOptions.optionFlags |= kNavDontAutoTranslate; |
513 | dialogCreateOptions.optionFlags |= kNavDontAddTranslateItems; | |
61ad44c7 | 514 | if (dialogCreateOptions.popupExtension == NULL) |
489468fe SC |
515 | dialogCreateOptions.optionFlags |= kNavNoTypePopup; |
516 | ||
517 | // The extension is important | |
61ad44c7 | 518 | if ( dialogCreateOptions.popupExtension == NULL || CFArrayGetCount(dialogCreateOptions.popupExtension)<2) |
489468fe SC |
519 | dialogCreateOptions.optionFlags |= kNavPreserveSaveFileExtension; |
520 | ||
521 | if (!(m_windowStyle & wxFD_OVERWRITE_PROMPT)) | |
522 | dialogCreateOptions.optionFlags |= kNavDontConfirmReplacement; | |
523 | ||
524 | err = ::NavCreatePutFileDialog( | |
525 | &dialogCreateOptions, | |
526 | kNavGenericSignature, // Suppresses the 'Default' (top) menu item | |
527 | kNavGenericSignature, | |
528 | sStandardNavEventFilter, | |
529 | &myData, // for defaultLocation | |
530 | &dialog ); | |
531 | } | |
532 | else | |
533 | { | |
534 | // let the user select bundles/programs in dialogs | |
535 | dialogCreateOptions.optionFlags |= kNavSupportPackages; | |
536 | ||
537 | navFilterUPP = NewNavObjectFilterUPP(CrossPlatformFilterCallback); | |
538 | err = ::NavCreateGetFileDialog( | |
539 | &dialogCreateOptions, | |
540 | NULL, // NavTypeListHandle | |
541 | sStandardNavEventFilter, | |
542 | NULL, // NavPreviewUPP | |
543 | navFilterUPP, | |
544 | (void *) &myData, // inClientData | |
545 | &dialog ); | |
546 | } | |
ce00f59b | 547 | |
2f30930a | 548 | SetupExtraControls(NavDialogGetWindow(dialog)); |
ce00f59b | 549 | |
489468fe | 550 | if (err == noErr) |
445e564f SC |
551 | { |
552 | wxDialog::OSXBeginModalDialog(); | |
489468fe | 553 | err = ::NavDialogRun(dialog); |
445e564f SC |
554 | wxDialog::OSXEndModalDialog(); |
555 | } | |
489468fe SC |
556 | |
557 | // clean up filter related data, etc. | |
558 | if (navFilterUPP) | |
559 | ::DisposeNavObjectFilterUPP(navFilterUPP); | |
560 | ||
561 | if (err != noErr) | |
562 | { | |
563 | ::NavDialogDispose(dialog); | |
564 | return wxID_CANCEL; | |
565 | } | |
566 | ||
567 | NavReplyRecord navReply; | |
568 | err = ::NavDialogGetReply(dialog, &navReply); | |
569 | if (err == noErr && navReply.validRecord) | |
570 | { | |
571 | AEKeyword theKeyword; | |
572 | DescType actualType; | |
573 | Size actualSize; | |
574 | FSRef theFSRef; | |
575 | wxString thePath ; | |
576 | long count; | |
577 | ||
61ad44c7 | 578 | m_filterIndex = myData.GetCurrentFilter(); |
489468fe SC |
579 | ::AECountItems( &navReply.selection, &count ); |
580 | for (long i = 1; i <= count; ++i) | |
581 | { | |
582 | err = ::AEGetNthPtr( | |
583 | &(navReply.selection), i, typeFSRef, &theKeyword, &actualType, | |
584 | &theFSRef, sizeof(theFSRef), &actualSize ); | |
585 | if (err != noErr) | |
586 | break; | |
587 | ||
588 | if (HasFdFlag(wxFD_SAVE)) | |
589 | thePath = wxMacFSRefToPath( &theFSRef, navReply.saveFileName ); | |
590 | else | |
591 | thePath = wxMacFSRefToPath( &theFSRef ); | |
592 | ||
593 | if (!thePath) | |
594 | { | |
595 | ::NavDisposeReply(&navReply); | |
596 | ::NavDialogDispose(dialog); | |
597 | return wxID_CANCEL; | |
598 | } | |
599 | ||
600 | m_path = thePath; | |
601 | m_paths.Add(m_path); | |
602 | m_fileName = wxFileNameFromPath(m_path); | |
603 | m_fileNames.Add(m_fileName); | |
604 | } | |
605 | ||
606 | // set these to the first hit | |
607 | m_path = m_paths[0]; | |
608 | m_fileName = wxFileNameFromPath(m_path); | |
609 | m_dir = wxPathOnly(m_path); | |
610 | } | |
611 | ||
d623e8b1 | 612 | UnsubclassWin(); |
489468fe SC |
613 | ::NavDisposeReply(&navReply); |
614 | ::NavDialogDispose(dialog); | |
615 | ||
616 | return (err == noErr) ? wxID_OK : wxID_CANCEL; | |
617 | } | |
618 | ||
61ad44c7 SC |
619 | bool wxFileDialog::SupportsExtraControl() const |
620 | { | |
621 | return true; | |
622 | } | |
623 | ||
489468fe SC |
624 | #endif // wxUSE_FILEDLG |
625 |