387230e8 |
1 | ;; Common Lisp bindings for GTK+ v2.0 |
2 | ;; Copyright (C) 2000 Espen S. Johnsen <esj@stud.cs.uit.no> |
3 | ;; |
4 | ;; This library is free software; you can redistribute it and/or |
5 | ;; modify it under the terms of the GNU Lesser General Public |
6 | ;; License as published by the Free Software Foundation; either |
7 | ;; version 2 of the License, or (at your option) any later version. |
8 | ;; |
9 | ;; This library is distributed in the hope that it will be useful, |
10 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | ;; Lesser General Public License for more details. |
13 | ;; |
14 | ;; You should have received a copy of the GNU Lesser General Public |
15 | ;; License along with this library; if not, write to the Free Software |
16 | ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 | |
8532ba0a |
18 | ;; $Id: gparam.lisp,v 1.13 2005-01-03 16:42:03 espen Exp $ |
387230e8 |
19 | |
20 | (in-package "GLIB") |
21 | |
22 | (deftype gvalue () 'pointer) |
23 | |
8532ba0a |
24 | (register-type 'gvalue "GValue") |
25 | |
4d83a8a6 |
26 | (eval-when (:compile-toplevel :load-toplevel :execute) |
27 | (defbinding (size-of-gvalue "size_of_gvalue") () unsigned-int)) |
28 | |
9adccb27 |
29 | ;(defconstant +gvalue-size+ (+ (size-of 'type-number) (* 2 (size-of 'double-float)))) |
4d83a8a6 |
30 | (defconstant +gvalue-size+ #.(size-of-gvalue)) |
31 | |
387230e8 |
32 | (defconstant +gvalue-value-offset+ (size-of 'type-number)) |
33 | |
9adccb27 |
34 | (defbinding (%gvalue-init "g_value_init") () nil |
4d83a8a6 |
35 | (value gvalue) |
387230e8 |
36 | (type type-number)) |
37 | |
68093e26 |
38 | (defbinding (gvalue-unset "g_value_unset") () nil |
39 | (value gvalue)) |
40 | |
9adccb27 |
41 | (defun gvalue-init (gvalue type &optional (value nil value-p)) |
42 | (%gvalue-init gvalue (find-type-number type)) |
43 | (when value-p |
44 | (funcall (writer-function type) value gvalue +gvalue-value-offset+))) |
68093e26 |
45 | |
3c44ba6c |
46 | (defun gvalue-new (&optional type (value nil value-p)) |
387230e8 |
47 | (let ((gvalue (allocate-memory +gvalue-size+))) |
3c44ba6c |
48 | (cond |
49 | (value-p (gvalue-init gvalue type value)) |
50 | (type (gvalue-init gvalue type))) |
387230e8 |
51 | gvalue)) |
52 | |
9adccb27 |
53 | (defun gvalue-free (gvalue &optional (unset-p t)) |
387230e8 |
54 | (unless (null-pointer-p gvalue) |
68093e26 |
55 | (when unset-p |
56 | (gvalue-unset gvalue)) |
387230e8 |
57 | (deallocate-memory gvalue))) |
58 | |
59 | (defun gvalue-type (gvalue) |
60 | (type-from-number (system:sap-ref-32 gvalue 0))) |
61 | |
62 | (defun gvalue-get (gvalue) |
9adccb27 |
63 | (funcall (reader-function (gvalue-type gvalue)) |
387230e8 |
64 | gvalue +gvalue-value-offset+)) |
65 | |
66 | (defun gvalue-set (gvalue value) |
9adccb27 |
67 | (funcall (writer-function (gvalue-type gvalue)) |
387230e8 |
68 | value gvalue +gvalue-value-offset+) |
69 | value) |
70 | |
8532ba0a |
71 | (defbinding (gvalue-p "g_type_check_value") () boolean |
72 | (location pointer)) |
73 | |
74 | (defmacro with-gvalue ((gvalue &optional type value) &body body) |
75 | `(let ((,gvalue ,(if type |
3c44ba6c |
76 | `(gvalue-new ,type ,value) |
77 | `(gvalue-new)))) |
6243c15e |
78 | (unwind-protect |
79 | (progn |
80 | ,@body |
8532ba0a |
81 | ,(unless type `(gvalue-get ,gvalue))) |
6243c15e |
82 | (gvalue-free ,gvalue)))) |
df0b4e7d |
83 | |
4d83a8a6 |
84 | |
df0b4e7d |
85 | (deftype param-flag-type () |
86 | '(flags |
4eb73e10 |
87 | (:readable 1) |
88 | (:writable 2) |
89 | (:construct 4) |
90 | (:construct-only 8) |
91 | (:lax-validation 16) |
92 | (:private 32))) |
df0b4e7d |
93 | |
9adccb27 |
94 | (eval-when (:compile-toplevel :load-toplevel :execute) |
95 | (defclass param-spec-class (ginstance-class) |
96 | ()) |
97 | |
98 | (defmethod validate-superclass |
99 | ((class param-spec-class) (super pcl::standard-class)) |
100 | t ;(subtypep (class-name super) 'param) |
101 | )) |
102 | |
103 | |
104 | (defbinding %param-spec-ref () pointer |
105 | (location pointer)) |
106 | |
107 | (defbinding %param-spec-unref () nil |
108 | (location pointer)) |
109 | |
110 | (defmethod reference-foreign ((class param-spec-class) location) |
111 | (declare (ignore class)) |
112 | (%param-spec-ref location)) |
113 | |
114 | (defmethod unreference-foreign ((class param-spec-class) location) |
115 | (declare (ignore class)) |
116 | (%param-spec-unref location)) |
117 | |
118 | |
119 | |
4d83a8a6 |
120 | ;; TODO: rename to param-spec |
9adccb27 |
121 | (defclass param (ginstance) |
122 | ((name |
123 | :allocation :alien |
124 | :reader param-name |
125 | :type string) |
126 | (flags |
127 | :allocation :alien |
128 | :reader param-flags |
129 | :type param-flag-type) |
130 | (value-type |
131 | :allocation :alien |
132 | :reader param-value-type |
133 | :type type-number) |
134 | (owner-type |
135 | :allocation :alien |
136 | :reader param-owner-type |
137 | :type type-number) |
138 | (nickname |
139 | :allocation :virtual |
140 | :getter "g_param_spec_get_nick" |
141 | :reader param-nickname |
9ca5565a |
142 | :type (copy-of string)) |
9adccb27 |
143 | (documentation |
144 | :allocation :virtual |
145 | :getter "g_param_spec_get_blurb" |
146 | :reader param-documentation |
9ca5565a |
147 | :type (copy-of string))) |
9adccb27 |
148 | (:metaclass param-spec-class)) |
df0b4e7d |
149 | |
150 | |
151 | (defclass param-char (param) |
152 | ((minimum |
153 | :allocation :alien |
154 | :reader param-char-minimum |
155 | :type char) |
156 | (maximum |
157 | :allocation :alien |
158 | :reader param-char-maximum |
159 | :type char) |
160 | (default-value |
161 | :allocation :alien |
162 | :reader param-char-default-value |
163 | :type char)) |
9adccb27 |
164 | (:metaclass param-spec-class)) |
df0b4e7d |
165 | |
166 | (defclass param-unsigned-char (param) |
167 | ( |
168 | ; (minimum |
169 | ; :allocation :alien |
170 | ; :reader param-unsigned-char-minimum |
171 | ; :type unsigned-char) |
172 | ; (maximum |
173 | ; :allocation :alien |
174 | ; :reader param-unsigned-char-maximum |
175 | ; :type unsigned-char) |
176 | ; (default-value |
177 | ; :allocation :alien |
178 | ; :reader param-unsigned-char-default-value |
179 | ; :type unsigned-char) |
180 | ) |
9adccb27 |
181 | (:metaclass param-spec-class) |
df0b4e7d |
182 | (:alien-name "GParamUChar")) |
183 | |
184 | (defclass param-boolean (param) |
185 | ((default-value |
186 | :allocation :alien |
187 | :reader param-boolean-default-value |
188 | :type boolean)) |
9adccb27 |
189 | (:metaclass param-spec-class)) |
df0b4e7d |
190 | |
191 | (defclass param-int (param) |
192 | ((minimum |
193 | :allocation :alien |
194 | :reader param-int-minimum |
195 | :type int) |
196 | (maximum |
197 | :allocation :alien |
198 | :reader param-int-maximum |
199 | :type int) |
200 | (default-value |
201 | :allocation :alien |
202 | :reader param-int-default-value |
203 | :type int)) |
9adccb27 |
204 | (:metaclass param-spec-class)) |
df0b4e7d |
205 | |
206 | (defclass param-unsigned-int (param) |
207 | ((minimum |
208 | :allocation :alien |
209 | :reader param-unsigned-int-minimum |
210 | :type unsigned-int) |
211 | (maximum |
212 | :allocation :alien |
213 | :reader param-unsigned-int-maximum |
214 | :type unsigned-int) |
215 | (default-value |
216 | :allocation :alien |
217 | :reader param-unsigned-int-default-value |
218 | :type unsigned-int)) |
9adccb27 |
219 | (:metaclass param-spec-class) |
df0b4e7d |
220 | (:alien-name "GParamUInt")) |
221 | |
222 | (defclass param-long (param) |
223 | ((minimum |
224 | :allocation :alien |
225 | :reader param-long-minimum |
226 | :type long) |
227 | (maximum |
228 | :allocation :alien |
229 | :reader param-long-maximum |
230 | :type long) |
231 | (default-value |
232 | :allocation :alien |
233 | :reader param-long-default-value |
234 | :type long)) |
9adccb27 |
235 | (:metaclass param-spec-class)) |
df0b4e7d |
236 | |
237 | (defclass param-unsigned-long (param) |
238 | ((minimum |
239 | :allocation :alien |
240 | :reader param-unsigned-long-minimum |
241 | :type unsigned-long) |
242 | (maximum |
243 | :allocation :alien |
244 | :reader param-unsigned-long-maximum |
245 | :type unsigned-long) |
246 | (default-value |
247 | :allocation :alien |
248 | :reader param-unsigned-long-default-value |
249 | :type unsigned-long)) |
9adccb27 |
250 | (:metaclass param-spec-class) |
df0b4e7d |
251 | (:alien-name "GParamULong")) |
252 | |
253 | (defclass param-unichar (param) |
254 | () |
9adccb27 |
255 | (:metaclass param-spec-class)) |
df0b4e7d |
256 | |
257 | (defclass param-enum (param) |
258 | ((class |
259 | :allocation :alien |
260 | :reader param-enum-class |
261 | :type pointer) |
262 | (default-value |
263 | :allocation :alien |
264 | :reader param-enum-default-value |
265 | :type long)) |
9adccb27 |
266 | (:metaclass param-spec-class)) |
df0b4e7d |
267 | |
268 | (defclass param-flags (param) |
269 | ((class |
270 | :allocation :alien |
271 | :reader param-flags-class |
272 | :type pointer) |
273 | (default-value |
274 | :allocation :alien |
275 | :reader param-flags-default-value |
276 | :type long)) |
9adccb27 |
277 | (:metaclass param-spec-class)) |
df0b4e7d |
278 | |
279 | (defclass param-single-float (param) |
280 | ((minimum |
281 | :allocation :alien |
282 | :reader param-single-float-minimum |
283 | :type single-float) |
284 | (maximum |
285 | :allocation :alien |
286 | :reader param-single-float-maximum |
287 | :type single-float) |
288 | (default-value |
289 | :allocation :alien |
290 | :reader param-single-float-default-value |
291 | :type single-float) |
292 | (epsilon |
293 | :allocation :alien |
294 | :reader param-single-float-epsilon |
295 | :type single-float)) |
9adccb27 |
296 | (:metaclass param-spec-class) |
df0b4e7d |
297 | (:alien-name "GParamFloat")) |
298 | |
299 | (defclass param-double-float (param) |
300 | ((minimum |
301 | :allocation :alien |
302 | :reader param-double-float-minimum |
303 | :type double-float) |
304 | (maximum |
305 | :allocation :alien |
306 | :reader param-double-float-maximum |
307 | :type double-float) |
308 | (default-value |
309 | :allocation :alien |
310 | :reader param-double-float-default-value |
311 | :type double-float) |
312 | (epsilon |
313 | :allocation :alien |
314 | :reader param-double-float-epsilon |
315 | :type double-float)) |
9adccb27 |
316 | (:metaclass param-spec-class) |
df0b4e7d |
317 | (:alien-name "GParamDouble")) |
318 | |
319 | (defclass param-string (param) |
320 | ((default-value |
321 | :allocation :alien |
322 | :reader param-string-default-value |
323 | :type string)) |
9adccb27 |
324 | (:metaclass param-spec-class)) |
df0b4e7d |
325 | |
326 | (defclass param-param (param) |
327 | () |
9adccb27 |
328 | (:metaclass param-spec-class)) |
df0b4e7d |
329 | |
330 | (defclass param-boxed (param) |
331 | () |
9adccb27 |
332 | (:metaclass param-spec-class)) |
df0b4e7d |
333 | |
334 | (defclass param-pointer (param) |
335 | () |
9adccb27 |
336 | (:metaclass param-spec-class)) |
df0b4e7d |
337 | |
338 | (defclass param-value-array (param) |
339 | ((element-spec |
340 | :allocation :alien |
341 | :reader param-value-array-element-spec |
342 | :type param) |
343 | (length |
344 | :allocation :alien |
345 | :reader param-value-array-length |
346 | :type unsigned-int)) |
9adccb27 |
347 | (:metaclass param-spec-class)) |
df0b4e7d |
348 | |
f784870f |
349 | ;; (defclass param-closure (param) |
350 | ;; () |
9adccb27 |
351 | ;; (:metaclass param-spec-class)) |
df0b4e7d |
352 | |
353 | (defclass param-object (param) |
354 | () |
9adccb27 |
355 | (:metaclass param-spec-class)) |