
# This code is shared by all the ICEM CFD GUI's.
#
# Copyright (c) 1993 - 1995 Pacific Marketing and Consulting, Inc,
#       and ICEM Systems, GmbH.  All rights reserved.
# Author:  Wayne A. Christopher, wayne@icemcfd.com

proc scroller {frame top canvas middle bottom {height ""} {incr 1}} {
    set wheight [winfo reqheight $middle]
    set wwidth [winfo reqwidth $middle]

    if {$height == ""} {set height 700}
    if {$wheight < $height} {
	# Easy.
	pack append $frame \
		$top {top fill} \
		$canvas {top fill expand} \
		$bottom {bottom fill}
	set id [$canvas create window 0 0 -window $middle -anchor nw]
	$canvas configure -width $wwidth -height $wheight
	bind $canvas <Configure> "$middle configure -width \[winfo width %W\] \
		-height \[winfo height %W\]"
	update idletasks
	top_deiconify $frame
	return
    }
    
    scrollbar $frame._s -command "$canvas yview" -relief raised \
	    -borderwidth 2 -orient v
   
    pack append $frame \
	$top {top fill} \
	$bottom {bottom fill} \
	$frame._s {right fill} \
	$canvas {left fill expand}
    
    $canvas create window 0 0 -window $middle -anchor nw
    $canvas configure -width $wwidth -height $height \
	-scrollregion "0 0 $wwidth $wheight" -yscrollcommand "$frame._s set"
    
    bind $canvas <Configure> "$middle configure -width \[winfo width %W\] \
	    -height \[winfo height %W\]"
}

proc scroller_simple {frame} {
    frame $frame
    canvas $frame.c -yscroll "$frame.s set"
    
    scrollbar $frame.s -command "$frame.c yview" -relief raised \
	    -borderwidth 2 -orient v
    
    frame $frame.c.w
    $frame.c create window 0 0 -window $frame.c.w -anchor nw
    
    pack $frame.c -side left -fill both -expand 1
    pack $frame.s -side right -fill y
    bind $frame.c.w <Configure> "scroller_simple_update $frame"
    return $frame.c.w
}

proc scroller_simple_update {frame} {
    set height [winfo reqheight $frame.c.w]
    set width [winfo reqwidth $frame.c.w]
    set rheight $height
    if {$height > 300} {set height 300}
    $frame.c configure -width $width -height $height \
	-scrollregion "0 0 $width $rheight"
    $frame.s set $rheight $height 0 $height
}
