summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvincentdarley <vincentdarley>2004-06-04 10:51:17 (GMT)
committervincentdarley <vincentdarley>2004-06-04 10:51:17 (GMT)
commitcb21b14adfd9b6e4f015d1d0acf252db71daea6a (patch)
treed72800bda1f80884a0368bed786b3e88820147df
parent1b67bc3f8c30be0bf1d37e5c56f7effc8483e86b (diff)
downloadtk-cb21b14adfd9b6e4f015d1d0acf252db71daea6a.zip
tk-cb21b14adfd9b6e4f015d1d0acf252db71daea6a.tar.gz
tk-cb21b14adfd9b6e4f015d1d0acf252db71daea6a.tar.bz2
text widget fixes
-rw-r--r--ChangeLog14
-rw-r--r--doc/text.n22
-rw-r--r--generic/tkText.c7
-rw-r--r--generic/tkTextDisp.c32
-rw-r--r--generic/tkTextIndex.c10
-rw-r--r--library/text.tcl7
-rw-r--r--tests/textDisp.test8
7 files changed, 77 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index 5ed1658..089cfed 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2004-06-04 Vince Darley <vincentdarley@users.sourceforge.net>
+
+ * generic/tkTextIndex.c:
+ * generic/tkText.c:
+ * generic/tkTextDisp.c:
+ * doc/text.n: fix to shimmering infinite loop scrolling problem
+ in text widget under some rare circumstances (Bug 965398).
+ Improved comments and documentation.
+
+ * tests/textDisp.test: corrected rounding from float to int
+ in test, fixing occasional failures
+
+ * library/text.tcl: corrected mousewheel bindings for TkAqua
+
2004-05-29 Joe English <jenglish@users.sourceforge.net>
* doc/messageBox.n: Fix minor markup errors (backslash
diff --git a/doc/text.n b/doc/text.n
index 35aa860..062254d 100644
--- a/doc/text.n
+++ b/doc/text.n
@@ -5,7 +5,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: text.n,v 1.25 2004/03/04 00:17:07 hobbs Exp $
+'\" RCS: @(#) $Id: text.n,v 1.26 2004/06/04 10:51:17 vincentdarley Exp $
'\"
.so man.macros
.TH text n 8.5 Tk "Tk Built-In Commands"
@@ -1706,21 +1706,27 @@ It can take any of the following forms:
\fIpathName \fByview\fR
Returns a list containing two elements, both of which are real fractions
between 0 and 1.
-The first element gives the position of the first character in the
+The first element gives the position of the first visible pixel of the
+first character (or image, etc) in the
top line in the window, relative to the text as a whole (0.5 means
it is halfway through the text, for example).
-The second element gives the position of the character just after
-the last one in the bottom line of the window,
+The second element gives the position of the first pixel just after the
+last visible one in the bottom line of the window,
relative to the text as a whole.
These are the same values passed to scrollbars via the \fB\-yscrollcommand\fR
option.
.TP
\fIpathName \fByview moveto\fI fraction\fR
-Adjusts the view in the window so that the character given by \fIfraction\fR
-appears on the top line of the window.
+Adjusts the view in the window so that the pixel given by \fIfraction\fR
+appears at the top of the top line of the window.
\fIFraction\fR is a fraction between 0 and 1; 0 indicates the first
-character in the text, 0.33 indicates the character one-third the
-way through the text, and so on.
+pixel of the first character in the text, 0.33 indicates the pixel that is
+one-third the way through the text; and so on. Values close to 1 will
+indicate values close to the last pixel in the text (1 actually refers
+to one pixel beyond the last pixel), but in such cases the widget will
+never scroll beyond the last pixel, and so a value of 1 will effectively
+be rounded back to whatever fraction ensures the last pixel is at the
+bottom of the window, and some other pixel is at the top.
.TP
\fIpathName \fByview scroll \fInumber what\fR
This command adjust the view in the window up or down according to
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);
diff --git a/library/text.tcl b/library/text.tcl
index d038002..7b181b1 100644
--- a/library/text.tcl
+++ b/library/text.tcl
@@ -3,7 +3,7 @@
# This file defines the default bindings for Tk text widgets and provides
# procedures that help in implementing the bindings.
#
-# RCS: @(#) $Id: text.tcl,v 1.30 2004/03/17 18:15:45 das Exp $
+# RCS: @(#) $Id: text.tcl,v 1.31 2004/06/04 10:51:18 vincentdarley Exp $
#
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
@@ -457,7 +457,10 @@ bind Text <MouseWheel> {
}
if {[string equal [tk windowingsystem] "aqua"]} {
bind Text <Option-MouseWheel> {
- %W yview scroll [expr {- 10*%D}] pixels
+ %W yview scroll [expr {-150 * %D}] pixels
+}
+bind Text <MouseWheel> {
+ %W yview scroll [expr {-15 * %D}] pixels
}
}
diff --git a/tests/textDisp.test b/tests/textDisp.test
index f2a7803..3205ddb 100644
--- a/tests/textDisp.test
+++ b/tests/textDisp.test
@@ -6,7 +6,7 @@
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
-# RCS: @(#) $Id: textDisp.test,v 1.25 2004/05/23 17:34:49 dkf Exp $
+# RCS: @(#) $Id: textDisp.test,v 1.26 2004/06/04 10:51:18 vincentdarley Exp $
package require tcltest 2.1
eval tcltest::configure $argv
@@ -3153,8 +3153,10 @@ test textDisp-27.7 {SizeOfTab procedure, center alignment, wrap -none (potential
set tab [expr {$tab + $cm}]
}
# Now we've calculated to the end of the tab after 'a', add one
- # more for 'bb\t' and we're there, with 4 for the border
- set tab [expr {4 + int($tab + $cm)}]
+ # more for 'bb\t' and we're there, with 4 for the border. Since
+ # Tk_GetPixelsFromObj uses the standard 'int(0.5 + float)' rounding,
+ # so must we.
+ set tab [expr {4 + int(0.5 + $tab + $cm)}]
update
set res [.t bbox 2.23]
lset res 0 [expr {[lindex $res 0] - $tab}]