summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--doc/canvas.n27
-rw-r--r--generic/tkCanvLine.c328
-rw-r--r--generic/tkCanvPoly.c370
-rw-r--r--generic/tkCanvPs.c7
-rw-r--r--generic/tkCanvText.c28
-rw-r--r--generic/tkCanvas.c909
-rw-r--r--tests/canvas.test551
8 files changed, 1326 insertions, 904 deletions
diff --git a/ChangeLog b/ChangeLog
index ce74f34..afcf3e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2008-11-01 Donal K. Fellows <dkf@users.sf.net>
+
+ TIP #97 IMPLEMENTATION
+
+ * generic/tkCanvas.c (CanvasWidgetCmd): Implementation of the 'imove'
+ and 'rchars' subcommands.
+ * generic/tk.h (TK_MOVABLE_POINTS): New flag to allow items to state
+ whether they support finding and moving individual coordinates.
+ * doc/canvas.n, tests/canvas.test: Docs 'n' tests.
+
2008-11-01 Pat Thoyts <patthoyts@users.sourceforge.net>
* generic/ttk/ttkEntry.c: Implemented the themed spinbox
diff --git a/doc/canvas.n b/doc/canvas.n
index 9cd411a..e45eeef 100644
--- a/doc/canvas.n
+++ b/doc/canvas.n
@@ -6,7 +6,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: canvas.n,v 1.38 2008/10/02 19:13:35 mistachkin Exp $
+'\" RCS: @(#) $Id: canvas.n,v 1.39 2008/11/01 16:14:30 dkf Exp $
'\"
.so man.macros
.TH canvas n 8.3 Tk "Tk Built-In Commands"
@@ -568,9 +568,9 @@ This command returns the id for the new item.
For each item given by \fItagOrId\fR, delete the characters, or coordinates,
in the range given by \fIfirst\fR and \fIlast\fR, inclusive.
If some of the items given by \fItagOrId\fR do not support
-indexing operations then they ignore dchars.
+indexing operations then they ignore this operation.
Text items interpret \fIfirst\fR and \fIlast\fR as indices to a character,
-line and polygon items interpret them indices to a coordinate (an x,y pair).
+line and polygon items interpret them as indices to a coordinate (an x,y pair).
Indices are described in \fBINDICES\fR above.
If \fIlast\fR is omitted, it defaults to \fIfirst\fR.
This command returns an empty string.
@@ -651,6 +651,15 @@ command \fBfocus\fR, below), but the cursor position may
be set even when the item does not have the focus.
This command returns an empty string.
.TP
+\fIpathName \fBimove \fItagOrId index x y\fR
+.VS 8.6
+This command causes the \fIindex\fR'th coordinate of each of the items
+indicated by \fItagOrId\fR to be relocated to the location (\fIx\fR,\fIy\fR).
+Each item interprets \fIindex\fR independently according to the rules
+described in \fBINDICES\fR above. Out of the standard set of items, only line
+and polygon items may have their coordinates relocated this way.
+.VE 8.6
+.TP
\fIpathName \fBindex \fItagOrId index\fR
.
This command returns a decimal string giving the numerical index
@@ -918,6 +927,18 @@ determined by the \fBraise\fR and \fBlower\fR commands, not the
\fBraise\fR and \fBlower\fR widget commands for canvases.
This command returns an empty string.
.TP
+\fIpathName \fBrchars \fItagOrId first last string\fR
+.VS 8.6
+This command causes the text or coordinates between \fIfirst\fR and \fIlast\fR
+for each of the items indicated by \fItagOrId\fR to be replaced by
+\fIstring\fR. Each item interprets \fIfirst\fR and \fIlast\fR independently
+according to the rules described in \fBINDICES\fR above. Out of the standard
+set of items, text items support this operation by altering their text as
+directed, and line and polygon items support this operation by altering their
+coordinate list (in which case \fIstring\fR should be a list of coordinates to
+use as a replacement). The other items ignore this operation.
+.VE 8.6
+.TP
\fIpathName \fBscale \fItagOrId xOrigin yOrigin xScale yScale\fR
.
Rescale all of the items given by \fItagOrId\fR in canvas coordinate
diff --git a/generic/tkCanvLine.c b/generic/tkCanvLine.c
index e3977fd..e04a72a 100644
--- a/generic/tkCanvLine.c
+++ b/generic/tkCanvLine.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkCanvLine.c,v 1.24 2008/10/30 21:39:16 nijtmans Exp $
+ * RCS: @(#) $Id: tkCanvLine.c,v 1.25 2008/11/01 16:14:30 dkf Exp $
*/
#include <stdio.h>
@@ -170,7 +170,8 @@ static Tk_ConfigSpec configSpecs[] = {
"0.0", Tk_Offset(LineItem, outline.activeWidth),
TK_CONFIG_DONT_SET_DEFAULT, &pixelOption},
{TK_CONFIG_CUSTOM, "-arrow", NULL, NULL,
- "none", Tk_Offset(LineItem, arrow), TK_CONFIG_DONT_SET_DEFAULT, &arrowOption},
+ "none", Tk_Offset(LineItem, arrow),
+ TK_CONFIG_DONT_SET_DEFAULT, &arrowOption},
{TK_CONFIG_CUSTOM, "-arrowshape", NULL, NULL,
"8 10 3", Tk_Offset(LineItem, arrowShapeA),
TK_CONFIG_DONT_SET_DEFAULT, &arrowShapeOption},
@@ -229,7 +230,7 @@ Tk_ItemType tkLineType = {
LineCoords, /* coordProc */
DeleteLine, /* deleteProc */
DisplayLine, /* displayProc */
- TK_CONFIG_OBJS, /* flags */
+ TK_CONFIG_OBJS | TK_MOVABLE_POINTS, /* flags */
LineToPoint, /* pointProc */
LineToArea, /* areaProc */
LineToPostscript, /* postscriptProc */
@@ -291,7 +292,7 @@ CreateLine(
* proper cleanup after errors during the the remainder of this function.
*/
- Tk_CreateOutline(&(linePtr->outline));
+ Tk_CreateOutline(&linePtr->outline);
linePtr->canvas = canvas;
linePtr->numPoints = 0;
linePtr->coordPtr = NULL;
@@ -408,7 +409,7 @@ LineCoords(
numPoints = objc/2;
if (linePtr->numPoints != numPoints) {
coordPtr = (double *)
- ckalloc((unsigned) (sizeof(double) * objc));
+ ckalloc(sizeof(double) * (unsigned) objc);
if (linePtr->coordPtr != NULL) {
ckfree((char *) linePtr->coordPtr);
}
@@ -416,7 +417,7 @@ LineCoords(
linePtr->numPoints = numPoints;
}
coordPtr = linePtr->coordPtr;
- for (i = 0; i <objc; i++) {
+ for (i = 0; i < objc ; i++) {
if (Tk_CanvasGetCoordFromObj(interp, canvas, objv[i],
coordPtr++) != TCL_OK) {
return TCL_ERROR;
@@ -492,7 +493,7 @@ ConfigureLine(
state = itemPtr->state;
- if(state == TK_STATE_NULL) {
+ if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
}
@@ -504,8 +505,7 @@ ConfigureLine(
} else {
itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT;
}
- mask = Tk_ConfigOutlineGC(&gcValues, canvas, itemPtr,
- &(linePtr->outline));
+ mask = Tk_ConfigOutlineGC(&gcValues, canvas, itemPtr, &linePtr->outline);
if (mask) {
if (linePtr->arrow == ARROWS_NONE) {
gcValues.cap_style = linePtr->capStyle;
@@ -516,9 +516,10 @@ ConfigureLine(
newGC = Tk_GetGC(tkwin, mask, &gcValues);
#ifdef MAC_OSX_TK
/*
- * Mac OS X CG drawing needs access to linewidth even for
- * arrow fills (as linewidth controls antialiasing).
+ * Mac OS X CG drawing needs access to linewidth even for arrow fills
+ * (as linewidth controls antialiasing).
*/
+
mask |= GCLineWidth;
#else
gcValues.line_width = 0;
@@ -546,7 +547,7 @@ ConfigureLine(
linePtr->splineSteps = 100;
}
- if ((!linePtr->numPoints) || (state==TK_STATE_HIDDEN)) {
+ if ((!linePtr->numPoints) || (state == TK_STATE_HIDDEN)) {
ComputeLineBbox(canvas, linePtr);
return TCL_OK;
}
@@ -611,7 +612,7 @@ DeleteLine(
{
LineItem *linePtr = (LineItem *) itemPtr;
- Tk_DeleteOutline(display, &(linePtr->outline));
+ Tk_DeleteOutline(display, &linePtr->outline);
if (linePtr->coordPtr != NULL) {
ckfree((char *) linePtr->coordPtr);
}
@@ -654,11 +655,11 @@ ComputeLineBbox(
Tk_State state = linePtr->header.state;
Tk_TSOffset *tsoffset;
- if(state == TK_STATE_NULL) {
+ if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
}
- if (!(linePtr->numPoints) || (state==TK_STATE_HIDDEN)) {
+ if (!(linePtr->numPoints) || (state == TK_STATE_HIDDEN)) {
linePtr->header.x1 = -1;
linePtr->header.x2 = -1;
linePtr->header.y1 = -1;
@@ -668,17 +669,17 @@ ComputeLineBbox(
width = linePtr->outline.width;
if (Canvas(canvas)->currentItemPtr == (Tk_Item *)linePtr) {
- if (linePtr->outline.activeWidth>width) {
+ if (linePtr->outline.activeWidth > width) {
width = linePtr->outline.activeWidth;
}
- } else if (state==TK_STATE_DISABLED) {
- if (linePtr->outline.disabledWidth>0) {
+ } else if (state == TK_STATE_DISABLED) {
+ if (linePtr->outline.disabledWidth > 0) {
width = linePtr->outline.disabledWidth;
}
}
coordPtr = linePtr->coordPtr;
- linePtr->header.x1 = linePtr->header.x2 = (int) *coordPtr;
+ linePtr->header.x1 = linePtr->header.x2 = (int) coordPtr[0];
linePtr->header.y1 = linePtr->header.y2 = (int) coordPtr[1];
/*
@@ -686,8 +687,8 @@ ComputeLineBbox(
* all directions by the line's width to take care of butting or rounded
* corners and projecting or rounded caps. This expansion is an
* overestimate (worst-case is square root of two over two) but it's
- * simple. eDon't do anything special for curves. This causes an
- * additional overestimate in the bounding box, but is faster.
+ * simple. Don't do anything special for curves. This causes an additional
+ * overestimate in the bounding box, but is faster.
*/
for (i = 1, coordPtr = linePtr->coordPtr+2; i < linePtr->numPoints;
@@ -709,16 +710,20 @@ ComputeLineBbox(
tsoffset = &linePtr->outline.tsoffset;
if (tsoffset->flags & TK_OFFSET_INDEX) {
- double *coordPtr = linePtr->coordPtr + (tsoffset->flags & ~TK_OFFSET_INDEX);
+ double *coordPtr = linePtr->coordPtr
+ + (tsoffset->flags & ~TK_OFFSET_INDEX);
+
if (tsoffset->flags <= 0) {
coordPtr = linePtr->coordPtr;
- if ((linePtr->arrow == ARROWS_FIRST) || (linePtr->arrow == ARROWS_BOTH)) {
+ if ((linePtr->arrow == ARROWS_FIRST)
+ || (linePtr->arrow == ARROWS_BOTH)) {
coordPtr = linePtr->firstArrowPtr;
}
}
if (tsoffset->flags > (linePtr->numPoints * 2)) {
coordPtr = linePtr->coordPtr + (linePtr->numPoints * 2);
- if ((linePtr->arrow == ARROWS_LAST) || (linePtr->arrow == ARROWS_BOTH)) {
+ if ((linePtr->arrow == ARROWS_LAST)
+ || (linePtr->arrow == ARROWS_BOTH)) {
coordPtr = linePtr->lastArrowPtr;
}
}
@@ -747,7 +752,7 @@ ComputeLineBbox(
linePtr->header.y1 -= intWidth;
linePtr->header.y2 += intWidth;
- if (linePtr->numPoints==1) {
+ if (linePtr->numPoints == 1) {
linePtr->header.x1 -= 1;
linePtr->header.x2 += 1;
linePtr->header.y1 -= 1;
@@ -840,7 +845,7 @@ DisplayLine(
int numPoints;
Tk_State state = itemPtr->state;
- if ((!linePtr->numPoints)||(linePtr->outline.gc==None)) {
+ if ((!linePtr->numPoints) || (linePtr->outline.gc == None)) {
return;
}
@@ -852,7 +857,7 @@ DisplayLine(
if (linePtr->outline.activeWidth != linewidth) {
linewidth = linePtr->outline.activeWidth;
}
- } else if (state==TK_STATE_DISABLED) {
+ } else if (state == TK_STATE_DISABLED) {
if (linePtr->outline.disabledWidth != linewidth) {
linewidth = linePtr->outline.disabledWidth;
}
@@ -874,14 +879,15 @@ DisplayLine(
if (numPoints <= MAX_STATIC_POINTS) {
pointPtr = staticPoints;
} else {
- pointPtr = (XPoint *)ckalloc((unsigned)(numPoints * 3*sizeof(XPoint)));
+ pointPtr = (XPoint *)
+ ckalloc((unsigned) numPoints * 3 * sizeof(XPoint));
}
if ((linePtr->smooth) && (linePtr->numPoints > 2)) {
numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr,
linePtr->numPoints, linePtr->splineSteps, pointPtr, NULL);
} else {
- numPoints = TkCanvTranslatePath((TkCanvas*)canvas, numPoints,
+ numPoints = TkCanvTranslatePath((TkCanvas *) canvas, numPoints,
linePtr->coordPtr, 0, pointPtr);
}
@@ -892,20 +898,22 @@ DisplayLine(
* read-only.
*/
- if (Tk_ChangeOutlineGC(canvas, itemPtr, &(linePtr->outline))) {
- Tk_CanvasSetOffset(canvas, linePtr->arrowGC, &linePtr->outline.tsoffset);
+ if (Tk_ChangeOutlineGC(canvas, itemPtr, &linePtr->outline)) {
+ Tk_CanvasSetOffset(canvas, linePtr->arrowGC,
+ &linePtr->outline.tsoffset);
}
- if (numPoints>1) {
+ if (numPoints > 1) {
XDrawLines(display, drawable, linePtr->outline.gc, pointPtr, numPoints,
- CoordModeOrigin);
+ CoordModeOrigin);
} else {
int intwidth = (int) (linewidth + 0.5);
- if (intwidth<1) {
- intwidth=1;
+
+ if (intwidth < 1) {
+ intwidth = 1;
}
XFillArc(display, drawable, linePtr->outline.gc,
pointPtr->x - intwidth/2, pointPtr->y - intwidth/2,
- (unsigned int)intwidth+1, (unsigned int)intwidth+1, 0, 64*360);
+ (unsigned) intwidth+1, (unsigned) intwidth+1, 0, 64*360);
}
if (pointPtr != staticPoints) {
ckfree((char *) pointPtr);
@@ -923,7 +931,7 @@ DisplayLine(
TkFillPolygon(canvas, linePtr->lastArrowPtr, PTS_IN_ARROW,
display, drawable, linePtr->arrowGC, NULL);
}
- if (Tk_ResetOutlineGC(canvas, itemPtr, &(linePtr->outline))) {
+ if (Tk_ResetOutlineGC(canvas, itemPtr, &linePtr->outline)) {
XSetTSOrigin(display, linePtr->arrowGC, 0, 0);
}
}
@@ -999,12 +1007,12 @@ LineInsert(
newCoordPtr[i+objc] = linePtr->coordPtr[i];
}
if (linePtr->coordPtr) {
- ckfree((char *)linePtr->coordPtr);
+ ckfree((char *) linePtr->coordPtr);
}
linePtr->coordPtr = newCoordPtr;
linePtr->numPoints = (length + objc)/2;
- if ((length>3) && (state != TK_STATE_HIDDEN)) {
+ if ((length > 3) && (state != TK_STATE_HIDDEN)) {
/*
* This is some optimizing code that will result that only the part of
* the polygon that changed (and the objects that are overlapping with
@@ -1016,19 +1024,25 @@ LineInsert(
itemPtr->redraw_flags |= TK_ITEM_DONT_REDRAW;
- if (beforeThis>0) {beforeThis -= 2; objc+=2; }
- if ((beforeThis+objc)<length) objc+=2;
+ if (beforeThis > 0) {
+ beforeThis -= 2;
+ objc += 2;
+ }
+ if (beforeThis+objc < length) {
+ objc += 2;
+ }
if (linePtr->smooth) {
- if(beforeThis>0) {
- beforeThis-=2; objc+=2;
+ if (beforeThis > 0) {
+ beforeThis -= 2;
+ objc += 2;
}
- if((beforeThis+objc+2)<length) {
- objc+=2;
+ if (beforeThis+objc+2 < length) {
+ objc += 2;
}
}
itemPtr->x1 = itemPtr->x2 = (int) linePtr->coordPtr[beforeThis];
itemPtr->y1 = itemPtr->y2 = (int) linePtr->coordPtr[beforeThis+1];
- if ((linePtr->firstArrowPtr != NULL) && (beforeThis<1)) {
+ if ((linePtr->firstArrowPtr != NULL) && (beforeThis < 1)) {
/*
* Include old first arrow.
*/
@@ -1038,7 +1052,7 @@ LineInsert(
TkIncludePoint(itemPtr, coordPtr);
}
}
- if ((linePtr->lastArrowPtr != NULL) && ((beforeThis+objc)>=length)) {
+ if ((linePtr->lastArrowPtr != NULL) && (beforeThis+objc >= length)) {
/*
* Include old last arrow.
*/
@@ -1048,10 +1062,10 @@ LineInsert(
TkIncludePoint(itemPtr, coordPtr);
}
}
- coordPtr = linePtr->coordPtr+beforeThis+2;
+ coordPtr = linePtr->coordPtr + beforeThis + 2;
for (i=2; i<objc; i+=2) {
TkIncludePoint(itemPtr, coordPtr);
- coordPtr+=2;
+ coordPtr += 2;
}
}
if (linePtr->firstArrowPtr != NULL) {
@@ -1070,7 +1084,7 @@ LineInsert(
double width;
int intWidth;
- if ((linePtr->firstArrowPtr != NULL) && (beforeThis>2)) {
+ if ((linePtr->firstArrowPtr != NULL) && (beforeThis > 2)) {
/*
* Include new first arrow.
*/
@@ -1092,11 +1106,11 @@ LineInsert(
}
width = linePtr->outline.width;
if (Canvas(canvas)->currentItemPtr == itemPtr) {
- if (linePtr->outline.activeWidth>width) {
+ if (linePtr->outline.activeWidth > width) {
width = linePtr->outline.activeWidth;
}
- } else if (state==TK_STATE_DISABLED) {
- if (linePtr->outline.disabledWidth>0) {
+ } else if (state == TK_STATE_DISABLED) {
+ if (linePtr->outline.disabledWidth > 0) {
width = linePtr->outline.disabledWidth;
}
}
@@ -1104,8 +1118,10 @@ LineInsert(
if (intWidth < 1) {
intWidth = 1;
}
- itemPtr->x1 -= intWidth; itemPtr->y1 -= intWidth;
- itemPtr->x2 += intWidth; itemPtr->y2 += intWidth;
+ itemPtr->x1 -= intWidth;
+ itemPtr->y1 -= intWidth;
+ itemPtr->x2 += intWidth;
+ itemPtr->y2 += intWidth;
Tk_CanvasEventuallyRedraw(canvas, itemPtr->x1, itemPtr->y1,
itemPtr->x2, itemPtr->y2);
}
@@ -1143,7 +1159,7 @@ LineDeleteCoords(
double *coordPtr;
Tk_State state = itemPtr->state;
- if(state == TK_STATE_NULL) {
+ if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
}
@@ -1167,15 +1183,24 @@ LineDeleteCoords(
linePtr->coordPtr[length-2] = linePtr->lastArrowPtr[0];
linePtr->coordPtr[length-1] = linePtr->lastArrowPtr[1];
}
- first1 = first; last1 = last;
- if(first1>0) first1 -= 2;
- if(last1<length-2) last1 += 2;
+ first1 = first;
+ last1 = last;
+ if (first1 > 0) {
+ first1 -= 2;
+ }
+ if (last1 < length-2) {
+ last1 += 2;
+ }
if (linePtr->smooth) {
- if(first1>0) first1 -= 2;
- if(last1<length-2) last1 += 2;
+ if (first1 > 0) {
+ first1 -= 2;
+ }
+ if (last1 < length-2) {
+ last1 += 2;
+ }
}
- if((first1<2) && (last1 >= length-2)) {
+ if ((first1 < 2) && (last1 >= length-2)) {
/*
* This is some optimizing code that will result that only the part of
* the line that changed (and the objects that are overlapping with
@@ -1188,7 +1213,7 @@ LineDeleteCoords(
itemPtr->redraw_flags |= TK_ITEM_DONT_REDRAW;
itemPtr->x1 = itemPtr->x2 = (int) linePtr->coordPtr[first1];
itemPtr->y1 = itemPtr->y2 = (int) linePtr->coordPtr[first1+1];
- if ((linePtr->firstArrowPtr != NULL) && (first1<2)) {
+ if ((linePtr->firstArrowPtr != NULL) && (first1 < 2)) {
/*
* Include old first arrow.
*/
@@ -1198,7 +1223,7 @@ LineDeleteCoords(
TkIncludePoint(itemPtr, coordPtr);
}
}
- if ((linePtr->lastArrowPtr != NULL) && (last1>=length-2)) {
+ if ((linePtr->lastArrowPtr != NULL) && (last1 >= length-2)) {
/*
* Include old last arrow.
*/
@@ -1211,7 +1236,7 @@ LineDeleteCoords(
coordPtr = linePtr->coordPtr+first1+2;
for (i=first1+2; i<=last1; i+=2) {
TkIncludePoint(itemPtr, coordPtr);
- coordPtr+=2;
+ coordPtr += 2;
}
}
@@ -1229,13 +1254,13 @@ LineDeleteCoords(
linePtr->lastArrowPtr = NULL;
}
if (linePtr->arrow != ARROWS_NONE) {
- ConfigureArrows(canvas, linePtr);
+ ConfigureArrows(canvas, linePtr);
}
- if(itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW) {
+ if (itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW) {
double width;
int intWidth;
- if ((linePtr->firstArrowPtr != NULL) && (first1<4)) {
+ if ((linePtr->firstArrowPtr != NULL) && (first1 < 4)) {
/*
* Include new first arrow.
*/
@@ -1245,7 +1270,7 @@ LineDeleteCoords(
TkIncludePoint(itemPtr, coordPtr);
}
}
- if ((linePtr->lastArrowPtr != NULL) && (last1>(length-4))) {
+ if ((linePtr->lastArrowPtr != NULL) && (last1 > length-4)) {
/*
* Include new right arrow.
*/
@@ -1257,20 +1282,22 @@ LineDeleteCoords(
}
width = linePtr->outline.width;
if (Canvas(canvas)->currentItemPtr == itemPtr) {
- if (linePtr->outline.activeWidth>width) {
- width = linePtr->outline.activeWidth;
- }
- } else if (state==TK_STATE_DISABLED) {
- if (linePtr->outline.disabledWidth>0) {
- width = linePtr->outline.disabledWidth;
- }
+ if (linePtr->outline.activeWidth > width) {
+ width = linePtr->outline.activeWidth;
+ }
+ } else if (state == TK_STATE_DISABLED) {
+ if (linePtr->outline.disabledWidth > 0) {
+ width = linePtr->outline.disabledWidth;
+ }
}
intWidth = (int) (width + 0.5);
if (intWidth < 1) {
intWidth = 1;
}
- itemPtr->x1 -= intWidth; itemPtr->y1 -= intWidth;
- itemPtr->x2 += intWidth; itemPtr->y2 += intWidth;
+ itemPtr->x1 -= intWidth;
+ itemPtr->y1 -= intWidth;
+ itemPtr->x2 += intWidth;
+ itemPtr->y2 += intWidth;
Tk_CanvasEventuallyRedraw(canvas, itemPtr->x1, itemPtr->y1,
itemPtr->x2, itemPtr->y2);
}
@@ -1322,17 +1349,17 @@ LineToPoint(
* which to do the check.
*/
- if(state == TK_STATE_NULL) {
+ if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
}
width = linePtr->outline.width;
if (Canvas(canvas)->currentItemPtr == itemPtr) {
- if (linePtr->outline.activeWidth>width) {
+ if (linePtr->outline.activeWidth > width) {
width = linePtr->outline.activeWidth;
}
- } else if (state==TK_STATE_DISABLED) {
- if (linePtr->outline.disabledWidth>0) {
+ } else if (state == TK_STATE_DISABLED) {
+ if (linePtr->outline.disabledWidth > 0) {
width = linePtr->outline.disabledWidth;
}
}
@@ -1343,8 +1370,8 @@ LineToPoint(
if (numPoints <= MAX_STATIC_POINTS) {
linePoints = staticSpace;
} else {
- linePoints = (double *) ckalloc((unsigned)
- (2*numPoints*sizeof(double)));
+ linePoints = (double *)
+ ckalloc((unsigned) (2*numPoints*sizeof(double)));
}
numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr,
linePtr->numPoints, linePtr->splineSteps, NULL, linePoints);
@@ -1357,12 +1384,14 @@ LineToPoint(
width = 1.0;
}
- if (!numPoints || itemPtr->state==TK_STATE_HIDDEN) {
+ if (!numPoints || itemPtr->state == TK_STATE_HIDDEN) {
return bestDist;
} else if (numPoints == 1) {
bestDist = hypot(linePoints[0]-pointPtr[0], linePoints[1]-pointPtr[1])
- width/2.0;
- if (bestDist < 0) bestDist = 0;
+ if (bestDist < 0) {
+ bestDist = 0;
+ }
return bestDist;
}
@@ -1538,23 +1567,23 @@ LineToArea(
double radius, width;
Tk_State state = itemPtr->state;
- if(state == TK_STATE_NULL) {
+ if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
}
width = linePtr->outline.width;
if (Canvas(canvas)->currentItemPtr == itemPtr) {
- if (linePtr->outline.activeWidth>width) {
+ if (linePtr->outline.activeWidth > width) {
width = linePtr->outline.activeWidth;
}
- } else if (state==TK_STATE_DISABLED) {
- if (linePtr->outline.disabledWidth>0) {
+ } else if (state == TK_STATE_DISABLED) {
+ if (linePtr->outline.disabledWidth > 0) {
width = linePtr->outline.disabledWidth;
}
}
radius = (width+1.0)/2.0;
- if ((state==TK_STATE_HIDDEN) || !linePtr->numPoints) {
+ if ((state == TK_STATE_HIDDEN) || !linePtr->numPoints) {
return -1;
} else if (linePtr->numPoints == 1) {
double oval[4];
@@ -1577,8 +1606,8 @@ LineToArea(
if (numPoints <= MAX_STATIC_POINTS) {
linePoints = staticSpace;
} else {
- linePoints = (double *) ckalloc((unsigned)
- (2*numPoints*sizeof(double)));
+ linePoints = (double *)
+ ckalloc((unsigned) (2*numPoints*sizeof(double)));
}
numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr,
linePtr->numPoints, linePtr->splineSteps, NULL, linePoints);
@@ -1591,13 +1620,12 @@ LineToArea(
* Check the segments of the line.
*/
- if (width < 1.0) {
+ if (width < 1.0) {
width = 1.0;
}
- result = TkThickPolyLineToArea(linePoints, numPoints,
- width, linePtr->capStyle, linePtr->joinStyle,
- rectPtr);
+ result = TkThickPolyLineToArea(linePoints, numPoints, width,
+ linePtr->capStyle, linePtr->joinStyle, rectPtr);
if (result == 0) {
goto done;
}
@@ -1742,7 +1770,7 @@ GetLineIndex(
}
} else if (string[0] == '@') {
int i;
- double x ,y, bestDist, dist, *coordPtr;
+ double x, y, bestDist, dist, *coordPtr;
char *end, *p;
p = string+1;
@@ -1758,9 +1786,9 @@ GetLineIndex(
bestDist = 1.0e36;
coordPtr = linePtr->coordPtr;
*indexPtr = 0;
- for(i=0; i<linePtr->numPoints; i++) {
+ for (i=0; i<linePtr->numPoints; i++) {
dist = hypot(coordPtr[0] - x, coordPtr[1] - y);
- if (dist<bestDist) {
+ if (dist < bestDist) {
bestDist = dist;
*indexPtr = 2*i;
}
@@ -1770,7 +1798,7 @@ GetLineIndex(
if (Tcl_GetIntFromObj(interp, obj, indexPtr) != TCL_OK) {
goto badIndex;
}
- *indexPtr &= -2; /* if index is odd, make it even */
+ *indexPtr &= -2; /* If index is odd, make it even. */
if (*indexPtr < 0){
*indexPtr = 0;
} else if (*indexPtr > (2*linePtr->numPoints)) {
@@ -1926,9 +1954,8 @@ PrintArrowShape(
* string here. */
{
LineItem *linePtr = (LineItem *) recordPtr;
- char *buffer;
+ char *buffer = ckalloc(120);
- buffer = (char *) ckalloc(120);
sprintf(buffer, "%.5g %.5g %.5g", linePtr->arrowShapeA,
linePtr->arrowShapeB, linePtr->arrowShapeC);
*freeProcPtr = TCL_DYNAMIC;
@@ -1967,7 +1994,7 @@ ArrowParseProc(
register Arrows *arrowPtr = (Arrows *) (widgRec + offset);
- if(value == NULL || *value == 0) {
+ if (value == NULL || *value == 0) {
*arrowPtr = ARROWS_NONE;
return TCL_OK;
}
@@ -2083,21 +2110,21 @@ ConfigureArrows(
double width;
Tk_State state = linePtr->header.state;
- if (linePtr->numPoints <2) {
+ if (linePtr->numPoints < 2) {
return TCL_OK;
}
- if(state == TK_STATE_NULL) {
+ if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
}
width = linePtr->outline.width;
if (Canvas(canvas)->currentItemPtr == (Tk_Item *)linePtr) {
- if (linePtr->outline.activeWidth>width) {
+ if (linePtr->outline.activeWidth > width) {
width = linePtr->outline.activeWidth;
}
- } else if (state==TK_STATE_DISABLED) {
- if (linePtr->outline.disabledWidth>0) {
+ } else if (state == TK_STATE_DISABLED) {
+ if (linePtr->outline.disabledWidth > 0) {
width = linePtr->outline.disabledWidth;
}
}
@@ -2124,8 +2151,8 @@ ConfigureArrows(
if (linePtr->arrow != ARROWS_LAST) {
poly = linePtr->firstArrowPtr;
if (poly == NULL) {
- poly = (double *) ckalloc((unsigned)
- (2*PTS_IN_ARROW*sizeof(double)));
+ poly = (double *)
+ ckalloc((unsigned) (2*PTS_IN_ARROW*sizeof(double)));
poly[0] = poly[10] = linePtr->coordPtr[0];
poly[1] = poly[11] = linePtr->coordPtr[1];
linePtr->firstArrowPtr = poly;
@@ -2240,7 +2267,7 @@ LineToPostscript(
Pixmap stipple;
Tk_State state = itemPtr->state;
- if(state == TK_STATE_NULL) {
+ if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
}
@@ -2248,36 +2275,36 @@ LineToPostscript(
color = linePtr->outline.color;
stipple = linePtr->outline.stipple;
if (Canvas(canvas)->currentItemPtr == itemPtr) {
- if (linePtr->outline.activeWidth>width) {
+ if (linePtr->outline.activeWidth > width) {
width = linePtr->outline.activeWidth;
}
- if (linePtr->outline.activeColor!=NULL) {
+ if (linePtr->outline.activeColor != NULL) {
color = linePtr->outline.activeColor;
}
- if (linePtr->outline.activeStipple!=None) {
+ if (linePtr->outline.activeStipple != None) {
stipple = linePtr->outline.activeStipple;
}
- } else if (state==TK_STATE_DISABLED) {
- if (linePtr->outline.disabledWidth>0) {
+ } else if (state == TK_STATE_DISABLED) {
+ if (linePtr->outline.disabledWidth > 0) {
width = linePtr->outline.disabledWidth;
}
- if (linePtr->outline.disabledColor!=NULL) {
+ if (linePtr->outline.disabledColor != NULL) {
color = linePtr->outline.disabledColor;
}
- if (linePtr->outline.disabledStipple!=None) {
+ if (linePtr->outline.disabledStipple != None) {
stipple = linePtr->outline.disabledStipple;
}
}
- if (color == NULL || linePtr->numPoints<1 || linePtr->coordPtr==NULL) {
+ if (color == NULL || linePtr->numPoints < 1 || linePtr->coordPtr == NULL){
return TCL_OK;
}
- if (linePtr->numPoints==1) {
+ if (linePtr->numPoints == 1) {
sprintf(buffer, "%.15g %.15g translate %.15g %.15g",
linePtr->coordPtr[0], Tk_CanvasPsY(canvas, linePtr->coordPtr[1]),
width/2.0, width/2.0);
- Tcl_AppendResult(interp, "matrix currentmatrix\n",buffer,
+ Tcl_AppendResult(interp, "matrix currentmatrix\n", buffer,
" scale 1 0 moveto 0 0 1 0 360 arc\nsetmatrix\n", NULL);
if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) {
return TCL_ERROR;
@@ -2299,37 +2326,34 @@ LineToPostscript(
if ((!linePtr->smooth) || (linePtr->numPoints < 3)) {
Tk_CanvasPsPath(interp, canvas, linePtr->coordPtr, linePtr->numPoints);
+ } else if ((stipple == None) && linePtr->smooth->postscriptProc) {
+ linePtr->smooth->postscriptProc(interp, canvas, linePtr->coordPtr,
+ linePtr->numPoints, linePtr->splineSteps);
} else {
- if ((stipple == None) && linePtr->smooth->postscriptProc) {
- linePtr->smooth->postscriptProc(interp, canvas,
- linePtr->coordPtr, linePtr->numPoints, linePtr->splineSteps);
- } else {
- /*
- * Special hack: Postscript printers don't appear to be able to
- * turn a path drawn with "curveto"s into a clipping path without
- * exceeding resource limits, so TkMakeBezierPostscript won't work
- * for stippled curves. Instead, generate all of the intermediate
- * points here and output them into the Postscript file with
- * "lineto"s instead.
- */
+ /*
+ * Special hack: Postscript printers don't appear to be able to turn a
+ * path drawn with "curveto"s into a clipping path without exceeding
+ * resource limits, so TkMakeBezierPostscript won't work for stippled
+ * curves. Instead, generate all of the intermediate points here and
+ * output them into the Postscript file with "lineto"s instead.
+ */
- double staticPoints[2*MAX_STATIC_POINTS];
- double *pointPtr;
- int numPoints;
+ double staticPoints[2*MAX_STATIC_POINTS];
+ double *pointPtr;
+ int numPoints;
- numPoints = linePtr->smooth->coordProc(canvas, NULL,
- linePtr->numPoints, linePtr->splineSteps, NULL, NULL);
- pointPtr = staticPoints;
- if (numPoints > MAX_STATIC_POINTS) {
- pointPtr = (double *) ckalloc((unsigned)
- (numPoints * 2 * sizeof(double)));
- }
- numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr,
- linePtr->numPoints, linePtr->splineSteps, NULL, pointPtr);
- Tk_CanvasPsPath(interp, canvas, pointPtr, numPoints);
- if (pointPtr != staticPoints) {
- ckfree((char *) pointPtr);
- }
+ numPoints = linePtr->smooth->coordProc(canvas, NULL,
+ linePtr->numPoints, linePtr->splineSteps, NULL, NULL);
+ pointPtr = staticPoints;
+ if (numPoints > MAX_STATIC_POINTS) {
+ pointPtr = (double *)
+ ckalloc((unsigned) (numPoints * 2 * sizeof(double)));
+ }
+ numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr,
+ linePtr->numPoints, linePtr->splineSteps, NULL, pointPtr);
+ Tk_CanvasPsPath(interp, canvas, pointPtr, numPoints);
+ if (pointPtr != staticPoints) {
+ ckfree((char *) pointPtr);
}
}
@@ -2352,7 +2376,7 @@ LineToPostscript(
}
Tcl_AppendResult(interp, style, NULL);
- if (Tk_CanvasPsOutline(canvas, itemPtr, &(linePtr->outline)) != TCL_OK) {
+ if (Tk_CanvasPsOutline(canvas, itemPtr, &linePtr->outline) != TCL_OK) {
return TCL_ERROR;
}
@@ -2422,7 +2446,7 @@ ArrowheadPostscript(
if (linePtr->outline.activeStipple!=None) {
stipple = linePtr->outline.activeStipple;
}
- } else if (state==TK_STATE_DISABLED) {
+ } else if (state == TK_STATE_DISABLED) {
if (linePtr->outline.activeStipple!=None) {
stipple = linePtr->outline.disabledStipple;
}
diff --git a/generic/tkCanvPoly.c b/generic/tkCanvPoly.c
index d5e63d8..c9c1e8d 100644
--- a/generic/tkCanvPoly.c
+++ b/generic/tkCanvPoly.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkCanvPoly.c,v 1.20 2008/10/30 23:18:59 nijtmans Exp $
+ * RCS: @(#) $Id: tkCanvPoly.c,v 1.21 2008/11/01 16:14:30 dkf Exp $
*/
#include <stdio.h>
@@ -199,7 +199,7 @@ Tk_ItemType tkPolygonType = {
PolygonCoords, /* coordProc */
DeletePolygon, /* deleteProc */
DisplayPolygon, /* displayProc */
- TK_CONFIG_OBJS, /* flags */
+ TK_CONFIG_OBJS | TK_MOVABLE_POINTS, /* flags */
PolygonToPoint, /* pointProc */
PolygonToArea, /* areaProc */
PolygonToPostscript, /* postscriptProc */
@@ -261,7 +261,7 @@ CreatePolygon(
* errors during the the remainder of this function.
*/
- Tk_CreateOutline(&(polyPtr->outline));
+ Tk_CreateOutline(&polyPtr->outline);
polyPtr->numPoints = 0;
polyPtr->pointsAllocated = 0;
polyPtr->coordPtr = NULL;
@@ -288,6 +288,7 @@ CreatePolygon(
for (i = 0; i < objc; i++) {
char *arg = Tcl_GetString(objv[i]);
+
if ((arg[0] == '-') && (arg[1] >= 'a') && (arg[1] <= 'z')) {
break;
}
@@ -357,50 +358,49 @@ PolygonCoords(
}
}
if (objc & 1) {
- char buf[64 + TCL_INTEGER_SPACE];
-
- sprintf(buf, "wrong # coordinates: expected an even number, got %d",
- objc);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "wrong # coordinates: expected an even number, got %d",
+ objc));
return TCL_ERROR;
- } else {
- numPoints = objc/2;
- if (polyPtr->pointsAllocated <= numPoints) {
- if (polyPtr->coordPtr != NULL) {
- ckfree((char *) polyPtr->coordPtr);
- }
-
- /*
- * One extra point gets allocated here, because we always add
- * another point to close the polygon.
- */
+ }
- polyPtr->coordPtr = (double *) ckalloc((unsigned)
- (sizeof(double) * (objc+2)));
- polyPtr->pointsAllocated = numPoints+1;
- }
- for (i = objc-1; i >= 0; i--) {
- if (Tk_CanvasGetCoordFromObj(interp, canvas, objv[i],
- &polyPtr->coordPtr[i]) != TCL_OK) {
- return TCL_ERROR;
- }
+ numPoints = objc/2;
+ if (polyPtr->pointsAllocated <= numPoints) {
+ if (polyPtr->coordPtr != NULL) {
+ ckfree((char *) polyPtr->coordPtr);
}
- polyPtr->numPoints = numPoints;
- polyPtr->autoClosed = 0;
/*
- * Close the polygon if it isn't already closed.
+ * One extra point gets allocated here, because we always add
+ * another point to close the polygon.
*/
- if (objc>2 && ((polyPtr->coordPtr[objc-2] != polyPtr->coordPtr[0])
- || (polyPtr->coordPtr[objc-1] != polyPtr->coordPtr[1]))) {
- polyPtr->autoClosed = 1;
- polyPtr->numPoints++;
- polyPtr->coordPtr[objc] = polyPtr->coordPtr[0];
- polyPtr->coordPtr[objc+1] = polyPtr->coordPtr[1];
+ polyPtr->coordPtr = (double *)
+ ckalloc(sizeof(double) * (unsigned)(objc+2));
+ polyPtr->pointsAllocated = numPoints+1;
+ }
+ for (i = objc-1; i >= 0; i--) {
+ if (Tk_CanvasGetCoordFromObj(interp, canvas, objv[i],
+ &polyPtr->coordPtr[i]) != TCL_OK) {
+ return TCL_ERROR;
}
- ComputePolygonBbox(canvas, polyPtr);
}
+ polyPtr->numPoints = numPoints;
+ polyPtr->autoClosed = 0;
+
+ /*
+ * Close the polygon if it isn't already closed.
+ */
+
+ if (objc>2 && ((polyPtr->coordPtr[objc-2] != polyPtr->coordPtr[0])
+ || (polyPtr->coordPtr[objc-1] != polyPtr->coordPtr[1]))) {
+ polyPtr->autoClosed = 1;
+ polyPtr->numPoints++;
+ polyPtr->coordPtr[objc] = polyPtr->coordPtr[0];
+ polyPtr->coordPtr[objc+1] = polyPtr->coordPtr[1];
+ }
+
+ ComputePolygonBbox(canvas, polyPtr);
return TCL_OK;
}
@@ -465,15 +465,15 @@ ConfigurePolygon(
itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT;
}
- if(state == TK_STATE_NULL) {
+ if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
}
- if (state==TK_STATE_HIDDEN) {
+ if (state == TK_STATE_HIDDEN) {
ComputePolygonBbox(canvas, polyPtr);
return TCL_OK;
}
- mask = Tk_ConfigOutlineGC(&gcValues, canvas, itemPtr, &(polyPtr->outline));
+ mask = Tk_ConfigOutlineGC(&gcValues, canvas, itemPtr, &polyPtr->outline);
if (mask) {
gcValues.cap_style = CapRound;
gcValues.join_style = polyPtr->joinStyle;
@@ -490,17 +490,17 @@ ConfigurePolygon(
color = polyPtr->fillColor;
stipple = polyPtr->fillStipple;
if (Canvas(canvas)->currentItemPtr == itemPtr) {
- if (polyPtr->activeFillColor!=NULL) {
+ if (polyPtr->activeFillColor != NULL) {
color = polyPtr->activeFillColor;
}
- if (polyPtr->activeFillStipple!=None) {
+ if (polyPtr->activeFillStipple != None) {
stipple = polyPtr->activeFillStipple;
}
- } else if (state==TK_STATE_DISABLED) {
- if (polyPtr->disabledFillColor!=NULL) {
+ } else if (state == TK_STATE_DISABLED) {
+ if (polyPtr->disabledFillColor != NULL) {
color = polyPtr->disabledFillColor;
}
- if (polyPtr->disabledFillStipple!=None) {
+ if (polyPtr->disabledFillStipple != None) {
stipple = polyPtr->disabledFillStipple;
}
}
@@ -570,7 +570,7 @@ DeletePolygon(
{
PolygonItem *polyPtr = (PolygonItem *) itemPtr;
- Tk_DeleteOutline(display,&(polyPtr->outline));
+ Tk_DeleteOutline(display, &polyPtr->outline);
if (polyPtr->coordPtr != NULL) {
ckfree((char *) polyPtr->coordPtr);
}
@@ -625,21 +625,22 @@ ComputePolygonBbox(
Tk_State state = polyPtr->header.state;
Tk_TSOffset *tsoffset;
- if(state == TK_STATE_NULL) {
+ if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
}
width = polyPtr->outline.width;
- if (polyPtr->coordPtr == NULL || (polyPtr->numPoints < 1) || (state==TK_STATE_HIDDEN)) {
+ if (polyPtr->coordPtr == NULL || (polyPtr->numPoints < 1)
+ || (state == TK_STATE_HIDDEN)) {
polyPtr->header.x1 = polyPtr->header.x2 =
- polyPtr->header.y1 = polyPtr->header.y2 = -1;
+ polyPtr->header.y1 = polyPtr->header.y2 = -1;
return;
}
- if (Canvas(canvas)->currentItemPtr == (Tk_Item *)polyPtr) {
- if (polyPtr->outline.activeWidth>width) {
+ if (Canvas(canvas)->currentItemPtr == (Tk_Item *) polyPtr) {
+ if (polyPtr->outline.activeWidth > width) {
width = polyPtr->outline.activeWidth;
}
- } else if (state==TK_STATE_DISABLED) {
- if (polyPtr->outline.disabledWidth>0.0) {
+ } else if (state == TK_STATE_DISABLED) {
+ if (polyPtr->outline.disabledWidth > 0.0) {
width = polyPtr->outline.disabledWidth;
}
}
@@ -665,6 +666,7 @@ ComputePolygonBbox(
tsoffset = &polyPtr->tsoffset;
if (tsoffset->flags & TK_OFFSET_INDEX) {
int index = tsoffset->flags & ~TK_OFFSET_INDEX;
+
if (tsoffset->flags == INT_MAX) {
index = (polyPtr->numPoints - polyPtr->autoClosed) * 2;
if (index < 0) {
@@ -672,7 +674,7 @@ ComputePolygonBbox(
}
}
index %= (polyPtr->numPoints - polyPtr->autoClosed) * 2;
- if (index <0) {
+ if (index < 0) {
index += (polyPtr->numPoints - polyPtr->autoClosed) * 2;
}
tsoffset->xoffset = (int) (polyPtr->coordPtr[index] + 0.5);
@@ -704,7 +706,7 @@ ComputePolygonBbox(
index = (polyPtr->numPoints - 1) * 2;
}
index %= (polyPtr->numPoints - 1) * 2;
- if (index <0) {
+ if (index < 0) {
index += (polyPtr->numPoints - 1) * 2;
}
tsoffset->xoffset = (int) (polyPtr->coordPtr[index] + 0.5);
@@ -713,21 +715,23 @@ ComputePolygonBbox(
if (tsoffset->flags & TK_OFFSET_LEFT) {
tsoffset->xoffset = polyPtr->header.x1;
} else if (tsoffset->flags & TK_OFFSET_CENTER) {
- tsoffset->xoffset = (polyPtr->header.x1 + polyPtr->header.x2)/2;
+ tsoffset->xoffset =
+ (polyPtr->header.x1 + polyPtr->header.x2) / 2;
} else if (tsoffset->flags & TK_OFFSET_RIGHT) {
tsoffset->xoffset = polyPtr->header.x2;
}
if (tsoffset->flags & TK_OFFSET_TOP) {
tsoffset->yoffset = polyPtr->header.y1;
} else if (tsoffset->flags & TK_OFFSET_MIDDLE) {
- tsoffset->yoffset = (polyPtr->header.y1 + polyPtr->header.y2)/2;
+ tsoffset->yoffset =
+ (polyPtr->header.y1 + polyPtr->header.y2) / 2;
} else if (tsoffset->flags & TK_OFFSET_BOTTOM) {
tsoffset->yoffset = polyPtr->header.y2;
}
}
}
- i = (int) ((width+1.5)/2.0);
+ i = (int) ((width+1.5) / 2.0);
polyPtr->header.x1 -= i;
polyPtr->header.x2 += i;
polyPtr->header.y1 -= i;
@@ -744,19 +748,17 @@ ComputePolygonBbox(
int j;
coordPtr = polyPtr->coordPtr;
- if (polyPtr->numPoints>3) {
+ if (polyPtr->numPoints > 3) {
if (TkGetMiterPoints(coordPtr+2*(polyPtr->numPoints-2),
- coordPtr, coordPtr+2, width,
- miter, miter+2)) {
+ coordPtr, coordPtr+2, width, miter, miter+2)) {
for (j = 0; j < 4; j += 2) {
TkIncludePoint((Tk_Item *) polyPtr, miter+j);
}
}
- }
+ }
for (i = polyPtr->numPoints ; i >= 3; i--, coordPtr += 2) {
-
- if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4,
- width, miter, miter+2)) {
+ if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, width,
+ miter, miter+2)) {
for (j = 0; j < 4; j += 2) {
TkIncludePoint((Tk_Item *) polyPtr, miter+j);
}
@@ -823,7 +825,7 @@ TkFillPolygon(
if (numPoints <= MAX_STATIC_POINTS) {
pointPtr = staticPoints;
} else {
- pointPtr = (XPoint *) ckalloc((unsigned) (numPoints * sizeof(XPoint)));
+ pointPtr = (XPoint *) ckalloc((unsigned) numPoints * sizeof(XPoint));
}
for (i=0, pPtr=pointPtr ; i<numPoints; i+=1, coordPtr+=2, pPtr++) {
@@ -836,13 +838,13 @@ TkFillPolygon(
* allocated.
*/
- if (gc != None && numPoints>3) {
+ if (gc != None && numPoints > 3) {
XFillPolygon(display, drawable, gc, pointPtr, numPoints, Complex,
CoordModeOrigin);
}
if (outlineGC != None) {
- XDrawLines(display, drawable, outlineGC, pointPtr,
- numPoints, CoordModeOrigin);
+ XDrawLines(display, drawable, outlineGC, pointPtr, numPoints,
+ CoordModeOrigin);
}
if (pointPtr != staticPoints) {
ckfree((char *) pointPtr);
@@ -891,14 +893,14 @@ DisplayPolygon(
state = Canvas(canvas)->canvas_state;
}
if (Canvas(canvas)->currentItemPtr == itemPtr) {
- if (polyPtr->outline.activeWidth>linewidth) {
+ if (polyPtr->outline.activeWidth > linewidth) {
linewidth = polyPtr->outline.activeWidth;
}
if (polyPtr->activeFillStipple != None) {
stipple = polyPtr->activeFillStipple;
}
- } else if (state==TK_STATE_DISABLED) {
- if (polyPtr->outline.disabledWidth>0.0) {
+ } else if (state == TK_STATE_DISABLED) {
+ if (polyPtr->outline.disabledWidth > 0.0) {
linewidth = polyPtr->outline.disabledWidth;
}
if (polyPtr->disabledFillStipple != None) {
@@ -913,10 +915,11 @@ DisplayPolygon(
if ((stipple != None) && (polyPtr->fillGC != None)) {
Tk_TSOffset *tsoffset = &polyPtr->tsoffset;
- int w=0; int h=0;
+ int w = 0, h = 0;
int flags = tsoffset->flags;
- if (!(flags & TK_OFFSET_INDEX) && (flags & (TK_OFFSET_CENTER|TK_OFFSET_MIDDLE))) {
+ if (!(flags & TK_OFFSET_INDEX)
+ && (flags & (TK_OFFSET_CENTER|TK_OFFSET_MIDDLE))) {
Tk_SizeOfBitmap(display, stipple, &w, &h);
if (flags & TK_OFFSET_CENTER) {
w /= 2;
@@ -935,20 +938,20 @@ DisplayPolygon(
tsoffset->xoffset += w;
tsoffset->yoffset += h;
}
- Tk_ChangeOutlineGC(canvas, itemPtr, &(polyPtr->outline));
+ Tk_ChangeOutlineGC(canvas, itemPtr, &polyPtr->outline);
- if(polyPtr->numPoints < 3) {
- short x,y;
+ if (polyPtr->numPoints < 3) {
+ short x, y;
int intLineWidth = (int) (linewidth + 0.5);
if (intLineWidth < 1) {
intLineWidth = 1;
}
Tk_CanvasDrawableCoords(canvas, polyPtr->coordPtr[0],
- polyPtr->coordPtr[1], &x,&y);
+ polyPtr->coordPtr[1], &x, &y);
XFillArc(display, drawable, polyPtr->outline.gc,
x - intLineWidth/2, y - intLineWidth/2,
- (unsigned int)intLineWidth+1, (unsigned int)intLineWidth+1,
+ (unsigned) intLineWidth+1, (unsigned) intLineWidth+1,
0, 64*360);
} else if (!polyPtr->smooth || polyPtr->numPoints < 4) {
TkFillPolygon(canvas, polyPtr->coordPtr, polyPtr->numPoints,
@@ -968,8 +971,8 @@ DisplayPolygon(
if (numPoints <= MAX_STATIC_POINTS) {
pointPtr = staticPoints;
} else {
- pointPtr = (XPoint *) ckalloc((unsigned)
- (numPoints * sizeof(XPoint)));
+ pointPtr = (XPoint *)
+ ckalloc((unsigned) numPoints * sizeof(XPoint));
}
numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr,
polyPtr->numPoints, polyPtr->splineSteps, pointPtr, NULL);
@@ -985,7 +988,7 @@ DisplayPolygon(
ckfree((char *) pointPtr);
}
}
- Tk_ResetOutlineGC(canvas, itemPtr, &(polyPtr->outline));
+ Tk_ResetOutlineGC(canvas, itemPtr, &polyPtr->outline);
if ((stipple != None) && (polyPtr->fillGC != None)) {
XSetTSOrigin(display, polyPtr->fillGC, 0, 0);
}
@@ -1030,10 +1033,10 @@ PolygonInsert(
return;
}
length = 2*(polyPtr->numPoints - polyPtr->autoClosed);
- while (beforeThis>length) {
+ while (beforeThis > length) {
beforeThis -= length;
}
- while (beforeThis<0) {
+ while (beforeThis < 0) {
beforeThis += length;
}
newCoordPtr = (double *)
@@ -1080,7 +1083,7 @@ PolygonInsert(
newCoordPtr[length] = newCoordPtr[0];
newCoordPtr[length+1] = newCoordPtr[1];
- if (((length-objc)>3) && (state != TK_STATE_HIDDEN)) {
+ if ((length-objc > 3) && (state != TK_STATE_HIDDEN)) {
/*
* This is some optimizing code that will result that only the part of
* the polygon that changed (and the objects that are overlapping with
@@ -1092,6 +1095,7 @@ PolygonInsert(
double width;
int j;
+
itemPtr->redraw_flags |= TK_ITEM_DONT_REDRAW;
/*
@@ -1103,10 +1107,11 @@ PolygonInsert(
itemPtr->x1 = itemPtr->x2 = (int) polyPtr->coordPtr[beforeThis];
itemPtr->y1 = itemPtr->y2 = (int) polyPtr->coordPtr[beforeThis+1];
- beforeThis-=2; objc+=4;
+ beforeThis -= 2;
+ objc += 4;
if (polyPtr->smooth) {
- beforeThis-=2;
- objc+=4;
+ beforeThis -= 2;
+ objc += 4;
}
/*
@@ -1115,9 +1120,9 @@ PolygonInsert(
for (i=beforeThis; i<beforeThis+objc; i+=2) {
j = i;
- if (j<0) {
+ if (j < 0) {
j += length;
- } else if (j>=length) {
+ } else if (j >= length) {
j -= length;
}
TkIncludePoint(itemPtr, polyPtr->coordPtr+j);
@@ -1127,13 +1132,15 @@ PolygonInsert(
if (polyPtr->outline.activeWidth > width) {
width = polyPtr->outline.activeWidth;
}
- } else if (state==TK_STATE_DISABLED) {
+ } else if (state == TK_STATE_DISABLED) {
if (polyPtr->outline.disabledWidth > 0.0) {
width = polyPtr->outline.disabledWidth;
}
}
- itemPtr->x1 -= (int) width; itemPtr->y1 -= (int) width;
- itemPtr->x2 += (int) width; itemPtr->y2 += (int) width;
+ itemPtr->x1 -= (int) width;
+ itemPtr->y1 -= (int) width;
+ itemPtr->x2 += (int) width;
+ itemPtr->y2 += (int) width;
Tk_CanvasEventuallyRedraw(canvas,
itemPtr->x1, itemPtr->y1, itemPtr->x2, itemPtr->y2);
}
@@ -1169,16 +1176,16 @@ PolygonDeleteCoords(
int count, i;
int length = 2*(polyPtr->numPoints - polyPtr->autoClosed);
- while (first>=length) {
+ while (first >= length) {
first -= length;
}
- while (first<0) {
+ while (first < 0) {
first += length;
}
- while (last>=length) {
+ while (last >= length) {
last -= length;
}
- while (last<0) {
+ while (last < 0) {
last += length;
}
@@ -1186,7 +1193,7 @@ PolygonDeleteCoords(
last &= -2;
count = last + 2 - first;
- if (count<=0) {
+ if (count <= 0) {
count += length;
}
@@ -1199,12 +1206,12 @@ PolygonDeleteCoords(
return;
}
- if (last>=first) {
- for(i=last+2; i<length; i++) {
+ if (last >= first) {
+ for (i=last+2; i<length; i++) {
polyPtr->coordPtr[i-count] = polyPtr->coordPtr[i];
}
} else {
- for(i=last; i<=first; i++) {
+ for (i=last; i<=first; i++) {
polyPtr->coordPtr[i-last] = polyPtr->coordPtr[i];
}
}
@@ -1261,11 +1268,11 @@ PolygonToPoint(
}
width = polyPtr->outline.width;
if (Canvas(canvas)->currentItemPtr == itemPtr) {
- if (polyPtr->outline.activeWidth>width) {
+ if (polyPtr->outline.activeWidth > width) {
width = polyPtr->outline.activeWidth;
}
- } else if (state==TK_STATE_DISABLED) {
- if (polyPtr->outline.disabledWidth>0.0) {
+ } else if (state == TK_STATE_DISABLED) {
+ if (polyPtr->outline.disabledWidth > 0.0) {
width = polyPtr->outline.disabledWidth;
}
}
@@ -1276,26 +1283,24 @@ PolygonToPoint(
* against which to do the check.
*/
- if ((polyPtr->smooth) && (polyPtr->numPoints>2)) {
+ if ((polyPtr->smooth) && (polyPtr->numPoints > 2)) {
numPoints = polyPtr->smooth->coordProc(canvas, NULL,
- polyPtr->numPoints, polyPtr->splineSteps, NULL,
- NULL);
+ polyPtr->numPoints, polyPtr->splineSteps, NULL, NULL);
if (numPoints <= MAX_STATIC_POINTS) {
polyPoints = staticSpace;
} else {
- polyPoints = (double *) ckalloc((unsigned)
- (2*numPoints*sizeof(double)));
+ polyPoints = (double *)
+ ckalloc((unsigned) 2*numPoints*sizeof(double));
}
numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr,
- polyPtr->numPoints, polyPtr->splineSteps, NULL,
- polyPoints);
+ polyPtr->numPoints, polyPtr->splineSteps, NULL, polyPoints);
} else {
numPoints = polyPtr->numPoints;
polyPoints = polyPtr->coordPtr;
}
bestDist = TkPolygonToPoint(polyPoints, numPoints, pointPtr);
- if (bestDist<=0.0) {
+ if (bestDist <= 0.0) {
goto donepoint;
}
if ((polyPtr->outline.gc != None) && (polyPtr->joinStyle == JoinRound)) {
@@ -1345,16 +1350,16 @@ PolygonToPoint(
*/
if (count == numPoints) {
- TkGetButtPoints(coordPtr+2, coordPtr, (double) width,
- 0, poly, poly+2);
+ TkGetButtPoints(coordPtr+2, coordPtr, (double) width, 0, poly,
+ poly+2);
} else if ((polyPtr->joinStyle == JoinMiter) && !changedMiterToBevel) {
poly[0] = poly[6];
poly[1] = poly[7];
poly[2] = poly[4];
poly[3] = poly[5];
} else {
- TkGetButtPoints(coordPtr+2, coordPtr, (double) width, 0,
- poly, poly+2);
+ TkGetButtPoints(coordPtr+2, coordPtr, (double) width, 0, poly,
+ poly+2);
/*
* If this line uses beveled joints, then check the distance to a
@@ -1377,8 +1382,8 @@ PolygonToPoint(
}
}
if (count == 2) {
- TkGetButtPoints(coordPtr, coordPtr+2, (double) width,
- 0, poly+4, poly+6);
+ TkGetButtPoints(coordPtr, coordPtr+2, (double) width, 0, poly+4,
+ poly+6);
} else if (polyPtr->joinStyle == JoinMiter) {
if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4,
(double) width, poly+4, poly+6) == 0) {
@@ -1387,8 +1392,8 @@ PolygonToPoint(
poly+4, poly+6);
}
} else {
- TkGetButtPoints(coordPtr, coordPtr+2, (double) width, 0,
- poly+4, poly+6);
+ TkGetButtPoints(coordPtr, coordPtr+2, (double) width, 0, poly+4,
+ poly+6);
}
poly[8] = poly[0];
poly[9] = poly[1];
@@ -1402,7 +1407,7 @@ PolygonToPoint(
}
donepoint:
- if ((polyPoints != staticSpace) && polyPoints != polyPtr->coordPtr) {
+ if (polyPoints != staticSpace && polyPoints != polyPtr->coordPtr) {
ckfree((char *) polyPoints);
}
return bestDist;
@@ -1459,11 +1464,11 @@ PolygonToArea(
width = polyPtr->outline.width;
if (Canvas(canvas)->currentItemPtr == itemPtr) {
- if (polyPtr->outline.activeWidth>width) {
+ if (polyPtr->outline.activeWidth > width) {
width = polyPtr->outline.activeWidth;
}
- } else if (state==TK_STATE_DISABLED) {
- if (polyPtr->outline.disabledWidth>0.0) {
+ } else if (state == TK_STATE_DISABLED) {
+ if (polyPtr->outline.disabledWidth > 0.0) {
width = polyPtr->outline.disabledWidth;
}
}
@@ -1471,9 +1476,9 @@ PolygonToArea(
radius = width/2.0;
inside = -1;
- if ((state==TK_STATE_HIDDEN) || polyPtr->numPoints<2) {
+ if ((state == TK_STATE_HIDDEN) || polyPtr->numPoints < 2) {
return -1;
- } else if (polyPtr->numPoints <3) {
+ } else if (polyPtr->numPoints < 3) {
double oval[4];
oval[0] = polyPtr->coordPtr[0]-radius;
@@ -1495,7 +1500,7 @@ PolygonToArea(
polyPoints = staticSpace;
} else {
polyPoints = (double *)
- ckalloc((unsigned) (2*numPoints*sizeof(double)));
+ ckalloc((unsigned) 2*numPoints*sizeof(double));
}
numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr,
polyPtr->numPoints, polyPtr->splineSteps, NULL, polyPoints);
@@ -1511,7 +1516,7 @@ PolygonToArea(
*/
inside = TkPolygonToArea(polyPoints, numPoints, rectPtr);
- if (inside==0) {
+ if (inside == 0) {
goto donearea;
}
@@ -1580,8 +1585,8 @@ PolygonToArea(
if (count == 2) {
TkGetButtPoints(coordPtr, coordPtr+2, width, 0, poly+4, poly+6);
} else if (polyPtr->joinStyle == JoinMiter) {
- if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4,
- width, poly+4, poly+6) == 0) {
+ if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, width,
+ poly+4, poly+6) == 0) {
changedMiterToBevel = 1;
TkGetButtPoints(coordPtr, coordPtr+2, width,0, poly+4, poly+6);
}
@@ -1677,22 +1682,13 @@ GetPolygonIndex(
char *string = Tcl_GetStringFromObj(obj, &length);
if (string[0] == 'e') {
- if (strncmp(string, "end", (unsigned)length) == 0) {
- *indexPtr = 2*(polyPtr->numPoints - polyPtr->autoClosed);
- } else {
- /*
- * Some of the paths here leave messages in interp->result, so we
- * have to clear it out before storing our own message.
- */
-
- badIndex:
- Tcl_SetResult(interp, NULL, TCL_STATIC);
- Tcl_AppendResult(interp, "bad index \"", string, "\"", NULL);
- return TCL_ERROR;
+ if (strncmp(string, "end", (unsigned)length) != 0) {
+ goto badIndex;
}
+ *indexPtr = 2*(polyPtr->numPoints - polyPtr->autoClosed);
} else if (string[0] == '@') {
int i;
- double x ,y, bestDist, dist, *coordPtr;
+ double x, y, bestDist, dist, *coordPtr;
char *end, *p;
p = string+1;
@@ -1708,9 +1704,9 @@ GetPolygonIndex(
bestDist = 1.0e36;
coordPtr = polyPtr->coordPtr;
*indexPtr = 0;
- for(i=0; i<(polyPtr->numPoints-1); i++) {
+ for (i=0; i<polyPtr->numPoints-1; i++) {
dist = hypot(coordPtr[0] - x, coordPtr[1] - y);
- if (dist<bestDist) {
+ if (dist < bestDist) {
bestDist = dist;
*indexPtr = 2*i;
}
@@ -1723,17 +1719,24 @@ GetPolygonIndex(
goto badIndex;
}
*indexPtr &= -2; /* if odd, make it even */
- if (count) {
- if (*indexPtr > 0) {
- *indexPtr = ((*indexPtr - 2) % count) + 2;
- } else {
- *indexPtr = -((-(*indexPtr)) % count);
- }
- } else {
+ if (!count) {
*indexPtr = 0;
+ } else if (*indexPtr > 0) {
+ *indexPtr = ((*indexPtr - 2) % count) + 2;
+ } else {
+ *indexPtr = -((-(*indexPtr)) % count);
}
}
return TCL_OK;
+
+ /*
+ * Some of the paths here leave messages in interp->result, so we have to
+ * clear it out before storing our own message.
+ */
+
+ badIndex:
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad index \"%s\"", string));
+ return TCL_ERROR;
}
/*
@@ -1809,11 +1812,11 @@ PolygonToPostscript(
Tk_State state = itemPtr->state;
double width;
- if (polyPtr->numPoints<2 || polyPtr->coordPtr==NULL) {
+ if (polyPtr->numPoints < 2 || polyPtr->coordPtr == NULL) {
return TCL_OK;
}
- if(state == TK_STATE_NULL) {
+ if (state == TK_STATE_NULL) {
state = Canvas(canvas)->canvas_state;
}
width = polyPtr->outline.width;
@@ -1822,49 +1825,63 @@ PolygonToPostscript(
fillColor = polyPtr->fillColor;
fillStipple = polyPtr->fillStipple;
if (Canvas(canvas)->currentItemPtr == itemPtr) {
- if (polyPtr->outline.activeWidth>width) {
+ if (polyPtr->outline.activeWidth > width) {
width = polyPtr->outline.activeWidth;
}
- if (polyPtr->outline.activeColor!=NULL) {
+ if (polyPtr->outline.activeColor != NULL) {
color = polyPtr->outline.activeColor;
}
- if (polyPtr->outline.activeStipple!=None) {
+ if (polyPtr->outline.activeStipple != None) {
stipple = polyPtr->outline.activeStipple;
}
- if (polyPtr->activeFillColor!=NULL) {
+ if (polyPtr->activeFillColor != NULL) {
fillColor = polyPtr->activeFillColor;
}
- if (polyPtr->activeFillStipple!=None) {
+ if (polyPtr->activeFillStipple != None) {
fillStipple = polyPtr->activeFillStipple;
}
- } else if (state==TK_STATE_DISABLED) {
- if (polyPtr->outline.disabledWidth>0.0) {
+ } else if (state == TK_STATE_DISABLED) {
+ if (polyPtr->outline.disabledWidth > 0.0) {
width = polyPtr->outline.disabledWidth;
}
- if (polyPtr->outline.disabledColor!=NULL) {
+ if (polyPtr->outline.disabledColor != NULL) {
color = polyPtr->outline.disabledColor;
}
- if (polyPtr->outline.disabledStipple!=None) {
+ if (polyPtr->outline.disabledStipple != None) {
stipple = polyPtr->outline.disabledStipple;
}
- if (polyPtr->disabledFillColor!=NULL) {
+ if (polyPtr->disabledFillColor != NULL) {
fillColor = polyPtr->disabledFillColor;
}
- if (polyPtr->disabledFillStipple!=None) {
+ if (polyPtr->disabledFillStipple != None) {
fillStipple = polyPtr->disabledFillStipple;
}
}
- if (polyPtr->numPoints==2) {
- char string[128];
+ if (polyPtr->numPoints == 2) {
if (color == NULL) {
return TCL_OK;
}
- sprintf(string, "%.15g %.15g translate %.15g %.15g",
- polyPtr->coordPtr[0], Tk_CanvasPsY(canvas, polyPtr->coordPtr[1]),
- width/2.0, width/2.0);
- Tcl_AppendResult(interp, "matrix currentmatrix\n",string,
- " scale 1 0 moveto 0 0 1 0 360 arc\nsetmatrix\n", NULL);
+ /*
+ * Create a point by using a small circle. (Printer pixels are too
+ * tiny to be used directly...)
+ */
+
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "matrix currentmatrix\n" /* save state */
+ "%.15g %.15g translate " /* go to drawing location */
+ "%.15g %.15g scale " /* scale the drawing */
+ "1 0 moveto " /* correct for origin */
+ "0 0 1 0 360 arc\n" /* make the circle */
+ "setmatrix\n", /* restore state */
+ polyPtr->coordPtr[0],
+ Tk_CanvasPsY(canvas, polyPtr->coordPtr[1]),
+ width/2.0, width/2.0));
+
+ /*
+ * Color it in.
+ */
+
if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) {
return TCL_ERROR;
}
@@ -1883,7 +1900,7 @@ PolygonToPostscript(
* Fill the area of the polygon.
*/
- if (fillColor != NULL && polyPtr->numPoints>3) {
+ if (fillColor != NULL && polyPtr->numPoints > 3) {
if (!polyPtr->smooth || !polyPtr->smooth->postscriptProc) {
Tk_CanvasPsPath(interp, canvas, polyPtr->coordPtr,
polyPtr->numPoints);
@@ -1927,9 +1944,8 @@ PolygonToPostscript(
} else {
style = "0";
}
- Tcl_AppendResult(interp, style," setlinejoin 1 setlinecap\n", NULL);
- if (Tk_CanvasPsOutline(canvas, itemPtr,
- &(polyPtr->outline)) != TCL_OK) {
+ Tcl_AppendResult(interp, style, " setlinejoin 1 setlinecap\n", NULL);
+ if (Tk_CanvasPsOutline(canvas, itemPtr, &polyPtr->outline) != TCL_OK){
return TCL_ERROR;
}
}
diff --git a/generic/tkCanvPs.c b/generic/tkCanvPs.c
index a5efd72..951245a 100644
--- a/generic/tkCanvPs.c
+++ b/generic/tkCanvPs.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkCanvPs.c,v 1.20 2008/04/27 22:38:55 dkf Exp $
+ * RCS: @(#) $Id: tkCanvPs.c,v 1.21 2008/11/01 16:14:30 dkf Exp $
*/
#include "tkInt.h"
@@ -383,7 +383,7 @@ TkCanvPostscriptCmd(
if (itemPtr->typePtr->postscriptProc == NULL) {
continue;
}
- result = (*itemPtr->typePtr->postscriptProc)(interp,
+ result = itemPtr->typePtr->postscriptProc(interp,
(Tk_Canvas) canvasPtr, itemPtr, 1);
Tcl_ResetResult(interp);
if (result != TCL_OK) {
@@ -393,6 +393,7 @@ TkCanvPostscriptCmd(
* can happen later that don't happen now, so we still have to
* check for errors later anyway).
*/
+
break;
}
}
@@ -527,7 +528,7 @@ TkCanvPostscriptCmd(
continue;
}
Tcl_AppendResult(interp, "gsave\n", NULL);
- result = (*itemPtr->typePtr->postscriptProc)(interp,
+ result = itemPtr->typePtr->postscriptProc(interp,
(Tk_Canvas) canvasPtr, itemPtr, 0);
if (result != TCL_OK) {
char msg[64 + TCL_INTEGER_SPACE];
diff --git a/generic/tkCanvText.c b/generic/tkCanvText.c
index 50fbebd..bc0fe74 100644
--- a/generic/tkCanvText.c
+++ b/generic/tkCanvText.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkCanvText.c,v 1.30 2008/10/30 23:18:59 nijtmans Exp $
+ * RCS: @(#) $Id: tkCanvText.c,v 1.31 2008/11/01 16:14:30 dkf Exp $
*/
#include <stdio.h>
@@ -337,10 +337,8 @@ TextCoords(
(Tcl_Obj ***) &objv) != TCL_OK) {
return TCL_ERROR;
} else if (objc != 2) {
- char buf[64 + TCL_INTEGER_SPACE];
-
- sprintf(buf, "wrong # coordinates: expected 2, got %d", objc);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "wrong # coordinates: expected 2, got %d", objc));
return TCL_ERROR;
}
}
@@ -352,10 +350,8 @@ TextCoords(
}
ComputeTextBbox(canvas, textPtr);
} else {
- char buf[64 + TCL_INTEGER_SPACE];
-
- sprintf(buf, "wrong # coordinates: expected 0 or 2, got %d", objc);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "wrong # coordinates: expected 0 or 2, got %d", objc));
return TCL_ERROR;
}
return TCL_OK;
@@ -492,7 +488,6 @@ ConfigureText(
}
textPtr->cursorOffGC = newGC;
-
/*
* If the text was changed, move the selection and insertion indices to
* keep them inside the item.
@@ -879,7 +874,7 @@ DisplayCanvText(
}
/*
- *--------------------------------------------------------------
+ *----------------------------------------------------------------------
*
* TextInsert --
*
@@ -892,7 +887,7 @@ DisplayCanvText(
* The text in the given item is modified. The cursor and selection
* positions are also modified to reflect the insertion.
*
- *--------------------------------------------------------------
+ *----------------------------------------------------------------------
*/
static void
@@ -924,7 +919,7 @@ TextInsert(
return;
}
- newStr = (char *) ckalloc((unsigned) textPtr->numBytes + byteCount + 1);
+ newStr = ckalloc((unsigned) textPtr->numBytes + byteCount + 1);
memcpy(newStr, text, (size_t) byteIndex);
strcpy(newStr + byteIndex, string);
strcpy(newStr + byteIndex + byteCount, text + byteIndex);
@@ -1005,7 +1000,7 @@ TextDeleteChars(
byteCount = Tcl_UtfAtIndex(text + byteIndex, charsRemoved)
- (text + byteIndex);
- newStr = (char *) ckalloc((unsigned) (textPtr->numBytes + 1 - byteCount));
+ newStr = ckalloc((unsigned) (textPtr->numBytes + 1 - byteCount));
memcpy(newStr, text, (size_t) byteIndex);
strcpy(newStr + byteIndex, text + byteIndex + byteCount);
@@ -1285,7 +1280,7 @@ GetTextIndex(
x + canvasPtr->scrollX1 - textPtr->leftEdge,
y + canvasPtr->scrollY1 - textPtr->header.y1);
} else if (Tcl_GetIntFromObj(NULL, obj, indexPtr) == TCL_OK) {
- if (*indexPtr < 0){
+ if (*indexPtr < 0) {
*indexPtr = 0;
} else if (*indexPtr > textPtr->numChars) {
*indexPtr = textPtr->numChars;
@@ -1297,8 +1292,7 @@ GetTextIndex(
*/
badIndex:
- Tcl_SetResult(interp, NULL, TCL_STATIC);
- Tcl_AppendResult(interp, "bad index \"", string, "\"", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad index \"%s\"", string));
return TCL_ERROR;
}
return TCL_OK;
diff --git a/generic/tkCanvas.c b/generic/tkCanvas.c
index efe8ac3..5b415bf 100644
--- a/generic/tkCanvas.c
+++ b/generic/tkCanvas.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkCanvas.c,v 1.54 2008/10/18 11:26:20 patthoyts Exp $
+ * RCS: @(#) $Id: tkCanvas.c,v 1.55 2008/11/01 16:14:30 dkf Exp $
*/
/* #define USE_OLD_TAG_SEARCH 1 */
@@ -268,8 +268,7 @@ static void CanvasUpdateScrollbars(TkCanvas *canvasPtr);
static int CanvasWidgetCmd(ClientData clientData,
Tcl_Interp *interp, int argc,
Tcl_Obj *const *argv);
-static void CanvasWorldChanged(
- ClientData instanceData);
+static void CanvasWorldChanged(ClientData instanceData);
static int ConfigureCanvas(Tcl_Interp *interp,
TkCanvas *canvasPtr, int argc,
Tcl_Obj *const *argv, int flags);
@@ -277,7 +276,7 @@ static void DestroyCanvas(char *memPtr);
static void DisplayCanvas(ClientData clientData);
static void DoItem(Tcl_Interp *interp,
Tk_Item *itemPtr, Tk_Uid tag);
-static void EventuallyRedrawItem(Tk_Canvas canvas,
+static void EventuallyRedrawItem(TkCanvas *canvasPtr,
Tk_Item *itemPtr);
#ifdef USE_OLD_TAG_SEARCH
static int FindItems(Tcl_Interp *interp, TkCanvas *canvasPtr,
@@ -341,6 +340,10 @@ static Tk_ClassProcs canvasClass = {
#define FOR_EVERY_CANVAS_ITEM_MATCHING(objPtr,searchPtrPtr,errorExitClause) \
for ((itemPtr) = StartTagSearch(canvasPtr, (objPtr), &search); \
(itemPtr) != NULL; (itemPtr) = NextItem(&search))
+#define FIND_ITEMS(objPtr, n) \
+ FindItems(interp, canvasPtr, objc, objv, (objPtr), (n))
+#define RELINK_ITEMS(objPtr, itemPtr) \
+ RelinkItems(canvasPtr, (objPtr), (itemPtr))
#else /* USE_OLD_TAG_SEARCH */
#define FIRST_CANVAS_ITEM_MATCHING(objPtr,searchPtrPtr,errorExitClause) \
if ((result=TagSearchScan(canvasPtr,(objPtr),(searchPtrPtr))) != TCL_OK){ \
@@ -353,8 +356,266 @@ static Tk_ClassProcs canvasClass = {
} \
for (itemPtr = TagSearchFirst(*(searchPtrPtr)); \
itemPtr != NULL; itemPtr = TagSearchNext(*(searchPtrPtr)))
+#define FIND_ITEMS(objPtr, n) \
+ FindItems(interp, canvasPtr, objc, objv, (objPtr), (n), &searchPtr)
+#define RELINK_ITEMS(objPtr, itemPtr) \
+ result = RelinkItems(canvasPtr, (objPtr), (itemPtr), &searchPtr)
#endif /* USE_OLD_TAG_SEARCH */
+
+/*
+ * ----------------------------------------------------------------------
+ *
+ * AlwaysRedraw, ItemConfigure, ItemCoords, etc. --
+ *
+ * Helper functions that make access to canvas item functions simpler.
+ * Note that these are all inline functions.
+ *
+ * ----------------------------------------------------------------------
+ */
+
+static inline int
+AlwaysRedraw(
+ Tk_Item *itemPtr)
+{
+ return itemPtr->typePtr->alwaysRedraw & 1;
+}
+
+static inline int
+ItemConfigure(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr,
+ int objc,
+ Tcl_Obj *const objv[])
+{
+ Tcl_Interp *interp = canvasPtr->interp;
+ int result;
+
+ if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
+ result = itemPtr->typePtr->configProc(interp, (Tk_Canvas) canvasPtr,
+ itemPtr, objc, objv, TK_CONFIG_ARGV_ONLY);
+ } else {
+ const char **args = TkGetStringsFromObjs(objc, objv);
+
+ result = itemPtr->typePtr->configProc(interp, (Tk_Canvas) canvasPtr,
+ itemPtr, objc, (Tcl_Obj **) args, TK_CONFIG_ARGV_ONLY);
+ if (args != NULL) {
+ ckfree((char *) args);
+ }
+ }
+ return result;
+}
+
+static inline int
+ItemConfigInfo(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr,
+ Tcl_Obj *fieldName)
+{
+ return Tk_ConfigureInfo(canvasPtr->interp, canvasPtr->tkwin,
+ itemPtr->typePtr->configSpecs, (char *) itemPtr,
+ (fieldName ? Tcl_GetString(fieldName) : NULL), 0);
+}
+
+static inline int
+ItemConfigValue(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr,
+ Tcl_Obj *fieldName)
+{
+ return Tk_ConfigureValue(canvasPtr->interp, canvasPtr->tkwin,
+ itemPtr->typePtr->configSpecs, (char *) itemPtr,
+ Tcl_GetString(fieldName), 0);
+}
+
+static inline int
+ItemCoords(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr,
+ int objc,
+ Tcl_Obj *const objv[])
+{
+ Tcl_Interp *interp = canvasPtr->interp;
+ int result;
+
+ if (itemPtr->typePtr->coordProc == NULL) {
+ result = TCL_OK;
+ } else if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
+ result = itemPtr->typePtr->coordProc(interp, (Tk_Canvas) canvasPtr,
+ itemPtr, objc, objv);
+ } else {
+ const char **args = TkGetStringsFromObjs(objc, objv);
+
+ result = itemPtr->typePtr->coordProc(interp, (Tk_Canvas) canvasPtr,
+ itemPtr, objc, (Tcl_Obj **) args);
+ if (args != NULL) {
+ ckfree((char *) args);
+ }
+ }
+ return result;
+}
+static inline int
+ItemCreate(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr, /* Warning: incomplete! typePtr field must be
+ * set by this point. */
+ int objc,
+ Tcl_Obj *const objv[])
+{
+ Tcl_Interp *interp = canvasPtr->interp;
+ int result;
+
+ if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
+ result = itemPtr->typePtr->createProc(interp, (Tk_Canvas) canvasPtr,
+ itemPtr, objc-3, objv+3);
+ } else {
+ const char **args = TkGetStringsFromObjs(objc-3, objv+3);
+
+ result = itemPtr->typePtr->createProc(interp, (Tk_Canvas) canvasPtr,
+ itemPtr, objc-3, (Tcl_Obj **) args);
+ if (args != NULL) {
+ ckfree((char *) args);
+ }
+ }
+ return result;
+}
+
+static inline void
+ItemCursor(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr,
+ int index)
+{
+ itemPtr->typePtr->icursorProc((Tk_Canvas) canvasPtr, itemPtr, index);
+}
+
+static inline void
+ItemDelChars(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr,
+ int first,
+ int last)
+{
+ itemPtr->typePtr->dCharsProc((Tk_Canvas) canvasPtr, itemPtr, first, last);
+}
+
+static inline void
+ItemDelete(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr)
+{
+ itemPtr->typePtr->deleteProc((Tk_Canvas) canvasPtr, itemPtr,
+ canvasPtr->display);
+}
+
+static inline void
+ItemDisplay(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr,
+ Pixmap pixmap,
+ int screenX1, int screenY1,
+ int width, int height)
+{
+ itemPtr->typePtr->displayProc((Tk_Canvas) canvasPtr, itemPtr,
+ canvasPtr->display, pixmap, screenX1, screenY1, width, height);
+}
+
+static inline int
+ItemIndex(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr,
+ Tcl_Obj *objPtr,
+ int *indexPtr)
+{
+ Tcl_Interp *interp = canvasPtr->interp;
+
+ if (itemPtr->typePtr->indexProc == NULL) {
+ return TCL_OK;
+ } else if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
+ return itemPtr->typePtr->indexProc(interp, (Tk_Canvas) canvasPtr,
+ itemPtr, (char *) objPtr, indexPtr);
+ } else {
+ return itemPtr->typePtr->indexProc(interp, (Tk_Canvas) canvasPtr,
+ itemPtr, Tcl_GetString(objPtr), indexPtr);
+ }
+}
+
+static inline void
+ItemInsert(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr,
+ int beforeThis,
+ Tcl_Obj *toInsert)
+{
+ if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
+ itemPtr->typePtr->insertProc((Tk_Canvas) canvasPtr, itemPtr,
+ beforeThis, (char *) toInsert);
+ } else {
+ itemPtr->typePtr->insertProc((Tk_Canvas) canvasPtr, itemPtr,
+ beforeThis, Tcl_GetString(toInsert));
+ }
+}
+
+static inline int
+ItemOverlap(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr,
+ double rect[])
+{
+ return itemPtr->typePtr->areaProc((Tk_Canvas) canvasPtr, itemPtr, rect);
+}
+
+static inline double
+ItemPoint(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr,
+ double coords[],
+ double halo)
+{
+ double dist;
+
+ dist = itemPtr->typePtr->pointProc((Tk_Canvas) canvasPtr, itemPtr,
+ coords) - halo;
+ return (dist < 0.0) ? 0.0 : dist;
+}
+
+static inline void
+ItemScale(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr,
+ double xOrigin, double yOrigin,
+ double xScale, double yScale)
+{
+ itemPtr->typePtr->scaleProc((Tk_Canvas) canvasPtr, itemPtr,
+ xOrigin, yOrigin, xScale, yScale);
+}
+
+static inline int
+ItemSelection(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr,
+ int offset,
+ char *buffer,
+ int maxBytes)
+{
+ if (itemPtr == NULL || itemPtr->typePtr->selectionProc == NULL) {
+ return -1;
+ }
+
+ return itemPtr->typePtr->selectionProc((Tk_Canvas) canvasPtr, itemPtr,
+ offset, buffer, maxBytes);
+}
+
+static inline void
+ItemTranslate(
+ TkCanvas *canvasPtr,
+ Tk_Item *itemPtr,
+ double xDelta,
+ double yDelta)
+{
+ itemPtr->typePtr->translateProc((Tk_Canvas) canvasPtr, itemPtr,
+ xDelta, yDelta);
+}
/*
*--------------------------------------------------------------
@@ -380,7 +641,7 @@ Tk_CanvasObjCmd(
int argc, /* Number of arguments. */
Tcl_Obj *const argv[]) /* Argument objects. */
{
- Tk_Window tkwin = (Tk_Window) clientData;
+ Tk_Window tkwin = clientData;
TkCanvas *canvasPtr;
Tk_Window newWin;
@@ -409,8 +670,8 @@ Tk_CanvasObjCmd(
canvasPtr->display = Tk_Display(newWin);
canvasPtr->interp = interp;
canvasPtr->widgetCmd = Tcl_CreateObjCommand(interp,
- Tk_PathName(canvasPtr->tkwin), CanvasWidgetCmd,
- (ClientData) canvasPtr, CanvasCmdDeletedProc);
+ Tk_PathName(canvasPtr->tkwin), CanvasWidgetCmd, canvasPtr,
+ CanvasCmdDeletedProc);
canvasPtr->firstItemPtr = NULL;
canvasPtr->lastItemPtr = NULL;
canvasPtr->borderWidth = 0;
@@ -483,21 +744,21 @@ Tk_CanvasObjCmd(
Tcl_InitHashTable(&canvasPtr->idTable, TCL_ONE_WORD_KEYS);
Tk_SetClass(canvasPtr->tkwin, "Canvas");
- Tk_SetClassProcs(canvasPtr->tkwin, &canvasClass, (ClientData) canvasPtr);
+ Tk_SetClassProcs(canvasPtr->tkwin, &canvasClass, canvasPtr);
Tk_CreateEventHandler(canvasPtr->tkwin,
ExposureMask|StructureNotifyMask|FocusChangeMask,
- CanvasEventProc, (ClientData) canvasPtr);
+ CanvasEventProc, canvasPtr);
Tk_CreateEventHandler(canvasPtr->tkwin, KeyPressMask|KeyReleaseMask
|ButtonPressMask|ButtonReleaseMask|EnterWindowMask
|LeaveWindowMask|PointerMotionMask|VirtualEventMask,
- CanvasBindProc, (ClientData) canvasPtr);
+ CanvasBindProc, canvasPtr);
Tk_CreateSelHandler(canvasPtr->tkwin, XA_PRIMARY, XA_STRING,
- CanvasFetchSelection, (ClientData) canvasPtr, XA_STRING);
+ CanvasFetchSelection, canvasPtr, XA_STRING);
if (ConfigureCanvas(interp, canvasPtr, argc-2, argv+2, 0) != TCL_OK) {
goto error;
}
- Tcl_SetResult(interp, Tk_PathName(canvasPtr->tkwin), TCL_STATIC);
+ Tcl_SetObjResult(interp, TkNewWindowObj(canvasPtr->tkwin));
return TCL_OK;
error:
@@ -547,10 +808,11 @@ CanvasWidgetCmd(
"canvasy", "cget", "configure", "coords",
"create", "dchars", "delete", "dtag",
"find", "focus", "gettags", "icursor",
- "index", "insert", "itemcget", "itemconfigure",
+ "imove", "index", "insert", "itemcget",
+ "itemconfigure",
"lower", "move", "moveto", "postscript",
- "raise", "scale", "scan", "select",
- "type", "xview", "yview",
+ "raise", "rchars", "scale", "scan",
+ "select", "type", "xview", "yview",
NULL
};
enum options {
@@ -558,10 +820,11 @@ CanvasWidgetCmd(
CANV_CANVASY, CANV_CGET, CANV_CONFIGURE, CANV_COORDS,
CANV_CREATE, CANV_DCHARS, CANV_DELETE, CANV_DTAG,
CANV_FIND, CANV_FOCUS, CANV_GETTAGS, CANV_ICURSOR,
- CANV_INDEX, CANV_INSERT, CANV_ITEMCGET, CANV_ITEMCONFIGURE,
+ CANV_IMOVE, CANV_INDEX, CANV_INSERT, CANV_ITEMCGET,
+ CANV_ITEMCONFIGURE,
CANV_LOWER, CANV_MOVE, CANV_MOVETO, CANV_POSTSCRIPT,
- CANV_RAISE, CANV_SCALE, CANV_SCAN, CANV_SELECT,
- CANV_TYPE, CANV_XVIEW, CANV_YVIEW
+ CANV_RAISE, CANV_RCHARS, CANV_SCALE, CANV_SCAN,
+ CANV_SELECT, CANV_TYPE, CANV_XVIEW, CANV_YVIEW
};
if (objc < 2) {
@@ -572,7 +835,7 @@ CanvasWidgetCmd(
&index) != TCL_OK) {
return TCL_ERROR;
}
- Tcl_Preserve((ClientData) canvasPtr);
+ Tcl_Preserve(canvasPtr);
result = TCL_OK;
switch ((enum options) index) {
@@ -582,12 +845,7 @@ CanvasWidgetCmd(
result = TCL_ERROR;
goto done;
}
-#ifdef USE_OLD_TAG_SEARCH
- result = FindItems(interp, canvasPtr, objc, objv, objv[2], 3);
-#else /* USE_OLD_TAG_SEARCH */
- result = FindItems(interp, canvasPtr, objc, objv, objv[2], 3,
- &searchPtr);
-#endif /* USE_OLD_TAG_SEARCH */
+ result = FIND_ITEMS(objv[2], 3);
break;
case CANV_BBOX: {
@@ -631,10 +889,13 @@ CanvasWidgetCmd(
}
}
if (gotAny) {
- char buf[TCL_INTEGER_SPACE * 4];
+ Tcl_Obj *resultObjs[4];
- sprintf(buf, "%d %d %d %d", x1, y1, x2, y2);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ resultObjs[0] = Tcl_NewIntObj(x1);
+ resultObjs[1] = Tcl_NewIntObj(y1);
+ resultObjs[2] = Tcl_NewIntObj(x2);
+ resultObjs[3] = Tcl_NewIntObj(y2);
+ Tcl_SetObjResult(interp, Tcl_NewListObj(4, resultObjs));
}
break;
}
@@ -665,8 +926,8 @@ CanvasWidgetCmd(
}
entryPtr = Tcl_FindHashEntry(&canvasPtr->idTable, (char *) id);
if (entryPtr != NULL) {
- itemPtr = (Tk_Item *) Tcl_GetHashValue(entryPtr);
- object = (ClientData) itemPtr;
+ itemPtr = Tcl_GetHashValue(entryPtr);
+ object = itemPtr;
}
if (object == 0) {
@@ -676,8 +937,8 @@ CanvasWidgetCmd(
goto done;
}
} else {
- bindByTag:
- object = (ClientData) Tk_GetUid(Tcl_GetString(objv[2]));
+ bindByTag:
+ object = Tk_GetUid(Tcl_GetString(objv[2]));
}
#else /* USE_OLD_TAG_SEARCH */
result = TagSearchScan(canvasPtr, objv[2], &searchPtr);
@@ -690,8 +951,8 @@ CanvasWidgetCmd(
entryPtr = Tcl_FindHashEntry(&canvasPtr->idTable,
(char *) INT2PTR(searchPtr->id));
if (entryPtr != NULL) {
- itemPtr = (Tk_Item *) Tcl_GetHashValue(entryPtr);
- object = (ClientData) itemPtr;
+ itemPtr = Tcl_GetHashValue(entryPtr);
+ object = itemPtr;
}
if (object == 0) {
@@ -716,7 +977,7 @@ CanvasWidgetCmd(
if (objc == 5) {
int append = 0;
unsigned long mask;
- char* argv4 = Tcl_GetString(objv[4]);
+ char *argv4 = Tcl_GetString(objv[4]);
if (argv4[0] == 0) {
result = Tk_DeleteBinding(interp, canvasPtr->bindingTable,
@@ -785,9 +1046,7 @@ CanvasWidgetCmd(
command = Tk_GetBinding(interp, canvasPtr->bindingTable,
object, Tcl_GetString(objv[3]));
if (command == NULL) {
- const char *string;
-
- string = Tcl_GetStringResult(interp);
+ const char *string = Tcl_GetStringResult(interp);
/*
* Ignore missing binding errors. This is a special hack that
@@ -798,11 +1057,10 @@ CanvasWidgetCmd(
if (string[0] != '\0') {
result = TCL_ERROR;
goto done;
- } else {
- Tcl_ResetResult(interp);
}
+ Tcl_ResetResult(interp);
} else {
- Tcl_SetResult(interp, (char *) command, TCL_STATIC);
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(command, -1));
}
} else {
Tk_GetAllBindings(interp, canvasPtr->bindingTable, object);
@@ -812,7 +1070,6 @@ CanvasWidgetCmd(
case CANV_CANVASX: {
int x;
double grid;
- char buf[TCL_DOUBLE_SPACE];
if ((objc < 3) || (objc > 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "screenx ?gridspacing?");
@@ -834,14 +1091,12 @@ CanvasWidgetCmd(
grid = 0.0;
}
x += canvasPtr->xOrigin;
- Tcl_PrintDouble(interp, GridAlign((double) x, grid), buf);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ Tcl_SetObjResult(interp, Tcl_NewDoubleObj(GridAlign((double)x,grid)));
break;
}
case CANV_CANVASY: {
int y;
double grid;
- char buf[TCL_DOUBLE_SPACE];
if ((objc < 3) || (objc > 4)) {
Tcl_WrongNumArgs(interp, 2, objv, "screeny ?gridspacing?");
@@ -863,8 +1118,7 @@ CanvasWidgetCmd(
grid = 0.0;
}
y += canvasPtr->yOrigin;
- Tcl_PrintDouble(interp, GridAlign((double) y, grid), buf);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ Tcl_SetObjResult(interp, Tcl_NewDoubleObj(GridAlign((double)y,grid)));
break;
}
case CANV_CGET:
@@ -897,33 +1151,88 @@ CanvasWidgetCmd(
FIRST_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done);
if (itemPtr != NULL) {
if (objc != 3) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
}
- if (itemPtr->typePtr->coordProc != NULL) {
- if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
- result = itemPtr->typePtr->coordProc(interp,
- (Tk_Canvas) canvasPtr, itemPtr, objc-3, objv+3);
- } else {
- const char **args = TkGetStringsFromObjs(objc-3, objv+3);
+ result = ItemCoords(canvasPtr, itemPtr, objc-3, objv+3);
+ if (objc != 3) {
+ EventuallyRedrawItem(canvasPtr, itemPtr);
+ }
+ }
+ break;
+ case CANV_IMOVE: {
+ double ignored;
+ Tcl_Obj *tmpObj;
- result = itemPtr->typePtr->coordProc(interp,
- (Tk_Canvas) canvasPtr, itemPtr, objc-3,
- (Tcl_Obj **) args);
- if (args != NULL) {
- ckfree((char *) args);
- }
- }
+ if (objc != 6) {
+ Tcl_WrongNumArgs(interp, 2, objv, "tagOrId index x y");
+ result = TCL_ERROR;
+ goto done;
+ }
+ if (Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr,
+ objv[4], &ignored) != TCL_OK
+ || Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr,
+ objv[5], &ignored) != TCL_OK) {
+ result = TCL_ERROR;
+ goto done;
+ }
+
+ /*
+ * Make a temporary object here that we can reuse for all the
+ * modifications in the loop.
+ */
+
+ tmpObj = Tcl_NewListObj(2, objv+4);
+
+ FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto doneImove) {
+ int index;
+ int x1,x2,y1,y2;
+
+ /*
+ * The TK_MOVABLE_POINTS flag should only be set for types that
+ * support the same semantics of index, dChars and insert methods
+ * as lines and canvases.
+ */
+
+ if (itemPtr == NULL ||
+ !(itemPtr->typePtr->alwaysRedraw & TK_MOVABLE_POINTS)) {
+ continue;
}
- if (objc != 3) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
+
+ result = ItemIndex(canvasPtr, itemPtr, objv[3], &index);
+ if (result != TCL_OK) {
+ break;
}
+
+ /*
+ * Redraw both item's old and new areas: it's possible that a
+ * replace could result in a new area larger than the old area.
+ * Except if the dCharsProc or insertProc sets the
+ * TK_ITEM_DONT_REDRAW flag, nothing more needs to be done.
+ */
+
+ x1 = itemPtr->x1; y1 = itemPtr->y1;
+ x2 = itemPtr->x2; y2 = itemPtr->y2;
+ itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
+
+ ItemDelChars(canvasPtr, itemPtr, index, index);
+ ItemInsert(canvasPtr, itemPtr, index, tmpObj);
+
+ if (!(itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW)) {
+ Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr,
+ x1, y1, x2, y2);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
+ }
+ itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
}
+
+ doneImove:
+ Tcl_DecrRefCount(tmpObj);
break;
+ }
case CANV_CREATE: {
Tk_ItemType *typePtr;
Tk_ItemType *matchPtr = NULL;
Tk_Item *itemPtr;
- char buf[TCL_INTEGER_SPACE];
int isNew = 0;
Tcl_HashEntry *entryPtr;
char *arg;
@@ -949,12 +1258,7 @@ CanvasWidgetCmd(
&& (!strncmp(arg, typePtr->name, (unsigned)length))) {
if (matchPtr != NULL) {
Tcl_MutexUnlock(&typeListMutex);
- badType:
- Tcl_AppendResult(interp,
- "unknown or ambiguous item type \"", arg, "\"",
- NULL);
- result = TCL_ERROR;
- goto done;
+ goto badType;
}
matchPtr = typePtr;
}
@@ -967,7 +1271,11 @@ CanvasWidgetCmd(
Tcl_MutexUnlock(&typeListMutex);
if (matchPtr == NULL) {
- goto badType;
+ badType:
+ Tcl_AppendResult(interp,
+ "unknown or ambiguous item type \"", arg, "\"", NULL);
+ result = TCL_ERROR;
+ goto done;
}
if (objc < 4) {
/*
@@ -978,6 +1286,7 @@ CanvasWidgetCmd(
result = TCL_ERROR;
goto done;
}
+
typePtr = matchPtr;
itemPtr = (Tk_Item *) ckalloc((unsigned) typePtr->itemSize);
itemPtr->id = canvasPtr->nextId;
@@ -988,23 +1297,13 @@ CanvasWidgetCmd(
itemPtr->typePtr = typePtr;
itemPtr->state = TK_STATE_NULL;
itemPtr->redraw_flags = 0;
- if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
- result = typePtr->createProc(interp, (Tk_Canvas) canvasPtr,
- itemPtr, objc-3, objv+3);
- } else {
- const char **args = TkGetStringsFromObjs(objc-3, objv+3);
- result = typePtr->createProc(interp, (Tk_Canvas) canvasPtr,
- itemPtr, objc-3, (Tcl_Obj **) args);
- if (args != NULL) {
- ckfree((char *) args);
- }
- }
- if (result != TCL_OK) {
+ if (ItemCreate(canvasPtr, itemPtr, objc, objv) != TCL_OK) {
ckfree((char *) itemPtr);
result = TCL_ERROR;
goto done;
}
+
itemPtr->nextPtr = NULL;
entryPtr = Tcl_CreateHashEntry(&canvasPtr->idTable,
(char *) INT2PTR(itemPtr->id), &isNew);
@@ -1019,10 +1318,9 @@ CanvasWidgetCmd(
}
canvasPtr->lastItemPtr = itemPtr;
itemPtr->redraw_flags |= FORCE_REDRAW;
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
canvasPtr->flags |= REPICK_NEEDED;
- sprintf(buf, "%d", itemPtr->id);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(itemPtr->id));
break;
}
case CANV_DCHARS: {
@@ -1039,28 +1337,12 @@ CanvasWidgetCmd(
|| (itemPtr->typePtr->dCharsProc == NULL)) {
continue;
}
- if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
- result = itemPtr->typePtr->indexProc(interp,
- (Tk_Canvas) canvasPtr, itemPtr, (char *) objv[3],
- &first);
- } else {
- result = itemPtr->typePtr->indexProc(interp,
- (Tk_Canvas) canvasPtr, itemPtr,
- Tcl_GetString(objv[3]), &first);
- }
+ result = ItemIndex(canvasPtr, itemPtr, objv[3], &first);
if (result != TCL_OK) {
goto done;
}
if (objc == 5) {
- if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
- result = itemPtr->typePtr->indexProc(interp,
- (Tk_Canvas) canvasPtr, itemPtr, (char *) objv[4],
- &last);
- } else {
- result = itemPtr->typePtr->indexProc(interp,
- (Tk_Canvas) canvasPtr, itemPtr,
- Tcl_GetString(objv[4]), &last);
- }
+ result = ItemIndex(canvasPtr, itemPtr, objv[4], &last);
if (result != TCL_OK) {
goto done;
}
@@ -1078,12 +1360,11 @@ CanvasWidgetCmd(
x1 = itemPtr->x1; y1 = itemPtr->y1;
x2 = itemPtr->x2; y2 = itemPtr->y2;
itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
- itemPtr->typePtr->dCharsProc((Tk_Canvas) canvasPtr, itemPtr,
- first, last);
+ ItemDelChars(canvasPtr, itemPtr, first, last);
if (!(itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW)) {
Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr,
x1, y1, x2, y2);
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
}
itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
}
@@ -1095,13 +1376,11 @@ CanvasWidgetCmd(
for (i = 2; i < objc; i++) {
FOR_EVERY_CANVAS_ITEM_MATCHING(objv[i], &searchPtr, goto done) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
if (canvasPtr->bindingTable != NULL) {
- Tk_DeleteAllBindings(canvasPtr->bindingTable,
- (ClientData) itemPtr);
+ Tk_DeleteAllBindings(canvasPtr->bindingTable, itemPtr);
}
- itemPtr->typePtr->deleteProc((Tk_Canvas) canvasPtr, itemPtr,
- canvasPtr->display);
+ ItemDelete(canvasPtr, itemPtr);
if (itemPtr->tagPtr != itemPtr->staticTagSpace) {
ckfree((char *) itemPtr->tagPtr);
}
@@ -1176,12 +1455,7 @@ CanvasWidgetCmd(
result = TCL_ERROR;
goto done;
}
-#ifdef USE_OLD_TAG_SEARCH
- result = FindItems(interp, canvasPtr, objc, objv, NULL, 2);
-#else /* USE_OLD_TAG_SEARCH */
- result = FindItems(interp, canvasPtr, objc, objv, NULL, 2,
- &searchPtr);
-#endif /* USE_OLD_TAG_SEARCH */
+ result = FIND_ITEMS(NULL, 2);
break;
case CANV_FOCUS:
if (objc > 3) {
@@ -1192,15 +1466,12 @@ CanvasWidgetCmd(
itemPtr = canvasPtr->textInfo.focusItemPtr;
if (objc == 2) {
if (itemPtr != NULL) {
- char buf[TCL_INTEGER_SPACE];
-
- sprintf(buf, "%d", itemPtr->id);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(itemPtr->id));
}
goto done;
}
- if ((itemPtr != NULL) && (canvasPtr->textInfo.gotFocus)) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
+ if (canvasPtr->textInfo.gotFocus) {
+ EventuallyRedrawItem(canvasPtr, itemPtr);
}
if (Tcl_GetString(objv[2])[0] == 0) {
canvasPtr->textInfo.focusItemPtr = NULL;
@@ -1216,7 +1487,7 @@ CanvasWidgetCmd(
}
canvasPtr->textInfo.focusItemPtr = itemPtr;
if (canvasPtr->textInfo.gotFocus) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
}
break;
case CANV_GETTAGS:
@@ -1246,30 +1517,20 @@ CanvasWidgetCmd(
|| (itemPtr->typePtr->icursorProc == NULL)) {
goto done;
}
- if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
- result = itemPtr->typePtr->indexProc(interp,
- (Tk_Canvas) canvasPtr, itemPtr, (char *) objv[3],
- &index);
- } else {
- result = itemPtr->typePtr->indexProc(interp,
- (Tk_Canvas) canvasPtr, itemPtr,
- Tcl_GetString(objv[3]), &index);
- }
+ result = ItemIndex(canvasPtr, itemPtr, objv[3], &index);
if (result != TCL_OK) {
goto done;
}
- itemPtr->typePtr->icursorProc((Tk_Canvas) canvasPtr, itemPtr,
- index);
+ ItemCursor(canvasPtr, itemPtr, index);
if ((itemPtr == canvasPtr->textInfo.focusItemPtr)
&& (canvasPtr->textInfo.cursorOn)) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
}
}
break;
}
case CANV_INDEX: {
int index;
- char buf[TCL_INTEGER_SPACE];
if (objc != 4) {
Tcl_WrongNumArgs(interp, 2, objv, "tagOrId string");
@@ -1287,18 +1548,11 @@ CanvasWidgetCmd(
result = TCL_ERROR;
goto done;
}
- if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
- result = itemPtr->typePtr->indexProc(interp, (Tk_Canvas)canvasPtr,
- itemPtr, (char *) objv[3], &index);
- } else {
- result = itemPtr->typePtr->indexProc(interp, (Tk_Canvas)canvasPtr,
- itemPtr, Tcl_GetString(objv[3]), &index);
- }
+ result = ItemIndex(canvasPtr, itemPtr, objv[3], &index);
if (result != TCL_OK) {
goto done;
}
- sprintf(buf, "%d", index);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(index));
break;
}
case CANV_INSERT: {
@@ -1315,15 +1569,7 @@ CanvasWidgetCmd(
|| (itemPtr->typePtr->insertProc == NULL)) {
continue;
}
- if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
- result = itemPtr->typePtr->indexProc(interp,
- (Tk_Canvas) canvasPtr, itemPtr, (char *) objv[3],
- &beforeThis);
- } else {
- result = itemPtr->typePtr->indexProc(interp,
- (Tk_Canvas) canvasPtr, itemPtr,
- Tcl_GetString(objv[3]), &beforeThis);
- }
+ result = ItemIndex(canvasPtr, itemPtr, objv[3], &beforeThis);
if (result != TCL_OK) {
goto done;
}
@@ -1338,17 +1584,11 @@ CanvasWidgetCmd(
x1 = itemPtr->x1; y1 = itemPtr->y1;
x2 = itemPtr->x2; y2 = itemPtr->y2;
itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
- if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
- itemPtr->typePtr->insertProc((Tk_Canvas) canvasPtr, itemPtr,
- beforeThis, (char *) objv[4]);
- } else {
- itemPtr->typePtr->insertProc((Tk_Canvas) canvasPtr, itemPtr,
- beforeThis, Tcl_GetString(objv[4]));
- }
+ ItemInsert(canvasPtr, itemPtr, beforeThis, objv[4]);
if (!(itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW)) {
Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr,
x1, y1, x2, y2);
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
}
itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
}
@@ -1362,9 +1602,7 @@ CanvasWidgetCmd(
}
FIRST_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done);
if (itemPtr != NULL) {
- result = Tk_ConfigureValue(canvasPtr->interp, canvasPtr->tkwin,
- itemPtr->typePtr->configSpecs, (char *) itemPtr,
- Tcl_GetString(objv[3]), 0);
+ result = ItemConfigValue(canvasPtr, itemPtr, objv[3]);
}
break;
case CANV_ITEMCONFIGURE:
@@ -1375,30 +1613,13 @@ CanvasWidgetCmd(
}
FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) {
if (objc == 3) {
- result = Tk_ConfigureInfo(canvasPtr->interp, canvasPtr->tkwin,
- itemPtr->typePtr->configSpecs, (char *) itemPtr,
- NULL, 0);
+ result = ItemConfigInfo(canvasPtr, itemPtr, NULL);
} else if (objc == 4) {
- result = Tk_ConfigureInfo(canvasPtr->interp, canvasPtr->tkwin,
- itemPtr->typePtr->configSpecs, (char *) itemPtr,
- Tcl_GetString(objv[3]), 0);
+ result = ItemConfigInfo(canvasPtr, itemPtr, objv[3]);
} else {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
- if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
- result = itemPtr->typePtr->configProc(interp,
- (Tk_Canvas) canvasPtr, itemPtr, objc-3, objv+3,
- TK_CONFIG_ARGV_ONLY);
- } else {
- const char **args = TkGetStringsFromObjs(objc-3, objv+3);
-
- result = itemPtr->typePtr->configProc(interp,
- (Tk_Canvas) canvasPtr, itemPtr, objc-3,
- (Tcl_Obj **) args, TK_CONFIG_ARGV_ONLY);
- if (args != NULL) {
- ckfree((char *) args);
- }
- }
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
+ result = ItemConfigure(canvasPtr, itemPtr, objc-3, objv+3);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
canvasPtr->flags |= REPICK_NEEDED;
}
if ((result != TCL_OK) || (objc < 5)) {
@@ -1430,11 +1651,7 @@ CanvasWidgetCmd(
}
itemPtr = itemPtr->prevPtr;
}
-#ifdef USE_OLD_TAG_SEARCH
- RelinkItems(canvasPtr, objv[2], itemPtr);
-#else /* USE_OLD_TAG_SEARCH */
- result = RelinkItems(canvasPtr, objv[2], itemPtr, &searchPtr);
-#endif /* USE_OLD_TAG_SEARCH */
+ RELINK_ITEMS(objv[2], itemPtr);
break;
}
case CANV_MOVE: {
@@ -1452,10 +1669,9 @@ CanvasWidgetCmd(
goto done;
}
FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
- itemPtr->typePtr->translateProc((Tk_Canvas) canvasPtr, itemPtr,
- xAmount, yAmount);
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
+ ItemTranslate(canvasPtr, itemPtr, xAmount, yAmount);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
canvasPtr->flags |= REPICK_NEEDED;
}
break;
@@ -1515,10 +1731,9 @@ CanvasWidgetCmd(
*/
FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
- itemPtr->typePtr->translateProc((Tk_Canvas) canvasPtr,
- itemPtr, xAmount, yAmount);
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
+ ItemTranslate(canvasPtr, itemPtr, xAmount, yAmount);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
canvasPtr->flags |= REPICK_NEEDED;
}
}
@@ -1560,11 +1775,54 @@ CanvasWidgetCmd(
goto done;
}
}
-#ifdef USE_OLD_TAG_SEARCH
- RelinkItems(canvasPtr, objv[2], prevPtr);
-#else /* USE_OLD_TAG_SEARCH */
- result = RelinkItems(canvasPtr, objv[2], prevPtr, &searchPtr);
-#endif /* USE_OLD_TAG_SEARCH */
+ RELINK_ITEMS(objv[2], prevPtr);
+ break;
+ }
+ case CANV_RCHARS: {
+ int first, last;
+ int x1,x2,y1,y2;
+
+ if (objc != 6) {
+ Tcl_WrongNumArgs(interp, 2, objv, "tagOrId first last string");
+ result = TCL_ERROR;
+ goto done;
+ }
+ FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) {
+ if ((itemPtr->typePtr->indexProc == NULL)
+ || (itemPtr->typePtr->dCharsProc == NULL)
+ || (itemPtr->typePtr->insertProc == NULL)) {
+ continue;
+ }
+ result = ItemIndex(canvasPtr, itemPtr, objv[3], &first);
+ if (result != TCL_OK) {
+ goto done;
+ }
+ result = ItemIndex(canvasPtr, itemPtr, objv[4], &last);
+ if (result != TCL_OK) {
+ goto done;
+ }
+
+ /*
+ * Redraw both item's old and new areas: it's possible that a
+ * replace could result in a new area larger than the old area.
+ * Except if the dCharsProc or insertProc sets the
+ * TK_ITEM_DONT_REDRAW flag, nothing more needs to be done.
+ */
+
+ x1 = itemPtr->x1; y1 = itemPtr->y1;
+ x2 = itemPtr->x2; y2 = itemPtr->y2;
+ itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
+
+ ItemDelChars(canvasPtr, itemPtr, first, last);
+ ItemInsert(canvasPtr, itemPtr, first, objv[5]);
+
+ if (!(itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW)) {
+ Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr,
+ x1, y1, x2, y2);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
+ }
+ itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW;
+ }
break;
}
case CANV_SCALE: {
@@ -1591,10 +1849,9 @@ CanvasWidgetCmd(
goto done;
}
FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
- itemPtr->typePtr->scaleProc((Tk_Canvas) canvasPtr, itemPtr,
- xOrigin, yOrigin, xScale, yScale);
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
+ ItemScale(canvasPtr, itemPtr, xOrigin, yOrigin, xScale, yScale);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
canvasPtr->flags |= REPICK_NEEDED;
}
break;
@@ -1673,15 +1930,7 @@ CanvasWidgetCmd(
}
}
if (objc == 5) {
- if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) {
- result = itemPtr->typePtr->indexProc(interp,
- (Tk_Canvas) canvasPtr, itemPtr, (char *) objv[4],
- &index);
- } else {
- result = itemPtr->typePtr->indexProc(interp,
- (Tk_Canvas) canvasPtr, itemPtr,
- Tcl_GetString(objv[4]), &index);
- }
+ result = ItemIndex(canvasPtr, itemPtr, objv[4], &index);
if (result != TCL_OK) {
goto done;
}
@@ -1716,12 +1965,8 @@ CanvasWidgetCmd(
result = TCL_ERROR;
goto done;
}
- if (canvasPtr->textInfo.selItemPtr != NULL) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr,
- canvasPtr->textInfo.selItemPtr);
- canvasPtr->textInfo.selItemPtr = NULL;
- }
- goto done;
+ EventuallyRedrawItem(canvasPtr, canvasPtr->textInfo.selItemPtr);
+ canvasPtr->textInfo.selItemPtr = NULL;
break;
case CANV_FROM:
if (objc != 5) {
@@ -1763,7 +2008,7 @@ CanvasWidgetCmd(
FIRST_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done);
if (itemPtr != NULL) {
Tcl_SetObjResult(interp,
- Tcl_NewStringObj(itemPtr->typePtr->name, -1));
+ Tcl_NewStringObj(itemPtr->typePtr->name, -1));
}
break;
case CANV_XVIEW: {
@@ -1867,7 +2112,7 @@ CanvasWidgetCmd(
#ifndef USE_OLD_TAG_SEARCH
TagSearchDestroy(searchPtr);
#endif /* not USE_OLD_TAG_SEARCH */
- Tcl_Release((ClientData) canvasPtr);
+ Tcl_Release(canvasPtr);
return result;
}
@@ -1906,8 +2151,7 @@ DestroyCanvas(
for (itemPtr = canvasPtr->firstItemPtr; itemPtr != NULL;
itemPtr = canvasPtr->firstItemPtr) {
canvasPtr->firstItemPtr = itemPtr->nextPtr;
- itemPtr->typePtr->deleteProc((Tk_Canvas) canvasPtr, itemPtr,
- canvasPtr->display);
+ ItemDelete(canvasPtr, itemPtr);
if (itemPtr->tagPtr != itemPtr->staticTagSpace) {
ckfree((char *) itemPtr->tagPtr);
}
@@ -2035,7 +2279,7 @@ ConfigureCanvas(
if (argc2 != 4) {
Tcl_AppendResult(interp, "bad scrollRegion \"",
canvasPtr->regionString, "\"", NULL);
- badRegion:
+ badRegion:
ckfree(canvasPtr->regionString);
ckfree((char *) argv2);
canvasPtr->regionString = NULL;
@@ -2085,7 +2329,7 @@ ConfigureCanvas(
}
/*
- *---------------------------------------------------------------------------
+ *----------------------------------------------------------------------
*
* CanvasWorldChanged --
*
@@ -2101,23 +2345,19 @@ ConfigureCanvas(
* side effect of causing all the items to recompute their geometry and
* to be redisplayed.
*
- *---------------------------------------------------------------------------
+ *----------------------------------------------------------------------
*/
static void
CanvasWorldChanged(
ClientData instanceData) /* Information about widget. */
{
- TkCanvas *canvasPtr = (TkCanvas *) instanceData;
+ TkCanvas *canvasPtr = instanceData;
Tk_Item *itemPtr;
- int result;
itemPtr = canvasPtr->firstItemPtr;
for ( ; itemPtr != NULL; itemPtr = itemPtr->nextPtr) {
- result = itemPtr->typePtr->configProc(canvasPtr->interp,
- (Tk_Canvas) canvasPtr, itemPtr, 0, NULL,
- TK_CONFIG_ARGV_ONLY);
- if (result != TCL_OK) {
+ if (ItemConfigure(canvasPtr, itemPtr, 0, NULL) != TCL_OK) {
Tcl_ResetResult(canvasPtr->interp);
}
}
@@ -2129,7 +2369,7 @@ CanvasWorldChanged(
}
/*
- *--------------------------------------------------------------
+ *----------------------------------------------------------------------
*
* DisplayCanvas --
*
@@ -2143,7 +2383,7 @@ CanvasWorldChanged(
* Side effects:
* Information appears on the screen.
*
- *--------------------------------------------------------------
+ *----------------------------------------------------------------------
*/
static void
@@ -2170,11 +2410,11 @@ DisplayCanvas(
*/
while (canvasPtr->flags & REPICK_NEEDED) {
- Tcl_Preserve((ClientData) canvasPtr);
+ Tcl_Preserve(canvasPtr);
canvasPtr->flags &= ~REPICK_NEEDED;
PickCurrentItem(canvasPtr, &canvasPtr->pickEvent);
tkwin = canvasPtr->tkwin;
- Tcl_Release((ClientData) canvasPtr);
+ Tcl_Release(canvasPtr);
if (tkwin == NULL) {
return;
}
@@ -2187,13 +2427,14 @@ DisplayCanvas(
*/
for (itemPtr = canvasPtr->firstItemPtr; itemPtr != NULL;
- itemPtr = itemPtr->nextPtr) {
+ itemPtr = itemPtr->nextPtr) {
if (itemPtr->redraw_flags & FORCE_REDRAW) {
itemPtr->redraw_flags &= ~FORCE_REDRAW;
- EventuallyRedrawItem((Tk_Canvas)canvasPtr, itemPtr);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
itemPtr->redraw_flags &= ~FORCE_REDRAW;
}
}
+
/*
* Compute the intersection between the area that needs redrawing and the
* area that's visible on the screen.
@@ -2291,7 +2532,7 @@ DisplayCanvas(
|| (itemPtr->y1 >= screenY2)
|| (itemPtr->x2 < screenX1)
|| (itemPtr->y2 < screenY1)) {
- if (!(itemPtr->typePtr->alwaysRedraw & 1)
+ if (!AlwaysRedraw(itemPtr)
|| (itemPtr->x1 >= canvasPtr->redrawX2)
|| (itemPtr->y1 >= canvasPtr->redrawY2)
|| (itemPtr->x2 < canvasPtr->redrawX1)
@@ -2300,12 +2541,11 @@ DisplayCanvas(
}
}
if (itemPtr->state == TK_STATE_HIDDEN ||
- (itemPtr->state == TK_STATE_NULL &&
- canvasPtr->canvas_state == TK_STATE_HIDDEN)) {
+ (itemPtr->state == TK_STATE_NULL &&
+ canvasPtr->canvas_state == TK_STATE_HIDDEN)) {
continue;
}
- itemPtr->typePtr->displayProc((Tk_Canvas) canvasPtr, itemPtr,
- canvasPtr->display, pixmap, screenX1, screenY1, width,
+ ItemDisplay(canvasPtr, itemPtr, pixmap, screenX1, screenY1, width,
height);
}
@@ -2369,7 +2609,7 @@ DisplayCanvas(
}
/*
- *--------------------------------------------------------------
+ *----------------------------------------------------------------------
*
* CanvasEventProc --
*
@@ -2380,10 +2620,10 @@ DisplayCanvas(
* None.
*
* Side effects:
- * When the window gets deleted, internal structures get cleaned up.
- * When it gets exposed, it is redisplayed.
+ * When the window gets deleted, internal structures get cleaned up. When
+ * it gets exposed, it is redisplayed.
*
- *--------------------------------------------------------------
+ *----------------------------------------------------------------------
*/
static void
@@ -2416,10 +2656,9 @@ CanvasEventProc(
canvasPtr->widgetCmd);
}
if (canvasPtr->flags & REDRAW_PENDING) {
- Tcl_CancelIdleCall(DisplayCanvas, (ClientData) canvasPtr);
+ Tcl_CancelIdleCall(DisplayCanvas, canvasPtr);
}
- Tcl_EventuallyFree((ClientData) canvasPtr,
- (Tcl_FreeProc *) DestroyCanvas);
+ Tcl_EventuallyFree(canvasPtr, (Tcl_FreeProc *) DestroyCanvas);
} else if (eventPtr->type == ConfigureNotify) {
canvasPtr->flags |= UPDATE_SCROLLBARS;
@@ -2453,9 +2692,8 @@ CanvasEventProc(
for (itemPtr = canvasPtr->firstItemPtr; itemPtr != NULL;
itemPtr = itemPtr->nextPtr) {
- if (itemPtr->typePtr->alwaysRedraw & 1) {
- itemPtr->typePtr->displayProc((Tk_Canvas) canvasPtr, itemPtr,
- canvasPtr->display, None, 0, 0, 0, 0);
+ if (AlwaysRedraw(itemPtr)) {
+ ItemDisplay(canvasPtr, itemPtr, None, 0, 0, 0, 0);
}
}
}
@@ -2500,7 +2738,7 @@ CanvasCmdDeletedProc(
}
/*
- *--------------------------------------------------------------
+ *----------------------------------------------------------------------
*
* Tk_CanvasEventuallyRedraw --
*
@@ -2513,7 +2751,7 @@ CanvasCmdDeletedProc(
* Side effects:
* The screen will eventually be refreshed.
*
- *--------------------------------------------------------------
+ *----------------------------------------------------------------------
*/
void
@@ -2562,13 +2800,13 @@ Tk_CanvasEventuallyRedraw(
canvasPtr->flags |= BBOX_NOT_EMPTY;
}
if (!(canvasPtr->flags & REDRAW_PENDING)) {
- Tcl_DoWhenIdle(DisplayCanvas, (ClientData) canvasPtr);
+ Tcl_DoWhenIdle(DisplayCanvas, canvasPtr);
canvasPtr->flags |= REDRAW_PENDING;
}
}
/*
- *--------------------------------------------------------------
+ *----------------------------------------------------------------------
*
* EventuallyRedrawItem --
*
@@ -2581,22 +2819,24 @@ Tk_CanvasEventuallyRedraw(
* Side effects:
* The screen will eventually be refreshed.
*
- *--------------------------------------------------------------
+ *----------------------------------------------------------------------
*/
static void
EventuallyRedrawItem(
- Tk_Canvas canvas, /* Information about widget. */
- Tk_Item *itemPtr) /* Item to be redrawn. */
+ TkCanvas *canvasPtr, /* Information about widget. */
+ Tk_Item *itemPtr) /* Item to be redrawn. May be NULL, in which
+ * case nothing happens. */
{
- TkCanvas *canvasPtr = Canvas(canvas);
-
+ if (itemPtr == NULL) {
+ return;
+ }
if ((itemPtr->x1 >= itemPtr->x2) || (itemPtr->y1 >= itemPtr->y2) ||
(itemPtr->x2 < canvasPtr->xOrigin) ||
(itemPtr->y2 < canvasPtr->yOrigin) ||
(itemPtr->x1 >= canvasPtr->xOrigin+Tk_Width(canvasPtr->tkwin)) ||
(itemPtr->y1 >= canvasPtr->yOrigin+Tk_Height(canvasPtr->tkwin))) {
- if (!(itemPtr->typePtr->alwaysRedraw & 1)) {
+ if (!AlwaysRedraw(itemPtr)) {
return;
}
}
@@ -2624,13 +2864,13 @@ EventuallyRedrawItem(
itemPtr->redraw_flags |= FORCE_REDRAW;
}
if (!(canvasPtr->flags & REDRAW_PENDING)) {
- Tcl_DoWhenIdle(DisplayCanvas, (ClientData) canvasPtr);
+ Tcl_DoWhenIdle(DisplayCanvas, canvasPtr);
canvasPtr->flags |= REDRAW_PENDING;
}
}
/*
- *--------------------------------------------------------------
+ *----------------------------------------------------------------------
*
* Tk_CreateItemType --
*
@@ -2646,7 +2886,7 @@ EventuallyRedrawItem(
* commands). If there was already a type with the same name as in
* typePtr, it is replaced with the new type.
*
- *--------------------------------------------------------------
+ *----------------------------------------------------------------------
*/
void
@@ -2786,11 +3026,8 @@ StartTagSearch(
Tk_Uid uid;
char *tag = Tcl_GetString(tagObj);
int count;
- TkWindow *tkwin;
- TkDisplay *dispPtr;
-
- tkwin = (TkWindow *) canvasPtr->tkwin;
- dispPtr = tkwin->dispPtr;
+ TkWindow *tkwin = (TkWindow *) canvasPtr->tkwin;
+ TkDisplay *dispPtr = tkwin->dispPtr;
/*
* Initialize the search.
@@ -2820,7 +3057,7 @@ StartTagSearch(
dispPtr->numSlowSearches++;
entryPtr = Tcl_FindHashEntry(&canvasPtr->idTable, (char*) id);
if (entryPtr != NULL) {
- itemPtr = (Tk_Item *)Tcl_GetHashValue(entryPtr);
+ itemPtr = Tcl_GetHashValue(entryPtr);
lastPtr = itemPtr->prevPtr;
} else {
lastPtr = itemPtr = NULL;
@@ -3012,9 +3249,9 @@ static void
TagSearchExprInit(
TagSearchExpr **exprPtrPtr)
{
- TagSearchExpr* expr = *exprPtrPtr;
+ TagSearchExpr *expr = *exprPtrPtr;
- if (! expr) {
+ if (expr == NULL) {
expr = (TagSearchExpr *) ckalloc(sizeof(TagSearchExpr));
expr->allocated = 0;
expr->uids = NULL;
@@ -3044,11 +3281,11 @@ static void
TagSearchExprDestroy(
TagSearchExpr *expr)
{
- if (expr) {
+ if (expr != NULL) {
if (expr->uids) {
- ckfree((char *)expr->uids);
+ ckfree((char *) expr->uids);
}
- ckfree((char *)expr);
+ ckfree((char *) expr);
}
}
@@ -3089,7 +3326,7 @@ TagSearchScan(
* Initialize the search.
*/
- if (*searchPtrPtr) {
+ if (*searchPtrPtr != NULL) {
searchPtr = *searchPtrPtr;
} else {
/*
@@ -3106,7 +3343,7 @@ TagSearchScan(
searchPtr->rewritebufferAllocated = 100;
searchPtr->rewritebuffer = ckalloc(searchPtr->rewritebufferAllocated);
}
- TagSearchExprInit(&(searchPtr->expr));
+ TagSearchExprInit(&searchPtr->expr);
/*
* How long is the tagOrId?
@@ -3118,7 +3355,7 @@ TagSearchScan(
* Make sure there is enough buffer to hold rewritten tags.
*/
- if ((unsigned int)searchPtr->stringLength >=
+ if ((unsigned) searchPtr->stringLength >=
searchPtr->rewritebufferAllocated) {
searchPtr->rewritebufferAllocated = searchPtr->stringLength + 100;
searchPtr->rewritebuffer =
@@ -3250,8 +3487,8 @@ TagSearchDestroy(
{
if (searchPtr) {
TagSearchExprDestroy(searchPtr->expr);
- ckfree((char *)searchPtr->rewritebuffer);
- ckfree((char *)searchPtr);
+ ckfree((char *) searchPtr->rewritebuffer);
+ ckfree((char *) searchPtr);
}
}
@@ -3596,7 +3833,7 @@ TagSearchEvalExpr(
negate_result = 0;
}
looking_for_tag = 0;
- } else { /* ! looking_for_tag */
+ } else { /* ! looking_for_tag */
if (((uid == searchUids->andUid) && (!result)) ||
((uid == searchUids->orUid) && result)) {
/*
@@ -3702,7 +3939,7 @@ TagSearchFirst(
entryPtr = Tcl_FindHashEntry(&searchPtr->canvasPtr->idTable,
(char *) INT2PTR(searchPtr->id));
if (entryPtr != NULL) {
- itemPtr = (Tk_Item *)Tcl_GetHashValue(entryPtr);
+ itemPtr = Tcl_GetHashValue(entryPtr);
lastPtr = itemPtr->prevPtr;
} else {
lastPtr = itemPtr = NULL;
@@ -3925,8 +4162,8 @@ DoItem(
itemPtr->tagSpace += 5;
newTagPtr = (Tk_Uid *)
- ckalloc((unsigned) (itemPtr->tagSpace * sizeof(Tk_Uid)));
- memcpy((void *) newTagPtr, itemPtr->tagPtr,
+ ckalloc((unsigned) itemPtr->tagSpace * sizeof(Tk_Uid));
+ memcpy(newTagPtr, itemPtr->tagPtr,
itemPtr->numTags * sizeof(Tk_Uid));
if (itemPtr->tagPtr != itemPtr->staticTagSpace) {
ckfree((char *) itemPtr->tagPtr);
@@ -4113,11 +4350,7 @@ FindItems(
if (itemPtr == NULL) {
return TCL_OK;
}
- closestDist = itemPtr->typePtr->pointProc((Tk_Canvas) canvasPtr,
- itemPtr, coords) - halo;
- if (closestDist < 0.0) {
- closestDist = 0.0;
- }
+ closestDist = ItemPoint(canvasPtr, itemPtr, coords, halo);
while (1) {
double newDist;
@@ -4156,11 +4389,7 @@ FindItems(
|| (itemPtr->y1 >= y2) || (itemPtr->y2 <= y1)) {
continue;
}
- newDist = itemPtr->typePtr->pointProc((Tk_Canvas) canvasPtr,
- itemPtr, coords) - halo;
- if (newDist < 0.0) {
- newDist = 0.0;
- }
+ newDist = ItemPoint(canvasPtr, itemPtr, coords, halo);
if (newDist <= closestDist) {
closestDist = newDist;
break;
@@ -4272,8 +4501,7 @@ FindArea(
|| (itemPtr->y1 >= y2) || (itemPtr->y2 <= y1)) {
continue;
}
- if (itemPtr->typePtr->areaProc((Tk_Canvas) canvasPtr, itemPtr, rect)
- >= enclosed) {
+ if (ItemOverlap(canvasPtr, itemPtr, rect) >= enclosed) {
DoItem(interp, itemPtr, uid);
}
}
@@ -4365,7 +4593,7 @@ RelinkItems(
lastMovePtr->nextPtr = itemPtr;
}
lastMovePtr = itemPtr;
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
canvasPtr->flags |= REPICK_NEEDED;
}
@@ -4429,6 +4657,7 @@ CanvasBindProc(
XEvent *eventPtr) /* Pointer to X event that just happened. */
{
TkCanvas *canvasPtr = clientData;
+ int mask;
Tcl_Preserve(canvasPtr);
@@ -4438,9 +4667,9 @@ CanvasBindProc(
* current item while buttons are down.
*/
- if (eventPtr->type == ButtonPress || eventPtr->type == ButtonRelease) {
- int mask;
-
+ switch (eventPtr->type) {
+ case ButtonPress:
+ case ButtonRelease:
switch (eventPtr->xbutton.button) {
case Button1:
mask = Button1Mask;
@@ -4494,19 +4723,20 @@ CanvasBindProc(
PickCurrentItem(canvasPtr, eventPtr);
eventPtr->xbutton.state ^= mask;
}
- goto done;
- } else if ((eventPtr->type == EnterNotify)
- || (eventPtr->type == LeaveNotify)) {
+ break;
+ case EnterNotify:
+ case LeaveNotify:
canvasPtr->state = eventPtr->xcrossing.state;
PickCurrentItem(canvasPtr, eventPtr);
- goto done;
- } else if (eventPtr->type == MotionNotify) {
+ break;
+ case MotionNotify:
canvasPtr->state = eventPtr->xmotion.state;
PickCurrentItem(canvasPtr, eventPtr);
+ /* fallthrough */
+ default:
+ CanvasDoEvent(canvasPtr, eventPtr);
}
- CanvasDoEvent(canvasPtr, eventPtr);
- done:
Tcl_Release(canvasPtr);
}
@@ -4704,10 +4934,8 @@ PickCurrentItem(
canvasPtr->currentItemPtr = canvasPtr->newCurrentPtr;
if (prevItemPtr != NULL && prevItemPtr != canvasPtr->currentItemPtr &&
(prevItemPtr->redraw_flags & TK_ITEM_STATE_DEPENDANT)) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, prevItemPtr);
- prevItemPtr->typePtr->configProc(canvasPtr->interp,
- (Tk_Canvas) canvasPtr, prevItemPtr, 0, NULL,
- TK_CONFIG_ARGV_ONLY);
+ EventuallyRedrawItem(canvasPtr, prevItemPtr);
+ ItemConfigure(canvasPtr, prevItemPtr, 0, NULL);
}
if (canvasPtr->currentItemPtr != NULL) {
XEvent event;
@@ -4716,14 +4944,11 @@ PickCurrentItem(
DoItem(NULL, canvasPtr->currentItemPtr, Tk_GetUid("current"));
#else /* USE_OLD_TAG_SEARCH */
DoItem(NULL, canvasPtr->currentItemPtr, searchUids->currentUid);
-#endif /* USE_OLD_TAG_SEA */
+#endif /* USE_OLD_TAG_SEARCH */
if ((canvasPtr->currentItemPtr->redraw_flags & TK_ITEM_STATE_DEPENDANT
&& prevItemPtr != canvasPtr->currentItemPtr)) {
- canvasPtr->currentItemPtr->typePtr->configProc(canvasPtr->interp,
- (Tk_Canvas) canvasPtr, canvasPtr->currentItemPtr, 0, NULL,
- TK_CONFIG_ARGV_ONLY);
- EventuallyRedrawItem((Tk_Canvas) canvasPtr,
- canvasPtr->currentItemPtr);
+ ItemConfigure(canvasPtr, canvasPtr->currentItemPtr, 0, NULL);
+ EventuallyRedrawItem(canvasPtr, canvasPtr->currentItemPtr);
}
event = canvasPtr->pickEvent;
event.type = EnterNotify;
@@ -4780,8 +5005,7 @@ CanvasFindClosest(
|| (itemPtr->y1 > y2) || (itemPtr->y2 < y1)) {
continue;
}
- if (itemPtr->typePtr->pointProc((Tk_Canvas) canvasPtr, itemPtr,
- coords) <= canvasPtr->closeEnough) {
+ if (ItemPoint(canvasPtr,itemPtr,coords,0) <= canvasPtr->closeEnough) {
bestPtr = itemPtr;
}
}
@@ -4956,10 +5180,7 @@ CanvasBlinkProc(
canvasPtr->insertBlinkHandler = Tcl_CreateTimerHandler(
canvasPtr->insertOnTime, CanvasBlinkProc, canvasPtr);
}
- if (canvasPtr->textInfo.focusItemPtr != NULL) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr,
- canvasPtr->textInfo.focusItemPtr);
- }
+ EventuallyRedrawItem(canvasPtr, canvasPtr->textInfo.focusItemPtr);
}
/*
@@ -4999,10 +5220,7 @@ CanvasFocusProc(
canvasPtr->textInfo.cursorOn = 0;
canvasPtr->insertBlinkHandler = (Tcl_TimerToken) NULL;
}
- if (canvasPtr->textInfo.focusItemPtr != NULL) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr,
- canvasPtr->textInfo.focusItemPtr);
- }
+ EventuallyRedrawItem(canvasPtr, canvasPtr->textInfo.focusItemPtr);
if (canvasPtr->highlightWidth > 0) {
canvasPtr->flags |= REDRAW_BORDERS;
if (!(canvasPtr->flags & REDRAW_PENDING)) {
@@ -5051,8 +5269,7 @@ CanvasSelectTo(
Tk_OwnSelection(canvasPtr->tkwin, XA_PRIMARY, CanvasLostSelection,
canvasPtr);
} else if (canvasPtr->textInfo.selItemPtr != itemPtr) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr,
- canvasPtr->textInfo.selItemPtr);
+ EventuallyRedrawItem(canvasPtr, canvasPtr->textInfo.selItemPtr);
}
canvasPtr->textInfo.selItemPtr = itemPtr;
@@ -5070,7 +5287,7 @@ CanvasSelectTo(
if ((canvasPtr->textInfo.selectFirst != oldFirst)
|| (canvasPtr->textInfo.selectLast != oldLast)
|| (itemPtr != oldSelPtr)) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr);
+ EventuallyRedrawItem(canvasPtr, itemPtr);
}
}
@@ -5107,14 +5324,7 @@ CanvasFetchSelection(
{
TkCanvas *canvasPtr = clientData;
- if (canvasPtr->textInfo.selItemPtr == NULL) {
- return -1;
- }
- if (canvasPtr->textInfo.selItemPtr->typePtr->selectionProc == NULL) {
- return -1;
- }
- return canvasPtr->textInfo.selItemPtr->typePtr->selectionProc(
- (Tk_Canvas) canvasPtr, canvasPtr->textInfo.selItemPtr, offset,
+ return ItemSelection(canvasPtr, canvasPtr->textInfo.selItemPtr, offset,
buffer, maxBytes);
}
@@ -5142,10 +5352,7 @@ CanvasLostSelection(
{
TkCanvas *canvasPtr = clientData;
- if (canvasPtr->textInfo.selItemPtr != NULL) {
- EventuallyRedrawItem((Tk_Canvas) canvasPtr,
- canvasPtr->textInfo.selItemPtr);
- }
+ EventuallyRedrawItem(canvasPtr, canvasPtr->textInfo.selItemPtr);
canvasPtr->textInfo.selItemPtr = NULL;
}
diff --git a/tests/canvas.test b/tests/canvas.test
index 1c95dc7..0ffad23 100644
--- a/tests/canvas.test
+++ b/tests/canvas.test
@@ -1,24 +1,26 @@
-# This file is a Tcl script to test out the procedures in tkCanvas.c,
-# which implements generic code for canvases. It is organized in the
-# standard fashion for Tcl tests.
+# This file is a Tcl script to test out the procedures in tkCanvas.c, which
+# implements generic code for canvases. It is organized in the standard
+# fashion for Tcl tests.
#
# Copyright (c) 1995-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-2000 Ajuba Solutions.
+# Copyright (c) 2008 Donal K. Fellows
# All rights reserved.
#
-# RCS: @(#) $Id: canvas.test,v 1.25 2008/08/08 17:46:38 aniap Exp $
+# RCS: @(#) $Id: canvas.test,v 1.26 2008/11/01 16:14:30 dkf Exp $
package require tcltest 2.1
eval tcltest::configure $argv
tcltest::loadTestedCommands
-# XXX - This test file is woefully incomplete. At present, only a
-# few of the features are tested.
+# XXX - This test file is woefully incomplete. At present, only a few of the
+# features are tested.
# Canvas used in 1.* test cases
canvas .c
pack .c
update
+
test canvas-1.1 {configuration options: good value for "background"} -body {
.c configure -background #ff0000
.c cget -background
@@ -26,7 +28,6 @@ test canvas-1.1 {configuration options: good value for "background"} -body {
test canvas-1.2 {configuration options: bad value for "background"} -body {
.c configure -background non-existent
} -returnCodes error -result {unknown color name "non-existent"}
-
test canvas-1.3 {configuration options: good value for "bg"} -body {
.c configure -bg #ff0000
.c cget -bg
@@ -34,7 +35,6 @@ test canvas-1.3 {configuration options: good value for "bg"} -body {
test canvas-1.4 {configuration options: bad value for "bg"} -body {
.c configure -bg non-existent
} -returnCodes error -result {unknown color name "non-existent"}
-
test canvas-1.5 {configuration options: good value for "bd"} -body {
.c configure -bd 4
.c cget -bd
@@ -42,7 +42,6 @@ test canvas-1.5 {configuration options: good value for "bd"} -body {
test canvas-1.6 {configuration options: bad value for "bd"} -body {
.c configure -bd badValue
} -returnCodes error -result {bad screen distance "badValue"}
-
test canvas-1.7 {configuration options: good value for "borderwidth"} -body {
.c configure -borderwidth 1.3
.c cget -borderwidth
@@ -50,7 +49,6 @@ test canvas-1.7 {configuration options: good value for "borderwidth"} -body {
test canvas-1.8 {configuration options: bad value for "borderwidth"} -body {
.c configure -borderwidth badValue
} -returnCodes error -result {bad screen distance "badValue"}
-
test canvas-1.9 {configuration options: good value for "closeenough"} -body {
.c configure -closeenough 24
.c cget -closeenough
@@ -58,7 +56,6 @@ test canvas-1.9 {configuration options: good value for "closeenough"} -body {
test canvas-1.10 {configuration options: bad value for "closeenough"} -body {
.c configure -closeenough bogus
} -returnCodes error -result {expected floating-point number but got "bogus"}
-
test canvas-1.11 {configuration options: good value for "confine"} -body {
.c configure -confine true
.c cget -confine
@@ -66,7 +63,6 @@ test canvas-1.11 {configuration options: good value for "confine"} -body {
test canvas-1.12 {configuration options: bad value for "confine"} -body {
.c configure -confine silly
} -returnCodes error -result {expected boolean value but got "silly"}
-
test canvas-1.13 {configuration options: good value for "cursor"} -body {
.c configure -cursor arrow
.c cget -cursor
@@ -74,7 +70,6 @@ test canvas-1.13 {configuration options: good value for "cursor"} -body {
test canvas-1.14 {configuration options: bad value for "cursor"} -body {
.c configure -cursor badValue
} -returnCodes error -result {bad cursor spec "badValue"}
-
test canvas-1.15 {configuration options: good value for "height"} -body {
.c configure -height 2.1
.c cget -height
@@ -82,7 +77,6 @@ test canvas-1.15 {configuration options: good value for "height"} -body {
test canvas-1.16 {configuration options: bad value for "height"} -body {
.c configure -height x42
} -returnCodes error -result {bad screen distance "x42"}
-
test canvas-1.17 {configuration options: good value for "highlightbackground"} -body {
.c configure -highlightbackground #112233
.c cget -highlightbackground
@@ -90,7 +84,6 @@ test canvas-1.17 {configuration options: good value for "highlightbackground"} -
test canvas-1.18 {configuration options: bad value for "highlightbackground"} -body {
.c configure -highlightbackground ugly
} -returnCodes error -result {unknown color name "ugly"}
-
test canvas-1.19 {configuration options: good value for "highlightcolor"} -body {
.c configure -highlightcolor #110022
.c cget -highlightcolor
@@ -98,7 +91,6 @@ test canvas-1.19 {configuration options: good value for "highlightcolor"} -body
test canvas-1.20 {configuration options: bad value for "highlightcolor"} -body {
.c configure -highlightcolor bogus
} -returnCodes error -result {unknown color name "bogus"}
-
test canvas-1.21 {configuration options: good value for "highlightthickness"} -body {
.c configure -highlightthickness 18
.c cget -highlightthickness
@@ -106,7 +98,6 @@ test canvas-1.21 {configuration options: good value for "highlightthickness"} -b
test canvas-1.22 {configuration options: bad value for "highlightthickness"} -body {
.c configure -highlightthickness badValue
} -returnCodes error -result {bad screen distance "badValue"}
-
test canvas-1.23 {configuration options: good value for "insertbackground"} -body {
.c configure -insertbackground #110022
.c cget -insertbackground
@@ -114,7 +105,6 @@ test canvas-1.23 {configuration options: good value for "insertbackground"} -bod
test canvas-1.24 {configuration options: bad value for "insertbackground"} -body {
.c configure -insertbackground bogus
} -returnCodes error -result {unknown color name "bogus"}
-
test canvas-1.25 {configuration options: good value for "insertborderwidth"} -body {
.c configure -insertborderwidth 1.3
.c cget -insertborderwidth
@@ -122,7 +112,6 @@ test canvas-1.25 {configuration options: good value for "insertborderwidth"} -bo
test canvas-1.26 {configuration options: bad value for "insertborderwidth"} -body {
.c configure -insertborderwidth 2.6x
} -returnCodes error -result {bad screen distance "2.6x"}
-
test canvas-1.27 {configuration options: good value for "insertofftime"} -body {
.c configure -insertofftime 100
.c cget -insertofftime
@@ -130,7 +119,6 @@ test canvas-1.27 {configuration options: good value for "insertofftime"} -body {
test canvas-1.28 {configuration options: bad value for "insertofftime"} -body {
.c configure -insertofftime 3.2
} -returnCodes error -result {expected integer but got "3.2"}
-
test canvas-1.29 {configuration options: good value for "insertontime"} -body {
.c configure -insertontime 100
.c cget -insertontime
@@ -138,7 +126,6 @@ test canvas-1.29 {configuration options: good value for "insertontime"} -body {
test canvas-1.30 {configuration options: bad value for "insertontime"} -body {
.c configure -insertontime 3.2
} -returnCodes error -result {expected integer but got "3.2"}
-
test canvas-1.31 {configuration options: good value for "insertwidth"} -body {
.c configure -insertwidth 1.3
.c cget -insertwidth
@@ -146,7 +133,6 @@ test canvas-1.31 {configuration options: good value for "insertwidth"} -body {
test canvas-1.32 {configuration options: bad value for "insertwidth"} -body {
.c configure -insertwidth 6x
} -returnCodes error -result {bad screen distance "6x"}
-
test canvas-1.33 {configuration options: good value for "relief"} -body {
.c configure -relief groove
.c cget -relief
@@ -154,7 +140,6 @@ test canvas-1.33 {configuration options: good value for "relief"} -body {
test canvas-1.34 {configuration options: bad value for "relief"} -body {
.c configure -relief 1.5
} -returnCodes error -result {bad relief type "1.5": must be flat, groove, raised, ridge, solid, or sunken}
-
test canvas-1.35 {configuration options: good value for "selectbackground"} -body {
.c configure -selectbackground #110022
.c cget -selectbackground
@@ -162,7 +147,6 @@ test canvas-1.35 {configuration options: good value for "selectbackground"} -bod
test canvas-1.36 {configuration options: bad value for "selectbackground"} -body {
.c configure -selectbackground bogus
} -returnCodes error -result {unknown color name "bogus"}
-
test canvas-1.37 {configuration options: good value for "selectborderwidth"} -body {
.c configure -selectborderwidth 1.3
.c cget -selectborderwidth
@@ -170,7 +154,6 @@ test canvas-1.37 {configuration options: good value for "selectborderwidth"} -bo
test canvas-1.38 {configuration options: bad value for "selectborderwidth"} -body {
.c configure -selectborderwidth badValue
} -returnCodes error -result {bad screen distance "badValue"}
-
test canvas-1.39 {configuration options: good value for "selectforeground"} -body {
.c configure -selectforeground #654321
.c cget -selectforeground
@@ -178,12 +161,10 @@ test canvas-1.39 {configuration options: good value for "selectforeground"} -bod
test canvas-1.40 {configuration options: bad value for "selectforeground"} -body {
.c configure -selectforeground bogus
} -returnCodes error -result {unknown color name "bogus"}
-
test canvas-1.41 {configuration options: good value for "takefocus"} -body {
.c configure -takefocus "any string"
.c cget -takefocus
} -result {any string}
-
test canvas-1.42 {configuration options: good value for "width"} -body {
.c configure -width 402
.c cget -width
@@ -191,17 +172,14 @@ test canvas-1.42 {configuration options: good value for "width"} -body {
test canvas-1.43 {configuration options: bad value for "width"} -body {
.c configure -width xyz
} -returnCodes error -result {bad screen distance "xyz"}
-
test canvas-1.44 {configuration options: good value for "xscrollcommand"} -body {
.c configure -xscrollcommand {Some command}
.c cget -xscrollcommand
} -result {Some command}
-
test canvas-1.45 {configuration options: good value for "yscrollcommand"} -body {
.c configure -yscrollcommand {Another command}
.c cget -yscrollcommand
} -result {Another command}
-
test canvas-1.46 {configure throws error on bad option} -body {
.c configure -gorp foo
} -returnCodes error -match glob -result {*}
@@ -212,23 +190,23 @@ test canvas-1.47 {configure throws error on bad option} -body {
} -returnCodes error -match glob -result {*}
catch {destroy .c}
-
# Canvas used in 2.* test cases
canvas .c -width 60 -height 40 -scrollregion {0 0 200 150} -bd 0 \
-highlightthickness 0
pack .c
update
+
test canvas-2.1 {CanvasWidgetCmd, bind option} -body {
set i [.c create rect 10 10 100 100]
.c bind $i <a>
} -cleanup {
- .c delete $i
+ .c delete $i
} -returnCodes ok
test canvas-2.2 {CanvasWidgetCmd, bind option} -body {
set i [.c create rect 10 10 100 100]
.c bind $i <
} -cleanup {
- .c delete $i
+ .c delete $i
} -returnCodes error -result {no event type or button # or keysym}
test canvas-2.3 {CanvasWidgetCmd, xview option} -body {
.c configure -xscrollincrement 40 -yscrollincrement 5
@@ -240,8 +218,8 @@ test canvas-2.3 {CanvasWidgetCmd, xview option} -body {
lappend x [.c xview]
} -result {{0.0 0.3} {0.4 0.7}}
test canvas-2.4 {CanvasWidgetCmd, xview option} -constraints nonPortable -body {
- # This test gives slightly different results on platforms such
- # as NetBSD. I don't know why...
+ # This test gives slightly different results on platforms such as NetBSD.
+ # I don't know why...
.c configure -xscrollincrement 0 -yscrollincrement 5
.c xview moveto 0.6
update
@@ -252,12 +230,12 @@ test canvas-2.4 {CanvasWidgetCmd, xview option} -constraints nonPortable -body {
} -result {{0.6 0.9} {0.66 0.96}}
catch {destroy .c}
-
# Canvas used in 3.* test cases
canvas .c -width 60 -height 40 -scrollregion {0 0 200 80} \
-borderwidth 0 -highlightthickness 0
pack .c
update
+
test canvas-3.1 {CanvasWidgetCmd, yview option} -body {
.c configure -xscrollincrement 40 -yscrollincrement 5
.c yview moveto 0
@@ -278,10 +256,9 @@ test canvas-3.2 {CanvasWidgetCmd, yview option} -body {
} -result {{0.0 0.5} {0.1 0.6}}
destroy .c
-
test canvas-4.1 {ButtonEventProc procedure} -setup {
deleteWindows
- set x {}
+ set x {}
} -body {
canvas .c1 -bg #543210
rename .c1 .c2
@@ -296,15 +273,15 @@ test canvas-5.1 {ButtonCmdDeletedProc procedure} -body {
rename .c1 {}
list [info command .c*] [winfo children .]
} -cleanup {
- destroy .c1
+ destroy .c1
} -result {{} {}}
-
# Canvas used in 6.* test cases
canvas .c -width 100 -height 50 -scrollregion {-200 -100 305 102} \
-borderwidth 2 -highlightthickness 3
pack .c
update
+
test canvas-6.1 {CanvasSetOrigin procedure} -body {
.c configure -xscrollincrement 0 -yscrollincrement 0
.c xview moveto 0
@@ -316,9 +293,9 @@ test canvas-6.2 {CanvasSetOrigin procedure} -body {
.c configure -xscrollincrement 20 -yscrollincrement 10
set x ""
foreach i {.08 .10 .48 .50} {
- .c xview moveto $i
- update
- lappend x [.c canvasx 0]
+ .c xview moveto $i
+ update
+ lappend x [.c canvasx 0]
}
return $x
} -result {-165.0 -145.0 35.0 55.0}
@@ -344,19 +321,15 @@ test canvas-6.5 {CanvasSetOrigin procedure} -body {
} -result {55.0}
deleteWindows
-
test canvas-7.1 {canvas widget vs hidden commands} -setup {
canvas .c
} -body {
- set l [lsort [interp hidden]]
interp hide {} .c
destroy .c
- set result [list [winfo children .] [lsort [interp hidden]]]
- expr {$result eq [list {} $l]}
+ list [winfo children .] [lsort [interp hidden]]
} -cleanup {
- destroy .c
-} -result {1}
-
+ destroy .c
+} -result [list {} [lsort [interp hidden]]]
test canvas-8.1 {canvas arc bbox} -setup {
catch {destroy .c}
@@ -371,29 +344,25 @@ test canvas-8.1 {canvas arc bbox} -setup {
list $arcBox $coordBox $pieBox
} -result {{48 21 100 94} {248 21 300 94} {398 21 500 112}}
-
test canvas-9.1 {canvas id creation and deletion} -setup {
catch {destroy .c}
canvas .c
} -body {
- # With Tk 8.0.4 the ids are now stored in a hash table. You
- # can use this test as a performance test with older versions
- # by changing the value of size.
+ # With Tk 8.0.4 the ids are now stored in a hash table. You can use this
+ # test as a performance test with older versions by changing the value of
+ # size.
set size 15
-
for {set i 0} {$i < $size} {incr i} {
- set x [expr {-10 + 3*$i}]
- for {set j 0; set y -10} {$j < 10} {incr j; incr y 3} {
- .c create rect ${x}c ${y}c [expr $x+2]c [expr $y+2]c \
- -outline black -fill blue -tags rect
- .c create text [expr $x+1]c [expr $y+1]c -text "$i,$j" \
- -anchor center -tags text
- }
+ set x [expr {-10 + 3*$i}]
+ for {set j 0; set y -10} {$j < 10} {incr j; incr y 3} {
+ .c create rect ${x}c ${y}c [expr $x+2]c [expr $y+2]c \
+ -outline black -fill blue -tags rect
+ .c create text [expr $x+1]c [expr $y+1]c -text "$i,$j" \
+ -anchor center -tags text
+ }
}
-
- # The actual bench mark - this code also exercises all the hash
- # table changes.
-
+ # The actual bench mark - this code also exercises all the hash table
+ # changes.
set time [lindex [time {
foreach id [.c find withtag all] {
.c lower $id
@@ -403,14 +372,13 @@ test canvas-9.1 {canvas id creation and deletion} -setup {
.c delete $id
}
}] 0]
-
set x ""
} -result {}
-
test canvas-10.1 {find items using tag expressions} -setup {
catch {destroy .c}
canvas .c
+ set res {}
} -body {
.c create oval 20 20 40 40 -fill red -tag [list a b c d]
.c create oval 20 60 40 80 -fill yellow -tag [list b a]
@@ -419,7 +387,6 @@ test canvas-10.1 {find items using tag expressions} -setup {
.c create oval 20 180 40 200 -fill bisque -tag [list a d e]
.c create oval 20 220 40 240 -fill bisque -tag b
.c create oval 20 260 40 280 -fill bisque -tag [list d "tag with spaces"]
- set res {}
lappend res [.c find withtag {!a}]
lappend res [.c find withtag {b&&c}]
lappend res [.c find withtag {b||c}]
@@ -486,9 +453,9 @@ test canvas-10.8 {check errors from tag expressions} -setup {
canvas .c
.c create oval 20 20 40 40 -fill red -tag [list a b c d]
.c create oval 20 260 40 280 -fill bisque -tag [list d "tag with spaces"]
-} -body {
+} -returnCodes error -body {
.c find withtag {a&&"tag with spaces"z}
-} -returnCodes error -result {Invalid boolean operator in tag search expression}
+} -result {Invalid boolean operator in tag search expression}
test canvas-10.9 {check errors from tag expressions} -setup {
catch {destroy .c}
canvas .c
@@ -508,7 +475,8 @@ test canvas-10.10 {check errors from tag expressions} -setup {
test canvas-10.11 {backward compatility - strange tags that are not expressions} -setup {
catch {destroy .c}
canvas .c
- .c create oval 20 20 40 40 -fill red -tag [list { strange tag(xxx&yyy|zzz) " && \" || ! ^ " }]
+ .c create oval 20 20 40 40 -fill red \
+ -tag [list { strange tag(xxx&yyy|zzz) " && \" || ! ^ " }]
} -body {
.c find withtag { strange tag(xxx&yyy|zzz) " && \" || ! ^ " }
} -result 1
@@ -520,7 +488,6 @@ test canvas-10.12 {multple events bound to same tag expr} -setup {
.c bind {a && b} <Leave> {puts Leave}
} -result {}
-
test canvas-11.1 {canvas poly fill check, bug 5783} -setup {
destroy .c
pack [canvas .c]
@@ -535,22 +502,21 @@ test canvas-11.2 {canvas poly overlap fill check, bug 226357} -setup {
set result {}
} -body {
.c create poly 30 30 90 90 30 90 90 30
- lappend result [.c find over 40 40 45 45]; # rect region inc. edge
- lappend result [.c find over 60 40 60 40]; # top-center point
- lappend result [.c find over 0 0 0 0]; # not on poly
- lappend result [.c find over 60 60 60 60]; # center-point
- lappend result [.c find over 45 50 45 50]; # outside poly
+ lappend result [.c find over 40 40 45 45]; # rect region inc. edge
+ lappend result [.c find over 60 40 60 40]; # top-center point
+ lappend result [.c find over 0 0 0 0]; # not on poly
+ lappend result [.c find over 60 60 60 60]; # center-point
+ lappend result [.c find over 45 50 45 50]; # outside poly
.c itemconfig 1 -fill "" -outline black
- lappend result [.c find over 40 40 45 45]; # rect region inc. edge
- lappend result [.c find over 60 40 60 40]; # top-center point
- lappend result [.c find over 0 0 0 0]; # not on poly
- lappend result [.c find over 60 60 60 60]; # center-point
- lappend result [.c find over 45 50 45 50]; # outside poly
+ lappend result [.c find over 40 40 45 45]; # rect region inc. edge
+ lappend result [.c find over 60 40 60 40]; # top-center point
+ lappend result [.c find over 0 0 0 0]; # not on poly
+ lappend result [.c find over 60 60 60 60]; # center-point
+ lappend result [.c find over 45 50 45 50]; # outside poly
.c itemconfig 1 -width 8
- lappend result [.c find over 45 50 45 50]; # outside poly
+ lappend result [.c find over 45 50 45 50]; # outside poly
} -result {1 1 {} 1 {} 1 1 {} 1 {} 1}
-
test canvas-12.1 {canvas mm obj, patch SF-403327, 102471} -setup {
destroy .c
pack [canvas .c]
@@ -581,41 +547,39 @@ proc kill_canvas {w} {
$w create rectangle 80 80 120 120 -fill blue -tags blue
# bind a button press to re-build the canvas
$w bind blue <ButtonRelease-1> [subst {
- [lindex [info level 0] 0] $w
- append ::x ok
- }
- ]
+ [lindex [info level 0] 0] $w
+ append ::x ok
+ }]
}
test canvas-13.1 {canvas delete during event, SF bug-228024} -body {
kill_canvas .c
set ::x {}
# do this many times to improve chances of triggering the crash
for {set i 0} {$i < 30} {incr i} {
- event generate .c <1> -x 100 -y 100
- event generate .c <ButtonRelease-1> -x 100 -y 100
+ event generate .c <1> -x 100 -y 100
+ event generate .c <ButtonRelease-1> -x 100 -y 100
}
return $::x
} -result {okokokokokokokokokokokokokokokokokokokokokokokokokokokokokok}
-
test canvas-14.1 {canvas scan SF bug 581560} -setup {
destroy .c
canvas .c
-} -body {
+} -returnCodes error -body {
.c scan
-} -returnCodes error -result {wrong # args: should be ".c scan mark|dragto x y ?dragGain?"}
+} -result {wrong # args: should be ".c scan mark|dragto x y ?dragGain?"}
test canvas-14.2 {canvas scan} -setup {
destroy .c
canvas .c
-} -body {
+} -returnCodes error -body {
.c scan bogus
-} -returnCodes error -result {wrong # args: should be ".c scan mark|dragto x y ?dragGain?"}
+} -result {wrong # args: should be ".c scan mark|dragto x y ?dragGain?"}
test canvas-14.3 {canvas scan} -setup {
destroy .c
canvas .c
-} -body {
+} -returnCodes error -body {
.c scan mark
-} -returnCodes error -result {wrong # args: should be ".c scan mark|dragto x y ?dragGain?"}
+} -result {wrong # args: should be ".c scan mark|dragto x y ?dragGain?"}
test canvas-14.4 {canvas scan} -setup {
destroy .c
canvas .c
@@ -635,136 +599,126 @@ test canvas-14.6 {canvas scan} -setup {
.c scan dragto 10 10 5
} -result {}
-
test canvas-15.1 {basic types check: arc requires coords} -setup {
- destroy .c
- canvas .c
-} -body {
- .c create arc
-} -returnCodes error -result {wrong # args: should be ".c create arc coords ?arg ...?"}
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create arc
+} -result {wrong # args: should be ".c create arc coords ?arg ...?"}
test canvas-15.2 "basic coords check: arc coords are paired" -setup {
- destroy .c
- canvas .c
+ destroy .c
+ canvas .c
} -body {
- .c create arc 0
+ .c create arc 0
} -returnCodes error -result {wrong # coordinates: expected 4, got 1}
-
test canvas-15.3 {basic types check: bitmap requires coords} -setup {
- destroy .c
- canvas .c
-} -body {
- .c create bitmap
-} -returnCodes error -result {wrong # args: should be ".c create bitmap coords ?arg ...?"}
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create bitmap
+} -result {wrong # args: should be ".c create bitmap coords ?arg ...?"}
test canvas-15.4 "basic coords check: bitmap coords are paired" -setup {
- destroy .c
- canvas .c
+ destroy .c
+ canvas .c
} -body {
- .c create bitmap 0
+ .c create bitmap 0
} -returnCodes error -result {wrong # coordinates: expected 2, got 1}
-
test canvas-15.5 {basic types check: image requires coords} -setup {
- destroy .c
- canvas .c
-} -body {
- .c create image
-} -returnCodes error -result {wrong # args: should be ".c create image coords ?arg ...?"}
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create image
+} -result {wrong # args: should be ".c create image coords ?arg ...?"}
test canvas-15.6 "basic coords check: image coords are paired" -setup {
- destroy .c
- canvas .c
-} -body {
- .c create image 0
-} -returnCodes error -result {wrong # coordinates: expected 2, got 1}
-
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create image 0
+} -result {wrong # coordinates: expected 2, got 1}
test canvas-15.7 {basic types check: line requires coords} -setup {
- destroy .c
- canvas .c
-} -body {
- .c create line
-} -returnCodes error -result {wrong # args: should be ".c create line coords ?arg ...?"}
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create line
+} -result {wrong # args: should be ".c create line coords ?arg ...?"}
test canvas-15.8 "basic coords check: line coords are paired" -setup {
- destroy .c
- canvas .c
-} -body {
- .c create line 0
-} -returnCodes error -result {wrong # coordinates: expected an even number, got 1}
-
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create line 0
+} -result {wrong # coordinates: expected an even number, got 1}
test canvas-15.9 {basic types check: oval requires coords} -setup {
- destroy .c
- canvas .c
-} -body {
- .c create oval
-} -returnCodes error -result {wrong # args: should be ".c create oval coords ?arg ...?"}
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create oval
+} -result {wrong # args: should be ".c create oval coords ?arg ...?"}
test canvas-15.10 "basic coords check: oval coords are paired" -setup {
- destroy .c
- canvas .c
-} -body {
- .c create oval 0
-} -returnCodes error -result {wrong # coordinates: expected 0 or 4, got 1}
-
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create oval 0
+} -result {wrong # coordinates: expected 0 or 4, got 1}
test canvas-15.11 {basic types check: polygon requires coords} -setup {
- destroy .c
- canvas .c
-} -body {
- .c create polygon
-} -returnCodes error -result {wrong # args: should be ".c create polygon coords ?arg ...?"}
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create polygon
+} -result {wrong # args: should be ".c create polygon coords ?arg ...?"}
test canvas-15.12 "basic coords check: polygon coords are paired" -setup {
- destroy .c
- canvas .c
-} -body {
- .c create polygon 0
-} -returnCodes error -result {wrong # coordinates: expected an even number, got 1}
-
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create polygon 0
+} -result {wrong # coordinates: expected an even number, got 1}
test canvas-15.13 {basic types check: rect requires coords} -setup {
- destroy .c
- canvas .c
-} -body {
- .c create rect
-} -returnCodes error -result {wrong # args: should be ".c create rect coords ?arg ...?"}
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create rect
+} -result {wrong # args: should be ".c create rect coords ?arg ...?"}
test canvas-15.14 "basic coords check: rect coords are paired" -setup {
- destroy .c
- canvas .c
-} -body {
- .c create rect 0
-} -returnCodes error -result {wrong # coordinates: expected 0 or 4, got 1}
-
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create rect 0
+} -result {wrong # coordinates: expected 0 or 4, got 1}
test canvas-15.15 {basic types check: text requires coords} -setup {
- destroy .c
- canvas .c
-} -body {
- .c create text
-} -returnCodes error -result {wrong # args: should be ".c create text coords ?arg ...?"}
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create text
+} -result {wrong # args: should be ".c create text coords ?arg ...?"}
test canvas-15.16 "basic coords check: text coords are paired" -setup {
- destroy .c
- canvas .c
-} -body {
- .c create text 0
-} -returnCodes error -result {wrong # coordinates: expected 2, got 1}
-
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create text 0
+} -result {wrong # coordinates: expected 2, got 1}
test canvas-15.17 {basic types check: window requires coords} -setup {
- destroy .c
- canvas .c
-} -body {
- .c create window
-} -returnCodes error -result {wrong # args: should be ".c create window coords ?arg ...?"}
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create window
+} -result {wrong # args: should be ".c create window coords ?arg ...?"}
test canvas-15.18 "basic coords check: window coords are paired" -setup {
- destroy .c
- canvas .c
-} -body {
- .c create window 0
-} -returnCodes error -result {wrong # coordinates: expected 2, got 1}
-
+ destroy .c
+ canvas .c
+} -returnCodes error -body {
+ .c create window 0
+} -result {wrong # coordinates: expected 2, got 1}
+destroy .c
test canvas-16.1 {arc coords check} -setup {
- destroy .c
canvas .c
} -body {
set id [.c create arc {0 10 20 30} -start 33]
.c itemcget $id -start
+} -cleanup {
+ destroy .c
} -result {33.0}
-
test canvas-17.1 {default smooth method handling} -setup {
- destroy .c
canvas .c
} -body {
set id [.c create line {0 0 1 1 2 2 3 3 4 4 5 5 6 6}]
@@ -774,14 +728,209 @@ test canvas-17.1 {default smooth method handling} -setup {
lappend result [.c itemcget $id -smooth]
}
return $result
+} -cleanup {
+ destroy .c
} -result {0 true true true raw raw true}
-destroy .c
+test canvas-18.1 {imove method - lines} -setup {
+ canvas .c
+} -body {
+ set id [.c create line 0 0 1 1 2 2 3 3]
+ .c imove $id 0 4 4
+ .c coords $id
+} -cleanup {
+ destroy .c
+} -result {4.0 4.0 1.0 1.0 2.0 2.0 3.0 3.0}
+test canvas-18.2 {imove method - lines} -setup {
+ canvas .c
+} -body {
+ set id [.c create line 0 0 1 1]
+ .c imove $id 0 4 4
+ .c coords $id
+} -cleanup {
+ destroy .c
+} -result {4.0 4.0 1.0 1.0}
+test canvas-18.3 {imove method - lines} -setup {
+ canvas .c
+} -body {
+ set id [.c create line 0 0 1 1 2 2 3 3]
+ .c imove $id @1,1 4 4
+ .c coords $id
+} -cleanup {
+ destroy .c
+} -result {0.0 0.0 4.0 4.0 2.0 2.0 3.0 3.0}
+test canvas-18.4 {imove method - lines} -constraints knownBug -setup {
+ canvas .c
+} -body {
+ set id [.c create line 0 0 1 1 2 2 3 3]
+ .c imove $id end 4 4
+ .c coords $id
+} -cleanup {
+ destroy .c
+} -result {0.0 0.0 1.0 1.0 2.0 2.0 4.0 4.0}
+test canvas-18.5 {imove method - polygon} -setup {
+ canvas .c
+} -body {
+ set id [.c create polygon 0 0 1 1 2 2 3 3]
+ .c imove $id 0 4 4
+ .c coords $id
+} -cleanup {
+ destroy .c
+} -result {4.0 4.0 1.0 1.0 2.0 2.0 3.0 3.0}
+test canvas-18.6 {imove method - polygon} -setup {
+ canvas .c
+} -body {
+ set id [.c create polygon 0 0 1 1]
+ .c imove $id 0 4 4
+ .c coords $id
+} -cleanup {
+ destroy .c
+} -result {4.0 4.0 1.0 1.0}
+test canvas-18.7 {imove method - polygon} -setup {
+ canvas .c
+} -body {
+ set id [.c create polygon 0 0 1 1 2 2 3 3]
+ .c imove $id @1,1 4 4
+ .c coords $id
+} -cleanup {
+ destroy .c
+} -result {0.0 0.0 4.0 4.0 2.0 2.0 3.0 3.0}
+test canvas-18.8 {imove method - polygon} -constraints knownBug -setup {
+ canvas .c
+} -body {
+ set id [.c create polygon 0 0 1 1 2 2 3 3]
+ .c imove $id end 4 4
+ .c coords $id
+} -cleanup {
+ destroy .c
+} -result {0.0 0.0 1.0 1.0 2.0 2.0 4.0 4.0}
+test canvas-18.9 {imove method - errors} -setup {
+ canvas .c
+} -body {
+ set id [.c create line 0 0 1 1 2 2 3 3]
+ .c imove $id foobar 4 4
+} -cleanup {
+ destroy .c
+} -returnCodes error -result {bad index "foobar"}
+test canvas-18.10 {imove method - errors} -setup {
+ canvas .c
+} -body {
+ set id [.c create line 0 0 1 1 2 2 3 3]
+ .c imove $id 0 foobar 4
+} -cleanup {
+ destroy .c
+} -returnCodes error -result {bad screen distance "foobar"}
+test canvas-18.11 {imove method - errors} -setup {
+ canvas .c
+} -body {
+ set id [.c create line 0 0 1 1 2 2 3 3]
+ .c imove $id 0 4 foobar
+} -cleanup {
+ destroy .c
+} -returnCodes error -result {bad screen distance "foobar"}
+
+test canvas-19.1 {rchars method - lines} -setup {
+ canvas .c
+} -body {
+ set id [.c create line 0 0 1 1 2 2 3 3]
+ .c rchars $id 2 4 {4 4}
+ .c coords $id
+} -cleanup {
+ destroy .c
+} -result {0.0 0.0 4.0 4.0 3.0 3.0}
+test canvas-19.2 {rchars method - lines} -setup {
+ canvas .c
+} -body {
+ set id [.c create line 0 0 1 1 2 2 3 3]
+ .c rchars $id 2 4 {}
+ .c coords $id
+} -cleanup {
+ destroy .c
+} -result {0.0 0.0 3.0 3.0}
+test canvas-19.3 {rchars method - lines} -setup {
+ canvas .c
+} -body {
+ set id [.c create line 0 0 1 1 2 2 3 3]
+ .c rchars $id 2 4 {10 11 12 13 14 15}
+ .c coords $id
+} -cleanup {
+ destroy .c
+} -result {0.0 0.0 10.0 11.0 12.0 13.0 14.0 15.0 3.0 3.0}
+test canvas-19.4 {rchars method - polygon} -setup {
+ canvas .c
+} -body {
+ set id [.c create polygon 0 0 1 1 2 2 3 3]
+ .c rchars $id 2 4 {4 4}
+ .c coords $id
+} -cleanup {
+ destroy .c
+} -result {0.0 0.0 4.0 4.0 3.0 3.0}
+test canvas-19.5 {rchars method - polygon} -setup {
+ canvas .c
+} -body {
+ set id [.c create polygon 0 0 1 1 2 2 3 3]
+ .c rchars $id 2 4 {}
+ .c coords $id
+} -cleanup {
+ destroy .c
+} -result {0.0 0.0 3.0 3.0}
+test canvas-19.6 {rchars method - polygon} -setup {
+ canvas .c
+} -body {
+ set id [.c create polygon 0 0 1 1 2 2 3 3]
+ .c rchars $id 2 4 {10 11 12 13 14 15}
+ .c coords $id
+} -cleanup {
+ destroy .c
+} -result {0.0 0.0 10.0 11.0 12.0 13.0 14.0 15.0 3.0 3.0}
+test canvas-19.7 {rchars method - text} -setup {
+ canvas .c
+} -body {
+ set id [.c create text 0 0 -text abcde]
+ .c rchars $id 1 3 XYZ
+ .c itemcget $id -text
+} -cleanup {
+ destroy .c
+} -result aXYZe
+test canvas-19.8 {rchars method - text} -setup {
+ canvas .c
+} -body {
+ set id [.c create text 0 0 -text abcde]
+ .c rchars $id 1 3 {}
+ .c itemcget $id -text
+} -cleanup {
+ destroy .c
+} -result ae
+test canvas-19.9 {rchars method - text} -setup {
+ canvas .c
+} -body {
+ set id [.c create text 0 0 -text abcde]
+ .c rchars $id 1 3 FOOBAR
+ .c itemcget $id -text
+} -cleanup {
+ destroy .c
+} -result aFOOBARe
+test canvas-19.10 {rchars method - errors} -setup {
+ canvas .c
+} -body {
+ set id [.c create line 0 0 1 1]
+ .c rchars $id foo 1 {2 2}
+} -cleanup {
+ destroy .c
+} -returnCodes error -result {bad index "foo"}
+test canvas-19.11 {rchars method - errors} -setup {
+ canvas .c
+} -body {
+ set id [.c create line 0 0 1 1]
+ .c rchars $id 1 foo {2 2}
+} -cleanup {
+ destroy .c
+} -returnCodes error -result {bad index "foo"}
# cleanup
cleanupTests
return
-
-
-
+# Local Variables:
+# mode: tcl
+# End: