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.24 2007/06/01 06:18:59 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 '(unsigned-byte 64))))
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 ;; We need to search for the for the most specific known type
65 ;; because internal types, unknown to Lisp, may be passed in GValues
66 (labels ((find-most-specific-known-type (type)
68 (type-from-number type)
69 (let ((parent (type-parent type)))
70 (unless (zerop parent)
71 (find-most-specific-known-type parent))))))
73 (find-most-specific-known-type (ref-type-number gvalue))
74 ;; This will signal an error if the type hierarchy is unknown
75 (type-from-number (ref-type-number gvalue) t))))
77 (defun gvalue-get (gvalue)
78 (funcall (reader-function (gvalue-type gvalue))
79 gvalue +gvalue-value-offset+))
81 (defun gvalue-peek (gvalue)
82 (funcall (reader-function (gvalue-type gvalue) :ref :peek)
83 gvalue +gvalue-value-offset+))
85 (defun gvalue-take (gvalue)
86 (funcall (reader-function (gvalue-type gvalue) :ref :get)
87 gvalue +gvalue-value-offset+))
89 (defun gvalue-set (gvalue value)
90 (funcall (writer-function (gvalue-type gvalue))
91 value gvalue +gvalue-value-offset+)
94 (defbinding (gvalue-p "g_type_check_value") () boolean
97 (defmacro with-gvalue ((gvalue &optional type (value nil value-p)) &body body)
98 `(with-memory (,gvalue +gvalue-size+)
100 ((and type value-p) `(gvalue-init ,gvalue ,type ,value))
101 (type `(gvalue-init ,gvalue ,type)))
103 ,(unless value-p `(gvalue-take ,gvalue))))
106 (deftype param-flag-type ()
115 (eval-when (:compile-toplevel :load-toplevel :execute)
116 (defclass param-spec-class (ginstance-class)
119 (defmethod shared-initialize ((class param-spec-class) names &rest initargs)
120 (declare (ignore names initargs))
122 (unless (slot-boundp class 'ref)
123 (setf (slot-value class 'ref) '%param-spec-ref))
124 (unless (slot-boundp class 'unref)
125 (setf (slot-value class 'unref) '%param-spec-unref)))
127 (defmethod validate-superclass ((class param-spec-class) (super standard-class))
128 t ;(subtypep (class-name super) 'param)
132 (defbinding %param-spec-ref () pointer
135 (defbinding %param-spec-unref () nil
139 ;; TODO: rename to param-spec
140 (defclass param (ginstance)
148 :type param-flag-type)
151 :reader param-value-type
155 :reader param-owner-type
159 :getter "g_param_spec_get_nick"
160 :reader param-nickname
161 :type (copy-of string))
164 :getter "g_param_spec_get_blurb"
165 :reader param-documentation
166 :type (copy-of string)))
167 (:metaclass param-spec-class)
171 (defclass param-char (param)
174 :reader param-minimum
178 :reader param-maximum
182 :reader param-default-value
184 (:metaclass param-spec-class)
185 (:gtype "GParamChar"))
187 (defclass param-unsigned-char (param)
191 ; :reader param-unsigned-char-minimum
192 ; :type unsigned-char)
195 ; :reader param-unsigned-char-maximum
196 ; :type unsigned-char)
199 ; :reader param-unsigned-char-default-value
200 ; :type unsigned-char)
202 (:metaclass param-spec-class)
203 (:gtype "GParamUChar"))
205 (defclass param-boolean (param)
208 :reader param-default-value
210 (:metaclass param-spec-class)
211 (:gtype "GParamBoolean"))
213 (defclass param-int (param)
216 :reader param-minimum
220 :reader param-maximum
224 :reader param-default-value
226 (:metaclass param-spec-class)
227 (:gtype "GParamInt"))
229 (defclass param-unsigned-int (param)
232 :reader param-minimum
236 :reader param-maximum
240 :reader param-default-value
242 (:metaclass param-spec-class)
243 (:gtype "GParamUInt"))
245 (defclass param-long (param)
248 :reader param-minimum
252 :reader param-maximum
256 :reader param-default-value
258 (:metaclass param-spec-class)
261 (defclass param-unsigned-long (param)
264 :reader param-minimum
268 :reader param-maximum
272 :reader param-default-value
273 :type unsigned-long))
274 (:metaclass param-spec-class)
275 (:gtype "GParamULong"))
277 (defclass param-unichar (param)
279 (:metaclass param-spec-class)
280 (:gtype "GParamUnichar"))
282 (defclass param-enum (param)
285 :reader param-enum-class
289 :reader param-default-value
291 (:metaclass param-spec-class)
292 (:gtype "GParamEnum"))
294 (defclass param-flags (param)
297 :reader param-flags-class
301 :reader param-default-value
303 (:metaclass param-spec-class)
304 (:gtype "GParamFlags"))
306 (defclass param-single-float (param)
309 :reader param-minimum
313 :reader param-maximum
317 :reader param-default-value
321 :reader param-float-epsilon
323 (:metaclass param-spec-class)
324 (:gtype "GParamFloat"))
326 (defclass param-double-float (param)
329 :reader param-minimum
333 :reader param-maximum
337 :reader param-default-value
341 :reader param-float-epsilon
343 (:metaclass param-spec-class)
344 (:gtype "GParamDouble"))
346 (defclass param-string (param)
349 :reader param-default-value
351 (:metaclass param-spec-class)
352 (:gtype "GParamString"))
354 (defclass param-param (param)
356 (:metaclass param-spec-class)
357 (:gtype "GParamParam"))
359 (defclass param-boxed (param)
361 (:metaclass param-spec-class)
362 (:gtype "GParamBoxed"))
364 (defclass param-pointer (param)
366 (:metaclass param-spec-class)
367 (:gtype "GParamPointer"))
369 (defclass param-value-array (param)
372 :reader param-value-array-element-spec
376 :reader param-value-array-length
378 (:metaclass param-spec-class)
379 (:gtype "GParamValueArray"))
381 (defclass param-object (param)
383 (:metaclass param-spec-class)
384 (:gtype "GParamObject"))
386 (defclass param-overrride (param)
388 (:metaclass param-spec-class)
389 (:gtype "GParamOverride"))