diff options
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tkText.c | 7 | ||||
-rw-r--r-- | generic/tkTextDisp.c | 32 | ||||
-rw-r--r-- | generic/tkTextIndex.c | 10 |
3 files changed, 39 insertions, 10 deletions
diff --git a/generic/tkText.c b/generic/tkText.c index bd417d0..01a09f9 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -14,7 +14,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkText.c,v 1.49 2004/03/17 18:15:44 das Exp $ + * RCS: @(#) $Id: tkText.c,v 1.50 2004/06/04 10:51:18 vincentdarley Exp $ */ #include "default.h" @@ -3361,6 +3361,11 @@ TkTextGetTabs(interp, textPtr, stringPtr) for (i = 0, tabPtr = &tabArrayPtr->tabs[0]; i < objc; i++, tabPtr++) { int index; + /* + * This will round fractional pixels above 0.5 upwards, and + * otherwise downwards, to find the right integer pixel + * position. + */ if (Tk_GetPixelsFromObj(interp, textPtr->tkwin, objv[i], &tabPtr->location) != TCL_OK) { goto error; diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index 027bba9..6dfe0a2 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.c @@ -13,7 +13,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkTextDisp.c,v 1.40 2004/01/13 02:06:00 davygrvy Exp $ + * RCS: @(#) $Id: tkTextDisp.c,v 1.41 2004/06/04 10:51:18 vincentdarley Exp $ */ #include "tkPort.h" @@ -4402,7 +4402,7 @@ TkTextSetYView(textPtr, indexPtr, pickPlace) indexPtr = &rounded; } - if (pickPlace == -2) { + if (pickPlace == TK_TEXT_NOPIXELADJUST) { if (textPtr->topIndex.linePtr == indexPtr->linePtr && textPtr->topIndex.byteIndex == indexPtr->byteIndex) { pickPlace = dInfoPtr->topPixelOffset; @@ -4411,7 +4411,7 @@ TkTextSetYView(textPtr, indexPtr, pickPlace) } } - if (pickPlace != -1) { + if (pickPlace != TK_TEXT_PICKPLACE) { /* * The specified position must go at the top of the screen. * Just leave all the DLine's alone: we may be able to reuse @@ -5195,6 +5195,7 @@ TkTextYviewCmd(textPtr, interp, objc, objv) return TCL_ERROR; case TKTEXT_SCROLL_MOVETO: { int numPixels = TkBTreeNumPixels(textPtr->tree); + int topMostPixel; if (numPixels == 0) { /* * If the window is totally empty no scrolling is @@ -5209,15 +5210,24 @@ TkTextYviewCmd(textPtr, interp, objc, objv) if (fraction < 0) { fraction = 0; } - fraction *= (numPixels - 1); + /* + * Calculate the pixel count for the new topmost pixel + * in the topmost line of the window. Note that the + * interpretation of 'fraction' is that it counts from + * 0 (top pixel in buffer) to 1.0 (one pixel past the + * last pixel in buffer). + */ + topMostPixel = (int) (0.5 + fraction * numPixels); + if (topMostPixel >= numPixels) { + topMostPixel = numPixels -1; + } /* * This function returns the number of pixels by which the * given line should overlap the top of the visible screen. * * This is then used to provide smooth scrolling. */ - pixels = TkTextMakePixelIndex(textPtr, - (int) (0.5 + fraction), &index); + pixels = TkTextMakePixelIndex(textPtr, topMostPixel, &index); TkTextSetYView(textPtr, &index, pixels); break; } @@ -5473,6 +5483,10 @@ GetXView(interp, textPtr, report) * * Results: * The number of pixels. + * + * This value has a valid range between '0' (the very top of the + * widget) and the number of pixels in the total widget minus the + * pixel-height of the last line. * * Side effects: * None. @@ -5632,7 +5646,9 @@ GetYView(interp, textPtr, report) /* * Add on the total number of visible pixels to get the count to - * the last visible pixel. + * one pixel _past_ the last visible pixel. This is how the + * 'yview' command is documented, and also explains why we are + * dividing by 'totalPixels' and not 'totalPixels-1'. */ while (1) { int extra; @@ -5689,7 +5705,7 @@ GetYView(interp, textPtr, report) count = totalPixels; } - last = ((double) (count))/((double)totalPixels); + last = ((double) count)/((double)totalPixels); } if (!report) { diff --git a/generic/tkTextIndex.c b/generic/tkTextIndex.c index 41702f1..44deddd 100644 --- a/generic/tkTextIndex.c +++ b/generic/tkTextIndex.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: tkTextIndex.c,v 1.17 2004/02/28 16:04:43 vincentdarley Exp $ + * RCS: @(#) $Id: tkTextIndex.c,v 1.18 2004/06/04 10:51:18 vincentdarley Exp $ */ #include "default.h" @@ -286,6 +286,10 @@ TkTextNewIndexObj(textPtr, indexPtr) * * Given a pixel index and a byte index, look things up in the B-tree * and fill in a TkTextIndex structure. + * + * The valid input range for pixelIndex is from 0 to the number + * of pixels in the widget-1. Anything outside that range will + * be rounded to the closest acceptable value. * * Results: * @@ -321,6 +325,10 @@ TkTextMakePixelIndex(textPtr, pixelIndex, indexPtr) } indexPtr->linePtr = TkBTreeFindPixelLine(textPtr->tree, pixelIndex, &pixelOffset); + /* + * 'pixedlIndex' was too large, so we try again, just to find + * the last pixel in the window + */ if (indexPtr->linePtr == NULL) { indexPtr->linePtr = TkBTreeFindPixelLine(textPtr->tree, TkBTreeNumPixels(textPtr->tree)-1, &pixelOffset); |