##############################################################################
# $Id: balloon.tcl,v 1.0 2002/2/22 10:58:30 China Xiamen University $
#
# balloon.tcl - procedures used by balloon help
#
# Copyright (C) 2002 Shengrui,li  CSD of Xiamen University ,China
#
# 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.
#

##############################################################################
#

package provide imScilab_balloon 1.0
namespace eval ::vBalloon {
namespace export imScilab:set_balloon
namespace export imScilab:kill_balloon
global imScilab
}


proc ::vBalloon::imScilab:set_balloon {target message} {
    global imScilab
    set imScilab(balloon,$target) $message

bind imScilab(balloon) <Enter> {
    set imScilab(balloon,set) 0
    set imScilab(balloon,first) 1
    set imScilab(balloon,id) [after 50 {::vBalloon::imScilab:balloon %W $imScilab(balloon,%W)}]
}

bind imScilab(balloon) <Button> {
    set imScilab(balloon,first) 0
    ::vBalloon::imScilab:kill_balloon
}

bind imScilab(balloon) <Leave> {
    set imScilab(balloon,first) 0
    ::vBalloon::imScilab:kill_balloon
}

bind imScilab(balloon) <Motion> {
    if {$imScilab(balloon,set) == 0} {
        after cancel $imScilab(balloon,id)
        set imScilab(balloon,id) [after 50 {::vBalloon::imScilab:balloon %W $imScilab(balloon,%W)}]
    }
}

bindtags $target "[bindtags $target] imScilab(balloon)"
}

proc ::vBalloon::imScilab:kill_balloon {} {
    global imScilab
    after cancel $imScilab(balloon,id)
    if {[winfo exists .imScilabballoon] == 1} {
        destroy .imScilabballoon
    }
    set imScilab(balloon,set) 0
}

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