;;; -*-Scheme-*-

(require 'xwidgets)
(load-widgets shell ascii box command label)

(define con (create-context))
(define dpy (initialize-display con #f 'text 'demo))
(define top (create-shell 'text 'demo (find-class 'application-shell) dpy))

(define box (create-managed-widget (find-class 'box) top))

(define lab (create-managed-widget (find-class 'label) box))
(set-values! lab 'border-width 0 'label "Enter a number:")

;;; string resource *must* be specified (bug in Xaw):
(define txt (create-managed-widget (find-class 'ascii-string) box
  'string "" 'length 100 'edit-type 'text-edit))

(define can (create-managed-widget (find-class 'command) box))
(set-values! can 'label "CANCEL")
(add-callback can 'callback (lambda foo (exit)))

(define acc (create-managed-widget (find-class 'command) box))
(set-values! acc 'label "ACCEPT")
(add-callback acc 'callback
	      (lambda foo
		(let ((s (car (get-values txt 'string))))
		  (if (not (number-string? s))
		      (format #t "~s is not a number!~%" s)
		      (format #t "Result is ~a~%" s)
		      (exit)))))
      
(define (number-string? s)
  (not (or (eqv? s "") (memq #f (map char-numeric? (string->list s))))))

(realize-widget top)
(context-main-loop con)
