55212af1 |
1 | ;; Common Lisp bindings for GTK+ v2.x |
2 | ;; Copyright 2000-2005 Espen S. Johnsen <espen@users.sf.net> |
2ca6ee06 |
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: |
2ca6ee06 |
11 | ;; |
55212af1 |
12 | ;; The above copyright notice and this permission notice shall be |
13 | ;; included in all copies or substantial portions of the Software. |
2ca6ee06 |
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. |
2ca6ee06 |
22 | |
6bd80ff0 |
23 | ;; $Id: gparam.lisp,v 1.20 2006/02/15 09:55:50 espen Exp $ |
2ca6ee06 |
24 | |
25 | (in-package "GLIB") |
26 | |
27 | (deftype gvalue () 'pointer) |
28 | |
dcb31db6 |
29 | (register-type 'gvalue '|g_value_get_type|) |
d84a536c |
30 | |
935a783c |
31 | (eval-when (:compile-toplevel :load-toplevel :execute) |
32 | (defbinding (size-of-gvalue "size_of_gvalue") () unsigned-int)) |
33 | |
6baf860c |
34 | ;(defconstant +gvalue-size+ (+ (size-of 'type-number) (* 2 (size-of 'double-float)))) |
935a783c |
35 | (defconstant +gvalue-size+ #.(size-of-gvalue)) |
36 | |
2ca6ee06 |
37 | (defconstant +gvalue-value-offset+ (size-of 'type-number)) |
38 | |
6baf860c |
39 | (defbinding (%gvalue-init "g_value_init") () nil |
935a783c |
40 | (value gvalue) |
2ca6ee06 |
41 | (type type-number)) |
42 | |
83f129a7 |
43 | (defbinding (gvalue-unset "g_value_unset") () nil |
44 | (value gvalue)) |
45 | |
6baf860c |
46 | (defun gvalue-init (gvalue type &optional (value nil value-p)) |
47 | (%gvalue-init gvalue (find-type-number type)) |
48 | (when value-p |
49 | (funcall (writer-function type) value gvalue +gvalue-value-offset+))) |
83f129a7 |
50 | |
13c1e78f |
51 | (defun gvalue-new (&optional type (value nil value-p)) |
2ca6ee06 |
52 | (let ((gvalue (allocate-memory +gvalue-size+))) |
13c1e78f |
53 | (cond |
54 | (value-p (gvalue-init gvalue type value)) |
55 | (type (gvalue-init gvalue type))) |
2ca6ee06 |
56 | gvalue)) |
57 | |
6baf860c |
58 | (defun gvalue-free (gvalue &optional (unset-p t)) |
2ca6ee06 |
59 | (unless (null-pointer-p gvalue) |
83f129a7 |
60 | (when unset-p |
61 | (gvalue-unset gvalue)) |
2ca6ee06 |
62 | (deallocate-memory gvalue))) |
63 | |
64 | (defun gvalue-type (gvalue) |
3d36c5d6 |
65 | (type-from-number (sap-ref-32 gvalue 0))) |
2ca6ee06 |
66 | |
0739b019 |
67 | (defun gvalue-get (gvalue &optional weak-p) |
6baf860c |
68 | (funcall (reader-function (gvalue-type gvalue)) |
0739b019 |
69 | gvalue +gvalue-value-offset+ weak-p)) |
2ca6ee06 |
70 | |
71 | (defun gvalue-set (gvalue value) |
6baf860c |
72 | (funcall (writer-function (gvalue-type gvalue)) |
2ca6ee06 |
73 | value gvalue +gvalue-value-offset+) |
74 | value) |
75 | |
d84a536c |
76 | (defbinding (gvalue-p "g_type_check_value") () boolean |
77 | (location pointer)) |
78 | |
87837a66 |
79 | (defmacro with-gvalue ((gvalue &optional type (value nil value-p)) &body body) |
6bd80ff0 |
80 | `(with-allocated-memory (,gvalue +gvalue-size+) |
81 | ,(cond |
82 | ((and type value-p) `(gvalue-init ,gvalue ,type ,value)) |
83 | (type `(gvalue-init ,gvalue ,type))) |
84 | ,@body |
85 | ,(unless value-p `(gvalue-get ,gvalue)))) |
42ff94e7 |
86 | |
935a783c |
87 | |
42ff94e7 |
88 | (deftype param-flag-type () |
89 | '(flags |
aebc385c |
90 | (:readable 1) |
91 | (:writable 2) |
92 | (:construct 4) |
93 | (:construct-only 8) |
94 | (:lax-validation 16) |
95 | (:private 32))) |
42ff94e7 |
96 | |
6baf860c |
97 | (eval-when (:compile-toplevel :load-toplevel :execute) |
98 | (defclass param-spec-class (ginstance-class) |
99 | ()) |
100 | |
3d36c5d6 |
101 | (defmethod validate-superclass ((class param-spec-class) (super standard-class)) |
6baf860c |
102 | t ;(subtypep (class-name super) 'param) |
103 | )) |
104 | |
105 | |
106 | (defbinding %param-spec-ref () pointer |
107 | (location pointer)) |
108 | |
109 | (defbinding %param-spec-unref () nil |
110 | (location pointer)) |
111 | |
112 | (defmethod reference-foreign ((class param-spec-class) location) |
113 | (declare (ignore class)) |
114 | (%param-spec-ref location)) |
115 | |
116 | (defmethod unreference-foreign ((class param-spec-class) location) |
117 | (declare (ignore class)) |
118 | (%param-spec-unref location)) |
119 | |
120 | |
121 | |
935a783c |
122 | ;; TODO: rename to param-spec |
6baf860c |
123 | (defclass param (ginstance) |
124 | ((name |
125 | :allocation :alien |
126 | :reader param-name |
127 | :type string) |
128 | (flags |
129 | :allocation :alien |
130 | :reader param-flags |
131 | :type param-flag-type) |
132 | (value-type |
133 | :allocation :alien |
134 | :reader param-value-type |
135 | :type type-number) |
136 | (owner-type |
137 | :allocation :alien |
138 | :reader param-owner-type |
139 | :type type-number) |
140 | (nickname |
141 | :allocation :virtual |
142 | :getter "g_param_spec_get_nick" |
143 | :reader param-nickname |
508d13a7 |
144 | :type (copy-of string)) |
6baf860c |
145 | (documentation |
146 | :allocation :virtual |
147 | :getter "g_param_spec_get_blurb" |
148 | :reader param-documentation |
508d13a7 |
149 | :type (copy-of string))) |
dcb31db6 |
150 | (:metaclass param-spec-class) |
151 | (:gtype "GParam")) |
42ff94e7 |
152 | |
153 | |
154 | (defclass param-char (param) |
155 | ((minimum |
156 | :allocation :alien |
157 | :reader param-char-minimum |
158 | :type char) |
159 | (maximum |
160 | :allocation :alien |
161 | :reader param-char-maximum |
162 | :type char) |
163 | (default-value |
164 | :allocation :alien |
165 | :reader param-char-default-value |
166 | :type char)) |
dcb31db6 |
167 | (:metaclass param-spec-class) |
168 | (:gtype "GParamChar")) |
42ff94e7 |
169 | |
170 | (defclass param-unsigned-char (param) |
171 | ( |
172 | ; (minimum |
173 | ; :allocation :alien |
174 | ; :reader param-unsigned-char-minimum |
175 | ; :type unsigned-char) |
176 | ; (maximum |
177 | ; :allocation :alien |
178 | ; :reader param-unsigned-char-maximum |
179 | ; :type unsigned-char) |
180 | ; (default-value |
181 | ; :allocation :alien |
182 | ; :reader param-unsigned-char-default-value |
183 | ; :type unsigned-char) |
184 | ) |
6baf860c |
185 | (:metaclass param-spec-class) |
dcb31db6 |
186 | (:gtype "GParamUChar")) |
42ff94e7 |
187 | |
188 | (defclass param-boolean (param) |
189 | ((default-value |
190 | :allocation :alien |
191 | :reader param-boolean-default-value |
192 | :type boolean)) |
dcb31db6 |
193 | (:metaclass param-spec-class) |
194 | (:gtype "GParamBoolean")) |
42ff94e7 |
195 | |
196 | (defclass param-int (param) |
197 | ((minimum |
198 | :allocation :alien |
199 | :reader param-int-minimum |
200 | :type int) |
201 | (maximum |
202 | :allocation :alien |
203 | :reader param-int-maximum |
204 | :type int) |
205 | (default-value |
206 | :allocation :alien |
207 | :reader param-int-default-value |
208 | :type int)) |
dcb31db6 |
209 | (:metaclass param-spec-class) |
210 | (:gtype "GParamInt")) |
42ff94e7 |
211 | |
212 | (defclass param-unsigned-int (param) |
213 | ((minimum |
214 | :allocation :alien |
215 | :reader param-unsigned-int-minimum |
216 | :type unsigned-int) |
217 | (maximum |
218 | :allocation :alien |
219 | :reader param-unsigned-int-maximum |
220 | :type unsigned-int) |
221 | (default-value |
222 | :allocation :alien |
223 | :reader param-unsigned-int-default-value |
224 | :type unsigned-int)) |
6baf860c |
225 | (:metaclass param-spec-class) |
dcb31db6 |
226 | (:gtype "GParamUInt")) |
42ff94e7 |
227 | |
228 | (defclass param-long (param) |
229 | ((minimum |
230 | :allocation :alien |
231 | :reader param-long-minimum |
232 | :type long) |
233 | (maximum |
234 | :allocation :alien |
235 | :reader param-long-maximum |
236 | :type long) |
237 | (default-value |
238 | :allocation :alien |
239 | :reader param-long-default-value |
240 | :type long)) |
dcb31db6 |
241 | (:metaclass param-spec-class) |
242 | (:gtype "GParam")) |
42ff94e7 |
243 | |
244 | (defclass param-unsigned-long (param) |
245 | ((minimum |
246 | :allocation :alien |
247 | :reader param-unsigned-long-minimum |
248 | :type unsigned-long) |
249 | (maximum |
250 | :allocation :alien |
251 | :reader param-unsigned-long-maximum |
252 | :type unsigned-long) |
253 | (default-value |
254 | :allocation :alien |
255 | :reader param-unsigned-long-default-value |
256 | :type unsigned-long)) |
6baf860c |
257 | (:metaclass param-spec-class) |
dcb31db6 |
258 | (:gtype "GParamULong")) |
42ff94e7 |
259 | |
260 | (defclass param-unichar (param) |
261 | () |
dcb31db6 |
262 | (:metaclass param-spec-class) |
263 | (:gtype "GParamUnichar")) |
42ff94e7 |
264 | |
265 | (defclass param-enum (param) |
266 | ((class |
267 | :allocation :alien |
268 | :reader param-enum-class |
269 | :type pointer) |
270 | (default-value |
271 | :allocation :alien |
272 | :reader param-enum-default-value |
273 | :type long)) |
dcb31db6 |
274 | (:metaclass param-spec-class) |
275 | (:gtype "GParamEnum")) |
42ff94e7 |
276 | |
277 | (defclass param-flags (param) |
278 | ((class |
279 | :allocation :alien |
280 | :reader param-flags-class |
281 | :type pointer) |
282 | (default-value |
283 | :allocation :alien |
284 | :reader param-flags-default-value |
285 | :type long)) |
dcb31db6 |
286 | (:metaclass param-spec-class) |
287 | (:gtype "GParamFlags")) |
42ff94e7 |
288 | |
289 | (defclass param-single-float (param) |
290 | ((minimum |
291 | :allocation :alien |
292 | :reader param-single-float-minimum |
293 | :type single-float) |
294 | (maximum |
295 | :allocation :alien |
296 | :reader param-single-float-maximum |
297 | :type single-float) |
298 | (default-value |
299 | :allocation :alien |
300 | :reader param-single-float-default-value |
301 | :type single-float) |
302 | (epsilon |
303 | :allocation :alien |
304 | :reader param-single-float-epsilon |
305 | :type single-float)) |
6baf860c |
306 | (:metaclass param-spec-class) |
dcb31db6 |
307 | (:gtype "GParamFloat")) |
42ff94e7 |
308 | |
309 | (defclass param-double-float (param) |
310 | ((minimum |
311 | :allocation :alien |
312 | :reader param-double-float-minimum |
313 | :type double-float) |
314 | (maximum |
315 | :allocation :alien |
316 | :reader param-double-float-maximum |
317 | :type double-float) |
318 | (default-value |
319 | :allocation :alien |
320 | :reader param-double-float-default-value |
321 | :type double-float) |
322 | (epsilon |
323 | :allocation :alien |
324 | :reader param-double-float-epsilon |
325 | :type double-float)) |
6baf860c |
326 | (:metaclass param-spec-class) |
dcb31db6 |
327 | (:gtype "GParamDouble")) |
42ff94e7 |
328 | |
329 | (defclass param-string (param) |
330 | ((default-value |
331 | :allocation :alien |
332 | :reader param-string-default-value |
333 | :type string)) |
dcb31db6 |
334 | (:metaclass param-spec-class) |
335 | (:gtype "GParamString")) |
42ff94e7 |
336 | |
337 | (defclass param-param (param) |
338 | () |
dcb31db6 |
339 | (:metaclass param-spec-class) |
340 | (:gtype "GParamParam")) |
42ff94e7 |
341 | |
342 | (defclass param-boxed (param) |
343 | () |
dcb31db6 |
344 | (:metaclass param-spec-class) |
345 | (:gtype "GParamBoxed")) |
42ff94e7 |
346 | |
347 | (defclass param-pointer (param) |
348 | () |
dcb31db6 |
349 | (:metaclass param-spec-class) |
350 | (:gtype "GParamPointer")) |
42ff94e7 |
351 | |
352 | (defclass param-value-array (param) |
353 | ((element-spec |
354 | :allocation :alien |
355 | :reader param-value-array-element-spec |
356 | :type param) |
357 | (length |
358 | :allocation :alien |
359 | :reader param-value-array-length |
360 | :type unsigned-int)) |
dcb31db6 |
361 | (:metaclass param-spec-class) |
362 | (:gtype "GParamValueArray")) |
42ff94e7 |
363 | |
364 | (defclass param-object (param) |
365 | () |
dcb31db6 |
366 | (:metaclass param-spec-class) |
367 | (:gtype "GParamObject")) |
368 | |
369 | (defclass param-overrride (param) |
370 | () |
371 | (:metaclass param-spec-class) |
372 | (:gtype "GParamOverride")) |