Added args argument to COMPUTE-SIGNAL-FUNCTION
[clg] / gtk / gtkcontainer.lisp
CommitLineData
55212af1 1;; Common Lisp bindings for GTK+ v2.x
2;; Copyright 2000-2005 Espen S. Johnsen <espen@users.sf.net>
0d07716f 3;;
55212af1 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:
0d07716f 11;;
55212af1 12;; The above copyright notice and this permission notice shall be
13;; included in all copies or substantial portions of the Software.
0d07716f 14;;
55212af1 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.
0d07716f 22
a68868d1 23;; $Id: gtkcontainer.lisp,v 1.22 2007/01/07 20:23:22 espen Exp $
0d07716f 24
25(in-package "GTK")
9f14cf36 26
4e431775 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))
31
32
55cdee3a 33(defun initial-add (object function initargs key pkey)
34 (loop
35 as (initarg value . rest) = initargs then rest
36 do (cond
37 ((eq initarg key) (funcall function object value))
38 ((eq initarg pkey) (mapc #'(lambda (value)
39 (funcall function object value))
40 value)))
41 while rest))
42
43(defun initial-apply-add (object function initargs key pkey)
44 (initial-add object #'(lambda (object value)
45 (apply function object (mklist value)))
46 initargs key pkey))
47
48
eb4f580c 49(defmethod shared-initialize ((container container) names &rest initargs
b45e8c9c 50 &key child children child-args
55cdee3a 51 (show-children nil show-children-p))
52 (declare (ignore names child children))
b45e8c9c 53 (when show-children-p
54 (if (not show-children)
55 (setf (user-data container 'show-recursive-p) nil)
56 (signal-connect container 'show #'container-show-recursive
57 :object t :remove t)))
58
0d07716f 59 (call-next-method)
9f14cf36 60 (initial-add container
61 #'(lambda (container args)
62 (apply #'container-add container (append (mklist args) child-args)))
63 initargs :child :children))
0d07716f 64
0d07716f 65
a68868d1 66(defmethod compute-signal-function ((container container) signal function object args)
55cdee3a 67 (declare (ignore signal))
b45e8c9c 68 (if (eq object :children)
a68868d1 69 #'(lambda (&rest emission-args)
70 (let ((all-args (nconc (rest emission-args) args)))
71 (container-foreach container
72 #'(lambda (child)
73 (apply function child all-args)))))
2519d4ca 74 (call-next-method)))
75
76
dd392521 77(defbinding %container-add () nil
0d07716f 78 (container container)
79 (widget widget))
80
2ba20df0 81(defmethod container-add ((container container) (widget widget) &rest args)
dd392521 82 (%container-add container widget)
83 (when args
84 (setf
c66e7b94 85 (slot-value widget 'child-properties)
dd392521 86 (apply
87 #'make-instance
88 (gethash (class-of container) *container-to-child-class-mappings*)
89 :parent container :child widget args))))
90
a68868d1 91(defmethod container-add ((container container) (widgets list) &rest args)
92 (dolist (widget widgets)
93 (apply #'container-add container widget args)))
94
dd392521 95(defbinding %container-remove () nil
0d07716f 96 (container container)
97 (widget widget))
98
2ba20df0 99(defmethod container-remove ((container container) (widget widget))
dd392521 100 (%container-remove container widget)
c66e7b94 101 (slot-makunbound widget 'child-properties))
dd392521 102
103
636746d9 104(defbinding %container-child-get-property () nil
105 (container container)
106 (child widget)
107 (property-name string)
108 (value gvalue))
109
110(defbinding %container-child-set-property () nil
111 (container container)
112 (child widget)
113 (property-name string)
114 (value gvalue))
115
116
08aad4db 117(defbinding container-check-resize () nil
0d07716f 118 (container container))
119
a92553bd 120(define-callback-marshal %foreach-callback nil (widget))
860e6a2e 121
122(defbinding %container-foreach (container callback-id) nil
0d07716f 123 (container container)
a92553bd 124 (%foreach-callback callback)
860e6a2e 125 (callback-id unsigned-int))
126
127(defun container-foreach (container function)
4886872c 128 (with-callback-function (id function)
129 (%container-foreach container id)))
0d07716f 130
141b7b09 131(defbinding %container-forall (container callback-id) nil
132 (container container)
a92553bd 133 (%foreach-callback callback)
141b7b09 134 (callback-id unsigned-int))
135
136(defun container-forall (container function)
137 (with-callback-function (id function)
138 (%container-forall container id)))
139
0d07716f 140(defun map-container (seqtype func container)
141 (case seqtype
142 ((nil)
eb4f580c 143 (container-foreach container func)
0d07716f 144 nil)
145 (list
146 (let ((list nil))
55cdee3a 147 (container-foreach container
0d07716f 148 #'(lambda (child)
149 (push (funcall func child) list)))
150 (nreverse list)))
151 (t
860e6a2e 152 (let ((seq (make-sequence seqtype (container-length container)))
0d07716f 153 (index 0))
55cdee3a 154 (container-foreach container
0d07716f 155 #'(lambda (child)
156 (setf (elt seq index) (funcall func child))
157 (incf index)))
158 seq))))
159
55cdee3a 160(defmethod container-all-children ((container container))
161 (let ((internal ()))
162 (container-forall container
163 #'(lambda (child)
164 (push child internal)))
165 (nreverse internal)))
166
167(defmethod container-internal-children ((container container))
168 (let ((public-children (container-children container))
169 (all-children (container-all-children container)))
170 (loop
171 for child in all-children
172 unless (find child public-children)
173 collect child)))
dd392521 174
175(defmethod (setf container-children) (children (container container))
0d07716f 176 (dolist (child (container-children container))
177 (container-remove container child))
178 (dolist (child children)
141b7b09 179 (apply #'container-add container (mklist child)))
0d07716f 180 children)
181
860e6a2e 182(defun container-length (container)
183 (let ((n 0))
184 (container-foreach container
185 #'(lambda (child)
186 (declare (ignore child))
187 (incf n)))
188 n))
0d07716f 189
08aad4db 190(defbinding container-resize-children () nil
0d07716f 191 (container container))
860e6a2e 192
193(defbinding container-propagate-expose () nil
194 (container container)
195 (child widget)
196 (event gdk:expose-event))
197
198
199(defbinding %container-get-focus-chain () boolean
200 (container container)
201 (focusable-widgets (glist widget) :out))
202
203(defun container-focus-chain (container)
204 (multiple-value-bind (chain-set-p focusable-widgets)
205 (%container-get-focus-chain container)
206 (and chain-set-p focusable-widgets)))
207
208(defbinding %container-set-focus-chain () nil
209 (container container)
210 (focusable-widgets (glist widget)))
211
212(defbinding %container-unset-focus-chain () nil
213 (container container))
214
215(defun (setf container-focus-chain) (focusable-widgets container)
216 (if (null focusable-widgets)
217 (%container-unset-focus-chain container)
218 (%container-set-focus-chain container focusable-widgets)))
b45e8c9c 219
220(defgeneric container-show-recursive (container))
221
222(defmethod container-show-recursive ((container container))
55cdee3a 223 "Recursively show any child widgets except widgets explicit hidden during construction."
b45e8c9c 224 (labels ((recursive-show (widget)
225 (when (typep widget 'container)
226 (if (not (user-data-p widget 'show-recursive-p))
227 (container-foreach widget #'recursive-show)
228 (unset-user-data widget 'show-recursive-p)))
229 (unless (widget-hidden-p widget)
230 (widget-show widget))))
231 (container-foreach container #'recursive-show)))