#!/usr/local/bin/stk -f
;******************************************************************************
;
; File name    : widget.stk
; Creation     : Jul-27-1993
; Modification : Aug-19-1993
;
;******************************************************************************
;
; STk adaptation of the Tk widget demo.
;
;******************************************************************************


(set! *load-path* (append `("./Widget" ,(string-append tk_library "/demos"))
			  *load-path*))
(define STk_bitmaps (string-append "@" tk_library "/bitmaps"))

(load "widgetinit.stk")

; 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
; ".stk" files in this directory, which are auto-loaded by Tcl
; when they are needed.  To find the code for a particular
; demo, look below for the procedure that's invoked by its menu
; entry, then grep for the file that contains the procedure
; definition.

(wm 'title "." "Widget Demonstration")

;-------------------------------------------------------
; The code below create the main window, consisting of a
; menu bar and a message explaining the basic operation
; of the program.
;-------------------------------------------------------

(frame ".menu" :relief "raised" :borderwidth 1)
(message ".m"
	 :font "-Adobe-times-medium-r-normal--*-180*" 
	 :relief "raised" 
	 :width "500" :borderwidth 1
	 :text "This application demonstrates the widgets provided by the Tk toolkit.  The menus above are organized by widget type:  each menu contains one or more demonstrations of a particular type of widget.  To invoke a demonstration, press mouse button 1 over one of the menu buttons above, drag the mouse to the desired entry in the menu, then release the mouse button.

To exit this demonstration, invoke the \"Quit\" entry in the \"Misc\" menu.")


(pack 'append "." .menu "top fillx" .m "bottom expand fill")

;-------------------------------------------------------
; The code below creates all the menus, which invoke procedures
; to create particular demonstrations of various widgets.
;-------------------------------------------------------


;---- Menu "Labels/Buttons"

(autoload "mkLabel" 	mkLabel)
(autoload "mkButton" 	mkButton)
(autoload "mkCheck" 	mkCheck)
(autoload "mkRadio" 	mkRadio)
(autoload "mkPuzzle"	mkPuzzle)
(autoload "mkIcon"	mkIcon)

(menubutton ".menu.button"
	    :text "Labels/Buttons" :under 7 :menu ".menu.button.m")
(menu ".menu.button.m")
(.menu.button.m 'add 'command
		:label "Labels" :under 0 :command '(mkLabel))
(.menu.button.m 'add 'command :label "Buttons" :under 0	:command '(mkButton))
(.menu.button.m 'add 'command
		:label "Checkbuttons" :under 0 :command '(mkCheck))
(.menu.button.m 'add 'command
		:label "Radiobuttons" :under 0 :command '(mkRadio))
(.menu.button.m 'add 'command
		:label "15-puzzle" :under 0 :command '(mkPuzzle))
(.menu.button.m 'add 'command
		:label "Iconic buttons" :under 0 :command '(mkIcon))

;---- Menu "Listboxes"

(autoload "mkListbox"	mkListbox)
(autoload "mkListbox2"	mkListbox2)
(autoload "mkListbox3"	mkListbox3)

(menubutton ".menu.listbox" :text "Listboxes" :under 0 :menu ".menu.listbox.m")
(menu ".menu.listbox.m")
(.menu.listbox.m 'add 'command :label "States" :under 0 :command '(mkListbox))
(.menu.listbox.m 'add 'command :label "Colors" :under 0 :command '(mkListbox2))
(.menu.listbox.m 'add 'command
		 :label "Well-known sayings" :under 0 :command '(mkListbox3))

;---- Menu "Entries"

(autoload "mkEntry"	mkEntry)
(autoload "mkEntry2"	mkEntry2)
(autoload "mkForm"	mkForm)

(menubutton ".menu.entry" :text "Entries" :under 0 :menu ".menu.entry.m")
(menu ".menu.entry.m")
(.menu.entry.m 'add 'command
	       :label "Without scrollbars" :under 4 :command '(mkEntry))
(.menu.entry.m 'add 'command
	       :label "With scrollbars" :under 0 :command '(mkEntry2))
(.menu.entry.m 'add 'command :label "Simple form" :under 0 :command '(mkForm))

;---- Menu "Text"

(autoload "mkBasic"	mkBasic)
(autoload "mkStyles"	mkStyles)
(autoload "mkTextBind"	mkTextBind)
(autoload "mkSearch"	mkTextSearch)

(menubutton ".menu.text" :text "Text" :under 0 :menu ".menu.text.m")
(menu ".menu.text.m")
(.menu.text.m 'add 'command :label "Basic text" :under 0 :command '(mkBasic))
(.menu.text.m 'add 'command
	      :label "Display styles" :under 0 :command '(mkStyles))
(.menu.text.m 'add 'command
	      :label "Command bindings" :under 0 :command '(mkTextBind))
(.menu.text.m 'add 'command :label "Search" :under 0 :command '(mkTextSearch))

;---- Menu "Scrollbars"

(menubutton ".menu.scroll" :text "Scrollbars" :under 0 :menu ".menu.scroll.m")
(menu ".menu.scroll.m")
(.menu.scroll.m 'add 'command
		:label "Vertical" :under 0 :command '(mkListbox2))
(.menu.scroll.m 'add 'command
		:label "Horizontal" :under 0 :command '(mkEntry2))

;---- Menu "Scales"

(autoload "mkVScale"	mkVScale)
(autoload "mkHScale"	mkHScale)

(menubutton ".menu.scale" :text "Scales" :under 2 :menu ".menu.scale.m")
(menu ".menu.scale.m")
(.menu.scale.m 'add 'command :label "Vertical" :under 0 :command '(mkVScale))
(.menu.scale.m 'add 'command :label "Horizontal" :under 0 :command '(mkHScale))

;---- Menu "Canvases"

(autoload "mkItems"	mkItems)
(autoload "mkPlot"	mkPlot)
(autoload "mkCanvText"	mkCanvText)
(autoload "mkArrow"	mkArrow)
(autoload "mkRuler"	mkRuler)
(autoload "mkScroll"	mkScroll)
(autoload "mkFloor"	mkFloor)

(menubutton ".menu.canvas" :text "Canvases" :under 0
	    :menu ".menu.canvas.m")
(menu ".menu.canvas.m")
(.menu.canvas.m 'add 'command :label "Item types" :under 0 :command '(mkItems))
(.menu.canvas.m 'add 'command :label "2-D plot" :under 0 :command '(mkPlot))
(.menu.canvas.m 'add 'command :label "Text" :under 0 :command '(mkCanvText))
(.menu.canvas.m 'add 'command
		:label "Arrow shapes" :under 0 :command '(mkArrow))
(.menu.canvas.m 'add 'command :label "Ruler" :under 0 :command '(mkRuler))
(.menu.canvas.m 'add 'command 
		:label "Scrollable canvas" :under 0 :command '(mkScroll))
(.menu.canvas.m 'add 'command :label "Floor plan" :under 0 :command '(mkFloor))

;---- Menu "Menus"

(autoload "mkTear"	mkTear)
(autoload "mkDialog"	mkDialog)

(menubutton ".menu.menu" :text "Menus" :under 0 :menu ".menu.menu.m")
(menu ".menu.menu.m")
(.menu.menu.m 'add 'command
	      :label "Print hello" :under 6 :accel "Control+a"
	      :command '(display "Hello\n"))
(bind .m "<Control-a>" '(display "Hello\n"))
(.menu.menu.m 'add 'command
	      :label "Print goodbye" :under 6 :accel "Control+b"
	      :command '(display "Goodbye\n"))
(bind .m "<Control-b>" '(display "Goodbye\n"))
(.menu.menu.m 'add 'command
	      :label "Light blue background" :under 0
	      :command '(tk-set! .m :bg "LightBlue1"))
(.menu.menu.m 'add 'command
	      :label "Info on tear-off menus" :under 0
	      :command '(mkTear))

(.menu.menu.m 'add 'cascade
	      :label "Check buttons" :under 0
	      :menu ".menu.menu.m.check")
(menu ".menu.menu.m.check")
(.menu.menu.m.check 'add 'check :label "Oil checked" :var 'oil)
(.menu.menu.m.check 'add 'check :label "Transmission checked" :var 'trans)
(.menu.menu.m.check 'add 'check :label "Brakes checked" :var 'brakes)
(.menu.menu.m.check 'add 'check :label "Lights checked" :var 'lights)
(.menu.menu.m.check 'add 'separator)
(.menu.menu.m.check 'add 'command 
		    :label "Show current values"
		    :command '(showVars ".menu.menu.dialog"
					'oil 'trans 'brakes 'lights))
(.menu.menu.m.check 'invoke 1)
(.menu.menu.m.check 'invoke 3)

(.menu.menu.m 'add 'cascade :label "Radio buttons" :under 0
	      :menu ".menu.menu.m.radio")
(menu ".menu.menu.m.radio")
(.menu.menu.m.radio 'add 'radio :label "10 point" :var 'pointSize :value 10)
(.menu.menu.m.radio 'add 'radio :label "14 point" :var 'pointSize :value 14)
(.menu.menu.m.radio 'add 'radio :label "18 point" :var 'pointSize :value 18)
(.menu.menu.m.radio 'add 'radio :label "24 point" :var 'pointSize :value 24)
(.menu.menu.m.radio 'add 'radio :label "32 point" :var 'pointSize :value 32)
(.menu.menu.m.radio 'add 'separator)
(.menu.menu.m.radio 'add 'radio :label "Roman" :var 'style :value "roman")
(.menu.menu.m.radio 'add 'radio :label "Bold" :var 'style :value "bold")
(.menu.menu.m.radio 'add 'radio :label "Italic" :var 'style :value "italic")
(.menu.menu.m.radio 'add 'separator)
(.menu.menu.m.radio 'add 'command
		    :label "Show current values"
		    :command '(showVars ".menu.menu.dialog" 'pointSize 'style))
(.menu.menu.m.radio 'invoke 1)
(.menu.menu.m.radio 'invoke 7)

(.menu.menu.m 'add 'command
	      :bitmap (& STk_bitmaps "/pattern")
	      :command '(mkDialog ".pattern"
				  '(:text "The menu entry you invoked displays a bitmap rather than a text string.  Other than this, it is just like any other menu entry." :aspect 250)
				  '(("OK"))))

;---- Menu "Misc"

(autoload "mkBitmaps"	mkBitmaps)

(menubutton ".menu.misc" :text "Misc" :under 1 :menu ".menu.misc.m")

(menu ".menu.misc.m")

(.menu.misc.m 'add 'command :label "Modal dialog (local grab)" :under 0
	      :command '(cmdLocalGrab))
(define (cmdLocalGrab)
  (mkDialog ".modal"
	    '(:text "This dialog box is a modal one.  It uses Tk's \"grab\" command to create a \"local grab\" on the dialog box.  The grab prevents any pointer-related events from getting to any other windows in the application.\n\nIf you press the \"OK\" button below (or hit the Return key) then the dialog box will go away and things will return to normal." :aspect 250 :justify "left")
	    '(("OK")))
  (dpos .modal)
  (tkwait 'visibility .modal)
  (grab .modal)
  (tkwait 'window .modal))

(.menu.misc.m 'add 'command :label "Modal dialog (global grab)" :under 0
	      :command '(cmdGlobalGrab))
(define (cmdGlobalGrab)
  (mkDialog ".modal"
	    '(:text "This is another modal dialog box.  However, in this case a \"global grab\" is used, which locks up the display so you can't talk to any windows in any applications anywhere, except for the dialog.\n\nIf you press the \"OK\" button below (or hit the Return key) then the dialog box will go away and things will return to normal." :aspect 250 :justify "left")
	    '(("OK")))
  (dpos .modal)
  (tkwait 'visibility .modal)
  (grab :global .modal)
  (tkwait 'window .modal))

(.menu.misc.m 'add 'command :label "Built-in bitmaps" :under 0
	      :command '(mkBitmaps))

(.menu.misc.m 'add 'command :label "Quit" :under 0 :command '(destroy "."))

(pack .menu.button .menu.listbox .menu.entry .menu.text .menu.scroll
      .menu.scale .menu.canvas .menu.menu .menu.misc
      :side "left")

; Set up for keyboard-based menu traversal

;(tk_bindForTraversal .m)
(bind "." "<Any-Enter>" '(focus .m))
;(tk_menuBar .menu
;	    .menu.button .menu.listbox .menu.entry .menu.text
;	    .menu.scroll .menu.scale .menu.canvas .menu.menu .menu.misc)

; Position a dialog box at a reasonable place on the screen.

(define (dpos w)
  (wm 'geometry w "+300+300"))
