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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [library/] [CObjView.tcl] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# CObjView.tcl --
2
#
3
#       This file implements the Canvas Object View widget. This is a base
4
#       class of IconView. It implements:
5
 
6
#       (1) Automatic placement/adjustment of the scrollbars according
7
#       to the canvas objects inside the canvas subwidget. The
8
#       scrollbars are adjusted so that the canvas is just large
9
#       enough to see all the objects.
10
#
11
#       (2) D+D bindings of the objects (%% not implemented)
12
#
13
#       (3) Keyboard traversal of the objects (%% not implemented). By the
14
#       virtual method :SelectObject.
15
#
16
#
17
# Copyright (c) 1996, Expert Interface Technologies
18
#
19
# See the file "license.terms" for information on usage and redistribution
20
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
21
#
22
 
23
tixWidgetClass tixCObjView {
24
    -classname TixCObjView
25
    -superclass tixScrolledWidget
26
    -method {
27
        adjustscrollregion
28
    }
29
    -flag {
30
        -xscrollincrement -yscrollincrement
31
    }
32
    -static {
33
    }
34
    -configspec {
35
        {-xscrollincrement xScrollIncrement ScrollIncrement 10}
36
        {-yscrollincrement yScrollIncrement ScrollIncrement 10}
37
    }
38
    -default {
39
        {.scrollbar                     auto}
40
        {*borderWidth                   1}
41
        {*canvas.background             #c3c3c3}
42
        {*canvas.highlightBackground    #d9d9d9}
43
        {*canvas.relief                 sunken}
44
        {*canvas.takeFocus              1}
45
        {*Scrollbar.background          #d9d9d9}
46
        {*Scrollbar.relief              sunken}
47
        {*Scrollbar.troughColor         #c3c3c3}
48
        {*Scrollbar.takeFocus           0}
49
        {*Scrollbar.width               15}
50
    }
51
    -forcecall {
52
        -scrollbar
53
    }
54
}
55
 
56
proc tixCObjView:ConstructWidget {w} {
57
    upvar #0 $w data
58
 
59
    tixChainMethod $w ConstructWidget
60
 
61
    set data(w:canvas) \
62
        [canvas $w.canvas]
63
    set data(w:hsb) \
64
        [scrollbar $w.hsb -orient horizontal]
65
    set data(w:vsb) \
66
        [scrollbar $w.vsb -orient vertical]
67
 
68
    set data(pw:client) $data(w:canvas)
69
 
70
    set data(xorig) 0
71
    set data(yorig) 0
72
 
73
    set data(sx1) 0
74
    set data(sy1) 0
75
    set data(sx2) 0
76
    set data(sy2) 0
77
}
78
 
79
proc tixCObjView:SetBindings {w} {
80
    upvar #0 $w data
81
 
82
    tixChainMethod $w SetBindings
83
 
84
# %% scan/drag of canvas??
85
#
86
#    $data(w:canvas) config \
87
#       -xscrollcommand "tixCObjView:XScroll $w"\
88
#       -yscrollcommand "tixCObjView:YScroll $w"
89
 
90
    $data(w:hsb) config -command "tixCObjView:UserScroll $w x"
91
    $data(w:vsb) config -command "tixCObjView:UserScroll $w y"
92
}
93
 
94
#----------------------------------------------------------------------
95
#
96
#               option configs
97
#----------------------------------------------------------------------
98
proc tixCObjView:config-takefocus {w value} {
99
    upvar #0 $w data
100
 
101
    $data(w:canvas) config -takefocus $value
102
}
103
 
104
#----------------------------------------------------------------------
105
#
106
#               Widget commands
107
#----------------------------------------------------------------------
108
proc tixCObjView:adjustscrollregion {w} {
109
    upvar #0 $w data
110
 
111
    set cW [tixWinWidth  $data(w:canvas)]
112
    set cH [tixWinHeight $data(w:canvas)]
113
 
114
    tixCObjView:GetScrollRegion $w $cW $cH 1 1
115
}
116
 
117
#----------------------------------------------------------------------
118
#
119
#               Private Methods
120
#----------------------------------------------------------------------
121
 
122
proc tixCObjView:GeometryInfo {w cW cH} {
123
    upvar #0 $w data
124
 
125
    set bd \
126
        [expr [$data(w:canvas) cget -bd] + [$data(w:canvas) cget -highlightthickness]]
127
 
128
    incr cW -[expr 2*$bd]
129
    incr cH -[expr 2*$bd]
130
 
131
    return [tixCObjView:GetScrollRegion $w $cW $cH 0 0]
132
}
133
 
134
proc tixCObjView:PlaceWindow {w} {
135
    upvar #0 $w data
136
 
137
    set cW [tixWinWidth  $data(w:canvas)]
138
    set cH [tixWinHeight $data(w:canvas)]
139
 
140
    tixCObjView:GetScrollRegion $w $cW $cH 1 0
141
 
142
    tixChainMethod $w PlaceWindow
143
}
144
 
145
proc tixCObjView:GetScrollRegion {w cW cH setReg callConfig} {
146
    upvar #0 $w data
147
 
148
    set x1max $data(xorig)
149
    set y1max $data(yorig)
150
 
151
    set x2min [expr $x1max + $cW - 1]
152
    set y2min [expr $y1max + $cH - 1]
153
 
154
    set bbox [$data(w:canvas) bbox all]
155
 
156
    if {$bbox == ""} {
157
        set bbox {0 0 1 1}
158
    }
159
 
160
    set x1 [lindex $bbox 0]
161
    set y1 [lindex $bbox 1]
162
    set x2 [lindex $bbox 2]
163
    set y2 [lindex $bbox 3]
164
 
165
    set bd \
166
        [expr [$data(w:canvas) cget -bd] + [$data(w:canvas) cget -highlightthickness]]
167
 
168
    incr x1 -$bd
169
    incr y1 -$bd
170
    incr x2 -$bd
171
    incr y2 -$bd
172
 
173
    if {$x1 > $x1max} {
174
        set x1 $x1max
175
    }
176
    if {$y1 > $y1max} {
177
        set y1 $y1max
178
    }
179
    if {$x2 < $x2min} {
180
        set x2 $x2min
181
    }
182
    if {$y2 < $y2min} {
183
        set y2 $y2min
184
    }
185
 
186
    set data(sx1) $x1
187
    set data(sy1) $y1
188
    set data(sx2) $x2
189
    set data(sy2) $y2
190
 
191
    set sW [expr $x2 - $x1 + 1]
192
    set sH [expr $y2 - $y1 + 1]
193
 
194
#    puts "sregion = {$x1 $y1 $x2 $y2}; sW=$sW; cW=$cW"
195
 
196
    if {$sW > $cW} {
197
        set hsbSpec {0.5 1}
198
    } else {
199
        set hsbSpec {0 1}
200
    }
201
    if {$sH > $cH} {
202
        set vsbSpec {0.5 1}
203
    } else {
204
        set vsbSpec {0 1}
205
    }
206
 
207
    if $setReg {
208
        tixCObjView:SetScrollBars $w $cW $cH $sW $sH
209
    }
210
    if $callConfig {
211
        tixWidgetDoWhenIdle tixScrolledWidget:Configure $w
212
    }
213
 
214
    return [list $hsbSpec $vsbSpec]
215
}
216
 
217
#xF = xFirst
218
#
219
proc tixCObjView:SetScrollBars {w cW cH sW sH} {
220
    upvar #0 $w data
221
 
222
#    puts "$data(xorig) <--> $data(sx1)"
223
 
224
    set xF [expr ($data(xorig).0-$data(sx1).0)/$sW.0]
225
    set xL [expr $cW.0/$sW.0 + $xF]
226
 
227
    set yF [expr ($data(yorig).0-$data(sy1).0)/$sH.0]
228
    set yL [expr $cH.0/$sH.0 + $yF]
229
 
230
#    puts "$xF $xL : $yF $yL"
231
    $data(w:hsb) set $xF $xL
232
    $data(w:vsb) set $yF $yL
233
}
234
 
235
proc tixCObjView:UserScroll {w dir type args} {
236
    upvar #0 $w data
237
 
238
    $data(w:canvas) config -xscrollincrement 1 -yscrollincrement 1
239
 
240
    case $dir {
241
        x {
242
            set n $data(xorig)
243
            set orig $data(xorig)
244
            set s1 $data(sx1)
245
            set total [expr $data(sx2)-$data(sx1)]
246
            set page  [tixWinWidth $data(w:canvas)]
247
            set min $data(sx1)
248
            set max [expr $data(sx1)+$total-$page]
249
            set inc $data(-xscrollincrement)
250
        }
251
        y {
252
            set n $data(yorig)
253
            set orig $data(yorig)
254
            set s1 $data(sy1)
255
            set total [expr $data(sy2)-$data(sy1)]
256
            set page  [tixWinHeight $data(w:canvas)]
257
            set min $data(sy1)
258
            set max [expr $data(sy1)+$total-$page]
259
            set inc $data(-yscrollincrement)
260
        }
261
    }
262
 
263
    case $type {
264
        scroll {
265
            set amt  [lindex $args 0]
266
            set unit [lindex $args 1]
267
 
268
            case $unit {
269
                units {
270
                    incr n [expr int($inc)*$amt]
271
                }
272
                pages {
273
                    incr n [expr $page*$amt]
274
                }
275
            }
276
        }
277
        moveto {
278
            set first [lindex $args 0]
279
            set n [expr round($first*$total)+$s1]
280
        }
281
    }
282
 
283
    if {$n < $min} {
284
        set n $min
285
    }
286
    if {$n > $max} {
287
        set n $max
288
    }
289
 
290
#    puts "n=$n min=$min max=$max"
291
 
292
    case $dir {
293
        x {
294
            $data(w:canvas) xview scroll [expr $n-$orig] units
295
            set data(xorig) $n
296
        }
297
        y {
298
            $data(w:canvas) yview scroll [expr $n-$orig] units
299
            set data(yorig) $n
300
        }
301
    }
302
 
303
    set cW [tixWinWidth $data(w:canvas)]
304
    set cH [tixWinHeight $data(w:canvas)]
305
    set sW [expr $data(sx2)-$data(sx1)+1]
306
    set sH [expr $data(sy2)-$data(sy1)+1]
307
 
308
    tixCObjView:SetScrollBars $w $cW $cH $sW $sH
309
}
310
 
311
# Junk
312
#
313
#
314
proc tixCObjView:XScroll {w first last} {
315
    upvar #0 $w data
316
 
317
    set sc [$data(w:canvas) cget -scrollregion]
318
    if {$sc == ""} {
319
        set x1 1
320
        set x2 [tixWinWidth $data(w:canvas)]
321
    } else {
322
        set x1 [lindex $sc 0]
323
        set x2 [lindex $sc 2]
324
    }
325
 
326
    set W [expr $x2 - $x1]
327
    if {$W < 1} {
328
        set W 1
329
    }
330
 
331
    $data(w:hsb) set $first $last
332
 
333
#    tixWidgetDoWhenIdle tixScrolledWidget:Configure $w
334
}
335
 
336
# Junk
337
#
338
proc tixCObjView:YScroll {w first last} {
339
    upvar #0 $w data
340
 
341
    set sc [$data(w:canvas) cget -scrollregion]
342
 
343
    if {$sc == ""} {
344
        set y1 1
345
        set y2 [tixWinHeight $data(w:canvas)]
346
    } else {
347
        set y1 [lindex $sc 1]
348
        set y2 [lindex $sc 3]
349
    }
350
 
351
    set H [expr $y2 - $y1]
352
    if {$H < 1} {
353
        set H 1
354
    }
355
 
356
    $data(w:vsb) set $first $last
357
 
358
#   tixWidgetDoWhenIdle tixScrolledWidget:Configure $w
359
}

powered by: WebSVN 2.1.0

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