diff --git a/generic/tk.h b/generic/tk.h index 2e00d8f5f..5c48d52ff 100644 --- a/generic/tk.h +++ b/generic/tk.h @@ -1124,7 +1124,7 @@ typedef struct Tk_ItemType { typedef struct Tk_CanvasTextInfo { Tk_3DBorder selBorder; /* Border and background for selected * characters. Read-only to items.*/ - int selBorderWidth; /* Width of border around selection. Read-only + Tcl_Obj *selBorderWidthObj; /* Width of border around selection. Read-only * to items. */ XColor *selFgColorPtr; /* Foreground color for selected text. * Read-only to items. */ @@ -1144,9 +1144,9 @@ typedef struct Tk_CanvasTextInfo { * items. */ Tk_3DBorder insertBorder; /* Used to draw vertical bar for insertion * cursor. Read-only to items. */ - int insertWidth; /* Total width of insertion cursor. Read-only + Tcl_Obj *insertWidthObj; /* Total width of insertion cursor. Read-only * to items. */ - int insertBorderWidth; /* Width of 3-D border around insert cursor. + Tcl_Obj *insertBorderWidthObj; /* Width of 3-D border around insert cursor. * Read-only to items. */ Tk_Item *focusItemPtr; /* Item that currently has the input focus, or * NULL if no such item. Read-only to items. */ diff --git a/generic/tkCanvText.c b/generic/tkCanvText.c index 2cf875721..bc3716422 100644 --- a/generic/tkCanvText.c +++ b/generic/tkCanvText.c @@ -715,7 +715,7 @@ ComputeTextBbox( TextItem *textPtr) /* Item whose bbox is to be recomputed. */ { Tk_CanvasTextInfo *textInfoPtr; - int width, height, fudge, i; + int width, height, fudge, i, insertWidth, selBorderWidth; Tk_State state = textPtr->header.state; double x[4], y[4], dx[4], dy[4], sinA, cosA, tmp; @@ -799,9 +799,11 @@ ComputeTextBbox( */ textInfoPtr = textPtr->textInfoPtr; - fudge = (textInfoPtr->insertWidth + 1) / 2; - if (textInfoPtr->selBorderWidth > fudge) { - fudge = textInfoPtr->selBorderWidth; + Tk_GetPixelsFromObj(NULL, Tk_CanvasTkwin(canvas), textInfoPtr->insertWidthObj, &insertWidth); + Tk_GetPixelsFromObj(NULL, Tk_CanvasTkwin(canvas), textInfoPtr->selBorderWidthObj, &selBorderWidth); + fudge = (insertWidth + 1) / 2; + if (selBorderWidth > fudge) { + fudge = selBorderWidth; } /* @@ -928,6 +930,7 @@ DisplayCanvText( if ((selFirstChar >= 0) && (selFirstChar <= selLastChar)) { int xFirst, yFirst, hFirst; int xLast, yLast, wLast; + int selBorderWidth; /* * Draw a special background under the selection. @@ -947,6 +950,7 @@ DisplayCanvText( x = xFirst; height = hFirst; + Tk_GetPixelsFromObj(NULL, Tk_CanvasTkwin(canvas), textInfoPtr->selBorderWidthObj, &selBorderWidth); for (y = yFirst ; y <= yLast; y += height) { int dx1, dy1, dx2, dy2; double s = textPtr->sine, c = textPtr->cosine; @@ -957,9 +961,9 @@ DisplayCanvText( } else { width = textPtr->actualWidth - x; } - dx1 = x - textInfoPtr->selBorderWidth; + dx1 = x - selBorderWidth; dy1 = y; - dx2 = width + 2 * textInfoPtr->selBorderWidth; + dx2 = width + 2 * selBorderWidth; dy2 = height; points[0].x = (short)(drawableX + dx1*c + dy1*s); points[0].y = (short)(drawableY + dy1*c - dx1*s); @@ -971,7 +975,7 @@ DisplayCanvText( 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); + selBorderWidth, TK_RELIEF_RAISED); x = 0; } } @@ -992,10 +996,12 @@ DisplayCanvText( int dx1, dy1, dx2, dy2; double s = textPtr->sine, c = textPtr->cosine; XPoint points[4]; + int insertWidth; - dx1 = x - (textInfoPtr->insertWidth / 2); + Tk_GetPixelsFromObj(NULL, Tk_CanvasTkwin(canvas), textInfoPtr->insertWidthObj, &insertWidth); + dx1 = x - (insertWidth / 2); dy1 = y; - dx2 = textInfoPtr->insertWidth; + dx2 = insertWidth; dy2 = height; points[0].x = (short)(drawableX + dx1*c + dy1*s); points[0].y = (short)(drawableY + dy1*c - dx1*s); @@ -1009,9 +1015,11 @@ DisplayCanvText( Tk_SetCaretPos(Tk_CanvasTkwin(canvas), points[0].x, points[0].y, height); if (textInfoPtr->cursorOn) { + int insertBorderWidth; + Tk_GetPixelsFromObj(NULL, Tk_CanvasTkwin(canvas), textInfoPtr->insertBorderWidthObj, &insertBorderWidth); Tk_Fill3DPolygon(Tk_CanvasTkwin(canvas), drawable, textInfoPtr->insertBorder, points, 4, - textInfoPtr->insertBorderWidth, TK_RELIEF_RAISED); + insertBorderWidth, TK_RELIEF_RAISED); } else if (textPtr->cursorOffGC != NULL) { /* * Redraw the background over the area of the cursor, even diff --git a/generic/tkCanvas.c b/generic/tkCanvas.c index 94bdc576b..29ac09d29 100644 --- a/generic/tkCanvas.c +++ b/generic/tkCanvas.c @@ -121,17 +121,17 @@ static const Tk_ConfigSpec configSpecs[] = { {TK_CONFIG_BORDER, "-insertbackground", "insertBackground", "Foreground", DEF_CANVAS_INSERT_BG, offsetof(TkCanvas, textInfo.insertBorder), 0, NULL}, {TK_CONFIG_PIXELS, "-insertborderwidth", "insertBorderWidth", "BorderWidth", - DEF_CANVAS_INSERT_BD_COLOR, - offsetof(TkCanvas, textInfo.insertBorderWidth), TK_CONFIG_COLOR_ONLY, NULL}, + DEF_CANVAS_INSERT_BD_COLOR, offsetof(TkCanvas, textInfo.insertBorderWidthObj), + TK_CONFIG_OBJS|TK_CONFIG_COLOR_ONLY, NULL}, {TK_CONFIG_PIXELS, "-insertborderwidth", "insertBorderWidth", "BorderWidth", - DEF_CANVAS_INSERT_BD_MONO, - offsetof(TkCanvas, textInfo.insertBorderWidth), TK_CONFIG_MONO_ONLY, NULL}, + DEF_CANVAS_INSERT_BD_MONO, offsetof(TkCanvas, textInfo.insertBorderWidthObj), + TK_CONFIG_OBJS|TK_CONFIG_MONO_ONLY, NULL}, {TK_CONFIG_INT, "-insertofftime", "insertOffTime", "OffTime", DEF_CANVAS_INSERT_OFF_TIME, offsetof(TkCanvas, insertOffTime), 0, NULL}, {TK_CONFIG_INT, "-insertontime", "insertOnTime", "OnTime", DEF_CANVAS_INSERT_ON_TIME, offsetof(TkCanvas, insertOnTime), 0, NULL}, {TK_CONFIG_PIXELS, "-insertwidth", "insertWidth", "InsertWidth", - DEF_CANVAS_INSERT_WIDTH, offsetof(TkCanvas, textInfo.insertWidth), 0, NULL}, + DEF_CANVAS_INSERT_WIDTH, offsetof(TkCanvas, textInfo.insertWidthObj), TK_CONFIG_OBJS, NULL}, {TK_CONFIG_CUSTOM, "-offset", "offset", "Offset", "0,0", offsetof(TkCanvas, tsoffset),TK_CONFIG_DONT_SET_DEFAULT, &offsetOption}, @@ -147,11 +147,11 @@ static const Tk_ConfigSpec configSpecs[] = { DEF_CANVAS_SELECT_MONO, offsetof(TkCanvas, textInfo.selBorder), TK_CONFIG_MONO_ONLY, NULL}, {TK_CONFIG_PIXELS, "-selectborderwidth", "selectBorderWidth", "BorderWidth", - DEF_CANVAS_SELECT_BD_COLOR, - offsetof(TkCanvas, textInfo.selBorderWidth), TK_CONFIG_COLOR_ONLY, NULL}, + DEF_CANVAS_SELECT_BD_COLOR, offsetof(TkCanvas, textInfo.selBorderWidthObj), + TK_CONFIG_OBJS|TK_CONFIG_COLOR_ONLY, NULL}, {TK_CONFIG_PIXELS, "-selectborderwidth", "selectBorderWidth", "BorderWidth", - DEF_CANVAS_SELECT_BD_MONO, offsetof(TkCanvas, textInfo.selBorderWidth), - TK_CONFIG_MONO_ONLY, NULL}, + DEF_CANVAS_SELECT_BD_MONO, offsetof(TkCanvas, textInfo.selBorderWidthObj), + TK_CONFIG_OBJS|TK_CONFIG_MONO_ONLY, NULL}, {TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Background", DEF_CANVAS_SELECT_FG_COLOR, offsetof(TkCanvas, textInfo.selFgColorPtr), TK_CONFIG_COLOR_ONLY|TK_CONFIG_NULL_OK, NULL}, @@ -170,16 +170,14 @@ static const Tk_ConfigSpec configSpecs[] = { DEF_CANVAS_X_SCROLL_CMD, offsetof(TkCanvas, xScrollCmd), TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_PIXELS, "-xscrollincrement", "xScrollIncrement", - "ScrollIncrement", - DEF_CANVAS_X_SCROLL_INCREMENT, offsetof(TkCanvas, xScrollIncrementObj), - TK_CONFIG_OBJS, NULL}, + "ScrollIncrement", DEF_CANVAS_X_SCROLL_INCREMENT, + offsetof(TkCanvas, xScrollIncrementObj), TK_CONFIG_OBJS, NULL}, {TK_CONFIG_STRING, "-yscrollcommand", "yScrollCommand", "ScrollCommand", DEF_CANVAS_Y_SCROLL_CMD, offsetof(TkCanvas, yScrollCmd), TK_CONFIG_NULL_OK, NULL}, {TK_CONFIG_PIXELS, "-yscrollincrement", "yScrollIncrement", - "ScrollIncrement", - DEF_CANVAS_Y_SCROLL_INCREMENT, offsetof(TkCanvas, yScrollIncrementObj), - TK_CONFIG_OBJS, NULL}, + "ScrollIncrement", DEF_CANVAS_Y_SCROLL_INCREMENT, + offsetof(TkCanvas, yScrollIncrementObj), TK_CONFIG_OBJS, NULL}, {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL} }; @@ -690,7 +688,7 @@ Tk_CanvasObjCmd( canvasPtr->heightObj = NULL; canvasPtr->confine = 0; canvasPtr->textInfo.selBorder = NULL; - canvasPtr->textInfo.selBorderWidth = 0; + canvasPtr->textInfo.selBorderWidthObj = NULL; canvasPtr->textInfo.selFgColorPtr = NULL; canvasPtr->textInfo.selItemPtr = NULL; canvasPtr->textInfo.selectFirst = TCL_INDEX_NONE; @@ -698,8 +696,8 @@ Tk_CanvasObjCmd( canvasPtr->textInfo.anchorItemPtr = NULL; canvasPtr->textInfo.selectAnchor = 0; canvasPtr->textInfo.insertBorder = NULL; - canvasPtr->textInfo.insertWidth = 0; - canvasPtr->textInfo.insertBorderWidth = 0; + canvasPtr->textInfo.insertWidthObj = NULL; + canvasPtr->textInfo.insertBorderWidthObj = NULL; canvasPtr->textInfo.focusItemPtr = NULL; canvasPtr->textInfo.gotFocus = 0; canvasPtr->textInfo.cursorOn = 0; @@ -2267,6 +2265,7 @@ ConfigureCanvas( Tk_State old_canvas_state=canvasPtr->canvas_state; int width, height, borderWidth, highlightWidth; int xScrollIncrement, yScrollIncrement; + int insertBorderWidth, insertWidth; if (Tk_ConfigureWidget(interp, canvasPtr->tkwin, configSpecs, objc, objv, canvasPtr, @@ -2281,36 +2280,50 @@ ConfigureCanvas( Tk_SetBackgroundFromBorder(canvasPtr->tkwin, canvasPtr->bgBorder); - Tk_GetPixelsFromObj(NULL, canvasPtr->tkwin, canvasPtr->heightObj, &height); - Tk_GetPixelsFromObj(NULL, canvasPtr->tkwin, canvasPtr->widthObj, &width); Tk_GetPixelsFromObj(NULL, canvasPtr->tkwin, canvasPtr->borderWidthObj, &borderWidth); + Tk_GetPixelsFromObj(NULL, canvasPtr->tkwin, canvasPtr->heightObj, &height); Tk_GetPixelsFromObj(NULL, canvasPtr->tkwin, canvasPtr->highlightWidthObj, &highlightWidth); + Tk_GetPixelsFromObj(NULL, canvasPtr->tkwin, canvasPtr->textInfo.insertBorderWidthObj, &insertBorderWidth); + Tk_GetPixelsFromObj(NULL, canvasPtr->tkwin, canvasPtr->textInfo.insertWidthObj, &insertWidth); + Tk_GetPixelsFromObj(NULL, canvasPtr->tkwin, canvasPtr->widthObj, &width); Tk_GetPixelsFromObj(NULL, canvasPtr->tkwin, canvasPtr->xScrollIncrementObj, &xScrollIncrement); Tk_GetPixelsFromObj(NULL, canvasPtr->tkwin, canvasPtr->yScrollIncrementObj, &yScrollIncrement); - if (height < 0) { - height = 0; - Tcl_DecrRefCount(canvasPtr->heightObj); - canvasPtr->heightObj = Tcl_NewIntObj(0); - Tcl_IncrRefCount(canvasPtr->heightObj); - } - if (width < 0) { - width = 0; - Tcl_DecrRefCount(canvasPtr->widthObj); - canvasPtr->widthObj = Tcl_NewIntObj(0); - Tcl_IncrRefCount(canvasPtr->widthObj); - } if (borderWidth < 0) { borderWidth = 0; Tcl_DecrRefCount(canvasPtr->borderWidthObj); canvasPtr->borderWidthObj = Tcl_NewIntObj(0); Tcl_IncrRefCount(canvasPtr->borderWidthObj); } + if (height < 0) { + height = 0; + Tcl_DecrRefCount(canvasPtr->heightObj); + canvasPtr->heightObj = Tcl_NewIntObj(0); + Tcl_IncrRefCount(canvasPtr->heightObj); + } if (highlightWidth < 0) { highlightWidth = 0; Tcl_DecrRefCount(canvasPtr->highlightWidthObj); canvasPtr->highlightWidthObj = Tcl_NewIntObj(0); Tcl_IncrRefCount(canvasPtr->highlightWidthObj); } + if (insertBorderWidth < 0) { + insertBorderWidth = 0; + Tcl_DecrRefCount(canvasPtr->textInfo.insertBorderWidthObj); + canvasPtr->textInfo.insertBorderWidthObj = Tcl_NewIntObj(0); + Tcl_IncrRefCount(canvasPtr->textInfo.insertBorderWidthObj); + } + if (insertWidth < 0) { + insertWidth = 0; + Tcl_DecrRefCount(canvasPtr->textInfo.insertWidthObj); + canvasPtr->textInfo.insertWidthObj = Tcl_NewIntObj(0); + Tcl_IncrRefCount(canvasPtr->textInfo.insertWidthObj); + } + if (width < 0) { + width = 0; + Tcl_DecrRefCount(canvasPtr->widthObj); + canvasPtr->widthObj = Tcl_NewIntObj(0); + Tcl_IncrRefCount(canvasPtr->widthObj); + } if (xScrollIncrement < 0) { xScrollIncrement = 0; Tcl_DecrRefCount(canvasPtr->xScrollIncrementObj); diff --git a/tests/canvas.test b/tests/canvas.test index 17821b219..6cf1928d7 100644 --- a/tests/canvas.test +++ b/tests/canvas.test @@ -107,7 +107,7 @@ test canvas-1.24 {configuration options: bad value for "insertbackground"} -body test canvas-1.25 {configuration options: good value for "insertborderwidth"} -body { .c configure -insertborderwidth 1.3 .c cget -insertborderwidth -} -result 1 +} -result 1.3 test canvas-1.26 {configuration options: bad value for "insertborderwidth"} -body { .c configure -insertborderwidth 2.6x } -returnCodes error -result {expected screen distance but got "2.6x"} @@ -128,7 +128,7 @@ test canvas-1.30 {configuration options: bad value for "insertontime"} -body { test canvas-1.31 {configuration options: good value for "insertwidth"} -body { .c configure -insertwidth 1.3 .c cget -insertwidth -} -result 1 +} -result 1.3 test canvas-1.32 {configuration options: bad value for "insertwidth"} -body { .c configure -insertwidth 6x } -returnCodes error -result {expected screen distance but got "6x"} @@ -149,7 +149,7 @@ test canvas-1.36 {configuration options: bad value for "selectbackground"} -body test canvas-1.37 {configuration options: good value for "selectborderwidth"} -body { .c configure -selectborderwidth 1.3 .c cget -selectborderwidth -} -result 1 +} -result 1.3 test canvas-1.38 {configuration options: bad value for "selectborderwidth"} -body { .c configure -selectborderwidth badValue } -returnCodes error -result {expected screen distance but got "badValue"}