#!/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 {Gridth -- Add row or column numbers to text.

This program teaches widgets that contain text to show their line or column
numbers. It provides two functions, one to turn on or off a horizontal 'grid'
of column numbers, and one to turn on or off a vertical 'grid' of row numbers.
It works on text, listbox and entry widgets.

} $TH_Bindings_Help {

Widgets of Gridth

The Packing Radiobuttons

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

} $TH_Teach_Bind_Help {

If the contents of a widget change in size, the grid will not change
accordingly; to fix this, remove and replace the grid.

These grids are very strict in how they can align to text. This means that
special characters (such as "\x0d") displayed in entry or text widgets will
screw up the alignment of horizontal grids. So will embedded windows and
different fonts. Vertical grids can be misaligned due to different spacing
between lines, or text lines that wrap in a text widget. The vertical grid
number will, however, always match the topmost index for a text widget.

The horizontal grid on a listbox may be off by 1 at times, due to inadequate
scrolling commands provided by listbox widgets.

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 horizontal and vertical grids 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 {} {
  global TH_Dir Class
  if {[file exists "$TH_Dir/lib/grid.[set Class].tcl"]} {
    include_files [list grid.$Class.tcl "th_[set Class]_toggle_grid_x"]
}}

# For a widget, returns the appropriate bindings. (They will depend on the
# widget, it must be able to support scrollbars.)
proc widget_bindings {} {
  global TH_Dir Bindings Side Widget Class App
  if {![file exists "$TH_Dir/lib/grid.[set Class].tcl"]} {return ""}

  set bindings [list [regexp_replace $Bindings(Grid,X) %XP $Side(X)]]
  if {$Class != "Entry"} {
    lappend bindings [regexp_replace $Bindings(Grid,Y) %YP $Side(Y)]
  }
  return $bindings
}


label .gp -text "Packing Sides for Grids" ; pack .gp -side top -fill x -expand no
radiobutton .top -text "Top" -variable Side(X) -value top
radiobutton .bottom -text "Bottom" -variable Side(X) -value bottom
radiobutton .left -text "Left" -variable Side(Y) -value left
radiobutton .right -text "Right" -variable Side(Y) -value right
foreach widget {.top .bottom .left .right} {pack $widget -side left -expand yes -fill x}
update_arguments Side(X) bottom
update_arguments Side(Y) left
