3 # ----------------------------------------------------------------------
4 # Implements horizontal and vertical scrollbars around a canvas childsite
5 # Includes options to control display of scrollbars. The standard
6 # canvas options and methods are supported.
8 # ----------------------------------------------------------------------
9 # AUTHOR: Mark Ulferts mulferts@austin.dsccc.com
12 # ----------------------------------------------------------------------
13 # Copyright (c) 1995 DSC Technologies Corporation
14 # ======================================================================
15 # Permission to use, copy, modify, distribute and license this software
16 # and its documentation for any purpose, and without fee or written
17 # agreement with DSC, is hereby granted, provided that the above copyright
18 # notice appears in all copies and that both the copyright notice and
19 # warranty disclaimer below appear in supporting documentation, and that
20 # the names of DSC Technologies Corporation or DSC Communications
21 # Corporation not be used in advertising or publicity pertaining to the
22 # software without specific, written prior permission.
24 # DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
25 # ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-
26 # INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE
27 # AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE,
28 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL
29 # DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
30 # ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
31 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
32 # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
34 # ======================================================================
39 itk::usual Scrolledcanvas {
40 keep -activebackground -activerelief -background -borderwidth -cursor \
41 -elementborderwidth -foreground -highlightcolor -highlightthickness \
42 -insertbackground -insertborderwidth -insertofftime -insertontime \
43 -insertwidth -jump -labelfont -selectbackground -selectborderwidth \
44 -selectforeground -textbackground -troughcolor
47 # ------------------------------------------------------------------
49 # ------------------------------------------------------------------
50 class iwidgets::Scrolledcanvas {
51 inherit iwidgets::Scrolledwidget
56 itk_option define -autoresize autoResize AutoResize 1
57 itk_option define -automargin autoMargin AutoMargin 0
59 public method childsite {}
60 public method justify {direction}
62 public method addtag {args}
63 public method bbox {args}
64 public method bind {args}
65 public method canvasx {args}
66 public method canvasy {args}
67 public method coords {args}
68 public method create {args}
69 public method dchars {args}
70 public method delete {args}
71 public method dtag {args}
72 public method find {args}
73 public method focus {args}
74 public method gettags {args}
75 public method icursor {args}
76 public method index {args}
77 public method insert {args}
78 public method itemconfigure {args}
79 public method itemcget {args}
80 public method lower {args}
81 public method move {args}
82 public method postscript {args}
83 public method raise {args}
84 public method scale {args}
85 public method scan {args}
86 public method select {args}
87 public method type {args}
88 public method xview {args}
89 public method yview {args}
93 # Provide a lowercased access method for the Scrolledcanvas class.
95 proc ::iwidgets::scrolledcanvas {pathName args} {
96 uplevel ::iwidgets::Scrolledcanvas $pathName $args
100 # Use option database to override default resources of base classes.
102 option add *Scrolledcanvas.width 200 widgetDefault
103 option add *Scrolledcanvas.height 230 widgetDefault
104 option add *Scrolledcanvas.labelPos n widgetDefault
106 # ------------------------------------------------------------------
108 # ------------------------------------------------------------------
109 body iwidgets::Scrolledcanvas::constructor {args} {
111 # Create a clipping frame which will provide the border for
114 itk_component add clipper {
115 frame $itk_interior.clipper
119 keep -borderwidth -relief -highlightthickness -highlightcolor
120 rename -highlightbackground -background background Background
122 grid $itk_component(clipper) -row 1 -column 1 -sticky nsew
123 grid rowconfigure $_interior 1 -weight 1
124 grid columnconfigure $_interior 1 -weight 1
127 # Create a canvas to scroll
129 itk_component add canvas {
130 canvas $itk_component(clipper).canvas \
131 -height 1.0 -width 1.0 \
132 -scrollregion "0 0 1 1" \
134 [code $this _scrollWidget $itk_interior.horizsb] \
136 [code $this _scrollWidget $itk_interior.vertsb]
140 ignore -highlightthickness -highlightcolor
142 keep -closeenough -confine -scrollregion
143 keep -xscrollincrement -yscrollincrement
145 rename -background -textbackground textBackground Background
147 grid $itk_component(canvas) -row 0 -column 0 -sticky nsew
148 grid rowconfigure $itk_component(clipper) 0 -weight 1
149 grid columnconfigure $itk_component(clipper) 0 -weight 1
152 # Configure the command on the vertical scroll bar in the base class.
154 $itk_component(vertsb) configure \
155 -command [code $itk_component(canvas) yview]
158 # Configure the command on the horizontal scroll bar in the base class.
160 $itk_component(horizsb) configure \
161 -command [code $itk_component(canvas) xview]
164 # Initialize the widget based on the command line options.
166 eval itk_initialize $args
169 # ------------------------------------------------------------------
171 # ------------------------------------------------------------------
172 body iwidgets::Scrolledcanvas::destructor {} {
175 # ------------------------------------------------------------------
177 # ------------------------------------------------------------------
179 # ------------------------------------------------------------------
180 # OPTION: -autoresize
182 # Automatically adjusts the scrolled region to be the bounding
183 # box covering all the items in the canvas following the execution
184 # of any method which creates or destroys items. Thus, as new
185 # items are added, the scrollbars adjust accordingly.
186 # ------------------------------------------------------------------
187 configbody iwidgets::Scrolledcanvas::autoresize {
188 if {$itk_option(-autoresize)} {
189 set bbox [$itk_component(canvas) bbox all]
192 set marg $itk_option(-automargin)
193 set bbox [lreplace $bbox 0 0 [expr [lindex $bbox 0] - $marg]]
194 set bbox [lreplace $bbox 1 1 [expr [lindex $bbox 1] - $marg]]
195 set bbox [lreplace $bbox 2 2 [expr [lindex $bbox 2] + $marg]]
196 set bbox [lreplace $bbox 3 3 [expr [lindex $bbox 3] + $marg]]
199 $itk_component(canvas) configure -scrollregion $bbox
203 # ------------------------------------------------------------------
205 # ------------------------------------------------------------------
207 # ------------------------------------------------------------------
210 # Returns the path name of the child site widget.
211 # ------------------------------------------------------------------
212 body iwidgets::Scrolledcanvas::childsite {} {
213 return $itk_component(canvas)
216 # ------------------------------------------------------------------
219 # Justifies the canvas scrolled region in one of four directions: top,
220 # bottom, left, or right.
221 # ------------------------------------------------------------------
222 body iwidgets::Scrolledcanvas::justify {direction} {
223 if {[winfo ismapped $itk_component(canvas)]} {
228 $itk_component(canvas) xview moveto 0
231 $itk_component(canvas) xview moveto 1
234 $itk_component(canvas) yview moveto 0
237 $itk_component(canvas) yview moveto 1
240 error "bad justify argument \"$direction\": should be\
241 left, right, top, or bottom"
247 # ------------------------------------------------------------------
250 # The following methods are thin wraps of standard canvas methods.
251 # Consult the Tk canvas man pages for functionallity and argument
253 # ------------------------------------------------------------------
255 # ------------------------------------------------------------------
256 # METHOD: addtag tag searchSpec ?arg arg ...?
257 # ------------------------------------------------------------------
258 body iwidgets::Scrolledcanvas::addtag {args} {
259 return [eval $itk_component(canvas) addtag $args]
262 # ------------------------------------------------------------------
263 # METHOD: bbox tagOrId ?tagOrId tagOrId ...?
264 # ------------------------------------------------------------------
265 body iwidgets::Scrolledcanvas::bbox {args} {
266 return [eval $itk_component(canvas) bbox $args]
269 # ------------------------------------------------------------------
270 # METHOD: bind tagOrId ?sequence? ?command?
271 # ------------------------------------------------------------------
272 body iwidgets::Scrolledcanvas::bind {args} {
273 return [eval $itk_component(canvas) bind $args]
276 # ------------------------------------------------------------------
277 # METHOD: canvasx screenx ?gridspacing?
278 # ------------------------------------------------------------------
279 body iwidgets::Scrolledcanvas::canvasx {args} {
280 return [eval $itk_component(canvas) canvasx $args]
283 # ------------------------------------------------------------------
284 # METHOD: canvasy screeny ?gridspacing?
285 # ------------------------------------------------------------------
286 body iwidgets::Scrolledcanvas::canvasy {args} {
287 return [eval $itk_component(canvas) canvasy $args]
290 # ------------------------------------------------------------------
291 # METHOD: coords tagOrId ?x0 y0 ...?
292 # ------------------------------------------------------------------
293 body iwidgets::Scrolledcanvas::coords {args} {
294 return [eval $itk_component(canvas) coords $args]
297 # ------------------------------------------------------------------
298 # METHOD: create type x y ?x y ...? ?option value ...?
299 # ------------------------------------------------------------------
300 body iwidgets::Scrolledcanvas::create {args} {
301 set retval [eval $itk_component(canvas) create $args]
303 configure -autoresize $itk_option(-autoresize)
308 # ------------------------------------------------------------------
309 # METHOD: dchars tagOrId first ?last?
310 # ------------------------------------------------------------------
311 body iwidgets::Scrolledcanvas::dchars {args} {
312 return [eval $itk_component(canvas) dchars $args]
315 # ------------------------------------------------------------------
316 # METHOD: delete tagOrId ?tagOrId tagOrId ...?
317 # ------------------------------------------------------------------
318 body iwidgets::Scrolledcanvas::delete {args} {
319 set retval [eval $itk_component(canvas) delete $args]
321 configure -autoresize $itk_option(-autoresize)
326 # ------------------------------------------------------------------
327 # METHOD: dtag tagOrId ?tagToDelete?
328 # ------------------------------------------------------------------
329 body iwidgets::Scrolledcanvas::dtag {args} {
330 eval $itk_component(canvas) dtag $args
332 configure -autoresize $itk_option(-autoresize)
335 # ------------------------------------------------------------------
336 # METHOD: find searchCommand ?arg arg ...?
337 # ------------------------------------------------------------------
338 body iwidgets::Scrolledcanvas::find {args} {
339 return [eval $itk_component(canvas) find $args]
342 # ------------------------------------------------------------------
343 # METHOD: focus ?tagOrId?
344 # ------------------------------------------------------------------
345 body iwidgets::Scrolledcanvas::focus {args} {
346 return [eval $itk_component(canvas) focus $args]
349 # ------------------------------------------------------------------
350 # METHOD: gettags tagOrId
351 # ------------------------------------------------------------------
352 body iwidgets::Scrolledcanvas::gettags {args} {
353 return [eval $itk_component(canvas) gettags $args]
356 # ------------------------------------------------------------------
357 # METHOD: icursor tagOrId index
358 # ------------------------------------------------------------------
359 body iwidgets::Scrolledcanvas::icursor {args} {
360 eval $itk_component(canvas) icursor $args
363 # ------------------------------------------------------------------
364 # METHOD: index tagOrId index
365 # ------------------------------------------------------------------
366 body iwidgets::Scrolledcanvas::index {args} {
367 return [eval $itk_component(canvas) index $args]
370 # ------------------------------------------------------------------
371 # METHOD: insert tagOrId beforeThis string
372 # ------------------------------------------------------------------
373 body iwidgets::Scrolledcanvas::insert {args} {
374 eval $itk_component(canvas) insert $args
377 # ------------------------------------------------------------------
378 # METHOD: itemconfigure tagOrId ?option? ?value? ?option value ...?
379 # ------------------------------------------------------------------
380 body iwidgets::Scrolledcanvas::itemconfigure {args} {
381 set retval [eval $itk_component(canvas) itemconfigure $args]
383 configure -autoresize $itk_option(-autoresize)
388 # ------------------------------------------------------------------
389 # METHOD: itemcget tagOrId ?option?
390 # ------------------------------------------------------------------
391 body iwidgets::Scrolledcanvas::itemcget {args} {
392 set retval [eval $itk_component(canvas) itemcget $args]
397 # ------------------------------------------------------------------
398 # METHOD: lower tagOrId ?belowThis?
399 # ------------------------------------------------------------------
400 body iwidgets::Scrolledcanvas::lower {args} {
401 eval $itk_component(canvas) lower $args
404 # ------------------------------------------------------------------
405 # METHOD: move tagOrId xAmount yAmount
406 # ------------------------------------------------------------------
407 body iwidgets::Scrolledcanvas::move {args} {
408 eval $itk_component(canvas) move $args
410 configure -autoresize $itk_option(-autoresize)
413 # ------------------------------------------------------------------
414 # METHOD: postscript ?option value ...?
415 # ------------------------------------------------------------------
416 body iwidgets::Scrolledcanvas::postscript {args} {
418 # Make sure the fontmap is in scope.
421 regexp -- {-fontmap +([^ ]+)} $args all fontmap
423 if {$fontmap != ""} {
427 return [eval $itk_component(canvas) postscript $args]
430 # ------------------------------------------------------------------
431 # METHOD: raise tagOrId ?aboveThis?
432 # ------------------------------------------------------------------
433 body iwidgets::Scrolledcanvas::raise {args} {
434 eval $itk_component(canvas) raise $args
437 # ------------------------------------------------------------------
438 # METHOD: scale tagOrId xOrigin yOrigin xScale yScale
439 # ------------------------------------------------------------------
440 body iwidgets::Scrolledcanvas::scale {args} {
441 eval $itk_component(canvas) scale $args
444 # ------------------------------------------------------------------
445 # METHOD: scan option args
446 # ------------------------------------------------------------------
447 body iwidgets::Scrolledcanvas::scan {args} {
448 eval $itk_component(canvas) scan $args
451 # ------------------------------------------------------------------
452 # METHOD: select option ?tagOrId arg?
453 # ------------------------------------------------------------------
454 body iwidgets::Scrolledcanvas::select {args} {
455 eval $itk_component(canvas) select $args
458 # ------------------------------------------------------------------
459 # METHOD: type tagOrId
460 # ------------------------------------------------------------------
461 body iwidgets::Scrolledcanvas::type {args} {
462 return [eval $itk_component(canvas) type $args]
465 # ------------------------------------------------------------------
466 # METHOD: xview index
467 # ------------------------------------------------------------------
468 body iwidgets::Scrolledcanvas::xview {args} {
469 eval $itk_component(canvas) xview $args
472 # ------------------------------------------------------------------
473 # METHOD: yview index
474 # ------------------------------------------------------------------
475 body iwidgets::Scrolledcanvas::yview {args} {
476 eval $itk_component(canvas) yview $args