;;;;
;;;; entry2.stk -- Another GTK+ Entry Demo
;;;;
;;;; Copyright © 2001-2021 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
;;;;
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 2 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;;; GNU General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program; if not, write to the Free Software
;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
;;;; USA.
;;;;
;;;;           Author: Erick Gallesio [eg@unice.fr]
;;;;    Creation date: 24-Jul-2001 21:54 (eg)
;;;;

(include "demos-utils.stk")


(define demo-message "
Entry and Events

This is a demonstration of the entry widget.
In this demo,an event handler is associated to the widget.
This event handler manages the \"Enter\" and \"Control-q\" keys.
The former prints a message and the later exits the demonstration.
")


(define (main args)
  (let* ((window (make <demo-window>
                   #:title "STklos Entry and Events"
                   #:border-width 15
                   #:file "entry2"
                   #:message demo-message))
         (entry  (make <entry> #:value "This is an entry" #:parent window)))
    ;; Connect event management
    (event-connect entry "key-press-event"
                   (lambda (widget ev)
                     (let ((ch (event-char ev)))
                       (cond
                        ((char=? ch #\newline)
                         (printf "entry value: ~S\n" (value entry)))
                        ((char=? ch #\q)
                         (when (member 'control (event-modifiers ev))
                           (printf "Quit\n")
                           (exit 0)))))
                     ;; Propagate event to widget
                     #f))
    (gtk-main)))
