#
# $Log: not supported by cvs2svn $
# Revision 1.9  2005/06/07 14:35:09  shang
# made tab frame expandable
#
# Revision 1.8  2004/04/06 19:50:12  borland
# Added frameIndexVariable option to the APSTabFrame procedure, allowing caller
# to specify a variable to which the frame index is written when a tab is
# pressed.
#
# Revision 1.7  2003/09/04 19:34:41  soliday
# Removed Iwidgets version number.
#
# Revision 1.6  2003/07/07 15:15:57  shang
# added packOption argument
#
# Revision 1.5  2003/06/26 15:09:46  shang
# added -packOption for APSFrame widget so that the tab frame is expandable
#
# Revision 1.4  2000/10/17 21:48:16  borland
# Fixed APSTabFrameHelp so it formats better.
#
# Revision 1.3  2000/10/17 21:45:42  borland
# Added APSTabFrameHelp procedure.
#
# Revision 1.2  2000/10/17 21:41:32  borland
# Now honors the packOption argument.
#
# Revision 1.1  2000/10/16 21:35:45  borland
# First version.  Uses Iwidget package.
#
#

proc APSTabFrameHelp {} {
    return "Usage: APSTabFrame <widget>\n\
-parent <widget>\n\
-labelList <listOfStrings>\n\
-width <pixels>\n\
-height <pixels>\n\
\[-noPack 0|1\]\n\
\[-packOption <string>\]\n\
\[-label <string>\]\n\
\[-frameIndexVariable <name>\]\n\
\[-commandList <listOfStrings>\]\n\
\[-tabPosition n|s|e|w\]\n\
\[-font <fontName>\]\n"
}

proc APSTabFrame {widget args} {
    global apsContextHelp
    set parent ""
    set noPack 0
    set packOption "-side top -anchor nw -fill both -expand 1"
    set label ""
    set width 100 
    set height 100
    set labelList ""
    set commandList ""
    set frameIndexVariable ""
    set tabPosition nw
    set font -adobe-courier-medium-r-normal-*-12-*-*-*-*-*-*-*
    APSStrictParseArguments {parent noPack packOption label width height \
			       labelList commandList tabPosition font \
                               frameIndexVariable}

    if {[llength $commandList]!=0 && [llength $commandList]!=[llength $labelList]} {
        return -code error "APSWidgetSwapFrame: commandList must be same length as labelList (APSWidgetSwapFrame)"
    }
    APSFrame $widget -parent $parent -label $label -packOption $packOption
    set w $parent$widget.frame

    ttk::style configure TNotebook -tabposition $tabPosition
    ttk::notebook $w.tn -width $width -height $height
    eval pack $w.tn $packOption 
    
    set frameList ""
    set index 0

    foreach label $labelList command $commandList {
        if [string length $frameIndexVariable] {
            if [string length $command] {
                set command "global $frameIndexVariable; set $frameIndexVariable $index ; $command"
            } else {
                set command "global $frameIndexVariable; set $frameIndexVariable $index"
            }
        }
        $w.tn add [ttk::frame $w.tn.f$index] -text $label
        lappend frameList $w.tn.f$index
        bind $w.tn <<NotebookTabChanged>> "APSTabFrameChanged %W [list $commandList]"
        incr index
    }
    $w.tn select 0
    return $frameList
}

proc APSTabFrameChanged {widget commandList} {
    set command [lindex $commandList [$widget index [$widget select]]]
    if {[string length $command]} {
        eval $command
    }
}
