1 # vim: foldmarker=<<<,>>>
3 option add *Hoverbox.background "#ffffe1" 45
4 option add *Hoverbox.font $tlc::config(smallfont) 45
5 option add *Hoverbox.borderWidth 1 45
6 option add *Hoverbox.relief solid 45
14 itk_option define -delay delay Delay 1500
15 itk_option define -showtime showTime ShowTime 10000
16 itk_option define -hottime hotTime HotTime 200
17 itk_option define -xofs xOfs XOfs 5
18 itk_option define -yofs yOfs YOfs 13
21 variable follow_mouse 1
23 method attach {widget text}
24 method detach {widget}
25 method popup {x y text}
37 method showtext {x y text}
46 body tlc::Hoverbox::constructor {args} { #<<<1
47 itk_component add display {
48 label $w.l -borderwidth 0 -relief flat -justify left
51 keep -background -textvariable -font
57 bind $w <Enter> [code $this overself]
58 wm overrideredirect $w 1
59 eval itk_initialize $args
63 body tlc::Hoverbox::destructor {} { #<<<1
64 after cancel $afterid; set afterid ""
65 after cancel $unshowid; set unshowid ""
69 body tlc::Hoverbox::attach {widget text} { #<<<1
70 bind $widget <Enter> [code $this showtext %X %Y $text]
71 bind $widget <Motion> [code $this motion %X %Y]
72 bind $widget <Leave> [code $this popdown]
74 foreach child [winfo children $widget] {
80 body tlc::Hoverbox::detach {widget} { #<<<1
81 bind $widget <Enter> {}
82 bind $widget <Motion> {}
83 bind $widget <Leave> {}
85 foreach child [winfo children $widget] {
91 body tlc::Hoverbox::showtext {x y text} { #<<<1
92 if {$afterid != ""} return
98 if {[info exists lasthide]} {
99 set interval [expr {[clock clicks -milliseconds] - $lasthide}]
100 if {$interval < $itk_option(-hottime)} {
108 set afterid [after $itk_option(-delay) [code $this popup $x $y $text]]
113 body tlc::Hoverbox::motion {x y} { #<<<1
127 body tlc::Hoverbox::reset {} { #<<<1
128 if {$afterid == ""} return
129 set handler [lindex [after info $afterid] 0]
130 after cancel $afterid; set afterid ""
131 set afterid [after $itk_option(-delay) $handler]
135 body tlc::Hoverbox::popup {x y text} { #<<<1
136 after cancel $afterid; set afterid ""
138 if {[info exists mouse_x]} {set x $mouse_x}
139 if {[info exists mouse_y]} {set y $mouse_y}
141 $w.l configure -text $text
144 set timeout $itk_option(-showtime)
145 if {$timeout != "" && $timeout != 0} {
146 set unshowid [after $timeout [code $this popdown]]
152 body tlc::Hoverbox::popdown {} { #<<<1
153 after cancel $afterid; set afterid ""
154 after cancel $unshowid; set unshowid ""
157 set lasthide [clock clicks -milliseconds]
163 body tlc::Hoverbox::overself {} { #<<<1
165 if {[info exists lasthide]} {
166 unset lasthide ;# prevent show / hide bounce
171 body tlc::Hoverbox::goto {x y} { #<<<1
172 blt::table arrange $w
174 incr x $itk_option(-xofs)
175 incr y $itk_option(-yofs)
177 set screen_w [winfo screenwidth $w]
178 set screen_h [winfo screenheight $w]
180 set wd [winfo reqwidth $w]
181 set ht [winfo reqheight $w]
183 if {$x + $wd > $screen_w} {
184 set newx [expr {$screen_w - $wd}]
189 if {$y + $ht > $screen_h} {
190 set newy [expr {$y - $itk_option(-yofs)*2 - $ht}]