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

set demoRoot [file dirname [info script]]
if [string compare "." $demoRoot] {
	lappend auto_path [file dirname $demoRoot]
} else {
	lappend auto_path [file dirname [pwd]]
}

#----------------------------------------------------------------------
# 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)] {
			catch {true_destroy $i}
		}
	}
}

proc StopOn {} {
	if ![string compare "" [info commands true_destroy]] {
		rename destroy true_destroy
		rename demo_destroy destroy
	}
}
proc StopOff {} {
	if [string compare "" [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 ![string compare "" [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.txt $obW.pw $obW.tab $obW.right $obW" {
	if [winfo exists $i] {
		destroy $i
	}
}

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

StrictMotif

frame $obW.pw

frame $obW.right -borderwidth 2 -relief sunken
puts $errorInfo
Tab $obW.tab

pack $obW.tab -fill both -expand yes -in $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

update

source $demoRoot/../README

frame $obW.file -relief groove -borderwidth 2

label $obW.file.welcome -text "Welcome to the obTcl demo!" \
	-font {-*-new century schoolbook-bold-r-*-*-14-*-*-*-*-*-*-*}

ScrolledText $obW.file.readme -textrelief sunken -state disabled \
	-scrollbars {x y} -height 4 -background grey80
$obW.file.readme insert end [GetDOC README]
ButtonRow $obW.file.quit
$obW.file.quit addButton "Quit Demo" true_exit
$obW.file.quit setDefault 0

pack $obW.file.welcome -padx 5 -pady 7
pack $obW.file.readme -expand true -fill both -padx 5 -pady 0
pack $obW.file.quit -expand no -anchor c -fill none -padx 0 -pady 2

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

#----------------------------------------------------------------------

proc demoSource file {
	global obW in_demoSource
	if [info exists in_demoSource] {
		return 0
	}
	set in_demoSource 1
	.obtclDemo configure -cursor watch
	update
	uplevel #0 "source $file"
	.obtclDemo configure -cursor {}
	unset in_demoSource
	return 1
}

set b [$obW.tab createTab "Docs"]
$obW.tab setAction $b "if \[demoSource $demoRoot/docs\] { \
	$obW.tab manageAtButton $b $obW.docs {-padx 5 -pady 3}; \
	$obW.tab triggerAction $b }"

#set b [$obW.tab createTab "Wrap"]
#$obW.tab setAction $b "if \[demoSource $demoRoot/wrap\] { \
#	$obW.tab manageAtButton $b $obW.wrap {-padx 10 -pady 10}; \
#	$obW.tab triggerAction $b }"

set b [$obW.tab createTab "Tabs"]
$obW.tab setAction $b "if \[demoSource $demoRoot/tabs\] { \
	$obW.tab manageAtButton $b $obW.tabdemo {-padx 10 -pady 10}; \
	$obW.tab triggerAction $b }"

set b [$obW.tab createTab "Paned Window"]
$obW.tab setAction $b "if \[demoSource $demoRoot/panedw\] { \
	$obW.tab manageAtButton $b $obW.panedW {-padx 10 -pady 10}; \
	$obW.tab triggerAction $b }"

cmt {
set b [$obW.tab createTab "Tcl7.5 Tricks"]
$obW.tab setAction $b "demoSource $demoRoot/tricks.tcl; \
	frame $obW.tricks
    if {$tk_version >= 4.1 } {
	label $obW.tricks.l \
	  -text {This page contains Tcl7.5/Tcl4.1 demos
(today it affects the Docs functions as well; which it shouldn't)} \
		-font {-*-new century schoolbook-bold-r-*-*-12-*-*-*-*-*-*-*}
	pack $obW.tricks.l -side top
	button $obW.tricks.b1 -text {Start DOC browser} \
		-command DOC_browse_start
	pack $obW.tricks.b1 -expand 1 -fill none -side top
    } else {
	label $obW.tricks.no \
	  -text \"Sorry, this page only works with Tk 4.1 and later
 (you are using Tk $tk_version)\" \
		-justify center \
		-font {-*-new century schoolbook-bold-r-*-*-12-*-*-*-*-*-*-*}
	pack $obW.tricks.no -expand 1 -fill none -side top
    }
	$obW.tab manageAtButton $b $obW.tricks {-padx 10 -pady 10}; \
	$obW.tab triggerAction $b"
}

. configure -width 300 -height 600

return ""
