figenc

[RADIOACTIVE] rsa and symmetric key encryption scripts and executables
git clone git://git.figbert.com/figenc.git
Log | Files | Refs | README

scale.tcl (2698B)


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