1 ;; Common Lisp bindings for GTK+ v2.0
2 ;; Copyright (C) 2000 Espen S. Johnsen <esj@stud.cs.uit.no>
4 ;; This library is free software; you can redistribute it and/or
5 ;; modify it under the terms of the GNU Lesser General Public
6 ;; License as published by the Free Software Foundation; either
7 ;; version 2 of the License, or (at your option) any later version.
9 ;; This library is distributed in the hope that it will be useful,
10 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;; Lesser General Public License for more details.
14 ;; You should have received a copy of the GNU Lesser General Public
15 ;; License along with this library; if not, write to the Free Software
16 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ;; $Id: gparam.lisp,v 1.14 2005-01-12 13:31:57 espen Exp $
22 (deftype gvalue () 'pointer)
24 (register-type 'gvalue "GValue")
26 (eval-when (:compile-toplevel :load-toplevel :execute)
27 (defbinding (size-of-gvalue "size_of_gvalue") () unsigned-int))
29 ;(defconstant +gvalue-size+ (+ (size-of 'type-number) (* 2 (size-of 'double-float))))
30 (defconstant +gvalue-size+ #.(size-of-gvalue))
32 (defconstant +gvalue-value-offset+ (size-of 'type-number))
34 (defbinding (%gvalue-init "g_value_init") () nil
38 (defbinding (gvalue-unset "g_value_unset") () nil
41 (defun gvalue-init (gvalue type &optional (value nil value-p))
42 (%gvalue-init gvalue (find-type-number type))
44 (funcall (writer-function type) value gvalue +gvalue-value-offset+)))
46 (defun gvalue-new (&optional type (value nil value-p))
47 (let ((gvalue (allocate-memory +gvalue-size+)))
49 (value-p (gvalue-init gvalue type value))
50 (type (gvalue-init gvalue type)))
53 (defun gvalue-free (gvalue &optional (unset-p t))
54 (unless (null-pointer-p gvalue)
56 (gvalue-unset gvalue))
57 (deallocate-memory gvalue)))
59 (defun gvalue-type (gvalue)
60 (type-from-number (system:sap-ref-32 gvalue 0)))
62 (defun gvalue-get (gvalue)
63 (funcall (reader-function (gvalue-type gvalue))
64 gvalue +gvalue-value-offset+))
66 (defun gvalue-set (gvalue value)
67 (funcall (writer-function (gvalue-type gvalue))
68 value gvalue +gvalue-value-offset+)
71 (defbinding (gvalue-p "g_type_check_value") () boolean
74 (defmacro with-gvalue ((gvalue &optional type (value nil value-p)) &body body)
75 `(let ((,gvalue ,(cond
76 ((and type value-p) `(gvalue-new ,type ,value))
77 (type `(gvalue-new ,type))
82 ,(unless value-p `(gvalue-get ,gvalue)))
83 (gvalue-free ,gvalue))))
86 (deftype param-flag-type ()
95 (eval-when (:compile-toplevel :load-toplevel :execute)
96 (defclass param-spec-class (ginstance-class)
99 (defmethod validate-superclass
100 ((class param-spec-class) (super pcl::standard-class))
101 t ;(subtypep (class-name super) 'param)
105 (defbinding %param-spec-ref () pointer
108 (defbinding %param-spec-unref () nil
111 (defmethod reference-foreign ((class param-spec-class) location)
112 (declare (ignore class))
113 (%param-spec-ref location))
115 (defmethod unreference-foreign ((class param-spec-class) location)
116 (declare (ignore class))
117 (%param-spec-unref location))
121 ;; TODO: rename to param-spec
122 (defclass param (ginstance)
130 :type param-flag-type)
133 :reader param-value-type
137 :reader param-owner-type
141 :getter "g_param_spec_get_nick"
142 :reader param-nickname
143 :type (copy-of string))
146 :getter "g_param_spec_get_blurb"
147 :reader param-documentation
148 :type (copy-of string)))
149 (:metaclass param-spec-class))
152 (defclass param-char (param)
155 :reader param-char-minimum
159 :reader param-char-maximum
163 :reader param-char-default-value
165 (:metaclass param-spec-class))
167 (defclass param-unsigned-char (param)
171 ; :reader param-unsigned-char-minimum
172 ; :type unsigned-char)
175 ; :reader param-unsigned-char-maximum
176 ; :type unsigned-char)
179 ; :reader param-unsigned-char-default-value
180 ; :type unsigned-char)
182 (:metaclass param-spec-class)
183 (:alien-name "GParamUChar"))
185 (defclass param-boolean (param)
188 :reader param-boolean-default-value
190 (:metaclass param-spec-class))
192 (defclass param-int (param)
195 :reader param-int-minimum
199 :reader param-int-maximum
203 :reader param-int-default-value
205 (:metaclass param-spec-class))
207 (defclass param-unsigned-int (param)
210 :reader param-unsigned-int-minimum
214 :reader param-unsigned-int-maximum
218 :reader param-unsigned-int-default-value
220 (:metaclass param-spec-class)
221 (:alien-name "GParamUInt"))
223 (defclass param-long (param)
226 :reader param-long-minimum
230 :reader param-long-maximum
234 :reader param-long-default-value
236 (:metaclass param-spec-class))
238 (defclass param-unsigned-long (param)
241 :reader param-unsigned-long-minimum
245 :reader param-unsigned-long-maximum
249 :reader param-unsigned-long-default-value
250 :type unsigned-long))
251 (:metaclass param-spec-class)
252 (:alien-name "GParamULong"))
254 (defclass param-unichar (param)
256 (:metaclass param-spec-class))
258 (defclass param-enum (param)
261 :reader param-enum-class
265 :reader param-enum-default-value
267 (:metaclass param-spec-class))
269 (defclass param-flags (param)
272 :reader param-flags-class
276 :reader param-flags-default-value
278 (:metaclass param-spec-class))
280 (defclass param-single-float (param)
283 :reader param-single-float-minimum
287 :reader param-single-float-maximum
291 :reader param-single-float-default-value
295 :reader param-single-float-epsilon
297 (:metaclass param-spec-class)
298 (:alien-name "GParamFloat"))
300 (defclass param-double-float (param)
303 :reader param-double-float-minimum
307 :reader param-double-float-maximum
311 :reader param-double-float-default-value
315 :reader param-double-float-epsilon
317 (:metaclass param-spec-class)
318 (:alien-name "GParamDouble"))
320 (defclass param-string (param)
323 :reader param-string-default-value
325 (:metaclass param-spec-class))
327 (defclass param-param (param)
329 (:metaclass param-spec-class))
331 (defclass param-boxed (param)
333 (:metaclass param-spec-class))
335 (defclass param-pointer (param)
337 (:metaclass param-spec-class))
339 (defclass param-value-array (param)
342 :reader param-value-array-element-spec
346 :reader param-value-array-length
348 (:metaclass param-spec-class))
350 ;; (defclass param-closure (param)
352 ;; (:metaclass param-spec-class))
354 (defclass param-object (param)
356 (:metaclass param-spec-class))