home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 April: Mac OS SDK / Dev.CD Apr 00 SDK1.toast / Development Kits / Mac OS / Speech Recognition Manager / SR Sample Code / Speakable Items Example / Sources / Process & Finder Stuff / FinderUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  4.2 KB  |  145 lines  |  [TEXT/CWIE]

  1. /*****************************************************************************
  2.  *
  3.  *  FingerUtils.c
  4.  *
  5.  *  DESCRIPTION
  6.  *        Utiltiy routines for programmatic control of the finder in System 7
  7.  *    using AppleEvents.
  8.  *
  9.  *  AUTHOR:     Matt Pallakoff
  10.  * 
  11.  *  CREATED:     11-25-91
  12.  *
  13.  *****************************************************************************/
  14.  
  15. #include "FinderUtils.h"
  16.  
  17. /****************************************************************************/
  18.  
  19. /* FUGetParent fills theParentFSSpec so that it represents the parent directory
  20.  *    of the item corresponding to the first given FSSpec.
  21.  */
  22. OSErr FUGetParent(FSSpec *theItemFSSpec, FSSpec *theParentFSSpec)
  23. {
  24.     OSErr        err = 0;
  25.     CInfoPBRec    cInfoRec;
  26.     
  27.     cInfoRec.dirInfo.ioCompletion = nil;
  28.     cInfoRec.dirInfo.ioNamePtr = theParentFSSpec->name;
  29.     cInfoRec.dirInfo.ioVRefNum = theItemFSSpec->vRefNum;
  30.     cInfoRec.dirInfo.ioDrDirID = theItemFSSpec->parID;
  31.     cInfoRec.dirInfo.ioFDirIndex = -1; /* Return info about directory given by ioDirID. */
  32.     
  33.     err = PBGetCatInfo(&cInfoRec,false);
  34.     
  35.     if ((!err) && (theParentFSSpec)) {
  36.         /* Name was got in call, since we passed pointer to it.    */
  37.         theParentFSSpec->vRefNum = theItemFSSpec->vRefNum;
  38.         theParentFSSpec->parID = cInfoRec.dirInfo.ioDrParID;
  39.     }
  40.     
  41.     return    err;
  42. }
  43.  
  44.  
  45. /****************************************************************************/
  46.  
  47. /* FUOpenFinderItem sends an AppleEvent to the finder telling it to open the item
  48.  *    given by the the given FSSpec. If justReveal is true, then the item isn't
  49.  *    opened, it's just shown -- that is, the parent folder is opened and scrolled
  50.  *    so you can see the item.
  51.  */
  52. OSErr FUOpenFinderItem(FSSpec *theItemFSSpec, Boolean justReveal)
  53. {
  54.     AppleEvent        theAevt;
  55.     AEAddressDesc    theTarget;
  56.     AppleEvent        theReply;
  57.     TargetID        theTargetID;
  58.     long            timeOut;
  59.     AliasHandle        theItemAlias = NULL, theParentFolderAlias = NULL;    
  60.     FSSpec            theParentFSSpec;
  61.     AEDescList        theItemAliasListDesc;
  62.     OSErr            err = 0, err2;
  63.     OSType            signature;
  64.     
  65.  
  66.         /*
  67.          * Create alias corresponding to item's parent folder.
  68.          */
  69.     if (!err) {
  70.         err = FUGetParent(theItemFSSpec, &theParentFSSpec);
  71.         if (!err)
  72.             err = NewAlias(nil, &theParentFSSpec, &theParentFolderAlias);
  73.     }
  74.  
  75.         /*
  76.          * Create alias and alias list corresponding to item.
  77.          */
  78.     if (!err)
  79.         err = NewAlias(nil, theItemFSSpec, &theItemAlias);
  80.     if ((!err) && (theItemAlias != NULL)) {
  81.         err = AECreateList(nil, 0, false, &theItemAliasListDesc);
  82.         if (!err) {
  83.             HLock((Handle)theItemAlias);
  84.             err = AEPutPtr(&theItemAliasListDesc, 1, typeAlias, (Ptr)*theItemAlias, GetHandleSize((Handle)theItemAlias));
  85.             HUnlock((Handle)theItemAlias);
  86.         }
  87.     }
  88.     
  89.  
  90.         /*
  91.          * Create target descriptor corresponding to finder.
  92.          */
  93.     if (!err) {
  94.         signature = kFinderProcessSignature;
  95.         err = AECreateDesc(typeApplSignature, (Ptr) &signature, (Size)sizeof(signature), &theTarget);
  96.     }
  97.     
  98.         /*
  99.          * Create AppleEvent.
  100.          */
  101.     if (!err)
  102.         if (justReveal)
  103.             err = AECreateAppleEvent(kFinderEventClass, kRevealSelectionEventID, &theTarget, kAutoGenerateReturnID, kAnyTransactionID, &theAevt);
  104.         else
  105.             err = AECreateAppleEvent(kFinderEventClass, kOpenSelectionEventID, &theTarget, kAutoGenerateReturnID, kAnyTransactionID, &theAevt);
  106.  
  107.         /*
  108.          * Put alias to folder containing item in direct parameter.
  109.          */
  110.     if ((!err) && (theParentFolderAlias != NULL)) {
  111.         HLock((Handle)theParentFolderAlias);
  112.         err = AEPutParamPtr(&theAevt, keyDirectObject, typeAlias, (Ptr) *theParentFolderAlias, GetHandleSize((Handle)theParentFolderAlias));
  113.         HUnlock((Handle)theParentFolderAlias);
  114.     }
  115.  
  116.         /*
  117.          * Put list of aliases to items to be opened in aeSelectionKeyword parameter.
  118.          */
  119.     if (!err)
  120.         err = AEPutParamDesc(&theAevt, aeSelectionKeyword, &theItemAliasListDesc);
  121.  
  122.         /*
  123.          * Send the AppleEvent.
  124.          */
  125.     if (!err)
  126.         err = AESend(&theAevt, &theReply, kAENoReply + kAECanInteract + kAECanSwitchLayer, kAENormalPriority, 240, (AEIdleUPP)0, (AEFilterUPP)0);
  127.  
  128.  
  129.         /*
  130.          * Cleanup
  131.          */
  132.     err2 = AEDisposeDesc(&theAevt);
  133.     err2 = AEDisposeDesc(&theTarget);
  134. //    err2 = AEDisposeDesc(&theReply);
  135.     err2 = AEDisposeDesc(&theItemAliasListDesc);
  136.     if (theItemAlias)
  137.         DisposHandle((Handle)theItemAlias);
  138.     if (theParentFolderAlias)
  139.         DisposHandle((Handle)theParentFolderAlias);
  140.     
  141.     return err;
  142. }
  143.  
  144. /****************************************************************************/
  145.