diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2008-09-30 23:54:46 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2008-09-30 23:54:46 (GMT) |
commit | bbcfb76ec591e0c23230e76757184d55a0e1e238 (patch) | |
tree | 123741868fb34edb760412b59981f60f8bceec75 /generic/tkCanvas.c | |
parent | 3c43b176962b1e9df80d6e7d0c0826029e1c8bca (diff) | |
download | tk-bbcfb76ec591e0c23230e76757184d55a0e1e238.zip tk-bbcfb76ec591e0c23230e76757184d55a0e1e238.tar.gz tk-bbcfb76ec591e0c23230e76757184d55a0e1e238.tar.bz2 |
Implemented TIP #236 from patch by Neil McKay.
Diffstat (limited to 'generic/tkCanvas.c')
-rw-r--r-- | generic/tkCanvas.c | 386 |
1 files changed, 228 insertions, 158 deletions
diff --git a/generic/tkCanvas.c b/generic/tkCanvas.c index e44c6fc..bc37043 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.50 2008/07/23 23:24:21 nijtmans Exp $ + * RCS: @(#) $Id: tkCanvas.c,v 1.51 2008/09/30 23:54:46 dkf Exp $ */ /* #define USE_OLD_TAG_SEARCH 1 */ @@ -105,7 +105,7 @@ typedef struct TagSearch { static Tk_CustomOption stateOption = { (Tk_OptionParseProc *) TkStateParseProc, TkStatePrintProc, - (ClientData) NULL /* only "normal" and "disabled" */ + (ClientData) NULL /* Only "normal" and "disabled". */ }; static Tk_CustomOption offsetOption = { @@ -215,8 +215,9 @@ static Tk_ConfigSpec configSpecs[] = { * protected by typeListMutex. */ -static Tk_ItemType *typeList = NULL; /* NULL means initialization hasn't - * been done yet. */ +static Tk_ItemType *typeList = NULL; + /* NULL means initialization hasn't been done + * yet. */ TCL_DECLARE_MUTEX(typeListMutex) #ifndef USE_OLD_TAG_SEARCH @@ -547,9 +548,9 @@ CanvasWidgetCmd( "create", "dchars", "delete", "dtag", "find", "focus", "gettags", "icursor", "index", "insert", "itemcget", "itemconfigure", - "lower", "move", "postscript", "raise", - "scale", "scan", "select", "type", - "xview", "yview", + "lower", "move", "moveto", "postscript", + "raise", "scale", "scan", "select", + "type", "xview", "yview", NULL }; enum options { @@ -558,9 +559,9 @@ CanvasWidgetCmd( 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_LOWER, CANV_MOVE, CANV_POSTSCRIPT,CANV_RAISE, - CANV_SCALE, CANV_SCAN, CANV_SELECT, CANV_TYPE, - CANV_XVIEW, CANV_YVIEW + CANV_LOWER, CANV_MOVE, CANV_MOVETO, CANV_POSTSCRIPT, + CANV_RAISE, CANV_SCALE, CANV_SCAN, CANV_SELECT, + CANV_TYPE, CANV_XVIEW, CANV_YVIEW }; if (objc < 2) { @@ -584,7 +585,8 @@ CanvasWidgetCmd( #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); + result = FindItems(interp, canvasPtr, objc, objv, objv[2], 3, + &searchPtr); #endif /* USE_OLD_TAG_SEARCH */ break; @@ -772,8 +774,8 @@ CanvasWidgetCmd( object, Tcl_GetString(objv[3])); Tcl_ResetResult(interp); Tcl_AppendResult(interp, "requested illegal events; ", - "only key, button, motion, enter, leave, and virtual ", - "events may be used", NULL); + "only key, button, motion, enter, leave, and virtual", + " events may be used", NULL); result = TCL_ERROR; goto done; } @@ -817,13 +819,14 @@ CanvasWidgetCmd( result = TCL_ERROR; goto done; } - if (Tk_GetPixelsFromObj(interp, canvasPtr->tkwin, objv[2], &x) != TCL_OK) { + if (Tk_GetPixelsFromObj(interp, canvasPtr->tkwin, objv[2], + &x) != TCL_OK) { result = TCL_ERROR; goto done; } if (objc == 4) { - if (Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr, objv[3], - &grid) != TCL_OK) { + if (Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr, + objv[3], &grid) != TCL_OK) { result = TCL_ERROR; goto done; } @@ -845,7 +848,8 @@ CanvasWidgetCmd( result = TCL_ERROR; goto done; } - if (Tk_GetPixelsFromObj(interp, canvasPtr->tkwin, objv[2], &y) != TCL_OK) { + if (Tk_GetPixelsFromObj(interp, canvasPtr->tkwin, objv[2], + &y) != TCL_OK) { result = TCL_ERROR; goto done; } @@ -897,12 +901,12 @@ CanvasWidgetCmd( } if (itemPtr->typePtr->coordProc != NULL) { if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) { - result = (*itemPtr->typePtr->coordProc)(interp, + result = itemPtr->typePtr->coordProc(interp, (Tk_Canvas) canvasPtr, itemPtr, objc-3, objv+3); } else { const char **args = TkGetStringsFromObjs(objc-3, objv+3); - result = (*itemPtr->typePtr->coordProc)(interp, + result = itemPtr->typePtr->coordProc(interp, (Tk_Canvas) canvasPtr, itemPtr, objc-3, (Tcl_Obj **) args); if (args != NULL) { @@ -932,26 +936,35 @@ CanvasWidgetCmd( } arg = Tcl_GetStringFromObj(objv[2], &length); c = arg[0]; + + /* + * Lock because the list of types is a global resource that could be + * updated by another thread. That's fairly unlikely, but not + * impossible. + */ + Tcl_MutexLock(&typeListMutex); - for (typePtr = typeList; typePtr != NULL; typePtr = typePtr->nextPtr) { + for (typePtr = typeList; typePtr != NULL; typePtr = typePtr->nextPtr){ if ((c == typePtr->name[0]) - && (strncmp(arg, typePtr->name, (unsigned)length) == 0)) { + && (!strncmp(arg, typePtr->name, (unsigned)length))) { if (matchPtr != NULL) { Tcl_MutexUnlock(&typeListMutex); badType: Tcl_AppendResult(interp, - "unknown or ambiguous item type \"",arg,"\"",NULL); + "unknown or ambiguous item type \"", arg, "\"", + NULL); result = TCL_ERROR; goto done; } matchPtr = typePtr; } } + /* - * Can unlock now because we no longer look at the fields of - * the matched item type that are potentially modified by - * other threads. + * Can unlock now because we no longer look at the fields of the + * matched item type that are potentially modified by other threads. */ + Tcl_MutexUnlock(&typeListMutex); if (matchPtr == NULL) { goto badType; @@ -960,6 +973,7 @@ CanvasWidgetCmd( /* * Allow more specific error return. */ + Tcl_WrongNumArgs(interp, 3, objv, "coords ?arg ...?"); result = TCL_ERROR; goto done; @@ -975,12 +989,12 @@ CanvasWidgetCmd( itemPtr->state = TK_STATE_NULL; itemPtr->redraw_flags = 0; if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) { - result = (*typePtr->createProc)(interp, (Tk_Canvas) canvasPtr, + 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, + result = typePtr->createProc(interp, (Tk_Canvas) canvasPtr, itemPtr, objc-3, (Tcl_Obj **) args); if (args != NULL) { ckfree((char *) args); @@ -1031,8 +1045,8 @@ CanvasWidgetCmd( &first); } else { result = itemPtr->typePtr->indexProc(interp, - (Tk_Canvas) canvasPtr, itemPtr, Tcl_GetString(objv[3]), - &first); + (Tk_Canvas) canvasPtr, itemPtr, + Tcl_GetString(objv[3]), &first); } if (result != TCL_OK) { goto done; @@ -1064,8 +1078,8 @@ 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); + itemPtr->typePtr->dCharsProc((Tk_Canvas) canvasPtr, itemPtr, + first, last); if (!(itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW)) { Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr, x1, y1, x2, y2); @@ -1086,7 +1100,7 @@ CanvasWidgetCmd( Tk_DeleteAllBindings(canvasPtr->bindingTable, (ClientData) itemPtr); } - (*itemPtr->typePtr->deleteProc)((Tk_Canvas) canvasPtr, itemPtr, + itemPtr->typePtr->deleteProc((Tk_Canvas) canvasPtr, itemPtr, canvasPtr->display); if (itemPtr->tagPtr != itemPtr->staticTagSpace) { ckfree((char *) itemPtr->tagPtr); @@ -1238,13 +1252,13 @@ CanvasWidgetCmd( &index); } else { result = itemPtr->typePtr->indexProc(interp, - (Tk_Canvas) canvasPtr, itemPtr, Tcl_GetString(objv[3]), - &index); + (Tk_Canvas) canvasPtr, itemPtr, + Tcl_GetString(objv[3]), &index); } if (result != TCL_OK) { goto done; } - (*itemPtr->typePtr->icursorProc)((Tk_Canvas) canvasPtr, itemPtr, + itemPtr->typePtr->icursorProc((Tk_Canvas) canvasPtr, itemPtr, index); if ((itemPtr == canvasPtr->textInfo.focusItemPtr) && (canvasPtr->textInfo.cursorOn)) { @@ -1274,10 +1288,10 @@ CanvasWidgetCmd( goto done; } if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) { - result = itemPtr->typePtr->indexProc(interp, (Tk_Canvas) canvasPtr, + result = itemPtr->typePtr->indexProc(interp, (Tk_Canvas)canvasPtr, itemPtr, (char *) objv[3], &index); } else { - result = itemPtr->typePtr->indexProc(interp, (Tk_Canvas) canvasPtr, + result = itemPtr->typePtr->indexProc(interp, (Tk_Canvas)canvasPtr, itemPtr, Tcl_GetString(objv[3]), &index); } if (result != TCL_OK) { @@ -1307,8 +1321,8 @@ CanvasWidgetCmd( &beforeThis); } else { result = itemPtr->typePtr->indexProc(interp, - (Tk_Canvas) canvasPtr, itemPtr, Tcl_GetString(objv[3]), - &beforeThis); + (Tk_Canvas) canvasPtr, itemPtr, + Tcl_GetString(objv[3]), &beforeThis); } if (result != TCL_OK) { goto done; @@ -1325,11 +1339,11 @@ CanvasWidgetCmd( 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]); + itemPtr->typePtr->insertProc((Tk_Canvas) canvasPtr, itemPtr, + beforeThis, (char *) objv[4]); } else { - (*itemPtr->typePtr->insertProc)((Tk_Canvas) canvasPtr, - itemPtr, beforeThis, Tcl_GetString(objv[4])); + itemPtr->typePtr->insertProc((Tk_Canvas) canvasPtr, itemPtr, + beforeThis, Tcl_GetString(objv[4])); } if (!(itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW)) { Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr, @@ -1371,13 +1385,13 @@ CanvasWidgetCmd( } else { EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr); if (itemPtr->typePtr->alwaysRedraw & TK_CONFIG_OBJS) { - result = (*itemPtr->typePtr->configProc)(interp, + 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, + result = itemPtr->typePtr->configProc(interp, (Tk_Canvas) canvasPtr, itemPtr, objc-3, (Tcl_Obj **) args, TK_CONFIG_ARGV_ONLY); if (args != NULL) { @@ -1439,13 +1453,77 @@ CanvasWidgetCmd( } FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) { EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr); - (void) (*itemPtr->typePtr->translateProc)((Tk_Canvas) canvasPtr, - itemPtr, xAmount, yAmount); + itemPtr->typePtr->translateProc((Tk_Canvas) canvasPtr, itemPtr, + xAmount, yAmount); EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr); canvasPtr->flags |= REPICK_NEEDED; } break; } + case CANV_MOVETO: { + int xBlank, yBlank; + double xAmount, yAmount; + double oldX = 0, oldY = 0, newX, newY; + + if (objc != 5) { + Tcl_WrongNumArgs(interp, 2, objv, "tagOrId x y"); + result = TCL_ERROR; + goto done; + } + + xBlank = 0; + if (Tcl_GetString(objv[3])[0] == '\0') { + xBlank = 1; + } else if (Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr, + objv[3], &newX) != TCL_OK) { + result = TCL_ERROR; + goto done; + } + + yBlank = 0; + if (Tcl_GetString(objv[4])[0] == '\0') { + yBlank = 1; + } else if (Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr, + objv[4], &newY) != TCL_OK) { + result = TCL_ERROR; + goto done; + } + + FIRST_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done); + if (itemPtr != NULL) { + oldX = itemPtr->x1; + oldY = itemPtr->y1; + + /* + * Calculate the displacement. + */ + + if (xBlank) { + xAmount = 0; + } else { + xAmount = newX - oldX; + } + + if (yBlank) { + yAmount = 0; + } else { + yAmount = newY - oldY; + } + + /* + * Move the object(s). + */ + + 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); + canvasPtr->flags |= REPICK_NEEDED; + } + } + break; + } case CANV_POSTSCRIPT: { const char **args = TkGetStringsFromObjs(objc, objv); @@ -1493,7 +1571,8 @@ CanvasWidgetCmd( double xOrigin, yOrigin, xScale, yScale; if (objc != 7) { - Tcl_WrongNumArgs(interp, 2, objv, "tagOrId xOrigin yOrigin xScale yScale"); + Tcl_WrongNumArgs(interp, 2, objv, + "tagOrId xOrigin yOrigin xScale yScale"); result = TCL_ERROR; goto done; } @@ -1501,8 +1580,8 @@ CanvasWidgetCmd( objv[3], &xOrigin) != TCL_OK) || (Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr, objv[4], &yOrigin) != TCL_OK) - || (Tcl_GetDoubleFromObj(interp, objv[5], &xScale) != TCL_OK) - || (Tcl_GetDoubleFromObj(interp, objv[6], &yScale) != TCL_OK)) { + || (Tcl_GetDoubleFromObj(interp, objv[5], &xScale)!=TCL_OK) + || (Tcl_GetDoubleFromObj(interp, objv[6], &yScale)!=TCL_OK)) { result = TCL_ERROR; goto done; } @@ -1513,8 +1592,8 @@ CanvasWidgetCmd( } FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto done) { EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr); - (void) (*itemPtr->typePtr->scaleProc)((Tk_Canvas) canvasPtr, - itemPtr, xOrigin, yOrigin, xScale, yScale); + itemPtr->typePtr->scaleProc((Tk_Canvas) canvasPtr, itemPtr, + xOrigin, yOrigin, xScale, yScale); EventuallyRedrawItem((Tk_Canvas) canvasPtr, itemPtr); canvasPtr->flags |= REPICK_NEEDED; } @@ -1600,8 +1679,8 @@ CanvasWidgetCmd( &index); } else { result = itemPtr->typePtr->indexProc(interp, - (Tk_Canvas) canvasPtr, itemPtr, Tcl_GetString(objv[4]), - &index); + (Tk_Canvas) canvasPtr, itemPtr, + Tcl_GetString(objv[4]), &index); } if (result != TCL_OK) { goto done; @@ -1688,8 +1767,8 @@ CanvasWidgetCmd( break; case CANV_XVIEW: { int count, type; - int newX = 0; /* Initialization needed only to prevent - * gcc warnings. */ + int newX = 0; /* Initialization needed only to prevent gcc + * warnings. */ double fraction; if (objc == 2) { @@ -1735,8 +1814,8 @@ CanvasWidgetCmd( } case CANV_YVIEW: { int count, type; - int newY = 0; /* Initialization needed only to prevent - * gcc warnings. */ + int newY = 0; /* Initialization needed only to prevent gcc + * warnings. */ double fraction; if (objc == 2) { @@ -1826,7 +1905,7 @@ DestroyCanvas( for (itemPtr = canvasPtr->firstItemPtr; itemPtr != NULL; itemPtr = canvasPtr->firstItemPtr) { canvasPtr->firstItemPtr = itemPtr->nextPtr; - (*itemPtr->typePtr->deleteProc)((Tk_Canvas) canvasPtr, itemPtr, + itemPtr->typePtr->deleteProc((Tk_Canvas) canvasPtr, itemPtr, canvasPtr->display); if (itemPtr->tagPtr != itemPtr->staticTagSpace) { ckfree((char *) itemPtr->tagPtr); @@ -2034,7 +2113,7 @@ CanvasWorldChanged( itemPtr = canvasPtr->firstItemPtr; for ( ; itemPtr != NULL; itemPtr = itemPtr->nextPtr) { - result = (*itemPtr->typePtr->configProc)(canvasPtr->interp, + result = itemPtr->typePtr->configProc(canvasPtr->interp, (Tk_Canvas) canvasPtr, itemPtr, 0, NULL, TK_CONFIG_ARGV_ONLY); if (result != TCL_OK) { @@ -2224,7 +2303,7 @@ DisplayCanvas( canvasPtr->canvas_state == TK_STATE_HIDDEN)) { continue; } - (*itemPtr->typePtr->displayProc)((Tk_Canvas) canvasPtr, itemPtr, + itemPtr->typePtr->displayProc((Tk_Canvas) canvasPtr, itemPtr, canvasPtr->display, pixmap, screenX1, screenY1, width, height); } @@ -2374,8 +2453,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); + itemPtr->typePtr->displayProc((Tk_Canvas) canvasPtr, itemPtr, + canvasPtr->display, None, 0, 0, 0, 0); } } } @@ -2514,8 +2593,8 @@ EventuallyRedrawItem( 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))) { + (itemPtr->x1 >= canvasPtr->xOrigin+Tk_Width(canvasPtr->tkwin)) || + (itemPtr->y1 >= canvasPtr->yOrigin+Tk_Height(canvasPtr->tkwin))) { if (!(itemPtr->typePtr->alwaysRedraw & 1)) { return; } @@ -2738,7 +2817,7 @@ StartTagSearch( if ((itemPtr == NULL) || (itemPtr->id != id) || (lastPtr == NULL) || (lastPtr->nextPtr != itemPtr)) { dispPtr->numSlowSearches++; - entryPtr = Tcl_FindHashEntry(&canvasPtr->idTable, (char *) id); + entryPtr = Tcl_FindHashEntry(&canvasPtr->idTable, (char*) id); if (entryPtr != NULL) { itemPtr = (Tk_Item *)Tcl_GetHashValue(entryPtr); lastPtr = itemPtr->prevPtr; @@ -3076,6 +3155,7 @@ TagSearchScan( * kept forever, but this should be thought of as a cache rather than as a * memory leak. */ + searchPtr->expr->uid = Tk_GetUid(tag); /* @@ -3087,8 +3167,8 @@ TagSearchScan( } /* - * Pre-scan tag for at least one unquoted "&&" "||" "^" "!" - * if not found then use string as simple tag + * Pre-scan tag for at least one unquoted "&&" "||" "^" "!"; if not found + * then use string as simple tag. */ for (i = 0; i < searchPtr->stringLength ; i++) { @@ -3165,7 +3245,7 @@ TagSearchScan( static void TagSearchDestroy( - TagSearch *searchPtr) /* Record describing tag search */ + TagSearch *searchPtr) /* Record describing tag search. */ { if (searchPtr) { TagSearchExprDestroy(searchPtr->expr); @@ -3196,15 +3276,15 @@ TagSearchDestroy( static int TagSearchScanExpr( Tcl_Interp *interp, /* Current interpreter. */ - TagSearch *searchPtr, /* Search data */ - TagSearchExpr *expr) /* compiled expression result */ + TagSearch *searchPtr, /* Search data. */ + TagSearchExpr *expr) /* Compiled expression result. */ { int looking_for_tag; /* When true, scanner expects next char(s) to - * be a tag, else operand expected */ - int found_tag; /* One or more tags found */ - int found_endquote; /* For quoted tag string parsing */ - int negate_result; /* Pending negation of next tag value */ - char *tag; /* Tag from tag expression string */ + * be a tag, else operand expected. */ + int found_tag; /* One or more tags found. */ + int found_endquote; /* For quoted tag string parsing. */ + int negate_result; /* Pending negation of next tag value. */ + char *tag; /* Tag from tag expression string. */ char c; SearchUids *searchUids; /* Collection of uids for basic search * expression terms. */ @@ -3219,36 +3299,33 @@ TagSearchScanExpr( if (expr->allocated == expr->index) { expr->allocated += 15; if (expr->uids) { - expr->uids = (Tk_Uid *) - ckrealloc((char *)(expr->uids), - (expr->allocated)*sizeof(Tk_Uid)); + expr->uids = (Tk_Uid *) ckrealloc((char *) expr->uids, + expr->allocated * sizeof(Tk_Uid)); } else { expr->uids = (Tk_Uid *) - ckalloc((expr->allocated)*sizeof(Tk_Uid)); + ckalloc(expr->allocated * sizeof(Tk_Uid)); } } if (looking_for_tag) { - switch (c) { - case ' ': /* ignore unquoted whitespace */ + case ' ': /* Ignore unquoted whitespace */ case '\t': case '\n': case '\r': break; - case '!': /* negate next tag or subexpr */ + case '!': /* Negate next tag or subexpr */ if (looking_for_tag > 1) { Tcl_AppendResult(interp, - "Too many '!' in tag search expression", - NULL); + "Too many '!' in tag search expression", NULL); return TCL_ERROR; } looking_for_tag++; negate_result = 1; break; - case '(': /* scan (negated) subexpr recursively */ + case '(': /* Scan (negated) subexpr recursively */ if (negate_result) { expr->uids[expr->index++] = searchUids->negparenUid; negate_result = 0; @@ -3267,7 +3344,7 @@ TagSearchScanExpr( found_tag = 1; break; - case '"': /* quoted tag string */ + case '"': /* Quoted tag string */ if (negate_result) { expr->uids[expr->index++] = searchUids->negtagvalUid; negate_result = 0; @@ -3287,13 +3364,13 @@ TagSearchScanExpr( } *tag++ = c; } - if (! found_endquote) { + if (!found_endquote) { Tcl_AppendResult(interp, "Missing endquote in tag search expression", NULL); return TCL_ERROR; } - if (! (tag - searchPtr->rewritebuffer)) { + if (!(tag - searchPtr->rewritebuffer)) { Tcl_AppendResult(interp, "Null quoted tag string in tag search expression", NULL); @@ -3306,7 +3383,7 @@ TagSearchScanExpr( found_tag = 1; break; - case '&': /* illegal chars when looking for tag */ + case '&': /* Illegal chars when looking for tag */ case '|': case '^': case ')': @@ -3315,7 +3392,7 @@ TagSearchScanExpr( NULL); return TCL_ERROR; - default: /* unquoted tag string */ + default: /* Unquoted tag string */ if (negate_result) { expr->uids[expr->index++] = searchUids->negtagvalUid; negate_result = 0; @@ -3362,48 +3439,46 @@ TagSearchScanExpr( found_tag = 1; } - } else { /* ! looking_for_tag */ + } else { /* ! looking_for_tag */ switch (c) { - case ' ': /* ignore whitespace */ + case ' ': /* Ignore whitespace */ case '\t': case '\n': case '\r': break; - case '&': /* AND operator */ + case '&': /* AND operator */ c = searchPtr->string[searchPtr->stringIndex++]; if (c != '&') { Tcl_AppendResult(interp, - "Singleton '&' in tag search expression", - NULL); + "Singleton '&' in tag search expression", NULL); return TCL_ERROR; } expr->uids[expr->index++] = searchUids->andUid; looking_for_tag = 1; break; - case '|': /* OR operator */ + case '|': /* OR operator */ c = searchPtr->string[searchPtr->stringIndex++]; if (c != '|') { Tcl_AppendResult(interp, - "Singleton '|' in tag search expression", - NULL); + "Singleton '|' in tag search expression", NULL); return TCL_ERROR; } expr->uids[expr->index++] = searchUids->orUid; looking_for_tag = 1; break; - case '^' : /* XOR operator */ + case '^': /* XOR operator */ expr->uids[expr->index++] = searchUids->xorUid; looking_for_tag = 1; break; - case ')' : /* end subexpression */ + case ')': /* End subexpression */ expr->uids[expr->index++] = searchUids->endparenUid; goto breakwhile; - default: /* syntax error */ + default: /* syntax error */ Tcl_AppendResult(interp, "Invalid boolean operator in tag search expression", NULL); @@ -3413,7 +3488,7 @@ TagSearchScanExpr( } breakwhile: - if (found_tag && ! looking_for_tag) { + if (found_tag && !looking_for_tag) { return TCL_OK; } Tcl_AppendResult(interp, "Missing tag in tag search expression", NULL); @@ -3453,7 +3528,7 @@ TagSearchEvalExpr( * expression terms. */ searchUids = GetStaticUids(); - result = 0; /* just to keep the compiler quiet */ + result = 0; /* Just to keep the compiler quiet. */ negate_result = 0; looking_for_tag = 1; @@ -3488,7 +3563,7 @@ TagSearchEvalExpr( result = 0; /* - * set result 1 if tag is found in item's tags + * set result 1 if tag is found in item's tags. */ for (tagPtr = itemPtr->tagPtr, count = itemPtr->numTags; @@ -3501,23 +3576,19 @@ TagSearchEvalExpr( } else if (uid == searchUids->parenUid) { /* - * Evaluate subexpressions with recursion + * Evaluate subexpressions with recursion. */ result = TagSearchEvalExpr(expr, itemPtr); } else if (uid == searchUids->negparenUid) { - negate_result = ! negate_result; + negate_result = !negate_result; /* - * Evaluate subexpressions with recursion + * Evaluate subexpressions with recursion. */ result = TagSearchEvalExpr(expr, itemPtr); -/* - * } else { - * assert(0); - */ } if (negate_result) { result = ! result; @@ -3566,16 +3637,12 @@ TagSearchEvalExpr( } else if (uid == searchUids->endparenUid) { return result; -/* - * } else { - * assert(0); - */ } looking_for_tag = 1; } } /* - * assert(! looking_for_tag); + * assert(!looking_for_tag); */ return result; } @@ -3664,7 +3731,7 @@ TagSearchFirst( uid = searchPtr->expr->uid; for (lastPtr = NULL, itemPtr = searchPtr->canvasPtr->firstItemPtr; - itemPtr != NULL; lastPtr = itemPtr, itemPtr = itemPtr->nextPtr) { + itemPtr != NULL; lastPtr=itemPtr, itemPtr=itemPtr->nextPtr) { for (tagPtr = itemPtr->tagPtr, count = itemPtr->numTags; count > 0; tagPtr++, count--) { if (*tagPtr == uid) { @@ -3675,13 +3742,12 @@ TagSearchFirst( } } } else { - /* * None of the above. Search for an item matching the tag expression. */ for (lastPtr = NULL, itemPtr = searchPtr->canvasPtr->firstItemPtr; - itemPtr != NULL; lastPtr = itemPtr, itemPtr = itemPtr->nextPtr) { + itemPtr != NULL; lastPtr=itemPtr, itemPtr=itemPtr->nextPtr) { searchPtr->expr->index = 0; if (TagSearchEvalExpr(searchPtr->expr, itemPtr)) { searchPtr->lastPtr = lastPtr; @@ -3767,7 +3833,7 @@ TagSearchNext( */ uid = searchPtr->expr->uid; - for (; itemPtr != NULL; lastPtr = itemPtr, itemPtr = itemPtr->nextPtr) { + for (; itemPtr != NULL; lastPtr=itemPtr, itemPtr=itemPtr->nextPtr) { for (tagPtr = itemPtr->tagPtr, count = itemPtr->numTags; count > 0; tagPtr++, count--) { if (*tagPtr == uid) { @@ -3996,14 +4062,15 @@ FindItems( Tcl_WrongNumArgs(interp, first+1, objv, "x y ?halo? ?start?"); return TCL_ERROR; } - if ((Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr, objv[first+1], - &coords[0]) != TCL_OK) || (Tk_CanvasGetCoordFromObj(interp, - (Tk_Canvas) canvasPtr, objv[first+2], &coords[1]) != TCL_OK)) { + if (Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr, + objv[first+1], &coords[0]) != TCL_OK + || Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr, + objv[first+2], &coords[1]) != TCL_OK) { return TCL_ERROR; } if (objc > first+3) { - if (Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr, objv[first+3], - &halo) != TCL_OK) { + if (Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr, + objv[first+3], &halo) != TCL_OK) { return TCL_ERROR; } if (halo < 0.0) { @@ -4045,7 +4112,7 @@ FindItems( if (itemPtr == NULL) { return TCL_OK; } - closestDist = (*itemPtr->typePtr->pointProc)((Tk_Canvas) canvasPtr, + closestDist = itemPtr->typePtr->pointProc((Tk_Canvas) canvasPtr, itemPtr, coords) - halo; if (closestDist < 0.0) { closestDist = 0.0; @@ -4088,7 +4155,7 @@ FindItems( || (itemPtr->y1 >= y2) || (itemPtr->y2 <= y1)) { continue; } - newDist = (*itemPtr->typePtr->pointProc)((Tk_Canvas) canvasPtr, + newDist = itemPtr->typePtr->pointProc((Tk_Canvas) canvasPtr, itemPtr, coords) - halo; if (newDist < 0.0) { newDist = 0.0; @@ -4169,11 +4236,11 @@ FindArea( if ((Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr, objv[0], &rect[0]) != TCL_OK) - || (Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr, objv[1], + || (Tk_CanvasGetCoordFromObj(interp,(Tk_Canvas)canvasPtr,objv[1], &rect[1]) != TCL_OK) - || (Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr, objv[2], + || (Tk_CanvasGetCoordFromObj(interp,(Tk_Canvas)canvasPtr,objv[2], &rect[2]) != TCL_OK) - || (Tk_CanvasGetCoordFromObj(interp, (Tk_Canvas) canvasPtr, objv[3], + || (Tk_CanvasGetCoordFromObj(interp,(Tk_Canvas)canvasPtr,objv[3], &rect[3]) != TCL_OK)) { return TCL_ERROR; } @@ -4189,21 +4256,22 @@ FindArea( * item-specific code except for items that are close. */ - x1 = (int) (rect[0]-1.0); - y1 = (int) (rect[1]-1.0); - x2 = (int) (rect[2]+1.0); - y2 = (int) (rect[3]+1.0); + x1 = (int) (rect[0] - 1.0); + y1 = (int) (rect[1] - 1.0); + x2 = (int) (rect[2] + 1.0); + y2 = (int) (rect[3] + 1.0); for (itemPtr = canvasPtr->firstItemPtr; itemPtr != NULL; itemPtr = itemPtr->nextPtr) { - if (itemPtr->state == TK_STATE_HIDDEN || (itemPtr->state == TK_STATE_NULL && - canvasPtr->canvas_state == TK_STATE_HIDDEN)) { + if (itemPtr->state == TK_STATE_HIDDEN || + (itemPtr->state == TK_STATE_NULL + && canvasPtr->canvas_state == TK_STATE_HIDDEN)) { continue; } if ((itemPtr->x1 >= x2) || (itemPtr->x2 <= x1) || (itemPtr->y1 >= y2) || (itemPtr->y2 <= y1)) { continue; } - if ((*itemPtr->typePtr->areaProc)((Tk_Canvas) canvasPtr, itemPtr, rect) + if (itemPtr->typePtr->areaProc((Tk_Canvas) canvasPtr, itemPtr, rect) >= enclosed) { DoItem(interp, itemPtr, uid); } @@ -4369,7 +4437,7 @@ CanvasBindProc( * current item while buttons are down. */ - if ((eventPtr->type == ButtonPress) || (eventPtr->type == ButtonRelease)) { + if (eventPtr->type == ButtonPress || eventPtr->type == ButtonRelease) { int mask; switch (eventPtr->xbutton.button) { @@ -4520,11 +4588,11 @@ PickCurrentItem( canvasPtr->pickEvent.xcrossing.y_root = eventPtr->xmotion.y_root; canvasPtr->pickEvent.xcrossing.mode = NotifyNormal; canvasPtr->pickEvent.xcrossing.detail = NotifyNonlinear; - canvasPtr->pickEvent.xcrossing.same_screen - = eventPtr->xmotion.same_screen; + canvasPtr->pickEvent.xcrossing.same_screen = + eventPtr->xmotion.same_screen; canvasPtr->pickEvent.xcrossing.focus = False; canvasPtr->pickEvent.xcrossing.state = eventPtr->xmotion.state; - } else { + } else { canvasPtr->pickEvent = *eventPtr; } } @@ -4556,7 +4624,7 @@ PickCurrentItem( if ((canvasPtr->newCurrentPtr == canvasPtr->currentItemPtr) && !(canvasPtr->flags & LEFT_GRABBED_ITEM)) { /* - * Nothing to do: the current item hasn't changed. + * Nothing to do: the current item hasn't changed. */ return; @@ -4619,7 +4687,7 @@ PickCurrentItem( * deleted. */ } - if ((canvasPtr->newCurrentPtr != canvasPtr->currentItemPtr) && buttonDown) { + if ((canvasPtr->newCurrentPtr!=canvasPtr->currentItemPtr) && buttonDown) { canvasPtr->flags |= LEFT_GRABBED_ITEM; return; } @@ -4636,7 +4704,7 @@ PickCurrentItem( if (prevItemPtr != NULL && prevItemPtr != canvasPtr->currentItemPtr && (prevItemPtr->redraw_flags & TK_ITEM_STATE_DEPENDANT)) { EventuallyRedrawItem((Tk_Canvas) canvasPtr, prevItemPtr); - (*prevItemPtr->typePtr->configProc)(canvasPtr->interp, + prevItemPtr->typePtr->configProc(canvasPtr->interp, (Tk_Canvas) canvasPtr, prevItemPtr, 0, NULL, TK_CONFIG_ARGV_ONLY); } @@ -4650,7 +4718,7 @@ PickCurrentItem( #endif /* USE_OLD_TAG_SEA */ if ((canvasPtr->currentItemPtr->redraw_flags & TK_ITEM_STATE_DEPENDANT && prevItemPtr != canvasPtr->currentItemPtr)) { - (*canvasPtr->currentItemPtr->typePtr->configProc)(canvasPtr->interp, + canvasPtr->currentItemPtr->typePtr->configProc(canvasPtr->interp, (Tk_Canvas) canvasPtr, canvasPtr->currentItemPtr, 0, NULL, TK_CONFIG_ARGV_ONLY); EventuallyRedrawItem((Tk_Canvas) canvasPtr, @@ -4700,8 +4768,10 @@ CanvasFindClosest( bestPtr = NULL; for (itemPtr = canvasPtr->firstItemPtr; itemPtr != NULL; itemPtr = itemPtr->nextPtr) { - if (itemPtr->state == TK_STATE_HIDDEN || itemPtr->state==TK_STATE_DISABLED || - (itemPtr->state == TK_STATE_NULL && (canvasPtr->canvas_state == TK_STATE_HIDDEN || + if (itemPtr->state == TK_STATE_HIDDEN || + itemPtr->state==TK_STATE_DISABLED || + (itemPtr->state == TK_STATE_NULL && + (canvasPtr->canvas_state == TK_STATE_HIDDEN || canvasPtr->canvas_state == TK_STATE_DISABLED))) { continue; } @@ -4709,8 +4779,8 @@ CanvasFindClosest( || (itemPtr->y1 > y2) || (itemPtr->y2 < y1)) { continue; } - if ((*itemPtr->typePtr->pointProc)((Tk_Canvas) canvasPtr, - itemPtr, coords) <= canvasPtr->closeEnough) { + if (itemPtr->typePtr->pointProc((Tk_Canvas) canvasPtr, itemPtr, + coords) <= canvasPtr->closeEnough) { bestPtr = itemPtr; } } @@ -5042,7 +5112,7 @@ CanvasFetchSelection( if (canvasPtr->textInfo.selItemPtr->typePtr->selectionProc == NULL) { return -1; } - return (*canvasPtr->textInfo.selItemPtr->typePtr->selectionProc)( + return canvasPtr->textInfo.selItemPtr->typePtr->selectionProc( (Tk_Canvas) canvasPtr, canvasPtr->textInfo.selItemPtr, offset, buffer, maxBytes); } @@ -5221,7 +5291,7 @@ CanvasUpdateScrollbars( Tcl_Obj *fractions = ScrollFractions(xOrigin + inset, xOrigin + width - inset, scrollX1, scrollX2); - result = Tcl_VarEval(interp, xScrollCmd, " ", Tcl_GetString(fractions), + result = Tcl_VarEval(interp, xScrollCmd," ",Tcl_GetString(fractions), NULL); Tcl_DecrRefCount(fractions); if (result != TCL_OK) { @@ -5235,7 +5305,7 @@ CanvasUpdateScrollbars( Tcl_Obj *fractions = ScrollFractions(yOrigin + inset, yOrigin + height - inset, scrollY1, scrollY2); - result = Tcl_VarEval(interp, yScrollCmd, " ", Tcl_GetString(fractions), + result = Tcl_VarEval(interp, yScrollCmd," ",Tcl_GetString(fractions), NULL); Tcl_DecrRefCount(fractions); if (result != TCL_OK) { @@ -5310,11 +5380,11 @@ CanvasSetOrigin( * Adjust the origin if necessary to keep as much as possible of the * canvas in the view. The variables left, right, etc. keep track of how * much extra space there is on each side of the view before it will stick - * out past the scroll region. If one side sticks out past the edge of - * the scroll region, adjust the view to bring that side back to the edge - * of the scrollregion (but don't move it so much that the other side - * sticks out now). If scroll increments are in effect, be sure to adjust - * only by full increments. + * out past the scroll region. If one side sticks out past the edge of the + * scroll region, adjust the view to bring that side back to the edge of + * the scrollregion (but don't move it so much that the other side sticks + * out now). If scroll increments are in effect, be sure to adjust only by + * full increments. */ if ((canvasPtr->confine) && (canvasPtr->regionString != NULL)) { |