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 | |
55cdee3a |
23 | ;; $Id: gtkcontainer.lisp,v 1.21 2006/04/26 12:31:34 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 | |
b45e8c9c |
66 | (defmethod compute-signal-function ((container container) signal function object) |
55cdee3a |
67 | (declare (ignore signal)) |
b45e8c9c |
68 | (if (eq object :children) |
2519d4ca |
69 | #'(lambda (&rest args) |
55cdee3a |
70 | (container-foreach container |
71 | #'(lambda (child) |
72 | (apply function child (rest args))))) |
2519d4ca |
73 | (call-next-method))) |
74 | |
75 | |
dd392521 |
76 | (defbinding %container-add () nil |
0d07716f |
77 | (container container) |
78 | (widget widget)) |
79 | |
2ba20df0 |
80 | (defmethod container-add ((container container) (widget widget) &rest args) |
dd392521 |
81 | (%container-add container widget) |
82 | (when args |
83 | (setf |
c66e7b94 |
84 | (slot-value widget 'child-properties) |
dd392521 |
85 | (apply |
86 | #'make-instance |
87 | (gethash (class-of container) *container-to-child-class-mappings*) |
88 | :parent container :child widget args)))) |
89 | |
dd392521 |
90 | (defbinding %container-remove () nil |
0d07716f |
91 | (container container) |
92 | (widget widget)) |
93 | |
2ba20df0 |
94 | (defmethod container-remove ((container container) (widget widget)) |
dd392521 |
95 | (%container-remove container widget) |
c66e7b94 |
96 | (slot-makunbound widget 'child-properties)) |
dd392521 |
97 | |
98 | |
636746d9 |
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 | |
08aad4db |
112 | (defbinding container-check-resize () nil |
0d07716f |
113 | (container container)) |
114 | |
a92553bd |
115 | (define-callback-marshal %foreach-callback nil (widget)) |
860e6a2e |
116 | |
117 | (defbinding %container-foreach (container callback-id) nil |
0d07716f |
118 | (container container) |
a92553bd |
119 | (%foreach-callback callback) |
860e6a2e |
120 | (callback-id unsigned-int)) |
121 | |
122 | (defun container-foreach (container function) |
4886872c |
123 | (with-callback-function (id function) |
124 | (%container-foreach container id))) |
0d07716f |
125 | |
141b7b09 |
126 | (defbinding %container-forall (container callback-id) nil |
127 | (container container) |
a92553bd |
128 | (%foreach-callback callback) |
141b7b09 |
129 | (callback-id unsigned-int)) |
130 | |
131 | (defun container-forall (container function) |
132 | (with-callback-function (id function) |
133 | (%container-forall container id))) |
134 | |
0d07716f |
135 | (defun map-container (seqtype func container) |
136 | (case seqtype |
137 | ((nil) |
eb4f580c |
138 | (container-foreach container func) |
0d07716f |
139 | nil) |
140 | (list |
141 | (let ((list nil)) |
55cdee3a |
142 | (container-foreach container |
0d07716f |
143 | #'(lambda (child) |
144 | (push (funcall func child) list))) |
145 | (nreverse list))) |
146 | (t |
860e6a2e |
147 | (let ((seq (make-sequence seqtype (container-length container))) |
0d07716f |
148 | (index 0)) |
55cdee3a |
149 | (container-foreach container |
0d07716f |
150 | #'(lambda (child) |
151 | (setf (elt seq index) (funcall func child)) |
152 | (incf index))) |
153 | seq)))) |
154 | |
55cdee3a |
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))) |
dd392521 |
169 | |
170 | (defmethod (setf container-children) (children (container container)) |
0d07716f |
171 | (dolist (child (container-children container)) |
172 | (container-remove container child)) |
173 | (dolist (child children) |
141b7b09 |
174 | (apply #'container-add container (mklist child))) |
0d07716f |
175 | children) |
176 | |
860e6a2e |
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)) |
0d07716f |
184 | |
08aad4db |
185 | (defbinding container-resize-children () nil |
0d07716f |
186 | (container container)) |
860e6a2e |
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))) |
b45e8c9c |
214 | |
215 | (defgeneric container-show-recursive (container)) |
216 | |
217 | (defmethod container-show-recursive ((container container)) |
55cdee3a |
218 | "Recursively show any child widgets except widgets explicit hidden during construction." |
b45e8c9c |
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))) |