1 ;; Common Lisp bindings for GTK+ v2.x
2 ;; Copyright 2000-2006 Espen S. Johnsen <espen@users.sf.net>
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:
12 ;; The above copyright notice and this permission notice shall be
13 ;; included in all copies or substantial portions of the Software.
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.
23 ;; $Id: gparam.lisp,v 1.21 2006-04-25 22:12:48 espen Exp $
27 (deftype gvalue () 'pointer)
29 (register-type 'gvalue '|g_value_get_type|)
31 (eval-when (:compile-toplevel :load-toplevel :execute)
32 (defbinding (size-of-gvalue "size_of_gvalue") () unsigned-int))
34 (defconstant +gvalue-size+ (size-of-gvalue))
35 (defconstant +gvalue-value-offset+ (size-of 'type-number))
37 (defbinding (%gvalue-init "g_value_init") () nil
41 (defbinding (gvalue-unset "g_value_unset") () nil
44 (defun gvalue-init (gvalue type &optional (value nil value-p))
45 (%gvalue-init gvalue (find-type-number type))
47 (funcall (writer-function type) value gvalue +gvalue-value-offset+)))
49 (defun gvalue-new (&optional type (value nil value-p))
50 (let ((gvalue (allocate-memory +gvalue-size+)))
52 (value-p (gvalue-init gvalue type value))
53 (type (gvalue-init gvalue type)))
56 (defun gvalue-free (gvalue &optional (unset-p t))
57 (unless (null-pointer-p gvalue)
59 (gvalue-unset gvalue))
60 (deallocate-memory gvalue)))
62 (defun gvalue-type (gvalue)
63 (type-from-number (ref-type-number gvalue)))
65 (defun gvalue-get (gvalue)
66 (funcall (reader-function (gvalue-type gvalue))
67 gvalue +gvalue-value-offset+))
69 (defun gvalue-peek (gvalue)
70 (funcall (reader-function (gvalue-type gvalue) :ref :peek)
71 gvalue +gvalue-value-offset+))
73 (defun gvalue-take (gvalue)
74 (funcall (reader-function (gvalue-type gvalue) :ref :get)
75 gvalue +gvalue-value-offset+))
77 (defun gvalue-set (gvalue value)
78 (funcall (writer-function (gvalue-type gvalue))
79 value gvalue +gvalue-value-offset+)
82 (defbinding (gvalue-p "g_type_check_value") () boolean
85 (defmacro with-gvalue ((gvalue &optional type (value nil value-p)) &body body)
86 `(with-memory (,gvalue +gvalue-size+)
88 ((and type value-p) `(gvalue-init ,gvalue ,type ,value))
89 (type `(gvalue-init ,gvalue ,type)))
91 ,(unless value-p `(gvalue-take ,gvalue))))
94 (deftype param-flag-type ()
103 (eval-when (:compile-toplevel :load-toplevel :execute)
104 (defclass param-spec-class (ginstance-class)
107 (defmethod shared-initialize ((class param-spec-class) names &rest initargs)
108 (declare (ignore names initargs))
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)))
115 (defmethod validate-superclass ((class param-spec-class) (super standard-class))
116 t ;(subtypep (class-name super) 'param)
120 (defbinding %param-spec-ref () pointer
123 (defbinding %param-spec-unref () nil
127 ;; TODO: rename to param-spec
128 (defclass param (ginstance)
136 :type param-flag-type)
139 :reader param-value-type
143 :reader param-owner-type
147 :getter "g_param_spec_get_nick"
148 :reader param-nickname
149 :type (copy-of string))
152 :getter "g_param_spec_get_blurb"
153 :reader param-documentation
154 :type (copy-of string)))
155 (:metaclass param-spec-class)
159 (defclass param-char (param)
162 :reader param-minimum
166 :reader param-maximum
170 :reader param-default-value
172 (:metaclass param-spec-class)
173 (:gtype "GParamChar"))
175 (defclass param-unsigned-char (param)
179 ; :reader param-unsigned-char-minimum
180 ; :type unsigned-char)
183 ; :reader param-unsigned-char-maximum
184 ; :type unsigned-char)
187 ; :reader param-unsigned-char-default-value
188 ; :type unsigned-char)
190 (:metaclass param-spec-class)
191 (:gtype "GParamUChar"))
193 (defclass param-boolean (param)
196 :reader param-default-value
198 (:metaclass param-spec-class)
199 (:gtype "GParamBoolean"))
201 (defclass param-int (param)
204 :reader param-minimum
208 :reader param-maximum
212 :reader param-default-value
214 (:metaclass param-spec-class)
215 (:gtype "GParamInt"))
217 (defclass param-unsigned-int (param)
220 :reader param-minimum
224 :reader param-maximum
228 :reader param-default-value
230 (:metaclass param-spec-class)
231 (:gtype "GParamUInt"))
233 (defclass param-long (param)
236 :reader param-minimum
240 :reader param-maximum
244 :reader param-default-value
246 (:metaclass param-spec-class)
249 (defclass param-unsigned-long (param)
252 :reader param-minimum
256 :reader param-maximum
260 :reader param-default-value
261 :type unsigned-long))
262 (:metaclass param-spec-class)
263 (:gtype "GParamULong"))
265 (defclass param-unichar (param)
267 (:metaclass param-spec-class)
268 (:gtype "GParamUnichar"))
270 (defclass param-enum (param)
273 :reader param-enum-class
277 :reader param-default-value
279 (:metaclass param-spec-class)
280 (:gtype "GParamEnum"))
282 (defclass param-flags (param)
285 :reader param-flags-class
289 :reader param-default-value
291 (:metaclass param-spec-class)
292 (:gtype "GParamFlags"))
294 (defclass param-single-float (param)
297 :reader param-minimum
301 :reader param-maximum
305 :reader param-default-value
309 :reader param-float-epsilon
311 (:metaclass param-spec-class)
312 (:gtype "GParamFloat"))
314 (defclass param-double-float (param)
317 :reader param-minimum
321 :reader param-maximum
325 :reader param-default-value
329 :reader param-float-epsilon
331 (:metaclass param-spec-class)
332 (:gtype "GParamDouble"))
334 (defclass param-string (param)
337 :reader param-default-value
339 (:metaclass param-spec-class)
340 (:gtype "GParamString"))
342 (defclass param-param (param)
344 (:metaclass param-spec-class)
345 (:gtype "GParamParam"))
347 (defclass param-boxed (param)
349 (:metaclass param-spec-class)
350 (:gtype "GParamBoxed"))
352 (defclass param-pointer (param)
354 (:metaclass param-spec-class)
355 (:gtype "GParamPointer"))
357 (defclass param-value-array (param)
360 :reader param-value-array-element-spec
364 :reader param-value-array-length
366 (:metaclass param-spec-class)
367 (:gtype "GParamValueArray"))
369 (defclass param-object (param)
371 (:metaclass param-spec-class)
372 (:gtype "GParamObject"))
374 (defclass param-overrride (param)
376 (:metaclass param-spec-class)
377 (:gtype "GParamOverride"))