TKE  3.6
Advanced code editor for programmers
scrolledframe Namespace Reference

Functions

 scrolledframe w args
 
 dispatch w cmd args
 
 config w args
 
 resize w args
 
 xset w
 
 yset w
 
 xview w ?cmd? args
 
 yview w ?cmd? args
 

Function Documentation

§ config()

scrolledframe::config   w args  

Definition at line 106 of file scrolledframe.tcl.

106  # --------------
107  proc config {w args} \
108  {
109  variable {}
110  set options {}
111  set flag 0
112  foreach {key value} $args \
113  {
114  switch -glob -- $key \
115  {
116  -fill \
117  {
118  # new fill option: what should the scrolled object do if it is smaller than the viewing window?
119  if {$value == "none"} {
120  set ($w:fillx) 0
121  set ($w:filly) 0
122  } elseif {$value == "x"} {
123  set ($w:fillx) 1
124  set ($w:filly) 0
125  } elseif {$value == "y"} {
126  set ($w:fillx) 0
127  set ($w:filly) 1
128  } elseif {$value == "both"} {
129  set ($w:fillx) 1
130  set ($w:filly) 1
131  } else {
132  error "invalid value: should be \"$w configure -fill value\", where \"value\" is \"x\", \"y\", \"none\", or \"both\""
133  }
134  resize $w force
135  set flag 1
136  }
137  -xsc* \
138  {
139  # new xscroll option
140  set ($w:xscroll) $value
141  set flag 1
142  }
143  -ysc* \
144  {
145  # new yscroll option
146  set ($w:yscroll) $value
147  set flag 1
148  }
149  default { lappend options $key $value }
150  }
151  }
152  # check if needed
153  if {!$flag || $options != ""} \
154  {
155  # call frame config
156  uplevel 1 [linsert $options 0 ::scrolledframe::_$w config]
157  }

§ dispatch()

scrolledframe::dispatch   w cmd args  

Definition at line 86 of file scrolledframe.tcl.

86  # --------------
87  proc dispatch {w cmd args} \
88  {
89  variable {}
90  switch -glob -- $cmd \
91  {
92  con* { uplevel 1 [linsert $args 0 ::scrolledframe::config $w]}
93  xvi* { uplevel 1 [linsert $args 0 ::scrolledframe::xview $w]}
94  yvi* { uplevel 1 [linsert $args 0 ::scrolledframe::yview $w]}
95  default { uplevel 1 [linsert $args 0 ::scrolledframe::_$w $cmd]}
96  }}

§ resize()

scrolledframe::resize   w args  

Definition at line 172 of file scrolledframe.tcl.

172  # --------------
173  proc resize {w args} \
174  {
175  variable {}
176 
177  # If the window is destroyed, do nothing
178  if {![winfo exists $w] || ![winfo exists $w.scrolled]} {
179  return
180  }
181 
182  set force [llength $args]
183 
184  set _vheight $($w:vheight)
185  set _vwidth $($w:vwidth)
186  # compute new height & width
187  set ($w:vheight) [winfo reqheight $w.scrolled]
188  set ($w:vwidth) [winfo reqwidth $w.scrolled]
189 
190  # The size may have changed, e.g. by manual resizing of the window
191  set _height $($w:height)
192  set _width $($w:width)
193  set ($w:height) [winfo height $w] ;# gives the actual height of the viewing window
194  set ($w:width) [winfo width $w] ;# gives the actual width of the viewing window
195 
196  if {$force || $($w:vheight) != $_vheight || $($w:height) != $_height} {
197  # resize the vertical scroll bar
198  yview $w scroll 0 unit
199  # yset $w
200  }
201 
202  if {$force || $($w:vwidth) != $_vwidth || $($w:width) != $_width} {
203  # resize the horizontal scroll bar
204  xview $w scroll 0 unit
205  # xset $w
206  }

§ scrolledframe()

scrolledframe::scrolledframe   w args  

Definition at line 43 of file scrolledframe.tcl.

43  # --------------
44  proc scrolledframe {w args} \
45  {
46  variable {}
47  # create a scrolled frame
48  ttk::frame $w
49  # trap the reference
50  rename $w ::scrolledframe::_$w
51  # redirect to dispatch
52  interp alias {} $w {} ::scrolledframe::dispatch $w
53  # create scrollable internal frame
54  ttk::frame $w.scrolled
55  # place it
56  place $w.scrolled -in $w -x 0 -y 0
57  if {$(debug,place)} { puts "place $w.scrolled -in $w -x 0 -y 0"} ;#DEBUG
58  # init internal data
59  set ($w:vheight) 0
60  set ($w:vwidth) 0
61  set ($w:vtop) 0
62  set ($w:vleft) 0
63  set ($w:xscroll) ""
64  set ($w:yscroll) ""
65  set ($w:width) 0
66  set ($w:height) 0
67  set ($w:fillx) 0
68  set ($w:filly) 0
69  # configure
70  if {$args != ""} { uplevel 1 ::scrolledframe::config $w $args}
71  # bind <Configure>
72  bind $w <Configure> [namespace code [list resize $w]]
73  bind $w.scrolled <Configure> [namespace code [list resize $w]]
74  # return widget ref
75  return $}

§ xset()

scrolledframe::xset   w  

Definition at line 215 of file scrolledframe.tcl.

215  # --------------
216  proc xset {w} \
217  {
218  variable {}
219  # call the xscroll command
220  set cmd $($w:xscroll)
221  if {$cmd != ""} { catch { eval $cmd [xview $w] } }

§ xview()

scrolledframe::xview   w ?cmd? args  

Definition at line 249 of file scrolledframe.tcl.

249  # -------------
250  proc xview {w {cmd ""} args} \
251  {
252  variable {}
253  # check args
254  set len [llength $args]
255  switch -glob -- $cmd \
256  {
257  "" {set args {}}
258  mov* \
259  { if {$len != 1} { error "wrong # args: should be \"$w xview moveto fraction\"" } }
260  scr* \
261  { if {$len != 2} { error "wrong # args: should be \"$w xview scroll count unit\""}}
262  default \
263  { error "unknown operation \"$cmd\": should be empty, moveto or scroll" }
264  }
265  # save old values:
266  set _vleft $($w:vleft)
267  set _vwidth $($w:vwidth)
268  set _width $($w:width)
269  # compute new vleft
270  set count ""
271  switch $len \
272  {
273  0 \
274  {
275  # return fractions
276  if {$_vwidth == 0} { return {0 1} }
277  set first [expr {double($_vleft) / $_vwidth}]
278  set last [expr {double($_vleft + $_width) / $_vwidth}]
279  if {$last > 1.0} { return {0 1} }
280  return [list $first $last]
281  }
282  1 \
283  {
284  # absolute movement
285  set vleft [expr {int(double($args) * $_vwidth)}]
286  }
287  2 \
288  {
289  # relative movement
290  foreach {count unit} $args break
291  if {[string match p* $unit]} { set count [expr {$count * 9}] }
292  set vleft [expr {$_vleft + $count * 0.1 * $_width}]
293  }
294  }
295  if {$vleft + $_width > $_vwidth} { set vleft [expr {$_vwidth - $_width}]}
296  if {$vleft < 0} { set vleft 0}
297  if {$vleft != $_vleft || $count == 0} \
298  {
299  set ($w:vleft) $vleft
300  xset $w
301  if {$($w:fillx) && ($_vwidth < $_width || $($w:xscroll) == "") } {
302  # "scrolled object" is not scrolled, because it is too small or because no scrollbar was requested
303  # fillx means that, in these cases, we must tell the object what its width should be
304  place $w.scrolled -in $w -x [expr {-$vleft}] -width $_width
305  if {$(debug,place)} { puts "place $w.scrolled -in $w -x [expr {-$vleft}] -width $_width" } ;#DEBUG
306  } else {
307  place $w.scrolled -in $w -x [expr {-$vleft}] -width {}
308  if {$(debug,place)} { puts "place $w.scrolled -in $w -x [expr {-$vleft}] -width {}" } ;#DEBUG
309  }
310 
311  }

§ yset()

scrolledframe::yset   w  

Definition at line 230 of file scrolledframe.tcl.

230  # --------------
231  proc yset {w} \
232  {
233  variable {}
234  # call the yscroll command
235  set cmd $($w:yscroll)
236  if {$cmd != ""} { catch { eval $cmd [yview $w] } }

§ yview()

scrolledframe::yview   w ?cmd? args  

Definition at line 324 of file scrolledframe.tcl.

324  # -------------
325  proc yview {w {cmd ""} args} \
326  {
327  variable {}
328  # check args
329  set len [llength $args]
330  switch -glob -- $cmd \
331  {
332  "" {set args {}}
333  mov* \
334  { if {$len != 1} { error "wrong # args: should be \"$w yview moveto fraction\"" } }
335  scr* \
336  { if {$len != 2} { error "wrong # args: should be \"$w yview scroll count unit\""}}
337  default \
338  { error "unknown operation \"$cmd\": should be empty, moveto or scroll" }
339  }
340  # save old values
341  set _vtop $($w:vtop)
342  set _vheight $($w:vheight)
343  # set _height [winfo height $w]
344  set _height $($w:height)
345  # compute new vtop
346  set count ""
347  switch $len \
348  {
349  0 \
350  {
351  # return fractions
352  if {$_vheight == 0} { return {0 1} }
353  set first [expr {double($_vtop) / $_vheight}]
354  set last [expr {double($_vtop + $_height) / $_vheight}]
355  if {$last > 1.0} { return {0 1} }
356  return [list $first $last]
357  }
358  1 \
359  {
360  # absolute movement
361  set vtop [expr {int(double($args) * $_vheight)}]
362  }
363  2 \
364  {
365  # relative movement
366  foreach {count unit} $args break
367  if {[string match p* $unit]} { set count [expr {$count * 9}] }
368  set vtop [expr {$_vtop + $count * 0.1 * $_height}]
369  }
370  }
371  if {$vtop + $_height > $_vheight} { set vtop [expr {$_vheight - $_height}]}
372  if {$vtop < 0} { set vtop 0}
373  if {$vtop != $_vtop || $count == 0} \
374  {
375  set ($w:vtop) $vtop
376  yset $w
377  if {$($w:filly) && ($_vheight < $_height || $($w:yscroll) == "")} {
378  # "scrolled object" is not scrolled, because it is too small or because no scrollbar was requested
379  # filly means that, in these cases, we must tell the object what its height should be
380  place $w.scrolled -in $w -y [expr {-$vtop}] -height $_height
381  if {$(debug,place)} { puts "place $w.scrolled -in $w -y [expr {-$vtop}] -height $_height" } ;#DEBUG
382  } else {
383  place $w.scrolled -in $w -y [expr {-$vtop}] -height {}
384  if {$(debug,place)} { puts "place $w.scrolled -in $w -y [expr {-$vtop}] -height {}" } ;#DEBUG
385  }
386  }