diff options
author | fvogelnew1@free.fr <fvogel> | 2016-02-25 14:40:12 (GMT) |
---|---|---|
committer | fvogelnew1@free.fr <fvogel> | 2016-02-25 14:40:12 (GMT) |
commit | 89b129671fd0ca6e6e67cbdee645e92e3e36b15f (patch) | |
tree | 039efe1806ca6290bb2cc672030b093b35f9edad | |
parent | 90888a5d3218a161dae936b54b271eed2b948248 (diff) | |
download | tk-89b129671fd0ca6e6e67cbdee645e92e3e36b15f.zip tk-89b129671fd0ca6e6e67cbdee645e92e3e36b15f.tar.gz tk-89b129671fd0ca6e6e67cbdee645e92e3e36b15f.tar.bz2 |
Fixed bug [841280] - spinbox -from and -to defaults and behaviour
-rw-r--r-- | doc/spinbox.n | 6 | ||||
-rw-r--r-- | generic/tkEntry.c | 16 | ||||
-rw-r--r-- | tests/spinbox.test | 15 |
3 files changed, 28 insertions, 9 deletions
diff --git a/doc/spinbox.n b/doc/spinbox.n index 330bb17..e030aa3 100644 --- a/doc/spinbox.n +++ b/doc/spinbox.n @@ -54,7 +54,8 @@ as it will format a floating-point number. A floating-point value corresponding to the lowest value for a spinbox, to be used in conjunction with \fB\-to\fR and \fB\-increment\fR. When all are specified correctly, the spinbox will use these values to control its -contents. This value must be less than the \fB\-to\fR option. +contents. If this value is greater than the \fB\-to\fR option, then +\fB\-from\fR and \fB\-to\fR values are automatically swapped. If \fB\-values\fR is specified, it supersedes this option. .OP "\-invalidcommand or \-invcmd" invalidCommand InvalidCommand Specifies a script to eval when \fB\-validatecommand\fR returns 0. Setting @@ -83,7 +84,8 @@ be displayed in a different color, depending on the values of the A floating-point value corresponding to the highest value for the spinbox, to be used in conjunction with \fB\-from\fR and \fB\-increment\fR. When all are specified correctly, the spinbox will use these values to control -its contents. This value must be greater than the \fB\-from\fR option. +its contents. If this value is less than the \fB\-from\fR option, then +\fB\-from\fR and \fB\-to\fR values are automatically swapped. If \fB\-values\fR is specified, it supersedes this option. .OP \-validate validate Validate Specifies the mode in which validation should operate: \fBnone\fR, diff --git a/generic/tkEntry.c b/generic/tkEntry.c index ea8d7f1..5681e47 100644 --- a/generic/tkEntry.c +++ b/generic/tkEntry.c @@ -1176,13 +1176,15 @@ ConfigureEntry( if (entryPtr->type == TK_SPINBOX) { if (sbPtr->fromValue > sbPtr->toValue) { - Tcl_SetObjResult(interp, Tcl_NewStringObj( - "-to value must be greater than -from value", - -1)); - Tcl_SetErrorCode(interp, "TK", "SPINBOX", "RANGE_SANITY", - NULL); - continue; - } + /* + * Swap -from and -to values. + */ + + double tmpFromTo = sbPtr->fromValue; + + sbPtr->fromValue = sbPtr->toValue; + sbPtr->toValue = tmpFromTo; + } if (sbPtr->reqFormat && (oldFormat != sbPtr->reqFormat)) { /* diff --git a/tests/spinbox.test b/tests/spinbox.test index 594cc90..0264b77 100644 --- a/tests/spinbox.test +++ b/tests/spinbox.test @@ -2072,6 +2072,21 @@ test spinbox-5.11 {ConfigureSpinbox procedure} -setup { } -cleanup { destroy .e } -result {} +test spinbox-5.12 {ConfigureSpinbox procedure, -from and -to swapping} -setup { + spinbox .e +} -body { + # this statement used to trigger error "-to value must be greater than -from value" + # because default value for -to is zero (bug [841280ffff]) + set res [catch {.e configure -from 10}] + .e configure -from 1971 -to 2016 ; # standard case + lappend res [.e cget -from] [.e cget -to] + .e configure -from 2016 -to 1971 ; # auto-swapping happens + lappend res [.e cget -from] [.e cget -to] + .e configure -to 1971 -from 2016 ; # auto-swapping, order of options does not matter + lappend res [.e cget -from] [.e cget -to] +} -cleanup { + destroy .e +} -result {0 1971.0 2016.0 1971.0 2016.0 1971.0 2016.0} # No tests for DisplaySpinbox. |