Rev 15595 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
/* This file has been modified by Stefano M.Iacus to work on R from the originalFile: FinderLaunch.cDescription:A routine for sending an open documents Apple event to thefinder. This routine provides functionality equivalent toselecting a document/file/application and choosing theopen command in the Finder's file menu.Author: John MontbriandCopyright:Copyright © 1999 by Apple Computer, Inc.All rights reserved worldwide.Disclaimer:You may incorporate this sample code into yourapplications without restriction, though the samplecode has been provided "AS IS" and the responsibilityfor its operation is 100% yours. However, what youare not permitted to do is to redistribute the sourceas "DSC Sample Code" after having made changes. Ifyou're going to re-distribute the source, we requirethat you make it clear in the source that the code wasdescended from Apple Sample Code, but that you've madechanges.Change History (most recent first):9/13/99 created by John Montbriand */#include <RCarbon.h>#include "RFLaunch.h"#include <QuickDraw.h>#include <AppleEvents.h>#include <Errors.h>#include <Files.h>#include <AERegistry.h>#include <Aliases.h>OSErr FinderLaunch(long nTargets, FSSpec *targetList){OSErr err;AppleEvent theAEvent, theReply;AEAddressDesc fndrAddress;AEDescList targetListDesc;OSType fndrCreator;Boolean wasChanged;AliasHandle targetAlias;long index;/* verify parameters */if ((nTargets == 0) || (targetList == NULL)) return paramErr;/* set up locals */AECreateDesc(typeNull, NULL, 0, &theAEvent);AECreateDesc(typeNull, NULL, 0, &fndrAddress);AECreateDesc(typeNull, NULL, 0, &theReply);AECreateDesc(typeNull, NULL, 0, &targetListDesc);targetAlias = NULL;fndrCreator = 'MACS';/* create an open documents event targeting the finder */err = AECreateDesc(typeApplSignature, (Ptr) &fndrCreator,sizeof(fndrCreator), &fndrAddress);if (err != noErr) goto bail;err = AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments,&fndrAddress, kAutoGenerateReturnID,kAnyTransactionID, &theAEvent);if (err != noErr) goto bail;/* create the list of files to open */err = AECreateList(NULL, 0, false, &targetListDesc);if (err != noErr) goto bail;for ( index=0; index < nTargets; index++) {if (targetAlias == NULL)err = NewAlias(NULL, (targetList + index), &targetAlias);else err = UpdateAlias(NULL, (targetList + index), targetAlias, &wasChanged);if (err != noErr) goto bail;HLock((Handle) targetAlias);err = AEPutPtr(&targetListDesc, (index + 1), typeAlias, *targetAlias, GetHandleSize((Handle) targetAlias));HUnlock((Handle) targetAlias);if (err != noErr) goto bail;}/* add the file list to the apple event */err = AEPutParamDesc(&theAEvent, keyDirectObject, &targetListDesc);if (err != noErr) goto bail;/* send the event to the Finder */err = AESend(&theAEvent, &theReply, kAENoReply,kAENormalPriority, kAEDefaultTimeout, NULL, NULL);/* clean up and leave */bail:if (targetAlias != NULL) DisposeHandle((Handle) targetAlias);AEDisposeDesc(&targetListDesc);AEDisposeDesc(&theAEvent);AEDisposeDesc(&fndrAddress);AEDisposeDesc(&theReply);return err;}