1 # ui-srclist.tcl --
2 #
3 # manages the list of sources
4 #
5 # Copyright (c) 1993-2002 The Regents of the University of California.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
10 #
11 # A. Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
13 # B. Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16 # C. Neither the names of the copyright holders nor the names of its
17 # contributors may be used to endorse or promote products derived from this
18 # software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31
32 import Observable Callback
33
34 Class SrcList -superclass { Callback Observable }
35
36 SrcList instproc init { } {
37 $self instvar canv_ bottom_ mainW_ bg_ font_ \
38 trackwidth_ trackX_ nameX_ srcHdr_
39
40 set bottom_ 2
41 set mainW_ [toplevel .srclist]
42
43 wm withdraw $mainW_
44 wm geometry $mainW_ 230x140
45 bind $mainW_ <Enter> "focus $mainW_"
46 wm title $mainW_ "MB Members"
47
48 frame $mainW_.b -relief sunken -borderwidth 1
49 scrollbar $mainW_.b.scroll -command "$mainW_.b.list yview" -width 12
50 #
51 # Note that we make the canvas dimensions small so that
52 # if the user resizes the window, the dismiss button
53 # doesn't disappear. The default size is set by the
54 # wm geometry command above.
55 #
56 set canv_ [canvas $mainW_.b.list -relief groove -borderwidth 1 \
57 -height 10 -width 10 -confine 1 -relief raised \
58 -yscrollcommand "$mainW_.b.scroll set"]
59 set bg_ [$canv_ cget -bg]
60
61 $canv_ xview moveto 0
62 $canv_ yview moveto 0
63 bind $canv_ <Configure> "$self reconfig_canv %w %h"
64
65 set bottom [frame $mainW_.bottom -borderwidth 0]
66 button $bottom.dismiss -text "Dismiss" -command "$self dismiss" \
67 -underline 0
68
69 checkbutton $bottom.autoraise -text "Auto Raise" \
70 -command "$self toggle_auto_raise"
71 $self tkvar followAny_
72 checkbutton $bottom.followany -text "Follow Activity" \
73 -variable [$self tkvarname followAny_] \
74 -command "$self followAny"
75
76 pack $mainW_.b -fill both -expand 1
77 pack $mainW_.b.list -side left -expand 1 -fill both
78 pack $mainW_.b.scroll -side right -fill y -pady 2 -padx 0
79 pack $bottom.dismiss $bottom.autoraise $bottom.followany -side right \
80 -anchor se -padx 2 -pady 2
81 pack $bottom -side bottom -expand false -fill x
82 $self set auto_raise_ 0
83 $self set currTrack_ {}
84
85 # construct the header
86 set font_ [$self get_option medfont]
87 set trackX_ 0
88 set trackhdrbut [button $canv_.track -text "Follow" -pady 0 -anchor w]
89 set trackhdr [$canv_ create window $trackX_ 0 \
90 -anchor nw -window $trackhdrbut]
91 set bbox [$canv_ bbox $trackhdr]
92 set trackwidth_ [expr {[lindex $bbox 2] - [lindex $bbox 0]}]
93 set nameX_ [expr [lindex $bbox 2] + 8]
94 set srchdrbut [button $canv_.srchdr -text "Source Name" \
95 -anchor w -pady 0]
96 set srcHdr_ [$canv_ create window [lindex $bbox 2] 0 \
97 -window $srchdrbut -anchor nw]
98 set bottom_ [lindex [$canv_ bbox $srcHdr_ $trackhdr] 3]
99 incr bottom_ 4
100 return
101 set entryheight_ [expr {[lindex [$canv_ bbox $srcHdr_ $trackhdr] 3] \
102 - 2}]
103 set y [expr {$entryheight_ + 2}]
104 set separator [$canv_ create line $trackX_ $y 250 $y -width 1]
105 # -fill blue]
106 set bottom_ [lindex [$canv_ bbox $separator] 3]
107 incr bottom_ 2
108 }
109
110 SrcList instproc reconfig_canv {w h} {
111 $self instvar nameX_ srcHdr_ canv_
112 puts "w:$w h:$h"
113 puts "c: [winfo width $canv_] [$canv_ cget -width]"
114 set w [expr {[winfo width $canv_] - $nameX_ + 3}]
115 $canv_ itemconfig $srcHdr_ -width $w
116 }
117
118 SrcList instproc dismiss {} {
119 $self toggle_window 0
120 $self callback dismiss
121 }
122
123 SrcList instproc toggle_auto_raise {} {
124 $self instvar auto_raise_
125 if {$auto_raise_} {
126 set auto_raise_ 0
127 } else {
128 set auto_raise_ 1
129 }
130 }
131
132 SrcList instproc toggle_window {onoff} {
133 $self instvar mainW_
134
135 if {$onoff==0} {
136 wm withdraw $mainW_
137 } else {
138 wm deiconify $mainW_
139 }
140 }
141
142 #
143 # Register a src in the src display. This happens for all the
144 # srcs participating in the conferencing (e.g., including
145 # those not actually sending data).
146 #
147 SrcList instproc register {src} {
148 $self notify_observers register $src
149 $self instvar srcstate_ canv_ bottom_ nametag_ map_ unhilitId_ \
150 tracktag_ trackButton_ bg_ font_ nameX_ entryheight_
151
152 # already registered
153 DbgOut [array names nametag_]
154 if [info exists nametag_($src)] {
155 return
156 }
157
158 set srcstate_($src) 1
159
160 set varname [$self tkvar trackSrc_]
161 # set trackButton_($src) [radiobutton $canv_.$src -text track \
162 # -variable $varname -indicatoron 0 -value $src \
163 # -command "$self track $src"]
164
165 set nametag_($src) [$canv_ create text $nameX_ $bottom_ \
166 -font $font_ -text "[$src cname]" -anchor nw]
167 if ![info exists entryheight_] {
168 set bbox [$canv_ bbox $nametag_($src)]
169 set entryheight_ [expr {[lindex $bbox 3] - [lindex $bbox 1]}]
170 }
171 $self instvar trackwidth_ trackX_
172 set rectsize [expr {int(0.6*$entryheight_)}]
173 set xoffset [expr {($trackwidth_ - $rectsize)/2}]
174 set yoffset [expr {($entryheight_ - $rectsize)/2}]
175 set tracktag_($src) [$canv_ create rect \
176 [expr {$trackX_+$xoffset}] [expr {$bottom_+$yoffset}] \
177 [expr {$trackX_+$xoffset+$rectsize}] \
178 [expr {$bottom_+$yoffset+$rectsize}] \
179 -fill $bg_]
180 $canv_ bind $tracktag_($src) <Button-1> "$self toggle_track $src"
181 set left [lindex [$canv_ bbox $tracktag_($src)] 2]
182
183 set bottom_ [lindex [$canv_ bbox $nametag_($src) $tracktag_($src)] 3]
184 incr bottom_ 2
185 $canv_ config -scrollregion "0 0 2.5i $bottom_"
186 set unhilitId_($src) {}
187 }
188
189 SrcList instproc adjustNames { thresh h } {
190 $self instvar nametag_ srclist bottom_
191 foreach s [array names nametag_] {
192 set y [lindex [$canv_ coords $nametag_($s)] 1]
193 if { $y > $thresh } {
194 $canv_ move $nametag_($s) 0 -$h
195 }
196 }
197 incr bottom_ -$h
198 $canv_ config -scrollregion "0 0 2.5i $bottom_"
199 }
200
201 #
202 # Remove a src from the src display. This happens when
203 # a party quits or has been dead for a sufficiently long time.
204 # We assume the src has already been deactivated.
205 #
206 SrcList instproc unregister {src} {
207 $self notify_observers unregister $src
208 $self instvar name_line_ info_line_ nametag_ canv_
209
210 destroy_rtp_stats $src
211 #
212 # Delete name_line_ and info_line_ if they exist.
213 # They might not be created until the first NAME
214 # report (and they aren't used until a source is activated).
215 #
216 if [info exists name_line_($src)] {
217 unset name_line_($src)
218 unset info_line_($src)
219 }
220 set thresh [lindex [$canv_ coords $nametag_($src)] 1]
221 set bb [$canv_ bbox $nametag_($src)]
222 set height [expr [lindex $bb 3] - [lindex $bb 1]]
223 incr height 2
224 if [info exists canv_] {
225 $canv_ delete $nametag_($src)
226 unset nametag_($src)
227 $self adjustNames $thresh $height
228 }
229 }
230
231 # SrcList instproc grayout src {
232 # global nametag_ canv_ srcstate_
233 # if [info exists canv_] {
234 # $canv_ itemconfigure $nametag_($src) -stipple gray50
235 # }
236 # set srcstate_($src) 2
237 # }
238
239 # SrcList instproc embolden src {
240 # global nametag_ canv_
241 # if [info exists canv_] {
242 # $canv_ itemconfigure $nametag_($src) -stipple {}
243 # }
244 # set srcstate_($src) 1
245 # }
246
247 #
248 # hilit the source
249 # - sets a timeout to unhilit the receiver and execute $command then
250 #
251 SrcList instproc hilit {src} {
252 $self notify_observers hilit $src
253 $self instvar map_ canv_ nametag_ unhilitId_ mainW_
254
255 if ![winfo ismapped $mainW_] {
256 return
257 }
258 set tag $nametag_($src)
259
260 $canv_ itemconfigure $tag -fill blue
261 if [$self set auto_raise_] {
262 raise $mainW_
263 }
264 if {$unhilitId_($src)!={}} {
265 after cancel $unhilitId_($src)
266 }
267 set unhilitId_($src) [after 200 $self unhilit $src $tag]
268 }
269
270 # change the name of a source
271 SrcList instproc update_src_info {src cname} {
272 $self notify_observers update_src_info $src $cname
273
274 $self instvar nametag_ canv_
275 $canv_ itemconfigure $nametag_($src) -text "$cname"
276
277 }
278
279 #
280 # unhighlight the source and execute command
281 #
282 SrcList instproc unhilit {src tag} {
283 $self instvar canv_
284 $canv_ itemconfigure $tag -fill black
285 set unhilitId_($src) {}
286 }
287
288 SrcList instproc toggle_track {src} {
289 $self instvar canv_ tracktag_ currTrack_ bg_
290 $self notify_observers toggle_track $src
291 if {$currTrack_!={}} {
292 if {$currTrack_ == $src} {
293 # uncheck and return without checking the new entry
294 $canv_ itemconfig $tracktag_($src) -fill $bg_
295 set currTrack_ {}
296 $self callback track $src 0
297 return
298 } else {
299 $canv_ itemconfig $tracktag_($currTrack_) -fill $bg_
300 }
301 }
302 # checking different entry
303 $canv_ itemconfig $tracktag_($src) -fill blue
304 set currTrack_ $src
305 $self callback track $src 1
306 $self tkvar followAny_
307 if {$followAny_ == 1} {
308 set followAny_ 0
309 $self callback followAny_ 0
310 }
311 }
312
313 SrcList instproc set_followAny {on} {
314 $self tkvar followAny_
315 set followAny_ $on
316 }
317
318 SrcList instproc followAny {} {
319 $self tkvar followAny_
320 $self instvar currTrack_
321 if {$currTrack_!={}} {
322 $self toggle_track $currTrack_
323 }
324 $self callback followAny $followAny_
325 }
326
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.