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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#
2
# Scrolledwidget
3
# ----------------------------------------------------------------------
4
# Implements a general purpose base class for scrolled widgets, by
5
# creating the necessary horizontal and vertical scrollbars and
6
# providing protected methods for controlling their display.  The
7
# derived class needs to take advantage of the fact that the grid
8
# is used and the vertical scrollbar is in row 0, column 2 and the
9
# horizontal scrollbar in row 2, column 0.
10
#
11
# ----------------------------------------------------------------------
12
#  AUTHOR: Mark Ulferts                        mulferts@austin.dsccc.com
13
#
14
#  @(#) $Id: scrolledwidget.itk,v 1.1.1.1 2002-01-16 10:24:50 markom Exp $
15
# ----------------------------------------------------------------------
16
#            Copyright (c) 1997 DSC Technologies Corporation
17
# ======================================================================
18
# Permission to use, copy, modify, distribute and license this software
19
# and its documentation for any purpose, and without fee or written
20
# agreement with DSC, is hereby granted, provided that the above copyright
21
# notice appears in all copies and that both the copyright notice and
22
# warranty disclaimer below appear in supporting documentation, and that
23
# the names of DSC Technologies Corporation or DSC Communications
24
# Corporation not be used in advertising or publicity pertaining to the
25
# software without specific, written prior permission.
26
#
27
# DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
28
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-
29
# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE
30
# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE,
31
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL
32
# DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
33
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
34
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
35
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
36
# SOFTWARE.
37
# ======================================================================
38
 
39
#
40
# Usual options.
41
#
42
itk::usual Scrolledwidget {
43
    keep -background -borderwidth -cursor -highlightcolor -highlightthickness
44
    keep -activebackground -activerelief -jump -troughcolor
45
    keep -labelfont -foreground
46
}
47
 
48
# ------------------------------------------------------------------
49
#                            SCROLLEDWIDGET
50
# ------------------------------------------------------------------
51
class iwidgets::Scrolledwidget {
52
    inherit iwidgets::Labeledframe
53
 
54
    constructor {args} {}
55
    destructor {}
56
    method childsite {}
57
 
58
    itk_option define -childsitepos childSitePos Position e
59
    itk_option define -sbwidth sbWidth Width ""
60
    itk_option define -scrollmargin scrollMargin ScrollMargin 3
61
    itk_option define -vscrollmode vscrollMode VScrollMode static
62
    itk_option define -hscrollmode hscrollMode HScrollMode static
63
    itk_option define -width width Width 30
64
    itk_option define -height height Height 30
65
 
66
   protected {
67
     method _scrollWidget {wid first last}
68
     method _vertScrollbarDisplay {mode}
69
     method _horizScrollbarDisplay {mode}
70
     method _configureEvent {}
71
 
72
     variable _vmode off            ;# Vertical scroll mode
73
     variable _hmode off            ;# Vertical scroll mode
74
     variable _recheckHoriz 1       ;# Flag to check need for
75
                                    ;#  horizontal scrollbar
76
     variable _recheckVert 1        ;# Flag to check need for
77
                                    ;#  vertical scrollbar
78
 
79
     variable _interior {}
80
   }
81
}
82
 
83
#
84
# Provide a lowercased access method for the Scrolledwidget class.
85
#
86
proc ::iwidgets::scrolledwidget {pathName args} {
87
    uplevel ::iwidgets::Scrolledwidget $pathName $args
88
}
89
 
90
#
91
# Use option database to override default resources of base classes.
92
#
93
option add *Scrolledwidget.labelPos n widgetDefault
94
 
95
# ------------------------------------------------------------------
96
#                        CONSTRUCTOR
97
# ------------------------------------------------------------------
98
body iwidgets::Scrolledwidget::constructor {args} {
99
 
100
    #
101
    # Turn off the borderwidth on the hull and save off the
102
    # interior for later use.
103
    #
104
    component hull configure -borderwidth 0
105
    set _interior [iwidgets::Labeledframe::childsite]
106
    set itk_interior $_interior
107
 
108
    #
109
    # Check if the scrollbars need mapping upon a configure event.
110
    #
111
    bind $_interior  [code $this _configureEvent]
112
 
113
    #
114
    # Turn off propagation in the containing shell.
115
    #
116
    # Due to a bug in the tk4.2 grid, we have to check the
117
    # propagation before setting it.  Setting it to the same
118
    # value it already is will cause it to toggle.
119
    #
120
    if {[grid propagate $_interior]} {
121
        grid propagate $_interior no
122
    }
123
 
124
    #
125
    # Create the vertical scroll bar
126
    #
127
    itk_component add vertsb {
128
        scrollbar $_interior.vertsb -orient vertical
129
    } {
130
        usual
131
        keep -elementborderwidth -jump
132
        rename -highlightbackground -background background Background
133
    }
134
 
135
    #
136
    # Create the horizontal scrollbar
137
    #
138
    itk_component add horizsb {
139
        scrollbar $_interior.horizsb -orient horizontal
140
    } {
141
        usual
142
        keep -elementborderwidth -jump
143
        rename -highlightbackground -background background Background
144
    }
145
 
146
    #
147
    # Create the childsite frame
148
    #
149
    itk_component add swchildsite {
150
      frame $_interior.cs
151
    }
152
 
153
    #
154
    # Initialize the widget based on the command line options.
155
    #
156
    eval itk_initialize $args
157
}
158
 
159
# ------------------------------------------------------------------
160
#                           DESTURCTOR
161
# ------------------------------------------------------------------
162
body iwidgets::Scrolledwidget::destructor {} {
163
}
164
 
165
# ------------------------------------------------------------------
166
#                             OPTIONS
167
# ------------------------------------------------------------------
168
 
169
# ------------------------------------------------------------------
170
# OPTION: -sbwidth
171
#
172
# Set the width of the scrollbars.
173
# ------------------------------------------------------------------
174
configbody iwidgets::Scrolledwidget::sbwidth {
175
   if {$itk_option(-sbwidth) != ""} {
176
        $itk_component(vertsb) configure -width $itk_option(-sbwidth)
177
        $itk_component(horizsb) configure -width $itk_option(-sbwidth)
178
   }
179
}
180
 
181
# ------------------------------------------------------------------
182
# OPTION: -scrollmargin
183
#
184
# Set the distance between the scrollbars and the list box.
185
# ------------------------------------------------------------------
186
configbody iwidgets::Scrolledwidget::scrollmargin {
187
    set pixels [winfo pixels $_interior $itk_option(-scrollmargin)]
188
 
189
    if {$_hmode == "on"} {
190
        grid rowconfigure $_interior 2 -minsize $pixels
191
    }
192
 
193
    if {$_vmode == "on"} {
194
        grid columnconfigure $_interior 2 -minsize $pixels
195
    }
196
}
197
 
198
# ------------------------------------------------------------------
199
# OPTION: -vscrollmode
200
#
201
# Enable/disable display and mode of veritcal scrollbars.
202
# ------------------------------------------------------------------
203
configbody iwidgets::Scrolledwidget::vscrollmode {
204
    switch $itk_option(-vscrollmode) {
205
        static {
206
            _vertScrollbarDisplay on
207
        }
208
 
209
        dynamic -
210
        none {
211
            _vertScrollbarDisplay off
212
        }
213
 
214
        default {
215
            error "bad vscrollmode option\
216
                    \"$itk_option(-vscrollmode)\": should be\
217
                    static, dynamic, or none"
218
        }
219
    }
220
}
221
 
222
# ------------------------------------------------------------------
223
# OPTION: -hscrollmode
224
#
225
# Enable/disable display and mode of horizontal scrollbars.
226
# ------------------------------------------------------------------
227
configbody iwidgets::Scrolledwidget::hscrollmode {
228
    switch $itk_option(-hscrollmode) {
229
        static {
230
            _horizScrollbarDisplay on
231
        }
232
 
233
        dynamic -
234
        none {
235
            _horizScrollbarDisplay off
236
        }
237
 
238
        default {
239
            error "bad hscrollmode option\
240
                    \"$itk_option(-hscrollmode)\": should be\
241
                    static, dynamic, or none"
242
        }
243
    }
244
}
245
 
246
# ------------------------------------------------------------------
247
# OPTION: -width
248
#
249
# Specifies the width of the scrolled widget.  The value may be
250
# specified in any of the forms acceptable to Tk_GetPixels.
251
# ------------------------------------------------------------------
252
configbody iwidgets::Scrolledwidget::width {
253
    $_interior configure -width \
254
        [winfo pixels $_interior $itk_option(-width)]
255
}
256
 
257
# ------------------------------------------------------------------
258
# OPTION: -height
259
#
260
# Specifies the height of the scrolled widget.  The value may be
261
# specified in any of the forms acceptable to Tk_GetPixels.
262
# ------------------------------------------------------------------
263
configbody iwidgets::Scrolledwidget::height {
264
    $_interior configure -height \
265
        [winfo pixels $_interior $itk_option(-height)]
266
}
267
 
268
# ------------------------------------------------------------------
269
# OPTION: -childsitepos
270
#
271
# Specifies the position of the child site in the widget.
272
# ------------------------------------------------------------------
273
configbody iwidgets::Scrolledwidget::childsitepos {
274
 
275
    # First reset all the other child sites to weight 0 so
276
    # they do not take any of the space...
277
 
278
    switch $itk_option(-childsitepos) {
279
        n {
280
            grid $itk_component(swchildsite) -row 0 -column 1 -columnspan 3 -sticky nsew
281
        }
282
 
283
        s {
284
            grid $itk_component(swchildsite) -row 4 -column 1 -columnspan 3 -sticky nsew
285
        }
286
 
287
        e {
288
            grid $itk_component(swchildsite) -row 1 -column 4 -rowspan 3 -sticky nsew
289
        }
290
 
291
        w {
292
            grid $itk_component(swchildsite) -row 1 -column 0 -rowspan 3 -sticky nsew
293
        }
294
 
295
        default {
296
            error "bad childsite option\
297
                    \"$itk_option(-childsitepos)\":\
298
                    should be n, e, s, or w"
299
        }
300
    }
301
}
302
 
303
# ------------------------------------------------------------------
304
#                            METHODS
305
# ------------------------------------------------------------------
306
 
307
# ------------------------------------------------------------------
308
# METHOD: childsite
309
#
310
# Returns the path name of the child site widget.
311
# ------------------------------------------------------------------
312
body iwidgets::Scrolledwidget::childsite {} {
313
    return $itk_component(swchildsite)
314
}
315
 
316
# ------------------------------------------------------------------
317
# PROTECTED METHOD: _vertScrollbarDisplay mode
318
#
319
# Displays the vertical scrollbar based on the input mode.
320
# ------------------------------------------------------------------
321
body iwidgets::Scrolledwidget::_vertScrollbarDisplay {mode} {
322
    switch $mode  {
323
        on {
324
            set _vmode on
325
 
326
            grid columnconfigure $_interior 2 -minsize \
327
                    [winfo pixels $_interior $itk_option(-scrollmargin)]
328
            grid $itk_component(vertsb) -row 1 -column 3 -sticky ns
329
        }
330
 
331
        off {
332
            set _vmode off
333
 
334
            grid columnconfigure $_interior 2 -minsize 0
335
            grid forget $itk_component(vertsb)
336
        }
337
 
338
        default {
339
            error "invalid argument \"$mode\": should be on or off"
340
        }
341
    }
342
}
343
 
344
# ------------------------------------------------------------------
345
# PROTECTED METHOD: _horizScrollbarDisplay mode
346
#
347
# Displays the horizontal scrollbar based on the input mode.
348
# ------------------------------------------------------------------
349
body iwidgets::Scrolledwidget::_horizScrollbarDisplay {mode} {
350
    switch $mode  {
351
        on {
352
            set _hmode on
353
 
354
            grid rowconfigure $_interior 2 -minsize \
355
                    [winfo pixels $_interior $itk_option(-scrollmargin)]
356
            grid $itk_component(horizsb) -row 3 -column 1 -sticky ew
357
        }
358
 
359
        off {
360
            set _hmode off
361
 
362
            grid rowconfigure $_interior 2 -minsize 0
363
            grid forget $itk_component(horizsb)
364
        }
365
 
366
        default {
367
            error "invalid argument \"$mode\": should be on or off"
368
        }
369
    }
370
}
371
 
372
# ------------------------------------------------------------------
373
# PROTECTED METHOD: _scrollWidget wid first last
374
#
375
# Performs scrolling and display of scrollbars based on the total
376
# and maximum frame size as well as the current -vscrollmode and
377
# -hscrollmode settings.  Parameters are automatic scroll parameters.
378
# ------------------------------------------------------------------
379
body iwidgets::Scrolledwidget::_scrollWidget {wid first last} {
380
    $wid set $first $last
381
 
382
    if {$wid == $itk_component(vertsb)} {
383
        if {$itk_option(-vscrollmode) == "dynamic"} {
384
            if {($_recheckVert != 1) && ($_vmode == "on")} {
385
                return
386
            } else {
387
                set _recheckVert 0
388
            }
389
 
390
            if {($first == 0) && ($last == 1)} {
391
                if {$_vmode != "off"} {
392
                    _vertScrollbarDisplay off
393
                }
394
 
395
            } else {
396
                if {$_vmode != "on"} {
397
                    _vertScrollbarDisplay on
398
                }
399
            }
400
        }
401
 
402
    } elseif {$wid == $itk_component(horizsb)} {
403
        if {$itk_option(-hscrollmode) == "dynamic"} {
404
            if {($_recheckHoriz != 1) && ($_hmode == "on")} {
405
                return
406
            } else {
407
                set _recheckHoriz 0
408
            }
409
 
410
            if {($first == 0) && ($last == 1)} {
411
                if {$_hmode != "off"} {
412
                    _horizScrollbarDisplay off
413
                }
414
 
415
            } else {
416
                if {$_hmode != "on"} {
417
                    _horizScrollbarDisplay on
418
                }
419
            }
420
        }
421
    }
422
}
423
 
424
# ------------------------------------------------------------------
425
# PROTECTED METHOD: _configureEvent
426
#
427
# Resets the recheck flags which determine if we'll try and map
428
# the scrollbars in dynamic mode.
429
# ------------------------------------------------------------------
430
body iwidgets::Scrolledwidget::_configureEvent {} {
431
    update idletasks
432
    set _recheckVert 1
433
    set _recheckHoriz 1
434
}

powered by: WebSVN 2.1.0

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