-static pascal Boolean SFGetFolderModalDialogFilter(DialogPtr theDlgPtr, EventRecord *eventRec,
- short *item, Ptr dataPtr)
-{
-#pragma unused (dataPtr)
-
- // make certain the proper dialog is showing, 'cause standard file
- // can nest dialogs but calls the same filter for each
-
- if (((WindowPeek) theDlgPtr)->refCon == sfMainDialogRefCon)
- {
- // check if the select button was hit
-
- if ((eventRec->what == keyDown)
- && (eventRec->modifiers & cmdKey)
- && ((eventRec->message & charCodeMask) == GetSelectKey()))
- {
- *item = kSelectItem;
- FlashButton(theDlgPtr, kSelectItem);
- return true;
- }
- }
-
- return false;
-}
-
-
-// MyDlgHook is a hook routine that maps the select button to Open
-// and sets the Select button name
-
-static pascal short SFGetFolderDialogHook(short item, DialogPtr theDlgPtr, Ptr dataPtr)
-{
- UserDataRecPtr theUserDataRecPtr;
- long desktopDirID;
- short desktopVRefNum;
- FSSpec tempSpec;
- Str63 desktopName;
- OSErr err;
-
- // be sure Std File is really showing us the intended dialog,
- // not a nested modal dialog
-
- if (((WindowPeek) theDlgPtr)->refCon != sfMainDialogRefCon)
- {
- return item;
- }
-
- theUserDataRecPtr = (UserDataRecPtr) dataPtr;
-
- // map the Select button to Open
-
- if (item == kSelectItem)
- {
- item = sfItemOpenButton;
- }
-
- // find the desktop folder
-
- err = FindFolder(theUserDataRecPtr->sfrPtr->sfFile.vRefNum,
- kDesktopFolderType, kDontCreateFolder,
- &desktopVRefNum, &desktopDirID);
-
- if (err != noErr)
- {
- // for errors, get value that won't match any real vRefNum/dirID
- desktopVRefNum = 0;
- desktopDirID = 0;
- }
-
- // change the Select button label if the selection has changed or
- // if this is the first call to the hook
-
- if (item == sfHookFirstCall
- || item == sfHookChangeSelection
- || item == sfHookRebuildList
- || ! SameFSSpec(&theUserDataRecPtr->sfrPtr->sfFile,
- &theUserDataRecPtr->oldSelectionFSSpec))
- {
- // be sure there is a file name selected
-
- if (theUserDataRecPtr->sfrPtr->sfFile.name[0] != '\0')
- {
- SetButtonName(theDlgPtr, kSelectItem,
- theUserDataRecPtr->sfrPtr->sfFile.name,
- kUseQuotes); // true -> use quotes
- }
- else
- {
- // is the desktop selected?
-
- if (theUserDataRecPtr->sfrPtr->sfFile.vRefNum == desktopVRefNum
- && theUserDataRecPtr->sfrPtr->sfFile.parID == desktopDirID)
- {
- // set button to "Select Desktop"
-
- GetLabelString(desktopName, kDesktopStrNum);
- SetButtonName(theDlgPtr, kSelectItem,
- desktopName, kDontUseQuotes); // false -> no quotes
- }
- else
- {
- // get parent directory's name for the Select button
- //
- // passing an empty name string to FSMakeFSSpec gets the
- // name of the folder specified by the parID parameter
-
- (void) FSMakeFSSpec(theUserDataRecPtr->sfrPtr->sfFile.vRefNum,
- theUserDataRecPtr->sfrPtr->sfFile.parID, "\p",
- &tempSpec);
- SetButtonName(theDlgPtr, kSelectItem,
- tempSpec.name, kUseQuotes); // true -> use quotes
- }
- }
- }
-
- // save the current selection as the old selection for comparison next time
- //
- // it's not valid on the first call, though, or if we don't have a
- // name available from standard file
-
- if (item != sfHookFirstCall || theUserDataRecPtr->sfrPtr->sfFile.name[0] != '\0')
- {
- theUserDataRecPtr->oldSelectionFSSpec = theUserDataRecPtr->sfrPtr->sfFile;
- }
- else
- {
- // on first call, empty string won't set the button correctly,
- // so invalidate oldSelection
-
- theUserDataRecPtr->oldSelectionFSSpec.vRefNum = 999;
- theUserDataRecPtr->oldSelectionFSSpec.parID = 0;
- }
-
- return item;
-}
-
-void StandardGetFolder( ConstStr255Param message , ConstStr255Param path , FileFilterYDUPP fileFilter, StandardFileReply *theSFR)
-{
- Point thePt;
- SFTypeList mySFTypeList;
- UserDataRec myData;
- FSSpec tempSpec;
- Boolean folderFlag;
- Boolean wasAliasedFlag;
- DlgHookYDUPP dlgHookUPP;
- ModalFilterYDUPP myModalFilterUPP;
- OSErr err;
-
-
- // presumably we're running System 7 or later so CustomGetFile is
- // available
-
- // set initial contents of Select button to a space
-
- memcpy(theSFR->sfFile.name, "\p ", 2);
-
- // point the user data parameter at the reply record so we can get to it later
-
- myData.sfrPtr = theSFR;
-
- // display the dialog
-
- #if !TARGET_CARBON
-
- dlgHookUPP = NewDlgHookYDProc(SFGetFolderDialogHook);
- myModalFilterUPP = NewModalFilterYDProc(SFGetFolderModalDialogFilter);
-
- thePt.h = thePt.v = -1; // center dialog
-
- ParamText( message , NULL , NULL , NULL ) ;
-
- CustomGetFile( fileFilter,
- -1, // show all types
- mySFTypeList,
- theSFR,
- kSFGetFolderDlgID,
- thePt, // top left point
- dlgHookUPP,
- myModalFilterUPP,
- nil, // activate list
- nil, // activate proc
- &myData);
-
- DisposeRoutineDescriptor(dlgHookUPP);
- DisposeRoutineDescriptor(myModalFilterUPP);
- #else
- #endif
-
- // if cancel wasn't pressed and no fatal error occurred...
-
- if (theSFR->sfGood)
- {
- // if no name is in the reply record file spec,
- // use the file spec of the parent folder
-
- if (theSFR->sfFile.name[0] == '\0')
- {
- err = FSMakeFSSpec(theSFR->sfFile.vRefNum, theSFR->sfFile.parID,
- "\p", &tempSpec);
- if (err == noErr)
- {
- theSFR->sfFile = tempSpec;
- }
- else
- {
- // no name to return, forget it
-
- theSFR->sfGood = false;
- }
- }
-
- // if there is now a name in the file spec, check if it's
- // for a folder or a volume
-
- if (theSFR->sfFile.name[0] != '\0')
- {
- // the parID of the root of a disk is always fsRtParID == 1
-
- if (theSFR->sfFile.parID == fsRtParID)
- {
- theSFR->sfIsVolume = true;
- theSFR->sfIsFolder = false; // it would be reasonable for this to be true, too
- }
-
- // we have a valid FSSpec, now let's make sure it's not for an alias file
-
- err = ResolveAliasFile(&theSFR->sfFile, true, &folderFlag, &wasAliasedFlag);
- if (err != noErr)
- {
- theSFR->sfGood = false;
- }
-
- // did the alias resolve to a folder?
-
- if (folderFlag && ! theSFR->sfIsVolume)
- {
- theSFR->sfIsFolder = true;
- }
- }
- }
-}
-
-static pascal Boolean OnlyVisibleFoldersCustomFileFilter(CInfoPBPtr myCInfoPBPtr, Ptr dataPtr)
-{
-#pragma unused (dataPtr)
-
- // return true if this item is invisible or a file
-
- Boolean visibleFlag;
- Boolean folderFlag;
-
- visibleFlag = ! (myCInfoPBPtr->hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible);
- folderFlag = (myCInfoPBPtr->hFileInfo.ioFlAttrib & 0x10);
-
- // because the semantics of the filter proc are "true means don't show
- // it" we need to invert the result that we return
-
- return !(visibleFlag && folderFlag);
-}
-
-#endif
-
-
-wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
- const wxString& defaultPath,
- long style, const wxPoint& pos)