
# This code emulates the blt_table program for use with the grid command
# in tk4.1
#
# Copyright (c) 1993 ICEM Systems.
# Author:  Wayne A. Christopher, wayne@pmac.com
#          Pacific Marketing and Consulting, Berkeley, California

if {[info proc blt_graph] == ""} {
    if {[info commands blt::graph] != ""} {
	proc blt_graph {obj args} {
	    eval blt::graph $obj $args
	}
    } else {
	proc blt_graph {obj args} {
	    proc $obj {args} { return "__noblt_graph" }
	}
    }
}

if !$has_blt {
    
proc blt_table {args} {
    switch [lindex $args 0] {
	row {
	    set parent [lindex $args 1]
	    switch [lindex $args 2] {
		configure {
		    set num [lindex $args 3]
		    set params [lrange $args 4 end]
		    eval grid rowconfigure $parent $num \
			[blt_table_params $params]
		}
	    }
	}
	column {
	    set parent [lindex $args 1]
	    switch [lindex $args 2] {
		configure {
		    set num [lindex $args 3]
		    set params [lrange $args 4 end]
		    eval grid columnconfigure $parent $num \
			[blt_table_params $params]
		}
	    }
	}
	forget {
	    eval grid $args
	}
	configure {
	    set parent [lindex $args 1]
	    set r_or_c [string index [lindex $args 2] 0]
	    set num [string range [lindex $args 2] 1 end]
	    set params [lrange $args 3 end]
	    if {$r_or_c == "r"} {
		set conf rowconfigure
	    } else {
		set conf columnconfigure
	    }
	    eval grid $conf $parent $num [blt_table_params $params]
	}
	info {
	    set info [grid info [lindex $args 1]]
	    set binfo ""
	    for {set i 0} {[lindex $info $i] != ""} {incr i 2} {
		set param [lindex $info $i]
		set val [lindex $info [expr $i + 1]]
		switch -- $param {
		    -in {}
		    -column { set c $val }
		    -row    { set r $val }
		    -sticky { # not yet
		    }
		    default {
			lappend binfo $param $val
		    }
		}
	    }
	    return "[lindex $args 1] $r,$c $binfo"
	}
	default {
	    set parent [lindex $args 0]
	    set child [lindex $args 1]
	    set rc [split [lindex $args 2] ,]
	    set params [lrange $args 3 end]
	    eval grid $child -row [lindex $rc 0] -column [lindex $rc 1] \
		-in $parent [blt_table_params $params]
	}
    }
}

proc blt_table_params {params} {
    set np [llength $params]
    set nparams ""
    set fillval none
    set anchorval c
    set stick 0
    for {set i 0} {$i < $np} {incr i} {
	set pn [lindex $params $i]
	set pv [lindex $params [incr i]]
	switch -- $pn {
	    -fill   { set fillval $pv; set stick 1 }
	    -anchor { set anchorval $pv; set stick 1 }
	    -height - -width {
		if {[llength $pv] > 1} { set pv [lindex $pv 1] }
		switch $pv {
		    Inf     { }
		    0       { lappend nparams -minsize 0 -weight 0 }
		    default { lappend nparams -minsize $pv }
		}
	    }
	    -resize {
		switch $pv {
		    none   { lappend nparams -weight 0 }
		    expand { lappend nparams -weight 1 }
		    shrink { lappend nparams -weight 1 }
		    both   { lappend nparams -weight 1 }
		}
	    }
	    default { lappend nparams $pn $pv }
	}
    }
    if $stick {
	switch -glob "$fillval $anchorval" {
	    "both *" { set sticky nsew }
	    "x n*"   { set sticky new }
	    "x s*"   { set sticky sew }
	    "x *"    { set sticky ew }
	    "y e*"   { set sticky nse }
	    "y w*"   { set sticky nsw }
	    "y *"    { set sticky ns }
	    "none *" { set sticky $anchorval }
	    default  { puts "BOGUS: $fillval $anchorval" }
	}
	if {$sticky != "c"} {
	    lappend nparams -sticky $sticky
	}
    }
    return $nparams
}

proc blt_table_column {w args} {
    eval blt_table column $w $args
}

proc blt_table_row {w args} {
    eval blt_table row $w $args
}
proc blt_table_slaves {w} {
    return [blt_table slaves $w]
}

}
