8 proc set_balloon
{target
message} {
10 set tags
[bindtags $target]
11 set n
[lsearch $tags Balloon
]
14 bindtags $target [lreplace $tags $n $n]
18 bindtags $target "Balloon $tags"
21 set Balloon
($target) $message
24 proc end_balloon
{target
} {
25 set_balloon
$target ""
28 bind Balloon
<Enter
> {
31 set Balloon
(id
) [after 500 {Balloon
:show
%W
$Balloon(%W
) %X
%Y
}]
34 bind Balloon
<Button
> {
39 bind Balloon
<Leave
> {
44 bind Balloon
<Motion
> {
45 if {$Balloon(set) == 0} {
46 after cancel
$Balloon(id
)
47 set Balloon
(id
) [after 500 {Balloon
:show
%W
$Balloon(%W
) %X
%Y
}]
51 proc Balloon
:kill
{} {
53 after cancel
$Balloon(id
)
54 if {[winfo exists .balloon
] == 1} {
60 proc Balloon
:show
{target
message {cx
0} {cy
0}} {
62 if {$Balloon(first
) == 1 } {
64 if {$cx == 0 && $cy == 0} {
65 set x
[expr [winfo rootx
$target] + ([winfo width
$target]/2)]
66 set y
[expr [winfo rooty
$target] + [winfo height
$target] + 4]
71 toplevel .balloon
-bg black
72 wm overrideredirect .balloon
1
73 label .balloon.l
-text $message -relief flat
\
74 -bg #ffffcc -fg black -padx 2 -pady 0 -anchor w
75 pack .balloon.l
-side left
-padx 1 -pady 1
76 wm geometry .balloon
+$x+$y
81 proc entry_balloon
{target
} {
83 bind $target <Enter
> {
86 if {[string compare
[focus] %W
] &&
87 [expr [lindex $xv 1] - [lindex $xv 0] < 0.999]} {
88 set Balloon
(id
) [after 500 {Balloon
:entry %W
}]
91 bind $target <Leave
> {
92 catch {after cancel
$Balloon(id
)}
93 if {![winfo exists .balloon
]} {
97 bind $target <Button
> {
98 catch {after cancel
$Balloon(id
)}
102 proc Balloon
:entry {target
} {
104 if {$Balloon(first
) == 1} {
105 set x
[winfo rootx
$target]
106 set y
[winfo rooty
$target]
107 toplevel .balloon
-bg black
108 wm overrideredirect .balloon
1
109 label .balloon.l
-text [$target get
] -relief flat
-bg #ffffcc -fg black \
110 -padx 2 -pady 0 -anchor w
-font [$target cget
-font]
111 pack .balloon.l
-side left
-padx 1 -pady 1
114 set w
[winfo reqwidth .balloon
]
115 if {[expr $x + $w > [winfo screenwidth .balloon
]]} {
116 set x
[expr [winfo screenwidth .balloon
] - $w]
118 wm geometry .balloon
+$x+$y
120 wm deiconify .balloon
121 bind .balloon
<Leave
> {
125 bind .balloon
<Button
> {Balloon
:kill
}