chiark / gitweb /
Proxies for non reference counted foreign objects passed as arguments to signal handl...
[clg] / glib / gparam.lisp
CommitLineData
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
ad112f20 23;; $Id: gparam.lisp,v 1.18 2006/02/06 11:56:22 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
ad112f20 67(defun gvalue-get (gvalue)
6baf860c 68 (funcall (reader-function (gvalue-type gvalue))
ad112f20 69 gvalue +gvalue-value-offset+))
70
71(defun gvalue-weak-get (gvalue)
72 (funcall (weak-reader-function (gvalue-type gvalue))
2ca6ee06 73 gvalue +gvalue-value-offset+))
74
75(defun gvalue-set (gvalue value)
6baf860c 76 (funcall (writer-function (gvalue-type gvalue))
2ca6ee06 77 value gvalue +gvalue-value-offset+)
78 value)
79
d84a536c 80(defbinding (gvalue-p "g_type_check_value") () boolean
81 (location pointer))
82
87837a66 83(defmacro with-gvalue ((gvalue &optional type (value nil value-p)) &body body)
84 `(let ((,gvalue ,(cond
85 ((and type value-p) `(gvalue-new ,type ,value))
86 (type `(gvalue-new ,type))
87 (`(gvalue-new)))))
7c6da969 88 (unwind-protect
89 (progn
90 ,@body
87837a66 91 ,(unless value-p `(gvalue-get ,gvalue)))
7c6da969 92 (gvalue-free ,gvalue))))
42ff94e7 93
935a783c 94
42ff94e7 95(deftype param-flag-type ()
96 '(flags
aebc385c 97 (:readable 1)
98 (:writable 2)
99 (:construct 4)
100 (:construct-only 8)
101 (:lax-validation 16)
102 (:private 32)))
42ff94e7 103
6baf860c 104(eval-when (:compile-toplevel :load-toplevel :execute)
105 (defclass param-spec-class (ginstance-class)
106 ())
107
3d36c5d6 108 (defmethod validate-superclass ((class param-spec-class) (super standard-class))
6baf860c 109 t ;(subtypep (class-name super) 'param)
110))
111
112
113(defbinding %param-spec-ref () pointer
114 (location pointer))
115
116(defbinding %param-spec-unref () nil
117 (location pointer))
118
119(defmethod reference-foreign ((class param-spec-class) location)
120 (declare (ignore class))
121 (%param-spec-ref location))
122
123(defmethod unreference-foreign ((class param-spec-class) location)
124 (declare (ignore class))
125 (%param-spec-unref location))
126
127
128
935a783c 129;; TODO: rename to param-spec
6baf860c 130(defclass param (ginstance)
131 ((name
132 :allocation :alien
133 :reader param-name
134 :type string)
135 (flags
136 :allocation :alien
137 :reader param-flags
138 :type param-flag-type)
139 (value-type
140 :allocation :alien
141 :reader param-value-type
142 :type type-number)
143 (owner-type
144 :allocation :alien
145 :reader param-owner-type
146 :type type-number)
147 (nickname
148 :allocation :virtual
149 :getter "g_param_spec_get_nick"
150 :reader param-nickname
508d13a7 151 :type (copy-of string))
6baf860c 152 (documentation
153 :allocation :virtual
154 :getter "g_param_spec_get_blurb"
155 :reader param-documentation
508d13a7 156 :type (copy-of string)))
dcb31db6 157 (:metaclass param-spec-class)
158 (:gtype "GParam"))
42ff94e7 159
160
161(defclass param-char (param)
162 ((minimum
163 :allocation :alien
164 :reader param-char-minimum
165 :type char)
166 (maximum
167 :allocation :alien
168 :reader param-char-maximum
169 :type char)
170 (default-value
171 :allocation :alien
172 :reader param-char-default-value
173 :type char))
dcb31db6 174 (:metaclass param-spec-class)
175 (:gtype "GParamChar"))
42ff94e7 176
177(defclass param-unsigned-char (param)
178 (
179; (minimum
180; :allocation :alien
181; :reader param-unsigned-char-minimum
182; :type unsigned-char)
183; (maximum
184; :allocation :alien
185; :reader param-unsigned-char-maximum
186; :type unsigned-char)
187; (default-value
188; :allocation :alien
189; :reader param-unsigned-char-default-value
190; :type unsigned-char)
191 )
6baf860c 192 (:metaclass param-spec-class)
dcb31db6 193 (:gtype "GParamUChar"))
42ff94e7 194
195(defclass param-boolean (param)
196 ((default-value
197 :allocation :alien
198 :reader param-boolean-default-value
199 :type boolean))
dcb31db6 200 (:metaclass param-spec-class)
201 (:gtype "GParamBoolean"))
42ff94e7 202
203(defclass param-int (param)
204 ((minimum
205 :allocation :alien
206 :reader param-int-minimum
207 :type int)
208 (maximum
209 :allocation :alien
210 :reader param-int-maximum
211 :type int)
212 (default-value
213 :allocation :alien
214 :reader param-int-default-value
215 :type int))
dcb31db6 216 (:metaclass param-spec-class)
217 (:gtype "GParamInt"))
42ff94e7 218
219(defclass param-unsigned-int (param)
220 ((minimum
221 :allocation :alien
222 :reader param-unsigned-int-minimum
223 :type unsigned-int)
224 (maximum
225 :allocation :alien
226 :reader param-unsigned-int-maximum
227 :type unsigned-int)
228 (default-value
229 :allocation :alien
230 :reader param-unsigned-int-default-value
231 :type unsigned-int))
6baf860c 232 (:metaclass param-spec-class)
dcb31db6 233 (:gtype "GParamUInt"))
42ff94e7 234
235(defclass param-long (param)
236 ((minimum
237 :allocation :alien
238 :reader param-long-minimum
239 :type long)
240 (maximum
241 :allocation :alien
242 :reader param-long-maximum
243 :type long)
244 (default-value
245 :allocation :alien
246 :reader param-long-default-value
247 :type long))
dcb31db6 248 (:metaclass param-spec-class)
249 (:gtype "GParam"))
42ff94e7 250
251(defclass param-unsigned-long (param)
252 ((minimum
253 :allocation :alien
254 :reader param-unsigned-long-minimum
255 :type unsigned-long)
256 (maximum
257 :allocation :alien
258 :reader param-unsigned-long-maximum
259 :type unsigned-long)
260 (default-value
261 :allocation :alien
262 :reader param-unsigned-long-default-value
263 :type unsigned-long))
6baf860c 264 (:metaclass param-spec-class)
dcb31db6 265 (:gtype "GParamULong"))
42ff94e7 266
267(defclass param-unichar (param)
268 ()
dcb31db6 269 (:metaclass param-spec-class)
270 (:gtype "GParamUnichar"))
42ff94e7 271
272(defclass param-enum (param)
273 ((class
274 :allocation :alien
275 :reader param-enum-class
276 :type pointer)
277 (default-value
278 :allocation :alien
279 :reader param-enum-default-value
280 :type long))
dcb31db6 281 (:metaclass param-spec-class)
282 (:gtype "GParamEnum"))
42ff94e7 283
284(defclass param-flags (param)
285 ((class
286 :allocation :alien
287 :reader param-flags-class
288 :type pointer)
289 (default-value
290 :allocation :alien
291 :reader param-flags-default-value
292 :type long))
dcb31db6 293 (:metaclass param-spec-class)
294 (:gtype "GParamFlags"))
42ff94e7 295
296(defclass param-single-float (param)
297 ((minimum
298 :allocation :alien
299 :reader param-single-float-minimum
300 :type single-float)
301 (maximum
302 :allocation :alien
303 :reader param-single-float-maximum
304 :type single-float)
305 (default-value
306 :allocation :alien
307 :reader param-single-float-default-value
308 :type single-float)
309 (epsilon
310 :allocation :alien
311 :reader param-single-float-epsilon
312 :type single-float))
6baf860c 313 (:metaclass param-spec-class)
dcb31db6 314 (:gtype "GParamFloat"))
42ff94e7 315
316(defclass param-double-float (param)
317 ((minimum
318 :allocation :alien
319 :reader param-double-float-minimum
320 :type double-float)
321 (maximum
322 :allocation :alien
323 :reader param-double-float-maximum
324 :type double-float)
325 (default-value
326 :allocation :alien
327 :reader param-double-float-default-value
328 :type double-float)
329 (epsilon
330 :allocation :alien
331 :reader param-double-float-epsilon
332 :type double-float))
6baf860c 333 (:metaclass param-spec-class)
dcb31db6 334 (:gtype "GParamDouble"))
42ff94e7 335
336(defclass param-string (param)
337 ((default-value
338 :allocation :alien
339 :reader param-string-default-value
340 :type string))
dcb31db6 341 (:metaclass param-spec-class)
342 (:gtype "GParamString"))
42ff94e7 343
344(defclass param-param (param)
345 ()
dcb31db6 346 (:metaclass param-spec-class)
347 (:gtype "GParamParam"))
42ff94e7 348
349(defclass param-boxed (param)
350 ()
dcb31db6 351 (:metaclass param-spec-class)
352 (:gtype "GParamBoxed"))
42ff94e7 353
354(defclass param-pointer (param)
355 ()
dcb31db6 356 (:metaclass param-spec-class)
357 (:gtype "GParamPointer"))
42ff94e7 358
359(defclass param-value-array (param)
360 ((element-spec
361 :allocation :alien
362 :reader param-value-array-element-spec
363 :type param)
364 (length
365 :allocation :alien
366 :reader param-value-array-length
367 :type unsigned-int))
dcb31db6 368 (:metaclass param-spec-class)
369 (:gtype "GParamValueArray"))
42ff94e7 370
371(defclass param-object (param)
372 ()
dcb31db6 373 (:metaclass param-spec-class)
374 (:gtype "GParamObject"))
375
376(defclass param-overrride (param)
377 ()
378 (:metaclass param-spec-class)
379 (:gtype "GParamOverride"))