chiark / gitweb /
Made iter argument to TREE-MODEL-ITER-N-CHILDREN optional
[clg] / gtk / gtkcontainer.lisp
CommitLineData
112ac1d3 1;; Common Lisp bindings for GTK+ v2.x
2;; Copyright 2000-2005 Espen S. Johnsen <espen@users.sf.net>
560af5c5 3;;
112ac1d3 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:
560af5c5 11;;
112ac1d3 12;; The above copyright notice and this permission notice shall be
13;; included in all copies or substantial portions of the Software.
560af5c5 14;;
112ac1d3 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.
560af5c5 22
76ff9f39 23;; $Id: gtkcontainer.lisp,v 1.21 2006-04-26 12:31:34 espen Exp $
560af5c5 24
25(in-package "GTK")
4a383aae 26
b3de3ed8 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
76ff9f39 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
1047e159 49(defmethod shared-initialize ((container container) names &rest initargs
67b44e86 50 &key child children child-args
76ff9f39 51 (show-children nil show-children-p))
52 (declare (ignore names child children))
67b44e86 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
560af5c5 59 (call-next-method)
4a383aae 60 (initial-add container
61 #'(lambda (container args)
62 (apply #'container-add container (append (mklist args) child-args)))
63 initargs :child :children))
560af5c5 64
560af5c5 65
67b44e86 66(defmethod compute-signal-function ((container container) signal function object)
76ff9f39 67 (declare (ignore signal))
67b44e86 68 (if (eq object :children)
03802c3c 69 #'(lambda (&rest args)
76ff9f39 70 (container-foreach container
71 #'(lambda (child)
72 (apply function child (rest args)))))
03802c3c 73 (call-next-method)))
74
75
e5b416f0 76(defbinding %container-add () nil
560af5c5 77 (container container)
78 (widget widget))
79
f9e76ebe 80(defmethod container-add ((container container) (widget widget) &rest args)
e5b416f0 81 (%container-add container widget)
82 (when args
83 (setf
c289d084 84 (slot-value widget 'child-properties)
e5b416f0 85 (apply
86 #'make-instance
87 (gethash (class-of container) *container-to-child-class-mappings*)
88 :parent container :child widget args))))
89
e5b416f0 90(defbinding %container-remove () nil
560af5c5 91 (container container)
92 (widget widget))
93
f9e76ebe 94(defmethod container-remove ((container container) (widget widget))
e5b416f0 95 (%container-remove container widget)
c289d084 96 (slot-makunbound widget 'child-properties))
e5b416f0 97
98
1f518a51 99(defbinding %container-child-get-property () nil
100 (container container)
101 (child widget)
102 (property-name string)
103 (value gvalue))
104
105(defbinding %container-child-set-property () nil
106 (container container)
107 (child widget)
108 (property-name string)
109 (value gvalue))
110
111
0d270bd9 112(defbinding container-check-resize () nil
560af5c5 113 (container container))
114
56ccd5b7 115(define-callback-marshal %foreach-callback nil (widget))
1de3a418 116
117(defbinding %container-foreach (container callback-id) nil
560af5c5 118 (container container)
56ccd5b7 119 (%foreach-callback callback)
1de3a418 120 (callback-id unsigned-int))
121
122(defun container-foreach (container function)
1a1949c7 123 (with-callback-function (id function)
124 (%container-foreach container id)))
560af5c5 125
d2ba9d86 126(defbinding %container-forall (container callback-id) nil
127 (container container)
56ccd5b7 128 (%foreach-callback callback)
d2ba9d86 129 (callback-id unsigned-int))
130
131(defun container-forall (container function)
132 (with-callback-function (id function)
133 (%container-forall container id)))
134
560af5c5 135(defun map-container (seqtype func container)
136 (case seqtype
137 ((nil)
1047e159 138 (container-foreach container func)
560af5c5 139 nil)
140 (list
141 (let ((list nil))
76ff9f39 142 (container-foreach container
560af5c5 143 #'(lambda (child)
144 (push (funcall func child) list)))
145 (nreverse list)))
146 (t
1de3a418 147 (let ((seq (make-sequence seqtype (container-length container)))
560af5c5 148 (index 0))
76ff9f39 149 (container-foreach container
560af5c5 150 #'(lambda (child)
151 (setf (elt seq index) (funcall func child))
152 (incf index)))
153 seq))))
154
76ff9f39 155(defmethod container-all-children ((container container))
156 (let ((internal ()))
157 (container-forall container
158 #'(lambda (child)
159 (push child internal)))
160 (nreverse internal)))
161
162(defmethod container-internal-children ((container container))
163 (let ((public-children (container-children container))
164 (all-children (container-all-children container)))
165 (loop
166 for child in all-children
167 unless (find child public-children)
168 collect child)))
e5b416f0 169
170(defmethod (setf container-children) (children (container container))
560af5c5 171 (dolist (child (container-children container))
172 (container-remove container child))
173 (dolist (child children)
d2ba9d86 174 (apply #'container-add container (mklist child)))
560af5c5 175 children)
176
1de3a418 177(defun container-length (container)
178 (let ((n 0))
179 (container-foreach container
180 #'(lambda (child)
181 (declare (ignore child))
182 (incf n)))
183 n))
560af5c5 184
0d270bd9 185(defbinding container-resize-children () nil
560af5c5 186 (container container))
1de3a418 187
188(defbinding container-propagate-expose () nil
189 (container container)
190 (child widget)
191 (event gdk:expose-event))
192
193
194(defbinding %container-get-focus-chain () boolean
195 (container container)
196 (focusable-widgets (glist widget) :out))
197
198(defun container-focus-chain (container)
199 (multiple-value-bind (chain-set-p focusable-widgets)
200 (%container-get-focus-chain container)
201 (and chain-set-p focusable-widgets)))
202
203(defbinding %container-set-focus-chain () nil
204 (container container)
205 (focusable-widgets (glist widget)))
206
207(defbinding %container-unset-focus-chain () nil
208 (container container))
209
210(defun (setf container-focus-chain) (focusable-widgets container)
211 (if (null focusable-widgets)
212 (%container-unset-focus-chain container)
213 (%container-set-focus-chain container focusable-widgets)))
67b44e86 214
215(defgeneric container-show-recursive (container))
216
217(defmethod container-show-recursive ((container container))
76ff9f39 218 "Recursively show any child widgets except widgets explicit hidden during construction."
67b44e86 219 (labels ((recursive-show (widget)
220 (when (typep widget 'container)
221 (if (not (user-data-p widget 'show-recursive-p))
222 (container-foreach widget #'recursive-show)
223 (unset-user-data widget 'show-recursive-p)))
224 (unless (widget-hidden-p widget)
225 (widget-show widget))))
226 (container-foreach container #'recursive-show)))