# $Id: TkCompositeWidgets.pm,v 1.5 1999/07/29 19:29:35 v2kea318 Exp $
# $Log: TkCompositeWidgets.pm,v $
# Revision 1.5  1999/07/29  19:29:35  v2kea318
# Set the active background for the scrollbar to equal the normal background.
#
# Revision 1.4  1999/06/04  22:17:44  v2kea318
# Moved the width and height parameters to the general routine.
#
# Revision 1.3  1999/06/04  19:45:30  v2kea318
# Wrote a generic scrolled widget builder, and implemented the scrolled text
# building with that.
#
# Revision 1.2  1999/06/04  19:37:13  v2kea318
# Fixed the documentation to look write when printed.
#
# Revision 1.1  1999/06/02  22:47:31  v2kea318
# Initial revision
#
#***************************************************************************

=head1 NAME

TkCompositeWidgets - a package to define composite widgets using Tk

=head1 ROUTINES

make_scrollbar($$$;$) Make a scrollbar.  The arguments are (1) the
parent widget, (2) the orientation, (3), the side, and (4) the 
background color

make_scrolled_text($$$;$$$$$) Make a scrolled text widget.  Arguments are
(1) parent widget, (2) vertical scroll bar requested, (3) horizontal 
scroll bar requested, (4) the background color, (5) the foreground
color, (6) the width, (7) the height, and (8) the wrap specification, 
defaulting to 'word'.

make_scrolled_widget($$$$;$$$$) Make a generic scrolled widget.  Arguments
are (1) parent widget, (2) the class of widget to be scrolled, I<e.g.>
Text, (3) vertical scroll bar requested, (4) horizontal scroll bar
requested, (5) background color, (6) foreground color, (7) the width,
and (8) the height

=cut

#***************************************************************************

# package name.
package TkCompositeWidgets;

# namespace management.
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(make_scrollbar make_scrolled_text make_scrolled_widget);

# library includes.
use Tk;

#***************************************************************************

sub make_scrollbar($$$;$) {
  my ($parent, $orient, $side, $bgcolor) = @_;
  my $scroll = $parent->Scrollbar(
				  -orient => $orient
				 );
  $scroll->configure(
		     -background       => $bgcolor,
		     -troughcolor      => $bgcolor,
		     -activebackground => $bgcolor
		    ) if (defined($bgcolor));
  $scroll->pack(
		-side => $side,
		-fill => 'y'
	       );
  return $scroll;
}

#***************************************************************************

sub make_scrolled_widget($$$$;$$$$) {
  my ($parent_w, $type, $do_vertical, $do_horiz, $bgcolor, $fgcolor,
      $width, $height) = @_;
  
  # make the entry widget.
  my $entry = $parent_w->$type();

  # Make the vertical scroll bar, if requested.
  my $vert_scroll = make_scrollbar($parent_w, 'vertical', 'right', $bgcolor)
    if ($do_vertical);
  my $horz_scroll = make_scrollbar($parent_w, 'horiz', 'bottom', $bgcolor)
    if ($do_horiz);
  
  # configure the entry widget.
  $entry->configure(		    
		    -background => $bgcolor
		   ) if (defined($bgcolor));
  $entry->configure(
		    -foreground => $fgcolor
		   ) if (defined($fgcolor));
  $entry->configure(
		    -yscrollcommand => [ $vert_scroll => 'set' ]
		   ) if ($do_vertical);
  $entry->configure(
		    -xscrollcommand => [ $horz_scroll => 'set' ]
		   ) if ($do_horiz);
  $entry->configure(
		    -width => $width
		   ) if (defined $width);
  $entry->configure(
		    -height => $height
		   ) if (defined $height);
  
  # configure the scroll bars, if necessary.
  $vert_scroll->configure(
			  -command => [ $entry => 'yview' ]
			 ) if ($do_vertical);
  $horz_scroll->configure(
			  -command => [ $entry => 'xview' ]
			 ) if ($do_horiz);

  # pack the entry.
  $entry->pack( -expand => 1, -fill => 'both' );

  # return the entry widget.
  return $entry;
}

#***************************************************************************

sub make_scrolled_text($$$;$$$$$) {
  my ($parent_w, $do_vertical, $do_horiz, $bgcolor, $fgcolor,
      $width, $height, $wrap) = @_;
  $wrap = 'word' unless (defined($wrap));
  my $text = make_scrolled_widget($parent_w, 'Text', $do_vertical,
				  $do_horiz, $bgcolor, $fgcolor, $width,
				  $height);
  $text->configure( -wrap => $wrap );
  return $text
}

#***************************************************************************

1;
