#!/bin/sh
# the next line restarts using wish \
exec wish4.0 "$0" "$@"

if { [info exists env(OBTCL_LIBRARY)] } {
	set OBTCL_LIBRARY $env(OBTCL_LIBRARY)
}
if { ![info exists OBTCL_LIBRARY] || "$OBTCL_LIBRARY" == "" } {
	set OBTCL_LIBRARY "."
}

#----------------------------------------------------------------------
# Get obtcl and Mega-widgets
#----------------------------------------------------------------------

source ${OBTCL_LIBRARY}/obtcl
source ${OBTCL_LIBRARY}/ScrText.tcl
source ${OBTCL_LIBRARY}/PanedW.tcl
source ${OBTCL_LIBRARY}/Tabs.tcl
source ${OBTCL_LIBRARY}/TkManText.tcl

set bg [option get . background Button]
if { $bg == ""} {
	set bg lightgray
}
option add *highlightBackground $bg userDefault

#----------------------------------------------------------------------
# Wrap `destroy' to be able to trap destruction from the `widget' demo
#----------------------------------------------------------------------

# StopList is used in demo_destroy to stop
# deletion of certain windows

set StopList(obtclDemo) 1
set StopList() 1

proc demo_destroy { args } {
	global StopList
	foreach i $args {
		set base [lindex [split $i "."] 1]
		if ![info exists StopList($base)] {
			true_destroy $i
		}
	}
}

proc StopOn {} {
	if {[info commands true_destroy] == ""} {
		rename destroy true_destroy
		rename demo_destroy destroy
	}
}
proc StopOff {} {
	if {[info commands true_destroy] != ""} {
		rename destroy demo_destroy
		rename true_destroy destroy
	}
}

#----------------------------------------------------------------------
# Wrap `exit' so exiting the `widget' demo does not terminate this demo.
#----------------------------------------------------------------------

proc demo_exit { args } {
	StopOn
	eval destroy [winfo children .]
	StopOff
	wm withdraw .
}

if {[info procs exit] == ""} {
	rename exit true_exit
	rename demo_exit exit
}


# Use "." for `widget' demo

wm withdraw .

proc WidgetDemo {} {
	uplevel #0 {
	StopOn
	source $tk_library/demos/widget
	StopOff
	wm deiconify .
	}
}
proc StopWidgetDemo {} {
	uplevel #0 {
		wm deiconify .
		StopOn
		eval destroy [winfo children .]
		StopOff
		wm withdraw .
	}
}

#----------------------------------------------------------------------
# Create  widgets
#----------------------------------------------------------------------

set obW .obtclDemo

foreach i "$obW.lb $obW.txt $obW.pw $obW.tab $obW.right $obW" {
	catch {destroy $i}
}

toplevel .obtclDemo -width 600 -height 600
wm geometry .obtclDemo 600x600

StrictMotif

listbox $obW.lb -selectmode single

#PanedWindow $obW.pw -orientation x -width 300 -height 300 \
#	-fraction ".3"

frame $obW.pw

frame $obW.right -borderwidth 2 -relief sunken
Tab $obW.tab -tab_background grey75 -background lightgrey

pack $obW.tab -fill both -expand yes -in $obW.right

#$obW.pw manage $obW.lb $obW.right
pack $obW.right -expand 1 -fill both -in $obW.pw
pack configure $obW.right -padx 2
pack $obW.pw -fill both -expand yes


set List {
	{"Demo of Tabs"	"TD"}
	{"Foo"		"bar"}
}

foreach i $List {
	$obW.lb insert end [lindex $i 0]
}

update

source $OBTCL_LIBRARY/Layout.tcl

frame $obW.file -relief groove -borderwidth 2 -background grey80
button $obW.file.quit -text "Quit Demo" -command true_exit
pack $obW.file.quit -expand yes -anchor c

$obW.tab manage [list "File" $obW.file {-padx 10 -pady 10}]

source $OBTCL_LIBRARY/docs
source $OBTCL_LIBRARY/wrap
source $OBTCL_LIBRARY/tabs
source $OBTCL_LIBRARY/panedw

. configure -width 300 -height 600

return ""
