chiark / gitweb /
Exporting all symbols for raw memory access
[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
8ee9e8d5 23;; $Id: gparam.lisp,v 1.27 2008/11/04 03:22:23 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+
efc1c549 36 (max (size-of 'type-number) (type-alignment '(unsigned-byte 64))))
8ee9e8d5 37(defconstant +gvalue-flags-offset+
38 (+ +gvalue-value-offset+ (size-of '(unsigned-byte 64))))
39(defconstant +gvalue-nocopy-contents-flag+ 27)
2ca6ee06 40
6baf860c 41(defbinding (%gvalue-init "g_value_init") () nil
935a783c 42 (value gvalue)
2ca6ee06 43 (type type-number))
44
83f129a7 45(defbinding (gvalue-unset "g_value_unset") () nil
46 (value gvalue))
47
c2cc3ad7 48(defun gvalue-init (gvalue type &optional (value nil value-p) temp-p)
6baf860c 49 (%gvalue-init gvalue (find-type-number type))
50 (when value-p
c2cc3ad7 51 (funcall (writer-function type :temp temp-p) value gvalue +gvalue-value-offset+)))
83f129a7 52
13c1e78f 53(defun gvalue-new (&optional type (value nil value-p))
2ca6ee06 54 (let ((gvalue (allocate-memory +gvalue-size+)))
13c1e78f 55 (cond
56 (value-p (gvalue-init gvalue type value))
57 (type (gvalue-init gvalue type)))
2ca6ee06 58 gvalue))
59
6baf860c 60(defun gvalue-free (gvalue &optional (unset-p t))
2ca6ee06 61 (unless (null-pointer-p gvalue)
83f129a7 62 (when unset-p
63 (gvalue-unset gvalue))
2ca6ee06 64 (deallocate-memory gvalue)))
65
66(defun gvalue-type (gvalue)
111ae625 67 ;; We need to search for the for the most specific known type
68 ;; because internal types, unknown to Lisp, may be passed in GValues
69 (labels ((find-most-specific-known-type (type)
70 (or
71 (type-from-number type)
72 (let ((parent (type-parent type)))
73 (unless (zerop parent)
74 (find-most-specific-known-type parent))))))
a9679992 75 (let ((type-number (ref-type-number gvalue)))
76 (unless (zerop type-number)
77 (or
78 (find-most-specific-known-type type-number)
79 ;; This will signal an error if the type hierarchy is unknown
80 (type-from-number type-number t))))))
2ca6ee06 81
8ee9e8d5 82(let ((flags-reader nil))
83 (defun gvalue-static-p (gvalue)
84 (unless flags-reader
85 (setf flags-reader (reader-function 'unsigned-int)))
86 (prog1
87 (ldb-test (byte 1 +gvalue-nocopy-contents-flag+)
88 (funcall flags-reader gvalue +gvalue-flags-offset+))
89 (force-output))))
90
20b02512 91(defun gvalue-get (gvalue)
6baf860c 92 (funcall (reader-function (gvalue-type gvalue))
20b02512 93 gvalue +gvalue-value-offset+))
94
95(defun gvalue-peek (gvalue)
96 (funcall (reader-function (gvalue-type gvalue) :ref :peek)
97 gvalue +gvalue-value-offset+))
98
99(defun gvalue-take (gvalue)
8ee9e8d5 100 (funcall (reader-function (gvalue-type gvalue)
101 :ref (if (gvalue-static-p gvalue) :peek :get))
20b02512 102 gvalue +gvalue-value-offset+))
2ca6ee06 103
104(defun gvalue-set (gvalue value)
6baf860c 105 (funcall (writer-function (gvalue-type gvalue))
2ca6ee06 106 value gvalue +gvalue-value-offset+)
107 value)
108
d84a536c 109(defbinding (gvalue-p "g_type_check_value") () boolean
110 (location pointer))
111
87837a66 112(defmacro with-gvalue ((gvalue &optional type (value nil value-p)) &body body)
20b02512 113 `(with-memory (,gvalue +gvalue-size+)
6bd80ff0 114 ,(cond
c2cc3ad7 115 ((and type value-p) `(gvalue-init ,gvalue ,type ,value t))
6bd80ff0 116 (type `(gvalue-init ,gvalue ,type)))
117 ,@body
20b02512 118 ,(unless value-p `(gvalue-take ,gvalue))))
42ff94e7 119
935a783c 120
42ff94e7 121(deftype param-flag-type ()
122 '(flags
aebc385c 123 (:readable 1)
124 (:writable 2)
125 (:construct 4)
126 (:construct-only 8)
127 (:lax-validation 16)
128 (:private 32)))
42ff94e7 129
6baf860c 130(eval-when (:compile-toplevel :load-toplevel :execute)
131 (defclass param-spec-class (ginstance-class)
132 ())
133
20b02512 134 (defmethod shared-initialize ((class param-spec-class) names &rest initargs)
135 (declare (ignore names initargs))
136 (call-next-method)
137 (unless (slot-boundp class 'ref)
138 (setf (slot-value class 'ref) '%param-spec-ref))
139 (unless (slot-boundp class 'unref)
140 (setf (slot-value class 'unref) '%param-spec-unref)))
141
3d36c5d6 142 (defmethod validate-superclass ((class param-spec-class) (super standard-class))
6baf860c 143 t ;(subtypep (class-name super) 'param)
144))
145
146
147(defbinding %param-spec-ref () pointer
148 (location pointer))
149
150(defbinding %param-spec-unref () nil
151 (location pointer))
152
6baf860c 153
935a783c 154;; TODO: rename to param-spec
6baf860c 155(defclass param (ginstance)
156 ((name
157 :allocation :alien
158 :reader param-name
159 :type string)
160 (flags
161 :allocation :alien
162 :reader param-flags
163 :type param-flag-type)
164 (value-type
165 :allocation :alien
166 :reader param-value-type
167 :type type-number)
168 (owner-type
169 :allocation :alien
170 :reader param-owner-type
171 :type type-number)
172 (nickname
173 :allocation :virtual
174 :getter "g_param_spec_get_nick"
175 :reader param-nickname
508d13a7 176 :type (copy-of string))
6baf860c 177 (documentation
178 :allocation :virtual
179 :getter "g_param_spec_get_blurb"
180 :reader param-documentation
508d13a7 181 :type (copy-of string)))
dcb31db6 182 (:metaclass param-spec-class)
183 (:gtype "GParam"))
42ff94e7 184
185
186(defclass param-char (param)
187 ((minimum
188 :allocation :alien
20b02512 189 :reader param-minimum
42ff94e7 190 :type char)
191 (maximum
192 :allocation :alien
20b02512 193 :reader param-maximum
42ff94e7 194 :type char)
195 (default-value
196 :allocation :alien
20b02512 197 :reader param-default-value
42ff94e7 198 :type char))
dcb31db6 199 (:metaclass param-spec-class)
200 (:gtype "GParamChar"))
42ff94e7 201
202(defclass param-unsigned-char (param)
203 (
204; (minimum
205; :allocation :alien
206; :reader param-unsigned-char-minimum
207; :type unsigned-char)
208; (maximum
209; :allocation :alien
210; :reader param-unsigned-char-maximum
211; :type unsigned-char)
212; (default-value
213; :allocation :alien
214; :reader param-unsigned-char-default-value
215; :type unsigned-char)
216 )
6baf860c 217 (:metaclass param-spec-class)
dcb31db6 218 (:gtype "GParamUChar"))
42ff94e7 219
220(defclass param-boolean (param)
221 ((default-value
222 :allocation :alien
20b02512 223 :reader param-default-value
42ff94e7 224 :type boolean))
dcb31db6 225 (:metaclass param-spec-class)
226 (:gtype "GParamBoolean"))
42ff94e7 227
228(defclass param-int (param)
229 ((minimum
230 :allocation :alien
20b02512 231 :reader param-minimum
42ff94e7 232 :type int)
233 (maximum
234 :allocation :alien
20b02512 235 :reader param-maximum
42ff94e7 236 :type int)
237 (default-value
238 :allocation :alien
20b02512 239 :reader param-default-value
42ff94e7 240 :type int))
dcb31db6 241 (:metaclass param-spec-class)
242 (:gtype "GParamInt"))
42ff94e7 243
244(defclass param-unsigned-int (param)
245 ((minimum
246 :allocation :alien
20b02512 247 :reader param-minimum
42ff94e7 248 :type unsigned-int)
249 (maximum
250 :allocation :alien
20b02512 251 :reader param-maximum
42ff94e7 252 :type unsigned-int)
253 (default-value
254 :allocation :alien
20b02512 255 :reader param-default-value
42ff94e7 256 :type unsigned-int))
6baf860c 257 (:metaclass param-spec-class)
dcb31db6 258 (:gtype "GParamUInt"))
42ff94e7 259
260(defclass param-long (param)
261 ((minimum
262 :allocation :alien
20b02512 263 :reader param-minimum
42ff94e7 264 :type long)
265 (maximum
266 :allocation :alien
20b02512 267 :reader param-maximum
42ff94e7 268 :type long)
269 (default-value
270 :allocation :alien
20b02512 271 :reader param-default-value
42ff94e7 272 :type long))
dcb31db6 273 (:metaclass param-spec-class)
274 (:gtype "GParam"))
42ff94e7 275
276(defclass param-unsigned-long (param)
277 ((minimum
278 :allocation :alien
20b02512 279 :reader param-minimum
42ff94e7 280 :type unsigned-long)
281 (maximum
282 :allocation :alien
20b02512 283 :reader param-maximum
42ff94e7 284 :type unsigned-long)
285 (default-value
286 :allocation :alien
20b02512 287 :reader param-default-value
42ff94e7 288 :type unsigned-long))
6baf860c 289 (:metaclass param-spec-class)
dcb31db6 290 (:gtype "GParamULong"))
42ff94e7 291
292(defclass param-unichar (param)
293 ()
dcb31db6 294 (:metaclass param-spec-class)
295 (:gtype "GParamUnichar"))
42ff94e7 296
297(defclass param-enum (param)
298 ((class
299 :allocation :alien
300 :reader param-enum-class
301 :type pointer)
302 (default-value
303 :allocation :alien
20b02512 304 :reader param-default-value
42ff94e7 305 :type long))
dcb31db6 306 (:metaclass param-spec-class)
307 (:gtype "GParamEnum"))
42ff94e7 308
309(defclass param-flags (param)
310 ((class
311 :allocation :alien
312 :reader param-flags-class
313 :type pointer)
314 (default-value
315 :allocation :alien
20b02512 316 :reader param-default-value
42ff94e7 317 :type long))
dcb31db6 318 (:metaclass param-spec-class)
319 (:gtype "GParamFlags"))
42ff94e7 320
321(defclass param-single-float (param)
322 ((minimum
323 :allocation :alien
20b02512 324 :reader param-minimum
42ff94e7 325 :type single-float)
326 (maximum
327 :allocation :alien
20b02512 328 :reader param-maximum
42ff94e7 329 :type single-float)
330 (default-value
331 :allocation :alien
20b02512 332 :reader param-default-value
42ff94e7 333 :type single-float)
334 (epsilon
335 :allocation :alien
20b02512 336 :reader param-float-epsilon
42ff94e7 337 :type single-float))
6baf860c 338 (:metaclass param-spec-class)
dcb31db6 339 (:gtype "GParamFloat"))
42ff94e7 340
341(defclass param-double-float (param)
342 ((minimum
343 :allocation :alien
20b02512 344 :reader param-minimum
42ff94e7 345 :type double-float)
346 (maximum
347 :allocation :alien
20b02512 348 :reader param-maximum
42ff94e7 349 :type double-float)
350 (default-value
351 :allocation :alien
20b02512 352 :reader param-default-value
42ff94e7 353 :type double-float)
354 (epsilon
355 :allocation :alien
20b02512 356 :reader param-float-epsilon
42ff94e7 357 :type double-float))
6baf860c 358 (:metaclass param-spec-class)
dcb31db6 359 (:gtype "GParamDouble"))
42ff94e7 360
361(defclass param-string (param)
362 ((default-value
363 :allocation :alien
20b02512 364 :reader param-default-value
42ff94e7 365 :type string))
dcb31db6 366 (:metaclass param-spec-class)
367 (:gtype "GParamString"))
42ff94e7 368
369(defclass param-param (param)
370 ()
dcb31db6 371 (:metaclass param-spec-class)
372 (:gtype "GParamParam"))
42ff94e7 373
374(defclass param-boxed (param)
375 ()
dcb31db6 376 (:metaclass param-spec-class)
377 (:gtype "GParamBoxed"))
42ff94e7 378
379(defclass param-pointer (param)
380 ()
dcb31db6 381 (:metaclass param-spec-class)
382 (:gtype "GParamPointer"))
42ff94e7 383
384(defclass param-value-array (param)
385 ((element-spec
386 :allocation :alien
387 :reader param-value-array-element-spec
388 :type param)
389 (length
390 :allocation :alien
391 :reader param-value-array-length
392 :type unsigned-int))
dcb31db6 393 (:metaclass param-spec-class)
394 (:gtype "GParamValueArray"))
42ff94e7 395
396(defclass param-object (param)
397 ()
dcb31db6 398 (:metaclass param-spec-class)
399 (:gtype "GParamObject"))
400
401(defclass param-overrride (param)
402 ()
403 (:metaclass param-spec-class)
404 (:gtype "GParamOverride"))