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