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.22 2007-02-23 12:50:54 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+
36 (max (size-of 'type-number) (type-alignment 'type-number)))
38 (defbinding (%gvalue-init "g_value_init") () nil
42 (defbinding (gvalue-unset "g_value_unset") () nil
45 (defun gvalue-init (gvalue type &optional (value nil value-p))
46 (%gvalue-init gvalue (find-type-number type))
48 (funcall (writer-function type) value gvalue +gvalue-value-offset+)))
50 (defun gvalue-new (&optional type (value nil value-p))
51 (let ((gvalue (allocate-memory +gvalue-size+)))
53 (value-p (gvalue-init gvalue type value))
54 (type (gvalue-init gvalue type)))
57 (defun gvalue-free (gvalue &optional (unset-p t))
58 (unless (null-pointer-p gvalue)
60 (gvalue-unset gvalue))
61 (deallocate-memory gvalue)))
63 (defun gvalue-type (gvalue)
64 (type-from-number (ref-type-number gvalue)))
66 (defun gvalue-get (gvalue)
67 (funcall (reader-function (gvalue-type gvalue))
68 gvalue +gvalue-value-offset+))
70 (defun gvalue-peek (gvalue)
71 (funcall (reader-function (gvalue-type gvalue) :ref :peek)
72 gvalue +gvalue-value-offset+))
74 (defun gvalue-take (gvalue)
75 (funcall (reader-function (gvalue-type gvalue) :ref :get)
76 gvalue +gvalue-value-offset+))
78 (defun gvalue-set (gvalue value)
79 (funcall (writer-function (gvalue-type gvalue))
80 value gvalue +gvalue-value-offset+)
83 (defbinding (gvalue-p "g_type_check_value") () boolean
86 (defmacro with-gvalue ((gvalue &optional type (value nil value-p)) &body body)
87 `(with-memory (,gvalue +gvalue-size+)
89 ((and type value-p) `(gvalue-init ,gvalue ,type ,value))
90 (type `(gvalue-init ,gvalue ,type)))
92 ,(unless value-p `(gvalue-take ,gvalue))))
95 (deftype param-flag-type ()
104 (eval-when (:compile-toplevel :load-toplevel :execute)
105 (defclass param-spec-class (ginstance-class)
108 (defmethod shared-initialize ((class param-spec-class) names &rest initargs)
109 (declare (ignore names initargs))
111 (unless (slot-boundp class 'ref)
112 (setf (slot-value class 'ref) '%param-spec-ref))
113 (unless (slot-boundp class 'unref)
114 (setf (slot-value class 'unref) '%param-spec-unref)))
116 (defmethod validate-superclass ((class param-spec-class) (super standard-class))
117 t ;(subtypep (class-name super) 'param)
121 (defbinding %param-spec-ref () pointer
124 (defbinding %param-spec-unref () nil
128 ;; TODO: rename to param-spec
129 (defclass param (ginstance)
137 :type param-flag-type)
140 :reader param-value-type
144 :reader param-owner-type
148 :getter "g_param_spec_get_nick"
149 :reader param-nickname
150 :type (copy-of string))
153 :getter "g_param_spec_get_blurb"
154 :reader param-documentation
155 :type (copy-of string)))
156 (:metaclass param-spec-class)
160 (defclass param-char (param)
163 :reader param-minimum
167 :reader param-maximum
171 :reader param-default-value
173 (:metaclass param-spec-class)
174 (:gtype "GParamChar"))
176 (defclass param-unsigned-char (param)
180 ; :reader param-unsigned-char-minimum
181 ; :type unsigned-char)
184 ; :reader param-unsigned-char-maximum
185 ; :type unsigned-char)
188 ; :reader param-unsigned-char-default-value
189 ; :type unsigned-char)
191 (:metaclass param-spec-class)
192 (:gtype "GParamUChar"))
194 (defclass param-boolean (param)
197 :reader param-default-value
199 (:metaclass param-spec-class)
200 (:gtype "GParamBoolean"))
202 (defclass param-int (param)
205 :reader param-minimum
209 :reader param-maximum
213 :reader param-default-value
215 (:metaclass param-spec-class)
216 (:gtype "GParamInt"))
218 (defclass param-unsigned-int (param)
221 :reader param-minimum
225 :reader param-maximum
229 :reader param-default-value
231 (:metaclass param-spec-class)
232 (:gtype "GParamUInt"))
234 (defclass param-long (param)
237 :reader param-minimum
241 :reader param-maximum
245 :reader param-default-value
247 (:metaclass param-spec-class)
250 (defclass param-unsigned-long (param)
253 :reader param-minimum
257 :reader param-maximum
261 :reader param-default-value
262 :type unsigned-long))
263 (:metaclass param-spec-class)
264 (:gtype "GParamULong"))
266 (defclass param-unichar (param)
268 (:metaclass param-spec-class)
269 (:gtype "GParamUnichar"))
271 (defclass param-enum (param)
274 :reader param-enum-class
278 :reader param-default-value
280 (:metaclass param-spec-class)
281 (:gtype "GParamEnum"))
283 (defclass param-flags (param)
286 :reader param-flags-class
290 :reader param-default-value
292 (:metaclass param-spec-class)
293 (:gtype "GParamFlags"))
295 (defclass param-single-float (param)
298 :reader param-minimum
302 :reader param-maximum
306 :reader param-default-value
310 :reader param-float-epsilon
312 (:metaclass param-spec-class)
313 (:gtype "GParamFloat"))
315 (defclass param-double-float (param)
318 :reader param-minimum
322 :reader param-maximum
326 :reader param-default-value
330 :reader param-float-epsilon
332 (:metaclass param-spec-class)
333 (:gtype "GParamDouble"))
335 (defclass param-string (param)
338 :reader param-default-value
340 (:metaclass param-spec-class)
341 (:gtype "GParamString"))
343 (defclass param-param (param)
345 (:metaclass param-spec-class)
346 (:gtype "GParamParam"))
348 (defclass param-boxed (param)
350 (:metaclass param-spec-class)
351 (:gtype "GParamBoxed"))
353 (defclass param-pointer (param)
355 (:metaclass param-spec-class)
356 (:gtype "GParamPointer"))
358 (defclass param-value-array (param)
361 :reader param-value-array-element-spec
365 :reader param-value-array-length
367 (:metaclass param-spec-class)
368 (:gtype "GParamValueArray"))
370 (defclass param-object (param)
372 (:metaclass param-spec-class)
373 (:gtype "GParamObject"))
375 (defclass param-overrride (param)
377 (:metaclass param-spec-class)
378 (:gtype "GParamOverride"))