#!/afs/ece/usr/tcl/bin/wish -f

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

# Help text.
set Help "" ; append Help {Resizeth -- Resize widgets interactively.

This program is useful for interactively resizing widgets using either keyboard
commands or menus. It resizes widgets by modifying their configuration options.
Of course, you can modify their configuration options with Configureth, but this
program provides a uniform means of expanding or shirnking widgets' horizontal
or vertical dimensions.

This program teaches remote widgets to shrink or expand themselves horizontally
or vertically by a certain number of units. Some widgets use pixels as the
units, and some use characters, and some can use either, depending on their
configuration. You can adjust the units, either characters or pixels that
widgets should use to resize themselves. Some widgets cannot be adjusted in
either or both dimensions; resizeth knows how to resize each widget, and only
provides bindings for the options each widget permits.

} $TH_Bindings_Help {

Widgets of Resizeth

The Increment Scales

These four scales adjust the increment values for resizing commands. For
example, if you shrink an Entry widget horizontally, that widget gets shrunk by
a certain number of characters, which is shown on the 'Horizontal Characters'
scale. If you teach an Entry widget how to resize, it will learn the value of
the Horizontal Character scale for when it gets interactively resized. You can
specify the initial values of the scales as command-line parameters.

} $TH_Teach_Bind_Help {

Bugs / Limitations

Resizeth changes widget sizes by changing configuration options in each widget.
This may be one of: geometry, length, width, height. As long as the widget's
actual size is not determined by the size specified by its configuration option,
it will not be visibly changed. For example, a widget that is expanded to fill
the entire horizontal width of a window will not appear to be affected by
horizontal resizing commands, until the -width configuration option becomes
greater than its actual size, in which case the window will expand to accomodate
the larger widget.

Using your window manager to interactively resize the toplevel window may
eliminate resizeth's effect on that window's widgets.

Many widgets have odd behavior when given a horizontal or vertical size of 0.
For example, labels, messages, and every type of button when given a width or
height of 0 allocate just enough width or height to store the text or bitmap
they may contain. So if you expand a label that looks the 'right' size, it may
actually shrink the first time, and if you then shrink that label, it will pop
back to it's regular size.

Also, text and listbox widgets will generate an error if they are sized down to
0. Resizeth makes no attempt to catch this error.

Although frame and toplevel widgets have '-geometry' options to them, resizeth
cannot change their shape; use your window manager's interactive resizing
facility to change their size. 
}

# Gives app all the code necessary to do our functions.
proc teach_code {app widget} {
  include_files $app {resize.tcl th_resize_widget}
}

# For a widget, returns the appropriate bindings. (They will depend on the
# class of the widget, and maybe some configuration options.)
proc widget_bindings {app w} {
  global Bindings Inc

  set bindings "" ; set opt_x "" ; set opt_y "" ; set unit Pixels

  switch [send $app winfo class $w] {
    "Message" {set opt_x "-width"}
    "Canvas" {set opt_x "-width" ; set opt_y "-height"}
    "Entry" {set opt_x "-width" ; set unit Chars}
    "Label" - "Button" - "Checkbutton" - "Radiobutton" - "Menubutton" {
      set opt_x "-width" ; set opt_y "-height"
      if {[lindex [send $app $w configure -bitmap] 4] == ""} {
        set unit Chars}}
    "Listbox" {set opt_x "-gx" ; set opt_y "-gy"
        set unit Chars}
    "Text" {set opt_x "-width" ; set opt_y "-height"
        set unit Chars}
    "Scale" {if {[lindex [send $app $w configure -orient] 4] == "vertical"} {
         set opt_x "-width" ; set opt_y "-length"
       } else {set opt_x "-length" ; set opt_y "-width"}}
    "Scrollbar" {if {[lindex [send $app $w configure -orient] 4] == "vertical"} {
      set opt_x "-width"} else {set opt_y "-width"}}
   }   

   if {$opt_x != ""} {set bindings [regexp_replace [regexp_replace \
       $Bindings(Resize,X) %O $opt_x] %I $Inc(Horizontal,$unit)]}
   if {$opt_y != ""} {append bindings [regexp_replace [regexp_replace \
       $Bindings(Resize,Y) %O $opt_y] %I $Inc(Vertical,$unit)]}
   return $bindings
}


label .l -text "Increment Values" ; pack .l -fill x -side top
foreach frame {.inch .incv} {
  frame $frame ; pack $frame -side left -fill x -expand yes
  if {$frame == ".inch"} {set type "Horizontal"} else {set type "Vertical"}
  label $frame.l -text $type ; pack $frame.l -side top -fill x
  create_form_scale $frame.sc "Characters" Inc($type,Chars) 1 -from 1 -to 25
  create_form_scale $frame.sp "Pixels" Inc($type,Pixels) 20 -from 1 -to 250
}


