# This software is distributed under the Lesser General Public License
#
# widgets/flatbutton.tcl
#
# Flat, autoraising buttons
#
#------------------------------------------ CVS
#
# CVS Headers -- The following headers are generated by the CVS
# version control system. Note that especially the attribute
# Author is not necessarily the author of the code.
#
# $Source: /home/br/CVS/graphlet/lib/graphscript/widgets/flatbutton.tcl,v $
# $Author: forster $
# $Revision: 1.2 $
# $Date: 1999/02/05 17:06:32 $
# $Locker:  $
# $State: Exp $
#
#------------------------------------------ CVS
#
# (C) University of Passau 1995-1999, Graphlet Project
#     Author: Michael Forster

package provide Flatbutton 1.0

namespace eval Flatbutton {

    namespace export create

    Widget::create_type Flatbutton \
	-options {
	} \
	-resources {
	    but.activeBackground	white
	    but.borderWidth		1
	    but.relief			flat
	} \
	-forward_options {
	    but {
		activebackground activeforeground anchor background bg bitmap
		borderwidth command height cursor disabledforeground ext
		font foreground highlightcolor highlightthickness
		ighlightbackground image justify padx pady relief state
		takefocus text textvariable underline width wraplength
	    }
	} \
	-forward_commands {
	    but {
		flash invoke
	    }
	} \
	-commands {
	    select Flatbutton::select
	    deselect Flatbutton::deselect
	    selected Flatbutton::selected
	}

    proc create { fb args } {
	variable _Selected
	variable _MouseOver
	
	# creation
	
	Widget::create Flatbutton $fb

	pack [button $fb.but] \
	    -fill both -expand true
	
	# initialization
	
	eval Widget::init Flatbutton $fb $args
	set _Selected($fb) 0
	set _MouseOver($fb) 0

	# events

	bind $fb.but <Enter> [namespace code "ev_Enter $fb"]
	bind $fb.but <Leave> [namespace code "ev_Leave $fb"]

	return $fb
    }

    proc ev_Enter { fb } {
	variable _MouseOver

	set _MouseOver($fb) 1
	show_state $fb
    }
    
    proc ev_Leave { fb } {
	variable _MouseOver

	set _MouseOver($fb) 0
	show_state $fb
    }

    proc select { fb } {
	variable _Selected

	set _Selected($fb) 1
	show_state $fb
    }
    
    proc deselect { fb } {
	variable _Selected

	set _Selected($fb) 0
	show_state $fb
    }

    proc selected { fb } {
	variable _Selected
	
	return $_Selected($fb)
    }

    proc show_state { fb } {
	variable _Selected
	variable _MouseOver

	if { $_Selected($fb) } {
	    $fb.but configure \
		-relief sunken \
		-background [$fb cget -activebackground]
	} else {
	    if { $_MouseOver($fb) && [$fb cget -state] == "normal" } {
		$fb.but configure \
		    -relief raised \
		    -background white
	    } else {
		$fb.but configure \
		    -relief flat \
		    -background [lindex [$fb.but configure -background] 3]
	    }
	}
    }

    #================================================== Event handling
}

#---------------------------------------------------------------------------
#   Set emacs variables
#---------------------------------------------------------------------------
# ;;; Local Variables: ***
# ;;; mode: tcl ***
# ;;; tcl-indent-level: 4 ***
# ;;; End: ***
#---------------------------------------------------------------------------
#   end of file
#---------------------------------------------------------------------------
