1 ;; -*- mode: Lisp; Syntax: Common-Lisp; Package: cells; -*-
4 Celtk -- Cells
, Tcl
, and Tk
6 Copyright
(C) 2006 by Kenneth Tilton
8 This library is free software
; you can redistribute it and/or
9 modify it under the terms of the Lisp Lesser GNU Public License
10 (http://opensource.franz.com
/preamble.html
), known as the LLGPL.
12 This library is distributed WITHOUT ANY WARRANTY
; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 See the Lisp Lesser GNU Public License for more details.
22 ; --- scroll bars ----------------------------------------
24 (deftk scrollbar
(widget)
27 -activebackground -activerelief
28 -background -borderwidth -command -cursor
30 -highlightbackground -highlightcolor -highlightthickness
31 -jump -orient -relief -repeatdelay
32 -repeatinterval -takefocus
35 :id
(gentemp "SBAR")))
37 (deftk scrolled-list
(row-mixin frame-selector
)
38 ((list-item-keys :initarg
:list-item-keys
:accessor list-item-keys
:initform nil
)
39 (list-item-factory :initarg
:list-item-factory
:accessor list-item-factory
:initform nil
)
40 (list-height :initarg
:list-height
:accessor list-height
:initform nil
)
41 (tkfont :initarg
:tkfont
:accessor tkfont
:initform
(c-in '(courier 9))))
43 :list-height
(c?
(max 1 (length (^list-item-keys
))))
46 (mk-listbox :id
:list-me
48 (mapcar (list-item-factory .parent
)
49 (list-item-keys .parent
))))
50 :tkfont
(c?
(tkfont .parent
))
51 :state
(c?
(if (enabled .parent
) 'normal
'disabled
))
52 :takefocus
(c?
(if (enabled .parent
) 1 0))
53 :height
(c?
(list-height .parent
))
54 :packing
(c?
(format nil
"pack ~a -side left -fill both -expand 1" (^path
)))
55 :yscrollcommand
(c?
(when (enabled .parent
)
56 (format nil
"~a set" (path (nsib))))))
57 (mk-scrollbar :id
:vscroll
58 :packing
(c?pack-self
"-side right -fill y")
59 :command
(c?
(format nil
"~a yview" (path (psib)))))))))
61 (defmethod tk-output-selection :after
((self scrolled-list
) new-value old-value old-value-boundp
)
62 (declare (ignorable old-value old-value-boundp
))
63 (trc nil
"scrolled-list selection output" self new-value
)
65 (let ((lb (car (^kids
)))
66 (item-no (position new-value
(^list-item-keys
) :test
'equal
)))
68 (tk-format `(:selection
,self
) "~(~a~) selection set ~a" (path lb
) item-no
)
69 (break "~&scrolled-list ~a selection ~a not found in item keys ~a" self new-value
(^list-item-keys
))))))
72 ;--- scroller (of canvas; need to generalize this) ----------
74 (defmodel scroller
(grid-manager frame
)
75 ((canvas :initarg
:canvas
:accessor canvas
:initform nil
))
79 :gridding
'(:columns
("-weight {1}" "-weight {0}")
80 :rows
("-weight {1}" "-weight {0}"))
83 (mk-scrollbar :id
:hscroll
85 :gridding
"-row 1 -column 0 -sticky we"
86 :command
(c?
(format nil
"~a xview" (path (kid1 .parent
)))))
87 (mk-scrollbar :id
:vscroll
89 :gridding
"-row 0 -column 1 -sticky ns"
90 :command
(c?
(format nil
"~a yview" (path (kid1 .parent
)))))))))
92 (defmacro mk-scroller
(&rest iargs
)
93 `(make-instance 'scroller
97 (defmethod initialize-instance :after
((self scroller
) &key
)
99 ; Tk does not do late binding on widget refs, so the canvas cannot mention the scrollbars
100 ; in x/y scrollcommands since the canvas gets made first
102 (with-integrity (:client
`(:post-make-tk
,self
))
103 (setf (xscrollcommand (kid1 self
)) (format nil
"~a set" (path (fm! :hscroll
))))
104 (setf (yscrollcommand (kid1 self
)) (format nil
"~a set" (path (fm! :vscroll
))))))