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 | |
b3de3ed8 |
23 | ;; $Id: gtkcontainer.lisp,v 1.20 2006-02-28 16:32:18 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 | |
1047e159 |
33 | (defmethod shared-initialize ((container container) names &rest initargs |
67b44e86 |
34 | &key child children child-args |
35 | (show-children nil show-children-p)) |
4a383aae |
36 | (declare (ignore child children)) |
67b44e86 |
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 | |
560af5c5 |
43 | (call-next-method) |
4a383aae |
44 | (initial-add container |
45 | #'(lambda (container args) |
46 | (apply #'container-add container (append (mklist args) child-args))) |
47 | initargs :child :children)) |
560af5c5 |
48 | |
560af5c5 |
49 | |
67b44e86 |
50 | (defmethod compute-signal-function ((container container) signal function object) |
51 | (if (eq object :children) |
03802c3c |
52 | #'(lambda (&rest args) |
53 | (mapc #'(lambda (child) |
54 | (apply function child (rest args))) |
55 | (container-children container))) |
56 | (call-next-method))) |
57 | |
58 | |
e5b416f0 |
59 | (defbinding %container-add () nil |
560af5c5 |
60 | (container container) |
61 | (widget widget)) |
62 | |
f9e76ebe |
63 | (defmethod container-add ((container container) (widget widget) &rest args) |
e5b416f0 |
64 | (%container-add container widget) |
65 | (when args |
66 | (setf |
c289d084 |
67 | (slot-value widget 'child-properties) |
e5b416f0 |
68 | (apply |
69 | #'make-instance |
70 | (gethash (class-of container) *container-to-child-class-mappings*) |
71 | :parent container :child widget args)))) |
72 | |
e5b416f0 |
73 | (defbinding %container-remove () nil |
560af5c5 |
74 | (container container) |
75 | (widget widget)) |
76 | |
f9e76ebe |
77 | (defmethod container-remove ((container container) (widget widget)) |
e5b416f0 |
78 | (%container-remove container widget) |
c289d084 |
79 | (slot-makunbound widget 'child-properties)) |
e5b416f0 |
80 | |
81 | |
1f518a51 |
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 | |
0d270bd9 |
95 | (defbinding container-check-resize () nil |
560af5c5 |
96 | (container container)) |
97 | |
56ccd5b7 |
98 | (define-callback-marshal %foreach-callback nil (widget)) |
1de3a418 |
99 | |
100 | (defbinding %container-foreach (container callback-id) nil |
560af5c5 |
101 | (container container) |
56ccd5b7 |
102 | (%foreach-callback callback) |
1de3a418 |
103 | (callback-id unsigned-int)) |
104 | |
105 | (defun container-foreach (container function) |
1a1949c7 |
106 | (with-callback-function (id function) |
107 | (%container-foreach container id))) |
560af5c5 |
108 | |
d2ba9d86 |
109 | (defbinding %container-forall (container callback-id) nil |
110 | (container container) |
56ccd5b7 |
111 | (%foreach-callback callback) |
d2ba9d86 |
112 | (callback-id unsigned-int)) |
113 | |
114 | (defun container-forall (container function) |
115 | (with-callback-function (id function) |
116 | (%container-forall container id))) |
117 | |
560af5c5 |
118 | (defun map-container (seqtype func container) |
119 | (case seqtype |
120 | ((nil) |
1047e159 |
121 | (container-foreach container func) |
560af5c5 |
122 | nil) |
123 | (list |
124 | (let ((list nil)) |
1de3a418 |
125 | (container-foreach |
560af5c5 |
126 | container |
127 | #'(lambda (child) |
128 | (push (funcall func child) list))) |
129 | (nreverse list))) |
130 | (t |
1de3a418 |
131 | (let ((seq (make-sequence seqtype (container-length container))) |
560af5c5 |
132 | (index 0)) |
1de3a418 |
133 | (container-foreach |
560af5c5 |
134 | container |
135 | #'(lambda (child) |
136 | (setf (elt seq index) (funcall func child)) |
137 | (incf index))) |
138 | seq)))) |
139 | |
e5b416f0 |
140 | (defmethod container-children ((container container)) |
1de3a418 |
141 | (map-container 'list #'identity container)) |
e5b416f0 |
142 | |
143 | (defmethod (setf container-children) (children (container container)) |
560af5c5 |
144 | (dolist (child (container-children container)) |
145 | (container-remove container child)) |
146 | (dolist (child children) |
d2ba9d86 |
147 | (apply #'container-add container (mklist child))) |
560af5c5 |
148 | children) |
149 | |
1de3a418 |
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)) |
560af5c5 |
157 | |
0d270bd9 |
158 | (defbinding container-resize-children () nil |
560af5c5 |
159 | (container container)) |
1de3a418 |
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))) |
67b44e86 |
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))) |