chiark / gitweb /
Bug fix
[clg] / glib / gparam.lisp
CommitLineData
2ca6ee06 1;; Common Lisp bindings for GTK+ v2.0
2;; Copyright (C) 2000 Espen S. Johnsen <esj@stud.cs.uit.no>
3;;
4;; This library is free software; you can redistribute it and/or
5;; modify it under the terms of the GNU Lesser General Public
6;; License as published by the Free Software Foundation; either
7;; version 2 of the License, or (at your option) any later version.
8;;
9;; This library is distributed in the hope that it will be useful,
10;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12;; Lesser General Public License for more details.
13;;
14;; You should have received a copy of the GNU Lesser General Public
15;; License along with this library; if not, write to the Free Software
16;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
87837a66 18;; $Id: gparam.lisp,v 1.14 2005/01/12 13:31:57 espen Exp $
2ca6ee06 19
20(in-package "GLIB")
21
22(deftype gvalue () 'pointer)
23
d84a536c 24(register-type 'gvalue "GValue")
25
935a783c 26(eval-when (:compile-toplevel :load-toplevel :execute)
27 (defbinding (size-of-gvalue "size_of_gvalue") () unsigned-int))
28
6baf860c 29;(defconstant +gvalue-size+ (+ (size-of 'type-number) (* 2 (size-of 'double-float))))
935a783c 30(defconstant +gvalue-size+ #.(size-of-gvalue))
31
2ca6ee06 32(defconstant +gvalue-value-offset+ (size-of 'type-number))
33
6baf860c 34(defbinding (%gvalue-init "g_value_init") () nil
935a783c 35 (value gvalue)
2ca6ee06 36 (type type-number))
37
83f129a7 38(defbinding (gvalue-unset "g_value_unset") () nil
39 (value gvalue))
40
6baf860c 41(defun gvalue-init (gvalue type &optional (value nil value-p))
42 (%gvalue-init gvalue (find-type-number type))
43 (when value-p
44 (funcall (writer-function type) value gvalue +gvalue-value-offset+)))
83f129a7 45
13c1e78f 46(defun gvalue-new (&optional type (value nil value-p))
2ca6ee06 47 (let ((gvalue (allocate-memory +gvalue-size+)))
13c1e78f 48 (cond
49 (value-p (gvalue-init gvalue type value))
50 (type (gvalue-init gvalue type)))
2ca6ee06 51 gvalue))
52
6baf860c 53(defun gvalue-free (gvalue &optional (unset-p t))
2ca6ee06 54 (unless (null-pointer-p gvalue)
83f129a7 55 (when unset-p
56 (gvalue-unset gvalue))
2ca6ee06 57 (deallocate-memory gvalue)))
58
59(defun gvalue-type (gvalue)
60 (type-from-number (system:sap-ref-32 gvalue 0)))
61
62(defun gvalue-get (gvalue)
6baf860c 63 (funcall (reader-function (gvalue-type gvalue))
2ca6ee06 64 gvalue +gvalue-value-offset+))
65
66(defun gvalue-set (gvalue value)
6baf860c 67 (funcall (writer-function (gvalue-type gvalue))
2ca6ee06 68 value gvalue +gvalue-value-offset+)
69 value)
70
d84a536c 71(defbinding (gvalue-p "g_type_check_value") () boolean
72 (location pointer))
73
87837a66 74(defmacro with-gvalue ((gvalue &optional type (value nil value-p)) &body body)
75 `(let ((,gvalue ,(cond
76 ((and type value-p) `(gvalue-new ,type ,value))
77 (type `(gvalue-new ,type))
78 (`(gvalue-new)))))
7c6da969 79 (unwind-protect
80 (progn
81 ,@body
87837a66 82 ,(unless value-p `(gvalue-get ,gvalue)))
7c6da969 83 (gvalue-free ,gvalue))))
42ff94e7 84
935a783c 85
42ff94e7 86(deftype param-flag-type ()
87 '(flags
aebc385c 88 (:readable 1)
89 (:writable 2)
90 (:construct 4)
91 (:construct-only 8)
92 (:lax-validation 16)
93 (:private 32)))
42ff94e7 94
6baf860c 95(eval-when (:compile-toplevel :load-toplevel :execute)
96 (defclass param-spec-class (ginstance-class)
97 ())
98
99 (defmethod validate-superclass
100 ((class param-spec-class) (super pcl::standard-class))
101 t ;(subtypep (class-name super) 'param)
102))
103
104
105(defbinding %param-spec-ref () pointer
106 (location pointer))
107
108(defbinding %param-spec-unref () nil
109 (location pointer))
110
111(defmethod reference-foreign ((class param-spec-class) location)
112 (declare (ignore class))
113 (%param-spec-ref location))
114
115(defmethod unreference-foreign ((class param-spec-class) location)
116 (declare (ignore class))
117 (%param-spec-unref location))
118
119
120
935a783c 121;; TODO: rename to param-spec
6baf860c 122(defclass param (ginstance)
123 ((name
124 :allocation :alien
125 :reader param-name
126 :type string)
127 (flags
128 :allocation :alien
129 :reader param-flags
130 :type param-flag-type)
131 (value-type
132 :allocation :alien
133 :reader param-value-type
134 :type type-number)
135 (owner-type
136 :allocation :alien
137 :reader param-owner-type
138 :type type-number)
139 (nickname
140 :allocation :virtual
141 :getter "g_param_spec_get_nick"
142 :reader param-nickname
508d13a7 143 :type (copy-of string))
6baf860c 144 (documentation
145 :allocation :virtual
146 :getter "g_param_spec_get_blurb"
147 :reader param-documentation
508d13a7 148 :type (copy-of string)))
6baf860c 149 (:metaclass param-spec-class))
42ff94e7 150
151
152(defclass param-char (param)
153 ((minimum
154 :allocation :alien
155 :reader param-char-minimum
156 :type char)
157 (maximum
158 :allocation :alien
159 :reader param-char-maximum
160 :type char)
161 (default-value
162 :allocation :alien
163 :reader param-char-default-value
164 :type char))
6baf860c 165 (:metaclass param-spec-class))
42ff94e7 166
167(defclass param-unsigned-char (param)
168 (
169; (minimum
170; :allocation :alien
171; :reader param-unsigned-char-minimum
172; :type unsigned-char)
173; (maximum
174; :allocation :alien
175; :reader param-unsigned-char-maximum
176; :type unsigned-char)
177; (default-value
178; :allocation :alien
179; :reader param-unsigned-char-default-value
180; :type unsigned-char)
181 )
6baf860c 182 (:metaclass param-spec-class)
42ff94e7 183 (:alien-name "GParamUChar"))
184
185(defclass param-boolean (param)
186 ((default-value
187 :allocation :alien
188 :reader param-boolean-default-value
189 :type boolean))
6baf860c 190 (:metaclass param-spec-class))
42ff94e7 191
192(defclass param-int (param)
193 ((minimum
194 :allocation :alien
195 :reader param-int-minimum
196 :type int)
197 (maximum
198 :allocation :alien
199 :reader param-int-maximum
200 :type int)
201 (default-value
202 :allocation :alien
203 :reader param-int-default-value
204 :type int))
6baf860c 205 (:metaclass param-spec-class))
42ff94e7 206
207(defclass param-unsigned-int (param)
208 ((minimum
209 :allocation :alien
210 :reader param-unsigned-int-minimum
211 :type unsigned-int)
212 (maximum
213 :allocation :alien
214 :reader param-unsigned-int-maximum
215 :type unsigned-int)
216 (default-value
217 :allocation :alien
218 :reader param-unsigned-int-default-value
219 :type unsigned-int))
6baf860c 220 (:metaclass param-spec-class)
42ff94e7 221 (:alien-name "GParamUInt"))
222
223(defclass param-long (param)
224 ((minimum
225 :allocation :alien
226 :reader param-long-minimum
227 :type long)
228 (maximum
229 :allocation :alien
230 :reader param-long-maximum
231 :type long)
232 (default-value
233 :allocation :alien
234 :reader param-long-default-value
235 :type long))
6baf860c 236 (:metaclass param-spec-class))
42ff94e7 237
238(defclass param-unsigned-long (param)
239 ((minimum
240 :allocation :alien
241 :reader param-unsigned-long-minimum
242 :type unsigned-long)
243 (maximum
244 :allocation :alien
245 :reader param-unsigned-long-maximum
246 :type unsigned-long)
247 (default-value
248 :allocation :alien
249 :reader param-unsigned-long-default-value
250 :type unsigned-long))
6baf860c 251 (:metaclass param-spec-class)
42ff94e7 252 (:alien-name "GParamULong"))
253
254(defclass param-unichar (param)
255 ()
6baf860c 256 (:metaclass param-spec-class))
42ff94e7 257
258(defclass param-enum (param)
259 ((class
260 :allocation :alien
261 :reader param-enum-class
262 :type pointer)
263 (default-value
264 :allocation :alien
265 :reader param-enum-default-value
266 :type long))
6baf860c 267 (:metaclass param-spec-class))
42ff94e7 268
269(defclass param-flags (param)
270 ((class
271 :allocation :alien
272 :reader param-flags-class
273 :type pointer)
274 (default-value
275 :allocation :alien
276 :reader param-flags-default-value
277 :type long))
6baf860c 278 (:metaclass param-spec-class))
42ff94e7 279
280(defclass param-single-float (param)
281 ((minimum
282 :allocation :alien
283 :reader param-single-float-minimum
284 :type single-float)
285 (maximum
286 :allocation :alien
287 :reader param-single-float-maximum
288 :type single-float)
289 (default-value
290 :allocation :alien
291 :reader param-single-float-default-value
292 :type single-float)
293 (epsilon
294 :allocation :alien
295 :reader param-single-float-epsilon
296 :type single-float))
6baf860c 297 (:metaclass param-spec-class)
42ff94e7 298 (:alien-name "GParamFloat"))
299
300(defclass param-double-float (param)
301 ((minimum
302 :allocation :alien
303 :reader param-double-float-minimum
304 :type double-float)
305 (maximum
306 :allocation :alien
307 :reader param-double-float-maximum
308 :type double-float)
309 (default-value
310 :allocation :alien
311 :reader param-double-float-default-value
312 :type double-float)
313 (epsilon
314 :allocation :alien
315 :reader param-double-float-epsilon
316 :type double-float))
6baf860c 317 (:metaclass param-spec-class)
42ff94e7 318 (:alien-name "GParamDouble"))
319
320(defclass param-string (param)
321 ((default-value
322 :allocation :alien
323 :reader param-string-default-value
324 :type string))
6baf860c 325 (:metaclass param-spec-class))
42ff94e7 326
327(defclass param-param (param)
328 ()
6baf860c 329 (:metaclass param-spec-class))
42ff94e7 330
331(defclass param-boxed (param)
332 ()
6baf860c 333 (:metaclass param-spec-class))
42ff94e7 334
335(defclass param-pointer (param)
336 ()
6baf860c 337 (:metaclass param-spec-class))
42ff94e7 338
339(defclass param-value-array (param)
340 ((element-spec
341 :allocation :alien
342 :reader param-value-array-element-spec
343 :type param)
344 (length
345 :allocation :alien
346 :reader param-value-array-length
347 :type unsigned-int))
6baf860c 348 (:metaclass param-spec-class))
42ff94e7 349
fe66d5f4 350;; (defclass param-closure (param)
351;; ()
6baf860c 352;; (:metaclass param-spec-class))
42ff94e7 353
354(defclass param-object (param)
355 ()
6baf860c 356 (:metaclass param-spec-class))