-static void FlashButton(DialogPtr theDlgPtr, short buttonID)
-{
- short buttonType;
- Handle buttonHandle;
- Rect buttonRect;
- unsigned long finalTicks;
-
- GetDialogItem(theDlgPtr, buttonID, &buttonType, &buttonHandle, &buttonRect);
- HiliteControl((ControlHandle) buttonHandle, kControlButtonPart);
- Delay(10, &finalTicks);
- HiliteControl((ControlHandle) buttonHandle, 0);
-}
-
-static Boolean SameFSSpec(FSSpecPtr spec1, FSSpecPtr spec2)
-{
- return (spec1->vRefNum == spec2->vRefNum
- && spec1->parID == spec2->parID
- && EqualString(spec1->name, spec2->name, false, false));
-}
-// MyModalDialogFilter maps a key to the Select button, and handles
-// flashing of the button when the key is hit
-
-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;
-}