1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
#
# Scrolledframe
# ----------------------------------------------------------------------
# Implements horizontal and vertical scrollbars around a childsite
# frame. Includes options to control display of scrollbars.
#
# ----------------------------------------------------------------------
# AUTHOR: Mark Ulferts mulferts@austin.dsccc.com
#
# @(#) $Id$
# ----------------------------------------------------------------------
# Copyright (c) 1995 DSC Technologies Corporation
# ======================================================================
# Permission to use, copy, modify, distribute and license this software
# and its documentation for any purpose, and without fee or written
# agreement with DSC, is hereby granted, provided that the above copyright
# notice appears in all copies and that both the copyright notice and
# warranty disclaimer below appear in supporting documentation, and that
# the names of DSC Technologies Corporation or DSC Communications
# Corporation not be used in advertising or publicity pertaining to the
# software without specific, written prior permission.
#
# DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-
# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE
# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL
# DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.
# ======================================================================
#
# Usual options.
#
itk::usual Scrolledframe {
keep -activebackground -activerelief -background -borderwidth -cursor \
-elementborderwidth -foreground -highlightcolor -highlightthickness \
-jump -labelfont -troughcolor
}
# ------------------------------------------------------------------
# SCROLLEDFRAME
# ------------------------------------------------------------------
class iwidgets::Scrolledframe {
inherit iwidgets::Scrolledwidget
constructor {args} {}
destructor {}
public method childsite {}
public method justify {direction}
public method xview {args}
public method yview {args}
protected method _configureCanvas {}
protected method _configureFrame {}
}
#
# Provide a lowercased access method for the Scrolledframe class.
#
proc ::iwidgets::scrolledframe {pathName args} {
uplevel ::iwidgets::Scrolledframe $pathName $args
}
#
# Use option database to override default resources of base classes.
#
option add *Scrolledframe.width 100 widgetDefault
option add *Scrolledframe.height 100 widgetDefault
option add *Scrolledframe.labelPos n widgetDefault
# ------------------------------------------------------------------
# CONSTRUCTOR
# ------------------------------------------------------------------
body iwidgets::Scrolledframe::constructor {args} {
itk_option remove iwidgets::Labeledwidget::state
#
# Create a clipping frame which will provide the border for
# relief display.
#
itk_component add clipper {
frame $itk_interior.clipper
} {
usual
keep -borderwidth -relief
}
grid $itk_component(clipper) -row 1 -column 1 -sticky nsew
grid rowconfigure $_interior 1 -weight 1
grid columnconfigure $_interior 1 -weight 1
#
# Create a canvas to scroll
#
itk_component add canvas {
canvas $itk_component(clipper).canvas \
-height 1.0 -width 1.0 \
-scrollregion "0 0 1 1" \
-xscrollcommand \
[code $this _scrollWidget $itk_interior.horizsb] \
-yscrollcommand \
[code $this _scrollWidget $itk_interior.vertsb] \
-highlightthickness 0 -takefocus 0
} {
ignore -highlightcolor -highlightthickness
keep -background -cursor
}
grid $itk_component(canvas) -row 0 -column 0 -sticky nsew
grid rowconfigure $itk_component(clipper) 0 -weight 1
grid columnconfigure $itk_component(clipper) 0 -weight 1
#
# Configure the command on the vertical scroll bar in the base class.
#
$itk_component(vertsb) configure \
-command [code $itk_component(canvas) yview]
#
# Configure the command on the horizontal scroll bar in the base class.
#
$itk_component(horizsb) configure \
-command [code $itk_component(canvas) xview]
#
# Handle configure events on the canvas to adjust the frame size
# according to the scrollregion.
#
bind $itk_component(canvas) <Configure> [code $this _configureCanvas]
#
# Create a Frame inside canvas to hold widgets to be scrolled
#
itk_component add -protected sfchildsite {
frame $itk_component(canvas).sfchildsite
} {
keep -background -cursor
}
pack $itk_component(sfchildsite) -fill both -expand yes
$itk_component(canvas) create window 0 0 -tags frameTag \
-window $itk_component(sfchildsite) -anchor nw
set itk_interior $itk_component(sfchildsite)
bind $itk_component(sfchildsite) <Configure> [code $this _configureFrame]
#
# Initialize the widget based on the command line options.
#
eval itk_initialize $args
}
# ------------------------------------------------------------------
# DESTURCTOR
# ------------------------------------------------------------------
body iwidgets::Scrolledframe::destructor {} {
}
# ------------------------------------------------------------------
# METHODS
# ------------------------------------------------------------------
# ------------------------------------------------------------------
# METHOD: childsite
#
# Returns the path name of the child site widget.
# ------------------------------------------------------------------
body iwidgets::Scrolledframe::childsite {} {
return $itk_component(sfchildsite)
}
# ------------------------------------------------------------------
# METHOD: justify
#
# Justifies the scrolled region in one of four directions: top,
# bottom, left, or right.
# ------------------------------------------------------------------
body iwidgets::Scrolledframe::justify {direction} {
if {[winfo ismapped $itk_component(canvas)]} {
update idletasks
switch $direction {
left {
$itk_component(canvas) xview moveto 0
}
right {
$itk_component(canvas) xview moveto 1
}
top {
$itk_component(canvas) yview moveto 0
}
bottom {
$itk_component(canvas) yview moveto 1
}
default {
error "bad justify argument \"$direction\": should be\
left, right, top, or bottom"
}
}
}
}
# ------------------------------------------------------------------
# METHOD: xview index
#
# Adjust the view in the frame so that character position index
# is displayed at the left edge of the widget.
# ------------------------------------------------------------------
body iwidgets::Scrolledframe::xview {args} {
return [eval $itk_component(canvas) xview $args]
}
# ------------------------------------------------------------------
# METHOD: yview index
#
# Adjust the view in the frame so that character position index
# is displayed at the top edge of the widget.
# ------------------------------------------------------------------
body iwidgets::Scrolledframe::yview {args} {
return [eval $itk_component(canvas) yview $args]
}
# ------------------------------------------------------------------
# PRIVATE METHOD: _configureCanvas
#
# Responds to configure events on the canvas widget. When canvas
# changes size, adjust frame size.
# ------------------------------------------------------------------
body iwidgets::Scrolledframe::_configureCanvas {} {
set sr [$itk_component(canvas) cget -scrollregion]
set srw [lindex $sr 2]
set srh [lindex $sr 3]
$itk_component(sfchildsite) configure -height $srh -width $srw
}
# ------------------------------------------------------------------
# PRIVATE METHOD: _configureFrame
#
# Responds to configure events on the frame widget. When the frame
# changes size, adjust scrolling region size.
# ------------------------------------------------------------------
body iwidgets::Scrolledframe::_configureFrame {} {
$itk_component(canvas) configure \
-scrollregion [$itk_component(canvas) bbox frameTag]
}
|