|
|
|
|
|
|
|
|
|
namespace eval ttk::spinbox { } |
|
|
|
|
|
|
|
|
|
|
|
|
|
ttk::copyBindings TEntry TSpinbox |
|
|
|
bind TSpinbox <Motion> { ttk::spinbox::Motion %W %x %y } |
|
bind TSpinbox <Button-1> { ttk::spinbox::Press %W %x %y } |
|
bind TSpinbox <ButtonRelease-1> { ttk::spinbox::Release %W } |
|
bind TSpinbox <Double-Button-1> { ttk::spinbox::DoubleClick %W %x %y } |
|
bind TSpinbox <Triple-Button-1> {} |
|
|
|
bind TSpinbox <Up> { event generate %W <<Increment>> } |
|
bind TSpinbox <Down> { event generate %W <<Decrement>> } |
|
|
|
bind TSpinbox <<Increment>> { ttk::spinbox::Spin %W +1 } |
|
bind TSpinbox <<Decrement>> { ttk::spinbox::Spin %W -1 } |
|
|
|
ttk::bindMouseWheel TSpinbox [list ttk::spinbox::MouseWheel %W] |
|
|
|
|
|
|
|
|
|
proc ttk::spinbox::Motion {w x y} { |
|
variable State |
|
ttk::saveCursor $w State(userConfCursor) [ttk::cursor text] |
|
if { [$w identify $x $y] eq "textarea" |
|
&& [$w instate {!readonly !disabled}] |
|
} { |
|
ttk::setCursor $w text |
|
} else { |
|
ttk::setCursor $w $State(userConfCursor) |
|
} |
|
} |
|
|
|
|
|
|
|
proc ttk::spinbox::Press {w x y} { |
|
if {[$w instate disabled]} { return } |
|
focus $w |
|
switch -glob -- [$w identify $x $y] { |
|
*textarea { ttk::entry::Press $w $x } |
|
*rightarrow - |
|
*uparrow { ttk::Repeatedly event generate $w <<Increment>> } |
|
*leftarrow - |
|
*downarrow { ttk::Repeatedly event generate $w <<Decrement>> } |
|
*spinbutton { |
|
if {$y * 2 >= [winfo height $w]} { |
|
set event <<Decrement>> |
|
} else { |
|
set event <<Increment>> |
|
} |
|
ttk::Repeatedly event generate $w $event |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::spinbox::DoubleClick {w x y} { |
|
if {[$w instate disabled]} { return } |
|
|
|
switch -glob -- [$w identify $x $y] { |
|
*textarea { SelectAll $w } |
|
* { Press $w $x $y } |
|
} |
|
} |
|
|
|
proc ttk::spinbox::Release {w} { |
|
ttk::CancelRepeat |
|
} |
|
|
|
|
|
|
|
|
|
|
|
proc ttk::spinbox::MouseWheel {w dir} { |
|
if {[$w instate disabled]} { return } |
|
if {$dir < 0} { |
|
event generate $w <<Increment>> |
|
} else { |
|
event generate $w <<Decrement>> |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::spinbox::SelectAll {w} { |
|
$w selection range 0 end |
|
$w icursor end |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::spinbox::Limit {v min max} { |
|
if {$v < $min} { return $min } |
|
if {$v > $max} { return $max } |
|
return $v |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::spinbox::Wrap {v min max} { |
|
if {$v < $min} { return $max } |
|
if {$v > $max} { return $min } |
|
return $v |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::spinbox::Adjust {w v min max} { |
|
if {[$w cget -wrap]} { |
|
return [Wrap $v $min $max] |
|
} else { |
|
return [Limit $v $min $max] |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::spinbox::Spin {w dir} { |
|
variable State |
|
|
|
if {[$w instate disabled]} { return } |
|
|
|
if {![info exists State($w,values.length)]} { |
|
set State($w,values.index) -1 |
|
set State($w,values.last) {} |
|
} |
|
set State($w,values) [$w cget -values] |
|
set State($w,values.length) [llength $State($w,values)] |
|
|
|
if {$State($w,values.length) > 0} { |
|
set value [$w get] |
|
set current $State($w,values.index) |
|
if {$value ne $State($w,values.last)} { |
|
set current [lsearch -exact $State($w,values) $value] |
|
if {$current < 0} {set current -1} |
|
} |
|
set State($w,values.index) [Adjust $w [expr {$current + $dir}] 0 \ |
|
[expr {$State($w,values.length) - 1}]] |
|
set State($w,values.last) [lindex $State($w,values) $State($w,values.index)] |
|
$w set $State($w,values.last) |
|
} else { |
|
if {[catch { |
|
set v [expr {[scan [$w get] %f] + $dir * [$w cget -increment]}] |
|
}]} { |
|
set v [$w cget -from] |
|
} |
|
$w set [FormatValue $w [Adjust $w $v [$w cget -from] [$w cget -to]]] |
|
} |
|
SelectAll $w |
|
uplevel #0 [$w cget -command] |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::spinbox::FormatValue {w val} { |
|
set fmt [$w cget -format] |
|
if {$fmt eq ""} { |
|
|
|
set delta [expr {abs([$w cget -increment])}] |
|
if {0 < $delta && $delta < 1} { |
|
|
|
|
|
set nsd [expr {int(ceil(-log10($delta)))}] |
|
set fmt "%.${nsd}f" |
|
} else { |
|
set fmt "%.0f" |
|
} |
|
} |
|
return [format $fmt $val] |
|
} |
|
|
|
|
|
|