chiark / gitweb /
Converted deprecated widgets option-menu and combo to combo-box and combo-box-entry
[clg] / glib / gparam.lisp
1 ;; Common Lisp bindings for GTK+ v2.0
2 ;; Copyright (C) 2000 Espen S. Johnsen <esj@stud.cs.uit.no>
3 ;;
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.
8 ;;
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.
13 ;;
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
17
18 ;; $Id: gparam.lisp,v 1.9 2004-11-06 21:39:58 espen Exp $
19
20 (in-package "GLIB")
21
22 (deftype gvalue () 'pointer)
23
24 (eval-when (:compile-toplevel :load-toplevel :execute)
25   (defbinding (size-of-gvalue "size_of_gvalue") () unsigned-int))
26
27 ;(defconstant +gvalue-size+ (+ (size-of 'type-number) (* 2 (size-of 'double-float))))
28 (defconstant +gvalue-size+ #.(size-of-gvalue))
29
30 (defconstant +gvalue-value-offset+ (size-of 'type-number))
31
32 (defbinding (%gvalue-init "g_value_init") () nil
33   (value gvalue)
34   (type type-number))
35
36 (defbinding (gvalue-unset "g_value_unset") () nil
37   (value gvalue))
38
39 (defun gvalue-init (gvalue type &optional (value nil value-p))
40   (%gvalue-init gvalue (find-type-number type))
41   (when value-p
42     (funcall (writer-function type) value gvalue +gvalue-value-offset+)))
43
44 (defun gvalue-new (type &optional (value nil value-p))
45   (let ((gvalue (allocate-memory +gvalue-size+)))
46     (if value-p
47         (gvalue-init gvalue type value)
48       (gvalue-init gvalue type))
49     gvalue))
50
51 (defun gvalue-free (gvalue &optional (unset-p t))
52   (unless (null-pointer-p gvalue)
53     (when unset-p
54       (gvalue-unset gvalue))
55     (deallocate-memory gvalue)))
56
57 (defun gvalue-type (gvalue)
58   (type-from-number (system:sap-ref-32 gvalue 0)))
59
60 (defun gvalue-get (gvalue)
61   (funcall (reader-function (gvalue-type gvalue))
62    gvalue +gvalue-value-offset+))
63
64 (defun gvalue-set (gvalue value)
65   (funcall (writer-function (gvalue-type gvalue))
66    value gvalue +gvalue-value-offset+)
67   value)
68
69
70
71 (deftype param-flag-type ()
72   '(flags
73     (:readable 1)
74     (:writable 2)
75     (:construct 4)
76     (:construct-only 8)
77     (:lax-validation 16)
78     (:private 32)))
79
80 (eval-when (:compile-toplevel :load-toplevel :execute)
81   (defclass param-spec-class (ginstance-class)
82     ())
83
84   (defmethod validate-superclass 
85       ((class param-spec-class) (super pcl::standard-class))
86     t ;(subtypep (class-name super) 'param)
87 ))
88
89
90 (defbinding %param-spec-ref () pointer
91   (location pointer))
92   
93 (defbinding %param-spec-unref () nil
94   (location pointer))
95
96 (defmethod reference-foreign ((class param-spec-class) location)
97   (declare (ignore class))
98   (%param-spec-ref location))
99
100 (defmethod unreference-foreign ((class param-spec-class) location)
101   (declare (ignore class))
102   (%param-spec-unref location))
103
104
105
106 ;; TODO: rename to param-spec
107 (defclass param (ginstance)
108   ((name
109     :allocation :alien
110     :reader param-name
111     :type string)
112    (flags
113     :allocation :alien
114     :reader param-flags
115     :type param-flag-type)
116    (value-type
117     :allocation :alien
118     :reader param-value-type
119     :type type-number)
120    (owner-type
121     :allocation :alien
122     :reader param-owner-type
123     :type type-number)
124    (nickname
125     :allocation :virtual
126     :getter "g_param_spec_get_nick"
127     :reader param-nickname
128     :type string)
129    (documentation
130     :allocation :virtual
131     :getter "g_param_spec_get_blurb"
132     :reader param-documentation
133     :type string))
134   (:metaclass param-spec-class))
135
136
137 (defclass param-char (param)
138   ((minimum
139     :allocation :alien
140     :reader param-char-minimum
141     :type char)
142    (maximum
143     :allocation :alien
144     :reader param-char-maximum
145     :type char)
146    (default-value
147     :allocation :alien
148     :reader param-char-default-value
149     :type char))
150   (:metaclass param-spec-class))
151
152 (defclass param-unsigned-char (param)
153   (
154 ; (minimum
155 ;     :allocation :alien
156 ;     :reader param-unsigned-char-minimum
157 ;     :type unsigned-char)
158 ;    (maximum
159 ;     :allocation :alien
160 ;     :reader param-unsigned-char-maximum
161 ;     :type unsigned-char)
162 ;    (default-value
163 ;     :allocation :alien
164 ;     :reader param-unsigned-char-default-value
165 ;     :type unsigned-char)
166    )
167   (:metaclass param-spec-class)
168   (:alien-name "GParamUChar"))
169
170 (defclass param-boolean (param)
171   ((default-value
172      :allocation :alien
173      :reader param-boolean-default-value
174      :type boolean))
175   (:metaclass param-spec-class))
176
177 (defclass param-int (param)
178   ((minimum
179     :allocation :alien
180     :reader param-int-minimum
181     :type int)
182    (maximum
183     :allocation :alien
184     :reader param-int-maximum
185     :type int)
186    (default-value
187     :allocation :alien
188     :reader param-int-default-value
189     :type int))
190   (:metaclass param-spec-class))
191
192 (defclass param-unsigned-int (param)
193   ((minimum
194     :allocation :alien
195     :reader param-unsigned-int-minimum
196     :type unsigned-int)
197    (maximum
198     :allocation :alien
199     :reader param-unsigned-int-maximum
200     :type unsigned-int)
201    (default-value
202     :allocation :alien
203     :reader param-unsigned-int-default-value
204     :type unsigned-int))
205   (:metaclass param-spec-class)
206   (:alien-name "GParamUInt"))
207
208 (defclass param-long (param)
209   ((minimum
210     :allocation :alien
211     :reader param-long-minimum
212     :type long)
213    (maximum
214     :allocation :alien
215     :reader param-long-maximum
216     :type long)
217    (default-value
218     :allocation :alien
219     :reader param-long-default-value
220     :type long))
221   (:metaclass param-spec-class))
222
223 (defclass param-unsigned-long (param)
224   ((minimum
225     :allocation :alien
226     :reader param-unsigned-long-minimum
227     :type unsigned-long)
228    (maximum
229     :allocation :alien
230     :reader param-unsigned-long-maximum
231     :type unsigned-long)
232    (default-value
233     :allocation :alien
234     :reader param-unsigned-long-default-value
235     :type unsigned-long))
236   (:metaclass param-spec-class)
237   (:alien-name "GParamULong"))
238
239 (defclass param-unichar (param)
240   ()
241   (:metaclass param-spec-class))
242
243 (defclass param-enum (param)
244   ((class
245     :allocation :alien
246     :reader param-enum-class
247     :type pointer)
248    (default-value
249     :allocation :alien
250     :reader param-enum-default-value
251     :type long))
252   (:metaclass param-spec-class))
253
254 (defclass param-flags (param)
255   ((class
256     :allocation :alien
257     :reader param-flags-class
258     :type pointer)
259    (default-value
260     :allocation :alien
261     :reader param-flags-default-value
262     :type long))
263   (:metaclass param-spec-class))
264
265 (defclass param-single-float (param)
266   ((minimum
267     :allocation :alien
268     :reader param-single-float-minimum
269     :type single-float)
270    (maximum
271     :allocation :alien
272     :reader param-single-float-maximum
273     :type single-float)
274    (default-value
275     :allocation :alien
276     :reader param-single-float-default-value
277     :type single-float)
278    (epsilon
279     :allocation :alien
280     :reader param-single-float-epsilon
281     :type single-float))
282   (:metaclass param-spec-class)
283   (:alien-name "GParamFloat"))
284
285 (defclass param-double-float (param)
286   ((minimum
287     :allocation :alien
288     :reader param-double-float-minimum
289     :type double-float)
290    (maximum
291     :allocation :alien
292     :reader param-double-float-maximum
293     :type double-float)
294    (default-value
295     :allocation :alien
296     :reader param-double-float-default-value
297     :type double-float)
298    (epsilon
299     :allocation :alien
300     :reader param-double-float-epsilon
301     :type double-float))
302   (:metaclass param-spec-class)
303   (:alien-name "GParamDouble"))
304
305 (defclass param-string (param)
306   ((default-value
307     :allocation :alien
308     :reader param-string-default-value
309     :type string))
310   (:metaclass param-spec-class))
311
312 (defclass param-param (param)
313   ()
314   (:metaclass param-spec-class))
315
316 (defclass param-boxed (param)
317   ()
318   (:metaclass param-spec-class))
319
320 (defclass param-pointer (param)
321   ()
322   (:metaclass param-spec-class))
323
324 (defclass param-value-array (param)
325   ((element-spec
326     :allocation :alien
327     :reader param-value-array-element-spec
328     :type param)
329    (length
330     :allocation :alien
331     :reader param-value-array-length
332     :type unsigned-int))
333   (:metaclass param-spec-class))
334
335 ;; (defclass param-closure (param)
336 ;;   ()
337 ;;   (:metaclass param-spec-class))
338
339 (defclass param-object (param)
340   ()
341   (:metaclass param-spec-class))