chiark / gitweb /
Made toggle reference depend on glib2.8
[clg] / glib / gparam.lisp
CommitLineData
112ac1d3 1;; Common Lisp bindings for GTK+ v2.x
2;; Copyright 2000-2005 Espen S. Johnsen <espen@users.sf.net>
387230e8 3;;
112ac1d3 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:
387230e8 11;;
112ac1d3 12;; The above copyright notice and this permission notice shall be
13;; included in all copies or substantial portions of the Software.
387230e8 14;;
112ac1d3 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.
387230e8 22
112ac1d3 23;; $Id: gparam.lisp,v 1.17 2005-04-23 16:48:51 espen Exp $
387230e8 24
25(in-package "GLIB")
26
27(deftype gvalue () 'pointer)
28
dfa4f314 29(register-type 'gvalue '|g_value_get_type|)
8532ba0a 30
4d83a8a6 31(eval-when (:compile-toplevel :load-toplevel :execute)
32 (defbinding (size-of-gvalue "size_of_gvalue") () unsigned-int))
33
9adccb27 34;(defconstant +gvalue-size+ (+ (size-of 'type-number) (* 2 (size-of 'double-float))))
4d83a8a6 35(defconstant +gvalue-size+ #.(size-of-gvalue))
36
387230e8 37(defconstant +gvalue-value-offset+ (size-of 'type-number))
38
9adccb27 39(defbinding (%gvalue-init "g_value_init") () nil
4d83a8a6 40 (value gvalue)
387230e8 41 (type type-number))
42
68093e26 43(defbinding (gvalue-unset "g_value_unset") () nil
44 (value gvalue))
45
9adccb27 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+)))
68093e26 50
3c44ba6c 51(defun gvalue-new (&optional type (value nil value-p))
387230e8 52 (let ((gvalue (allocate-memory +gvalue-size+)))
3c44ba6c 53 (cond
54 (value-p (gvalue-init gvalue type value))
55 (type (gvalue-init gvalue type)))
387230e8 56 gvalue))
57
9adccb27 58(defun gvalue-free (gvalue &optional (unset-p t))
387230e8 59 (unless (null-pointer-p gvalue)
68093e26 60 (when unset-p
61 (gvalue-unset gvalue))
387230e8 62 (deallocate-memory gvalue)))
63
64(defun gvalue-type (gvalue)
73572c12 65 (type-from-number (sap-ref-32 gvalue 0)))
387230e8 66
67(defun gvalue-get (gvalue)
9adccb27 68 (funcall (reader-function (gvalue-type gvalue))
387230e8 69 gvalue +gvalue-value-offset+))
70
71(defun gvalue-set (gvalue value)
9adccb27 72 (funcall (writer-function (gvalue-type gvalue))
387230e8 73 value gvalue +gvalue-value-offset+)
74 value)
75
8532ba0a 76(defbinding (gvalue-p "g_type_check_value") () boolean
77 (location pointer))
78
a54e8339 79(defmacro with-gvalue ((gvalue &optional type (value nil value-p)) &body body)
80 `(let ((,gvalue ,(cond
81 ((and type value-p) `(gvalue-new ,type ,value))
82 (type `(gvalue-new ,type))
83 (`(gvalue-new)))))
6243c15e 84 (unwind-protect
85 (progn
86 ,@body
a54e8339 87 ,(unless value-p `(gvalue-get ,gvalue)))
6243c15e 88 (gvalue-free ,gvalue))))
df0b4e7d 89
4d83a8a6 90
df0b4e7d 91(deftype param-flag-type ()
92 '(flags
4eb73e10 93 (:readable 1)
94 (:writable 2)
95 (:construct 4)
96 (:construct-only 8)
97 (:lax-validation 16)
98 (:private 32)))
df0b4e7d 99
9adccb27 100(eval-when (:compile-toplevel :load-toplevel :execute)
101 (defclass param-spec-class (ginstance-class)
102 ())
103
73572c12 104 (defmethod validate-superclass ((class param-spec-class) (super standard-class))
9adccb27 105 t ;(subtypep (class-name super) 'param)
106))
107
108
109(defbinding %param-spec-ref () pointer
110 (location pointer))
111
112(defbinding %param-spec-unref () nil
113 (location pointer))
114
115(defmethod reference-foreign ((class param-spec-class) location)
116 (declare (ignore class))
117 (%param-spec-ref location))
118
119(defmethod unreference-foreign ((class param-spec-class) location)
120 (declare (ignore class))
121 (%param-spec-unref location))
122
123
124
4d83a8a6 125;; TODO: rename to param-spec
9adccb27 126(defclass param (ginstance)
127 ((name
128 :allocation :alien
129 :reader param-name
130 :type string)
131 (flags
132 :allocation :alien
133 :reader param-flags
134 :type param-flag-type)
135 (value-type
136 :allocation :alien
137 :reader param-value-type
138 :type type-number)
139 (owner-type
140 :allocation :alien
141 :reader param-owner-type
142 :type type-number)
143 (nickname
144 :allocation :virtual
145 :getter "g_param_spec_get_nick"
146 :reader param-nickname
9ca5565a 147 :type (copy-of string))
9adccb27 148 (documentation
149 :allocation :virtual
150 :getter "g_param_spec_get_blurb"
151 :reader param-documentation
9ca5565a 152 :type (copy-of string)))
dfa4f314 153 (:metaclass param-spec-class)
154 (:gtype "GParam"))
df0b4e7d 155
156
157(defclass param-char (param)
158 ((minimum
159 :allocation :alien
160 :reader param-char-minimum
161 :type char)
162 (maximum
163 :allocation :alien
164 :reader param-char-maximum
165 :type char)
166 (default-value
167 :allocation :alien
168 :reader param-char-default-value
169 :type char))
dfa4f314 170 (:metaclass param-spec-class)
171 (:gtype "GParamChar"))
df0b4e7d 172
173(defclass param-unsigned-char (param)
174 (
175; (minimum
176; :allocation :alien
177; :reader param-unsigned-char-minimum
178; :type unsigned-char)
179; (maximum
180; :allocation :alien
181; :reader param-unsigned-char-maximum
182; :type unsigned-char)
183; (default-value
184; :allocation :alien
185; :reader param-unsigned-char-default-value
186; :type unsigned-char)
187 )
9adccb27 188 (:metaclass param-spec-class)
dfa4f314 189 (:gtype "GParamUChar"))
df0b4e7d 190
191(defclass param-boolean (param)
192 ((default-value
193 :allocation :alien
194 :reader param-boolean-default-value
195 :type boolean))
dfa4f314 196 (:metaclass param-spec-class)
197 (:gtype "GParamBoolean"))
df0b4e7d 198
199(defclass param-int (param)
200 ((minimum
201 :allocation :alien
202 :reader param-int-minimum
203 :type int)
204 (maximum
205 :allocation :alien
206 :reader param-int-maximum
207 :type int)
208 (default-value
209 :allocation :alien
210 :reader param-int-default-value
211 :type int))
dfa4f314 212 (:metaclass param-spec-class)
213 (:gtype "GParamInt"))
df0b4e7d 214
215(defclass param-unsigned-int (param)
216 ((minimum
217 :allocation :alien
218 :reader param-unsigned-int-minimum
219 :type unsigned-int)
220 (maximum
221 :allocation :alien
222 :reader param-unsigned-int-maximum
223 :type unsigned-int)
224 (default-value
225 :allocation :alien
226 :reader param-unsigned-int-default-value
227 :type unsigned-int))
9adccb27 228 (:metaclass param-spec-class)
dfa4f314 229 (:gtype "GParamUInt"))
df0b4e7d 230
231(defclass param-long (param)
232 ((minimum
233 :allocation :alien
234 :reader param-long-minimum
235 :type long)
236 (maximum
237 :allocation :alien
238 :reader param-long-maximum
239 :type long)
240 (default-value
241 :allocation :alien
242 :reader param-long-default-value
243 :type long))
dfa4f314 244 (:metaclass param-spec-class)
245 (:gtype "GParam"))
df0b4e7d 246
247(defclass param-unsigned-long (param)
248 ((minimum
249 :allocation :alien
250 :reader param-unsigned-long-minimum
251 :type unsigned-long)
252 (maximum
253 :allocation :alien
254 :reader param-unsigned-long-maximum
255 :type unsigned-long)
256 (default-value
257 :allocation :alien
258 :reader param-unsigned-long-default-value
259 :type unsigned-long))
9adccb27 260 (:metaclass param-spec-class)
dfa4f314 261 (:gtype "GParamULong"))
df0b4e7d 262
263(defclass param-unichar (param)
264 ()
dfa4f314 265 (:metaclass param-spec-class)
266 (:gtype "GParamUnichar"))
df0b4e7d 267
268(defclass param-enum (param)
269 ((class
270 :allocation :alien
271 :reader param-enum-class
272 :type pointer)
273 (default-value
274 :allocation :alien
275 :reader param-enum-default-value
276 :type long))
dfa4f314 277 (:metaclass param-spec-class)
278 (:gtype "GParamEnum"))
df0b4e7d 279
280(defclass param-flags (param)
281 ((class
282 :allocation :alien
283 :reader param-flags-class
284 :type pointer)
285 (default-value
286 :allocation :alien
287 :reader param-flags-default-value
288 :type long))
dfa4f314 289 (:metaclass param-spec-class)
290 (:gtype "GParamFlags"))
df0b4e7d 291
292(defclass param-single-float (param)
293 ((minimum
294 :allocation :alien
295 :reader param-single-float-minimum
296 :type single-float)
297 (maximum
298 :allocation :alien
299 :reader param-single-float-maximum
300 :type single-float)
301 (default-value
302 :allocation :alien
303 :reader param-single-float-default-value
304 :type single-float)
305 (epsilon
306 :allocation :alien
307 :reader param-single-float-epsilon
308 :type single-float))
9adccb27 309 (:metaclass param-spec-class)
dfa4f314 310 (:gtype "GParamFloat"))
df0b4e7d 311
312(defclass param-double-float (param)
313 ((minimum
314 :allocation :alien
315 :reader param-double-float-minimum
316 :type double-float)
317 (maximum
318 :allocation :alien
319 :reader param-double-float-maximum
320 :type double-float)
321 (default-value
322 :allocation :alien
323 :reader param-double-float-default-value
324 :type double-float)
325 (epsilon
326 :allocation :alien
327 :reader param-double-float-epsilon
328 :type double-float))
9adccb27 329 (:metaclass param-spec-class)
dfa4f314 330 (:gtype "GParamDouble"))
df0b4e7d 331
332(defclass param-string (param)
333 ((default-value
334 :allocation :alien
335 :reader param-string-default-value
336 :type string))
dfa4f314 337 (:metaclass param-spec-class)
338 (:gtype "GParamString"))
df0b4e7d 339
340(defclass param-param (param)
341 ()
dfa4f314 342 (:metaclass param-spec-class)
343 (:gtype "GParamParam"))
df0b4e7d 344
345(defclass param-boxed (param)
346 ()
dfa4f314 347 (:metaclass param-spec-class)
348 (:gtype "GParamBoxed"))
df0b4e7d 349
350(defclass param-pointer (param)
351 ()
dfa4f314 352 (:metaclass param-spec-class)
353 (:gtype "GParamPointer"))
df0b4e7d 354
355(defclass param-value-array (param)
356 ((element-spec
357 :allocation :alien
358 :reader param-value-array-element-spec
359 :type param)
360 (length
361 :allocation :alien
362 :reader param-value-array-length
363 :type unsigned-int))
dfa4f314 364 (:metaclass param-spec-class)
365 (:gtype "GParamValueArray"))
df0b4e7d 366
367(defclass param-object (param)
368 ()
dfa4f314 369 (:metaclass param-spec-class)
370 (:gtype "GParamObject"))
371
372(defclass param-overrride (param)
373 ()
374 (:metaclass param-spec-class)
375 (:gtype "GParamOverride"))