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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#
2
# Scrolledcanvas
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.
7
#
8
# ----------------------------------------------------------------------
9
#  AUTHOR: Mark Ulferts                        mulferts@austin.dsccc.com
10
#
11
#  @(#) $Id: scrolledcanvas.itk,v 1.1.1.1 2002-01-16 10:24:50 markom Exp $
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.
23
#
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
33
# SOFTWARE.
34
# ======================================================================
35
 
36
#
37
# Usual options.
38
#
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
45
}
46
 
47
# ------------------------------------------------------------------
48
#                            SCROLLEDCANVAS
49
# ------------------------------------------------------------------
50
class iwidgets::Scrolledcanvas {
51
    inherit iwidgets::Scrolledwidget
52
 
53
    constructor {args} {}
54
    destructor {}
55
 
56
    itk_option define -autoresize autoResize AutoResize 1
57
    itk_option define -automargin autoMargin AutoMargin 0
58
 
59
    public method childsite {}
60
    public method justify {direction}
61
 
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}
90
}
91
 
92
#
93
# Provide a lowercased access method for the Scrolledcanvas class.
94
#
95
proc ::iwidgets::scrolledcanvas {pathName args} {
96
    uplevel ::iwidgets::Scrolledcanvas $pathName $args
97
}
98
 
99
#
100
# Use option database to override default resources of base classes.
101
#
102
option add *Scrolledcanvas.width 200 widgetDefault
103
option add *Scrolledcanvas.height 230 widgetDefault
104
option add *Scrolledcanvas.labelPos n widgetDefault
105
 
106
# ------------------------------------------------------------------
107
#                        CONSTRUCTOR
108
# ------------------------------------------------------------------
109
body iwidgets::Scrolledcanvas::constructor {args} {
110
    #
111
    # Create a clipping frame which will provide the border for
112
    # relief display.
113
    #
114
    itk_component add clipper {
115
        frame $itk_interior.clipper
116
    } {
117
        usual
118
 
119
        keep -borderwidth -relief -highlightthickness -highlightcolor
120
        rename -highlightbackground -background background Background
121
    }
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
125
 
126
    #
127
    # Create a canvas to scroll
128
    #
129
    itk_component add canvas {
130
        canvas $itk_component(clipper).canvas \
131
                -height 1.0 -width 1.0 \
132
                -scrollregion "0 0 1 1" \
133
                -xscrollcommand \
134
                [code $this _scrollWidget $itk_interior.horizsb] \
135
                -yscrollcommand \
136
                [code $this _scrollWidget $itk_interior.vertsb]
137
    } {
138
        usual
139
 
140
        ignore -highlightthickness -highlightcolor
141
 
142
        keep -closeenough -confine -scrollregion
143
        keep -xscrollincrement -yscrollincrement
144
 
145
        rename -background -textbackground textBackground Background
146
    }
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
150
 
151
    #
152
    # Configure the command on the vertical scroll bar in the base class.
153
    #
154
    $itk_component(vertsb) configure \
155
        -command [code $itk_component(canvas) yview]
156
 
157
    #
158
    # Configure the command on the horizontal scroll bar in the base class.
159
    #
160
    $itk_component(horizsb) configure \
161
                -command [code $itk_component(canvas) xview]
162
 
163
    #
164
    # Initialize the widget based on the command line options.
165
    #
166
    eval itk_initialize $args
167
}
168
 
169
# ------------------------------------------------------------------
170
#                           DESTURCTOR
171
# ------------------------------------------------------------------
172
body iwidgets::Scrolledcanvas::destructor {} {
173
}
174
 
175
# ------------------------------------------------------------------
176
#                             OPTIONS
177
# ------------------------------------------------------------------
178
 
179
# ------------------------------------------------------------------
180
# OPTION: -autoresize
181
#
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]
190
 
191
        if {$bbox != {}} {
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]]
197
        }
198
 
199
        $itk_component(canvas) configure -scrollregion $bbox
200
    }
201
}
202
 
203
# ------------------------------------------------------------------
204
#                            METHODS
205
# ------------------------------------------------------------------
206
 
207
# ------------------------------------------------------------------
208
# METHOD: childsite
209
#
210
# Returns the path name of the child site widget.
211
# ------------------------------------------------------------------
212
body iwidgets::Scrolledcanvas::childsite {} {
213
    return $itk_component(canvas)
214
}
215
 
216
# ------------------------------------------------------------------
217
# METHOD: justify
218
#
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)]} {
224
        update idletasks
225
 
226
        switch $direction {
227
            left {
228
                $itk_component(canvas) xview moveto 0
229
            }
230
            right {
231
                $itk_component(canvas) xview moveto 1
232
            }
233
            top {
234
                $itk_component(canvas) yview moveto 0
235
            }
236
            bottom {
237
                $itk_component(canvas) yview moveto 1
238
            }
239
            default {
240
                error "bad justify argument \"$direction\": should be\
241
                        left, right, top, or bottom"
242
            }
243
        }
244
    }
245
}
246
 
247
# ------------------------------------------------------------------
248
# CANVAS METHODS:
249
#
250
# The following methods are thin wraps of standard canvas methods.
251
# Consult the Tk canvas man pages for functionallity and argument
252
# documentation
253
# ------------------------------------------------------------------
254
 
255
# ------------------------------------------------------------------
256
# METHOD: addtag tag searchSpec ?arg arg ...?
257
# ------------------------------------------------------------------
258
body iwidgets::Scrolledcanvas::addtag {args} {
259
    return [eval $itk_component(canvas) addtag $args]
260
}
261
 
262
# ------------------------------------------------------------------
263
# METHOD: bbox tagOrId ?tagOrId tagOrId ...?
264
# ------------------------------------------------------------------
265
body iwidgets::Scrolledcanvas::bbox {args} {
266
    return [eval $itk_component(canvas) bbox $args]
267
}
268
 
269
# ------------------------------------------------------------------
270
# METHOD: bind tagOrId ?sequence? ?command?
271
# ------------------------------------------------------------------
272
body iwidgets::Scrolledcanvas::bind {args} {
273
    return [eval $itk_component(canvas) bind $args]
274
}
275
 
276
# ------------------------------------------------------------------
277
# METHOD: canvasx screenx ?gridspacing?
278
# ------------------------------------------------------------------
279
body iwidgets::Scrolledcanvas::canvasx {args} {
280
    return [eval $itk_component(canvas) canvasx $args]
281
}
282
 
283
# ------------------------------------------------------------------
284
# METHOD: canvasy screeny ?gridspacing?
285
# ------------------------------------------------------------------
286
body iwidgets::Scrolledcanvas::canvasy {args} {
287
    return [eval $itk_component(canvas) canvasy $args]
288
}
289
 
290
# ------------------------------------------------------------------
291
# METHOD: coords tagOrId ?x0 y0 ...?
292
# ------------------------------------------------------------------
293
body iwidgets::Scrolledcanvas::coords {args} {
294
    return [eval $itk_component(canvas) coords $args]
295
}
296
 
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]
302
 
303
    configure -autoresize $itk_option(-autoresize)
304
 
305
    return $retval
306
}
307
 
308
# ------------------------------------------------------------------
309
# METHOD: dchars  tagOrId first ?last?
310
# ------------------------------------------------------------------
311
body iwidgets::Scrolledcanvas::dchars {args} {
312
    return [eval $itk_component(canvas) dchars $args]
313
}
314
 
315
# ------------------------------------------------------------------
316
# METHOD: delete tagOrId ?tagOrId tagOrId ...?
317
# ------------------------------------------------------------------
318
body iwidgets::Scrolledcanvas::delete {args} {
319
    set retval [eval $itk_component(canvas) delete $args]
320
 
321
    configure -autoresize $itk_option(-autoresize)
322
 
323
    return $retval
324
}
325
 
326
# ------------------------------------------------------------------
327
# METHOD: dtag tagOrId ?tagToDelete?
328
# ------------------------------------------------------------------
329
body iwidgets::Scrolledcanvas::dtag {args} {
330
    eval $itk_component(canvas) dtag $args
331
 
332
    configure -autoresize $itk_option(-autoresize)
333
}
334
 
335
# ------------------------------------------------------------------
336
# METHOD: find searchCommand ?arg arg ...?
337
# ------------------------------------------------------------------
338
body iwidgets::Scrolledcanvas::find {args} {
339
    return [eval $itk_component(canvas) find $args]
340
}
341
 
342
# ------------------------------------------------------------------
343
# METHOD: focus ?tagOrId?
344
# ------------------------------------------------------------------
345
body iwidgets::Scrolledcanvas::focus {args} {
346
    return [eval $itk_component(canvas) focus $args]
347
}
348
 
349
# ------------------------------------------------------------------
350
# METHOD: gettags tagOrId
351
# ------------------------------------------------------------------
352
body iwidgets::Scrolledcanvas::gettags {args} {
353
    return [eval $itk_component(canvas) gettags $args]
354
}
355
 
356
# ------------------------------------------------------------------
357
# METHOD: icursor tagOrId index
358
# ------------------------------------------------------------------
359
body iwidgets::Scrolledcanvas::icursor {args} {
360
    eval $itk_component(canvas) icursor $args
361
}
362
 
363
# ------------------------------------------------------------------
364
# METHOD: index tagOrId index
365
# ------------------------------------------------------------------
366
body iwidgets::Scrolledcanvas::index {args} {
367
    return [eval $itk_component(canvas) index $args]
368
}
369
 
370
# ------------------------------------------------------------------
371
# METHOD: insert tagOrId beforeThis string
372
# ------------------------------------------------------------------
373
body iwidgets::Scrolledcanvas::insert {args} {
374
    eval $itk_component(canvas) insert $args
375
}
376
 
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]
382
 
383
    configure -autoresize $itk_option(-autoresize)
384
 
385
    return $retval
386
}
387
 
388
# ------------------------------------------------------------------
389
# METHOD: itemcget tagOrId ?option?
390
# ------------------------------------------------------------------
391
body iwidgets::Scrolledcanvas::itemcget {args} {
392
    set retval [eval $itk_component(canvas) itemcget $args]
393
 
394
    return $retval
395
}
396
 
397
# ------------------------------------------------------------------
398
# METHOD: lower tagOrId ?belowThis?
399
# ------------------------------------------------------------------
400
body iwidgets::Scrolledcanvas::lower {args} {
401
    eval $itk_component(canvas) lower $args
402
}
403
 
404
# ------------------------------------------------------------------
405
# METHOD: move tagOrId xAmount yAmount
406
# ------------------------------------------------------------------
407
body iwidgets::Scrolledcanvas::move {args} {
408
    eval $itk_component(canvas) move $args
409
 
410
    configure -autoresize $itk_option(-autoresize)
411
}
412
 
413
# ------------------------------------------------------------------
414
# METHOD: postscript ?option value ...?
415
# ------------------------------------------------------------------
416
body iwidgets::Scrolledcanvas::postscript {args} {
417
    #
418
    # Make sure the fontmap is in scope.
419
    #
420
    set fontmap ""
421
    regexp -- {-fontmap +([^ ]+)} $args all fontmap
422
 
423
    if {$fontmap != ""} {
424
        global $fontmap
425
    }
426
 
427
    return [eval $itk_component(canvas) postscript $args]
428
}
429
 
430
# ------------------------------------------------------------------
431
# METHOD: raise tagOrId ?aboveThis?
432
# ------------------------------------------------------------------
433
body iwidgets::Scrolledcanvas::raise {args} {
434
    eval $itk_component(canvas) raise $args
435
}
436
 
437
# ------------------------------------------------------------------
438
# METHOD: scale tagOrId xOrigin yOrigin xScale yScale
439
# ------------------------------------------------------------------
440
body iwidgets::Scrolledcanvas::scale {args} {
441
    eval $itk_component(canvas) scale $args
442
}
443
 
444
# ------------------------------------------------------------------
445
# METHOD: scan option args
446
# ------------------------------------------------------------------
447
body iwidgets::Scrolledcanvas::scan {args} {
448
    eval $itk_component(canvas) scan $args
449
}
450
 
451
# ------------------------------------------------------------------
452
# METHOD: select option ?tagOrId arg?
453
# ------------------------------------------------------------------
454
body iwidgets::Scrolledcanvas::select {args} {
455
    eval $itk_component(canvas) select $args
456
}
457
 
458
# ------------------------------------------------------------------
459
# METHOD: type tagOrId
460
# ------------------------------------------------------------------
461
body iwidgets::Scrolledcanvas::type {args} {
462
    return [eval $itk_component(canvas) type $args]
463
}
464
 
465
# ------------------------------------------------------------------
466
# METHOD: xview index
467
# ------------------------------------------------------------------
468
body iwidgets::Scrolledcanvas::xview {args} {
469
    eval $itk_component(canvas) xview $args
470
}
471
 
472
# ------------------------------------------------------------------
473
# METHOD: yview index
474
# ------------------------------------------------------------------
475
body iwidgets::Scrolledcanvas::yview {args} {
476
    eval $itk_component(canvas) yview $args
477
}

powered by: WebSVN 2.1.0

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