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
9 inherit tlc::Module tlc::Baselog
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 ttk::label $w.l -justify left
50 keep -textvariable -font
56 bind $w <Enter> [code $this overself]
57 wm overrideredirect [component hull] 1
58 itk_initialize {*}$args
62 body tlc::Hoverbox::destructor {} { #<<<1
63 after cancel $afterid; set afterid ""
64 after cancel $unshowid; set unshowid ""
68 body tlc::Hoverbox::attach {widget text} { #<<<1
69 bind $widget <Enter> [code $this showtext %X %Y $text]
70 bind $widget <Motion> [code $this motion %X %Y]
71 bind $widget <Leave> [code $this popdown]
73 foreach child [winfo children $widget] {
79 body tlc::Hoverbox::detach {widget} { #<<<1
80 bind $widget <Enter> {}
81 bind $widget <Motion> {}
82 bind $widget <Leave> {}
84 foreach child [winfo children $widget] {
90 body tlc::Hoverbox::showtext {x y text} { #<<<1
91 if {$afterid != ""} return
97 if {[info exists lasthide]} {
98 set interval [expr {[clock clicks -milliseconds] - $lasthide}]
99 if {$interval < $itk_option(-hottime)} {
107 set afterid [after $itk_option(-delay) [code $this popup $x $y $text]]
112 body tlc::Hoverbox::motion {x y} { #<<<1
126 body tlc::Hoverbox::reset {} { #<<<1
127 if {$afterid == ""} return
128 set handler [lindex [after info $afterid] 0]
129 after cancel $afterid; set afterid ""
130 set afterid [after $itk_option(-delay) $handler]
134 body tlc::Hoverbox::popup {x y text} { #<<<1
135 after cancel $afterid; set afterid ""
137 if {[info exists mouse_x]} {set x $mouse_x}
138 if {[info exists mouse_y]} {set y $mouse_y}
140 if {[string index $text 0] eq "@"} {
141 log debug "Interpreting text \"$text\" as an image to display"
142 $w.l configure -text "" -image [string range $text 1 end]
144 log debug "Interpreting text \"$text\" as text to display"
145 $w.l configure -text $text -image ""
149 set timeout $itk_option(-showtime)
150 if {$timeout != "" && $timeout != 0} {
151 set unshowid [after $timeout [code $this popdown]]
157 body tlc::Hoverbox::popdown {} { #<<<1
158 after cancel $afterid; set afterid ""
159 after cancel $unshowid; set unshowid ""
162 set lasthide [clock clicks -milliseconds]
168 body tlc::Hoverbox::overself {} { #<<<1
170 if {[info exists lasthide]} {
171 unset lasthide ;# prevent show / hide bounce
176 body tlc::Hoverbox::goto {x y} { #<<<1
177 blt::table arrange $w
179 incr x $itk_option(-xofs)
180 incr y $itk_option(-yofs)
182 set screen_w [winfo screenwidth $w]
183 set screen_h [winfo screenheight $w]
185 set wd [winfo reqwidth $w]
186 set ht [winfo reqheight $w]
188 if {$x + $wd > $screen_w} {
189 set newx [expr {$screen_w - $wd}]
194 if {$y + $ht > $screen_h} {
195 set newy [expr {$y - $itk_option(-yofs)*2 - $ht}]