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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [library/] [IconView.tcl] - Blame information for rev 1778

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# IconView.tcl --
2
#
3
#       This file implements the Icon View widget: the "icon" view mode of
4
#       the MultiView widget. It implements:
5
#
6
#       (1) Creation of the icons in the canvas subwidget.
7
#       (2) Automatic arrangement of the objects
8
#
9
# Copyright (c) 1996, Expert Interface Technologies
10
#
11
# See the file "license.terms" for information on usage and redistribution
12
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13
#
14
 
15
tixWidgetClass tixIconView {
16
    -classname TixIconView
17
    -superclass tixCObjView
18
    -method {
19
        add arrange
20
    }
21
    -flag {
22
        -autoarrange
23
    }
24
    -static {
25
    }
26
    -configspec {
27
        {-autoarrange autoArrange AutoArrange 0 tixVerifyBoolean}
28
    }
29
    -default {
30
        {.scrollbar                     auto}
31
        {*borderWidth                   1}
32
        {*canvas.background             #c3c3c3}
33
        {*canvas.highlightBackground    #d9d9d9}
34
        {*canvas.relief                 sunken}
35
        {*canvas.takeFocus              1}
36
        {*Scrollbar.background          #d9d9d9}
37
        {*Scrollbar.relief              sunken}
38
        {*Scrollbar.troughColor         #c3c3c3}
39
        {*Scrollbar.takeFocus           0}
40
        {*Scrollbar.width               15}
41
    }
42
    -forcecall {
43
    }
44
}
45
 
46
proc tixIconView:ConstructWidget {w} {
47
    upvar #0 $w data
48
 
49
    tixChainMethod $w ConstructWidget
50
}
51
 
52
proc tixIconView:SetBindings {w} {
53
    upvar #0 $w data
54
 
55
    tixChainMethod $w SetBindings
56
 
57
    set c $data(w:canvas)
58
 
59
    bind $c <1>         "tixIconView:StartDrag $w %x %y"
60
    bind $c <B1-Motion> "tixIconView:Drag $w %x %y"
61
    bind $c <ButtonRelease-1> "tixIconView:EndDrag $w"
62
}
63
 
64
proc tixIconView:StartDrag {w x y} {
65
    upvar #0 $w data
66
    global lastX lastY
67
 
68
    set c $data(w:canvas)
69
    $c raise current
70
 
71
    set lastX [$c canvasx $x]
72
    set lastY [$c canvasy $y]
73
}
74
 
75
 
76
proc tixIconView:Drag {w x y} {
77
    upvar #0 $w data
78
    global lastX lastY
79
 
80
    set c $data(w:canvas)
81
    set x [$c canvasx $x]
82
    set y [$c canvasy $y]
83
    $c move current [expr $x-$lastX] [expr $y-$lastY]
84
    set lastX $x
85
    set lastY $y
86
}
87
 
88
proc tixIconView:EndDrag {w} {
89
    upvar #0 $w data
90
 
91
    tixCallMethod $w adjustscrollregion
92
}
93
 
94
#----------------------------------------------------------------------
95
#
96
#               option configs
97
#----------------------------------------------------------------------
98
proc tixIconView:add {w tag image text} {
99
    upvar #0 $w data
100
 
101
    set cmp [image create compound -window $data(w:canvas)]
102
 
103
    $cmp add image -image $image
104
    $cmp add line
105
    $cmp add text -text $text
106
 
107
    set id [$data(w:canvas) create image 0 0 -image $cmp -anchor nw]
108
    $data(w:canvas) addtag $tag withtag $id
109
 
110
    if {$data(-autoarrange)} {
111
        tixWidgetDoWhenIdle tixIconView:Arrange $w 1
112
    }
113
}
114
 
115
# Do it in an idle handler, so that Arrange is not called before the window
116
# is properly mapped.
117
#
118
proc tixIconView:arrange {w} {
119
    tixWidgetDoWhenIdle tixIconView:Arrange $w 1
120
}
121
 
122
 
123
proc tixIconView:PackOneRow {w row y maxH bd padX padY} {
124
    upvar #0 $w data
125
 
126
    set iX [expr $bd+$padX]
127
    foreach i $row {
128
        set box [$data(w:canvas) bbox $i]
129
        set W [expr [lindex $box 2]-[lindex $box 0]+1]
130
        set H [expr [lindex $box 3]-[lindex $box 1]+1]
131
 
132
        set iY [expr $y + $maxH - $H]
133
        $data(w:canvas) coords $i $iX $iY
134
        incr iX [expr $W+$padX]
135
    }
136
}
137
 
138
# virtual method
139
#
140
proc tixIconView:PlaceWindow {w} {
141
    upvar #0 $w data
142
 
143
    if {$data(-autoarrange)} {
144
        tixWidgetDoWhenIdle tixIconView:Arrange $w 0
145
    }
146
 
147
    tixChainMethod $w PlaceWindow
148
}
149
 
150
proc tixIconView:Arrange {w adjust} {
151
    upvar #0 $w data
152
 
153
    set padX 2
154
    set padY 2
155
 
156
    tixIconView:ArrangeGrid $w $padX $padY
157
    if {$adjust} {
158
        tixCallMethod $w adjustscrollregion
159
    }
160
}
161
 
162
# the items are not packed
163
#
164
proc tixIconView:ArrangeGrid {w padX padY} {
165
    upvar #0 $w data
166
 
167
    set maxW 0
168
    set maxH 0
169
    foreach item [$data(w:canvas) find all] {
170
        set box [$data(w:canvas) bbox $item]
171
        set itemW [expr [lindex $box 2]-[lindex $box 0]+1]
172
        set itemH [expr [lindex $box 3]-[lindex $box 1]+1]
173
        if {$maxW < $itemW} {
174
            set maxW $itemW
175
        }
176
        if {$maxH < $itemH} {
177
            set maxH $itemH
178
        }
179
    }
180
    if {$maxW == 0 || $maxH == 0} {
181
        return
182
    }
183
 
184
    set winW [tixWinWidth $data(w:canvas)]
185
    set bd [expr [$data(w:canvas) cget -bd]+\
186
        [$data(w:canvas) cget -highlightthickness]]
187
    set cols [expr $winW / ($maxW+$padX)]
188
    if {$cols < 1} {
189
        set cols 1
190
    }
191
    set y $bd
192
 
193
    set c 0
194
    set x $bd
195
    foreach item [$data(w:canvas) find all] {
196
        set box [$data(w:canvas) bbox $item]
197
        set itemW [expr [lindex $box 2]-[lindex $box 0]+1]
198
        set itemH [expr [lindex $box 3]-[lindex $box 1]+1]
199
 
200
        set iX [expr $x + $padX + ($maxW-$itemW)/2]
201
        set iY [expr $y + $padY + ($maxH-$itemH)  ]
202
 
203
        $data(w:canvas) coords $item $iX $iY
204
        incr c
205
        incr x [expr $maxW + $padY]
206
        if {$c == $cols} {
207
            set c 0
208
            incr y [expr $maxH + $padY]
209
            set x $bd
210
        }
211
    }
212
}
213
 
214
# the items are packed
215
#
216
proc tixIconView:ArrangePack {w padX padY} {
217
    upvar #0 $w data
218
 
219
    set winW [tixWinWidth $data(w:canvas)]
220
    set bd [expr [$data(w:canvas) cget -bd]+\
221
        [$data(w:canvas) cget -highlightthickness]]
222
    set y [expr $bd + $padY]
223
 
224
    set maxH 0
225
    set usedW $padX
226
    set row ""
227
    foreach item [$data(w:canvas) find all] {
228
        set box [$data(w:canvas) bbox $item]
229
        set itemW [expr [lindex $box 2]-[lindex $box 0]+1]
230
        set itemH [expr [lindex $box 3]-[lindex $box 1]+1]
231
 
232
        if {[expr $usedW + $itemW] > $winW} {
233
            if {$row == ""} {
234
                # only one item in this row
235
                #
236
                $data(w:canvas) coords $item [expr $bd + $padX] $y
237
                incr y [expr $itemH+$padY]
238
                continue
239
            } else {
240
                # this item is not in this row. Arrange the previous items
241
                # first
242
                #
243
                tixIconView:PackOneRow $w $row $y $maxH $bd $padX $padY
244
 
245
                incr y $maxH
246
                set row ""
247
                set maxH 0
248
                set usedW $padX
249
            }
250
        }
251
        lappend row $item
252
        if {$maxH < $itemH} {
253
            set maxH $itemH
254
        }
255
        incr usedW [expr $padX+$itemW]
256
    }
257
    if {$row != ""} {
258
        tixIconView:PackOneRow $w $row $y $maxH $bd $padX $padY
259
    }
260
}
261
 
262
#----------------------------------------------------------------------
263
#
264
#               Widget commands
265
#----------------------------------------------------------------------
266
 
267
#----------------------------------------------------------------------
268
#
269
#               Private Methods
270
#----------------------------------------------------------------------
271
 

powered by: WebSVN 2.1.0

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