# $Header: /home/cvsroot/tcldb/wisql/Tlib/ezEselect,v 1.4 1998/02/16 04:40:58 de Exp $
# tcl procs saved on Tue Sep 05 09:32:46 PDT 1995

proc ezEselect {which op y} {

global base table 

upvar #0 colatts colatts
upvar #0 EZEcols cols
upvar #0 EZEshows shows
upvar #0 EZEcci cci
upvar #0 EZEforf forf
upvar #0 EZEnrec nr
upvar #0 EZEvform vf
upvar #0 EZEhform hf
upvar #0 EZEcurl cl
upvar #0 EZEcury cy


	set lastr [expr {$nr - 1}]
	
	if {$op == "mouse"} {

	$hf.data.pic.win.$which.d get  [$hf.data.pic.win.$which.d nearest $y]
	set cci [$hf.data.pic.win.$which.d curselection]

	} else {
		incr cci $op
		if {$cci > $lastr} {set cci 0}
		if {$cci < 0} {set cci $lastr}
	}		

	set first [lindex $cols 0]
	foreach c $cols {
		if {$shows($c) > 0} {
			set first $c
			break
		}
	}

	$hf.data.pic.win.$first.d select clear $cci
	$hf.data.pic.win.$first.d get $cci

#	dynamically get the listbox height.  all boxes are the same, so...
        set lbh [$hf.data.pic.win.$first.d cget -height]

#	IF we scrolled from the vform (not mode mouse) then
#	view the current record more or less in the middle
#
	set yv $cl

	if {$op != "mouse"} {

		set halfway [lindex [split [expr {$lbh /2}] .] 0]

		set yv [expr {$cci - $halfway}]
		if {$yv < 0} {set yv 0}
		set cl $yv

		foreach c $cols {

#	Fix up the H form:  make sure the selected record is visible,
#	if we set it from the vform with Prev/Next

		if {$shows($c)} {
        	$hf.data.pic.win.$c.d yview $yv
		}

		} 
	}
	
	$hf.data.msg configure -text "Records [expr {$yv + 1}] - [expr {$yv + $lbh}] of $nr selected record(s)"

#	get the value of this column from the selected record

	set rfont [getFont $hf mediumcou]
	set ofont [getFont $hf mediumcoui]

	foreach c $cols {

	if {$shows($c)} {

	set colvalue [$hf.data.pic.win.$c.d get $cci]

	$hf.data.pic.win.$c.e configure -state normal

	if {$c == $which} {
	$hf.data.pic.win.$c.e configure  -font $ofont 
	} else {
	$hf.data.pic.win.$c.e configure  -font $rfont
	}
	$hf.data.pic.win.$c.e delete 0 end
	$hf.data.pic.win.$c.e insert 0 $colvalue

	if {[lsearch $forf $c] >= 0} {
	$hf.data.pic.win.$c.e configure -state disabled -background black  -foreground white
	}
	
#	Fix up the V form

#	first make sure there is a vform!
        set err [catch {$vf.data.can.fr.new.$c delete 0 end}]

	if {!$err} {
        $vf.data.can.fr.old.$c configure -state normal
        $vf.data.can.fr.old.$c delete 0 end
        $vf.data.can.fr.old.$c insert 0 "$colvalue"
        $vf.data.can.fr.old.$c configure -state disabled
	}

	}
	}

	if {!$err} {
        $vf.msg configure -text "Vertical Form Data Editor: table $table record [expr {$cci + 1}] of $nr selected record(s)" 
	}


}

