Tk_Image Tk_GetImage( Tcl_Interp *interp, /* Place to leave error message if image can't * be found. */ Tk_Window tkwin, /* Token for window in which image will be * used. */ const char *name, /* Name of desired image. */ Tk_ImageChangedProc *changeProc, /* Function to invoke when redisplay is needed * because image's pixels or size changed. */ ClientData clientData) /* One-word argument to pass to damageProc. */ { Tcl_HashEntry *hPtr; ImageMaster *masterPtr; Image *imagePtr; hPtr = Tcl_FindHashEntry(&((TkWindow *) tkwin)->mainPtr->imageTable, name); if (hPtr == NULL) { goto noSuchImage; } masterPtr = Tcl_GetHashValue(hPtr); if (masterPtr->typePtr == NULL) { goto noSuchImage; } if (masterPtr->deleted) { goto noSuchImage; } imagePtr = (Image *) ckalloc(sizeof(Image)); imagePtr->tkwin = tkwin; imagePtr->display = Tk_Display(tkwin); imagePtr->masterPtr = masterPtr; imagePtr->instanceData = masterPtr->typePtr->getProc(tkwin, masterPtr->masterData); imagePtr->changeProc = changeProc; imagePtr->widgetClientData = clientData; imagePtr->nextPtr = masterPtr->instancePtr; masterPtr->instancePtr = imagePtr; return (Tk_Image) imagePtr; noSuchImage: if (interp) { Tcl_AppendResult(interp, "image \"", name, "\" doesn't exist", NULL); } return NULL; }
static int SetOp(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) { Tk_Window tkwin = clientData; int buffer; char *string; int length; buffer = 0; if (objc == 4) { if (GetCutNumberFromObj(interp, objv[3], &buffer) != TCL_OK) { return TCL_ERROR; } } string = Tcl_GetStringFromObj(objv[2], &length); XStoreBuffer(Tk_Display(tkwin), string, length + 1, buffer); return TCL_OK; }
bool shgPhases::altPress(int x, int y) { // returns true if a redraw is called for (in which case a scroll // is done as well as an XWarpPointer) if (!existsCurrent()) return false; if (currInstalledAltMoveHandler) { if (ignoreNextShgAltMove) { ignoreNextShgAltMove = false; return false; } int deltax = x - shgAltAnchorX; int deltay = y - shgAltAnchorY; // add some extra speedup juice as an incentive to use alt-mousemove scrolling deltax *= 4; deltay *= 4; getCurrent().adjustHorizSBOffsetFromDeltaPix(deltax); getCurrent().adjustVertSBOffsetFromDeltaPix(deltay); #if !defined(i386_unknown_nt4_0) XWarpPointer(Tk_Display(theTkWindow), Tk_WindowId(theTkWindow), Tk_WindowId(theTkWindow), 0, 0, 0, 0, shgAltAnchorX, shgAltAnchorY); #else // !defined(i386_unknown_nt4_0) // TODO - implement warping support #endif // !defined(i386_unknown_nt4_0) ignoreNextShgAltMove = true; return true; } else { shgAltAnchorX = x; shgAltAnchorY = y; currInstalledAltMoveHandler = true; return false; } }
static void BorderElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { BorderElement *border = elementRecord; RECT rc = BoxToRect(b); int relief = TK_RELIEF_FLAT; TkWinDCState dcState; HDC hdc; Tk_GetReliefFromObj(NULL, border->reliefObj, &relief); if (relief != TK_RELIEF_FLAT) { UINT xFlags = (relief == TK_RELIEF_SOLID) ? BF_FLAT : 0; hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); DrawEdge(hdc, &rc, ReliefToEdge(relief), BF_RECT | xFlags); TkWinReleaseDrawableDC(d, hdc, &dcState); } }
void TkpShowBusyWindow( TkBusy busy) { Busy *busyPtr = (Busy *) busy; if (busyPtr->tkBusy != NULL) { Tk_MapWindow(busyPtr->tkBusy); /* * Always raise the busy window just in case new sibling windows have * been created in the meantime. Can't use Tk_RestackWindow because it * doesn't work under Win32. */ XRaiseWindow(Tk_Display(busyPtr->tkBusy), Tk_WindowId(busyPtr->tkBusy)); } }
static void ArrowElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { int direction = *(int *)clientData; ArrowElement *arrow = elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, arrow->borderObj); XColor *arrowColor = Tk_GetColorFromObj(tkwin, arrow->colorObj); int relief = TK_RELIEF_RAISED; int borderWidth = 1; Tk_GetReliefFromObj(NULL, arrow->reliefObj, &relief); Tk_Fill3DRectangle( tkwin, d, border, b.x, b.y, b.width, b.height, borderWidth, relief); TtkFillArrow(Tk_Display(tkwin), d, Tk_GCForColor(arrowColor, d), Ttk_PadBox(b, ArrowMargins), direction); }
static bool tk_start(char **result) { static bool first_init = false; Tk_Window mainw; if (!first_init) { first_init = true; /* this works around a bug in some Tcl/Tk versions */ Tcl_FindExecutable(NULL); /* finalize Tcl at program exit */ atexit(Tcl_Finalize); } *result = NULL; if (interp) return true; /* start up a new interpreter */ if (!(interp = Tcl_CreateInterp())) return false; if (Tcl_Init(interp) != TCL_OK) { if (check_result(interp)) set_result(result, get_result(interp)); else set_result(result, "error initializing Tcl"); tk_stop(); return false; } /* create a command to invoke Pure callbacks from Tcl */ Tcl_CreateCommand(interp, "pure", (Tcl_CmdProc*)tk_pure, (ClientData)0, NULL); /* oddly, there are no `env' variables passed, and this one is needed */ Tcl_SetVar2(interp, "env", "DISPLAY", getenv("DISPLAY"), TCL_GLOBAL_ONLY); if (Tk_Init(interp) != TCL_OK) { if (check_result(interp)) set_result(result, get_result(interp)); else set_result(result, "error initializing Tk"); tk_stop(); return false; } /* set up an X error handler */ mainw = Tk_MainWindow(interp); Tk_CreateErrorHandler(Tk_Display(mainw), -1, -1, -1, XErrorProc, (ClientData)mainw); return true; }
static GC Ttk_GCForColor(Tk_Window tkwin, Tcl_Obj* colorObj, Drawable d) { GC gc = Tk_GCForColor(Tk_GetColorFromObj(tkwin, colorObj), d); #ifdef MAC_OSX_TK /* * Workaround for Tk bug under Aqua where the default line width is 0. */ Display *display = Tk_Display(tkwin); unsigned long mask = 0ul; XGCValues gcValues; gcValues.line_width = 1; mask = GCLineWidth; XChangeGC(display, gc, mask, &gcValues); #endif return gc; }
static void EmbedFocusProc( ClientData clientData, /* Token for container window. */ XEvent *eventPtr) /* ResizeRequest event. */ { Container *containerPtr = clientData; Display *display; XEvent event; if (containerPtr->embeddedPtr != NULL) { display = Tk_Display(containerPtr->parentPtr); event.xfocus.serial = LastKnownRequestProcessed(display); event.xfocus.send_event = false; event.xfocus.display = display; event.xfocus.mode = NotifyNormal; event.xfocus.window = containerPtr->embedded; if (eventPtr->type == FocusIn) { /* * The focus just arrived at the container. Change the X focus to * move it to the embedded application, if there is one. Ignore X * errors that occur during this operation (it's possible that the * new focus window isn't mapped). */ event.xfocus.detail = NotifyNonlinear; event.xfocus.type = FocusIn; } else if (eventPtr->type == FocusOut) { /* * When the container gets a FocusOut event, it has to tell the * embedded app that it has lost the focus. */ event.xfocus.type = FocusOut; event.xfocus.detail = NotifyNonlinear; } Tk_QueueWindowEvent(&event, TCL_QUEUE_MARK); } }
void TkpCreateBusy( Tk_FakeWin *winPtr, Tk_Window tkRef, Window *parentPtr, Tk_Window tkParent, TkBusy busy) { if (winPtr->flags & TK_REPARENTED) { /* * This works around a bug in the implementation of menubars for * non-MacIntosh window systems (Win32 and X11). Tk doesn't reset the * pointers to the parent window when the menu is reparented (since * winPtr->parentPtr points to the wrong window). We get around this * by determining the parent via the native API calls. */ *parentPtr = GetParent(Tk_Display(tkRef), Tk_WindowId(tkRef)); } else { *parentPtr = Tk_WindowId(tkParent); } }
static void CheckIndicatorElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned state) { Display *display = Tk_Display(tkwin); IndicatorElement *indicator = elementRecord; GC gcb=Ttk_GCForColor(tkwin,indicator->backgroundObj,d); GC gcf=Ttk_GCForColor(tkwin,indicator->foregroundObj,d); GC gcu=Ttk_GCForColor(tkwin,indicator->upperColorObj,d); GC gcl=Ttk_GCForColor(tkwin,indicator->lowerColorObj,d); Ttk_Padding padding; const int w = WIN32_XDRAWLINE_HACK; Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &padding); b = Ttk_PadBox(b, padding); XFillRectangle(display,d,gcb, b.x,b.y,b.width,b.height); XDrawLine(display,d,gcl,b.x,b.y+b.height,b.x+b.width+w,b.y+b.height);/*S*/ XDrawLine(display,d,gcl,b.x+b.width,b.y,b.x+b.width,b.y+b.height+w); /*E*/ XDrawLine(display,d,gcu,b.x,b.y, b.x,b.y+b.height+w); /*W*/ XDrawLine(display,d,gcu,b.x,b.y, b.x+b.width+w,b.y); /*N*/ if (state & TTK_STATE_SELECTED) { int p,q,r,s; b = Ttk_PadBox(b,Ttk_UniformPadding(2)); p = b.x, q = b.y, r = b.x+b.width, s = b.y+b.height; r+=w, s+=w; XDrawLine(display, d, gcf, p, q, r, s); XDrawLine(display, d, gcf, p+1, q, r, s-1); XDrawLine(display, d, gcf, p, q+1, r-1, s); s-=w, q-=w; XDrawLine(display, d, gcf, p, s, r, q); XDrawLine(display, d, gcf, p+1, s, r, q+1); XDrawLine(display, d, gcf, p, s-1, r-1, q); } }
void TkpSetKeycodeAndState( Tk_Window tkwin, KeySym keysym, XEvent *eventPtr) { if (keysym == NoSymbol) { eventPtr->xkey.keycode = 0; } else { Display *display = Tk_Display(tkwin); int macKeycode = XKeysymToMacKeycode(display, keysym); /* * See also XKeysymToKeycode. */ if ((keysym >= XK_F1) && (keysym <= XK_F35)) { eventPtr->xkey.keycode = 0x0010; } else { eventPtr->xkey.keycode = 0x00FF & keysym; } eventPtr->xkey.keycode |= (macKeycode & MAC_KEYCODE_MASK) << 16; if (shiftKey & macKeycode) { eventPtr->xkey.state |= ShiftMask; } if (optionKey & macKeycode) { eventPtr->xkey.state |= OPTION_MASK; } if (keysym <= LATIN1_MAX) { int done; done = Tcl_UniCharToUtf(keysym,eventPtr->xkey.trans_chars); eventPtr->xkey.trans_chars[done] = 0; } else { eventPtr->xkey.trans_chars[0] = 0; } } }
void expose_handler (ClientData cd, XEvent *ev) { Display *display; Window window; Visual *visual; GC gc; int screen; int depth; Tk_Window tkwin; tkwin=(Tk_Window) cd; display=Tk_Display (tkwin); window=Tk_WindowId (tkwin); gc=Tk_GetGC (tkwin,0,NULL); visual=Tk_Visual (tkwin); if (ximage==NULL) { screen=DefaultScreen (display); depth=DisplayPlanes (display,screen); image_data=(char *) malloc (RESX*RESY); ximage=XCreateImage (display,visual,depth,ZPixmap,0,image_data,RESX,RESY,8,0); gen_image (); } }
static void DrawCorner( Tk_Window tkwin, Drawable d, Tk_3DBorder border, /* get most GCs from here... */ GC borderGC, /* "window border" color GC */ int x,int y, int width,int height, /* where to draw */ int corner, /* 0 => top left; 1 => bottom right */ enum BorderColor color) { XPoint points[3]; GC gc; --width; --height; points[0].x = x; points[0].y = y+height; points[1].x = x+width*corner; points[1].y = y+height*corner; points[2].x = x+width; points[2].y = y; if (color == BRDR) gc = borderGC; else gc = Tk_3DBorderGC(tkwin, border, (int)color); XDrawLines(Tk_Display(tkwin), d, gc, points, 3, CoordModeOrigin); }
static void freeTile (HtmlImage2 *pImage) { HtmlTree *pTree = pImage->pImageServer->pTree; int flags = TCL_GLOBAL_ONLY; Tcl_Obj *pScript; if (pImage->pTileName) { pScript = Tcl_NewStringObj("image delete", -1); Tcl_IncrRefCount(pScript); Tcl_ListObjAppendElement(0, pScript, pImage->pTileName); Tcl_EvalObjEx(pTree->interp, pScript, flags); Tcl_DecrRefCount(pScript); Tcl_DecrRefCount(pImage->pTileName); pImage->tile = 0; pImage->pTileName = 0; } if (pImage->tilepixmap) { assert(pImage->pixmap); Tk_FreePixmap( Tk_Display(pImage->pImageServer->pTree->tkwin), pImage->tilepixmap); pImage->tilepixmap = 0; } }
static void EntryElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { EntryElement *e = elementRecord; Tk_3DBorder backgroundPtr = Tk_Get3DBorderFromObj(tkwin,e->backgroundObj); Ttk_Box inner = Ttk_PadBox(b, Ttk_UniformPadding(3)); Rect bounds = BoxToRect(d, inner); ThemeDrawState drawState = Ttk_StateTableLookup(ThemeStateTable, state); /* * Erase w/background color: */ XFillRectangle(Tk_Display(tkwin), d, Tk_3DBorderGC(tkwin, backgroundPtr, TK_3D_FLAT_GC), inner.x,inner.y, inner.width, inner.height); BEGIN_DRAWING(d) ChkErr(DrawThemeEditTextFrame, &bounds, drawState); if (state & TTK_STATE_FOCUS) { ChkErr(DrawThemeFocusRect, &bounds, 1); } END_DRAWING }
static void TabElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { NotebookElement *tab = elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, tab->backgroundObj); Display *display = Tk_Display(tkwin); int borderWidth = 2, dh = 0; int x1,y1,x2,y2; GC gc; const int w = WIN32_XDRAWLINE_HACK; if (state & TTK_STATE_SELECTED) { dh = borderWidth; } if (state & TTK_STATE_USER2) { /* Rightmost tab */ --b.width; } Tk_Fill3DRectangle(tkwin, d, border, b.x+2, b.y+2, b.width-1, b.height-2+dh, borderWidth, TK_RELIEF_FLAT); x1 = b.x, x2 = b.x + b.width; y1 = b.y, y2 = b.y + b.height; gc=Ttk_GCForColor(tkwin,tab->borderColorObj,d); XDrawLine(display,d,gc, x1,y1+1, x1,y2+w); XDrawLine(display,d,gc, x2,y1+1, x2,y2+w); XDrawLine(display,d,gc, x1+1,y1, x2-1+w,y1); gc=Ttk_GCForColor(tkwin,tab->lightColorObj,d); XDrawLine(display,d,gc, x1+1,y1+1, x1+1,y2-1+dh+w); XDrawLine(display,d,gc, x1+1,y1+1, x2-1+w,y1+1); }
/* * TextDraw -- * Draw a text element. * Called by TextElementDraw() and LabelElementDraw(). */ static void TextDraw(TextElement *text, Tk_Window tkwin, Drawable d, Ttk_Box b) { XColor *color = Tk_GetColorFromObj(tkwin, text->foregroundObj); int underline = -1; XGCValues gcValues; GC gc1, gc2; Tk_Anchor anchor = TK_ANCHOR_CENTER; TkRegion clipRegion = NULL; gcValues.font = Tk_FontId(text->tkfont); gcValues.foreground = color->pixel; gc1 = Tk_GetGC(tkwin, GCFont | GCForeground, &gcValues); gcValues.foreground = WhitePixelOfScreen(Tk_Screen(tkwin)); gc2 = Tk_GetGC(tkwin, GCFont | GCForeground, &gcValues); /* * Place text according to -anchor: */ Tk_GetAnchorFromObj(NULL, text->anchorObj, &anchor); b = Ttk_AnchorBox(b, text->width, text->height, anchor); /* * Clip text if it's too wide: */ if (b.width < text->width) { XRectangle rect; clipRegion = TkCreateRegion(); rect.x = b.x; rect.y = b.y; rect.width = b.width + (text->embossed ? 1 : 0); rect.height = b.height + (text->embossed ? 1 : 0); TkUnionRectWithRegion(&rect, clipRegion, clipRegion); TkSetRegion(Tk_Display(tkwin), gc1, clipRegion); TkSetRegion(Tk_Display(tkwin), gc2, clipRegion); #ifdef HAVE_XFT TkUnixSetXftClipRegion(clipRegion); #endif } if (text->embossed) { Tk_DrawTextLayout(Tk_Display(tkwin), d, gc2, text->textLayout, b.x+1, b.y+1, 0/*firstChar*/, -1/*lastChar*/); } Tk_DrawTextLayout(Tk_Display(tkwin), d, gc1, text->textLayout, b.x, b.y, 0/*firstChar*/, -1/*lastChar*/); Tcl_GetIntFromObj(NULL, text->underlineObj, &underline); if (underline >= 0) { if (text->embossed) { Tk_UnderlineTextLayout(Tk_Display(tkwin), d, gc2, text->textLayout, b.x+1, b.y+1, underline); } Tk_UnderlineTextLayout(Tk_Display(tkwin), d, gc1, text->textLayout, b.x, b.y, underline); } if (clipRegion != NULL) { #ifdef HAVE_XFT TkUnixSetXftClipRegion(None); #endif XSetClipMask(Tk_Display(tkwin), gc1, None); XSetClipMask(Tk_Display(tkwin), gc2, None); TkDestroyRegion(clipRegion); } Tk_FreeGC(Tk_Display(tkwin), gc1); Tk_FreeGC(Tk_Display(tkwin), gc2); }
static int CreateBLine(Tcl_Interp* interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, CONST84 char** argv) { BLineItem *linePtr = (BLineItem *) itemPtr; int i; tagsOption.parseProc = Tk_CanvasTagsParseProc; tagsOption.printProc = Tk_CanvasTagsPrintProc; if (argc < 4) { Tcl_AppendResult(interp, "wrong # args: should be \"", Tk_PathName(Tk_CanvasTkwin(canvas)), "\" create ", itemPtr->typePtr->name, " x1 y1 x2 y2 ?x3 y3 ...? ?options?", (char *) NULL); return TCL_ERROR; } /* * Carry out initialization that is needed to set defaults and to * allow proper cleanup after errors during the the remainder of * this procedure. */ linePtr->numPoints = 0; linePtr->coordPtr = NULL; linePtr->width = 1; linePtr->capStyle = CapButt; linePtr->joinStyle = JoinRound; linePtr->borderWidth = 2; linePtr->relief = TK_RELIEF_RAISED; linePtr->border = NULL; /* * Count the number of points and then parse them into a point * array. Leading arguments are assumed to be points if they * start with a digit or a minus sign followed by a digit. */ for (i = 4; i < (argc-1); i+=2) { if ((!isdigit(UCHAR(argv[i][0]))) && ((argv[i][0] != '-') || (!isdigit(UCHAR(argv[i][1]))))) { break; } } if (BLineCoords(interp, canvas, itemPtr, i, argv) != TCL_OK) { goto error; } if (ConfigureBLine(interp, canvas, itemPtr, argc-i, argv+i, 0) == TCL_OK) { return TCL_OK; } error: DeleteBLine(canvas, itemPtr, Tk_Display(Tk_CanvasTkwin(canvas))); return TCL_ERROR; }
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); Ttk_Padding padding; XColor *fgColor, *frameColor, *shadeColor, *indicatorColor, *borderColor; 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); frameColor = Tk_GetColorFromObj(tkwin, indicator->backgroundObj); shadeColor = Tk_GetColorFromObj(tkwin, indicator->shadeColorObj); indicatorColor = Tk_GetColorFromObj(tkwin, indicator->colorObj); borderColor = Tk_GetColorFromObj(tkwin, indicator->borderColorObj); imgColors[0 /*A*/] = shadeColor->pixel; imgColors[1 /*B*/] = indicatorColor->pixel; imgColors[2 /*C*/] = frameColor->pixel; imgColors[3 /*D*/] = indicatorColor->pixel; imgColors[4 /*E*/] = borderColor->pixel; imgColors[5 /*F*/] = frameColor->pixel; imgColors[6 /*G*/] = fgColor->pixel; imgColors[7 /*H*/] = fgColor->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 Tk_Draw3DPolygon( Tk_Window tkwin, /* Window for which border was allocated. */ Drawable drawable, /* X window or pixmap in which to draw. */ Tk_3DBorder border, /* Token for border to draw. */ XPoint *pointPtr, /* Array of points describing polygon. All * points must be absolute * (CoordModeOrigin). */ int numPoints, /* Number of points at *pointPtr. */ int borderWidth, /* Width of border, measured in pixels to the * left of the polygon's trajectory. May be * negative. */ int leftRelief) /* TK_RELIEF_RAISED or TK_RELIEF_SUNKEN: * indicates how stuff to left of trajectory * looks relative to stuff on right. */ { XPoint poly[4], b1, b2, newB1, newB2; XPoint perp, c, shift1, shift2; /* Used for handling parallel lines. */ register XPoint *p1Ptr, *p2Ptr; TkBorder *borderPtr = (TkBorder *) border; GC gc; int i, lightOnLeft, dx, dy, parallel, pointsSeen; Display *display = Tk_Display(tkwin); if (borderPtr->lightGC == None) { TkpGetShadows(borderPtr, tkwin); } /* * Handle grooves and ridges with recursive calls. */ if ((leftRelief == TK_RELIEF_GROOVE) || (leftRelief == TK_RELIEF_RIDGE)) { int halfWidth; halfWidth = borderWidth/2; Tk_Draw3DPolygon(tkwin, drawable, border, pointPtr, numPoints, halfWidth, (leftRelief == TK_RELIEF_GROOVE) ? TK_RELIEF_RAISED : TK_RELIEF_SUNKEN); Tk_Draw3DPolygon(tkwin, drawable, border, pointPtr, numPoints, -halfWidth, (leftRelief == TK_RELIEF_GROOVE) ? TK_RELIEF_SUNKEN : TK_RELIEF_RAISED); return; } /* * If the polygon is already closed, drop the last point from it (we'll * close it automatically). */ p1Ptr = &pointPtr[numPoints-1]; p2Ptr = &pointPtr[0]; if ((p1Ptr->x == p2Ptr->x) && (p1Ptr->y == p2Ptr->y)) { numPoints--; } /* * The loop below is executed once for each vertex in the polgon. At the * beginning of each iteration things look like this: * * poly[1] / * * / * | / * b1 * poly[0] (pointPtr[i-1]) * | | * | | * | | * | | * | | * | | *p1Ptr *p2Ptr * b2 *--------------------* * | * | * x------------------------- * * The job of this iteration is to do the following: * (a) Compute x (the border corner corresponding to pointPtr[i]) and put * it in poly[2]. As part of this, compute a new b1 and b2 value for * the next side of the polygon. * (b) Put pointPtr[i] into poly[3]. * (c) Draw the polygon given by poly[0..3]. * (d) Advance poly[0], poly[1], b1, and b2 for the next side of the * polygon. */ /* * The above situation doesn't first come into existence until two points * have been processed; the first two points are used to "prime the pump", * so some parts of the processing are ommitted for these points. The * variable "pointsSeen" keeps track of the priming process; it has to be * separate from i in order to be able to ignore duplicate points in the * polygon. */ pointsSeen = 0; for (i = -2, p1Ptr = &pointPtr[numPoints-2], p2Ptr = p1Ptr+1; i < numPoints; i++, p1Ptr = p2Ptr, p2Ptr++) { if ((i == -1) || (i == numPoints-1)) { p2Ptr = pointPtr; } if ((p2Ptr->x == p1Ptr->x) && (p2Ptr->y == p1Ptr->y)) { /* * Ignore duplicate points (they'd cause core dumps in ShiftLine * calls below). */ continue; } ShiftLine(p1Ptr, p2Ptr, borderWidth, &newB1); newB2.x = newB1.x + (p2Ptr->x - p1Ptr->x); newB2.y = newB1.y + (p2Ptr->y - p1Ptr->y); poly[3] = *p1Ptr; parallel = 0; if (pointsSeen >= 1) { parallel = Intersect(&newB1, &newB2, &b1, &b2, &poly[2]); /* * If two consecutive segments of the polygon are parallel, then * things get more complex. Consider the following diagram: * * poly[1] * *----b1-----------b2------a * \ * \ * *---------*----------* b * poly[0] *p2Ptr *p1Ptr / * / * --*--------*----c * newB1 newB2 * * Instead of using x and *p1Ptr for poly[2] and poly[3], as in * the original diagram, use a and b as above. Then instead of * using x and *p1Ptr for the new poly[0] and poly[1], use b and c * as above. * * Do the computation in three stages: * 1. Compute a point "perp" such that the line p1Ptr-perp is * perpendicular to p1Ptr-p2Ptr. * 2. Compute the points a and c by intersecting the lines b1-b2 * and newB1-newB2 with p1Ptr-perp. * 3. Compute b by shifting p1Ptr-perp to the right and * intersecting it with p1Ptr-p2Ptr. */ if (parallel) { perp.x = p1Ptr->x + (p2Ptr->y - p1Ptr->y); perp.y = p1Ptr->y - (p2Ptr->x - p1Ptr->x); (void) Intersect(p1Ptr, &perp, &b1, &b2, &poly[2]); (void) Intersect(p1Ptr, &perp, &newB1, &newB2, &c); ShiftLine(p1Ptr, &perp, borderWidth, &shift1); shift2.x = shift1.x + (perp.x - p1Ptr->x); shift2.y = shift1.y + (perp.y - p1Ptr->y); (void) Intersect(p1Ptr, p2Ptr, &shift1, &shift2, &poly[3]); } } if (pointsSeen >= 2) { dx = poly[3].x - poly[0].x; dy = poly[3].y - poly[0].y; if (dx > 0) { lightOnLeft = (dy <= dx); } else { lightOnLeft = (dy < dx); } if (lightOnLeft ^ (leftRelief == TK_RELIEF_RAISED)) { gc = borderPtr->lightGC; } else { gc = borderPtr->darkGC; } XFillPolygon(display, drawable, gc, poly, 4, Convex, CoordModeOrigin); } b1.x = newB1.x; b1.y = newB1.y; b2.x = newB2.x; b2.y = newB2.y; poly[0].x = poly[3].x; poly[0].y = poly[3].y; if (parallel) { poly[1].x = c.x; poly[1].y = c.y; } else if (pointsSeen >= 1) { poly[1].x = poly[2].x; poly[1].y = poly[2].y; } pointsSeen++; } }
static int BitmapToPostscript( Tcl_Interp *interp, /* Leave Postscript or error message here. */ Tk_Canvas canvas, /* Information about overall canvas. */ Tk_Item *itemPtr, /* Item for which Postscript is wanted. */ int prepass) /* 1 means this is a prepass to collect font * information; 0 means final Postscript is * being created. */ { BitmapItem *bmapPtr = (BitmapItem *) itemPtr; double x, y; int width, height, rowsAtOnce, rowsThisTime; int curRow; char buffer[100 + TCL_DOUBLE_SPACE * 2 + TCL_INTEGER_SPACE * 4]; XColor *fgColor; XColor *bgColor; Pixmap bitmap; Tk_State state = itemPtr->state; if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } fgColor = bmapPtr->fgColor; bgColor = bmapPtr->bgColor; bitmap = bmapPtr->bitmap; if (Canvas(canvas)->currentItemPtr == itemPtr) { if (bmapPtr->activeFgColor!=NULL) { fgColor = bmapPtr->activeFgColor; } if (bmapPtr->activeBgColor!=NULL) { bgColor = bmapPtr->activeBgColor; } if (bmapPtr->activeBitmap!=None) { bitmap = bmapPtr->activeBitmap; } } else if (state == TK_STATE_DISABLED) { if (bmapPtr->disabledFgColor!=NULL) { fgColor = bmapPtr->disabledFgColor; } if (bmapPtr->disabledBgColor!=NULL) { bgColor = bmapPtr->disabledBgColor; } if (bmapPtr->disabledBitmap!=None) { bitmap = bmapPtr->disabledBitmap; } } if (bitmap == None) { return TCL_OK; } /* * Compute the coordinates of the lower-left corner of the bitmap, taking * into account the anchor position for the bitmp. */ x = bmapPtr->x; y = Tk_CanvasPsY(canvas, bmapPtr->y); Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)), bitmap, &width, &height); switch (bmapPtr->anchor) { case TK_ANCHOR_NW: y -= height; break; case TK_ANCHOR_N: x -= width/2.0; y -= height; break; case TK_ANCHOR_NE: x -= width; y -= height; break; case TK_ANCHOR_E: x -= width; y -= height/2.0; break; case TK_ANCHOR_SE: x -= width; break; case TK_ANCHOR_S: x -= width/2.0; break; case TK_ANCHOR_SW: break; case TK_ANCHOR_W: y -= height/2.0; break; case TK_ANCHOR_CENTER: x -= width/2.0; y -= height/2.0; break; } /* * Color the background, if there is one. */ if (bgColor != NULL) { sprintf(buffer, "%.15g %.15g moveto %d 0 rlineto 0 %d rlineto %d %s\n", x, y, width, height, -width, "0 rlineto closepath"); Tcl_AppendResult(interp, buffer, NULL); if (Tk_CanvasPsColor(interp, canvas, bgColor) != TCL_OK) { return TCL_ERROR; } Tcl_AppendResult(interp, "fill\n", NULL); } /* * Draw the bitmap, if there is a foreground color. If the bitmap is very * large, then chop it up into multiple bitmaps, each consisting of one or * more rows. This is needed because Postscript can't handle single * strings longer than 64 KBytes long. */ if (fgColor != NULL) { if (Tk_CanvasPsColor(interp, canvas, fgColor) != TCL_OK) { return TCL_ERROR; } if (width > 60000) { Tcl_ResetResult(interp); Tcl_AppendResult(interp, "can't generate Postscript", " for bitmaps more than 60000 pixels wide", NULL); return TCL_ERROR; } rowsAtOnce = 60000/width; if (rowsAtOnce < 1) { rowsAtOnce = 1; } sprintf(buffer, "%.15g %.15g translate\n", x, y+height); Tcl_AppendResult(interp, buffer, NULL); for (curRow = 0; curRow < height; curRow += rowsAtOnce) { rowsThisTime = rowsAtOnce; if (rowsThisTime > (height - curRow)) { rowsThisTime = height - curRow; } sprintf(buffer, "0 -%.15g translate\n%d %d true matrix {\n", (double) rowsThisTime, width, rowsThisTime); Tcl_AppendResult(interp, buffer, NULL); if (Tk_CanvasPsBitmap(interp, canvas, bitmap, 0, curRow, width, rowsThisTime) != TCL_OK) { return TCL_ERROR; } Tcl_AppendResult(interp, "\n} imagemask\n", NULL); } } return TCL_OK; }
static int ConfigureRectOval( Tcl_Interp *interp, /* Used 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. */ { RectOvalItem *rectOvalPtr = (RectOvalItem *) itemPtr; XGCValues gcValues; GC newGC; unsigned long mask; Tk_Window tkwin; Tk_TSOffset *tsoffset; XColor *color; Pixmap stipple; Tk_State state; tkwin = Tk_CanvasTkwin(canvas); if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc, (const char **)objv, (char *) rectOvalPtr, flags|TK_CONFIG_OBJS)) { return TCL_ERROR; } state = itemPtr->state; /* * A few of the options require additional processing, such as graphics * contexts. */ if (rectOvalPtr->outline.activeWidth > rectOvalPtr->outline.width || rectOvalPtr->outline.activeDash.number != 0 || rectOvalPtr->outline.activeColor != NULL || rectOvalPtr->outline.activeStipple != None || rectOvalPtr->activeFillColor != NULL || rectOvalPtr->activeFillStipple != None) { itemPtr->redraw_flags |= TK_ITEM_STATE_DEPENDANT; } else { itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT; } tsoffset = &rectOvalPtr->outline.tsoffset; flags = tsoffset->flags; if (flags & TK_OFFSET_LEFT) { tsoffset->xoffset = (int) (rectOvalPtr->bbox[0] + 0.5); } else if (flags & TK_OFFSET_CENTER) { tsoffset->xoffset = (int) ((rectOvalPtr->bbox[0]+rectOvalPtr->bbox[2]+1)/2); } else if (flags & TK_OFFSET_RIGHT) { tsoffset->xoffset = (int) (rectOvalPtr->bbox[2] + 0.5); } if (flags & TK_OFFSET_TOP) { tsoffset->yoffset = (int) (rectOvalPtr->bbox[1] + 0.5); } else if (flags & TK_OFFSET_MIDDLE) { tsoffset->yoffset = (int) ((rectOvalPtr->bbox[1]+rectOvalPtr->bbox[3]+1)/2); } else if (flags & TK_OFFSET_BOTTOM) { tsoffset->yoffset = (int) (rectOvalPtr->bbox[2] + 0.5); } /* * Configure the outline graphics context. If mask is non-zero, the gc has * changed and must be reallocated, provided that the new settings specify * a valid outline (non-zero width and non-NULL color) */ mask = Tk_ConfigOutlineGC(&gcValues, canvas, itemPtr, &(rectOvalPtr->outline)); if (mask && \ rectOvalPtr->outline.width != 0 && \ rectOvalPtr->outline.color != NULL) { gcValues.cap_style = CapProjecting; mask |= GCCapStyle; newGC = Tk_GetGC(tkwin, mask, &gcValues); } else { newGC = None; } if (rectOvalPtr->outline.gc != None) { Tk_FreeGC(Tk_Display(tkwin), rectOvalPtr->outline.gc); } rectOvalPtr->outline.gc = newGC; if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } if (state == TK_STATE_HIDDEN) { ComputeRectOvalBbox(canvas, rectOvalPtr); return TCL_OK; } color = rectOvalPtr->fillColor; stipple = rectOvalPtr->fillStipple; if (Canvas(canvas)->currentItemPtr == itemPtr) { if (rectOvalPtr->activeFillColor!=NULL) { color = rectOvalPtr->activeFillColor; } if (rectOvalPtr->activeFillStipple!=None) { stipple = rectOvalPtr->activeFillStipple; } } else if (state == TK_STATE_DISABLED) { if (rectOvalPtr->disabledFillColor!=NULL) { color = rectOvalPtr->disabledFillColor; } if (rectOvalPtr->disabledFillStipple!=None) { stipple = rectOvalPtr->disabledFillStipple; } } if (color == NULL) { newGC = None; } else { gcValues.foreground = color->pixel; if (stipple != None) { gcValues.stipple = stipple; gcValues.fill_style = FillStippled; mask = GCForeground|GCStipple|GCFillStyle; } else { mask = GCForeground; } #ifdef MAC_OSX_TK /* * Mac OS X CG drawing needs access to the outline linewidth even for * fills (as linewidth controls antialiasing). */ gcValues.line_width = rectOvalPtr->outline.gc != None ? rectOvalPtr->outline.gc->line_width : 0; mask |= GCLineWidth; #endif newGC = Tk_GetGC(tkwin, mask, &gcValues); } if (rectOvalPtr->fillGC != None) { Tk_FreeGC(Tk_Display(tkwin), rectOvalPtr->fillGC); } rectOvalPtr->fillGC = newGC; tsoffset = &rectOvalPtr->tsoffset; flags = tsoffset->flags; if (flags & TK_OFFSET_LEFT) { tsoffset->xoffset = (int) (rectOvalPtr->bbox[0] + 0.5); } else if (flags & TK_OFFSET_CENTER) { tsoffset->xoffset = (int) ((rectOvalPtr->bbox[0]+rectOvalPtr->bbox[2]+1)/2); } else if (flags & TK_OFFSET_RIGHT) { tsoffset->xoffset = (int) (rectOvalPtr->bbox[2] + 0.5); } if (flags & TK_OFFSET_TOP) { tsoffset->yoffset = (int) (rectOvalPtr->bbox[1] + 0.5); } else if (flags & TK_OFFSET_MIDDLE) { tsoffset->yoffset = (int) ((rectOvalPtr->bbox[1]+rectOvalPtr->bbox[3]+1)/2); } else if (flags & TK_OFFSET_BOTTOM) { tsoffset->yoffset = (int) (rectOvalPtr->bbox[3] + 0.5); } ComputeRectOvalBbox(canvas, rectOvalPtr); return TCL_OK; }
/* ARGSUSED */ static void ComputeBitmapBbox( Tk_Canvas canvas, /* Canvas that contains item. */ BitmapItem *bmapPtr) /* Item whose bbox is to be recomputed. */ { int width, height; int x, y; Pixmap bitmap; Tk_State state = bmapPtr->header.state; if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } bitmap = bmapPtr->bitmap; if (Canvas(canvas)->currentItemPtr == (Tk_Item *)bmapPtr) { if (bmapPtr->activeBitmap!=None) { bitmap = bmapPtr->activeBitmap; } } else if (state==TK_STATE_DISABLED) { if (bmapPtr->disabledBitmap!=None) { bitmap = bmapPtr->disabledBitmap; } } x = (int) (bmapPtr->x + ((bmapPtr->x >= 0) ? 0.5 : - 0.5)); y = (int) (bmapPtr->y + ((bmapPtr->y >= 0) ? 0.5 : - 0.5)); if (state==TK_STATE_HIDDEN || bitmap == None) { bmapPtr->header.x1 = bmapPtr->header.x2 = x; bmapPtr->header.y1 = bmapPtr->header.y2 = y; return; } /* * Compute location and size of bitmap, using anchor information. */ Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)), bitmap, &width, &height); switch (bmapPtr->anchor) { case TK_ANCHOR_N: x -= width/2; break; case TK_ANCHOR_NE: x -= width; break; case TK_ANCHOR_E: x -= width; y -= height/2; break; case TK_ANCHOR_SE: x -= width; y -= height; break; case TK_ANCHOR_S: x -= width/2; y -= height; break; case TK_ANCHOR_SW: y -= height; break; case TK_ANCHOR_W: y -= height/2; break; case TK_ANCHOR_NW: break; case TK_ANCHOR_CENTER: x -= width/2; y -= height/2; break; } /* * Store the information in the item header. */ bmapPtr->header.x1 = x; bmapPtr->header.y1 = y; bmapPtr->header.x2 = x + width; bmapPtr->header.y2 = y + height; }
static int ConfigureBitmap( Tcl_Interp *interp, /* Used for error reporting. */ Tk_Canvas canvas, /* Canvas containing itemPtr. */ Tk_Item *itemPtr, /* Bitmap 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. */ { BitmapItem *bmapPtr = (BitmapItem *) itemPtr; XGCValues gcValues; GC newGC; Tk_Window tkwin; unsigned long mask; XColor *fgColor; XColor *bgColor; Pixmap bitmap; Tk_State state; tkwin = Tk_CanvasTkwin(canvas); if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc, (const char **) objv, (char *) bmapPtr, flags|TK_CONFIG_OBJS)) { return TCL_ERROR; } /* * A few of the options require additional processing, such as those that * determine the graphics context. */ state = itemPtr->state; if (bmapPtr->activeFgColor!=NULL || bmapPtr->activeBgColor!=NULL || bmapPtr->activeBitmap!=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; } if (state == TK_STATE_HIDDEN) { ComputeBitmapBbox(canvas, bmapPtr); return TCL_OK; } fgColor = bmapPtr->fgColor; bgColor = bmapPtr->bgColor; bitmap = bmapPtr->bitmap; if (Canvas(canvas)->currentItemPtr == itemPtr) { if (bmapPtr->activeFgColor!=NULL) { fgColor = bmapPtr->activeFgColor; } if (bmapPtr->activeBgColor!=NULL) { bgColor = bmapPtr->activeBgColor; } if (bmapPtr->activeBitmap!=None) { bitmap = bmapPtr->activeBitmap; } } else if (state == TK_STATE_DISABLED) { if (bmapPtr->disabledFgColor!=NULL) { fgColor = bmapPtr->disabledFgColor; } if (bmapPtr->disabledBgColor!=NULL) { bgColor = bmapPtr->disabledBgColor; } if (bmapPtr->disabledBitmap!=None) { bitmap = bmapPtr->disabledBitmap; } } if (bitmap == None) { newGC = None; } else { gcValues.foreground = fgColor->pixel; mask = GCForeground; if (bgColor != NULL) { gcValues.background = bgColor->pixel; mask |= GCBackground; } else { gcValues.clip_mask = bitmap; mask |= GCClipMask; } newGC = Tk_GetGC(tkwin, mask, &gcValues); } if (bmapPtr->gc != None) { Tk_FreeGC(Tk_Display(tkwin), bmapPtr->gc); } bmapPtr->gc = newGC; ComputeBitmapBbox(canvas, bmapPtr); return TCL_OK; }
Pixmap Tk_AllocBitmapFromObj( Tcl_Interp *interp, /* Interp for error results. This may be * NULL. */ Tk_Window tkwin, /* Need the screen the bitmap is used on.*/ Tcl_Obj *objPtr) /* Object describing bitmap; see manual entry * for legal syntax of string value. */ { TkBitmap *bitmapPtr; if (objPtr->typePtr != &tkBitmapObjType) { InitBitmapObj(objPtr); } bitmapPtr = objPtr->internalRep.twoPtrValue.ptr1; /* * If the object currently points to a TkBitmap, see if it's the one we * want. If so, increment its reference count and return. */ if (bitmapPtr != NULL) { if (bitmapPtr->resourceRefCount == 0) { /* * This is a stale reference: it refers to a TkBitmap that's no * longer in use. Clear the reference. */ FreeBitmapObj(objPtr); bitmapPtr = NULL; } else if ((Tk_Display(tkwin) == bitmapPtr->display) && (Tk_ScreenNumber(tkwin) == bitmapPtr->screenNum)) { bitmapPtr->resourceRefCount++; return bitmapPtr->bitmap; } } /* * The object didn't point to the TkBitmap that we wanted. Search the list * of TkBitmaps with the same name to see if one of the others is the * right one. */ if (bitmapPtr != NULL) { TkBitmap *firstBitmapPtr = Tcl_GetHashValue(bitmapPtr->nameHashPtr); FreeBitmapObj(objPtr); for (bitmapPtr = firstBitmapPtr; bitmapPtr != NULL; bitmapPtr = bitmapPtr->nextPtr) { if ((Tk_Display(tkwin) == bitmapPtr->display) && (Tk_ScreenNumber(tkwin) == bitmapPtr->screenNum)) { bitmapPtr->resourceRefCount++; bitmapPtr->objRefCount++; objPtr->internalRep.twoPtrValue.ptr1 = bitmapPtr; return bitmapPtr->bitmap; } } } /* * Still no luck. Call GetBitmap to allocate a new TkBitmap object. */ bitmapPtr = GetBitmap(interp, tkwin, Tcl_GetString(objPtr)); objPtr->internalRep.twoPtrValue.ptr1 = bitmapPtr; if (bitmapPtr == NULL) { return None; } bitmapPtr->objRefCount++; return bitmapPtr->bitmap; }
Window TkpMakeWindow( TkWindow *winPtr, Window parent) { MacDrawable *macWin; XEvent event; /* * If this window is marked as embedded then * the window structure should have already been * created in the TkpUseWindow function. */ if (Tk_IsEmbedded(winPtr)) { return (Window) winPtr->privatePtr; } /* * Allocate sub window */ macWin = (MacDrawable *) ckalloc(sizeof(MacDrawable)); if (macWin == NULL) { winPtr->privatePtr = NULL; return None; } macWin->winPtr = winPtr; winPtr->privatePtr = macWin; macWin->clipRgn = NewRgn(); macWin->aboveClipRgn = NewRgn(); macWin->referenceCount = 0; macWin->flags = TK_CLIP_INVALID; if (Tk_IsTopLevel(macWin->winPtr)) { /* *This will be set when we are mapped. */ macWin->portPtr = (GWorldPtr) NULL; macWin->toplevel = macWin; macWin->xOff = 0; macWin->yOff = 0; } else { macWin->portPtr = NULL; macWin->xOff = winPtr->parentPtr->privatePtr->xOff + winPtr->parentPtr->changes.border_width + winPtr->changes.x; macWin->yOff = winPtr->parentPtr->privatePtr->yOff + winPtr->parentPtr->changes.border_width + winPtr->changes.y; macWin->toplevel = winPtr->parentPtr->privatePtr->toplevel; } macWin->toplevel->referenceCount++; /* * TODO: need general solution for visibility events. */ event.xany.serial = Tk_Display(winPtr)->request; event.xany.send_event = False; event.xany.display = Tk_Display(winPtr); event.xvisibility.type = VisibilityNotify; event.xvisibility.window = (Window) macWin;; event.xvisibility.state = VisibilityUnobscured; Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); return (Window) macWin; }
static TkBitmap * GetBitmap( Tcl_Interp *interp, /* Interpreter to use for error reporting, * this may be NULL. */ Tk_Window tkwin, /* Window in which bitmap will be used. */ const char *string) /* Description of bitmap. See manual entry for * details on legal syntax. */ { Tcl_HashEntry *nameHashPtr, *predefHashPtr; TkBitmap *bitmapPtr, *existingBitmapPtr; TkPredefBitmap *predefPtr; Pixmap bitmap; int isNew, width, height, dummy2; TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr; ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); if (!dispPtr->bitmapInit) { BitmapInit(dispPtr); } nameHashPtr = Tcl_CreateHashEntry(&dispPtr->bitmapNameTable, string, &isNew); if (!isNew) { existingBitmapPtr = Tcl_GetHashValue(nameHashPtr); for (bitmapPtr = existingBitmapPtr; bitmapPtr != NULL; bitmapPtr = bitmapPtr->nextPtr) { if ((Tk_Display(tkwin) == bitmapPtr->display) && (Tk_ScreenNumber(tkwin) == bitmapPtr->screenNum)) { bitmapPtr->resourceRefCount++; return bitmapPtr; } } } else { existingBitmapPtr = NULL; } /* * No suitable bitmap exists. Create a new bitmap from the information * contained in the string. If the string starts with "@" then the rest of * the string is a file name containing the bitmap. Otherwise the string * must refer to a bitmap defined by a call to Tk_DefineBitmap. */ if (*string == '@') { /* INTL: ISO char */ Tcl_DString buffer; int result; if (Tcl_IsSafe(interp)) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "can't specify bitmap with '@' in a safe interpreter", -1)); Tcl_SetErrorCode(interp, "TK", "SAFE", "BITMAP_FILE", NULL); goto error; } /* * Note that we need to cast away the const from the string because * Tcl_TranslateFileName is non-const, even though it doesn't modify * the string. */ string = Tcl_TranslateFileName(interp, (char *) string + 1, &buffer); if (string == NULL) { goto error; } result = TkReadBitmapFile(Tk_Display(tkwin), RootWindowOfScreen(Tk_Screen(tkwin)), string, (unsigned int *) &width, (unsigned int *) &height, &bitmap, &dummy2, &dummy2); if (result != BitmapSuccess) { if (interp != NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "error reading bitmap file \"%s\"", string)); Tcl_SetErrorCode(interp, "TK", "BITMAP", "FILE_ERROR", NULL); } Tcl_DStringFree(&buffer); goto error; } Tcl_DStringFree(&buffer); } else { predefHashPtr = Tcl_FindHashEntry(&tsdPtr->predefBitmapTable, string); if (predefHashPtr == NULL) { /* * The following platform specific call allows the user to define * bitmaps that may only exist during run time. If it returns None * nothing was found and we return the error. */ bitmap = TkpGetNativeAppBitmap(Tk_Display(tkwin), string, &width, &height); if (bitmap == None) { if (interp != NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "bitmap \"%s\" not defined", string)); Tcl_SetErrorCode(interp, "TK", "LOOKUP", "BITMAP", string, NULL); } goto error; } } else { predefPtr = Tcl_GetHashValue(predefHashPtr); width = predefPtr->width; height = predefPtr->height; if (predefPtr->native) { bitmap = TkpCreateNativeBitmap(Tk_Display(tkwin), predefPtr->source); if (bitmap == None) { Tcl_Panic("native bitmap creation failed"); } } else { bitmap = XCreateBitmapFromData(Tk_Display(tkwin), RootWindowOfScreen(Tk_Screen(tkwin)), predefPtr->source, (unsigned)width, (unsigned)height); } } } /* * Add information about this bitmap to our database. */ bitmapPtr = ckalloc(sizeof(TkBitmap)); bitmapPtr->bitmap = bitmap; bitmapPtr->width = width; bitmapPtr->height = height; bitmapPtr->display = Tk_Display(tkwin); bitmapPtr->screenNum = Tk_ScreenNumber(tkwin); bitmapPtr->resourceRefCount = 1; bitmapPtr->objRefCount = 0; bitmapPtr->nameHashPtr = nameHashPtr; bitmapPtr->idHashPtr = Tcl_CreateHashEntry(&dispPtr->bitmapIdTable, (char *) bitmap, &isNew); if (!isNew) { Tcl_Panic("bitmap already registered in Tk_GetBitmap"); } bitmapPtr->nextPtr = existingBitmapPtr; Tcl_SetHashValue(nameHashPtr, bitmapPtr); Tcl_SetHashValue(bitmapPtr->idHashPtr, bitmapPtr); return bitmapPtr; error: if (isNew) { Tcl_DeleteHashEntry(nameHashPtr); } return NULL; }
int TkpUseWindow( Tcl_Interp *interp, /* If not NULL, used for error reporting * if string is bogus. */ Tk_Window tkwin, /* Tk window that does not yet have an * associated X window. */ CONST char *string) /* String identifying an X window to use * for tkwin; must be an integer value. */ { TkWindow *winPtr = (TkWindow *) tkwin; TkWindow *usePtr; MacDrawable *parent, *macWin; Container *containerPtr; XEvent event; int result; if (winPtr->window != None) { panic("TkpUseWindow: X window already assigned"); } /* * Decode the container pointer, and look for it among the *list of available containers. * * N.B. For now, we are limiting the containers to be in the same Tk * application as tkwin, since otherwise they would not be in our list * of containers. * */ if (Tcl_GetInt(interp, string, &result) != TCL_OK) { return TCL_ERROR; } usePtr = (TkWindow *) Tk_IdToWindow(winPtr->display, (Window) result); if (usePtr == NULL) { Tcl_AppendResult(interp, "Tk window does not correspond to id \"", string, "\"", (char *) NULL); return TCL_ERROR; } else { if (!(usePtr->flags & TK_CONTAINER)) { Tcl_AppendResult(interp, "window \"", usePtr->pathName, "\" doesn't have -container option set", (char *) NULL); return TCL_ERROR; } } parent = (MacDrawable *) result; /* * Save information about the container and the embedded window * in a Container structure. Currently, there must already be an existing * Container structure, since we only allow the case where both container * and embedded app. are in the same process. */ for (containerPtr = firstContainerPtr; containerPtr != NULL; containerPtr = containerPtr->nextPtr) { if (containerPtr->parent == (Window) parent) { winPtr->flags |= TK_BOTH_HALVES; containerPtr->parentPtr->flags |= TK_BOTH_HALVES; break; } } /* * Make the embedded window. */ macWin = (MacDrawable *) ckalloc(sizeof(MacDrawable)); if (macWin == NULL) { winPtr->privatePtr = NULL; return TCL_ERROR; } macWin->winPtr = winPtr; winPtr->privatePtr = macWin; /* * The portPtr will be NULL for a Tk in Tk embedded window. * It is none of our business what it is for a Tk not in Tk embedded window, * but we will initialize it to NULL, and let the registerWinProc * set it. In any case, you must always use TkMacGetDrawablePort * to get the portPtr. It will correctly find the container's port. */ macWin->portPtr = (GWorldPtr) NULL; macWin->clipRgn = NewRgn(); macWin->aboveClipRgn = NewRgn(); macWin->referenceCount = 0; macWin->flags = TK_CLIP_INVALID; macWin->toplevel = macWin; macWin->toplevel->referenceCount++; winPtr->flags |= TK_EMBEDDED; /* * Make a copy of the TK_EMBEDDED flag, since sometimes * we need this to get the port after the TkWindow structure * has been freed. */ macWin->flags |= TK_EMBEDDED; /* * Now check whether it is embedded in another Tk widget. If not (the first * case below) we see if there is an in-process embedding handler registered, * and if so, let that fill in the rest of the macWin. */ if (containerPtr == NULL) { /* * If someone has registered an in process embedding handler, then * see if it can handle this window... */ if (gMacEmbedHandler == NULL || gMacEmbedHandler->registerWinProc(result, (Tk_Window) winPtr) != TCL_OK) { Tcl_AppendResult(interp, "The window ID ", string, " does not correspond to a valid Tk Window.", (char *) NULL); return TCL_ERROR; } else { containerPtr = (Container *) ckalloc(sizeof(Container)); containerPtr->parentPtr = NULL; containerPtr->embedded = (Window) macWin; containerPtr->embeddedPtr = macWin->winPtr; containerPtr->nextPtr = firstContainerPtr; firstContainerPtr = containerPtr; } } else { /* * The window is embedded in another Tk window. */ macWin->xOff = parent->winPtr->privatePtr->xOff + parent->winPtr->changes.border_width + winPtr->changes.x; macWin->yOff = parent->winPtr->privatePtr->yOff + parent->winPtr->changes.border_width + winPtr->changes.y; /* * Finish filling up the container structure with the embedded window's * information. */ containerPtr->embedded = (Window) macWin; containerPtr->embeddedPtr = macWin->winPtr; /* * Create an event handler to clean up the Container structure when * tkwin is eventually deleted. */ Tk_CreateEventHandler(tkwin, StructureNotifyMask, EmbeddedEventProc, (ClientData) winPtr); } /* * TODO: need general solution for visibility events. */ event.xany.serial = Tk_Display(winPtr)->request; event.xany.send_event = False; event.xany.display = Tk_Display(winPtr); event.xvisibility.type = VisibilityNotify; event.xvisibility.window = (Window) macWin;; event.xvisibility.state = VisibilityUnobscured; Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); /* * TODO: need general solution for visibility events. */ event.xany.serial = Tk_Display(winPtr)->request; event.xany.send_event = False; event.xany.display = Tk_Display(winPtr); event.xvisibility.type = VisibilityNotify; event.xvisibility.window = (Window) macWin;; event.xvisibility.state = VisibilityUnobscured; Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); return TCL_OK; }
bool ParadynTkGUI::Init( void ) { // initialize our base class if( !ParadynTclUI::Init() ) { return false; } // do our own initialization if( Tk_Init( interp ) == TCL_ERROR ) { Panic( "Tk_Init() failed (perhaps TK_LIBRARY not set?)" ); } #if READY Tk_Window mainWin = Tk_MainWindow( interp ); if( mainWin == NULL ) { Panic( "Tk_MainWindow gave NULL after Tk_Init" ); } Tk_SetClass( mainWin, "Paradyn" ); #endif // READY tunableBooleanConstantDeclarator* tcWaShowTips = new tunableBooleanConstantDeclarator("showWhereAxisTips", "If true, the WhereAxis window will be drawn with helpful reminders" " on shortcuts for expanding, unexpanding, selecting, and scrolling." " A setting of false saves screen real estate.", true, // default value ShowWhereAxisTipsCallback, userConstant); // initialize tunable constants tunableBooleanConstantDeclarator* tcHideRetiredRes = new tunableBooleanConstantDeclarator("whereAxisHideRetiredRes", "If true, the WhereAxis window will not display resource" " on shortcuts for expanding, unexpanding, selecting, and scrolling." " A setting of false saves screen real estate.", false, // default value HideWhereAxisRetiredResCallback, userConstant); tunableBooleanConstantDeclarator* tcShgShowKey = new tunableBooleanConstantDeclarator("showShgKey", "If true, the search history graph will be drawn with a key for" " decoding the meaning of the several background colors, text colors," " italics, etc. A setting of false saves screen real estate.", true, // default value ShowShgKeyCallback, userConstant); tunableBooleanConstantDeclarator* tcShgShowTips = new tunableBooleanConstantDeclarator("showShgTips", "If true, the search history graph will be drawn with reminders" " on shortcuts for expanding, unexpanding, selecting, and scrolling." " A setting of false saves screen real estate.", true, // default value ShowShgTipsCallback, userConstant); tunableBooleanConstantDeclarator* tcShowTrue = new tunableBooleanConstantDeclarator("showShgTrueNodes", "To save space in the Performance Consultant Search History Graph," " a false setting of this tunable constant will hide all true nodes" " (background colored blue).", true, // default value ShowShgTrueCallback, userConstant); tunableBooleanConstantDeclarator* tcHideFalse = new tunableBooleanConstantDeclarator("showShgFalseNodes", "To save space in the Performance Consultant Search History Graph," " a false setting of this tunable constant will hide all false nodes" " (background colored pink).", true, // default value ShowShgFalseCallback, userConstant); tunableBooleanConstantDeclarator* tcHideUnknown = new tunableBooleanConstantDeclarator("showShgUnknownNodes", "To save space in the Performance Consultant Search History Graph," " a false setting of this tunable constant will hide all nodes with" " an unknown value (background colored green).", true, // default value ShowShgUnknownCallback, userConstant); tunableBooleanConstantDeclarator* tcHideNever = new tunableBooleanConstantDeclarator("showShgNeverSeenNodes", "To save space in the Performance Consultant Search History Graph," " a false setting of this tunable constant will hide all" " never-before-seen nodes (background colored gray).", true, // default value ShowShgNeverCallback, userConstant); tunableBooleanConstantDeclarator* tcHideActive = new tunableBooleanConstantDeclarator("showShgActiveNodes", "To save space in the Performance Consultant Search History Graph," " a false setting of this tunable constant will hide all active nodes" " (foreground text white).", true, // default value ShowShgActiveCallback, userConstant); tunableBooleanConstantDeclarator* tcHideInactive = new tunableBooleanConstantDeclarator("showShgInactiveNodes", "To save space in the Performance Consultant Search History Graph," " a false setting of this tunable constant will hide all inactive nodes" " (foreground text black).", true, // default value ShowShgInactiveCallback, userConstant); tunableBooleanConstantDeclarator* tcHideShadow = new tunableBooleanConstantDeclarator("showShgShadowNodes", "To save space in the Performance Consultant Search History Graph," " a false setting of this tunable constant will hide all true nodes.", true, // default value ShowShgShadowCallback, userConstant); // load the TCL sources into the interpreter if(initialize_tcl_sources( interp ) != TCL_OK) { // we already indicated the error to the user return false; } // Initialize the bitmaps we use pdLogo::install_fixed_logo("paradynLogo", logo_bits, logo_width, logo_height); pdLogo::install_fixed_logo("dont", error_bits, error_width, error_height); // now install the tcl cmd "createPdLogo" (must be done before anyone // tries to create a logo) tcl_cmd_installer createPdLogo( interp, "makeLogo", pdLogo::makeLogoCommand, (ClientData)Tk_MainWindow( interp )); /* display the paradyn main menu tool bar */ myTclEval( interp, "buildMainWindow"); // New Where Axis: --ari installWhereAxisCommands( interp ); myTclEval( interp, "whereAxisInitialize"); // New Search History Graph: --ari installShgCommands( interp ); // New Call Graph --trey installCallGraphCommands( interp ); // // initialize status lines library // it is assumed that by this point, all the appropriate // containing frames have been created and packed into place // // after this point onwards, any thread may make use of // status lines. // if any thread happens to create status_lines before here, // it should be prepared for a core dump. // // --krishna // status_line::status_init( interp ); ui_status = new status_line("UIM status"); assert(ui_status); ui_status->message("ready"); // set our version number char buf[32]; sprintf( buf, "setTitleVersion %s", (V_id.OK() ? V_id.release() : "v4") ); myTclEval( interp, buf); // register fd for X events with threadlib as special #if !defined(i386_unknown_nt4_0) Display *UIMdisplay = Tk_Display( Tk_MainWindow( interp ) ); int xfd = XConnectionNumber( UIMdisplay ); msg_bind_socket( xfd, 1, // libthread leaves it to us to manually dequeue NULL, NULL, &xtid ); #else // !defined(i386_unknown_nt4_0) msg_bind_wmsg( &xtid ); #endif // !defined(i386_unknown_nt4_0) return true; }