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

# widget --
# This script demonstrates the various widgets provided by Tk,
# along with many of the features of the Tk toolkit.  This file
# only contains code to generate the main window for the
# application, which invokes individual demonstrations.  The
# code for the actual demonstrations is contained in separate
# ".tcl" files is this directory, which are sourced by this script
# as needed.
#
# @(#) widget 1.9 95/06/21 17:32:37

eval destroy [winfo child .]
wm title . "Widget Demonstration"

# kanji_font
set msg_kanji_font -*--24-*-jisx0208.1983-0
# kanji_font
set kanji_font -*--16-*-jisx0208.1983-0

set tk_library ..

option add "*kanjiFont" $kanji_font startupFile

#----------------------------------------------------------------
# The code below create the main window, consisting of a menu bar
# and a text widget that explains how to use the program, plus lists
# all of the demos as hypertext items.
#----------------------------------------------------------------

set font -*-Helvetica-Medium-R-Normal--*-140-*-*-*-*-*-*
frame .menuBar
pack .menuBar -side top -fill x
menubutton .menuBar.file -text File -menu .menuBar.file.m -underline 0
menu .menuBar.file.m
.menuBar.file.m add command -label "Quit" -command "exit" -underline 0
pack .menuBar.file -side left

scrollbar .s -orient vertical -command {.t yview}
pack .s -side right -fill y
text .t -yscrollcommand {.s set} -wrap word -width 60 -height 30 -font $font \
	-setgrid 1
pack .t -expand y -fill both

# Create a bunch of tags to use in the text widget, such as those for
# section titles and demo descriptions.  Also define the bindings for
# tags.

global msg_kanji_font
.t tag configure title -font -*-Helvetica-Bold-R-Normal--*-180-*-*-*-*-*-*
.t tag configure middle -kanjifont $kanji_font
.t tag configure demo -lmargin1 1c -lmargin2 1c
if {[winfo depth .] == 1} {
    .t tag configure hot -background black -foreground white
} else {
    .t tag configure hot -relief raised -borderwidth 1 -background SeaGreen3
}
.t tag bind demo <Button-1> {
    invoke [.t index current]
}
set lastLine ""
.t tag bind demo <Enter> {
    set lastLine [.t index {@%x,%y linestart}]
    .t tag add hot $lastLine "$lastLine lineend"
}
.t tag bind demo <Leave> {
    .t tag remove hot 1.0 end
}
.t tag bind demo <Motion> {
    set newLine [.t index {@%x,%y linestart}]
    if {[string compare $newLine $lastLine] != 0} {
	.t tag remove hot 1.0 end
	set lastLine $newLine
	.t tag add hot $lastLine "$lastLine lineend"
    }
}

# Create the text for the text widget.

.t insert end {Tk Widget} title
.t insert end {  fXg[V
} middle
.t insert end {
̃AvP[V́ATk Widget pĂǂ̂悤ȂƂł邩\
߂́A̏ȃXNvgɑ΂tgGh\
Ă܂BȉɏԂɋĂfXg[Vs\
ɂ̓}EXŃNbNĂBfXg[ṼEB\
hEƁAfXg[V𐶐 Tcl/TK ̃R[h\
邽߂ɁA"R[hQ" {^NbN邱Ƃł܂BȂ\
]ނȂÃR[hC邱Ƃł܂BCR[hŃf\
Xg[VĎs邽߂ɂ́AR[hꂽEBhE\
"fĎs" {^NbNĂB

}
.t insert end "x, {^, `FbN{^, WI{^\n" middle
.t insert end "1. x (eLXgArbg}bv)\n" {demo demo-label}
.t insert end "2. {^ \n" {demo demo-button}
.t insert end "3. `FbN{^ (I\)\n" {demo demo-check}
.t insert end "4. WI{^ (Cӂ̈I\)\n" {demo demo-radio}
.t insert end "5. {^ōꂽ15-pYQ[\n" {demo demo-puzzle}
.t insert end "6. rbg}bvgpACR{^\n" {demo demo-icon}
.t insert end "7. 摜\̃x\n" {demo demo-image1}
.t insert end "8. 摜邽߂̊ȒPȃ[UC^tF[X\n" {demo demo-image2}

.t insert end \n {} "Xg{bNX\n" middle
.t insert end "1. s{.\n" {demo demo-states}
.t insert end "2. F: AvP[V̂߂̔zFς\n" \
	{demo demo-colors}
.t insert end "3. iW\n" {demo demo-sayings}

.t insert end \n {} "Gg\n" middle
.t insert end "1. XN[o[Ȃ\n" {demo demo-entry1}
.t insert end "2. XN[o[\n" {demo demo-entry2}
.t insert end "3. ȒPȃtH[\n" {demo demo-form}

.t insert end \n {} "eLXg\n" middle
.t insert end "1. {IȃeLXg\n" {demo demo-text}
.t insert end "2. \X^C.\n" {demo demo-style}
.t insert end "3. nCp[eLXg(^OoCh).\n" {demo demo-bind}
.t insert end "4. EBhE𖄂ߍ񂾃eLXg\n" {demo demo-twind}
.t insert end "5. \n" {demo demo-search}

.t insert end \n {} "LoX\n" middle
.t insert end "1. ACě^\n" {demo demo-items}
.t insert end "2. 2 ̃vbg\n" {demo demo-plot}
.t insert end "3. eLXg\n" {demo demo-ctext}
.t insert end "4. ̌`\n" {demo demo-arrow}
.t insert end "5. [[\n" {demo demo-ruler}
.t insert end "6. tAv\n" {demo demo-floor}
.t insert end "7. XN[\ȃLoX\n" {demo demo-cscroll}

.t insert end \n {} "XP[\n" middle
.t insert end "1. \n" {demo demo-vscale}
.t insert end "2. \n" {demo demo-hscale}

.t insert end \n {} "j[\n" middle
.t insert end "1. j[ƃJXP[h܂񂾃EBhE\n" \
	{demo demo-menu}

.t insert end \n {} "̑\n" middle
.t insert end "1. gݍ݂̃rbg}bv\n" {demo demo-bitmap}
.t insert end "2. [__CAO([JOu)\n" {demo demo-dialog1}
.t insert end "3. [__CAO(O[oOu)\n" {demo demo-dialog2}

.t configure -state disabled

# positionWindow --
# This procedure is invoked by most of the demos to position a
# new demo window.
#
# Arguments:
# w -		The name of the window to position.

proc positionWindow w {
    wm geometry $w +300+300
}

# showVars --
# Displays the values of one or more variables in a window, and
# updates the display whenever any of the variables changes.
#
# Arguments:
# w -		Name of new window to create for display.
# args -	Any number of names of variables.

proc showVars {w args} {
    catch {destroy $w}
    toplevel $w
    wm title $w "Variable values"
    label $w.title -text "ϐl:" -width 20 -anchor center \
	    -font -Adobe-helvetica-medium-r-normal--*-180-*-*-*-*-*-*
    pack $w.title -side top -fill x
    foreach i $args {
	frame $w.$i
	label $w.$i.name -text "$i: "
	label $w.$i.value -textvar $i -anchor w
	pack $w.$i.name -side left
	pack $w.$i.value -side left -expand 1 -fill x
	pack $w.$i -side top -anchor w -fill x
    }
    button $w.ok -text  -command "destroy $w"
    pack $w.ok -side bottom -pady 2
}

# invoke --
# This procedure is called when the user clicks on a demo description.
# It is responsible for invoking the demonstration.
#
# Arguments:
# index -	The index of the character that the user clicked on.

proc invoke index {
    global tk_library
    set tags [.t tag names $index]
    set i [lsearch -glob $tags demo-*]
    if {$i < 0} {
	return
    }
    .t configure -cursor watch
    update
    set demo [string range [lindex $tags $i] 5 end]
    uplevel source $tk_library/demos/$demo.tcl
    update
    .t configure -cursor xterm
}

# showCode --
# This procedure creates a toplevel window that displays the code for
# a demonstration and allows it to be edited and reinvoked.
#
# Arguments:
# w -		The name of the demonstration's window, which can be
#		used to derive the name of the file containing its code.

proc showCode w {
    global tk_library
    set file [string range $w 1 end].tcl
    if ![winfo exists .code] {
	toplevel .code
	frame .code.buttons
	pack .code.buttons -side bottom -expand 1 -fill x
	button .code.buttons.dismiss -text  -command "destroy .code"
	button .code.buttons.rerun -text "Ďs" -command {
	    eval [.code.text get 1.0 end]
	}
	pack .code.buttons.dismiss .code.buttons.rerun -side left \
		-expand 1
	text .code.text -height 40 -yscrollcommand ".code.scroll set" -setgrid 1
	pack .code.text -side left -expand 1 -fill both
	scrollbar .code.scroll -command ".code.text yview"
	pack .code.scroll -side right -fill y
    } else {
	wm deiconify .code
	raise .code
    }
    wm title .code "Demo code: $tk_library/demos/$file"
    wm iconname .code $file
    .code.text delete 1.0 end
    .code.text insert 1.0 [exec cat $tk_library/demos/$file]
    .code.text mark set insert 1.0
}
