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