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