static void DisplayRectOval( Tk_Canvas canvas, /* Canvas that contains item. */ Tk_Item *itemPtr, /* Item to be displayed. */ Display *display, /* Display on which to draw item. */ Drawable drawable, /* Pixmap or window in which to draw item. */ int x, int y, int width, int height) /* Describes region of canvas that must be * redisplayed (not used). */ { RectOvalItem *rectOvalPtr = (RectOvalItem *) itemPtr; short x1, y1, x2, y2; Pixmap fillStipple; Tk_State state = itemPtr->state; /* * Compute the screen coordinates of the bounding box for the item. Make * sure that the bbox is at least one pixel large, since some X servers * will die if it isn't. */ Tk_CanvasDrawableCoords(canvas, rectOvalPtr->bbox[0],rectOvalPtr->bbox[1], &x1, &y1); Tk_CanvasDrawableCoords(canvas, rectOvalPtr->bbox[2],rectOvalPtr->bbox[3], &x2, &y2); if (x2 <= x1) { x2 = x1+1; } if (y2 <= y1) { y2 = y1+1; } /* * Display filled part first (if wanted), then outline. If we're * stippling, then modify the stipple offset in the GC. Be sure to reset * the offset when done, since the GC is supposed to be read-only. */ if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } fillStipple = rectOvalPtr->fillStipple; if (Canvas(canvas)->currentItemPtr == (Tk_Item *) rectOvalPtr) { if (rectOvalPtr->activeFillStipple != None) { fillStipple = rectOvalPtr->activeFillStipple; } } else if (state == TK_STATE_DISABLED) { if (rectOvalPtr->disabledFillStipple != None) { fillStipple = rectOvalPtr->disabledFillStipple; } } if (rectOvalPtr->fillGC != None) { if (fillStipple != None) { Tk_TSOffset *tsoffset; int w = 0, h = 0; tsoffset = &rectOvalPtr->tsoffset; if (tsoffset) { int flags = tsoffset->flags; if (flags & (TK_OFFSET_CENTER|TK_OFFSET_MIDDLE)) { Tk_SizeOfBitmap(display, fillStipple, &w, &h); if (flags & TK_OFFSET_CENTER) { w /= 2; } else { w = 0; } if (flags & TK_OFFSET_MIDDLE) { h /= 2; } else { h = 0; } } tsoffset->xoffset -= w; tsoffset->yoffset -= h; } Tk_CanvasSetOffset(canvas, rectOvalPtr->fillGC, tsoffset); if (tsoffset) { tsoffset->xoffset += w; tsoffset->yoffset += h; } } if (rectOvalPtr->header.typePtr == &tkRectangleType) { XFillRectangle(display, drawable, rectOvalPtr->fillGC, x1, y1, (unsigned int) (x2-x1), (unsigned int) (y2-y1)); } else { XFillArc(display, drawable, rectOvalPtr->fillGC, x1, y1, (unsigned) (x2-x1), (unsigned) (y2-y1), 0, 360*64); } if (fillStipple != None) { XSetTSOrigin(display, rectOvalPtr->fillGC, 0, 0); } } if (rectOvalPtr->outline.gc != None) { Tk_ChangeOutlineGC(canvas, itemPtr, &(rectOvalPtr->outline)); if (rectOvalPtr->header.typePtr == &tkRectangleType) { XDrawRectangle(display, drawable, rectOvalPtr->outline.gc, x1, y1, (unsigned) (x2-x1), (unsigned) (y2-y1)); } else { XDrawArc(display, drawable, rectOvalPtr->outline.gc, x1, y1, (unsigned) (x2-x1), (unsigned) (y2-y1), 0, 360*64); } Tk_ResetOutlineGC(canvas, itemPtr, &(rectOvalPtr->outline)); } }
static void DisplayCanvText( Tk_Canvas canvas, /* Canvas that contains item. */ Tk_Item *itemPtr, /* Item to be displayed. */ Display *display, /* Display on which to draw item. */ Drawable drawable, /* Pixmap or window in which to draw item. */ int x, int y, int width, int height) /* Describes region of canvas that must be * redisplayed (not used). */ { TextItem *textPtr; Tk_CanvasTextInfo *textInfoPtr; int selFirstChar, selLastChar; short drawableX, drawableY; Pixmap stipple; Tk_State state = itemPtr->state; textPtr = (TextItem *) itemPtr; textInfoPtr = textPtr->textInfoPtr; if (state == TK_STATE_NULL) { state = Canvas(canvas)->canvas_state; } stipple = textPtr->stipple; if (Canvas(canvas)->currentItemPtr == itemPtr) { if (textPtr->activeStipple != None) { stipple = textPtr->activeStipple; } } else if (state == TK_STATE_DISABLED) { if (textPtr->disabledStipple != None) { stipple = textPtr->disabledStipple; } } if (textPtr->gc == NULL) { return; } /* * If we're stippling, then modify the stipple offset in the GC. Be sure * to reset the offset when done, since the GC is supposed to be * read-only. */ if (stipple != None) { Tk_CanvasSetOffset(canvas, textPtr->gc, &textPtr->tsoffset); } selFirstChar = -1; selLastChar = 0; /* lint. */ Tk_CanvasDrawableCoords(canvas, textPtr->drawOrigin[0], textPtr->drawOrigin[1], &drawableX, &drawableY); if (textInfoPtr->selItemPtr == itemPtr) { selFirstChar = textInfoPtr->selectFirst; selLastChar = textInfoPtr->selectLast; if (selLastChar > textPtr->numChars) { selLastChar = textPtr->numChars - 1; } if ((selFirstChar >= 0) && (selFirstChar <= selLastChar)) { int xFirst, yFirst, hFirst; int xLast, yLast, wLast; /* * Draw a special background under the selection. */ Tk_CharBbox(textPtr->textLayout, selFirstChar, &xFirst, &yFirst, NULL, &hFirst); Tk_CharBbox(textPtr->textLayout, selLastChar, &xLast, &yLast, &wLast, NULL); /* * If the selection spans the end of this line, then display * selection background all the way to the end of the line. * However, for the last line we only want to display up to the * last character, not the end of the line. */ x = xFirst; height = hFirst; for (y = yFirst ; y <= yLast; y += height) { int dx1, dy1, dx2, dy2; double s = textPtr->sine, c = textPtr->cosine; XPoint points[4]; if (y == yLast) { width = xLast + wLast - x; } else { width = textPtr->actualWidth - x; } dx1 = x - textInfoPtr->selBorderWidth; dy1 = y; dx2 = width + 2 * textInfoPtr->selBorderWidth; dy2 = height; points[0].x = (short)(drawableX + dx1*c + dy1*s); points[0].y = (short)(drawableY + dy1*c - dx1*s); points[1].x = (short)(drawableX + (dx1+dx2)*c + dy1*s); points[1].y = (short)(drawableY + dy1*c - (dx1+dx2)*s); points[2].x = (short)(drawableX + (dx1+dx2)*c + (dy1+dy2)*s); points[2].y = (short)(drawableY + (dy1+dy2)*c - (dx1+dx2)*s); points[3].x = (short)(drawableX + dx1*c + (dy1+dy2)*s); points[3].y = (short)(drawableY + (dy1+dy2)*c - dx1*s); Tk_Fill3DPolygon(Tk_CanvasTkwin(canvas), drawable, textInfoPtr->selBorder, points, 4, textInfoPtr->selBorderWidth, TK_RELIEF_RAISED); x = 0; } } } /* * If the insertion point should be displayed, then draw a special * background for the cursor before drawing the text. Note: if we're the * cursor item but the cursor is turned off, then redraw background over * the area of the cursor. This guarantees that the selection won't make * the cursor invisible on mono displays, where both are drawn in the same * color. */ if ((textInfoPtr->focusItemPtr == itemPtr) && (textInfoPtr->gotFocus)) { if (Tk_CharBbox(textPtr->textLayout, textPtr->insertPos, &x, &y, NULL, &height)) { int dx1, dy1, dx2, dy2; double s = textPtr->sine, c = textPtr->cosine; XPoint points[4]; dx1 = x - (textInfoPtr->insertWidth / 2); dy1 = y; dx2 = textInfoPtr->insertWidth; dy2 = height; points[0].x = (short)(drawableX + dx1*c + dy1*s); points[0].y = (short)(drawableY + dy1*c - dx1*s); points[1].x = (short)(drawableX + (dx1+dx2)*c + dy1*s); points[1].y = (short)(drawableY + dy1*c - (dx1+dx2)*s); points[2].x = (short)(drawableX + (dx1+dx2)*c + (dy1+dy2)*s); points[2].y = (short)(drawableY + (dy1+dy2)*c - (dx1+dx2)*s); points[3].x = (short)(drawableX + dx1*c + (dy1+dy2)*s); points[3].y = (short)(drawableY + (dy1+dy2)*c - dx1*s); Tk_SetCaretPos(Tk_CanvasTkwin(canvas), points[0].x, points[0].y, height); if (textInfoPtr->cursorOn) { Tk_Fill3DPolygon(Tk_CanvasTkwin(canvas), drawable, textInfoPtr->insertBorder, points, 4, textInfoPtr->insertBorderWidth, TK_RELIEF_RAISED); } else if (textPtr->cursorOffGC != NULL) { /* * Redraw the background over the area of the cursor, even * though the cursor is turned off. This guarantees that the * selection won't make the cursor invisible on mono displays, * where both may be drawn in the same color. */ XFillPolygon(display, drawable, textPtr->cursorOffGC, points, 4, Convex, CoordModeOrigin); } } } /* * If there is no selected text or the selected text foreground is the * same as the regular text foreground, then draw one text string. If * there is selected text and the foregrounds differ, draw the regular * text up to the selection, draw the selection, then draw the rest of the * regular text. Drawing the regular text and then the selected text over * it would causes problems with anti-aliased text because the two * anti-aliasing colors would blend together. */ if ((selFirstChar >= 0) && (textPtr->selTextGC != textPtr->gc)) { TkDrawAngledTextLayout(display, drawable, textPtr->gc, textPtr->textLayout, drawableX, drawableY, textPtr->angle, 0, selFirstChar); TkDrawAngledTextLayout(display, drawable, textPtr->selTextGC, textPtr->textLayout, drawableX, drawableY, textPtr->angle, selFirstChar, selLastChar + 1); TkDrawAngledTextLayout(display, drawable, textPtr->gc, textPtr->textLayout, drawableX, drawableY, textPtr->angle, selLastChar + 1, -1); } else { TkDrawAngledTextLayout(display, drawable, textPtr->gc, textPtr->textLayout, drawableX, drawableY, textPtr->angle, 0, -1); } TkUnderlineAngledTextLayout(display, drawable, textPtr->gc, textPtr->textLayout, drawableX, drawableY, textPtr->angle, textPtr->underline); if (stipple != None) { XSetTSOrigin(display, textPtr->gc, 0, 0); } }