scale.tcl 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # scale.tcl - Copyright (C) 2004 Pat Thoyts <patthoyts@users.sourceforge.net>
  2. #
  3. # Bindings for the TScale widget
  4. namespace eval ttk::scale {
  5. variable State
  6. array set State {
  7. dragging 0
  8. }
  9. }
  10. bind TScale <ButtonPress-1> { ttk::scale::Press %W %x %y }
  11. bind TScale <B1-Motion> { ttk::scale::Drag %W %x %y }
  12. bind TScale <ButtonRelease-1> { ttk::scale::Release %W %x %y }
  13. bind TScale <ButtonPress-2> { ttk::scale::Jump %W %x %y }
  14. bind TScale <B2-Motion> { ttk::scale::Drag %W %x %y }
  15. bind TScale <ButtonRelease-2> { ttk::scale::Release %W %x %y }
  16. bind TScale <ButtonPress-3> { ttk::scale::Jump %W %x %y }
  17. bind TScale <B3-Motion> { ttk::scale::Drag %W %x %y }
  18. bind TScale <ButtonRelease-3> { ttk::scale::Release %W %x %y }
  19. bind TScale <Left> { ttk::scale::Increment %W -1 }
  20. bind TScale <Up> { ttk::scale::Increment %W -1 }
  21. bind TScale <Right> { ttk::scale::Increment %W 1 }
  22. bind TScale <Down> { ttk::scale::Increment %W 1 }
  23. bind TScale <Control-Left> { ttk::scale::Increment %W -10 }
  24. bind TScale <Control-Up> { ttk::scale::Increment %W -10 }
  25. bind TScale <Control-Right> { ttk::scale::Increment %W 10 }
  26. bind TScale <Control-Down> { ttk::scale::Increment %W 10 }
  27. bind TScale <Home> { %W set [%W cget -from] }
  28. bind TScale <End> { %W set [%W cget -to] }
  29. proc ttk::scale::Press {w x y} {
  30. variable State
  31. set State(dragging) 0
  32. switch -glob -- [$w identify $x $y] {
  33. *track -
  34. *trough {
  35. set inc [expr {([$w get $x $y] <= [$w get]) ^ ([$w cget -from] > [$w cget -to]) ? -1 : 1}]
  36. ttk::Repeatedly Increment $w $inc
  37. }
  38. *slider {
  39. set State(dragging) 1
  40. set State(initial) [$w get]
  41. }
  42. }
  43. }
  44. # scale::Jump -- ButtonPress-2/3 binding for scale acts like
  45. # Press except that clicking in the trough jumps to the
  46. # clicked position.
  47. proc ttk::scale::Jump {w x y} {
  48. variable State
  49. set State(dragging) 0
  50. switch -glob -- [$w identify $x $y] {
  51. *track -
  52. *trough {
  53. $w set [$w get $x $y]
  54. set State(dragging) 1
  55. set State(initial) [$w get]
  56. }
  57. *slider {
  58. Press $w $x $y
  59. }
  60. }
  61. }
  62. proc ttk::scale::Drag {w x y} {
  63. variable State
  64. if {$State(dragging)} {
  65. $w set [$w get $x $y]
  66. }
  67. }
  68. proc ttk::scale::Release {w x y} {
  69. variable State
  70. set State(dragging) 0
  71. ttk::CancelRepeat
  72. }
  73. proc ttk::scale::Increment {w delta} {
  74. if {![winfo exists $w]} return
  75. if {([$w cget -from] > [$w cget -to])} {
  76. set delta [expr {-$delta}]
  77. }
  78. $w set [expr {[$w get] + $delta}]
  79. }