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