home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************
- *
- * FingerUtils.c
- *
- * DESCRIPTION
- * Utiltiy routines for programmatic control of the finder in System 7
- * using AppleEvents.
- *
- * AUTHOR: Matt Pallakoff
- *
- * CREATED: 11-25-91
- *
- *****************************************************************************/
-
- #include "FinderUtils.h"
-
- /****************************************************************************/
-
- /* FUGetParent fills theParentFSSpec so that it represents the parent directory
- * of the item corresponding to the first given FSSpec.
- */
- OSErr FUGetParent(FSSpec *theItemFSSpec, FSSpec *theParentFSSpec)
- {
- OSErr err = 0;
- CInfoPBRec cInfoRec;
-
- cInfoRec.dirInfo.ioCompletion = nil;
- cInfoRec.dirInfo.ioNamePtr = theParentFSSpec->name;
- cInfoRec.dirInfo.ioVRefNum = theItemFSSpec->vRefNum;
- cInfoRec.dirInfo.ioDrDirID = theItemFSSpec->parID;
- cInfoRec.dirInfo.ioFDirIndex = -1; /* Return info about directory given by ioDirID. */
-
- err = PBGetCatInfo(&cInfoRec,false);
-
- if ((!err) && (theParentFSSpec)) {
- /* Name was got in call, since we passed pointer to it. */
- theParentFSSpec->vRefNum = theItemFSSpec->vRefNum;
- theParentFSSpec->parID = cInfoRec.dirInfo.ioDrParID;
- }
-
- return err;
- }
-
-
- /****************************************************************************/
-
- /* FUOpenFinderItem sends an AppleEvent to the finder telling it to open the item
- * given by the the given FSSpec. If justReveal is true, then the item isn't
- * opened, it's just shown -- that is, the parent folder is opened and scrolled
- * so you can see the item.
- */
- OSErr FUOpenFinderItem(FSSpec *theItemFSSpec, Boolean justReveal)
- {
- AppleEvent theAevt;
- AEAddressDesc theTarget;
- AppleEvent theReply;
- TargetID theTargetID;
- long timeOut;
- AliasHandle theItemAlias = NULL, theParentFolderAlias = NULL;
- FSSpec theParentFSSpec;
- AEDescList theItemAliasListDesc;
- OSErr err = 0, err2;
- OSType signature;
-
-
- /*
- * Create alias corresponding to item's parent folder.
- */
- if (!err) {
- err = FUGetParent(theItemFSSpec, &theParentFSSpec);
- if (!err)
- err = NewAlias(nil, &theParentFSSpec, &theParentFolderAlias);
- }
-
- /*
- * Create alias and alias list corresponding to item.
- */
- if (!err)
- err = NewAlias(nil, theItemFSSpec, &theItemAlias);
- if ((!err) && (theItemAlias != NULL)) {
- err = AECreateList(nil, 0, false, &theItemAliasListDesc);
- if (!err) {
- HLock((Handle)theItemAlias);
- err = AEPutPtr(&theItemAliasListDesc, 1, typeAlias, (Ptr)*theItemAlias, GetHandleSize((Handle)theItemAlias));
- HUnlock((Handle)theItemAlias);
- }
- }
-
-
- /*
- * Create target descriptor corresponding to finder.
- */
- if (!err) {
- signature = kFinderProcessSignature;
- err = AECreateDesc(typeApplSignature, (Ptr) &signature, (Size)sizeof(signature), &theTarget);
- }
-
- /*
- * Create AppleEvent.
- */
- if (!err)
- if (justReveal)
- err = AECreateAppleEvent(kFinderEventClass, kRevealSelectionEventID, &theTarget, kAutoGenerateReturnID, kAnyTransactionID, &theAevt);
- else
- err = AECreateAppleEvent(kFinderEventClass, kOpenSelectionEventID, &theTarget, kAutoGenerateReturnID, kAnyTransactionID, &theAevt);
-
- /*
- * Put alias to folder containing item in direct parameter.
- */
- if ((!err) && (theParentFolderAlias != NULL)) {
- HLock((Handle)theParentFolderAlias);
- err = AEPutParamPtr(&theAevt, keyDirectObject, typeAlias, (Ptr) *theParentFolderAlias, GetHandleSize((Handle)theParentFolderAlias));
- HUnlock((Handle)theParentFolderAlias);
- }
-
- /*
- * Put list of aliases to items to be opened in aeSelectionKeyword parameter.
- */
- if (!err)
- err = AEPutParamDesc(&theAevt, aeSelectionKeyword, &theItemAliasListDesc);
-
- /*
- * Send the AppleEvent.
- */
- if (!err)
- err = AESend(&theAevt, &theReply, kAENoReply + kAECanInteract + kAECanSwitchLayer, kAENormalPriority, 240, (AEIdleUPP)0, (AEFilterUPP)0);
-
-
- /*
- * Cleanup
- */
- err2 = AEDisposeDesc(&theAevt);
- err2 = AEDisposeDesc(&theTarget);
- // err2 = AEDisposeDesc(&theReply);
- err2 = AEDisposeDesc(&theItemAliasListDesc);
- if (theItemAlias)
- DisposHandle((Handle)theItemAlias);
- if (theParentFolderAlias)
- DisposHandle((Handle)theParentFolderAlias);
-
- return err;
- }
-
- /****************************************************************************/
-