1 ;; Common Lisp bindings for GTK+ v2.x
2 ;; Copyright 2000-2005 Espen S. Johnsen <espen@users.sf.net>
4 ;; Permission is hereby granted, free of charge, to any person obtaining
5 ;; a copy of this software and associated documentation files (the
6 ;; "Software"), to deal in the Software without restriction, including
7 ;; without limitation the rights to use, copy, modify, merge, publish,
8 ;; distribute, sublicense, and/or sell copies of the Software, and to
9 ;; permit persons to whom the Software is furnished to do so, subject to
10 ;; the following conditions:
12 ;; The above copyright notice and this permission notice shall be
13 ;; included in all copies or substantial portions of the Software.
15 ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 ;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 ;; CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 ;; $Id: gtkcontainer.lisp,v 1.20 2006-02-28 16:32:18 espen Exp $
27 (defgeneric container-add (container widget &rest args))
28 (defgeneric container-remove (container widget))
29 (defgeneric container-children (container))
30 (defgeneric (setf container-children) (children container))
33 (defmethod shared-initialize ((container container) names &rest initargs
34 &key child children child-args
35 (show-children nil show-children-p))
36 (declare (ignore child children))
38 (if (not show-children)
39 (setf (user-data container 'show-recursive-p) nil)
40 (signal-connect container 'show #'container-show-recursive
41 :object t :remove t)))
44 (initial-add container
45 #'(lambda (container args)
46 (apply #'container-add container (append (mklist args) child-args)))
47 initargs :child :children))
50 (defmethod compute-signal-function ((container container) signal function object)
51 (if (eq object :children)
52 #'(lambda (&rest args)
53 (mapc #'(lambda (child)
54 (apply function child (rest args)))
55 (container-children container)))
59 (defbinding %container-add () nil
63 (defmethod container-add ((container container) (widget widget) &rest args)
64 (%container-add container widget)
67 (slot-value widget 'child-properties)
70 (gethash (class-of container) *container-to-child-class-mappings*)
71 :parent container :child widget args))))
73 (defbinding %container-remove () nil
77 (defmethod container-remove ((container container) (widget widget))
78 (%container-remove container widget)
79 (slot-makunbound widget 'child-properties))
82 (defbinding %container-child-get-property () nil
85 (property-name string)
88 (defbinding %container-child-set-property () nil
91 (property-name string)
95 (defbinding container-check-resize () nil
96 (container container))
98 (define-callback-marshal %foreach-callback nil (widget))
100 (defbinding %container-foreach (container callback-id) nil
101 (container container)
102 (%foreach-callback callback)
103 (callback-id unsigned-int))
105 (defun container-foreach (container function)
106 (with-callback-function (id function)
107 (%container-foreach container id)))
109 (defbinding %container-forall (container callback-id) nil
110 (container container)
111 (%foreach-callback callback)
112 (callback-id unsigned-int))
114 (defun container-forall (container function)
115 (with-callback-function (id function)
116 (%container-forall container id)))
118 (defun map-container (seqtype func container)
121 (container-foreach container func)
128 (push (funcall func child) list)))
131 (let ((seq (make-sequence seqtype (container-length container)))
136 (setf (elt seq index) (funcall func child))
140 (defmethod container-children ((container container))
141 (map-container 'list #'identity container))
143 (defmethod (setf container-children) (children (container container))
144 (dolist (child (container-children container))
145 (container-remove container child))
146 (dolist (child children)
147 (apply #'container-add container (mklist child)))
150 (defun container-length (container)
152 (container-foreach container
154 (declare (ignore child))
158 (defbinding container-resize-children () nil
159 (container container))
161 (defbinding container-propagate-expose () nil
162 (container container)
164 (event gdk:expose-event))
167 (defbinding %container-get-focus-chain () boolean
168 (container container)
169 (focusable-widgets (glist widget) :out))
171 (defun container-focus-chain (container)
172 (multiple-value-bind (chain-set-p focusable-widgets)
173 (%container-get-focus-chain container)
174 (and chain-set-p focusable-widgets)))
176 (defbinding %container-set-focus-chain () nil
177 (container container)
178 (focusable-widgets (glist widget)))
180 (defbinding %container-unset-focus-chain () nil
181 (container container))
183 (defun (setf container-focus-chain) (focusable-widgets container)
184 (if (null focusable-widgets)
185 (%container-unset-focus-chain container)
186 (%container-set-focus-chain container focusable-widgets)))
188 (defgeneric container-show-recursive (container))
190 (defmethod container-show-recursive ((container container))
191 "Recursively shows any child widgets except widgets explicit hidden during construction."
192 (labels ((recursive-show (widget)
193 (when (typep widget 'container)
194 (if (not (user-data-p widget 'show-recursive-p))
195 (container-foreach widget #'recursive-show)
196 (unset-user-data widget 'show-recursive-p)))
197 (unless (widget-hidden-p widget)
198 (widget-show widget))))
199 (container-foreach container #'recursive-show)))