stk/STklos/Tk/Composite/Scrollbox.stklos

117 lines
4.0 KiB
Plaintext
Raw Normal View History

1996-09-27 06:29:02 -04:00
;;;;
;;;; S c r o l l b o x . s t k -- Scroll Listbox composite widget
;;;;
1998-04-10 06:59:06 -04:00
;;;; Copyright <20> 1993-1998 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
1996-09-27 06:29:02 -04:00
;;;;
;;;; 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.
;;;;
1998-09-30 07:11:02 -04:00
;;;; $Id: Scrollbox.stklos 1.4 Wed, 04 Feb 1998 11:34:59 +0100 eg $
1998-04-10 06:59:06 -04:00
;;;;
1996-09-27 06:29:02 -04:00
;;;; Author: Erick Gallesio [eg@kaolin.unice.fr]
;;;; Creation date: 22-Mar-1994 13:05
1998-04-10 06:59:06 -04:00
;;;; Last file update: 4-Feb-1998 10:58
(require "Basics")
(select-module STklos+Tk)
1996-09-27 06:29:02 -04:00
1998-04-10 06:59:06 -04:00
;=============================================================================
;
; < S c r o l l - l i s t b o x >
;
;=============================================================================
1996-09-27 06:29:02 -04:00
;;;;
1998-04-10 06:59:06 -04:00
;;;; Resources
;;;;
;;;;
;;;; Class definition
1996-09-27 06:29:02 -04:00
;;;;
(define-class <Scroll-listbox> (<Tk-composite-widget> <Listbox>)
1998-04-10 06:59:06 -04:00
((class :init-keyword :class
:init-form "ScrollListbox")
(listbox :accessor listbox-of)
1996-09-27 06:29:02 -04:00
(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
1998-04-10 06:59:06 -04:00
:slot-ref (lambda (o)
(STk:h-scroll-side (slot-ref o 'h-scrollbar)))
1996-09-27 06:29:02 -04:00
:slot-set! (lambda (o v)
1998-04-10 06:59:06 -04:00
(STk:h-scroll-side-set!
(slot-ref o 'h-scrollbar) v)))
1996-09-27 06:29:02 -04:00
(v-scroll-side :accessor v-scroll-side
:allocation :virtual
:init-keyword :v-scroll-side
:slot-ref (lambda (o)
1998-04-10 06:59:06 -04:00
(STk:v-scroll-side (slot-ref o 'v-scrollbar)))
1996-09-27 06:29:02 -04:00
:slot-set! (lambda (o v)
1998-04-10 06:59:06 -04:00
(STk:v-scroll-side-set!
(slot-ref o 'v-scrollbar) v)))
1996-09-27 06:29:02 -04:00
;; Non allocated slots
(background :accessor background
:init-keyword :background
:allocation :propagated
:propagate-to (frame listbox 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-listbox> methods
;;;;
(define-method initialize-composite-widget ((self <Scroll-listbox>) initargs parent)
(let* ((hs (make <Scrollbar> :parent parent :orientation "horizontal"))
(vs (make <Scrollbar> :parent parent :orientation "vertical"))
(l (make <Listbox> :parent parent)))
;; Set internal true slots
(slot-set! self 'Id (slot-ref l 'Id))
(slot-set! self 'listbox l)
(slot-set! self 'h-scrollbar hs)
(slot-set! self 'v-scrollbar vs)
1998-04-10 06:59:06 -04:00
;; Place internal widgets
(grid hs :row 0 :column 1 :sticky "we") (grid 'remove hs)
(grid l :row 1 :column 1 :sticky "nswe")
(grid vs :row 1 :column 2 :sticky "ns")
(grid 'rowconf parent 1 :weight 1)
(grid 'columnconf parent 1 :weight 1)
1996-09-27 06:29:02 -04:00
;; Attach command to scrollbar and listbox
(slot-set! l 'x-scroll-command (lambda l (apply (slot-ref hs 'Id) 'set l)))
(slot-set! l 'y-scroll-command (lambda l (apply (slot-ref vs 'Id) 'set l)))
(slot-set! hs 'command (lambda args (apply (slot-ref l 'Id) 'xview args)))
(slot-set! vs 'command (lambda args (apply (slot-ref l 'Id) 'yview args)))
))
(provide "Scrollbox")
1998-04-10 06:59:06 -04:00
#|
Example:
(define l1 (make <Scroll-listbox> :h-scroll-side "bottom"
:relief "ridge" :border-width 2
:value '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17)))
(define l2 (make <Scroll-listbox> :v-scroll-side #f :h-scroll-side "top"
:relief "ridge" :border-width 2
:value '("A long long phrase which can be scrolled ...")))
(pack l1 l2 :side 'left :expand #t :fill 'both)
|#