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