Added compatibility loader for TTLC
[tcl-tlc.git] / scripts / myscrollbar_win32.itk
blobf61ef4e735ee5e8bc45c67ffe0a6e4dcaa45a0d8
1 # vim: foldmarker=<<<,>>>
3 ::itk::usual tlc::myscrollbar_win32 {
4         keep -background -cursor -troughcolor
5         keep -activebackground -activerelief
6         keep -highlightcolor -highlightthickness
7         rename -highlightbackground -background background Background
10 proc tlc::myscrollbar_win32 {pathName args} {
11         uplevel tlc::Myscrollbar_win32 [list $pathName] $args
14 class tlc::Myscrollbar_win32 {
15         inherit itk::Widget
17         constructor {args} {}
18         destructor {}
20         itk_option define -mode mode ShowMode "fancy" repack
21         itk_option define -orient orient Orient "vertical"
23         public {
24                 variable debug          0
26                 method activate {args}          {uplevel $w.sb activate $args}
27 #               method cget {args}                      {uplevel $w.sb cget $args}
28 #               method configure {args}         {uplevel $w.sb configure $args}
29                 method delta {args}                     {uplevel $w.sb delta $args}
30                 method fraction {args}          {uplevel $w.sb fraction $args}
31                 method get {args}                       {uplevel $w.sb get $args}
32                 method identify {args}          {uplevel $w.sb identify $args}
33                 method set {args}
34                 method shown_ref {}
35         }
36         
37         private {
38                 variable w
39                 variable wdb
40                         
41                 variable shown
42                 variable mode
44                 method repack {args}
45         }
49 configbody tlc::Myscrollbar_win32::orient { #<<<1
50         $w.sb configure -orient $itk_option(-orient)
51         repack
55 body tlc::Myscrollbar_win32::constructor {args} { #<<<1
56         ::set w         $itk_interior
57         ::set wdb       [string range $w 1 end]
59         tlc::Signal #auto shown -name "$this shown"
61         if {$::tcl_platform(platform) == "windows"} {
62                 ::set sbw               "scrollbar"
63                 ::set mode              "standard"
64         } else {
65                 if {[info commands ::ttk::scrollbar] != ""} {
66                         ::set sbw               "ttk::scrollbar"
67                         ::set mode              "ttk"
68                 } else {
69                         ::set sbw               "blt::tile::scrollbar"
70                         ::set mode              "blt"
71                 }
72         }
73         #  
74         
75         if {$mode == "ttk"} {
76                 itk_component add sb {
77                         $sbw $w.sb
78                 } {
79                         keep -command
80                 }
81         } else {
82                 itk_component add sb {
83                         $sbw $w.sb \
84                                         -activebackground [$tlc::theme setting background] \
85                                         -activerelief raised \
86                                         -background [$tlc::theme setting background] \
87                                         -borderwidth 2 \
88                                         -cursor {} \
89                                         -elementborderwidth -1 \
90                                         -highlightthickness 0 \
91                                         -jump 0 \
92                                         -orient vertical \
93                                         -relief sunken \
94                                         -repeatdelay 300 \
95                                         -repeatinterval 100 \
96                                         -takefocus 0 \
97                                         -troughcolor [$tlc::theme setting textbackground] \
98                                         -width 15
99                 } {
100                         keep -command -relief -borderwidth
101                 }
102         }
103         
104         itk_component add blank {
105                 ttk::frame $w.blank
106         } {
107                 #rename -background -hidebg troughColor Background
108         }
109         itk_initialize {*}$args
110         $shown set_state 1
111         $shown attach_output [code $this repack]
115 body tlc::Myscrollbar_win32::set {args} { #<<<1
116         if {[llength $args] == 2} {
117                 foreach {first last} $args {break}
119                 if {$debug} {
120                         puts "$w set: first: ($first) last: ($last)"
121                 }
122                 $shown set_state        [expr {!($first <= 0.0 && $last >= 1.0)}]
123         } else {
124                 if {$debug} {
125                         puts "$w odd number of args: ($args)"
126                 }
127         }
129         uplevel $w.sb set $args
133 body tlc::Myscrollbar_win32::repack {args} { #<<<1
134         ::set newstate  [$shown state]
136         if {$debug} {
137                 puts "${w}::repack: table children before: ([blt::table search $w])"
138         }
139         catch {blt::table forget $w.sb}
140         catch {blt::table forget $w.blank}
141         if {$debug} {
142                 puts "${w}::repack: table children after: ([blt::table search $w])"
143         }
145         if {$debug} {
146                 puts "${w}::repack: shown: ($newstate) mode: ($itk_option(-mode))"
147         }
148         if {$newstate || $itk_option(-mode) == "static"} {
149                 blt::table $w $w.sb             1,1 -fill both
150                 switch [string index $itk_option(-orient) 0] {
151                         "v"     {
152                                 blt::table configure $w c1 -width $w.sb
153                                 blt::table configure $w r1 -height {}
154                         }
156                         "h"     {
157                                 blt::table configure $w c1 -width {}
158                                 blt::table configure $w r1 -height $w.sb
159                         }
160                 }
161         } else {
162                 switch $itk_option(-mode) {
163                         fancy {
164                                 blt::table $w $w.blank  1,1 -fill both
165                         }
167                         dynamic -
168                         vanishing {
169                         }
170                 }
171                 
172                 switch $itk_option(-mode) {
173                         static -
174                         dynamic -
175                         fancy {
176                                 switch [string index $itk_option(-orient) 0] {
177                                         "v"     {
178                                                 blt::table configure $w c1 -width $w.sb
179                                                 blt::table configure $w r1 -height {}
180                                         }
182                                         "h"     {
183                                                 blt::table configure $w c1 -width {}
184                                                 blt::table configure $w r1 -height $w.sb
185                                         }
186                                 }
187                         }
189                         vanishing {
190                                 switch [string index $itk_option(-orient) 0] {
191                                         "v"     {
192                                                 blt::table configure $w c1 -width {0 0 0}
193                                                 blt::table configure $w r1 -height {0 0 0}
194                                         }
196                                         "h"     {
197                                                 blt::table configure $w c1 -width {0 0 0}
198                                                 blt::table configure $w r1 -height {0 0 0}
199                                         }
200                                 }
201                         }
202                 } 
203         }
204         blt::table arrange $w
208 body tlc::Myscrollbar_win32::shown_ref {} { #<<<1
209         return $shown