]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: filedlg.cpp | |
2f1ae414 | 3 | // Purpose: wxFileDialog |
e9576ca5 SC |
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 "filedlg.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/defs.h" | |
5fde6fcc | 17 | #include "wx/app.h" |
e9576ca5 SC |
18 | #include "wx/utils.h" |
19 | #include "wx/dialog.h" | |
20 | #include "wx/filedlg.h" | |
21 | #include "wx/intl.h" | |
fe35d097 | 22 | #include "wx/tokenzr.h" |
e9576ca5 | 23 | |
f11bdd03 | 24 | #ifndef __DARWIN__ |
03e11df5 GD |
25 | #include "PLStringFuncs.h" |
26 | #endif | |
5b781a67 | 27 | |
2f1ae414 | 28 | #if !USE_SHARED_LIBRARY |
e9576ca5 | 29 | IMPLEMENT_CLASS(wxFileDialog, wxDialog) |
2f1ae414 | 30 | #endif |
e9576ca5 | 31 | |
519cb848 SC |
32 | // begin wxmac |
33 | ||
f11bdd03 | 34 | #ifndef __DARWIN__ |
03e11df5 GD |
35 | #include <Navigation.h> |
36 | #endif | |
5b781a67 | 37 | |
da2b4b7a GD |
38 | #include "MoreFiles.h" |
39 | #include "MoreFilesExtras.h" | |
519cb848 | 40 | |
5b781a67 SC |
41 | extern bool gUseNavServices ; |
42 | ||
4d4d8bbf SC |
43 | // the data we need to pass to our standard file hook routine |
44 | // includes a pointer to the dialog, a pointer to the standard | |
45 | // file reply record (so we can inspect the current selection) | |
46 | // and a copy of the "previous" file spec of the reply record | |
47 | // so we can see if the selection has changed | |
48 | ||
49 | const int kwxMacFileTypes = 10 ; | |
50 | ||
51 | struct OpenUserDataRec { | |
52 | int currentfilter ; | |
53 | wxString name [kwxMacFileTypes] ; | |
54 | wxString extensions[kwxMacFileTypes] ; | |
55 | OSType filtermactypes[kwxMacFileTypes] ; | |
56 | int numfilters ; | |
57 | }; | |
58 | typedef struct OpenUserDataRec | |
59 | OpenUserDataRec, *OpenUserDataRecPtr; | |
60 | ||
5b781a67 SC |
61 | static pascal void NavEventProc( |
62 | NavEventCallbackMessage inSelector, | |
63 | NavCBRecPtr ioParams, | |
64 | NavCallBackUserData ioUserData); | |
65 | ||
66 | #if TARGET_CARBON | |
67 | static NavEventUPP sStandardNavEventFilter = NewNavEventUPP(NavEventProc); | |
68 | #else | |
69 | static NavEventUPP sStandardNavEventFilter = NewNavEventProc(NavEventProc); | |
70 | #endif | |
71 | ||
72 | static pascal void | |
73 | NavEventProc( | |
74 | NavEventCallbackMessage inSelector, | |
75 | NavCBRecPtr ioParams, | |
4d4d8bbf | 76 | NavCallBackUserData ioUserData ) |
5b781a67 | 77 | { |
4d4d8bbf | 78 | OpenUserDataRec * data = ( OpenUserDataRec *) ioUserData ; |
5b781a67 SC |
79 | if (inSelector == kNavCBEvent) { |
80 | // In Universal Headers 3.2, Apple changed the definition of | |
81 | /* | |
82 | #if UNIVERSAL_INTERFACES_VERSION >= 0x0320 // Universal Headers 3.2 | |
83 | UModalAlerts::ProcessModalEvent(*(ioParams->eventData.eventDataParms.event)); | |
84 | ||
85 | #else | |
86 | UModalAlerts::ProcessModalEvent(*(ioParams->eventData.event)); | |
87 | #endif | |
88 | */ | |
89 | ||
5fde6fcc | 90 | wxTheApp->MacHandleOneEvent(ioParams->eventData.eventDataParms.event); |
4d4d8bbf SC |
91 | } else if ( inSelector == kNavCBPopupMenuSelect ) |
92 | { | |
93 | NavMenuItemSpec * menu = (NavMenuItemSpec *) ioParams->eventData.eventDataParms.param ; | |
94 | data->currentfilter = menu->menuType ; | |
5b781a67 SC |
95 | } |
96 | } | |
97 | ||
519cb848 SC |
98 | char * gfilters[] = |
99 | { | |
100 | "*.TXT" , | |
4d4d8bbf SC |
101 | "*.TIF" , |
102 | "*.JPG" , | |
519cb848 SC |
103 | |
104 | NULL | |
105 | } ; | |
106 | ||
107 | OSType gfiltersmac[] = | |
108 | { | |
109 | 'TEXT' , | |
4d4d8bbf SC |
110 | 'TIFF' , |
111 | 'JPEG' , | |
519cb848 SC |
112 | |
113 | '****' | |
114 | } ; | |
115 | ||
2f1ae414 SC |
116 | |
117 | #if !TARGET_CARBON | |
118 | ||
519cb848 SC |
119 | static void wxMacSetupStandardFile(short newVRefNum, long newDirID) |
120 | { | |
121 | enum | |
122 | { SFSaveDisk = 0x214, CurDirStore = 0x398 }; | |
123 | *(short *) SFSaveDisk = -1 * newVRefNum; | |
124 | *(long *) CurDirStore = newDirID; | |
125 | } | |
126 | ||
127 | static void wxMacSetupStandardFileFromPath( const char* s ) | |
128 | { | |
129 | Str255 volume ; | |
130 | Str255 path ; | |
131 | short vRefNum ; | |
132 | long dirRef ; | |
133 | short i,j ; | |
134 | Boolean isDirectory ; | |
135 | ||
136 | for (i=0 ; (s[i]!=0) && (s[i]!=':') ;i++) | |
137 | { | |
138 | volume[i]=s[i] ; | |
139 | } | |
140 | volume[i]=':' ; | |
141 | volume[i+1]=0 ; | |
142 | ||
143 | // then copy the rest of the filename | |
144 | ||
145 | for (j=0;(s[i]!=0);i++,j++) | |
146 | { | |
147 | path[j]=s[i] ; | |
148 | } | |
149 | path[j]=0 ; | |
150 | ||
151 | c2pstr((Ptr) volume) ; | |
152 | c2pstr((Ptr) path) ; | |
153 | ||
154 | SetVol(volume, 0) ; | |
155 | GetVol( NULL, &vRefNum ) ; | |
156 | ||
157 | GetDirectoryID( vRefNum , fsRtDirID , path , &dirRef , &isDirectory ) ; | |
158 | wxMacSetupStandardFile(vRefNum, dirRef) ; | |
159 | } | |
160 | ||
161 | enum { | |
162 | kSelectItem = 10, // select button item number | |
163 | kSFGetFileDlgID = 251, // dialog resource number | |
164 | kStrListID = 251, // our strings | |
165 | kSelectStrNum = 1, // word 'Select: ' for button | |
166 | kDesktopStrNum = 2, // word 'Desktop' for button | |
167 | kSelectNoQuoteStrNum = 3, // word 'Select: ' for button | |
168 | ||
169 | kUseQuotes = true, // parameter for SetButtonName | |
170 | kDontUseQuotes = false | |
171 | }; | |
172 | ||
519cb848 SC |
173 | static void GetLabelString(StringPtr theStr, short stringNum) |
174 | { | |
175 | GetIndString(theStr, kStrListID, stringNum); | |
176 | } | |
177 | ||
178 | static void CopyPStr(StringPtr src, StringPtr dest) | |
179 | { | |
180 | BlockMoveData(src, dest, 1 + src[0]); | |
181 | } | |
182 | ||
183 | static char GetSelectKey(void) | |
184 | { | |
185 | // this is the key used to trigger the select button | |
186 | ||
187 | // NOT INTERNATIONAL SAVVY; should at least grab it from resources | |
188 | ||
189 | return 's'; | |
190 | } | |
191 | ||
192 | // FlashButton briefly highlights the dialog button | |
193 | // as feedback for key equivalents | |
194 | ||
195 | static void FlashButton(DialogPtr theDlgPtr, short buttonID) | |
196 | { | |
197 | short buttonType; | |
198 | Handle buttonHandle; | |
199 | Rect buttonRect; | |
200 | unsigned long finalTicks; | |
201 | ||
202 | GetDialogItem(theDlgPtr, buttonID, &buttonType, &buttonHandle, &buttonRect); | |
203 | HiliteControl((ControlHandle) buttonHandle, kControlButtonPart); | |
204 | Delay(10, &finalTicks); | |
205 | HiliteControl((ControlHandle) buttonHandle, 0); | |
206 | } | |
207 | ||
208 | static Boolean SameFSSpec(FSSpecPtr spec1, FSSpecPtr spec2) | |
209 | { | |
210 | return (spec1->vRefNum == spec2->vRefNum | |
211 | && spec1->parID == spec2->parID | |
212 | && EqualString(spec1->name, spec2->name, false, false)); | |
213 | } | |
214 | // MyModalDialogFilter maps a key to the Select button, and handles | |
215 | // flashing of the button when the key is hit | |
216 | ||
217 | static pascal Boolean SFGetFolderModalDialogFilter(DialogPtr theDlgPtr, EventRecord *eventRec, | |
5fde6fcc | 218 | short *item, void *dataPtr) |
519cb848 SC |
219 | { |
220 | #pragma unused (dataPtr) | |
221 | ||
222 | // make certain the proper dialog is showing, 'cause standard file | |
223 | // can nest dialogs but calls the same filter for each | |
224 | ||
225 | if (((WindowPeek) theDlgPtr)->refCon == sfMainDialogRefCon) | |
226 | { | |
227 | // check if the select button was hit | |
228 | /* | |
229 | if ((eventRec->what == keyDown) | |
230 | && (eventRec->modifiers & cmdKey) | |
231 | && ((eventRec->message & charCodeMask) == GetSelectKey())) | |
232 | { | |
233 | *item = kSelectItem; | |
234 | FlashButton(theDlgPtr, kSelectItem); | |
235 | return true; | |
236 | } | |
237 | */ | |
238 | } | |
239 | ||
240 | return false; | |
241 | } | |
5b781a67 | 242 | #endif !TARGET_CARBON |
519cb848 | 243 | |
4d4d8bbf SC |
244 | void MakeUserDataRec(OpenUserDataRec *myData , const wxString& filter ) |
245 | { | |
246 | myData->currentfilter = 0 ; | |
247 | ||
248 | if ( filter && filter[0] ) | |
249 | { | |
250 | wxString filter2(filter) ; | |
251 | int filterIndex = 0; | |
252 | bool isName = true ; | |
253 | wxString current ; | |
254 | for( unsigned int i = 0; i < filter2.Len(); i++ ) | |
255 | { | |
256 | if( filter2.GetChar(i) == wxT('|') ) | |
257 | { | |
258 | if( isName ) { | |
259 | myData->name[filterIndex] = current ; | |
260 | } | |
261 | else { | |
262 | myData->extensions[filterIndex] = current.MakeUpper() ; | |
263 | ++filterIndex ; | |
264 | } | |
265 | isName = !isName ; | |
266 | current = "" ; | |
267 | } | |
268 | else | |
269 | { | |
270 | current += filter2.GetChar(i) ; | |
271 | } | |
272 | } | |
fe35d097 | 273 | // if ( filterIndex > 0 ) |
4d4d8bbf SC |
274 | { |
275 | wxASSERT_MSG( !isName , "incorrect format of format string" ) ; | |
276 | myData->extensions[filterIndex] = current.MakeUpper() ; | |
277 | ++filterIndex ; | |
278 | } | |
279 | ||
280 | myData->numfilters = filterIndex ; | |
281 | for ( int i = 0 ; i < myData->numfilters ; i++ ) | |
282 | { | |
283 | int j ; | |
284 | for ( j = 0 ; gfilters[j] ; j++ ) | |
285 | { | |
286 | if ( strcmp( myData->extensions[i] , gfilters[j] ) == 0 ) | |
287 | { | |
288 | myData->filtermactypes[i] = gfiltersmac[j] ; | |
289 | break ; | |
290 | } | |
291 | } | |
292 | if( gfilters[j] == NULL ) | |
293 | { | |
294 | myData->filtermactypes[i] = '****' ; | |
295 | } | |
296 | } | |
297 | } | |
298 | else | |
299 | { | |
300 | myData->numfilters = 0 ; | |
301 | } | |
302 | ||
303 | } | |
304 | void ExtendedOpenFile( ConstStr255Param message , ConstStr255Param path , const char *filter , FileFilterYDUPP fileFilter, StandardFileReply *theSFR ) | |
519cb848 SC |
305 | { |
306 | Point thePt; | |
307 | OpenUserDataRec myData; | |
308 | FSSpec tempSpec; | |
309 | Boolean folderFlag; | |
310 | Boolean wasAliasedFlag; | |
311 | DlgHookYDUPP dlgHookUPP; | |
312 | ModalFilterYDUPP myModalFilterUPP; | |
313 | OSErr err; | |
314 | SFTypeList types ; | |
315 | ||
fe35d097 | 316 | |
519cb848 SC |
317 | // presumably we're running System 7 or later so CustomGetFile is |
318 | // available | |
319 | ||
320 | // set initial contents of Select button to a space | |
321 | ||
2f1ae414 | 322 | memcpy( theSFR->sfFile.name , "\p " , 2 ) ; |
519cb848 SC |
323 | |
324 | // point the user data parameter at the reply record so we can get to it later | |
325 | ||
4d4d8bbf | 326 | MakeUserDataRec( &myData , filter ) ; |
519cb848 | 327 | // display the dialog |
2f1ae414 | 328 | |
fe35d097 SC |
329 | #if !TARGET_CARBON |
330 | ||
519cb848 SC |
331 | dlgHookUPP = NULL ; |
332 | // dlgHookUPP = NewDlgHookYDProc(SFGetFolderDialogHook); | |
333 | myModalFilterUPP = NewModalFilterYDProc(SFGetFolderModalDialogFilter); | |
334 | ||
335 | thePt.h = thePt.v = -1; // center dialog | |
336 | ||
337 | ParamText( message , NULL , NULL , NULL ) ; | |
338 | ||
339 | CustomGetFile( fileFilter, | |
da2b4b7a GD |
340 | -1, // show all types |
341 | NULL, | |
342 | theSFR, | |
343 | kSFGetFileDlgID, | |
344 | thePt, // top left point | |
345 | dlgHookUPP, | |
346 | myModalFilterUPP, | |
347 | nil, // activate list | |
348 | nil, // activate proc | |
349 | &myData); | |
519cb848 SC |
350 | |
351 | DisposeRoutineDescriptor(dlgHookUPP); | |
352 | DisposeRoutineDescriptor(myModalFilterUPP); | |
fe35d097 SC |
353 | #else |
354 | #endif | |
519cb848 SC |
355 | // if cancel wasn't pressed and no fatal error occurred... |
356 | ||
357 | if (theSFR->sfGood) | |
358 | { | |
359 | // if no name is in the reply record file spec, | |
360 | // use the file spec of the parent folder | |
361 | ||
362 | if (theSFR->sfFile.name[0] == '\0') | |
363 | { | |
364 | err = FSMakeFSSpec(theSFR->sfFile.vRefNum, theSFR->sfFile.parID, | |
da2b4b7a | 365 | "\p", &tempSpec); |
519cb848 SC |
366 | if (err == noErr) |
367 | { | |
368 | theSFR->sfFile = tempSpec; | |
369 | } | |
370 | else | |
371 | { | |
372 | // no name to return, forget it | |
373 | ||
374 | theSFR->sfGood = false; | |
375 | } | |
376 | } | |
377 | ||
378 | // if there is now a name in the file spec, check if it's | |
379 | // for a folder or a volume | |
380 | ||
381 | if (theSFR->sfFile.name[0] != '\0') | |
382 | { | |
383 | // the parID of the root of a disk is always fsRtParID == 1 | |
384 | ||
385 | if (theSFR->sfFile.parID == fsRtParID) | |
386 | { | |
387 | theSFR->sfIsVolume = true; | |
388 | theSFR->sfIsFolder = false; // it would be reasonable for this to be true, too | |
389 | } | |
390 | ||
391 | // we have a valid FSSpec, now let's make sure it's not for an alias file | |
392 | ||
393 | err = ResolveAliasFile(&theSFR->sfFile, true, &folderFlag, &wasAliasedFlag); | |
394 | if (err != noErr) | |
395 | { | |
396 | theSFR->sfGood = false; | |
397 | } | |
398 | ||
399 | // did the alias resolve to a folder? | |
400 | ||
401 | if (folderFlag && ! theSFR->sfIsVolume) | |
402 | { | |
403 | theSFR->sfIsFolder = true; | |
404 | } | |
405 | } | |
406 | } | |
407 | } | |
408 | ||
4d4d8bbf SC |
409 | static Boolean CheckFile( ConstStr255Param name , OSType type , OpenUserDataRecPtr data) |
410 | { | |
da2b4b7a GD |
411 | Str255 filename ; |
412 | ||
413 | #if TARGET_CARBON | |
414 | p2cstrcpy((char *)filename, name) ; | |
415 | #else | |
416 | PLstrcpy( filename , name ) ; | |
9f92f6fb | 417 | p2cstr( filename ) ; |
da2b4b7a | 418 | #endif |
9f92f6fb SC |
419 | wxString file(filename) ; |
420 | file.MakeUpper() ; | |
421 | ||
da2b4b7a GD |
422 | if ( data->numfilters > 0 ) |
423 | { | |
424 | //for ( int i = 0 ; i < data->numfilters ; ++i ) | |
fe35d097 SC |
425 | int i = data->currentfilter ; |
426 | if ( data->extensions[i].Right(2) == ".*" ) | |
427 | return true ; | |
da2b4b7a | 428 | |
fe35d097 SC |
429 | { |
430 | if ( type == data->filtermactypes[i] ) | |
431 | return true ; | |
da2b4b7a | 432 | |
fe35d097 SC |
433 | wxStringTokenizer tokenizer( data->extensions[i] , ";" ) ; |
434 | while( tokenizer.HasMoreTokens() ) | |
435 | { | |
436 | wxString extension = tokenizer.GetNextToken() ; | |
437 | if ( extension.GetChar(0) == '*' ) | |
438 | extension = extension.Mid(1) ; | |
439 | ||
440 | if ( file.Len() >= extension.Len() && extension == file.Right(extension.Len() ) ) | |
441 | return true ; | |
442 | } | |
443 | } | |
444 | return false ; | |
da2b4b7a GD |
445 | } |
446 | return true ; | |
4d4d8bbf SC |
447 | } |
448 | ||
5fde6fcc | 449 | static pascal Boolean CrossPlatformFileFilter(CInfoPBPtr myCInfoPBPtr, void *dataPtr) |
519cb848 | 450 | { |
519cb848 SC |
451 | OpenUserDataRecPtr data = (OpenUserDataRecPtr) dataPtr ; |
452 | // return true if this item is invisible or a file | |
453 | ||
454 | Boolean visibleFlag; | |
455 | Boolean folderFlag; | |
456 | ||
457 | visibleFlag = ! (myCInfoPBPtr->hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible); | |
458 | folderFlag = (myCInfoPBPtr->hFileInfo.ioFlAttrib & 0x10); | |
459 | ||
460 | // because the semantics of the filter proc are "true means don't show | |
461 | // it" we need to invert the result that we return | |
462 | ||
463 | if ( !visibleFlag ) | |
464 | return true ; | |
465 | ||
466 | if ( !folderFlag ) | |
467 | { | |
4d4d8bbf | 468 | return !CheckFile( myCInfoPBPtr->hFileInfo.ioNamePtr , myCInfoPBPtr->hFileInfo.ioFlFndrInfo.fdType , data ) ; |
519cb848 SC |
469 | } |
470 | ||
471 | return false ; | |
472 | } | |
473 | ||
474 | // end wxmac | |
475 | ||
476 | wxString wxFileSelector(const char *title, | |
e9576ca5 SC |
477 | const char *defaultDir, const char *defaultFileName, |
478 | const char *defaultExtension, const char *filter, int flags, | |
479 | wxWindow *parent, int x, int y) | |
480 | { | |
481 | // If there's a default extension specified but no filter, we create a suitable | |
482 | // filter. | |
483 | ||
484 | wxString filter2(""); | |
485 | if ( defaultExtension && !filter ) | |
486 | filter2 = wxString("*.") + wxString(defaultExtension) ; | |
487 | else if ( filter ) | |
488 | filter2 = filter; | |
489 | ||
490 | wxString defaultDirString; | |
491 | if (defaultDir) | |
492 | defaultDirString = defaultDir; | |
493 | else | |
494 | defaultDirString = ""; | |
495 | ||
496 | wxString defaultFilenameString; | |
497 | if (defaultFileName) | |
498 | defaultFilenameString = defaultFileName; | |
499 | else | |
500 | defaultFilenameString = ""; | |
501 | ||
502 | wxFileDialog fileDialog(parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y)); | |
503 | ||
504 | if ( fileDialog.ShowModal() == wxID_OK ) | |
505 | { | |
506 | strcpy(wxBuffer, (const char *)fileDialog.GetPath()); | |
507 | return wxBuffer; | |
508 | } | |
509 | else | |
8be97d65 | 510 | return wxGetEmptyString(); |
e9576ca5 SC |
511 | } |
512 | ||
169935ad | 513 | WXDLLEXPORT wxString wxFileSelectorEx(const char *title, |
e9576ca5 SC |
514 | const char *defaultDir, |
515 | const char *defaultFileName, | |
516 | int* defaultFilterIndex, | |
517 | const char *filter, | |
518 | int flags, | |
519 | wxWindow* parent, | |
520 | int x, | |
521 | int y) | |
522 | ||
523 | { | |
524 | wxFileDialog fileDialog(parent, title ? title : "", defaultDir ? defaultDir : "", | |
525 | defaultFileName ? defaultFileName : "", filter ? filter : "", flags, wxPoint(x, y)); | |
526 | ||
527 | if ( fileDialog.ShowModal() == wxID_OK ) | |
528 | { | |
529 | *defaultFilterIndex = fileDialog.GetFilterIndex(); | |
530 | strcpy(wxBuffer, (const char *)fileDialog.GetPath()); | |
531 | return wxBuffer; | |
532 | } | |
533 | else | |
8be97d65 | 534 | return wxGetEmptyString(); |
e9576ca5 SC |
535 | } |
536 | ||
537 | wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, | |
538 | const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard, | |
539 | long style, const wxPoint& pos) | |
540 | { | |
541 | m_message = message; | |
542 | m_dialogStyle = style; | |
543 | m_parent = parent; | |
544 | m_path = ""; | |
545 | m_fileName = defaultFileName; | |
546 | m_dir = defaultDir; | |
547 | m_wildCard = wildCard; | |
548 | m_filterIndex = 1; | |
549 | } | |
550 | ||
4d4d8bbf | 551 | |
f11bdd03 | 552 | pascal Boolean CrossPlatformFilterCallback ( |
4d4d8bbf SC |
553 | AEDesc *theItem, |
554 | void *info, | |
555 | void *callBackUD, | |
556 | NavFilterModes filterMode | |
557 | ) | |
558 | { | |
559 | bool display = true; | |
560 | OpenUserDataRecPtr data = (OpenUserDataRecPtr) callBackUD ; | |
561 | ||
562 | if (filterMode == kNavFilteringBrowserList) | |
563 | { | |
564 | NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo*) info ; | |
565 | if (theItem->descriptorType == typeFSS && !theInfo->isFolder) | |
566 | { | |
567 | FSSpec spec; | |
fe35d097 | 568 | memcpy( &spec , *theItem->dataHandle , sizeof(FSSpec) ) ; |
4d4d8bbf SC |
569 | display = CheckFile( spec.name , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ; |
570 | } | |
571 | } | |
572 | ||
573 | return display; | |
574 | } | |
575 | ||
e9576ca5 SC |
576 | int wxFileDialog::ShowModal() |
577 | { | |
da2b4b7a | 578 | #if !TARGET_CARBON |
5b781a67 SC |
579 | if ( !gUseNavServices ) |
580 | { | |
519cb848 SC |
581 | if ( m_dialogStyle & wxSAVE ) |
582 | { | |
583 | StandardFileReply reply ; | |
584 | Str255 prompt ; | |
585 | Str255 filename ; | |
586 | ||
587 | strcpy((char *)prompt, m_message) ; | |
588 | c2pstr((char *)prompt ) ; | |
519cb848 SC |
589 | strcpy((char *)filename, m_fileName) ; |
590 | c2pstr((char *)filename ) ; | |
03e11df5 | 591 | |
519cb848 SC |
592 | StandardPutFile( prompt , filename , &reply ) ; |
593 | if ( reply.sfGood == false ) | |
594 | { | |
595 | m_path = "" ; | |
596 | return wxID_CANCEL ; | |
597 | } | |
598 | else | |
599 | { | |
bedaf53e | 600 | m_path = wxMacFSSpec2MacFilename( &reply.sfFile ) ; |
519cb848 SC |
601 | return wxID_OK ; |
602 | } | |
603 | } | |
604 | else | |
605 | { | |
606 | OSType types = '????' ; | |
607 | Str255 prompt ; | |
608 | Str255 path ; | |
609 | ||
610 | strcpy((char *)prompt, m_message) ; | |
611 | c2pstr((char *)prompt ) ; | |
03e11df5 | 612 | strcpy((char *)path, m_dir ) ; |
519cb848 SC |
613 | c2pstr((char *)path ) ; |
614 | ||
519cb848 | 615 | StandardFileReply reply ; |
2f1ae414 | 616 | FileFilterYDUPP crossPlatformFileFilterUPP = 0 ; |
fe35d097 | 617 | #if !TARGET_CARBON |
519cb848 SC |
618 | crossPlatformFileFilterUPP = |
619 | NewFileFilterYDProc(CrossPlatformFileFilter); | |
fe35d097 SC |
620 | #endif |
621 | ||
519cb848 | 622 | ExtendedOpenFile( prompt , path , m_wildCard , crossPlatformFileFilterUPP, &reply); |
fe35d097 | 623 | #if !TARGET_CARBON |
2f1ae414 | 624 | DisposeFileFilterYDUPP(crossPlatformFileFilterUPP); |
fe35d097 | 625 | #endif |
519cb848 SC |
626 | if ( reply.sfGood == false ) |
627 | { | |
628 | m_path = "" ; | |
629 | return wxID_CANCEL ; | |
630 | } | |
631 | else | |
632 | { | |
fe35d097 | 633 | m_path = wxMacFSSpec2UnixFilename( &reply.sfFile ) ; |
519cb848 SC |
634 | return wxID_OK ; |
635 | } | |
636 | } | |
e9576ca5 SC |
637 | return wxID_CANCEL; |
638 | } | |
5b781a67 SC |
639 | else |
640 | #endif | |
641 | { | |
642 | NavDialogOptions mNavOptions; | |
643 | NavObjectFilterUPP mNavFilterUPP = NULL; | |
644 | NavPreviewUPP mNavPreviewUPP = NULL ; | |
645 | NavReplyRecord mNavReply; | |
646 | AEDesc mDefaultLocation ; | |
647 | bool mSelectDefault = false ; | |
648 | ||
649 | ::NavGetDefaultDialogOptions(&mNavOptions); | |
650 | ||
651 | mNavFilterUPP = nil; | |
652 | mNavPreviewUPP = nil; | |
653 | mSelectDefault = false; | |
654 | mNavReply.validRecord = false; | |
655 | mNavReply.replacing = false; | |
656 | mNavReply.isStationery = false; | |
657 | mNavReply.translationNeeded = false; | |
658 | mNavReply.selection.descriptorType = typeNull; | |
659 | mNavReply.selection.dataHandle = nil; | |
660 | mNavReply.keyScript = smSystemScript; | |
661 | mNavReply.fileTranslation = nil; | |
662 | ||
663 | // Set default location, the location | |
664 | // that's displayed when the dialog | |
665 | // first appears | |
666 | ||
667 | FSSpec location ; | |
bedaf53e | 668 | wxMacFilename2FSSpec( m_dir , &location ) ; |
5b781a67 SC |
669 | OSErr err = noErr ; |
670 | ||
671 | mDefaultLocation.descriptorType = typeNull; | |
672 | mDefaultLocation.dataHandle = nil; | |
673 | ||
674 | err = ::AECreateDesc(typeFSS, &location, sizeof(FSSpec), &mDefaultLocation ); | |
675 | ||
676 | if ( mDefaultLocation.dataHandle ) { | |
677 | ||
678 | if (mSelectDefault) { | |
679 | mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation; | |
680 | } else { | |
681 | mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation; | |
682 | } | |
683 | } | |
684 | ||
03e11df5 GD |
685 | #if TARGET_CARBON |
686 | c2pstrcpy((StringPtr)mNavOptions.message, m_message) ; | |
687 | #else | |
5b781a67 SC |
688 | strcpy((char *)mNavOptions.message, m_message) ; |
689 | c2pstr((char *)mNavOptions.message ) ; | |
03e11df5 GD |
690 | #endif |
691 | #if TARGET_CARBON | |
692 | c2pstrcpy((StringPtr)mNavOptions.savedFileName, m_fileName) ; | |
693 | #else | |
5b781a67 SC |
694 | strcpy((char *)mNavOptions.savedFileName, m_fileName) ; |
695 | c2pstr((char *)mNavOptions.savedFileName ) ; | |
03e11df5 | 696 | #endif |
5b781a67 SC |
697 | |
698 | if ( m_dialogStyle & wxSAVE ) | |
699 | { | |
700 | ||
701 | mNavOptions.dialogOptionFlags |= kNavNoTypePopup ; | |
702 | mNavOptions.dialogOptionFlags |= kNavDontAutoTranslate ; | |
703 | mNavOptions.dialogOptionFlags |= kNavDontAddTranslateItems ; | |
704 | ||
705 | err = ::NavPutFile( | |
706 | &mDefaultLocation, | |
707 | &mNavReply, | |
708 | &mNavOptions, | |
709 | sStandardNavEventFilter , | |
710 | 'TEXT', | |
711 | 'TEXT', | |
712 | 0L); // User Data | |
713 | } | |
714 | else | |
715 | { | |
4d4d8bbf SC |
716 | OpenUserDataRec myData; |
717 | MakeUserDataRec( &myData , m_wildCard ) ; | |
718 | NavTypeListHandle typelist = NULL ; | |
719 | ||
720 | if ( myData.numfilters > 0 ) | |
721 | { | |
722 | mNavOptions.popupExtension = (NavMenuItemSpecArrayHandle) NewHandle( sizeof( NavMenuItemSpec ) * myData.numfilters ) ; | |
723 | for ( int i = 0 ; i < myData.numfilters ; ++i ) { | |
724 | (*mNavOptions.popupExtension)[i].version = kNavMenuItemSpecVersion ; | |
725 | (*mNavOptions.popupExtension)[i].menuCreator = 'WXNG' ; | |
726 | (*mNavOptions.popupExtension)[i].menuType = i ; | |
727 | #if TARGET_CARBON | |
728 | c2pstrcpy((StringPtr)(*mNavOptions.popupExtension)[i].menuItemName, myData.name[i]) ; | |
729 | #else | |
730 | strcpy((char *)(*mNavOptions.popupExtension)[i].menuItemName, myData.name[i]) ; | |
731 | c2pstr((char *)(*mNavOptions.popupExtension)[i].menuItemName ) ; | |
732 | #endif | |
733 | } | |
734 | } | |
735 | ||
f11bdd03 | 736 | mNavFilterUPP = NewNavObjectFilterUPP( CrossPlatformFilterCallback ) ; |
5b781a67 SC |
737 | if ( m_dialogStyle & wxMULTIPLE ) |
738 | mNavOptions.dialogOptionFlags |= kNavAllowMultipleFiles ; | |
739 | else | |
740 | mNavOptions.dialogOptionFlags &= ~kNavAllowMultipleFiles ; | |
741 | ||
742 | err = ::NavGetFile( | |
743 | &mDefaultLocation, | |
744 | &mNavReply, | |
745 | &mNavOptions, | |
746 | sStandardNavEventFilter , | |
747 | mNavPreviewUPP, | |
748 | mNavFilterUPP, | |
4d4d8bbf SC |
749 | typelist /*inFileTypes.TypeListHandle() */, |
750 | &myData); // User Data | |
751 | if ( typelist ) | |
752 | DisposeHandle( (Handle) typelist ) ; | |
5b781a67 SC |
753 | } |
754 | ||
4d4d8bbf | 755 | DisposeNavObjectFilterUPP(mNavFilterUPP); |
5b781a67 SC |
756 | if ( mDefaultLocation.dataHandle != nil ) |
757 | { | |
758 | ::AEDisposeDesc(&mDefaultLocation); | |
759 | } | |
760 | ||
761 | if ( (err != noErr) && (err != userCanceledErr) ) { | |
762 | m_path = "" ; | |
763 | return wxID_CANCEL ; | |
764 | } | |
765 | ||
766 | if (mNavReply.validRecord) { | |
767 | ||
768 | FSSpec outFileSpec ; | |
769 | AEDesc specDesc ; | |
fe35d097 | 770 | AEKeyword keyWord ; |
5b781a67 SC |
771 | |
772 | long count ; | |
773 | ::AECountItems( &mNavReply.selection , &count ) ; | |
774 | for ( long i = 1 ; i <= count ; ++i ) | |
775 | { | |
fe35d097 | 776 | OSErr err = ::AEGetNthDesc( &mNavReply.selection , i , typeFSS, &keyWord , &specDesc); |
5b781a67 SC |
777 | if ( err != noErr ) { |
778 | m_path = "" ; | |
779 | return wxID_CANCEL ; | |
780 | } | |
781 | outFileSpec = **(FSSpec**) specDesc.dataHandle; | |
782 | if (specDesc.dataHandle != nil) { | |
783 | ::AEDisposeDesc(&specDesc); | |
784 | } | |
785 | ||
786 | ||
787 | // outFolderDirID = thePB.dirInfo.ioDrDirID; | |
bedaf53e | 788 | m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ; |
5b781a67 SC |
789 | m_paths.Add( m_path ) ; |
790 | m_fileNames.Add(m_fileName); | |
791 | } | |
792 | // set these to the first hit | |
793 | m_path = m_paths[ 0 ] ; | |
794 | m_fileName = wxFileNameFromPath(m_path); | |
795 | m_dir = wxPathOnly(m_path); | |
fe35d097 | 796 | NavDisposeReply( &mNavReply ) ; |
5b781a67 SC |
797 | return wxID_OK ; |
798 | } | |
799 | return wxID_CANCEL; | |
800 | } | |
801 | } | |
e9576ca5 SC |
802 | |
803 | // Generic file load/save dialog | |
169935ad | 804 | static wxString |
e9576ca5 SC |
805 | wxDefaultFileSelector(bool load, const char *what, const char *extension, const char *default_name, wxWindow *parent) |
806 | { | |
807 | char *ext = (char *)extension; | |
808 | ||
809 | char prompt[50]; | |
810 | wxString str; | |
811 | if (load) | |
812 | str = "Load %s file"; | |
813 | else | |
814 | str = "Save %s file"; | |
815 | sprintf(prompt, wxGetTranslation(str), what); | |
816 | ||
817 | if (*ext == '.') ext++; | |
818 | char wild[60]; | |
819 | sprintf(wild, "*.%s", ext); | |
820 | ||
821 | return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent); | |
822 | } | |
823 | ||
824 | // Generic file load dialog | |
169935ad | 825 | wxString |
e9576ca5 SC |
826 | wxLoadFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent) |
827 | { | |
828 | return wxDefaultFileSelector(TRUE, what, extension, default_name, parent); | |
829 | } | |
830 | ||
831 | ||
832 | // Generic file save dialog | |
169935ad | 833 | wxString |
e9576ca5 SC |
834 | wxSaveFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent) |
835 | { | |
836 | return wxDefaultFileSelector(FALSE, what, extension, default_name, parent); | |
837 | } | |
838 | ||
839 |