static void ImgBmapConfigureInstance( BitmapInstance *instancePtr)/* Instance to reconfigure. */ { BitmapMaster *masterPtr = instancePtr->masterPtr; XColor *colorPtr; XGCValues gcValues; GC gc; unsigned int mask; Pixmap oldBitmap, oldMask; /* * For each of the options in masterPtr, translate the string form into an * internal form appropriate for instancePtr. */ if (*masterPtr->bgUid != 0) { colorPtr = Tk_GetColor(masterPtr->interp, instancePtr->tkwin, masterPtr->bgUid); if (colorPtr == NULL) { goto error; } } else { colorPtr = NULL; } if (instancePtr->bg != NULL) { Tk_FreeColor(instancePtr->bg); } instancePtr->bg = colorPtr; colorPtr = Tk_GetColor(masterPtr->interp, instancePtr->tkwin, masterPtr->fgUid); if (colorPtr == NULL) { goto error; } if (instancePtr->fg != NULL) { Tk_FreeColor(instancePtr->fg); } instancePtr->fg = colorPtr; /* * Careful: We have to allocate new Pixmaps before deleting the old ones. * Otherwise, The XID allocator will always return the same XID for the * new Pixmaps as was used for the old Pixmaps. And that will prevent the * data and/or mask from changing in the GC below. */ oldBitmap = instancePtr->bitmap; instancePtr->bitmap = None; oldMask = instancePtr->mask; instancePtr->mask = None; if (masterPtr->data != NULL) { instancePtr->bitmap = XCreateBitmapFromData( Tk_Display(instancePtr->tkwin), RootWindowOfScreen(Tk_Screen(instancePtr->tkwin)), masterPtr->data, (unsigned) masterPtr->width, (unsigned) masterPtr->height); } if (masterPtr->maskData != NULL) { instancePtr->mask = XCreateBitmapFromData( Tk_Display(instancePtr->tkwin), RootWindowOfScreen(Tk_Screen(instancePtr->tkwin)), masterPtr->maskData, (unsigned) masterPtr->width, (unsigned) masterPtr->height); } if (oldMask != None) { Tk_FreePixmap(Tk_Display(instancePtr->tkwin), oldMask); } if (oldBitmap != None) { Tk_FreePixmap(Tk_Display(instancePtr->tkwin), oldBitmap); } if (masterPtr->data != NULL) { gcValues.foreground = instancePtr->fg->pixel; gcValues.graphics_exposures = False; mask = GCForeground|GCGraphicsExposures; if (instancePtr->bg != NULL) { gcValues.background = instancePtr->bg->pixel; mask |= GCBackground; if (instancePtr->mask != None) { gcValues.clip_mask = instancePtr->mask; mask |= GCClipMask; } } else { gcValues.clip_mask = instancePtr->bitmap; mask |= GCClipMask; } gc = Tk_GetGC(instancePtr->tkwin, mask, &gcValues); } else { gc = None; } if (instancePtr->gc != None) { Tk_FreeGC(Tk_Display(instancePtr->tkwin), instancePtr->gc); } instancePtr->gc = gc; return; error: /* * An error occurred: clear the graphics context in the instance to make * it clear that this instance cannot be displayed. Then report the error. */ if (instancePtr->gc != None) { Tk_FreeGC(Tk_Display(instancePtr->tkwin), instancePtr->gc); } instancePtr->gc = None; Tcl_AppendObjToErrorInfo(masterPtr->interp, Tcl_ObjPrintf( "\n (while configuring image \"%s\")", Tk_NameOfImage( masterPtr->tkMaster))); Tcl_BackgroundError(masterPtr->interp); }
static int ConfigureText( Tcl_Interp *interp, /* Interpreter for error reporting. */ Tk_Canvas canvas, /* Canvas containing itemPtr. */ Tk_Item *itemPtr, /* Rectangle item to reconfigure. */ int objc, /* Number of elements in objv. */ Tcl_Obj *const objv[], /* Arguments describing things to configure. */ int flags) /* Flags to pass to Tk_ConfigureWidget. */ { TextItem *textPtr = (TextItem *) itemPtr; XGCValues gcValues; GC newGC, newSelGC; unsigned long mask; Tk_Window tkwin; Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr; XColor *selBgColorPtr; XColor *color; Pixmap stipple; Tk_State state; tkwin = Tk_CanvasTkwin(canvas); if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc, (const char **) objv, (char *) textPtr, flags|TK_CONFIG_OBJS)) { return TCL_ERROR; } /* * A few of the options require additional processing, such as graphics * contexts. */ state = itemPtr->state; if (textPtr->activeColor != NULL || textPtr->activeStipple != None) { itemPtr->redraw_flags |= TK_ITEM_STATE_DEPENDANT; } else { itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT; } if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } color = textPtr->color; stipple = textPtr->stipple; if (Canvas(canvas)->currentItemPtr == itemPtr) { if (textPtr->activeColor != NULL) { color = textPtr->activeColor; } if (textPtr->activeStipple != None) { stipple = textPtr->activeStipple; } } else if (state == TK_STATE_DISABLED) { if (textPtr->disabledColor != NULL) { color = textPtr->disabledColor; } if (textPtr->disabledStipple != None) { stipple = textPtr->disabledStipple; } } newGC = newSelGC = None; if (textPtr->tkfont != NULL) { gcValues.font = Tk_FontId(textPtr->tkfont); mask = GCFont; if (color != NULL) { gcValues.foreground = color->pixel; mask |= GCForeground; if (stipple != None) { gcValues.stipple = stipple; gcValues.fill_style = FillStippled; mask |= GCStipple|GCFillStyle; } newGC = Tk_GetGC(tkwin, mask, &gcValues); } mask &= ~(GCTile|GCFillStyle|GCStipple); if (stipple != None) { gcValues.stipple = stipple; gcValues.fill_style = FillStippled; mask |= GCStipple|GCFillStyle; } if (textInfoPtr->selFgColorPtr != NULL) { gcValues.foreground = textInfoPtr->selFgColorPtr->pixel; } newSelGC = Tk_GetGC(tkwin, mask|GCForeground, &gcValues); } if (textPtr->gc != None) { Tk_FreeGC(Tk_Display(tkwin), textPtr->gc); } textPtr->gc = newGC; if (textPtr->selTextGC != None) { Tk_FreeGC(Tk_Display(tkwin), textPtr->selTextGC); } textPtr->selTextGC = newSelGC; selBgColorPtr = Tk_3DBorderColor(textInfoPtr->selBorder); if (Tk_3DBorderColor(textInfoPtr->insertBorder)->pixel == selBgColorPtr->pixel) { if (selBgColorPtr->pixel == BlackPixelOfScreen(Tk_Screen(tkwin))) { gcValues.foreground = WhitePixelOfScreen(Tk_Screen(tkwin)); } else { gcValues.foreground = BlackPixelOfScreen(Tk_Screen(tkwin)); } newGC = Tk_GetGC(tkwin, GCForeground, &gcValues); } else { newGC = None; } if (textPtr->cursorOffGC != None) { Tk_FreeGC(Tk_Display(tkwin), textPtr->cursorOffGC); } textPtr->cursorOffGC = newGC; /* * If the text was changed, move the selection and insertion indices to * keep them inside the item. */ textPtr->numBytes = strlen(textPtr->text); textPtr->numChars = Tcl_NumUtfChars(textPtr->text, textPtr->numBytes); if (textInfoPtr->selItemPtr == itemPtr) { if (textInfoPtr->selectFirst >= textPtr->numChars) { textInfoPtr->selItemPtr = NULL; } else { if (textInfoPtr->selectLast >= textPtr->numChars) { textInfoPtr->selectLast = textPtr->numChars - 1; } if ((textInfoPtr->anchorItemPtr == itemPtr) && (textInfoPtr->selectAnchor >= textPtr->numChars)) { textInfoPtr->selectAnchor = textPtr->numChars - 1; } } } if (textPtr->insertPos >= textPtr->numChars) { textPtr->insertPos = textPtr->numChars; } /* * Restrict so that 0.0 <= angle < 360.0, and then recompute the cached * sine and cosine of the angle. Note that fmod() can produce negative * results, and we try to avoid negative zero as well. */ textPtr->angle = fmod(textPtr->angle, 360.0); if (textPtr->angle < 0.0) { textPtr->angle += 360.0; } if (textPtr->angle == 0.0) { textPtr->angle = 0.0; } textPtr->sine = sin(textPtr->angle * PI/180.0); textPtr->cosine = cos(textPtr->angle * PI/180.0); ComputeTextBbox(canvas, textPtr); return TCL_OK; }
static void IndicatorElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { IndicatorSpec *spec = clientData; IndicatorElement *indicator = elementRecord; Display *display = Tk_Display(tkwin); Tk_3DBorder bgBorder; Ttk_Padding padding; XColor *fgColor, *bgColor, *lightColor, *shadeColor, *selectColor; int index, ix, iy; XGCValues gcValues; GC copyGC; unsigned long imgColors[8]; XImage *img; Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &padding); b = Ttk_PadBox(b, padding); if ( b.x < 0 || b.y < 0 || Tk_Width(tkwin) < b.x + spec->width || Tk_Height(tkwin) < b.y + spec->height) { /* Oops! not enough room to display the image. * Don't draw anything. */ return; } /* * Fill in imgColors palette: * * (SHOULD: take light and shade colors from the border object, * but Tk doesn't provide easy access to these in the public API.) */ fgColor = Tk_GetColorFromObj(tkwin, indicator->foregroundObj); bgBorder = Tk_Get3DBorderFromObj(tkwin, indicator->backgroundObj); bgColor = Tk_3DBorderColor(bgBorder); lightColor = Tk_GetColorFromObj(tkwin, indicator->lightColorObj); shadeColor = Tk_GetColorFromObj(tkwin, indicator->shadeColorObj); selectColor = Tk_GetColorFromObj(tkwin, indicator->colorObj); imgColors[0 /*A*/] = bgColor->pixel; imgColors[1 /*B*/] = bgColor->pixel; imgColors[2 /*C*/] = lightColor->pixel; imgColors[3 /*D*/] = selectColor->pixel; imgColors[4 /*E*/] = shadeColor->pixel; imgColors[5 /*F*/] = bgColor->pixel; imgColors[6 /*G*/] = fgColor->pixel; imgColors[7 /*H*/] = selectColor->pixel; /* * Create a scratch buffer to store the image: */ img = XGetImage(display,d, 0, 0, (unsigned int)spec->width, (unsigned int)spec->height, AllPlanes, ZPixmap); if (img == NULL) return; /* * Create the image, painting it into an XImage one pixel at a time. */ index = Ttk_StateTableLookup(spec->map, state); for (iy=0 ; iy<spec->height ; iy++) { for (ix=0 ; ix<spec->width ; ix++) { XPutPixel(img, ix, iy, imgColors[spec->pixels[iy][index*spec->width+ix] - 'A'] ); } } /* * Copy onto our target drawable surface. */ memset(&gcValues, 0, sizeof(gcValues)); copyGC = Tk_GetGC(tkwin, 0, &gcValues); TkPutImage(NULL, 0, display, d, copyGC, img, 0, 0, b.x, b.y, spec->width, spec->height); /* * Tidy up. */ Tk_FreeGC(display, copyGC); XDestroyImage(img); }
void TkpDrawCheckIndicator( Tk_Window tkwin, /* handle for resource alloc */ Display *display, Drawable d, /* what to draw on */ int x, int y, /* where to draw */ Tk_3DBorder bgBorder, /* colors of the border */ XColor *indicatorColor, /* color of the indicator */ XColor *selectColor, /* color when selected */ XColor *disableColor, /* color when disabled */ int on, /* are we on? */ int disabled, /* are we disabled? */ int mode) /* kind of indicator to draw */ { int ix, iy; int dim; int imgsel, imgstart; TkBorder *bg_brdr = (TkBorder*)bgBorder; XGCValues gcValues; GC copyGC; unsigned long imgColors[8]; XImage *img; Pixmap pixmap; int depth; /* * Sanity check. */ if (tkwin == NULL || display == None || d == None || bgBorder == NULL || indicatorColor == NULL) { return; } if (disableColor == NULL) { disableColor = bg_brdr->bgColorPtr; } if (selectColor == NULL) { selectColor = bg_brdr->bgColorPtr; } depth = Tk_Depth(tkwin); /* * Compute starting point and dimensions of image inside button_images to * be used. */ switch (mode) { default: case CHECK_BUTTON: imgsel = on == 2 ? CHECK_DISON_OFFSET : on == 1 ? CHECK_ON_OFFSET : CHECK_OFF_OFFSET; imgsel += disabled && on != 2 ? CHECK_DISOFF_OFFSET : 0; imgstart = CHECK_START; dim = CHECK_BUTTON_DIM; break; case CHECK_MENU: imgsel = on == 2 ? CHECK_DISOFF_OFFSET : on == 1 ? CHECK_ON_OFFSET : CHECK_OFF_OFFSET; imgsel += disabled && on != 2 ? CHECK_DISOFF_OFFSET : 0; imgstart = CHECK_START + 2; imgsel += 2; dim = CHECK_MENU_DIM; break; case RADIO_BUTTON: imgsel = on == 2 ? RADIO_DISON_OFFSET : on==1 ? RADIO_ON_OFFSET : RADIO_OFF_OFFSET; imgsel += disabled && on != 2 ? RADIO_DISOFF_OFFSET : 0; imgstart = RADIO_START; dim = RADIO_BUTTON_DIM; break; case RADIO_MENU: imgsel = on == 2 ? RADIO_DISOFF_OFFSET : on==1 ? RADIO_ON_OFFSET : RADIO_OFF_OFFSET; imgsel += disabled && on != 2 ? RADIO_DISOFF_OFFSET : 0; imgstart = RADIO_START + 3; imgsel += 3; dim = RADIO_MENU_DIM; break; } /* * Allocate the drawing areas to use. Note that we use double-buffering * here because not all code paths leading to this function do so. */ pixmap = Tk_GetPixmap(display, d, dim, dim, depth); if (pixmap == None) { return; } x -= dim/2; y -= dim/2; img = XGetImage(display, pixmap, 0, 0, (unsigned int)dim, (unsigned int)dim, AllPlanes, ZPixmap); if (img == NULL) { return; } /* * Set up the color mapping table. */ TkpGetShadows(bg_brdr, tkwin); imgColors[0 /*A*/] = Tk_GetColorByValue(tkwin, bg_brdr->bgColorPtr)->pixel; imgColors[1 /*B*/] = Tk_GetColorByValue(tkwin, bg_brdr->bgColorPtr)->pixel; imgColors[2 /*C*/] = (bg_brdr->lightColorPtr != NULL) ? Tk_GetColorByValue(tkwin, bg_brdr->lightColorPtr)->pixel : WhitePixelOfScreen(bg_brdr->screen); imgColors[3 /*D*/] = Tk_GetColorByValue(tkwin, selectColor)->pixel; imgColors[4 /*E*/] = (bg_brdr->darkColorPtr != NULL) ? Tk_GetColorByValue(tkwin, bg_brdr->darkColorPtr)->pixel : BlackPixelOfScreen(bg_brdr->screen); imgColors[5 /*F*/] = Tk_GetColorByValue(tkwin, bg_brdr->bgColorPtr)->pixel; imgColors[6 /*G*/] = Tk_GetColorByValue(tkwin, indicatorColor)->pixel; imgColors[7 /*H*/] = Tk_GetColorByValue(tkwin, disableColor)->pixel; /* * Create the image, painting it into an XImage one pixel at a time. */ for (iy=0 ; iy<dim ; iy++) { for (ix=0 ; ix<dim ; ix++) { XPutPixel(img, ix, iy, imgColors[button_images[imgstart+iy][imgsel+ix] - 'A'] ); } } /* * Copy onto our target drawable surface. */ memset(&gcValues, 0, sizeof(gcValues)); gcValues.background = bg_brdr->bgColorPtr->pixel; gcValues.graphics_exposures = False; copyGC = Tk_GetGC(tkwin, 0, &gcValues); XPutImage(display, pixmap, copyGC, img, 0, 0, 0, 0, (unsigned int)dim, (unsigned int)dim); XCopyArea(display, pixmap, d, copyGC, 0, 0, (unsigned int)dim, (unsigned int)dim, x, y); /* * Tidy up. */ Tk_FreeGC(display, copyGC); XDestroyImage(img); Tk_FreePixmap(display, pixmap); }
int Tk_PostscriptImage( Tk_Image image, /* Token for image to redisplay. */ Tcl_Interp *interp, Tk_Window tkwin, Tk_PostscriptInfo psinfo, /* postscript info */ int x, int y, /* Upper-left pixel of region in image that * needs to be redisplayed. */ int width, int height, /* Dimensions of region to redraw. */ int prepass) { Image *imagePtr = (Image *) image; int result; XImage *ximage; Pixmap pmap; GC newGC; XGCValues gcValues; if (imagePtr->masterPtr->typePtr == NULL) { /* * No master for image, so nothing to display on postscript. */ return TCL_OK; } /* * Check if an image specific postscript-generation function exists; * otherwise go on with generic code. */ if (imagePtr->masterPtr->typePtr->postscriptProc != NULL) { return imagePtr->masterPtr->typePtr->postscriptProc( imagePtr->masterPtr->masterData, interp, tkwin, psinfo, x, y, width, height, prepass); } if (prepass) { return TCL_OK; } /* * Create a Pixmap, tell the image to redraw itself there, and then * generate an XImage from the Pixmap. We can then read pixel values out * of the XImage. */ pmap = Tk_GetPixmap(Tk_Display(tkwin), Tk_WindowId(tkwin), width, height, Tk_Depth(tkwin)); gcValues.foreground = WhitePixelOfScreen(Tk_Screen(tkwin)); newGC = Tk_GetGC(tkwin, GCForeground, &gcValues); if (newGC != None) { XFillRectangle(Tk_Display(tkwin), pmap, newGC, 0, 0, (unsigned) width, (unsigned) height); Tk_FreeGC(Tk_Display(tkwin), newGC); } Tk_RedrawImage(image, x, y, width, height, pmap, 0, 0); ximage = XGetImage(Tk_Display(tkwin), pmap, 0, 0, (unsigned) width, (unsigned) height, AllPlanes, ZPixmap); Tk_FreePixmap(Tk_Display(tkwin), pmap); if (ximage == NULL) { /* * The XGetImage() function is apparently not implemented on this * system. Just ignore it. */ return TCL_OK; } result = TkPostscriptImage(interp, tkwin, psinfo, ximage, x, y, width, height); XDestroyImage(ximage); return result; }