summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-08-22 15:02:23 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-08-22 15:02:23 (GMT)
commit127c180c66bf291cae359b4c83fcfce3961af8be (patch)
tree75c30064dcd65da3c0b1a72f00f0985cee83c720
parente1486d48b18bdd738d42c22f61f597b17ea02fc4 (diff)
downloadtk-127c180c66bf291cae359b4c83fcfce3961af8be.zip
tk-127c180c66bf291cae359b4c83fcfce3961af8be.tar.gz
tk-127c180c66bf291cae359b4c83fcfce3961af8be.tar.bz2
Allow using floating-point number in "scroll (x|y)view (units|pages)". They are rounded away from zero towards an integer.
-rw-r--r--doc/GetScroll.33
-rw-r--r--doc/canvas.n3
-rw-r--r--doc/entry.n3
-rw-r--r--doc/listbox.n3
-rw-r--r--doc/spinbox.n3
-rw-r--r--doc/text.n14
-rw-r--r--doc/ttk_widget.n3
-rw-r--r--generic/tkTextDisp.c11
-rw-r--r--library/listbox.tcl8
-rw-r--r--library/scrlbar.tcl8
-rw-r--r--library/ttk/utils.tcl12
-rw-r--r--tests/entry.test2
-rw-r--r--tests/spinbox.test2
-rw-r--r--tests/textDisp.test8
-rw-r--r--tests/util.test2
15 files changed, 48 insertions, 37 deletions
diff --git a/doc/GetScroll.3 b/doc/GetScroll.3
index dd12cca..d61e744 100644
--- a/doc/GetScroll.3
+++ b/doc/GetScroll.3
@@ -62,7 +62,8 @@ is returned as result and \fI*fractionPtr\fR is filled in with the
value.
If \fIobjv\fR has the \fBscroll\fR form, \fBTK_SCROLL_PAGES\fR
or \fBTK_SCROLL_UNITS\fR is returned and \fI*stepsPtr\fR is filled
-in with the \fInumber\fR value, which must be a proper integer.
+in with the \fInumber\fR value, which must be a integer or a float,
+but if it is a float then it is converted to an integer, rounded away from 0.
If an error occurs in parsing the arguments, \fBTK_SCROLL_ERROR\fR
is returned and an error message is left in interpreter
\fIinterp\fR's result.
diff --git a/doc/canvas.n b/doc/canvas.n
index ddaebcf..95c732e 100644
--- a/doc/canvas.n
+++ b/doc/canvas.n
@@ -1146,7 +1146,8 @@ total width of the canvas is off-screen to the left.
.
This command shifts the view in the window left or right according to
\fInumber\fR and \fIwhat\fR.
-\fINumber\fR must be an integer.
+\fINumber\fR must be an integer or a float, but if it is a float then
+it is converted to an integer, rounded away from 0.
\fIWhat\fR must be either \fBpages\fR or \fBunits\fR or an abbreviation
of one of these.
If \fIwhat is \fBpages\fR then the view
diff --git a/doc/entry.n b/doc/entry.n
index 4589af0..dd198a7 100644
--- a/doc/entry.n
+++ b/doc/entry.n
@@ -403,7 +403,8 @@ way through the text appears at the left edge of the window.
\fIpathName \fBxview scroll \fInumber what\fR
This command shifts the view in the window left or right according to
\fInumber\fR and \fIwhat\fR.
-\fINumber\fR must be an integer.
+\fINumber\fR must be an integer or a float, but if it is a float then
+it is converted to an integer, rounded away from 0.
\fIWhat\fR must be either \fBpages\fR or \fBunits\fR or an abbreviation
of one of these.
If \fIwhat\fR is \fBpages\fR then the view adjusts by \fInumber\fR screenfuls.
diff --git a/doc/listbox.n b/doc/listbox.n
index ef3ae1c..c2ff09e 100644
--- a/doc/listbox.n
+++ b/doc/listbox.n
@@ -383,7 +383,8 @@ total width of the listbox text is off-screen to the left.
.
This command shifts the view in the window left or right according to
\fInumber\fR and \fIwhat\fR.
-\fINumber\fR must be an integer.
+\fINumber\fR must be an integer or a float, but if it is a float then
+it is converted to an integer, rounded away from 0.
\fIWhat\fR must be either \fBpages\fR or \fBunits\fR or an abbreviation
of one of these.
If \fIwhat\fR is \fBpages\fR then the view adjusts by
diff --git a/doc/spinbox.n b/doc/spinbox.n
index 6719ca3..6d0646b 100644
--- a/doc/spinbox.n
+++ b/doc/spinbox.n
@@ -470,7 +470,8 @@ way through the text appears at the left edge of the window.
\fIpathName \fBxview scroll \fInumber what\fR
This command shifts the view in the window left or right according to
\fInumber\fR and \fIwhat\fR.
-\fINumber\fR must be an integer.
+\fINumber\fR must be an integer or a float, but if it is a float then
+it is converted to an integer, rounded away from 0.
\fIWhat\fR must be either \fBpages\fR or \fBunits\fR or an abbreviation
of one of these.
If \fIwhat\fR is \fBpages\fR then the view adjusts by \fInumber\fR
diff --git a/doc/text.n b/doc/text.n
index 95a4272..c4128a1 100644
--- a/doc/text.n
+++ b/doc/text.n
@@ -1930,8 +1930,8 @@ and 1.
\fIpathName \fBxview scroll \fInumber what\fR
.
This command shifts the view in the window left or right according to
-\fInumber\fR and \fIwhat\fR. \fIWhat\fR must be \fBmouseunits\fR, \fBpages\fR,
-\fBpixels\fR, or \fBunits\fR. If \fIwhat\fR is \fBmouseunits\fR, \fBpages\fR or
+\fInumber\fR and \fIwhat\fR. \fIWhat\fR must be \fBpages\fR,
+\fBpixels\fR, or \fBunits\fR. If \fIwhat\fR is \fBpages\fR or
\fBunits\fR then \fInumber\fR must be an integer, otherwise number may be
specified in any of the forms acceptable to \fBTk_GetPixels\fR, such as
.QW 2.0c
@@ -1943,9 +1943,7 @@ pixels are assumed). If \fIwhat\fR is \fBpages\fR then the view adjusts by
\fInumber\fR pixels; if it is \fBunits\fR, the view adjusts left or
right by \fInumber\fR average-width characters on the display. If \fInumber\fR is
negative then characters farther to the left become visible; if it is positive
-then characters farther to the right become visible. If \fIwhat\fR is
-\fBmouseunits\fR then the view adjusts about -\fInumber\fR/3 pixels, since
-mouse units work in the other direction than pixels.
+then characters farther to the right become visible.
.RE
.TP
\fIpathName \fByview \fR?\fIargs\fR?
@@ -1980,7 +1978,7 @@ the bottom of the window, and some other pixel is at the top.
\fIpathName \fByview scroll \fInumber what\fR
.
This command adjust the view in the window up or down according to
-\fInumber\fR and \fIwhat\fR. \fIWhat\fR must be \fBmouseunits\fR, \fBpages\fR,
+\fInumber\fR and \fIwhat\fR. \fIWhat\fR must be \fBpages\fR,
\fBpixels\fR, or \fBunits\fR. If \fIwhat\fR is \fBunits\fR or \fBpages\fR then
\fInumber\fR must be an integer, otherwise number may be specified in any of
the forms acceptable to \fBTk_GetPixels\fR, such as
@@ -1993,9 +1991,7 @@ by \fInumber\fR lines on the display; if it is \fBpages\fR then the view
adjusts by \fInumber\fR screenfuls; if it is \fBpixels\fR then the view
adjusts by \fInumber\fR pixels. If \fInumber\fR is negative then earlier
positions in the text become visible; if it is positive then later positions
-in the text become visible. If \fIwhat\fR is \fBmouseunits\fR then the view
-adjusts about -\fInumber\fR/3 pixels, since mouse units work in the other
-direction than pixels.
+in the text become visible.
.TP
\fIpathName \fByview \fR?\fB\-pickplace\fR? \fIindex\fR
.
diff --git a/doc/ttk_widget.n b/doc/ttk_widget.n
index 2dca269..fdacfd0 100644
--- a/doc/ttk_widget.n
+++ b/doc/ttk_widget.n
@@ -253,7 +253,8 @@ way through the content appears at the left edge of the window.
\fIpathName \fBxview scroll \fInumber what\fR
This command shifts the view in the window left or right according to
\fInumber\fR and \fIwhat\fR.
-\fINumber\fR must be an integer.
+\fINumber\fR must be an integer or a float, but if it is a float then
+it is converted to an integer, rounded away from 0.
\fIWhat\fR must be either \fBpages\fR or \fBunits\fR.
'\" or an abbreviation of one of these, but we don't document that.
If \fIwhat\fR is
diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c
index 33b9720..e6dc988 100644
--- a/generic/tkTextDisp.c
+++ b/generic/tkTextDisp.c
@@ -8776,6 +8776,7 @@ TextGetScrollInfoObj(
VIEW_SCROLL_PAGES, VIEW_SCROLL_PIXELS, VIEW_SCROLL_UNITS
};
int index;
+ double d;
if (Tcl_GetIndexFromObjStruct(interp, objv[2], subcommands,
sizeof(char *), "option", 0, &index) != TCL_OK) {
@@ -8814,9 +8815,17 @@ TextGetScrollInfoObj(
}
return TKTEXT_SCROLL_PIXELS;
case VIEW_SCROLL_UNITS:
- if (Tcl_GetIntFromObj(interp, objv[3], intPtr) != TCL_OK) {
+ if (Tcl_GetDoubleFromObj(interp, objv[3], &d) != TCL_OK) {
return TKTEXT_SCROLL_ERROR;
}
+ if (d > 0) {
+ *intPtr = ceil(d);
+ } else {
+ *intPtr = floor(d);
+ }
+ if (dblPtr) {
+ *dblPtr = d;
+ }
return TKTEXT_SCROLL_UNITS;
}
}
diff --git a/library/listbox.tcl b/library/listbox.tcl
index 4a76a18..7400494 100644
--- a/library/listbox.tcl
+++ b/library/listbox.tcl
@@ -177,16 +177,16 @@ bind Listbox <B2-Motion> {
}
bind Listbox <MouseWheel> {
- %W yview scroll [expr {-(%D/30)}] units
+ %W yview scroll [expr {%D/-30}] units
}
bind Listbox <Option-MouseWheel> {
- %W yview scroll [expr {-(%D/3)}] units
+ %W yview scroll [expr {%D/-3}] units
}
bind Listbox <Shift-MouseWheel> {
- %W xview scroll [expr {-(%D/30)}] units
+ %W xview scroll [expr {%D/-30}] units
}
bind Listbox <Shift-Option-MouseWheel> {
- %W xview scroll [expr {-(%D/3)}] units
+ %W xview scroll [expr {%D/-3}] units
}
# ::tk::ListboxBeginSelect --
diff --git a/library/scrlbar.tcl b/library/scrlbar.tcl
index d797b24..2b3503a 100644
--- a/library/scrlbar.tcl
+++ b/library/scrlbar.tcl
@@ -130,16 +130,16 @@ bind Scrollbar <<LineEnd>> {
}
bind Scrollbar <MouseWheel> {
- tk::ScrollByUnits %W v [expr {-(%D / 30)}]
+ tk::ScrollByUnits %W v [expr {%D/-30.0}]
}
bind Scrollbar <Option-MouseWheel> {
- tk::ScrollByUnits %W v [expr {-(%D / 3)}]
+ tk::ScrollByUnits %W v [expr {%D/-3.0}]
}
bind Scrollbar <Shift-MouseWheel> {
- tk::ScrollByUnits %W h [expr {-(%D / 30)}]
+ tk::ScrollByUnits %W h [expr {%D/-30.0}]
}
bind Scrollbar <Shift-Option-MouseWheel> {
- tk::ScrollByUnits %W h [expr {-(%D / 3)}]
+ tk::ScrollByUnits %W h [expr {%D/-3.0}]
}
# tk::ScrollButtonDown --
diff --git a/library/ttk/utils.tcl b/library/ttk/utils.tcl
index fc8b4e0..4827aa3 100644
--- a/library/ttk/utils.tcl
+++ b/library/ttk/utils.tcl
@@ -285,8 +285,8 @@ proc ttk::copyBindings {from to} {
#
proc ttk::bindMouseWheel {bindtag callback} {
- bind $bindtag <MouseWheel> [append callback { [expr {-(%D / 120)}]}]
- bind $bindtag <Option-MouseWheel> [append callback { [expr {-(%D / 12)}]}]
+ bind $bindtag <MouseWheel> [append callback { [expr {%D/-120.0}]}]
+ bind $bindtag <Option-MouseWheel> [append callback { [expr {%D/-12.0}]}]
}
## Mousewheel bindings for standard scrollable widgets.
@@ -298,12 +298,12 @@ proc ttk::bindMouseWheel {bindtag callback} {
#
bind TtkScrollable <MouseWheel> \
- { %W yview scroll [expr {-(%D / 120)}] units }
+ { %W yview scroll [expr {%D/-120}] units }
bind TtkScrollable <Option-MouseWheel> \
- { %W yview scroll [expr {-(%D / 12)}] units }
+ { %W yview scroll [expr {%D/-12}] units }
bind TtkScrollable <Shift-MouseWheel> \
- { %W xview scroll [expr {-(%D / 120)}] units }
+ { %W xview scroll [expr {%D/-120}] units }
bind TtkScrollable <Shift-Option-MouseWheel> \
- { %W xview scroll [expr {-(%D / 12)}] units }
+ { %W xview scroll [expr {%D/-12}] units }
#*EOF*
diff --git a/tests/entry.test b/tests/entry.test
index 6207c69..47b459d 100644
--- a/tests/entry.test
+++ b/tests/entry.test
@@ -1446,7 +1446,7 @@ test entry-3.72 {EntryWidgetCmd procedure, "xview" widget command} -setup {
.e xview scroll gorp units
} -cleanup {
destroy .e
-} -returnCodes error -result {expected integer but got "gorp"}
+} -returnCodes error -result {expected floating-point number but got "gorp"}
test entry-3.73 {EntryWidgetCmd procedure, "xview" widget command} -setup {
entry .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
pack .e
diff --git a/tests/spinbox.test b/tests/spinbox.test
index efd5b63..65c5bd9 100644
--- a/tests/spinbox.test
+++ b/tests/spinbox.test
@@ -1784,7 +1784,7 @@ test spinbox-3.72 {SpinboxWidgetCmd procedure, "xview" widget command} -setup {
.e xview scroll gorp units
} -cleanup {
destroy .e
-} -returnCodes error -result {expected integer but got "gorp"}
+} -returnCodes error -result {expected floating-point number but got "gorp"}
test spinbox-3.73 {SpinboxWidgetCmd procedure, "xview" widget command} -setup {
spinbox .e -font {Courier -12} -borderwidth 2 -highlightthickness 2
pack .e
diff --git a/tests/textDisp.test b/tests/textDisp.test
index 1b6f4c5..c029a69 100644
--- a/tests/textDisp.test
+++ b/tests/textDisp.test
@@ -1873,7 +1873,7 @@ test textDisp-14.11 {TkTextXviewCmd procedure} {
} {1 {wrong # args: should be ".t xview scroll number pages|pixels|units"}}
test textDisp-14.12 {TkTextXviewCmd procedure} {
list [catch {.t xview scroll gorp units} msg] $msg
-} {1 {expected integer but got "gorp"}}
+} {1 {expected floating-point number but got "gorp"}}
test textDisp-14.13 {TkTextXviewCmd procedure} {
.t delete 1.0 end
.t insert end xxxxxxxxx\n
@@ -2091,11 +2091,11 @@ test textDisp-16.20 {TkTextYviewCmd procedure, "scroll" option} {
list [catch {.t yview scroll a b c} msg] $msg
} {1 {wrong # args: should be ".t yview scroll number pages|pixels|units"}}
test textDisp-16.21 {TkTextYviewCmd procedure, "scroll" option} {
- list [catch {.t yview scroll badInt bogus} msg] $msg
+ list [catch {.t yview scroll bogus bogus} msg] $msg
} {1 {bad argument "bogus": must be pages, pixels, or units}}
test textDisp-16.21.2 {TkTextYviewCmd procedure, "scroll" option} {
- list [catch {.t yview scroll badInt units} msg] $msg
-} {1 {expected integer but got "badInt"}}
+ list [catch {.t yview scroll bogus units} msg] $msg
+} {1 {expected floating-point number but got "bogus"}}
test textDisp-16.22 {TkTextYviewCmd procedure, "scroll" option, back pages} {
.t yview 50.0
update
diff --git a/tests/util.test b/tests/util.test
index d457b50..c2f4542 100644
--- a/tests/util.test
+++ b/tests/util.test
@@ -34,7 +34,7 @@ test util-1.5 {Tk_GetScrollInfo procedure} -body {
} -returnCodes error -result {wrong # args: should be ".l yview scroll number pages|units"}
test util-1.6 {Tk_GetScrollInfo procedure} -body {
.l yview scroll xyz units
-} -returnCodes error -result {expected integer but got "xyz"}
+} -returnCodes error -result {expected floating-point number but got "xyz"}
test util-1.7 {Tk_GetScrollInfo procedure} -body {
.l yview 0
.l yview scroll 2 pages