PRIVATE PicHandle pict_from_gworld (GWorldPtr gp, int *lenp) { PicHandle retval; if (!gp) retval = NULL; else { Rect pict_frame; PixMapHandle pm; pm = GetGWorldPixMap (gp); pict_frame = PIXMAP_BOUNDS (pm); retval = OpenPicture (&pict_frame); if (retval) { ClipRect (&pict_frame); HLock ((Handle) pm); CopyBits ((BitMap *) STARH (pm), PORT_BITS_FOR_COPY (thePort), &pict_frame, &pict_frame, srcCopy, NULL); HUnlock ((Handle) pm); ClosePicture (); } } return retval; }
static void SaveToPICT (SFReply *reply) { Rect MyPicFrame ; CQDProcs MyPicProcs,*SavePtr ; OSErr error ; long LongZero, LongCount ; short Counter ; CGrafPtr theCGrafPort; WindowPtr theWindow; OpenCPicParams myOpenCPicParams; /* get my window */ theWindow = myWindow.theWindow; theCGrafPort = (CGrafPtr) theWindow; error = FSOpen(reply->fName, reply->vRefNum, &FileSys_RefNR ) ; SetStdCProcs ( &MyPicProcs ) ; SavePtr = (CQDProcs *) theWindow->grafProcs; theWindow->grafProcs = (QDProcs *) (&MyPicProcs) ; MyPicProcs.putPicProc = NewQDPutPicProc(MyPutPicData) ; LongZero = 0 ; LongCount = 4 ; PicCounter = sizeof(Picture) ; for (Counter=1 ; Counter <= 128+sizeof(Picture) ; Counter++ ) error = FSWrite(FileSys_RefNR, &LongCount, &LongZero ); error = SetFPos(FileSys_RefNR, fsFromStart, 512+sizeof(Picture)) ; SetPort((GrafPtr)(theWindow)); MyPicFrame = ((GrafPtr)(theWindow))->portRect; MyPicFrame.right = MyPicFrame.right-16; MyPicFrame.bottom = MyPicFrame.bottom-16; MyPicHand = NULL ; myOpenCPicParams.srcRect = MyPicFrame; myOpenCPicParams.hRes = cHRes; myOpenCPicParams.vRes = cVRes; myOpenCPicParams.version = -2; myOpenCPicParams.reserved1 = 0; myOpenCPicParams.reserved2 = 0; MyPicHand = OpenCPicture ( &myOpenCPicParams ); ClipRect(&MyPicFrame); /* draw picture */ RefreshCommand(); ClosePicture() ; /* close File */ error = SetFPos(FileSys_RefNR, fsFromStart, 512) ; LongCount = sizeof(Picture) ; error = FSWrite(FileSys_RefNR, &LongCount, (void *) (*MyPicHand) ); error = FSClose(FileSys_RefNR) ; KillPicture(MyPicHand); theWindow->grafProcs = (QDProcs *) SavePtr ; return; }
PicHandle PixMapToPict(PixMapHandle inMap,Rect *sourceRect,Rect *destRect) { PicHandle recordPic=0L; recordPic=OpenPicture(destRect); if (!recordPic) return 0L; CopyBits((BitMap *)*inMap,(BitMap *)*inMap,sourceRect,destRect,srcCopy,0L); ClosePicture(); return recordPic; }
void _HYPlatformGraphicPane::_CopyToClipboard (void) { _HYGraphicPane* parent = (_HYGraphicPane*)this; #ifdef TARGET_API_MAC_CARBON ClearCurrentScrap(); #else ZeroScrap(); #endif Rect bRect; bRect.left = bRect.top = 0; bRect.right = parent->w; bRect.bottom = parent->h; PicHandle pic = OpenPicture (&bRect); GrafPtr topPort; GetPort (&topPort); LockPixels (GetGWorldPixMap(thePane)); #ifdef OPAQUE_TOOLBOX_STRUCTS CopyBits (GetPortBitMapForCopyBits(thePane),GetPortBitMapForCopyBits(topPort), &bRect,&bRect,srcCopy,(RgnHandle)nil); #else CopyBits ((BitMap*)*GetGWorldPixMap(thePane), (BitMap*)&(topPort->portBits),&bRect,&bRect, srcCopy,(RgnHandle)nil); #endif UnlockPixels (GetGWorldPixMap(thePane)); ClosePicture (); HLock ((Handle)pic); #ifdef TARGET_API_MAC_CARBON ScrapRef theScrapRef; GetCurrentScrap(&theScrapRef); PutScrapFlavor(theScrapRef, 'PICT', kScrapFlavorMaskNone,GetHandleSize((Handle)pic),*pic); #else PutScrap (GetHandleSize((Handle)pic),'PICT',*pic); #endif KillPicture (pic); }
void TkpDisplayMenuButton( ClientData clientData) /* Information about widget. */ { TkMenuButton *butPtr = (TkMenuButton *) clientData; Tk_Window tkwin = butPtr->tkwin; TkWindow * winPtr; Pixmap pixmap; MacMenuButton * mbPtr = (MacMenuButton *) butPtr; GWorldPtr dstPort; CGrafPtr saveWorld; GDHandle saveDevice; int hasImageOrBitmap = 0; int width, height; int err; ControlButtonGraphicAlignment theAlignment; Rect paneRect, cntrRect; butPtr->flags &= ~REDRAW_PENDING; if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { return; } pixmap = ( Pixmap )Tk_WindowId(tkwin); GetGWorld(&saveWorld, &saveDevice); dstPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin)); SetGWorld(dstPort, NULL); TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin)); winPtr=(TkWindow *)butPtr->tkwin; paneRect.left=winPtr->privatePtr->xOff; paneRect.top=winPtr->privatePtr->yOff; paneRect.right=paneRect.left+Tk_Width(butPtr->tkwin)-1; paneRect.bottom=paneRect.top+Tk_Height(butPtr->tkwin)-1; cntrRect=paneRect; cntrRect.left+=butPtr->inset; cntrRect.top+=butPtr->inset; cntrRect.right-=butPtr->inset; cntrRect.bottom-=butPtr->inset; if (mbPtr->userPane) { MenuButtonControlParams params; bzero(¶ms, sizeof(params)); ComputeMenuButtonControlParams(butPtr, ¶ms ); if (bcmp(¶ms,&mbPtr->params,sizeof(params))) { if (mbPtr->userPane) { DisposeControl(mbPtr->userPane); mbPtr->userPane = NULL; mbPtr->control = NULL; } } } if (!mbPtr->userPane) { if (MenuButtonInitControl(mbPtr,&paneRect,&cntrRect ) ) { fprintf(stderr,"Init Control failed\n" ); return; } } SetControlBounds(mbPtr->userPane,&paneRect); SetControlBounds(mbPtr->control,&cntrRect); /* * We need to cache the title and its style */ if (!(mbPtr->flags&2)) { ControlTitleParams titleParams; int titleChanged; int styleChanged; ComputeControlTitleParams(butPtr,&titleParams); CompareControlTitleParams(&titleParams,&mbPtr->titleParams, &titleChanged,&styleChanged); if (titleChanged) { CFStringRef cf; cf = CFStringCreateWithCString(NULL, titleParams.title, kCFStringEncodingUTF8); if (hasImageOrBitmap) { SetControlTitleWithCFString(mbPtr->control, cf); } else { SetMenuItemTextWithCFString(mbPtr->menuRef, 1, cf); } CFRelease(cf); bcopy(titleParams.title,mbPtr->titleParams.title,titleParams.len+1); mbPtr->titleParams.len = titleParams.len; } if ((titleChanged||styleChanged) && titleParams .len) { if (hasImageOrBitmap) { if ((err=SetControlFontStyle(mbPtr->control,&titleParams.style))!=noErr) { fprintf(stderr,"SetControlFontStyle failed %d\n", err); return; } } bcopy(&titleParams.style,&mbPtr->titleParams.style,sizeof(titleParams.style)); } } if (butPtr->image != None) { Tk_SizeOfImage(butPtr->image, &width, &height); hasImageOrBitmap = 1; } else if (butPtr->bitmap != None) { Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height); hasImageOrBitmap = 1; } if (hasImageOrBitmap) { mbPtr->picParams.srcRect.right = width; mbPtr->picParams.srcRect.bottom = height; /* Set the flag to circumvent clipping and bounds problems with OS 10.0.4 */ tkPictureIsOpen = 1; if (!(mbPtr->bevelButtonContent.u.picture = OpenCPicture(&mbPtr->picParams)) ) { fprintf(stderr,"OpenCPicture failed\n"); } /* * TO DO - There is one case where XCopyPlane calls CopyDeepMask, * which does not get recorded in the picture. So the bitmap code * will fail in that case. */ if (butPtr->image != NULL) { Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap, 0, 0); } else { XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, NULL, 0, 0, (unsigned int) width, (unsigned int) height, 0, 0, 1); } ClosePicture(); tkPictureIsOpen = 0; if ( (err=SetControlData(mbPtr->control, kControlButtonPart, kControlBevelButtonContentTag, sizeof(ControlButtonContentInfo), (char *) &mbPtr->bevelButtonContent)) != noErr ) { fprintf(stderr,"SetControlData BevelButtonContent failed, %d\n", err ); } switch (butPtr->anchor) { case TK_ANCHOR_N: theAlignment = kControlBevelButtonAlignTop; break; case TK_ANCHOR_NE: theAlignment = kControlBevelButtonAlignTopRight; break; case TK_ANCHOR_E: theAlignment = kControlBevelButtonAlignRight; break; case TK_ANCHOR_SE: theAlignment = kControlBevelButtonAlignBottomRight; break; case TK_ANCHOR_S: theAlignment = kControlBevelButtonAlignBottom; break; case TK_ANCHOR_SW: theAlignment = kControlBevelButtonAlignBottomLeft; break; case TK_ANCHOR_W: theAlignment = kControlBevelButtonAlignLeft; break; case TK_ANCHOR_NW: theAlignment = kControlBevelButtonAlignTopLeft; break; case TK_ANCHOR_CENTER: theAlignment = kControlBevelButtonAlignCenter; break; } if ((err=SetControlData(mbPtr->control, kControlButtonPart, kControlBevelButtonGraphicAlignTag, sizeof(ControlButtonGraphicAlignment), (char *) &theAlignment)) != noErr ) { fprintf(stderr,"SetControlData BevelButtonGraphicAlign failed, %d\n", err ); } } if (butPtr->flags & GOT_FOCUS) { HiliteControl(mbPtr->control,kControlButtonPart); } else { HiliteControl(mbPtr->control,kControlNoPart); } UpdateControlColors(mbPtr); if (mbPtr->flags&2) { ShowControl(mbPtr->control); ShowControl(mbPtr->userPane); mbPtr->flags ^= 2; } else { Draw1Control(mbPtr->userPane); SetControlVisibility(mbPtr->control, true, true); } if (hasImageOrBitmap) { KillPicture(mbPtr->bevelButtonContent.u.picture); } SetGWorld(saveWorld, saveDevice); }
/* ------------ Local code */ static void add_overhead_thumbnail( FileSpecifier &File) { PicHandle picture; PicHandle preview; RgnHandle clip_region; FontInfo info; short text_x, text_y; short text_length; Str255 temporary; GWorldPtr old_gworld; GDHandle old_device; struct overhead_map_data overhead_data; Rect bounds; AEDesc aeFileSpec; FSSpec *SpecPtr; // Skip all this if there's no nav services to install the preview if(!machine_has_nav_services() || NavLibraryVersion() < kNavServicesVersion_2_0) return; GetGWorld(&old_gworld, &old_device); SetGWorld(world_pixels, (GDHandle) NULL); // Note well. We're using world_pixels to create our thumbnail pict within. // If world_pixels is runing as a postage stamp (low-res + small display space) // Then it is actually smaller than the size we're looking to build a thumbnail // within. But seeing as we're generating pict images and using drawing commands // instead of bit-wise operations. It all works out. /* Create the bounding rectangle */ SetRect(&bounds, 0, 0, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT); /* Start recording.. */ picture= OpenPicture(&bounds); PaintRect(&bounds); overhead_data.scale= OVERHEAD_MAP_MINIMUM_SCALE; overhead_data.origin.x= local_player->location.x; overhead_data.origin.y= local_player->location.y; overhead_data.half_width= RECTANGLE_WIDTH(&bounds)/2; overhead_data.half_height= RECTANGLE_HEIGHT(&bounds)/2; overhead_data.width= RECTANGLE_WIDTH(&bounds); overhead_data.height= RECTANGLE_HEIGHT(&bounds); overhead_data.mode= _rendering_saved_game_preview; _render_overhead_map(&overhead_data); RGBForeColor(&rgb_black); PenSize(1, 1); TextFont(0); TextFace(normal); TextSize(0); ClosePicture(); // JTP: Add Nav Services style preview SetRect(&bounds, 0, 0, PREVIEW_WIDTH, PREVIEW_HEIGHT); preview= OpenPicture(&bounds); SetRect(&bounds, PREVIEW_IMAGE_X, PREVIEW_IMAGE_Y, THUMBNAIL_WIDTH + PREVIEW_IMAGE_X, THUMBNAIL_HEIGHT + PREVIEW_IMAGE_Y); clip_region= NewRgn(); GetClip(clip_region); ClipRect(&bounds); DrawPicture(picture, &bounds); SetClip(clip_region); /* Center the text in the rectangle */ // LP: Classic doesn't have this function #ifdef TARGET_API_MAC_CARBON CopyCStringToPascal(static_world->level_name, temporary); #else strncpy((char *)temporary,static_world->level_name,LEVEL_NAME_LENGTH); c2pstr((char *)temporary); #endif // LP: fix to allow lengths more than 127 bytes (not really necessary, but...) text_length = *ptemporary; TruncText(PREVIEW_WIDTH, (char *)temporary+1, &text_length, smTruncEnd); *ptemporary = text_length; GetFontInfo(&info); text_y= PREVIEW_HEIGHT - info.descent; text_x= PREVIEW_LABEL_X + (PREVIEW_WIDTH-StringWidth(temporary))/2; MoveTo(text_x, text_y); DrawString(temporary); ClosePicture(); // This requires NavServices 2.0, what's the inline check? // From FSS get a AEDesc OSStatus err; SpecPtr = &File.GetSpec(); err = AECreateDesc(typeFSS, SpecPtr, sizeof(FSSpec), &aeFileSpec); HLock((Handle)preview); err = NavCreatePreview(&aeFileSpec, 'PICT', *preview, GetHandleSize((Handle)preview)); HUnlock((Handle)preview); AEDisposeDesc(&aeFileSpec); KillPicture(preview); KillPicture(picture); DisposeRgn(clip_region); SetGWorld(old_gworld, old_device); }
bool MCImageBitmapToPICT(MCImageBitmap *p_bitmap, MCMacSysPictHandle &r_pict) { #ifdef LIBGRAPHICS_BROKEN bool t_success = true; Pixmap drawdata = nil, drawmask = nil; MCBitmap *maskimagealpha = nil; t_success = MCImageSplitPixmaps(p_bitmap, drawdata, drawmask, maskimagealpha); if (!t_success) return false; Rect t_rect; SetRect(&t_rect, 0, 0, p_bitmap->width, p_bitmap->height); GWorldPtr t_old_gworld; GDHandle t_old_gdevice; GetGWorld(&t_old_gworld, &t_old_gdevice); PixMapHandle t_draw_pixmap; t_draw_pixmap = GetGWorldPixMap((CGrafPtr)drawdata -> handle . pixmap); GWorldPtr t_img_gworld; t_img_gworld = NULL; if (t_success) { QDErr t_err; t_err = NewGWorld(&t_img_gworld, 32, &t_rect, NULL, NULL, 0); if (t_err != noErr) t_success = false; } if (t_success) { SetGWorld(t_img_gworld, GetGDevice()); PenMode(srcCopy); ForeColor(blackColor); BackColor(whiteColor); if (maskimagealpha != NULL) { GWorldPtr t_alpha_gworld; if (NewGWorldFromPtr(&t_alpha_gworld, 8, &t_rect, GetCTable(40), NULL, 0, maskimagealpha -> data, maskimagealpha -> bytes_per_line) == noErr) { const BitMap *t_dst_bits; t_dst_bits = GetPortBitMapForCopyBits(t_img_gworld); const BitMap *t_src_bits; t_src_bits = GetPortBitMapForCopyBits((CGrafPtr)drawdata -> handle . pixmap); const BitMap *t_mask_bits; t_mask_bits = GetPortBitMapForCopyBits(t_alpha_gworld); EraseRect(&t_rect); CopyDeepMask(t_src_bits, t_mask_bits, t_dst_bits, &t_rect, &t_rect, &t_rect, srcCopy, NULL); } } else if (drawmask != NULL) { PixMapHandle t_mask_pixmap; t_mask_pixmap = GetGWorldPixMap((CGrafPtr)drawmask -> handle . pixmap); EraseRect(&t_rect); const BitMap *t_dst_bits; t_dst_bits = GetPortBitMapForCopyBits(t_img_gworld); const BitMap *t_src_bits; LockPixels(t_draw_pixmap); t_src_bits = (BitMap *)*t_draw_pixmap; const BitMap *t_mask_bits; LockPixels(t_mask_pixmap); t_mask_bits = (BitMap *)*t_mask_pixmap; CopyMask(t_src_bits, t_mask_bits, t_dst_bits, &t_rect, &t_rect, &t_rect); UnlockPixels(t_mask_pixmap); UnlockPixels(t_draw_pixmap); } else { const BitMap *t_dst_bits; t_dst_bits = GetPortBitMapForCopyBits(t_img_gworld); const BitMap *t_src_bits; LockPixels(t_draw_pixmap); t_src_bits = (BitMap *)*t_draw_pixmap; CopyBits(t_src_bits, t_dst_bits, &t_rect, &t_rect, srcCopy, NULL); UnlockPixels(t_draw_pixmap); } } PicHandle t_handle; t_handle = NULL; if (t_success) { OpenCPicParams t_params; t_params . srcRect = t_rect; t_params . hRes = 72 << 16; t_params . vRes = 72 << 16; t_params . version = -2; t_params . reserved1 = 0; t_params . reserved2 = 0; t_handle = OpenCPicture(&t_params); if (t_handle == NULL) t_success = false; } if (t_success) { GWorldPtr t_pict_gworld; GDHandle t_pict_gdevice; GetGWorld(&t_pict_gworld, &t_pict_gdevice); PenMode(srcCopy); ForeColor(blackColor); BackColor(whiteColor); const BitMap *t_dst_bits; t_dst_bits = GetPortBitMapForCopyBits(t_pict_gworld); const BitMap *t_src_bits; t_src_bits = GetPortBitMapForCopyBits(t_img_gworld); CopyBits(t_src_bits, t_dst_bits, &t_rect, &t_rect, srcCopy, NULL); ClosePicture(); } if (t_img_gworld != NULL) DisposeGWorld(t_img_gworld); SetGWorld(t_old_gworld, t_old_gdevice); MCscreen->freepixmap(drawdata); MCscreen->freepixmap(drawmask); if (maskimagealpha != nil) MCscreen->destroyimage(maskimagealpha); if (t_success) r_pict = (MCMacSysPictHandle)t_handle; return t_success; #else return false; #endif }
wxMetaFile *wxMetaFileDC::Close() { ClosePicture() ; return m_metaFile; }
PicHandle GetScreenAsPicHandle(int width, int height, int destWidth, int destHeight) { PicHandle myPicture; Rect drawSize, scaleSize; GWorldPtr drawWorld, scaleWorld; Byte *graphicsIn, *graphicsOut; int row, graphicsRowBytes; SetRect(&drawSize, 0, 0, width, height); SetRect(&scaleSize, 0, 0, destWidth, destHeight); InitGWorld(&drawWorld, &drawSize, 16); InitGWorld(&scaleWorld, &scaleSize, 16); graphicsIn = (Byte *) GFX.Screen; graphicsOut = (Byte *) GetPixBaseAddr(GetGWorldPixMap(drawWorld)); graphicsRowBytes = GetPixRowBytes(GetGWorldPixMap(drawWorld)); for (row = 0; row < height; row++) { memcpy(graphicsOut, graphicsIn, width * 2); if (directDisplay) { if (drawingMethod != kDrawingOpenGL) graphicsIn += 512 * 2; else graphicsIn += width * 2; } else { if (lastDrawingMethod != kDrawingOpenGL) graphicsIn += 512 * 2; else graphicsIn += width * 2; } graphicsOut += graphicsRowBytes; } if ((scaleSize.right * scaleSize.bottom) < (drawSize.right * drawSize.bottom)) { PrepareForGDrawing(drawWorld); CopyBits(GetPortBitMapForCopyBits(drawWorld), GetPortBitMapForCopyBits(scaleWorld), &drawSize, &scaleSize, srcCopy | ditherCopy, nil); FinishGDrawing(drawWorld); PrepareForGDrawing(scaleWorld); myPicture = OpenPicture(&scaleSize); CopyBits(GetPortBitMapForCopyBits(scaleWorld), GetPortBitMapForCopyBits(scaleWorld), &scaleSize, &scaleSize, srcCopy, nil); ClosePicture(); FinishGDrawing(scaleWorld); } else { PrepareForGDrawing(scaleWorld); myPicture = OpenPicture(&scaleSize); CopyBits(GetPortBitMapForCopyBits(drawWorld), GetPortBitMapForCopyBits(scaleWorld), &drawSize, &scaleSize, srcCopy, nil); ClosePicture(); FinishGDrawing(scaleWorld); } DisposeGWorld(drawWorld); DisposeGWorld(scaleWorld); return myPicture; }
void wxMacToolTip::Draw() { if ( m_label.Length() == 0 ) return ; if ( m_window == s_ToolTipWindowRef ) { m_shown = true ; #if TARGET_CARBON HMHelpContentRec tag ; tag.version = kMacHelpVersion; SetRect( &tag.absHotRect , m_position.x - 2 , m_position.y - 2 , m_position.x + 2 , m_position.y + 2 ) ; QDLocalToGlobalRect( GetWindowPort( m_window ) , &tag.absHotRect ) ; m_helpTextRef.Assign( m_label , wxFONTENCODING_DEFAULT ) ; tag.content[kHMMinimumContentIndex].contentType = kHMCFStringContent ; tag.content[kHMMinimumContentIndex].u.tagCFString = m_helpTextRef ; tag.content[kHMMaximumContentIndex].contentType = kHMCFStringContent ; tag.content[kHMMaximumContentIndex].u.tagCFString = m_helpTextRef ; tag.tagSide = kHMDefaultSide; HMDisplayTag( &tag ); #else wxMacPortStateHelper help( (GrafPtr) GetWindowPort( m_window ) ); FontFamilyID fontId ; Str255 fontName ; SInt16 fontSize ; Style fontStyle ; GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; GetFNum( fontName, &fontId ); TextFont( fontId ) ; TextSize( fontSize ) ; TextFace( fontStyle ) ; FontInfo fontInfo; ::GetFontInfo(&fontInfo); short lineh = fontInfo.ascent + fontInfo.descent + fontInfo.leading; short height = 0 ; int i = 0 ; int length = m_label.Length() ; int width = 0 ; int thiswidth = 0 ; int laststop = 0 ; wxCharBuffer text = m_label.mb_str( wxConvLocal) ; while( i < length ) { if( text[i] == 13 || text[i] == 10) { thiswidth = ::TextWidth( text , laststop , i - laststop ) ; if ( thiswidth > width ) width = thiswidth ; height += lineh ; laststop = i+1 ; } i++ ; } if ( i - laststop > 0 ) { thiswidth = ::TextWidth( text , laststop , i - laststop ) ; if ( thiswidth > width ) width = thiswidth ; height += lineh ; } m_rect.left = m_position.x + kTipOffset; m_rect.top = m_position.y + kTipOffset; m_rect.right = m_rect.left + width + 2 * kTipBorder; m_rect.bottom = m_rect.top + height + 2 * kTipBorder; Rect r ; GetPortBounds( GetWindowPort( m_window ) , &r ) ; if ( m_rect.top < 0 ) { m_rect.bottom += -m_rect.top ; m_rect.top = 0 ; } if ( m_rect.left < 0 ) { m_rect.right += -m_rect.left ; m_rect.left = 0 ; } if ( m_rect.right > r.right ) { m_rect.left -= (m_rect.right - r.right ) ; m_rect.right = r.right ; } if ( m_rect.bottom > r.bottom ) { m_rect.top -= (m_rect.bottom - r.bottom) ; m_rect.bottom = r.bottom ; } ClipRect( &m_rect ) ; BackColor( whiteColor ) ; ForeColor(blackColor ) ; GWorldPtr port ; NewGWorld( &port , wxDisplayDepth() , &m_rect , NULL , NULL , 0 ) ; CGrafPtr origPort ; GDHandle origDevice ; GetGWorld( &origPort , &origDevice ) ; SetGWorld( port , NULL ) ; m_backpict = OpenPicture(&m_rect); CopyBits(GetPortBitMapForCopyBits(GetWindowPort(m_window)), GetPortBitMapForCopyBits(port), &m_rect, &m_rect, srcCopy, NULL); ClosePicture(); SetGWorld( origPort , origDevice ) ; DisposeGWorld( port ) ; PenNormal() ; RGBColor tooltipbackground = { 0xFFFF , 0xFFFF , 0xC000 } ; BackColor( whiteColor ) ; RGBForeColor( &tooltipbackground ) ; PaintRect( &m_rect ) ; ForeColor(blackColor ) ; FrameRect( &m_rect ) ; SetThemeTextColor(kThemeTextColorNotification,wxDisplayDepth(),true) ; ::MoveTo( m_rect.left + kTipBorder , m_rect.top + fontInfo.ascent + kTipBorder); i = 0 ; laststop = 0 ; height = 0 ; while( i < length ) { if( text[i] == 13 || text[i] == 10) { ::DrawText( text , laststop , i - laststop ) ; height += lineh ; ::MoveTo( m_rect.left + kTipBorder , m_rect.top + fontInfo.ascent + kTipBorder + height ); laststop = i+1 ; } i++ ; } ::DrawText( text , laststop , i - laststop ) ; ::TextMode( srcOr ) ; #endif } }
void saveToPICTFile() { /* Saving a PixMap as a PICT file isn't too hard. 1. Open a Picture with the port set to the destination of #2. 2. CopyBits the PixMap onto itself or another port. (Because CopyBits is recorded in Pictures. 3. Close the picture. 4. Open the data fork for the file. 5. Write out 512 bytes of zeros followed by the contents of the Picture handle. 6. Close the file. */ PicHandle picHandle; OSErr anErr = noErr; OSType fileTypeToSave = 'PICT'; OSType creatorType = 'ogle'; NavReplyRecord reply; NavDialogOptions dialogOptions; FSSpec documentFSSpec; long inOutCount; short refNum, count; AEKeyword theKeyword; DescType actualType; unsigned char header[512]; Size actualSize; Rect tempRect1; CopyBits(GetPortBitMapForCopyBits(GetWindowPort(FrontWindow())), (BitMap*) &gPixMap, GetPortBounds(GetWindowPort(gWindow), &tempRect1), &gPixMap.bounds, srcCopy, 0L); SetPortWindowPort(gWindow); picHandle = OpenPicture(&gPixMap.bounds); CopyBits((BitMap*) &gPixMap, GetPortBitMapForCopyBits(GetWindowPort(FrontWindow())), &gPixMap.bounds, GetPortBounds(GetWindowPort(gWindow), &tempRect1), srcCopy, 0L); ClosePicture(); for (count = 0; count < 512; count++) header[count] = 0x00; anErr = NavGetDefaultDialogOptions(&dialogOptions); dialogOptions.dialogOptionFlags |= kNavSelectDefaultLocation; anErr = NavPutFile( nil, &reply, &dialogOptions, nil, fileTypeToSave, creatorType, nil ); if (anErr == noErr && reply.validRecord) { anErr = AEGetNthPtr(&(reply.selection), 1, typeFSS, &theKeyword, &actualType, &documentFSSpec, sizeof(documentFSSpec), &actualSize ); if (anErr == noErr) { anErr = FSpCreate(&documentFSSpec, creatorType, fileTypeToSave, smSystemScript); if (anErr == dupFNErr) { anErr = FSpDelete(&documentFSSpec); anErr = FSpCreate(&documentFSSpec, creatorType, fileTypeToSave, smSystemScript); } // this is quick 'n' dirty or there'd be more robust handling here // write the file FSpOpenDF(&documentFSSpec, fsRdWrPerm, &refNum ); inOutCount = 512; anErr = FSWrite(refNum, &inOutCount, header); // write the header if (anErr == noErr) { inOutCount = GetHandleSize((Handle)picHandle); anErr = FSWrite(refNum,&inOutCount,*picHandle); } FSClose( refNum ); } reply.translationNeeded = false; anErr = NavCompleteSave(&reply, kNavTranslateInPlace); NavDisposeReply(&reply); } KillPicture(picHandle); }
void SetupBevelButton( MacButton *mbPtr, /* Mac button. */ ControlRef controlHandle, /* The control to set this picture to. */ GWorldPtr destPort, /* Off screen GWorld. */ GC gc, /* The GC we are drawing into - needed for the * bevel button. */ Pixmap pixmap) /* The pixmap we are drawing into - needed for * the bevel button. */ { TkButton *butPtr = (TkButton *) mbPtr; int height, width; ControlButtonGraphicAlignment theAlignment; CGrafPtr savePort; Boolean portChanged = false; if (butPtr->image != None) { Tk_SizeOfImage(butPtr->image, &width, &height); } else { Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height); } if ((butPtr->width > 0) && (butPtr->width < width)) { width = butPtr->width; } if ((butPtr->height > 0) && (butPtr->height < height)) { height = butPtr->height; } { portChanged = QDSwapPort(destPort, &savePort); mbPtr->picParams.version = -2; mbPtr->picParams.hRes = 0x00480000; mbPtr->picParams.vRes = 0x00480000; mbPtr->picParams.srcRect.top = 0; mbPtr->picParams.srcRect.left = 0; mbPtr->picParams.srcRect.bottom = height; mbPtr->picParams.srcRect.right = width; mbPtr->picParams.reserved1 = 0; mbPtr->picParams.reserved2 = 0; mbPtr->bevelButtonContent.contentType = kControlContentPictHandle; mbPtr->bevelButtonContent.u.picture = OpenCPicture(&mbPtr->picParams); if (!mbPtr->bevelButtonContent.u.picture) { TkMacOSXDbgMsg("OpenCPicture failed"); } tkPictureIsOpen = 1; /* * TO DO - There is one case where XCopyPlane calls CopyDeepMask, * which does not get recorded in the picture. So the bitmap code * will fail in that case. */ } if (butPtr->selectImage != NULL && (butPtr->flags & SELECTED)) { Tk_RedrawImage(butPtr->selectImage, 0, 0, width, height, pixmap, 0, 0); #if 0 } else if (butPtr->tristateImage != NULL && (butPtr->flags & TRISTATED)) { Tk_RedrawImage(butPtr->tristateImage, 0, 0, width, height, pixmap, 0, 0); #endif } else if (butPtr->image != NULL) { Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap, 0, 0); } else { XSetClipOrigin(butPtr->display, gc, 0, 0); XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, 0, 0, width, height, 0, 0, 1); } { ClosePicture(); tkPictureIsOpen = 0; if (portChanged) { QDSwapPort(savePort, NULL); } } ChkErr(SetControlData, controlHandle, kControlButtonPart, kControlBevelButtonContentTag, sizeof(ControlButtonContentInfo), (char *) &mbPtr->bevelButtonContent); if (butPtr->anchor == TK_ANCHOR_N) { theAlignment = kControlBevelButtonAlignTop; } else if (butPtr->anchor == TK_ANCHOR_NE) { theAlignment = kControlBevelButtonAlignTopRight; } else if (butPtr->anchor == TK_ANCHOR_E) { theAlignment = kControlBevelButtonAlignRight; } else if (butPtr->anchor == TK_ANCHOR_SE) { theAlignment = kControlBevelButtonAlignBottomRight; } else if (butPtr->anchor == TK_ANCHOR_S) { theAlignment = kControlBevelButtonAlignBottom; } else if (butPtr->anchor == TK_ANCHOR_SW) { theAlignment = kControlBevelButtonAlignBottomLeft; } else if (butPtr->anchor == TK_ANCHOR_W) { theAlignment = kControlBevelButtonAlignLeft; } else if (butPtr->anchor == TK_ANCHOR_NW) { theAlignment = kControlBevelButtonAlignTopLeft; } else if (butPtr->anchor == TK_ANCHOR_CENTER) { theAlignment = kControlBevelButtonAlignCenter; } ChkErr(SetControlData, controlHandle, kControlButtonPart, kControlBevelButtonGraphicAlignTag, sizeof(ControlButtonGraphicAlignment), (char *) &theAlignment); if (butPtr->compound != COMPOUND_NONE) { ControlButtonTextPlacement thePlacement = kControlBevelButtonPlaceNormally; if (butPtr->compound == COMPOUND_TOP) { thePlacement = kControlBevelButtonPlaceBelowGraphic; } else if (butPtr->compound == COMPOUND_BOTTOM) { thePlacement = kControlBevelButtonPlaceAboveGraphic; } else if (butPtr->compound == COMPOUND_LEFT) { thePlacement = kControlBevelButtonPlaceToRightOfGraphic; } else if (butPtr->compound == COMPOUND_RIGHT) { thePlacement = kControlBevelButtonPlaceToLeftOfGraphic; } ChkErr(SetControlData, controlHandle, kControlButtonPart, kControlBevelButtonTextPlaceTag, sizeof(ControlButtonTextPlacement), (char *) &thePlacement); } }
/* convert IPIcon to Picture */ PicHandle IPIconToPicture(const IPIconRec *ipIcon,short iconKind) { ResType iconType; short iconSize,iconDepth; long offset=0; OSErr err; GWorldPtr iconGWorld; PixMapHandle iconPix; Handle dataHandle; Ptr src,dst; PicHandle picture; OpenCPicParams picParam; Rect iconRect; Rect temp; long rowBytes,iconRowBytes; short i; CTabHandle ctab=nil; GWorldPtr cPort; GDHandle cDevice; /* invalid icon kind */ if (iconKind < 0) return nil; iconType=gIconType[iconKind]; iconSize=gIconSize[iconKind]; iconDepth=gIconDepth[iconKind]; SetRect(&iconRect,0,0,iconSize,iconSize); temp=iconRect; temp.right++; err=GetDataFromIPIcon(&dataHandle,ipIcon,iconKind); if (err != noErr || dataHandle == nil) return nil; /* return nil when there are no icons */ if (GetHandleSize(dataHandle) != iconSize*(long)iconSize*(iconDepth>1 ? iconDepth : 2)/8) return nil; switch (iconKind) { case kL1Mask: offset=32*32/8; break; case kS1Mask: offset=16*16/8; break; case kL8Mask: case kS8Mask: case kT8Mask: ctab=GetGrayscaleCTable(iconDepth,true); break; } GetGWorld(&cPort,&cDevice); err=NewGWorld(&iconGWorld,iconDepth,&temp,ctab,0,useTempMem); if (ctab != NULL) DisposeHandle((Handle)ctab); if (err != noErr) return nil; HLock(dataHandle); SetGWorld(iconGWorld,0); iconPix=GetGWorldPixMap(iconGWorld); LockPixels(iconPix); rowBytes=MyGetPixRowBytes(iconPix) & 0x3fff; EraseRect(&iconRect); src=*dataHandle+offset; dst=MyGetPixBaseAddr(iconPix); iconRowBytes=iconSize*iconDepth/8; for (i=0; i<iconSize; i++) { BlockMoveData(src,dst,iconRowBytes); src+=iconRowBytes; dst+=rowBytes; } HUnlock(dataHandle); UnlockPixels(iconPix); picParam.srcRect=iconRect; picParam.hRes=72L<<16; picParam.vRes=72L<<16; picParam.version=-2; picParam.reserved1=0; picParam.reserved2=0; picture=OpenCPicture(&picParam); ForeColor(blackColor); BackColor(whiteColor); ClipRect(&iconRect); EraseRect(&iconRect); #if 1 CopyBits(GetPortBitMapForCopyBits(iconGWorld),GetPortBitMapForCopyBits(iconGWorld), &iconRect,&iconRect,srcCopy,nil); #else { IconFamilyHandle iconFamily; IconRef iconRef; err=IPIconToIconFamily(ipIcon,&iconFamily); err=RegisterIconRefFromIconFamily(kIconPartyCreator,'TEMP',iconFamily,&iconRef); DisposeHandle((Handle)iconFamily); err=PlotIconRef(&iconRect,kAlignNone,kTransformNone,kIconServicesNormalUsageFlag, iconRef); err=ReleaseIconRef(iconRef); } #endif #if __BIG_ENDIAN__ (**picture).picFrame=iconRect; #endif ClosePicture(); SetGWorld(cPort,cDevice); #if 0 CopyBits(GetPortBitMapForCopyBits(iconGWorld),GetPortBitMapForCopyBits(GetWindowPort(MyFrontNonFloatingWindow())), &iconRect,&familyIconRect[iconKind],srcCopy,nil); DrawPicture(picture,&familyIconRect[iconKind]); #endif DisposeGWorld(iconGWorld); return picture; }