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 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 $w.l configure -text $text
143 set timeout $itk_option(-showtime)
144 if {$timeout != "" && $timeout != 0} {
145 set unshowid [after $timeout [code $this popdown]]
151 body tlc::Hoverbox::popdown {} { #<<<1
152 after cancel $afterid; set afterid ""
153 after cancel $unshowid; set unshowid ""
156 set lasthide [clock clicks -milliseconds]
162 body tlc::Hoverbox::overself {} { #<<<1
164 if {[info exists lasthide]} {
165 unset lasthide ;# prevent show / hide bounce
170 body tlc::Hoverbox::goto {x y} { #<<<1
171 blt::table arrange $w
173 incr x $itk_option(-xofs)
174 incr y $itk_option(-yofs)
176 set screen_w [winfo screenwidth $w]
177 set screen_h [winfo screenheight $w]
179 set wd [winfo reqwidth $w]
180 set ht [winfo reqheight $w]
182 if {$x + $wd > $screen_w} {
183 set newx [expr {$screen_w - $wd}]
188 if {$y + $ht > $screen_h} {
189 set newy [expr {$y - $itk_option(-yofs)*2 - $ht}]