;******************************************************************************
;
; File name    : mkForm.stk
; Creation     : Jul-29-1993
; Modification : Jul-29-1993
;
;******************************************************************************
;
; STk adaptation of the Tk widget demo.
;
; mkForm:
; Create a top-level window that displays a bunch of entries with tabs set up
; to move between them.
;
;******************************************************************************


(provide "mkForm")

; This vector contains windows to receive the focus
(define tabList (make-vector 5))


(define (mkForm)
  (catch (destroy .top-form))
  (toplevel ".top-form")
  (dpos .top-form)
  (wm 'title .top-form "Form Demonstration")
  (wm 'iconname .top-form "Form")
  (message ".top-form.m" 
	   :font "-Adobe-times-medium-r-normal--*-180*"
	   :width '4i
	   :text "This window contains a simple form where you can type in the various entries and use <Tab> to move circularly between the entries.\n\nClick the \"OK\" button or type <Return> when you're done.")

  (for-each (lambda (i)
	      (frame (& ".top-form." i) :bd '1m)
	      (pack [entry (& ".top-form." i ".e") :relief "sunken" :width 40]
		    :side "right")
	      (bind (& ".top-form." i ".e") "<Tab>" '(Tab))
	      (bind (& ".top-form." i ".e") "<Return>" '(destroy .top-form))
	      (pack [label (& ".top-form." i ".l")]
		    :side "left"))
	    '(f1 f2 f3 f4 f5))

  (tk-set! .top-form.f1.l :text "Name:")
  (tk-set! .top-form.f2.l :text "Address:")
  (tk-set! .top-form.f5.l :text "Phone:")
  (button ".top-form.ok" :text "OK" :command '(destroy .top-form))
  (pack .top-form.m .top-form.f1 .top-form.f2 .top-form.f3 .top-form.f4 .top-form.f5
	.top-form.ok :side "top" :fill "x")

  ; The list of windows to receive focus

  (vector-set! tabList 0 '.top-form.f1.e)
  (vector-set! tabList 1 '.top-form.f2.e)
  (vector-set! tabList 2 '.top-form.f3.e)
  (vector-set! tabList 3 '.top-form.f4.e)
  (vector-set! tabList 4 '.top-form.f5.e))


; The procedure below is invoked in response to tabs in the entry
; windows.  It moves the focus to the next window in the tab list.

(define (Tab)
  (focus (vector-ref tabList (modulo (+ (vector-index tabList (focus)) 1) 5))))
