# $Header: /home/cvsroot/tcldb/wisql/Tlib/ezEscroll,v 1.2 1997/08/25 03:14:44 de Exp $
# tcl procs saved on Tue Sep 05 09:32:46 PDT 1995

proc ezEscroll {cc op x y} {



upvar #0 EZEcols cols
upvar #0 EZEcolatts colatts
upvar #0 EZEshows shows
upvar #0 EZEcurx cx
upvar #0 EZEcury cy
upvar #0 EZEcurl cl
upvar #0 EZEnrec nr
upvar #0 EZEvform vf
upvar #0 EZEhform hf

	if {$nr == 0} {return}

	case $op in {

	{up down Up Down} {

	#set geom [$hf.data.pic.win.$cc.d configure -geometry]
	#set li [lsearch $geom *x*]
	#set lbh [lindex [split [lindex $geom $li] x] 1]
        set lbh [$hf.data.pic.win.$cc.d cget -height]
	set pag [expr {$lbh - 1}]
	set blim [expr {$nr - $pag}]
	if {$blim < 0} {set blim 0}

	if {$op == "up"} {set ny  [expr {$cl - 1}]}
	if {$op == "down"} {set ny  [expr {$cl + 1}]}
	if {$op == "Up"} {set ny  [expr {$cl - $pag}]}
	if {$op == "Down"} {set ny  [expr {$cl + $pag}]}
	if {$ny < 0} {set ny 0}
	if {$ny > $blim} {set ny $blim}

	set i 0
	foreach c $cols {
	if {$shows($c)} {
        $hf.data.pic.win.$c.d yview $ny
	}
	incr i
	}
        set cl $ny

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

	{dragto} {

	set hori 0
	set vert 0

	if {$cx($cc) != $x} {
		set dh [expr {$cx($cc) - $x}]
		set hori 1
	}
	if {$cy != $y} {
		set dv [expr {$cy - $y}]
		set vert 1
	}

	if {$hori} {
		set nx $x
#		if {$dh > 0} {set nx  [expr {$cx($cc) + 1}]}
#		if {$dh < 0} {set nx  [expr {$cx($cc) - 1}]}
#		set nx [expr {$cx($cc) + $dh}]
#		if {$nx < 0} {set nx 0}
#		$hf.data.pic.win.$cc.d scan $op $nx $cy
		$hf.data.pic.win.$cc.d xview [expr {$nx / 3}]
		set cx($cc) [expr {$nx / 3}]
	}

#	This never worked right -- scroll was out of synch on screen
#	if {$vert} {
#		DONT DO IT!
#		foreach c $cols {
#			set ny $y
#			if {$dv > 0} {set ny  [expr {$cy + 1}]}
#			if {$dv < 0} {set ny  [expr {$cy - 1}]}
#			set ny [expr {$cy + $dv}]
#			if {$ny < 0} {set ny 0}
#			$hf.data.pic.win.$c.d scan $op $cx($c) $ny
#			$hf.data.pic.win.$c.d yview $ny
#			set cy $ny
#		}
#		$hf.data.pic.win.$cc.d scan $op $cx($cc) $ny
#	}
#

	}

	}
	
}

