OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [iwidgets3.0.0/] [generic/] [scrolledframe.itk] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.