ComponentResult FFAvi_MovieImportSetSampleDescription(ff_global_ptr storage, SampleDescriptionHandle desc, OSType media) { ComponentResult result = noErr; switch(media) { case VideoMediaType: if(storage->imgHdl) /* already one stored */ DisposeHandle((Handle)storage->imgHdl); storage->imgHdl = (ImageDescriptionHandle)desc; if(storage->imgHdl) result = HandToHand((Handle*)&storage->imgHdl); break; case SoundMediaType: if(storage->sndHdl) DisposeHandle((Handle)storage->sndHdl); storage->sndHdl = (SoundDescriptionHandle)desc; if(storage->sndHdl) result = HandToHand((Handle*)&storage->sndHdl); break; default: break; } return result; } /* FFAvi_MovieImportSetSampleDescription() */
static pascal ComponentResult myDataHGetDataRef ( DataHandler dh, Handle *dataRef) { Handle storage = GetComponentInstanceStorage(dh); TRACE("\n"); *dataRef = storage; HandToHand(dataRef); return noErr; }
short ModalMacros(NewMacroInfo *macrost) { DialogPtr dtemp; short dItem; short i; Rect dBox; Str255 temp; Handle MacString[10], rubbish; SetUpMovableModalMenus(); dtemp=GetNewMyDialog( MacroDLOG + 2, NULL, kInFront, (void *)ThirdCenterDialog); SetDialogDefaultItem(dtemp, 1); SetDialogCancelItem(dtemp, 2); SetDialogTracksCursor(dtemp, 1); HideDialogItem(dtemp, 25); // no save default in session macros dialog dialogPane = 0; // start with Command-[0-9] // RAB BetterTelnet 2.0b5 - fix cancel button so it works again oldMacros = macrost->handle; HandToHand(&oldMacros); oldMacroIndexes = *macrost; // now fix the strings for (i=0; i<10; i++) { GetIndString(temp, 7100, i + (10 * dialogPane) + 1); GetDialogItem(dtemp, i+3, &dItem, &rubbish, &dBox); if (!temp[0]) { HideDialogItem(dtemp, i+13); HideDialogItem(dtemp, i+3); } else { ShowDialogItem(dtemp, i+13); ShowDialogItem(dtemp, i+3); } SetDialogItemText(rubbish, temp); } for (i=0; i<10; i++) { getmacro(macrost, i, (char *) &temp, 256); /* BYU LSC */ c2pstr((char *)temp); /* BYU LSC */ GetDialogItem( dtemp, i+13, &dItem, &MacString[i], &dBox); SetDialogItemText( MacString[i], temp ); } TelInfo->macrosModeless = dtemp; dItem = 0; while ((dItem != 1) && (dItem != 2)) { movableModalDialog(0, &dItem); MacroDialog(macrost, dtemp, 0, dItem); } if (dItem == 2) CancelMacros(macrost, dtemp); else CloseMacros(macrost, dtemp); ResetMenus(); return dItem; }
void Macros( void) { DialogPtr dtemp; short dItem; short i; Rect dBox; Str255 temp; Handle MacString[10], rubbish; setLastCursor(theCursors[normcurs]); if (TelInfo->macrosModeless) { SelectWindow(TelInfo->macrosModeless); return; } dtemp=GetNewMyDialog( MacroDLOG, NULL, kInFront, (void *)ThirdCenterDialog); SetDialogDefaultItem(dtemp, 1); SetDialogCancelItem(dtemp, 2); SetDialogTracksCursor(dtemp, 1); dialogPane = 0; // start with Command-[0-9] // RAB BetterTelnet 2.0b5 - fix cancel button so it works again oldMacros = TelInfo->newMacros.handle; HandToHand(&oldMacros); oldMacroIndexes = TelInfo->newMacros; // now fix the strings for (i=0; i<10; i++) { GetIndString(temp, 7100, i + (10 * dialogPane) + 1); GetDialogItem(dtemp, i+3, &dItem, &rubbish, &dBox); if (!temp[0]) { HideDialogItem(dtemp, i+13); HideDialogItem(dtemp, i+3); } else { ShowDialogItem(dtemp, i+13); ShowDialogItem(dtemp, i+3); } SetDialogItemText(rubbish, temp); } for (i=0; i<10; i++) { getmacro(&TelInfo->newMacros, i, (char *) &temp, 256); /* BYU LSC */ c2pstr((char *)temp); /* BYU LSC */ GetDialogItem( dtemp, i+13, &dItem, &MacString[i], &dBox); SetDialogItemText( MacString[i], temp ); } TelInfo->macrosModeless = dtemp; }
void initPixmap() { Ptr offBaseAddr; /* Pointer to the off-screen pixel image */ short bytesPerRow; GDHandle mainDevice; CTabHandle cTable; short depth; /* Get a handle to the main device. */ mainDevice = GetMainDevice(); /* Store its current pixel depth. */ depth = (**(**mainDevice).gdPMap).pixelSize; /* Make an identical copy of its pixmap's colortable. */ cTable = (**(**mainDevice).gdPMap).pmTable; (void) HandToHand( (Handle*)(&cTable) ); bytesPerRow = ((gBounds.right - gBounds.left) * depth) / 8; offBaseAddr = NewPtr((unsigned long)bytesPerRow * (gBounds.bottom - gBounds.top)); gPixMap.baseAddr = offBaseAddr; /* Point to image */ gPixMap.rowBytes = bytesPerRow | 0x8000; /* MSB set for PixMap */ gPixMap.bounds = gBounds; /* Use given bounds */ gPixMap.pmVersion = 0; /* No special stuff */ gPixMap.packType = 0; /* Default PICT pack */ gPixMap.packSize = 0; /* Always zero in mem */ gPixMap.hRes = 72; /* 72 DPI default res */ gPixMap.vRes = 72; /* 72 DPI default res */ gPixMap.pixelSize = depth; /* Set # bits/pixel */ //gPixMap.planeBytes = 0; /* Not used */ //gPixMap.pmReserved = 0; /* Not used */ gPixMap.pixelType = 0; /* Indicates indexed */ gPixMap.cmpCount = 1; /* Have 1 component */ gPixMap.cmpSize = depth; /* Component size=depth */ gPixMap.pmTable = cTable; /* Handle to CLUT */ }
void saveMacros(NewMacroInfo *macrost, FSSpec *theFile) { SFReply whereReply; short refNum,exist; FSSpec macroFile; long junk, len, len2; short i; Point where; OSErr err; Str255 tempString,tempString2; Handle macroHandle; Ptr pos; if (!macrost->handle) return; // sanity check where.h = 100; where.v = 100; GetIndString(tempString,MISC_STRINGS,SAVE_MACROS_STRING); GetIndString(tempString2,MISC_STRINGS,DEFAULT_MACRO_SET_NAME); if (theFile == 0) { SFPutFile( where, tempString, tempString2, 0L, &whereReply); if (!whereReply.good) return; BlockMoveData(&whereReply.fName, macroFile.name, (*whereReply.fName)+1); GetWDInfo(whereReply.vRefNum, ¯oFile.vRefNum, ¯oFile.parID, &junk); } else macroFile = *theFile; if ((err = HCreate(macroFile.vRefNum, macroFile.parID, macroFile.name, kNCSACreatorSignature, 'TEXT')) == dupFNErr) exist = 1; err = HOpenDF(macroFile.vRefNum, macroFile.parID, macroFile.name, fsWrPerm, &refNum); if (exist) SetEOF(refNum, 0L); // the new code - RAB BetterTelnet 2.0b5 macroHandle = macrost->handle; HandToHand(¯oHandle); HLock(macroHandle); pos = *macroHandle; len = len2 = GetHandleSize(macroHandle); while (len) { if (*pos == 0) *pos = 13; pos++; len--; } pos = *macroHandle; junk = 2; FSWrite(refNum, &junk, "!\015"); FSWrite(refNum, &len2, pos); DisposeHandle(macroHandle); // it's a copy anyway, get rid of it! FSClose(refNum); }
void wxMacClassicPrintData::CopyFrom( wxNativePrintData* data ) { DisposeHandle( (Handle) m_macPrintSettings ) ; m_macPrintSettings = ((wxMacClassicPrintData*)data)->m_macPrintSettings; HandToHand( (Handle*) &m_macPrintSettings ); }
/* ---------------------------------------------------------------------------- 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; }
/* ** 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 wxCursor::CreateFromImage(const wxImage & image) { m_refData = new wxCursorRefData; int w = 16; int h = 16; int hotSpotX = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X); int hotSpotY = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y); int image_w = image.GetWidth(); int image_h = image.GetHeight(); wxASSERT_MSG( hotSpotX >= 0 && hotSpotX < image_w && hotSpotY >= 0 && hotSpotY < image_h, _T("invalid cursor hot spot coordinates") ); wxImage image16(image); // final image of correct size // if image is too small then place it in the center, resize it if too big if ((w > image_w) && (h > image_h)) { wxPoint offset((w - image_w)/2, (h - image_h)/2); hotSpotX = hotSpotX + offset.x; hotSpotY = hotSpotY + offset.y; image16 = image.Size(wxSize(w, h), offset); } else if ((w != image_w) || (h != image_h)) { hotSpotX = int(hotSpotX * double(w) / double(image_w)); hotSpotY = int(hotSpotY * double(h) / double(image_h)); image16 = image.Scale(w, h); } unsigned char * rgbBits = image16.GetData(); bool bHasMask = image16.HasMask() ; #if 0 // monochrome implementation M_CURSORDATA->m_hCursor = NewHandle( sizeof( Cursor ) ) ; M_CURSORDATA->m_disposeHandle = true ; HLock( (Handle) M_CURSORDATA->m_hCursor ) ; CursPtr cp = *(CursHandle)M_CURSORDATA->m_hCursor ; memset( cp->data , 0 , sizeof( Bits16 ) ) ; memset( cp->mask , 0 , sizeof( Bits16 ) ) ; unsigned char mr = image16.GetMaskRed() ; unsigned char mg = image16.GetMaskGreen() ; unsigned char mb = image16.GetMaskBlue() ; for ( int y = 0 ; y < h ; ++y ) { short rowbits = 0 ; short maskbits = 0 ; for ( int x = 0 ; x < w ; ++x ) { long pos = (y * w + x) * 3; unsigned char r = rgbBits[pos] ; unsigned char g = rgbBits[pos+1] ; unsigned char b = rgbBits[pos+2] ; if ( bHasMask && r==mr && g==mg && b==mb ) { // masked area, does not appear anywhere } else { if ( (int)r + (int)g + (int)b < 0x0200 ) { rowbits |= ( 1 << (15-x) ) ; } maskbits |= ( 1 << (15-x) ) ; } } cp->data[y] = rowbits ; cp->mask[y] = maskbits ; } if ( !bHasMask ) { memcpy( cp->mask , cp->data , sizeof( Bits16) ) ; } cp->hotSpot.h = hotSpotX ; cp->hotSpot.v = hotSpotY ; HUnlock( (Handle) M_CURSORDATA->m_hCursor ) ; #else PixMapHandle pm = (PixMapHandle) NewHandleClear( sizeof (PixMap)) ; short extent = 16 ; short bytesPerPixel = 1 ; short depth = 8 ; Rect bounds = { 0 , 0 , extent , extent } ; CCrsrHandle ch = (CCrsrHandle) NewHandleClear ( sizeof( CCrsr ) ) ; CTabHandle newColors = GetCTable( 8 ) ; HandToHand((Handle *) &newColors); // set the values to the indices for ( int i = 0 ; i < (**newColors).ctSize ; ++i ) { (**newColors).ctTable[i].value = i ; } HLock( (Handle) ch) ; (**ch).crsrType = 0x8001 ; // color cursors (**ch).crsrMap = pm ; short bytesPerRow = bytesPerPixel * extent ; (**pm).baseAddr = 0; (**pm).rowBytes = bytesPerRow | 0x8000; (**pm).bounds = bounds; (**pm).pmVersion = 0; (**pm).packType = 0; (**pm).packSize = 0; (**pm).hRes = 0x00480000; /* 72 DPI default res */ (**pm).vRes = 0x00480000; /* 72 DPI default res */ (**pm).pixelSize = depth; (**pm).pixelType = 0; (**pm).cmpCount = 1; (**pm).cmpSize = depth; (**pm).pmTable = newColors; (**ch).crsrData = NewHandleClear( extent * bytesPerRow ) ; (**ch).crsrXData = NULL ; (**ch).crsrXValid = 0; (**ch).crsrXHandle = NULL; (**ch).crsrHotSpot.h = hotSpotX ; (**ch).crsrHotSpot.v = hotSpotY ; (**ch).crsrXTable = NULL ; (**ch).crsrID = GetCTSeed() ; memset( (**ch).crsr1Data , 0 , sizeof( Bits16 ) ) ; memset( (**ch).crsrMask , 0 , sizeof( Bits16 ) ) ; unsigned char mr = image16.GetMaskRed() ; unsigned char mg = image16.GetMaskGreen() ; unsigned char mb = image16.GetMaskBlue() ; for ( int y = 0 ; y < h ; ++y ) { short rowbits = 0 ; short maskbits = 0 ; for ( int x = 0 ; x < w ; ++x ) { long pos = (y * w + x) * 3; unsigned char r = rgbBits[pos] ; unsigned char g = rgbBits[pos+1] ; unsigned char b = rgbBits[pos+2] ; RGBColor col = { 0xFFFF ,0xFFFF, 0xFFFF } ; if ( bHasMask && r==mr && g==mg && b==mb ) { // masked area, does not appear anywhere } else { if ( (int)r + (int)g + (int)b < 0x0200 ) { rowbits |= ( 1 << (15-x) ) ; } maskbits |= ( 1 << (15-x) ) ; col = *((RGBColor*) wxColor( r , g , b ).GetPixel()) ; } *((*(**ch).crsrData) + y * bytesPerRow + x) = GetCTabIndex( newColors , &col) ; } (**ch).crsr1Data[y] = rowbits ; (**ch).crsrMask[y] = maskbits ; } if ( !bHasMask ) { memcpy( (**ch).crsrMask , (**ch).crsr1Data , sizeof( Bits16) ) ; } HUnlock((Handle) ch) ; M_CURSORDATA->m_hCursor = ch ; M_CURSORDATA->m_isColorCursor = true ; #endif }
void createOffscreen() { Rect rect; Handle iclHandle; char *image; int row, col, index, value; SetRect( &rect, 0, 0, 32, 32 ); /* Create offscreen pixmap image using an 'icl8' icon resource. */ iclHandle = GetResource( 'icl8', 129 ); HandToHand( &iclHandle ); HLock( iclHandle ); HNoPurge( iclHandle ); //gPixmap = (PixMapHandle)NewHandle( sizeof( PixMap ) ); gPixmap = NewPixMap(); (**gPixmap).baseAddr = *iclHandle; (**gPixmap).rowBytes = ((32 * 8) / 8) | 0x8000; (**gPixmap).bounds = rect; (**gPixmap).pmVersion = 0; (**gPixmap).packType = 0; (**gPixmap).packSize = 0; (**gPixmap).hRes = 72; (**gPixmap).vRes = 72; (**gPixmap).pixelSize = 8; //(**gPixmap).planeBytes = 0; //(**gPixmap).pmReserved = 0; (**gPixmap).pixelType = 0; (**gPixmap).cmpCount = 1; (**gPixmap).cmpSize = 8; (**gPixmap).pmTable = GetCTable( 8 ); (**gPixmap).pixelFormat = 0; /* Give a unique seed for the pixmap's colortable. */ (**(**gPixmap).pmTable).ctSeed = GetCTSeed(); SetRect( &rect, 0, 0, 20, 20 ); /* Set the pointer to the beginning of the pixel image. */ image = GetPixBaseAddr( gPixmap ); /*****************************************************************/ /* For this example, let's set the pixel values of the left half */ /* of the image to half their original values. */ /*****************************************************************/ for (row = 0; row < rect.bottom; row++) { // Loop through the first 10 columns of the pixel image. for (index = 0, col = 0; col < rect.right / 2; col++) { // Set the value at this index to half its value. value = (unsigned char)*(image + index); *(image + index) = value / 2; index++; } // Increment the pointer to the next row of the pixel image. image += ((**gPixmap).rowBytes & 0x7fff); } }
PixMapHandle get_shape_pixmap( short shape, boolean force_copy) { OSErr error; struct collection_definition *collection; struct low_level_shape_definition *low_level_shape; struct bitmap_definition *bitmap; short collection_index, low_level_shape_index, clut_index; collection_index= GET_COLLECTION(GET_DESCRIPTOR_COLLECTION(shape)); clut_index= GET_COLLECTION_CLUT(GET_DESCRIPTOR_COLLECTION(shape)); low_level_shape_index= GET_DESCRIPTOR_SHAPE(shape); collection= get_collection_definition(collection_index); switch (interface_bit_depth) { case 8: /* if the ctSeed of our offscreen pixmap is different from the ctSeed of the world device then the color environment has changed since the last call to our routine, and we just HandToHand the deviceÕs ctTable and throw away our old one. */ if ((*(*(*world_device)->gdPMap)->pmTable)->ctSeed!=(*(*hollow_pixmap)->pmTable)->ctSeed) { DisposeHandle((Handle)(*hollow_pixmap)->pmTable); (*hollow_pixmap)->pmTable= (*(*world_device)->gdPMap)->pmTable; HLock((Handle)hollow_pixmap); error= HandToHand((Handle *)&(*hollow_pixmap)->pmTable); HUnlock((Handle)hollow_pixmap); assert(error==noErr); /* this is a device color table so we donÕt clear ctFlags (well, it isnÕt a device color table anymore, but itÕs formatted like one */ } break; case 16: case 32: if (!hollow_pixmap_color_table) { hollow_pixmap_color_table= (CTabHandle) NewHandle(sizeof(ColorTable)+PIXEL8_MAXIMUM_COLORS*sizeof(ColorSpec)); MoveHHi((Handle)hollow_pixmap_color_table); HLock((Handle)hollow_pixmap_color_table); assert(hollow_pixmap_color_table); } (*hollow_pixmap_color_table)->ctSeed= GetCTSeed(); (*hollow_pixmap_color_table)->ctSize= collection->color_count-NUMBER_OF_PRIVATE_COLORS-1; (*hollow_pixmap_color_table)->ctFlags= 0; BlockMove(get_collection_colors(collection_index, clut_index)+NUMBER_OF_PRIVATE_COLORS, &(*hollow_pixmap_color_table)->ctTable, (collection->color_count-NUMBER_OF_PRIVATE_COLORS)*sizeof(ColorSpec)); (*hollow_pixmap)->pmTable= hollow_pixmap_color_table; break; default: halt(); } low_level_shape= get_low_level_shape_definition(collection_index, low_level_shape_index); bitmap= get_bitmap_definition(collection_index, low_level_shape->bitmap_index); /* setup the pixmap (canÕt wait to change this for Copland) */ SetRect(&(*hollow_pixmap)->bounds, 0, 0, bitmap->width, bitmap->height); (*hollow_pixmap)->rowBytes= bitmap->width|0x8000; (*hollow_pixmap)->baseAddr= (Ptr)bitmap->row_addresses[0]; if (bitmap->bytes_per_row==NONE) /* is this a compressed shape? */ { register pixel8 *read, *write; register short run_count; short x; /* for now all RLE shapes are in column-order */ assert(bitmap->flags&_COLUMN_ORDER_BIT); /* donÕt overflow the buffer */ assert(bitmap->width*bitmap->height<=HOLLOW_PIXMAP_BUFFER_SIZE); /* decompress column-order shape into row-order buffer */ for (x=0;x<bitmap->width;x+=1) { short bytes_per_row= bitmap->width; write= hollow_data+x; read= bitmap->row_addresses[x]; while (run_count= *((short*)read)++) { if (run_count<0) while ((run_count+=1)<=0) *write= iBLACK, write+= bytes_per_row; /* fill transparent areas with black */ else while ((run_count-=1)>=0) *write= *read++, write+= bytes_per_row; /* copy shape data */ } } (*hollow_pixmap)->baseAddr= (Ptr)hollow_data; } else { /* if this is a raw, row-order shape then only copy it if weÕve been asked to */ if (force_copy) { assert(bitmap->width*bitmap->height<=HOLLOW_PIXMAP_BUFFER_SIZE); BlockMove(bitmap->row_addresses[0], hollow_data, bitmap->width*bitmap->height); (*hollow_pixmap)->baseAddr= (Ptr)hollow_data; } } return hollow_pixmap; }
PixMapHandle editor_get_shape_pixmap( short shape) { OSErr error; struct collection_definition *collection; struct low_level_shape_definition *low_level_shape; struct bitmap_definition *bitmap; short collection_index, low_level_shape_index, clut_index; collection_index= GET_COLLECTION(GET_DESCRIPTOR_COLLECTION(shape)); clut_index= GET_COLLECTION_CLUT(GET_DESCRIPTOR_COLLECTION(shape)); low_level_shape_index= GET_DESCRIPTOR_SHAPE(shape); collection= get_collection_definition(collection_index); switch (interface_bit_depth) { case 8: /* if the ctSeed of our offscreen pixmap is different from the ctSeed of the world device then the color environment has changed since the last call to our routine, and we just HandToHand the deviceÕs ctTable and throw away our old one. */ if ((*(*(*world_device)->gdPMap)->pmTable)->ctSeed!=(*(*hollow_pixmap)->pmTable)->ctSeed) { DisposeHandle((Handle)(*hollow_pixmap)->pmTable); (*hollow_pixmap)->pmTable= (*(*world_device)->gdPMap)->pmTable; HLock((Handle)hollow_pixmap); error= HandToHand((Handle *)&(*hollow_pixmap)->pmTable); HUnlock((Handle)hollow_pixmap); assert(error==noErr); /* this is a device color table so we donÕt clear ctFlags (well, it isnÕt a device color table anymore, but itÕs formatted like one */ } break; case 16: case 32: if (!hollow_pixmap_color_table) { hollow_pixmap_color_table= (CTabHandle) NewHandle(sizeof(ColorTable)+PIXEL8_MAXIMUM_COLORS*sizeof(ColorSpec)); MoveHHi((Handle)hollow_pixmap_color_table); HLock((Handle)hollow_pixmap_color_table); assert(hollow_pixmap_color_table); } (*hollow_pixmap_color_table)->ctSeed= GetCTSeed(); (*hollow_pixmap_color_table)->ctSize= collection->color_count-NUMBER_OF_PRIVATE_COLORS-1; (*hollow_pixmap_color_table)->ctFlags= 0; BlockMove(get_collection_colors(collection_index, clut_index)+NUMBER_OF_PRIVATE_COLORS, &(*hollow_pixmap_color_table)->ctTable, (collection->color_count-NUMBER_OF_PRIVATE_COLORS)*sizeof(ColorSpec)); (*hollow_pixmap)->pmTable= hollow_pixmap_color_table; break; default: halt(); } low_level_shape= get_low_level_shape_definition(collection_index, low_level_shape_index); bitmap= get_bitmap_definition(collection_index, low_level_shape->bitmap_index); /* setup the pixmap (canÕt wait to change this for Copland) */ SetRect(&(*hollow_pixmap)->bounds, 0, 0, bitmap->width, bitmap->height); (*hollow_pixmap)->rowBytes= bitmap->width|0x8000; (*hollow_pixmap)->baseAddr= (Ptr)bitmap->row_addresses[0]; /* Rotate if necessary */ if ((bitmap->flags&_COLUMN_ORDER_BIT) && bitmap->width==128 && bitmap->height==128) { static char *buffer= NULL; if(!buffer) { buffer= (char *)malloc(bitmap->width*bitmap->height*sizeof(pixel8)); } if(buffer) { short x, y; pixel8 *dest= (pixel8 *) buffer; /* decompress column-order shape into row-order buffer */ for (x=0;x<bitmap->width;x+=1) { for(y= 0; y<bitmap->height; y+=1) { *dest++= bitmap->row_addresses[y][x]; } } (*hollow_pixmap)->baseAddr= buffer; } } return hollow_pixmap; }
OSErr IconFamilyToIPIconWithSelector(IconFamilyHandle theIconFamily, const IPIconSelector *ipSelector,IPIconRec *ipIcon) { OSErr err=noErr; Handle dataHandle; long dataSize; if (ipSelector->selector != 0) { err=IconFamilyToIconSuite(theIconFamily,ipSelector->selector,&ipIcon->iconSuite); if (err==noErr) { /* Mac OS X 10.8 (Mavericks) で動作させると、32ビットデータがコピーされないので、 手作業でコピーする */ if (ipSelector->selector|kLarge32BitData) { Handle dummyHandle; dummyHandle = NewHandle(0); err=GetIconFamilyData(theIconFamily,kLarge32BitData,dummyHandle); if (err==noErr) { dataSize=GetHandleSize(dummyHandle); err=AddIconToSuite(dummyHandle,ipIcon->iconSuite,kLarge32BitData); } else { DisposeHandle(dummyHandle); err=noErr; } } if (ipSelector->selector|kSmall32BitData) { Handle dummyHandle; dummyHandle = NewHandle(0); err=GetIconFamilyData(theIconFamily,kSmall32BitData,dummyHandle); if (err==noErr) { dataSize=GetHandleSize(dummyHandle); err=AddIconToSuite(dummyHandle,ipIcon->iconSuite,kSmall32BitData); } else { DisposeHandle(dummyHandle); err=noErr; } } } } else ipIcon->iconSuite = NULL; if (err==noErr) { if (isThumbnailIconsAvailable) { /* the others */ if (ipSelector->it32) { dataHandle=NewHandle(0); err=GetIconFamilyData(theIconFamily,kThumbnail32BitData,dataHandle); if (err==noErr) { dataSize = GetHandleSize(dataHandle); if (dataSize > 0) { ipIcon->it32Data = dataHandle; HandToHand(&ipIcon->it32Data); } else ipIcon->it32Data = NULL; } else if (err == noIconDataAvailableErr || err == paramErr) // 1.20b14 { err = noErr; ipIcon->it32Data = NULL; } DisposeHandle(dataHandle); } else ipIcon->it32Data = NULL; if (ipSelector->t8mk) { dataHandle=NewHandle(0); err=GetIconFamilyData(theIconFamily,kThumbnail8BitMask,dataHandle); if (err==noErr) { dataSize = GetHandleSize(dataHandle); if (dataSize > 0) { ipIcon->t8mkData = dataHandle; HandToHand(&ipIcon->t8mkData); } else ipIcon->t8mkData = NULL; } else if (err == noIconDataAvailableErr || err == paramErr) // 1.20b14 { err = noErr; ipIcon->t8mkData = NULL; } DisposeHandle(dataHandle); } else ipIcon->t8mkData = NULL; } else { ipIcon->it32Data = NULL; ipIcon->t8mkData = NULL; } } return err; }
// // AskIfNewResolutionWorks() creates a dialog box in the center of the screen. The dialog asks the // user if the current display setting works. This is necessary because a number of display settings // listed by the OS dont actually work and leave the user with a black screen. The dialog has a 5 // second timeout. If the user does not hit ok within 5 seconds the cancel item is chosen automatically // for him. This feature allows the user to do nothing (which he will probably do if confronted by a // black screen) and still be ok. The method that I have employed to do the timeout requires Appearances // 1.1. I believe this was introduced with OS 8.5. If you want to support back to OS 8.1, then you will // have to do your own modal dialog event proc that implements a timeout. The dialog has not default // button by default. Cmd-period and esc trigger the cancel button. // // OSStatus AskIfNewResolutionWorks( ScreenRef screen ) { DEBUGMESSAGE( "Querying user whether the new resolution works...." ); if( ! screen ) return noErr; //Read the new screen dimensions RLDrawInfo screenData; Rect dialogBounds = {0,0,130, 340}; OSStatus error = GetCurrentScreenDrawingInfo( screen, &screenData ); if( error ) { DEBUGMESSAGE( "Unable to get current screen drawing information. Got back error # " << error ); return error; } //Make a copy of our dialog item list. This will be destroyed when the dialog is destroyed. Handle ditlCopy = LoadDITL(); HandToHand( &ditlCopy ); //Center the dialog rect on the screen { SInt32 horizontalOffset = (SInt32( screenData.bounds.right) + SInt32( screenData.bounds.left ) - SInt32(dialogBounds.right) + SInt32(dialogBounds.left) ) / 2; SInt32 verticalOffset = (SInt32( screenData.bounds.bottom) + SInt32( screenData.bounds.top ) - SInt32(dialogBounds.bottom) + SInt32(dialogBounds.top) ) / 2; dialogBounds.left += horizontalOffset; dialogBounds.right += horizontalOffset; dialogBounds.top += verticalOffset; dialogBounds.bottom += verticalOffset; } //Init a new dialog hidden DialogPtr dialog = NewFeaturesDialog( NULL, &dialogBounds, "\pResolution Verification", true, kWindowModalDialogProc, (WindowPtr) -1L, false, TickCount(), ditlCopy, 0 ); if( ! dialog ) { DEBUGMESSAGE( "Unable to init the \"AskIfNewResolutionWorks\" dialog window. Perhaps there is insufficient free memory or the DITL did not load properly at library startup?" ); return rlOutOfMemory; } //Make sure the dialog cancel item is button # 2 SetDialogCancelItem( dialog, 2 ); //Set dialog to timeout after 5 seconds SetDialogTimeout( dialog, 2, 5 ); for( bool done = false; !done; ) { short itemHit = 0; ModalDialog ( NULL, &itemHit ); switch( itemHit ) { case 2: //cancel DEBUGMESSAGE( "The user hit cancel or the dialog timed out. The new resolution is probably not good." ); done = true; error = rlRezNotFound; break; case 3: //ok DEBUGMESSAGE( "The user hit ok. The new resolution seems to be Okay!" ); done = true; error = noErr; break; } } DisposeDialog( dialog ); return error; }