summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvincentdarley <vincentdarley>2003-11-15 16:57:57 (GMT)
committervincentdarley <vincentdarley>2003-11-15 16:57:57 (GMT)
commit3ee6271dc8db892b1d6a9fb9b18ff75aa59e5c90 (patch)
tree1f1eba40232a626bc6bf40c37acd1a111fc449f6
parentcfd7d12d4a0827d30a37fc3fedcc0750d6d693d3 (diff)
downloadtk-3ee6271dc8db892b1d6a9fb9b18ff75aa59e5c90.zip
tk-3ee6271dc8db892b1d6a9fb9b18ff75aa59e5c90.tar.gz
tk-3ee6271dc8db892b1d6a9fb9b18ff75aa59e5c90.tar.bz2
single line wraps to whole display fix
-rw-r--r--ChangeLog4
-rw-r--r--generic/tkTextDisp.c51
-rw-r--r--tests/textDisp.test23
3 files changed, 71 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 6abbb11..47cc504 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,9 @@
* generic/tkTextDisp.c:
* tests/textDisp.test: fixes to one more old Tk [Bug 422411]
- this time concerning inconsistent tab interpretation.
+ this time concerning inconsistent tab interpretation. Also
+ fixed an unreported new problem if a single logical line wraps
+ to fill more than the entire display.
2003-11-14 Joe English <jenglish@users.sourceforge.net>
* doc/text.n: Fix markup errors.
diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c
index 040c907..a3e311d 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.31 2003/11/15 12:47:15 vincentdarley Exp $
+ * RCS: @(#) $Id: tkTextDisp.c,v 1.32 2003/11/15 16:57:57 vincentdarley Exp $
*/
#include "tkPort.h"
@@ -5286,6 +5286,13 @@ GetXView(interp, textPtr, report)
*
* How many pixels are there between the absolute top of the
* widget and the top of the given DLine.
+ *
+ * This is only ever called when dlPtr is the first display
+ * line in the widget (by 'GetYView'). We have to be careful
+ * if dlPtr's logical line wraps enough times to fill the
+ * text widget's current view -- in this case we won't have
+ * enough dlPtrs in the linked list to be able to subtract off
+ * what we want.
*
* Results:
* The number of pixels.
@@ -5307,7 +5314,17 @@ GetPixelCount(textPtr, dlPtr)
* Get the pixel count of one pixel beyond the
* botton of the given line.
*/
- int count = TkBTreePixels(linePtr) + linePtr->pixelHeight;
+ int count = TkBTreePixels(linePtr);
+
+ /*
+ * For the common case where this dlPtr is also the start of
+ * the logical line, we can return right away.
+ */
+ if (dlPtr->index.byteIndex == 0) {
+ return count;
+ }
+
+ count += linePtr->pixelHeight;
/*
* Now we have to subtract off the distance between the top of this
@@ -5315,8 +5332,32 @@ GetPixelCount(textPtr, dlPtr)
*/
do {
count -= dlPtr->height;
- dlPtr = dlPtr->nextPtr;
- } while (dlPtr != NULL && (dlPtr->index.linePtr == linePtr));
+ if (dlPtr->nextPtr == NULL) {
+ /* We've run out of lines */
+ TkTextIndex index;
+ DLine *dlPrev = NULL;
+ while (1) {
+ TkTextIndexForwBytes(&dlPtr->index, dlPtr->byteCount, &index);
+ if (index.linePtr != linePtr) {
+ break;
+ }
+ if (dlPrev != NULL) {
+ FreeDLines(textPtr, dlPrev, (DLine *) NULL,
+ DLINE_FREE_TEMP);
+ }
+ dlPtr = LayoutDLine(textPtr, &index);
+ dlPrev = dlPtr;
+ count -= dlPtr->height;
+ }
+ if (dlPrev != NULL) {
+ FreeDLines(textPtr, dlPrev, (DLine *) NULL,
+ DLINE_FREE_TEMP);
+ }
+ break;
+ } else {
+ dlPtr = dlPtr->nextPtr;
+ }
+ } while (dlPtr->index.linePtr == linePtr);
return count;
}
@@ -5374,7 +5415,7 @@ GetYView(interp, textPtr, report)
last = 1.0;
} else {
/*
- * Get the pixel count for the first display visible pixel of the
+ * Get the pixel count for the first visible pixel of the
* first visible line. If the first visible line is only
* partially visible, then we use 'topPixelOffset' to get the
* difference.
diff --git a/tests/textDisp.test b/tests/textDisp.test
index bb60912..4fad84b 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.19 2003/11/15 12:47:15 vincentdarley Exp $
+# RCS: @(#) $Id: textDisp.test,v 1.20 2003/11/15 16:57:57 vincentdarley Exp $
package require tcltest 2.1
eval tcltest::configure $argv
@@ -3492,6 +3492,27 @@ test textDisp-32.1 {everything elided} {
destroy .tt
} {}
+test textDisp-33.0 {one line longer than fits in the widget} {
+ pack [text .tt -wrap char]
+ .tt insert 1.0 [string repeat "hello there " 2500]
+ update ; update ; update
+ .tt see 1.0
+ lindex [.tt yview] 0
+} {0.0}
+
+test textDisp-33.1 {one line longer than fits in the widget} {
+ destroy .tt
+ pack [text .tt -wrap char]
+ .tt insert 1.0 [string repeat "hello there " 2500]
+ update ; update ; update
+ .tt yview "1.0 +1 displaylines"
+ if {[lindex [.tt yview] 0] > 0.1} {
+ set result "bad result"
+ } else {
+ set result "ok"
+ }
+} {ok}
+
deleteWindows
option clear