chiark / gitweb /
Changed how memory allocation/deallocation functions are specified
[clg] / glib / gparam.lisp
CommitLineData
55212af1 1;; Common Lisp bindings for GTK+ v2.x
20b02512 2;; Copyright 2000-2006 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
20b02512 23;; $Id: gparam.lisp,v 1.21 2006/04/25 22:12:48 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
20b02512 34(defconstant +gvalue-size+ (size-of-gvalue))
2ca6ee06 35(defconstant +gvalue-value-offset+ (size-of 'type-number))
36
6baf860c 37(defbinding (%gvalue-init "g_value_init") () nil
935a783c 38 (value gvalue)
2ca6ee06 39 (type type-number))
40
83f129a7 41(defbinding (gvalue-unset "g_value_unset") () nil
42 (value gvalue))
43
6baf860c 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+)))
83f129a7 48
13c1e78f 49(defun gvalue-new (&optional type (value nil value-p))
2ca6ee06 50 (let ((gvalue (allocate-memory +gvalue-size+)))
13c1e78f 51 (cond
52 (value-p (gvalue-init gvalue type value))
53 (type (gvalue-init gvalue type)))
2ca6ee06 54 gvalue))
55
6baf860c 56(defun gvalue-free (gvalue &optional (unset-p t))
2ca6ee06 57 (unless (null-pointer-p gvalue)
83f129a7 58 (when unset-p
59 (gvalue-unset gvalue))
2ca6ee06 60 (deallocate-memory gvalue)))
61
62(defun gvalue-type (gvalue)
20b02512 63 (type-from-number (ref-type-number gvalue)))
2ca6ee06 64
20b02512 65(defun gvalue-get (gvalue)
6baf860c 66 (funcall (reader-function (gvalue-type gvalue))
20b02512 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+))
2ca6ee06 76
77(defun gvalue-set (gvalue value)
6baf860c 78 (funcall (writer-function (gvalue-type gvalue))
2ca6ee06 79 value gvalue +gvalue-value-offset+)
80 value)
81
d84a536c 82(defbinding (gvalue-p "g_type_check_value") () boolean
83 (location pointer))
84
87837a66 85(defmacro with-gvalue ((gvalue &optional type (value nil value-p)) &body body)
20b02512 86 `(with-memory (,gvalue +gvalue-size+)
6bd80ff0 87 ,(cond
88 ((and type value-p) `(gvalue-init ,gvalue ,type ,value))
89 (type `(gvalue-init ,gvalue ,type)))
90 ,@body
20b02512 91 ,(unless value-p `(gvalue-take ,gvalue))))
42ff94e7 92
935a783c 93
42ff94e7 94(deftype param-flag-type ()
95 '(flags
aebc385c 96 (:readable 1)
97 (:writable 2)
98 (:construct 4)
99 (:construct-only 8)
100 (:lax-validation 16)
101 (:private 32)))
42ff94e7 102
6baf860c 103(eval-when (:compile-toplevel :load-toplevel :execute)
104 (defclass param-spec-class (ginstance-class)
105 ())
106
20b02512 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
3d36c5d6 115 (defmethod validate-superclass ((class param-spec-class) (super standard-class))
6baf860c 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
6baf860c 126
935a783c 127;; TODO: rename to param-spec
6baf860c 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
508d13a7 149 :type (copy-of string))
6baf860c 150 (documentation
151 :allocation :virtual
152 :getter "g_param_spec_get_blurb"
153 :reader param-documentation
508d13a7 154 :type (copy-of string)))
dcb31db6 155 (:metaclass param-spec-class)
156 (:gtype "GParam"))
42ff94e7 157
158
159(defclass param-char (param)
160 ((minimum
161 :allocation :alien
20b02512 162 :reader param-minimum
42ff94e7 163 :type char)
164 (maximum
165 :allocation :alien
20b02512 166 :reader param-maximum
42ff94e7 167 :type char)
168 (default-value
169 :allocation :alien
20b02512 170 :reader param-default-value
42ff94e7 171 :type char))
dcb31db6 172 (:metaclass param-spec-class)
173 (:gtype "GParamChar"))
42ff94e7 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 )
6baf860c 190 (:metaclass param-spec-class)
dcb31db6 191 (:gtype "GParamUChar"))
42ff94e7 192
193(defclass param-boolean (param)
194 ((default-value
195 :allocation :alien
20b02512 196 :reader param-default-value
42ff94e7 197 :type boolean))
dcb31db6 198 (:metaclass param-spec-class)
199 (:gtype "GParamBoolean"))
42ff94e7 200
201(defclass param-int (param)
202 ((minimum
203 :allocation :alien
20b02512 204 :reader param-minimum
42ff94e7 205 :type int)
206 (maximum
207 :allocation :alien
20b02512 208 :reader param-maximum
42ff94e7 209 :type int)
210 (default-value
211 :allocation :alien
20b02512 212 :reader param-default-value
42ff94e7 213 :type int))
dcb31db6 214 (:metaclass param-spec-class)
215 (:gtype "GParamInt"))
42ff94e7 216
217(defclass param-unsigned-int (param)
218 ((minimum
219 :allocation :alien
20b02512 220 :reader param-minimum
42ff94e7 221 :type unsigned-int)
222 (maximum
223 :allocation :alien
20b02512 224 :reader param-maximum
42ff94e7 225 :type unsigned-int)
226 (default-value
227 :allocation :alien
20b02512 228 :reader param-default-value
42ff94e7 229 :type unsigned-int))
6baf860c 230 (:metaclass param-spec-class)
dcb31db6 231 (:gtype "GParamUInt"))
42ff94e7 232
233(defclass param-long (param)
234 ((minimum
235 :allocation :alien
20b02512 236 :reader param-minimum
42ff94e7 237 :type long)
238 (maximum
239 :allocation :alien
20b02512 240 :reader param-maximum
42ff94e7 241 :type long)
242 (default-value
243 :allocation :alien
20b02512 244 :reader param-default-value
42ff94e7 245 :type long))
dcb31db6 246 (:metaclass param-spec-class)
247 (:gtype "GParam"))
42ff94e7 248
249(defclass param-unsigned-long (param)
250 ((minimum
251 :allocation :alien
20b02512 252 :reader param-minimum
42ff94e7 253 :type unsigned-long)
254 (maximum
255 :allocation :alien
20b02512 256 :reader param-maximum
42ff94e7 257 :type unsigned-long)
258 (default-value
259 :allocation :alien
20b02512 260 :reader param-default-value
42ff94e7 261 :type unsigned-long))
6baf860c 262 (:metaclass param-spec-class)
dcb31db6 263 (:gtype "GParamULong"))
42ff94e7 264
265(defclass param-unichar (param)
266 ()
dcb31db6 267 (:metaclass param-spec-class)
268 (:gtype "GParamUnichar"))
42ff94e7 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
20b02512 277 :reader param-default-value
42ff94e7 278 :type long))
dcb31db6 279 (:metaclass param-spec-class)
280 (:gtype "GParamEnum"))
42ff94e7 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
20b02512 289 :reader param-default-value
42ff94e7 290 :type long))
dcb31db6 291 (:metaclass param-spec-class)
292 (:gtype "GParamFlags"))
42ff94e7 293
294(defclass param-single-float (param)
295 ((minimum
296 :allocation :alien
20b02512 297 :reader param-minimum
42ff94e7 298 :type single-float)
299 (maximum
300 :allocation :alien
20b02512 301 :reader param-maximum
42ff94e7 302 :type single-float)
303 (default-value
304 :allocation :alien
20b02512 305 :reader param-default-value
42ff94e7 306 :type single-float)
307 (epsilon
308 :allocation :alien
20b02512 309 :reader param-float-epsilon
42ff94e7 310 :type single-float))
6baf860c 311 (:metaclass param-spec-class)
dcb31db6 312 (:gtype "GParamFloat"))
42ff94e7 313
314(defclass param-double-float (param)
315 ((minimum
316 :allocation :alien
20b02512 317 :reader param-minimum
42ff94e7 318 :type double-float)
319 (maximum
320 :allocation :alien
20b02512 321 :reader param-maximum
42ff94e7 322 :type double-float)
323 (default-value
324 :allocation :alien
20b02512 325 :reader param-default-value
42ff94e7 326 :type double-float)
327 (epsilon
328 :allocation :alien
20b02512 329 :reader param-float-epsilon
42ff94e7 330 :type double-float))
6baf860c 331 (:metaclass param-spec-class)
dcb31db6 332 (:gtype "GParamDouble"))
42ff94e7 333
334(defclass param-string (param)
335 ((default-value
336 :allocation :alien
20b02512 337 :reader param-default-value
42ff94e7 338 :type string))
dcb31db6 339 (:metaclass param-spec-class)
340 (:gtype "GParamString"))
42ff94e7 341
342(defclass param-param (param)
343 ()
dcb31db6 344 (:metaclass param-spec-class)
345 (:gtype "GParamParam"))
42ff94e7 346
347(defclass param-boxed (param)
348 ()
dcb31db6 349 (:metaclass param-spec-class)
350 (:gtype "GParamBoxed"))
42ff94e7 351
352(defclass param-pointer (param)
353 ()
dcb31db6 354 (:metaclass param-spec-class)
355 (:gtype "GParamPointer"))
42ff94e7 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))
dcb31db6 366 (:metaclass param-spec-class)
367 (:gtype "GParamValueArray"))
42ff94e7 368
369(defclass param-object (param)
370 ()
dcb31db6 371 (:metaclass param-spec-class)
372 (:gtype "GParamObject"))
373
374(defclass param-overrride (param)
375 ()
376 (:metaclass param-spec-class)
377 (:gtype "GParamOverride"))