chiark / gitweb /
Bug fix
[clg] / glib / gparam.lisp
CommitLineData
387230e8 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
a54e8339 18;; $Id: gparam.lisp,v 1.14 2005-01-12 13:31:57 espen Exp $
387230e8 19
20(in-package "GLIB")
21
22(deftype gvalue () 'pointer)
23
8532ba0a 24(register-type 'gvalue "GValue")
25
4d83a8a6 26(eval-when (:compile-toplevel :load-toplevel :execute)
27 (defbinding (size-of-gvalue "size_of_gvalue") () unsigned-int))
28
9adccb27 29;(defconstant +gvalue-size+ (+ (size-of 'type-number) (* 2 (size-of 'double-float))))
4d83a8a6 30(defconstant +gvalue-size+ #.(size-of-gvalue))
31
387230e8 32(defconstant +gvalue-value-offset+ (size-of 'type-number))
33
9adccb27 34(defbinding (%gvalue-init "g_value_init") () nil
4d83a8a6 35 (value gvalue)
387230e8 36 (type type-number))
37
68093e26 38(defbinding (gvalue-unset "g_value_unset") () nil
39 (value gvalue))
40
9adccb27 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+)))
68093e26 45
3c44ba6c 46(defun gvalue-new (&optional type (value nil value-p))
387230e8 47 (let ((gvalue (allocate-memory +gvalue-size+)))
3c44ba6c 48 (cond
49 (value-p (gvalue-init gvalue type value))
50 (type (gvalue-init gvalue type)))
387230e8 51 gvalue))
52
9adccb27 53(defun gvalue-free (gvalue &optional (unset-p t))
387230e8 54 (unless (null-pointer-p gvalue)
68093e26 55 (when unset-p
56 (gvalue-unset gvalue))
387230e8 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)
9adccb27 63 (funcall (reader-function (gvalue-type gvalue))
387230e8 64 gvalue +gvalue-value-offset+))
65
66(defun gvalue-set (gvalue value)
9adccb27 67 (funcall (writer-function (gvalue-type gvalue))
387230e8 68 value gvalue +gvalue-value-offset+)
69 value)
70
8532ba0a 71(defbinding (gvalue-p "g_type_check_value") () boolean
72 (location pointer))
73
a54e8339 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)))))
6243c15e 79 (unwind-protect
80 (progn
81 ,@body
a54e8339 82 ,(unless value-p `(gvalue-get ,gvalue)))
6243c15e 83 (gvalue-free ,gvalue))))
df0b4e7d 84
4d83a8a6 85
df0b4e7d 86(deftype param-flag-type ()
87 '(flags
4eb73e10 88 (:readable 1)
89 (:writable 2)
90 (:construct 4)
91 (:construct-only 8)
92 (:lax-validation 16)
93 (:private 32)))
df0b4e7d 94
9adccb27 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
4d83a8a6 121;; TODO: rename to param-spec
9adccb27 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
9ca5565a 143 :type (copy-of string))
9adccb27 144 (documentation
145 :allocation :virtual
146 :getter "g_param_spec_get_blurb"
147 :reader param-documentation
9ca5565a 148 :type (copy-of string)))
9adccb27 149 (:metaclass param-spec-class))
df0b4e7d 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))
9adccb27 165 (:metaclass param-spec-class))
df0b4e7d 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 )
9adccb27 182 (:metaclass param-spec-class)
df0b4e7d 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))
9adccb27 190 (:metaclass param-spec-class))
df0b4e7d 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))
9adccb27 205 (:metaclass param-spec-class))
df0b4e7d 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))
9adccb27 220 (:metaclass param-spec-class)
df0b4e7d 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))
9adccb27 236 (:metaclass param-spec-class))
df0b4e7d 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))
9adccb27 251 (:metaclass param-spec-class)
df0b4e7d 252 (:alien-name "GParamULong"))
253
254(defclass param-unichar (param)
255 ()
9adccb27 256 (:metaclass param-spec-class))
df0b4e7d 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))
9adccb27 267 (:metaclass param-spec-class))
df0b4e7d 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))
9adccb27 278 (:metaclass param-spec-class))
df0b4e7d 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))
9adccb27 297 (:metaclass param-spec-class)
df0b4e7d 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))
9adccb27 317 (:metaclass param-spec-class)
df0b4e7d 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))
9adccb27 325 (:metaclass param-spec-class))
df0b4e7d 326
327(defclass param-param (param)
328 ()
9adccb27 329 (:metaclass param-spec-class))
df0b4e7d 330
331(defclass param-boxed (param)
332 ()
9adccb27 333 (:metaclass param-spec-class))
df0b4e7d 334
335(defclass param-pointer (param)
336 ()
9adccb27 337 (:metaclass param-spec-class))
df0b4e7d 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))
9adccb27 348 (:metaclass param-spec-class))
df0b4e7d 349
f784870f 350;; (defclass param-closure (param)
351;; ()
9adccb27 352;; (:metaclass param-spec-class))
df0b4e7d 353
354(defclass param-object (param)
355 ()
9adccb27 356 (:metaclass param-spec-class))