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