Changes required by SBCL
[clg] / glib / gparam.lisp
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
18 ;; $Id: gparam.lisp,v 1.15 2005-02-03 23:09:04 espen Exp $
19
20 (in-package "GLIB")
21
22 (deftype gvalue () 'pointer)
23
24 (register-type 'gvalue "GValue")
25
26 (eval-when (:compile-toplevel :load-toplevel :execute)
27 (defbinding (size-of-gvalue "size_of_gvalue") () unsigned-int))
28
29 ;(defconstant +gvalue-size+ (+ (size-of 'type-number) (* 2 (size-of 'double-float))))
30 (defconstant +gvalue-size+ #.(size-of-gvalue))
31
32 (defconstant +gvalue-value-offset+ (size-of 'type-number))
33
34 (defbinding (%gvalue-init "g_value_init") () nil
35 (value gvalue)
36 (type type-number))
37
38 (defbinding (gvalue-unset "g_value_unset") () nil
39 (value gvalue))
40
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+)))
45
46 (defun gvalue-new (&optional type (value nil value-p))
47 (let ((gvalue (allocate-memory +gvalue-size+)))
48 (cond
49 (value-p (gvalue-init gvalue type value))
50 (type (gvalue-init gvalue type)))
51 gvalue))
52
53 (defun gvalue-free (gvalue &optional (unset-p t))
54 (unless (null-pointer-p gvalue)
55 (when unset-p
56 (gvalue-unset gvalue))
57 (deallocate-memory gvalue)))
58
59 (defun gvalue-type (gvalue)
60 (type-from-number (sap-ref-32 gvalue 0)))
61
62 (defun gvalue-get (gvalue)
63 (funcall (reader-function (gvalue-type gvalue))
64 gvalue +gvalue-value-offset+))
65
66 (defun gvalue-set (gvalue value)
67 (funcall (writer-function (gvalue-type gvalue))
68 value gvalue +gvalue-value-offset+)
69 value)
70
71 (defbinding (gvalue-p "g_type_check_value") () boolean
72 (location pointer))
73
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)))))
79 (unwind-protect
80 (progn
81 ,@body
82 ,(unless value-p `(gvalue-get ,gvalue)))
83 (gvalue-free ,gvalue))))
84
85
86 (deftype param-flag-type ()
87 '(flags
88 (:readable 1)
89 (:writable 2)
90 (:construct 4)
91 (:construct-only 8)
92 (:lax-validation 16)
93 (:private 32)))
94
95 (eval-when (:compile-toplevel :load-toplevel :execute)
96 (defclass param-spec-class (ginstance-class)
97 ())
98
99 (defmethod validate-superclass ((class param-spec-class) (super standard-class))
100 t ;(subtypep (class-name super) 'param)
101 ))
102
103
104 (defbinding %param-spec-ref () pointer
105 (location pointer))
106
107 (defbinding %param-spec-unref () nil
108 (location pointer))
109
110 (defmethod reference-foreign ((class param-spec-class) location)
111 (declare (ignore class))
112 (%param-spec-ref location))
113
114 (defmethod unreference-foreign ((class param-spec-class) location)
115 (declare (ignore class))
116 (%param-spec-unref location))
117
118
119
120 ;; TODO: rename to param-spec
121 (defclass param (ginstance)
122 ((name
123 :allocation :alien
124 :reader param-name
125 :type string)
126 (flags
127 :allocation :alien
128 :reader param-flags
129 :type param-flag-type)
130 (value-type
131 :allocation :alien
132 :reader param-value-type
133 :type type-number)
134 (owner-type
135 :allocation :alien
136 :reader param-owner-type
137 :type type-number)
138 (nickname
139 :allocation :virtual
140 :getter "g_param_spec_get_nick"
141 :reader param-nickname
142 :type (copy-of string))
143 (documentation
144 :allocation :virtual
145 :getter "g_param_spec_get_blurb"
146 :reader param-documentation
147 :type (copy-of string)))
148 (:metaclass param-spec-class))
149
150
151 (defclass param-char (param)
152 ((minimum
153 :allocation :alien
154 :reader param-char-minimum
155 :type char)
156 (maximum
157 :allocation :alien
158 :reader param-char-maximum
159 :type char)
160 (default-value
161 :allocation :alien
162 :reader param-char-default-value
163 :type char))
164 (:metaclass param-spec-class))
165
166 (defclass param-unsigned-char (param)
167 (
168 ; (minimum
169 ; :allocation :alien
170 ; :reader param-unsigned-char-minimum
171 ; :type unsigned-char)
172 ; (maximum
173 ; :allocation :alien
174 ; :reader param-unsigned-char-maximum
175 ; :type unsigned-char)
176 ; (default-value
177 ; :allocation :alien
178 ; :reader param-unsigned-char-default-value
179 ; :type unsigned-char)
180 )
181 (:metaclass param-spec-class)
182 (:alien-name "GParamUChar"))
183
184 (defclass param-boolean (param)
185 ((default-value
186 :allocation :alien
187 :reader param-boolean-default-value
188 :type boolean))
189 (:metaclass param-spec-class))
190
191 (defclass param-int (param)
192 ((minimum
193 :allocation :alien
194 :reader param-int-minimum
195 :type int)
196 (maximum
197 :allocation :alien
198 :reader param-int-maximum
199 :type int)
200 (default-value
201 :allocation :alien
202 :reader param-int-default-value
203 :type int))
204 (:metaclass param-spec-class))
205
206 (defclass param-unsigned-int (param)
207 ((minimum
208 :allocation :alien
209 :reader param-unsigned-int-minimum
210 :type unsigned-int)
211 (maximum
212 :allocation :alien
213 :reader param-unsigned-int-maximum
214 :type unsigned-int)
215 (default-value
216 :allocation :alien
217 :reader param-unsigned-int-default-value
218 :type unsigned-int))
219 (:metaclass param-spec-class)
220 (:alien-name "GParamUInt"))
221
222 (defclass param-long (param)
223 ((minimum
224 :allocation :alien
225 :reader param-long-minimum
226 :type long)
227 (maximum
228 :allocation :alien
229 :reader param-long-maximum
230 :type long)
231 (default-value
232 :allocation :alien
233 :reader param-long-default-value
234 :type long))
235 (:metaclass param-spec-class))
236
237 (defclass param-unsigned-long (param)
238 ((minimum
239 :allocation :alien
240 :reader param-unsigned-long-minimum
241 :type unsigned-long)
242 (maximum
243 :allocation :alien
244 :reader param-unsigned-long-maximum
245 :type unsigned-long)
246 (default-value
247 :allocation :alien
248 :reader param-unsigned-long-default-value
249 :type unsigned-long))
250 (:metaclass param-spec-class)
251 (:alien-name "GParamULong"))
252
253 (defclass param-unichar (param)
254 ()
255 (:metaclass param-spec-class))
256
257 (defclass param-enum (param)
258 ((class
259 :allocation :alien
260 :reader param-enum-class
261 :type pointer)
262 (default-value
263 :allocation :alien
264 :reader param-enum-default-value
265 :type long))
266 (:metaclass param-spec-class))
267
268 (defclass param-flags (param)
269 ((class
270 :allocation :alien
271 :reader param-flags-class
272 :type pointer)
273 (default-value
274 :allocation :alien
275 :reader param-flags-default-value
276 :type long))
277 (:metaclass param-spec-class))
278
279 (defclass param-single-float (param)
280 ((minimum
281 :allocation :alien
282 :reader param-single-float-minimum
283 :type single-float)
284 (maximum
285 :allocation :alien
286 :reader param-single-float-maximum
287 :type single-float)
288 (default-value
289 :allocation :alien
290 :reader param-single-float-default-value
291 :type single-float)
292 (epsilon
293 :allocation :alien
294 :reader param-single-float-epsilon
295 :type single-float))
296 (:metaclass param-spec-class)
297 (:alien-name "GParamFloat"))
298
299 (defclass param-double-float (param)
300 ((minimum
301 :allocation :alien
302 :reader param-double-float-minimum
303 :type double-float)
304 (maximum
305 :allocation :alien
306 :reader param-double-float-maximum
307 :type double-float)
308 (default-value
309 :allocation :alien
310 :reader param-double-float-default-value
311 :type double-float)
312 (epsilon
313 :allocation :alien
314 :reader param-double-float-epsilon
315 :type double-float))
316 (:metaclass param-spec-class)
317 (:alien-name "GParamDouble"))
318
319 (defclass param-string (param)
320 ((default-value
321 :allocation :alien
322 :reader param-string-default-value
323 :type string))
324 (:metaclass param-spec-class))
325
326 (defclass param-param (param)
327 ()
328 (:metaclass param-spec-class))
329
330 (defclass param-boxed (param)
331 ()
332 (:metaclass param-spec-class))
333
334 (defclass param-pointer (param)
335 ()
336 (:metaclass param-spec-class))
337
338 (defclass param-value-array (param)
339 ((element-spec
340 :allocation :alien
341 :reader param-value-array-element-spec
342 :type param)
343 (length
344 :allocation :alien
345 :reader param-value-array-length
346 :type unsigned-int))
347 (:metaclass param-spec-class))
348
349 ;; (defclass param-closure (param)
350 ;; ()
351 ;; (:metaclass param-spec-class))
352
353 (defclass param-object (param)
354 ()
355 (:metaclass param-spec-class))