summaryrefslogtreecommitdiff
path: root/tcl/scripts/balloon.tcl
blob: 637d743f25515b4f3bd092a5dc99bc97a095b8b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#####################################################################
# balloon.tcl - procedures used by balloon help
#
# Copyright (C) 1996-1997 Stewart Allen
# 
# This is part of vtcl source code
# Adapted for general purpose by 
# Daniel Roche <daniel.roche@bigfoot.com>
# thanks to D. Richard Hipp for the multi-headed display fix
# version 1.2 ( Sep 21 2000 ) 
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

# Modification history:
#  5-Jul-2001  FMP added -justify left to the balloon help label;
#              enable_balloons

#####################################################################
# Sourced by tkemc
# Uses emchelp.tcl for specific widget help messages
#####################################################################

set do_balloons 0

proc enable_balloons {e} {
    global do_balloons
    set do_balloons $e
}

bind Bulle <Enter> {
    global do_balloons
    if {$do_balloons} {
	set Bulle(set) 0
	set Bulle(first) 1
	set Bulle(id) [after 500 {balloon %W $Bulle(%W) %X %Y}]
    }
}

bind Bulle <Button> {
    global do_balloons
    if {$do_balloons} {
	set Bulle(first) 0
	kill_balloon
    }
}

bind Bulle <Leave> {
    global do_balloons
    if {$do_balloons} {
	set Bulle(first) 0
	kill_balloon
    }
}

bind Bulle <Motion> {
    global do_balloons
    if {$do_balloons} {
	if {$Bulle(set) == 0} {
	    after cancel $Bulle(id)
	    set Bulle(id) [after 500 {balloon %W $Bulle(%W) %X %Y}]
	}
    }
}

proc set_balloon {target message} {
    global Bulle
    set Bulle($target) $message
    bindtags $target "[bindtags $target] Bulle"
}

proc kill_balloon {} {
    global Bulle
    after cancel $Bulle(id)
    if {[winfo exists .balloon] == 1} {
        destroy .balloon
    }
    set Bulle(set) 0
}

proc balloon {target message {cx 0} {cy 0} } {
    global Bulle
    if {$Bulle(first) == 1 } {
        set Bulle(first) 2
	if { $cx == 0 && $cy == 0 } {
	    set x [expr [winfo rootx $target] + ([winfo width $target]/2)]
	    set y [expr [winfo rooty $target] + [winfo height $target] + 4]
	} else {
	    set x [expr $cx + 4]
	    set y [expr $cy + 4]
	}
        toplevel .balloon -bg black -screen [winfo screen $target]
        wm overrideredirect .balloon 1
        label .balloon.l \
            -text $message -justify left -relief flat \
            -bg #ffffaa -fg black -padx 2 -pady 0 -anchor w
        pack .balloon.l -side left -padx 1 -pady 1
        wm geometry .balloon +${x}+${y}
        set Bulle(set) 1
    }
}