# A Labeled Frame widget for Tcl/Tk
# $Revision: 1.1 $
#
# Copyright (C) 1998 D. Richard Hipp
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
# 
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA  02111-1307, USA.
#
# Author contact information:
#   drh@acm.org
#   http://www.hwaci.com/drh/

#
# Usage Example:
#
#     set f [LabelFrame:create .name -text "Frame Label"]
#     pack .name
#     button $f.content -text "Content of the Frame"
#     pack $f.content
#
# The first argument is the name of the label frame.  The
# return value is the name of a subframe within the frame
# into which the contents of the frame should be packed.
# Arguments after the first are options.
#
proc LabelFrame:create {w args} {
  frame $w -bd 0
  label $w.l
  frame $w.f -bd 2 -relief groove
  frame $w.f.f
  pack $w.f.f
  set text {}
  set font {}
  set padx 3
  set pady 7
  set ipadx 2
  set ipady 9
  foreach {tag value} $args {
    switch -- $tag {
      -font  {set font $value}
      -text  {set text $value}
      -padx  {set padx $value}
      -pady  {set pady $value}
      -ipadx {set ipadx $value}
      -ipady {set ipady $value}
      -bd     {$w.f config -bd $value}
      -relief {$w.f config -relief $value}
    }
  }
  if {"$font"!=""} {
    $w.l config -font $font
  }
  $w.l config -text $text
  pack $w.f -padx $padx -pady $pady -fill both -expand 1
  place $w.l -x [expr $padx+10] -y $pady -anchor w
  pack $w.f.f -padx $ipadx -pady $ipady -fill both -expand 1
  raise $w.l
  return $w.f.f
}

#################################
# The following code implements an example of using the
# labeled frame widget.
#
set f1 [LabelFrame:create .f1 -text "Frame One"]
label $f1.l1 -text "The interior\nof Frame One" -bg skyblue
pack $f1.l1 -fill both -expand 1
pack .f1 -side right -fill both -expand 1 -padx 5 -pady 5

set f2 [LabelFrame:create .f2 -text "Frame Two" -font fixed]
label $f2.l -text "This frame has a\nfixed pitch font\non its label"
pack $f2.l -fill both -expand 1
pack .f2 -side bottom -fill both -expand 1 -padx 5 -pady 5

set f3 [LabelFrame:create .f3 -text "Buttons" -relief ridge]
button $f3.b -text OK -command exit
button $f3.c -text Cancel -command exit
pack $f3.b $f3.c -side left
pack .f3 -side top -fill both -expand 1 -padx 5 -pady 5

