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