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.27 2008-11-04 03:22:23 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))))
37 (defconstant +gvalue-flags-offset+
38 (+ +gvalue-value-offset+ (size-of '(unsigned-byte 64))))
39 (defconstant +gvalue-nocopy-contents-flag+ 27)
41 (defbinding (%gvalue-init "g_value_init") () nil
45 (defbinding (gvalue-unset "g_value_unset") () nil
48 (defun gvalue-init (gvalue type &optional (value nil value-p) temp-p)
49 (%gvalue-init gvalue (find-type-number type))
51 (funcall (writer-function type :temp temp-p) value gvalue +gvalue-value-offset+)))
53 (defun gvalue-new (&optional type (value nil value-p))
54 (let ((gvalue (allocate-memory +gvalue-size+)))
56 (value-p (gvalue-init gvalue type value))
57 (type (gvalue-init gvalue type)))
60 (defun gvalue-free (gvalue &optional (unset-p t))
61 (unless (null-pointer-p gvalue)
63 (gvalue-unset gvalue))
64 (deallocate-memory gvalue)))
66 (defun gvalue-type (gvalue)
67 ;; We need to search for the for the most specific known type
68 ;; because internal types, unknown to Lisp, may be passed in GValues
69 (labels ((find-most-specific-known-type (type)
71 (type-from-number type)
72 (let ((parent (type-parent type)))
73 (unless (zerop parent)
74 (find-most-specific-known-type parent))))))
75 (let ((type-number (ref-type-number gvalue)))
76 (unless (zerop type-number)
78 (find-most-specific-known-type type-number)
79 ;; This will signal an error if the type hierarchy is unknown
80 (type-from-number type-number t))))))
82 (let ((flags-reader nil))
83 (defun gvalue-static-p (gvalue)
85 (setf flags-reader (reader-function 'unsigned-int)))
87 (ldb-test (byte 1 +gvalue-nocopy-contents-flag+)
88 (funcall flags-reader gvalue +gvalue-flags-offset+))
91 (defun gvalue-get (gvalue)
92 (funcall (reader-function (gvalue-type gvalue))
93 gvalue +gvalue-value-offset+))
95 (defun gvalue-peek (gvalue)
96 (funcall (reader-function (gvalue-type gvalue) :ref :peek)
97 gvalue +gvalue-value-offset+))
99 (defun gvalue-take (gvalue)
100 (funcall (reader-function (gvalue-type gvalue)
101 :ref (if (gvalue-static-p gvalue) :peek :get))
102 gvalue +gvalue-value-offset+))
104 (defun gvalue-set (gvalue value)
105 (funcall (writer-function (gvalue-type gvalue))
106 value gvalue +gvalue-value-offset+)
109 (defbinding (gvalue-p "g_type_check_value") () boolean
112 (defmacro with-gvalue ((gvalue &optional type (value nil value-p)) &body body)
113 `(with-memory (,gvalue +gvalue-size+)
115 ((and type value-p) `(gvalue-init ,gvalue ,type ,value t))
116 (type `(gvalue-init ,gvalue ,type)))
118 ,(unless value-p `(gvalue-take ,gvalue))))
121 (deftype param-flag-type ()
130 (eval-when (:compile-toplevel :load-toplevel :execute)
131 (defclass param-spec-class (ginstance-class)
134 (defmethod shared-initialize ((class param-spec-class) names &rest initargs)
135 (declare (ignore names initargs))
137 (unless (slot-boundp class 'ref)
138 (setf (slot-value class 'ref) '%param-spec-ref))
139 (unless (slot-boundp class 'unref)
140 (setf (slot-value class 'unref) '%param-spec-unref)))
142 (defmethod validate-superclass ((class param-spec-class) (super standard-class))
143 t ;(subtypep (class-name super) 'param)
147 (defbinding %param-spec-ref () pointer
150 (defbinding %param-spec-unref () nil
154 ;; TODO: rename to param-spec
155 (defclass param (ginstance)
163 :type param-flag-type)
166 :reader param-value-type
170 :reader param-owner-type
174 :getter "g_param_spec_get_nick"
175 :reader param-nickname
176 :type (copy-of string))
179 :getter "g_param_spec_get_blurb"
180 :reader param-documentation
181 :type (copy-of string)))
182 (:metaclass param-spec-class)
186 (defclass param-char (param)
189 :reader param-minimum
193 :reader param-maximum
197 :reader param-default-value
199 (:metaclass param-spec-class)
200 (:gtype "GParamChar"))
202 (defclass param-unsigned-char (param)
206 ; :reader param-unsigned-char-minimum
207 ; :type unsigned-char)
210 ; :reader param-unsigned-char-maximum
211 ; :type unsigned-char)
214 ; :reader param-unsigned-char-default-value
215 ; :type unsigned-char)
217 (:metaclass param-spec-class)
218 (:gtype "GParamUChar"))
220 (defclass param-boolean (param)
223 :reader param-default-value
225 (:metaclass param-spec-class)
226 (:gtype "GParamBoolean"))
228 (defclass param-int (param)
231 :reader param-minimum
235 :reader param-maximum
239 :reader param-default-value
241 (:metaclass param-spec-class)
242 (:gtype "GParamInt"))
244 (defclass param-unsigned-int (param)
247 :reader param-minimum
251 :reader param-maximum
255 :reader param-default-value
257 (:metaclass param-spec-class)
258 (:gtype "GParamUInt"))
260 (defclass param-long (param)
263 :reader param-minimum
267 :reader param-maximum
271 :reader param-default-value
273 (:metaclass param-spec-class)
276 (defclass param-unsigned-long (param)
279 :reader param-minimum
283 :reader param-maximum
287 :reader param-default-value
288 :type unsigned-long))
289 (:metaclass param-spec-class)
290 (:gtype "GParamULong"))
292 (defclass param-unichar (param)
294 (:metaclass param-spec-class)
295 (:gtype "GParamUnichar"))
297 (defclass param-enum (param)
300 :reader param-enum-class
304 :reader param-default-value
306 (:metaclass param-spec-class)
307 (:gtype "GParamEnum"))
309 (defclass param-flags (param)
312 :reader param-flags-class
316 :reader param-default-value
318 (:metaclass param-spec-class)
319 (:gtype "GParamFlags"))
321 (defclass param-single-float (param)
324 :reader param-minimum
328 :reader param-maximum
332 :reader param-default-value
336 :reader param-float-epsilon
338 (:metaclass param-spec-class)
339 (:gtype "GParamFloat"))
341 (defclass param-double-float (param)
344 :reader param-minimum
348 :reader param-maximum
352 :reader param-default-value
356 :reader param-float-epsilon
358 (:metaclass param-spec-class)
359 (:gtype "GParamDouble"))
361 (defclass param-string (param)
364 :reader param-default-value
366 (:metaclass param-spec-class)
367 (:gtype "GParamString"))
369 (defclass param-param (param)
371 (:metaclass param-spec-class)
372 (:gtype "GParamParam"))
374 (defclass param-boxed (param)
376 (:metaclass param-spec-class)
377 (:gtype "GParamBoxed"))
379 (defclass param-pointer (param)
381 (:metaclass param-spec-class)
382 (:gtype "GParamPointer"))
384 (defclass param-value-array (param)
387 :reader param-value-array-element-spec
391 :reader param-value-array-length
393 (:metaclass param-spec-class)
394 (:gtype "GParamValueArray"))
396 (defclass param-object (param)
398 (:metaclass param-spec-class)
399 (:gtype "GParamObject"))
401 (defclass param-overrride (param)
403 (:metaclass param-spec-class)
404 (:gtype "GParamOverride"))