;;;;
;;;; S c r o l l t e x t . s t k 	  --  Scroll Text composite widget
;;;;
;;;; Copyright (C) 1993,1994,1995 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
;;;; 
;;;; Permission to use, copy, and/or distribute this software and its
;;;; documentation for any purpose and without fee is hereby granted, provided
;;;; that both the above copyright notice and this permission notice appear in
;;;; all copies and derived works.  Fees for distribution or use of this
;;;; software or derived works may only be charged with express written
;;;; permission of the copyright holder.  
;;;; This software is provided ``as is'' without express or implied warranty.
;;;;
;;;;           Author: Erick Gallesio [eg@kaolin.unice.fr]
;;;;    Creation date:  4-Apr-1995 11:19
;;;; Last file update: 23-Jun-1995 22:27

(require "Frame")
(require "Text")
(require "Scrollbar")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
;;;; <Scroll-text> class definition
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define-class <Scroll-text> (<Tk-composite-widget> <Text>)
  ((text 	  :accessor     text-of)
   (h-scrollbar	  :accessor     h-scrollbar-of)
   (v-scrollbar	  :accessor     v-scrollbar-of)
   (h-scroll-side :accessor     h-scroll-side
		  :allocation   :virtual
		  :init-keyword :h-scroll-side
		  :slot-ref     (lambda (o)   "not available in Tk3.6!")
		  :slot-set!    (lambda (o v) "not available in Tk3.6!"))
   (v-scroll-side :accessor     v-scroll-side
		  :allocation   :virtual
		  :init-keyword :v-scroll-side
		  :slot-ref     (lambda (o)
				  (let ((vs (v-scrollbar-of o)))
				    (if (= (winfo 'ismapped vs) 1)
					(cadr (member '-side 
						      (pack 'newinfo vs)))
					#f)))
		  :slot-set!    (lambda (o v)
				  (unless (memv v '(left right #f))
				     (error "bad scroll side specification: ~S" v))
				  (let ((vs (v-scrollbar-of o)))
				    (if v 
					(pack vs :fill 'y :side v 
					         :before (text-of o))
					(pack 'forget vs)))))
   ;; Non allocated slots
   (background   :accessor     background
		 :init-keyword :background
		 :allocation   :propagated
		 :propagate-to (frame text h-scrollbar v-scrollbar))
   (border-width :accessor     border-width 
		 :allocation   :propagated
		 :init-keyword :border-width
		 :propagate-to (frame))
   (relief	 :accessor     relief
		 :init-keyword :relief
		 :allocation   :propagated
		 :propagate-to (frame))))

;;;;
;;;;  <Scroll-text> methods
;;;;

(define-method initialize-composite-widget ((self <Scroll-text>) initargs parent)
  (let* ((hs "Not available in Tk 3.6")
	 (vs (make <Scrollbar> :parent parent :border-width 2 
		   	       :relief "groove" :orientation "vertical"))
	 (t  (make <Text>      :parent parent :border-width 2 
		   	       :relief "groove")))

    ;; Set internal true slots 
    (slot-set! self 'Id	          (Id t))
    (slot-set! self 'text         t)
    (slot-set! self 'h-scrollbar  hs)
    (slot-set! self 'v-scrollbar  vs)

    ;; Pack internal widgets (Warning: Order is dependant !!!!)
    (pack vs :fill 'y :side 'right)
    (pack t  :expand #t :fill "both" :side 'bottom :after vs)

    ;; Attach command to scrollbar and text
    (set! (y-scroll-command t) (format #f "~S 'set "  (address-of (Id vs))))
    (set! (command vs)         (format #f "~S 'yview "(address-of (Id t))))
))

(provide "Scrolltext")
