/******************************************************************************** Add a parameter of type typeAlias to an AERecord (or AppleEvent) using the provided FSRef. pFSRef input: Pointer to the FSRef to use. pKeyword input: The key for the data to be added to the record. pAERecord input: Pointer to the record (or event) to add the data to. RESULT CODES ____________ noErr 0 No error paramErr -50 The value of target or alias parameter, or of both, is NIL, or the alias record is corrupt memFullErr -108 Not enough room in heap zone */ pascal OSErr MoreAEOAddAliasParameterFromFSRef(const FSRefPtr pFSRef, const DescType pKeyword, AERecord *pAERecord ) { OSErr anErr = noErr; AliasHandle tAliasHandle; anErr = FSNewAlias( NULL, pFSRef, &tAliasHandle); if ( noErr == anErr && tAliasHandle == NULL ) { anErr = paramErr; } if ( noErr == anErr ) { char handleState; handleState = HGetState((Handle) tAliasHandle ); HLock((Handle) tAliasHandle ); anErr = AEPutParamPtr( pAERecord, pKeyword, typeAlias, *tAliasHandle, (*tAliasHandle)->aliasSize); HSetState( (Handle)tAliasHandle, handleState ); DisposeHandle( (Handle)tAliasHandle ); } return anErr; }//end MoreAEOAddAliasParameterFromFSRef
Handle NewEmptyHandle(void) { Ptr p = _AllocateMasterPointerInZone(_MemGetPrivate()->currentZone); HSetState(&p, 0); return &p; }
Handle TempNewHandle(Size logicalSize, OSErr * resultCode) { Ptr p = _AllocateMasterPointerInZone(_MemGetPrivate()->tempZone); HSetState(&p, 0); *resultCode = noErr; return &p; }
/******************************************************************************** Create and return an AEDesc of type typeAlias using the provided alias record. pAliasHdl input: Handle to an alias record. pAliasAEDesc input: Pointer to null AEDesc. output: an AEDesc of type typeAlias. RESULT CODES ____________ noErr 0 No error memFullErr -108 Not enough room in heap zone */ pascal OSErr MoreAEOCreateAliasDesc( const AliasHandle pAliasHdl, AEDesc *pAliasAEDesc ) { OSErr anErr = noErr; char handleState = HGetState( (Handle)pAliasHdl ); HLock( (Handle)pAliasHdl ); anErr = AECreateDesc( typeAlias, *pAliasHdl, GetHandleSize( (Handle)pAliasHdl ), pAliasAEDesc ); HSetState( (Handle)pAliasHdl, handleState ); return anErr; }//end MoreAEOCreateAliasDesc
static void dump_handle (Handle h) { SignedByte state; LONGINT length; state = HGetState (h); length = GetHandleSize (h); HLock (h); printf ("state = 0x%x, length = %d, bytes = \"%.*s\"\n", state, length, (int) length, *h); HSetState (h, state); }
static PyObject *ResObj_get_data(ResourceObject *self, void *closure) { PyObject *res; char state; state = HGetState(self->ob_itself); HLock(self->ob_itself); res = PyString_FromStringAndSize( *self->ob_itself, GetHandleSize(self->ob_itself)); HUnlock(self->ob_itself); HSetState(self->ob_itself, state); return res; }
extern pascal void MoreLookupError(SInt16 errorResourceID, OSStatus errNum, Str255 errStr) { Handle errH; SInt8 s; OSStatus candidateErrNum; UInt8 *errDataPtr; ByteCount indexIntoErrsData; ByteCount maxIndexIntoErrsData; Boolean found; errStr[0] = 0; errH = GetResource('µErr', errorResourceID); if (errH != NULL) { s = HGetState(errH); HLock(errH); errDataPtr = (UInt8 *) *errH; indexIntoErrsData = 0; maxIndexIntoErrsData = GetHandleSize(errH); found = false; // Loop through the resource looking for a match. while ( (indexIntoErrsData < maxIndexIntoErrsData) && !found ) { // Extract the error number. // I use BlockMoveData here because the data may not be word aligned, and // original 68Ks will take an Address Error if I attempt to move an // unaligned longint. BlockMoveData(&errDataPtr[indexIntoErrsData], &candidateErrNum, sizeof(candidateErrNum)); indexIntoErrsData += sizeof(candidateErrNum); // Extract the error string. BlockMoveData(&errDataPtr[indexIntoErrsData], errStr, errDataPtr[indexIntoErrsData] + 1); indexIntoErrsData += errDataPtr[indexIntoErrsData] + 1; // Figure out whether we've found what we're looking for. found = ( (candidateErrNum == errNum) || (candidateErrNum == 0) ); } if ( !found ) { errStr[0] = 0; } HSetState(errH, s); } }
static OSErr SpriteUtils_GetImageDescription (QTAtomContainer theKeySample, QTAtom theImagesContainerAtom, short theImageIndex, ImageDescriptionHandle theImageDesc) { QTAtom myImageAtom, myImageDataAtom; UInt8 mySaveState; UInt32 mySize; OSErr myErr = noErr; myImageAtom = QTFindChildByIndex(theKeySample, theImagesContainerAtom, kSpriteImageAtomType, theImageIndex, NULL); if (myImageAtom == 0) { myErr = cannotFindAtomErr; goto bail; } myImageDataAtom = QTFindChildByIndex(theKeySample, myImageAtom, kSpriteImageDataAtomType, 1, NULL); if (myImageDataAtom == 0) { myErr = cannotFindAtomErr; goto bail; } mySaveState = HGetState((Handle)theImageDesc); HUnlock((Handle)theImageDesc); // copy the data (ImageDescription followed by image data) to a handle myErr = QTCopyAtomDataToHandle(theKeySample, myImageDataAtom, (Handle)theImageDesc); if (myErr != noErr) goto bail; mySize = EndianU32_BtoN((**theImageDesc).idSize); // pull off anything following the image description (& its color table, if any, and any image description extensions) SetHandleSize((Handle)theImageDesc, mySize); #if TARGET_RT_LITTLE_ENDIAN EndianUtils_ImageDescription_BtoN(theImageDesc); #endif HSetState((Handle)theImageDesc, mySaveState); myErr = MemError(); bail: return(myErr); }
// This routine takes a CTab and generates a mapping array which will map one colour onto the best // tinted colour in the palette. It makes no attempt to change the colours in the palette, they // are mapped to the closest match. void MakeTintMapShifted(CTabHandle theClut,TintPtr theTint,long rShift,long gShift,long bShift) { char origState=HGetState((Handle)theClut); RGBColor theCol; short count,index; Boolean openedWorld=false; HLock((Handle)theClut); CTabChanged(theClut); // important, otherwise the remapping goes : "fsd;jhgflkasrhgflkdsavbn.asdkjrhvliuabhdv.kjhopsd; jrg;osnalkgvsa;rlfjhlkhbeoirlh" if (!gBL_TintWorld) { OpenTintWorld(theClut); openedWorld=true; } if (gBL_TintWorld) { for(count=0; count<=(**theClut).ctSize; count++) { theCol=(**theClut).ctTable[count].rgb; ShiftColour(&theCol,rShift,gShift,bShift); index=RGB2IndexGW(theClut,&theCol); if (index!=-1) // if a match could not be found then put the original colour in theTint[count]=index; else theTint[count]=count; } if (openedWorld) CloseTintWorld(); } HSetState((Handle)theClut,origState); }
/* ---------------------------------------------------------------------------- tbitStartup Initialize TPS off-screen bitmap subsystem at startup. Returns error code indicating success. ---------------------------------------------------------------------------- */ TPSAPI_DECLP( BOOLEAN ) tbitStartup (uWORD NrPorts, uWORD depth, HNATIVE hColor) { sWORD i; Rect Bounds; OSErr osError = noErr; SignedByte saveState; PixMapHandle hPixMap = nil; // handle to new off-screen PixMap short bytesPerRow; // bytes per row in PixMap fHasColorQuickdraw = tsysMacHasCQD(true); /** validations/initializations **/ TpsAssert((_TPorts == nil), "Bitmap subsystem was already been started up!"); TpsAssert((hColor != nil), "Bitmap subsystem color table must be provided!"); TpsAssert(tsysMacHasSys7(), "System 7 or greater required!"); TpsAssert(fHasColorQuickdraw, "32Bit Color QuickDraw required!"); TpsAssert(tsysMacHasGWorlds(), "QuickDraw Color GWorlds required!"); GetPort(&_pStartupPort); _hStartupDevice = GetGDevice(); /** clone the clut (to be used throughout) **/ saveState = HGetState((Handle)hColor); // save color tableÕs current state HNoPurge((Handle)hColor); // make sure it isnÕt purgeable _hColorTable = (CTabHandle)hColor; osError = HandToHand((Handle *)&_hColorTable); HSetState((Handle)hColor, saveState); // restore color tableÕs state if (osError != noErr) { // terrSetErrorCode(TERR_TMEMSECTION, TMEM_ERRALLOC); return FALSE; } /** create device (to be used throughout) **/ //SetRect(&Bounds, 0, 0, 1, 1); Bounds.left = 0; Bounds.top = 0; Bounds.right = 1; Bounds.bottom = 1; bytesPerRow = 16; // 16 byte align rowbytes if ((hPixMap = (PixMapHandle)NewHandleClear(sizeof(PixMap))) == nil) goto Failure; if (_SetUpPixMap(depth, &Bounds, _hColorTable, bytesPerRow, hPixMap) != noErr) goto Failure; if ((_hTBitDevice = (GDHandle)NewHandleClear(sizeof(GDevice))) == nil) goto Failure; if (_CreateGDevice(hPixMap, _hTBitDevice) != noErr) goto Failure; /** create internal port list **/ if ((_TPorts = (TBitPort *)NewPtrClear(sizeof(TBitPort) * (NrPorts + 1))) == nil) goto Failure; /** create pool of off-screen ports **/ //SetRect(&Bounds, 0, 0, 1, 1); Bounds.left = 0; Bounds.top = 0; Bounds.right = 1; Bounds.bottom = 1; for (i = 0; i < NrPorts; i++) { if ((_TPorts[i].pPort = (CGrafPtr)NewPtrClear(sizeof(CGrafPort))) == nil) goto Failure; OpenCPort(_TPorts[i].pPort); _TPorts[i].hOldPixMap = (_TPorts[i].pPort)->portPixMap; SetPortPix(nil); } /** clean up and out **/ SetPort(_pStartupPort); SetGDevice(_hStartupDevice); _NrTPorts = NrPorts; return TRUE; Failure: if (hPixMap != nil) { if ((**hPixMap).pmTable != nil) DisposCTable((**hPixMap).pmTable); if ((**hPixMap).baseAddr != nil) DisposHandle((Handle)(**hPixMap).baseAddr); DisposHandle((Handle)hPixMap); } if (_hTBitDevice != nil) { if ((**_hTBitDevice).gdITable != nil) DisposHandle((Handle)(**_hTBitDevice).gdITable); DisposHandle((Handle)_hTBitDevice); _hTBitDevice = nil; } if (_TPorts != nil) { for (i = 0; i < NrPorts; i++) { if (_TPorts[i].pPort != nil) { SetPort((GrafPtr)_TPorts[i].pPort); SetPortPix(_TPorts[i].hOldPixMap); CloseCPort(_TPorts[i].pPort); } } tmemFreeNativePtr(_TPorts); _TPorts = nil; } if (_hColorTable != nil) DisposCTable(_hColorTable); SetGDevice(_hStartupDevice); SetPort(_pStartupPort); // terrSetErrorCode(TERR_TMEMSECTION, TMEM_ERRALLOC); return FALSE; }
OSErr SpriteUtils_AddCompressedSpriteSampleToMedia (Media theMedia, QTAtomContainer theSample, TimeValue theDuration, Boolean isKeyFrame, OSType theDataCompressorType, TimeValue *theSampleTime) { SpriteDescriptionHandle mySampleDesc = NULL; Handle myCompressedSample = NULL; ComponentInstance myComponent = NULL; OSErr myErr = noErr; myErr = OpenADefaultComponent(DataCompressorComponentType, theDataCompressorType, &myComponent); if (myErr != noErr) goto bail; mySampleDesc = (SpriteDescriptionHandle)NewHandleClear(sizeof(SpriteDescription)); if (mySampleDesc == NULL) { myErr = MemError(); goto bail; } if (myComponent != NULL) { UInt32 myCompressBufferSize, myActualCompressedSize, myDecompressSlop = 0; UInt32 myUncompressedSize; SignedByte mySaveState = HGetState(theSample); myErr = (OSErr)DataCodecGetCompressBufferSize(myComponent, GetHandleSize(theSample), &myCompressBufferSize); if (myErr != noErr) goto bail; myCompressedSample = NewHandle(sizeof(UInt32) + myCompressBufferSize); myErr = MemError(); if (myErr != noErr) goto bail; HLockHi(theSample); HLockHi(myCompressedSample); myErr = (OSErr)DataCodecCompress(myComponent, *theSample, GetHandleSize(theSample), *myCompressedSample + sizeof(UInt32), // room for size at beginning myCompressBufferSize, &myActualCompressedSize, &myDecompressSlop); HSetState(theSample, mySaveState); HUnlock(myCompressedSample); if (myErr != noErr) goto bail; SetHandleSize(myCompressedSample, sizeof(UInt32) + myActualCompressedSize); myErr = MemError(); if (myErr != noErr) goto bail; (**mySampleDesc).decompressorType = EndianU32_NtoB(theDataCompressorType); myUncompressedSize = GetHandleSize(theSample); (*(UInt32*) *myCompressedSample) = EndianU32_NtoB(myUncompressedSize); // add uncompressed size at beginning myErr = AddMediaSample(theMedia, (Handle)myCompressedSample, 0, GetHandleSize(myCompressedSample), theDuration, (SampleDescriptionHandle)mySampleDesc, 1, (short)(isKeyFrame ? 0 : mediaSampleNotSync), theSampleTime); } else { myErr = AddMediaSample(theMedia, (Handle)theSample, 0, GetHandleSize(theSample), theDuration, (SampleDescriptionHandle)mySampleDesc, 1, (short)(isKeyFrame ? 0 : mediaSampleNotSync), theSampleTime); } bail: if (myCompressedSample != NULL) DisposeHandle(myCompressedSample); if (mySampleDesc != NULL) DisposeHandle((Handle)mySampleDesc); if (myComponent != NULL) CloseComponent(myComponent); return(myErr); }
/* ** GetIconFromDesktopFile ** ** INPUT a pointer to a non-existent Handle, because we'll allocate one ** ** search each BNDL resource for the right fileCreator and once we get it ** find the 'FREF' type in BNDL ** for each localID in the type, open the FREF resource ** if the FREF is the desired fileType ** get its icon localID ** get the ICN# type in BNDL ** get the icon resource number from the icon localID ** get the icon resource type from the desktop mgr's iconType ** get the icon of that type and number */ static OSErr GetIconFromDesktopFile(ConstStr255Param volName, short vRefNum, short iconType, OSType fileCreator, OSType fileType, Handle *iconHandle) { OSErr error; short realVRefNum; Str255 desktopName; short savedResFile; short dfRefNum; BNDLRecHandle theBndl = NULL; BundleTypePtr theBundleType; short iconLocalID; short iconRsrcID; OSType iconRsrcType; Handle returnIconHandle; char bndlState; *iconHandle = NULL; error = DetermineVRefNum(volName, vRefNum, &realVRefNum); if ( error == noErr ) { error = GetDesktopFileName(realVRefNum, desktopName); if ( error == noErr ) { savedResFile = CurResFile(); /* ** Open the 'Desktop' file in the root directory. (because ** opening the resource file could preload unwanted resources, ** bracket the call with SetResLoad(s)) */ SetResLoad(false); dfRefNum = HOpenResFile(realVRefNum, fsRtDirID, desktopName, fsRdPerm); SetResLoad(true); if ( dfRefNum != -1 ) { /* ** Find the BNDL resource with the specified creator. */ error = FindBundleGivenCreator(fileCreator, &theBndl); if ( error == noErr ) { /* Lock the BNDL resource so it won't be purged when other resources are loaded */ bndlState = HGetState((Handle)theBndl); HLock((Handle)theBndl); /* Find the 'FREF' BundleType record in the BNDL resource. */ error = FindTypeInBundle(kFREFResType, theBndl, &theBundleType); if ( error == noErr ) { /* Find the local ID in the 'FREF' resource with the specified fileType */ error = GetLocalIDFromFREF(theBundleType, fileType, &iconLocalID); if ( error == noErr ) { /* Find the 'ICN#' BundleType record in the BNDL resource. */ error = FindTypeInBundle(kIconFamResType, theBndl, &theBundleType); if ( error == noErr ) { /* Find the icon's resource ID in the 'ICN#' BundleType record */ error = GetIconRsrcIDFromLocalID(theBundleType, iconLocalID, &iconRsrcID); if ( error == noErr ) { /* Map Desktop Manager icon type to resource type */ iconRsrcType = DTIconToResIcon(iconType); if ( iconRsrcType != (OSType)0 ) { /* Load the icon */ returnIconHandle = Get1Resource(iconRsrcType, iconRsrcID); if ( returnIconHandle != NULL ) { /* Copy the resource handle, and return the copy */ HandToHand(&returnIconHandle); if ( MemError() == noErr ) { *iconHandle = returnIconHandle; } else { error = afpItemNotFound; } } else { error = afpItemNotFound; } } } } } } /* Restore the state of the BNDL resource */ HSetState((Handle)theBndl, bndlState); } /* Restore the resource chain and close the Desktop file */ UseResFile(savedResFile); CloseResFile(dfRefNum); } else { error = ResError(); /* could not open Desktop file */ } } if ( (error != noErr) && (error != memFullErr) ) { error = afpItemNotFound; /* force an error we should return */ } } return ( error ); }
void hashicons (ControlHandle c) { /* todo: worry about filenames in FREFs */ /* get FREF, BNDL, ICN#, ics#, icl8, ics8, icl4, ics4 */ /* BNDL is: 4 bytes of signature 2 bytes of 0 [signature resource id?] 2 bytes of <number of main entries - 1> (almost always 1) numberofmainentries * 4 bytes of 'ICN#' or 'FREF' 2 bytes of <number of entries - 1> numberofentries * 2 bytes of localid 2 bytes of resid */ /* todo: see what happens with multiple BNDLs */ char *p; short i, j, spacemade, nummain, numbndls; unsigned short hashval; iconentry **iconarray; icontableentry **node; Handle h; OSType signature; short refnum, sigid; unsigned char state; applist **ah; refnum = openappres (c); numbndls = Count1Resources ('BNDL'); for (i = 1; i <= numbndls; i++) { h = (Handle) Get1IndResource ('BNDL', i); state = HGetState (h); HLock (h); p = *h; signature = *(OSType *) p; p += 4; sigid = *(short *) p; p += 2; hashval = (unsigned long) signature % SIGARRAYSIZE; #define CONTROLPROBLEMS #ifndef CONTROLPROBLEMS for (ah = sigowners[hashval]; ah != 0 && (*ah)->sig != signature; ah = (*ah)->next) ; if (ah == 0) { #endif /* CONTROLPROBLEMS */ ah = sigowners[hashval]; sigowners[hashval] = (applist **) NewHandle (sizeof (applist)); (*sigowners[hashval])->next = ah; (*sigowners[hashval])->parid = (*(item **) (*c)->contrlData)->ioparid; (*sigowners[hashval])->vrefnum = (*(item **) (*c)->contrlData)->vrefnum; (*sigowners[hashval])->sig = signature; mystr255copy ((*sigowners[hashval])->name, (*c)->contrlTitle); #ifndef CONTROLPROBLEMS } #endif /* CONTROLPROBLEMS */ /* todo: find out if nummain must == 2 */ nummain = *(short *) p + 1; p += 2; spacemade = 0; for (j = 0; j < nummain; j++) { dobundle (&spacemade, &iconarray, &p); } for (j = 0; j < spacemade; j++) { hashval = ((unsigned long) signature + (unsigned long) (*iconarray)[j].type) % ICONTABLESIZE; for (node = icontable[hashval]; node != 0 && ((*node)->sig != signature || (*node)->type != (*iconarray)[j].type); node = (*node)->next) ; if (node == 0) { node = (icontableentry **) NewHandle (sizeof (icontableentry)); (*node)->sig = signature; (*node)->type = (*iconarray)[j].type; (*node)->next = icontable[hashval]; geticons (node, (*iconarray)[j].resid); icontable[hashval] = node; } } DisposHandle ((Handle) iconarray); HSetState (h, state); ReleaseResource (h); } CloseResFile (refnum); }
void HLock(Handle h) { HSetState(h, HGetState(h) | kHandleLockedMask); }
void HNoPurge(Handle h) { HSetState(h, HGetState(h) & ~kHandlePurgeableMask); }
void HPurge(Handle h) { HSetState(h, HGetState(h) | kHandlePurgeableMask); }
void HUnlock(Handle h) { HSetState(h, HGetState(h) & ~kHandleLockedMask); }