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.26 2007/08/20 10:50:25 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) temp-p)
46 (%gvalue-init gvalue (find-type-number type))
48 (funcall (writer-function type :temp temp-p) 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))))))
72 (let ((type-number (ref-type-number gvalue)))
73 (unless (zerop type-number)
75 (find-most-specific-known-type type-number)
76 ;; This will signal an error if the type hierarchy is unknown
77 (type-from-number type-number t))))))
79 (defun gvalue-get (gvalue)
80 (funcall (reader-function (gvalue-type gvalue))
81 gvalue +gvalue-value-offset+))
83 (defun gvalue-peek (gvalue)
84 (funcall (reader-function (gvalue-type gvalue) :ref :peek)
85 gvalue +gvalue-value-offset+))
87 (defun gvalue-take (gvalue)
88 (funcall (reader-function (gvalue-type gvalue) :ref :get)
89 gvalue +gvalue-value-offset+))
91 (defun gvalue-set (gvalue value)
92 (funcall (writer-function (gvalue-type gvalue))
93 value gvalue +gvalue-value-offset+)
96 (defbinding (gvalue-p "g_type_check_value") () boolean
99 (defmacro with-gvalue ((gvalue &optional type (value nil value-p)) &body body)
100 `(with-memory (,gvalue +gvalue-size+)
102 ((and type value-p) `(gvalue-init ,gvalue ,type ,value t))
103 (type `(gvalue-init ,gvalue ,type)))
105 ,(unless value-p `(gvalue-take ,gvalue))))
108 (deftype param-flag-type ()
117 (eval-when (:compile-toplevel :load-toplevel :execute)
118 (defclass param-spec-class (ginstance-class)
121 (defmethod shared-initialize ((class param-spec-class) names &rest initargs)
122 (declare (ignore names initargs))
124 (unless (slot-boundp class 'ref)
125 (setf (slot-value class 'ref) '%param-spec-ref))
126 (unless (slot-boundp class 'unref)
127 (setf (slot-value class 'unref) '%param-spec-unref)))
129 (defmethod validate-superclass ((class param-spec-class) (super standard-class))
130 t ;(subtypep (class-name super) 'param)
134 (defbinding %param-spec-ref () pointer
137 (defbinding %param-spec-unref () nil
141 ;; TODO: rename to param-spec
142 (defclass param (ginstance)
150 :type param-flag-type)
153 :reader param-value-type
157 :reader param-owner-type
161 :getter "g_param_spec_get_nick"
162 :reader param-nickname
163 :type (copy-of string))
166 :getter "g_param_spec_get_blurb"
167 :reader param-documentation
168 :type (copy-of string)))
169 (:metaclass param-spec-class)
173 (defclass param-char (param)
176 :reader param-minimum
180 :reader param-maximum
184 :reader param-default-value
186 (:metaclass param-spec-class)
187 (:gtype "GParamChar"))
189 (defclass param-unsigned-char (param)
193 ; :reader param-unsigned-char-minimum
194 ; :type unsigned-char)
197 ; :reader param-unsigned-char-maximum
198 ; :type unsigned-char)
201 ; :reader param-unsigned-char-default-value
202 ; :type unsigned-char)
204 (:metaclass param-spec-class)
205 (:gtype "GParamUChar"))
207 (defclass param-boolean (param)
210 :reader param-default-value
212 (:metaclass param-spec-class)
213 (:gtype "GParamBoolean"))
215 (defclass param-int (param)
218 :reader param-minimum
222 :reader param-maximum
226 :reader param-default-value
228 (:metaclass param-spec-class)
229 (:gtype "GParamInt"))
231 (defclass param-unsigned-int (param)
234 :reader param-minimum
238 :reader param-maximum
242 :reader param-default-value
244 (:metaclass param-spec-class)
245 (:gtype "GParamUInt"))
247 (defclass param-long (param)
250 :reader param-minimum
254 :reader param-maximum
258 :reader param-default-value
260 (:metaclass param-spec-class)
263 (defclass param-unsigned-long (param)
266 :reader param-minimum
270 :reader param-maximum
274 :reader param-default-value
275 :type unsigned-long))
276 (:metaclass param-spec-class)
277 (:gtype "GParamULong"))
279 (defclass param-unichar (param)
281 (:metaclass param-spec-class)
282 (:gtype "GParamUnichar"))
284 (defclass param-enum (param)
287 :reader param-enum-class
291 :reader param-default-value
293 (:metaclass param-spec-class)
294 (:gtype "GParamEnum"))
296 (defclass param-flags (param)
299 :reader param-flags-class
303 :reader param-default-value
305 (:metaclass param-spec-class)
306 (:gtype "GParamFlags"))
308 (defclass param-single-float (param)
311 :reader param-minimum
315 :reader param-maximum
319 :reader param-default-value
323 :reader param-float-epsilon
325 (:metaclass param-spec-class)
326 (:gtype "GParamFloat"))
328 (defclass param-double-float (param)
331 :reader param-minimum
335 :reader param-maximum
339 :reader param-default-value
343 :reader param-float-epsilon
345 (:metaclass param-spec-class)
346 (:gtype "GParamDouble"))
348 (defclass param-string (param)
351 :reader param-default-value
353 (:metaclass param-spec-class)
354 (:gtype "GParamString"))
356 (defclass param-param (param)
358 (:metaclass param-spec-class)
359 (:gtype "GParamParam"))
361 (defclass param-boxed (param)
363 (:metaclass param-spec-class)
364 (:gtype "GParamBoxed"))
366 (defclass param-pointer (param)
368 (:metaclass param-spec-class)
369 (:gtype "GParamPointer"))
371 (defclass param-value-array (param)
374 :reader param-value-array-element-spec
378 :reader param-value-array-length
380 (:metaclass param-spec-class)
381 (:gtype "GParamValueArray"))
383 (defclass param-object (param)
385 (:metaclass param-spec-class)
386 (:gtype "GParamObject"))
388 (defclass param-overrride (param)
390 (:metaclass param-spec-class)
391 (:gtype "GParamOverride"))