# This software is distributed under the Lesser General Public License
#
# inspector/font_ctl.tcl
#
# Control for editing font attributes
#
#------------------------------------------ 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/inspector/font_ctl.tcl,v $
# $Author: forster $
# $Revision: 1.7 $
# $Date: 1999/03/01 16:58:31 $
# $Locker:  $
# $State: Exp $
#
#------------------------------------------ CVS
#
# (C) University of Passau 1995-1999, Graphlet Project
#     Author: Michael Forster

package require Graphlet
package provide Graphscript [gt_version]

package require Flatbutton
package require Combobox
package require Numentry
package require Colorbutton

namespace eval ::GT::IS::font_ctl {

    namespace export create
    namespace import ::GT::IS::define_attrs
    namespace import ::GT::IS::bind_attrs

    proc create { IS ctl attrs } {
	define_attrs $IS $ctl $attrs { family size color font_style }

	frame $ctl

	create_widgets $IS $ctl $attrs
	create_layout  $IS $ctl
	
	return $ctl
    }

    proc create_widgets { IS ctl attrs } {

	Combobox::create $ctl.family \
	    -textvariable ::GT::IS::_Value($IS,[lindex $attrs 0]) \
	    -values [lsort [font families]]
	
	Numentry::create $ctl.size \
	    -textvariable ::GT::IS::_Value($IS,[lindex $attrs 1])
	
	foreach style { bold italic underline overstrike } {
	    
	    Flatbutton::create $ctl.$style \
		-image [GT::get_image inspector/font_style/$style] \
		-command [namespace code "ev_style_changed $IS $ctl $style"]

	    GT::tooltips $ctl.$style "Style: $style"
	}

	Colorbutton::create $ctl.color \
	    -variable ::GT::IS::_Value($IS,[lindex $attrs 2])
    }

    proc create_layout { IS ctl } {

	pack propagate $ctl.family 0

	grid columnconfigure $ctl { 0 1 2 3 } -weight 1
	
	grid $ctl.family -           -              -               $ctl.size  
	grid $ctl.bold   $ctl.italic $ctl.underline $ctl.overstrike $ctl.color 

	grid $ctl.family $ctl.size $ctl.color -sticky news

	global tcl_platform
	if { $tcl_platform(platform) == "windows" } {
	    eval grid [grid slaves $ctl] -padx 1 -pady 1
	}
    }

    proc update { IS ctl } {
	variable ::GT::IS::_HaveNodes
	variable ::GT::IS::_HaveEdges
	bind_attrs $IS $ctl

	foreach style { bold italic underline overstrike } {

	    $ctl.$style deselect

	    if { $_HaveNodes($IS) || $_HaveEdges($IS) } {

		$ctl.$style configure -state normal

		if [GT::lcontains $font_style "$style"] {
		    $ctl.$style select
		}
		
	    } else {
		
		$ctl.$style configure -state disabled
	    }
	}

	if { $_HaveNodes($IS) || $_HaveEdges($IS) } {

	    $ctl.family configure -state normal
	    $ctl.size configure -state normal
	    $ctl.color configure -state normal

	} else {

	    set family ""
	    set size ""
	    set color ""
	    
 	    $ctl.family configure -state disabled
 	    $ctl.size configure -state disabled
 	    $ctl.color configure -state disabled
	}
	
    }

    proc ev_style_changed { IS ctl value } {
	bind_attrs $IS $ctl

	foreach style { bold italic underline overstrike } {
	    set $style [$ctl.$style selected]
	}
	set $value [expr ![set $value]]
	
	set styles {}
	foreach style { bold italic underline overstrike  } {
	    if { [set $style] } {
		lappend styles $style
	    }
	}
	
	if { $styles == {} } {
	    set font_style {roman}
	} else {
	    set font_style $styles
	}

	update $IS $ctl
    }
}

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