chiark / gitweb /
Defgenerics added to get rid of a few style warnings
[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
4e431775 23;; $Id: gtkcontainer.lisp,v 1.20 2006/02/28 16:32:18 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
eb4f580c 33(defmethod shared-initialize ((container container) names &rest initargs
b45e8c9c 34 &key child children child-args
35 (show-children nil show-children-p))
9f14cf36 36 (declare (ignore child children))
b45e8c9c 37 (when show-children-p
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)))
42
0d07716f 43 (call-next-method)
9f14cf36 44 (initial-add container
45 #'(lambda (container args)
46 (apply #'container-add container (append (mklist args) child-args)))
47 initargs :child :children))
0d07716f 48
0d07716f 49
b45e8c9c 50(defmethod compute-signal-function ((container container) signal function object)
51 (if (eq object :children)
2519d4ca 52 #'(lambda (&rest args)
53 (mapc #'(lambda (child)
54 (apply function child (rest args)))
55 (container-children container)))
56 (call-next-method)))
57
58
dd392521 59(defbinding %container-add () nil
0d07716f 60 (container container)
61 (widget widget))
62
2ba20df0 63(defmethod container-add ((container container) (widget widget) &rest args)
dd392521 64 (%container-add container widget)
65 (when args
66 (setf
c66e7b94 67 (slot-value widget 'child-properties)
dd392521 68 (apply
69 #'make-instance
70 (gethash (class-of container) *container-to-child-class-mappings*)
71 :parent container :child widget args))))
72
dd392521 73(defbinding %container-remove () nil
0d07716f 74 (container container)
75 (widget widget))
76
2ba20df0 77(defmethod container-remove ((container container) (widget widget))
dd392521 78 (%container-remove container widget)
c66e7b94 79 (slot-makunbound widget 'child-properties))
dd392521 80
81
636746d9 82(defbinding %container-child-get-property () nil
83 (container container)
84 (child widget)
85 (property-name string)
86 (value gvalue))
87
88(defbinding %container-child-set-property () nil
89 (container container)
90 (child widget)
91 (property-name string)
92 (value gvalue))
93
94
08aad4db 95(defbinding container-check-resize () nil
0d07716f 96 (container container))
97
a92553bd 98(define-callback-marshal %foreach-callback nil (widget))
860e6a2e 99
100(defbinding %container-foreach (container callback-id) nil
0d07716f 101 (container container)
a92553bd 102 (%foreach-callback callback)
860e6a2e 103 (callback-id unsigned-int))
104
105(defun container-foreach (container function)
4886872c 106 (with-callback-function (id function)
107 (%container-foreach container id)))
0d07716f 108
141b7b09 109(defbinding %container-forall (container callback-id) nil
110 (container container)
a92553bd 111 (%foreach-callback callback)
141b7b09 112 (callback-id unsigned-int))
113
114(defun container-forall (container function)
115 (with-callback-function (id function)
116 (%container-forall container id)))
117
0d07716f 118(defun map-container (seqtype func container)
119 (case seqtype
120 ((nil)
eb4f580c 121 (container-foreach container func)
0d07716f 122 nil)
123 (list
124 (let ((list nil))
860e6a2e 125 (container-foreach
0d07716f 126 container
127 #'(lambda (child)
128 (push (funcall func child) list)))
129 (nreverse list)))
130 (t
860e6a2e 131 (let ((seq (make-sequence seqtype (container-length container)))
0d07716f 132 (index 0))
860e6a2e 133 (container-foreach
0d07716f 134 container
135 #'(lambda (child)
136 (setf (elt seq index) (funcall func child))
137 (incf index)))
138 seq))))
139
dd392521 140(defmethod container-children ((container container))
860e6a2e 141 (map-container 'list #'identity container))
dd392521 142
143(defmethod (setf container-children) (children (container container))
0d07716f 144 (dolist (child (container-children container))
145 (container-remove container child))
146 (dolist (child children)
141b7b09 147 (apply #'container-add container (mklist child)))
0d07716f 148 children)
149
860e6a2e 150(defun container-length (container)
151 (let ((n 0))
152 (container-foreach container
153 #'(lambda (child)
154 (declare (ignore child))
155 (incf n)))
156 n))
0d07716f 157
08aad4db 158(defbinding container-resize-children () nil
0d07716f 159 (container container))
860e6a2e 160
161(defbinding container-propagate-expose () nil
162 (container container)
163 (child widget)
164 (event gdk:expose-event))
165
166
167(defbinding %container-get-focus-chain () boolean
168 (container container)
169 (focusable-widgets (glist widget) :out))
170
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)))
175
176(defbinding %container-set-focus-chain () nil
177 (container container)
178 (focusable-widgets (glist widget)))
179
180(defbinding %container-unset-focus-chain () nil
181 (container container))
182
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)))
b45e8c9c 187
188(defgeneric container-show-recursive (container))
189
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)))