#!/afs/ece/usr/tcl/bin/wish -f
# The next line is executed by most shells, but not Tcl \
wish $0 $*


set Bind_Keyword [file tail [info script]]
source "[file dirname [info script]]/../aux/teach_bind.tcl"


# Help text.
set Help "" ; append Help {Scrolleth -- Add/remove scrollbars to widgets

This program is useful for interactively adding and removing scrollbars to
scrollable widgets using either keyboard commands or menus.

} $TH_Bindings_Help {

Widgets of Scrolleth

The Packing Radiobuttons

These buttons indicate on what sides of the remote widget the horizontal
and vertical scrollbars should be placed.

} $TH_Teach_Bind_Help {

Scrolleth will not add or delete a scrollbar to a widget with a grid (produced
by gridth) in the same direction...to add the scrollbar, first delete the grid.
If you like, you can then add the grid after the scrollbar.

For listboxes, entries, and texts not managed by the packer (i.e. they're
managed by the placer, or a text or canvas widget), the packing side is
ignored. The scrollbars get created in their own toplevel windows, and the user
can then decide where they should go.}


# Gives app all the code necessary to do our functions.
proc teach_code {} {
  include_files {scrollbar.tcl th_toggle_scrollbar}
  global App Widget Class
  if {[lsearch "Text Entry Listbox Canvas" $Class] < 0} {return}
  if {[send $App $Widget cget -xscrollcommand] != ""} {
    do_cmd_set TH(Scrollbar,X,$Widget) 1}

  if {$Class != "Entry"} {
    if {[send $App $Widget cget -yscrollcommand] != ""} {
      do_cmd_set TH(Scrollbar,Y,$Widget) 1
}}}

# For a widget, returns the appropriate bindings. (They will depend on the
# class of the widget, and maybe some configuration options.)
proc widget_bindings {} {
  global Bindings Inc Class Widget Scrollbar App
  if {[lsearch "Text Entry Listbox Canvas" $Class] < 0} {return ""}
  return [regexp_replace [regexp_replace $Bindings(Scrollbar) \
	%SX $Scrollbar(X)] %SY $Scrollbar(Y)]
}

label .sp -text "Packing Sides for Scrollbars" ; pack .sp -side top -fill x -expand no
radiobutton .sctop -text "Top" -variable Scrollbar(X) -value top
radiobutton .scbottom -text "Bottom" -variable Scrollbar(X) -value bottom
radiobutton .scleft -text "Left" -variable Scrollbar(Y) -value left
radiobutton .scright -text "Right" -variable Scrollbar(Y) -value right
foreach widget {.sctop .scbottom .scleft .scright} {pack $widget -side left -expand yes -fill x}
update_arguments Scrollbar(X) bottom
update_arguments Scrollbar(Y) left
