chiark / gitweb /
Changes to initialization/event handling
[clg] / glib / gparam.lisp
CommitLineData
112ac1d3 1;; Common Lisp bindings for GTK+ v2.x
fa30048e 2;; Copyright 2000-2006 Espen S. Johnsen <espen@users.sf.net>
387230e8 3;;
112ac1d3 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:
387230e8 11;;
112ac1d3 12;; The above copyright notice and this permission notice shall be
13;; included in all copies or substantial portions of the Software.
387230e8 14;;
112ac1d3 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.
387230e8 22
110bd96c 23;; $Id: gparam.lisp,v 1.24 2007-06-01 06:18:59 espen Exp $
387230e8 24
25(in-package "GLIB")
26
27(deftype gvalue () 'pointer)
28
dfa4f314 29(register-type 'gvalue '|g_value_get_type|)
8532ba0a 30
4d83a8a6 31(eval-when (:compile-toplevel :load-toplevel :execute)
32 (defbinding (size-of-gvalue "size_of_gvalue") () unsigned-int))
33
fa30048e 34(defconstant +gvalue-size+ (size-of-gvalue))
60e767f4 35(defconstant +gvalue-value-offset+
110bd96c 36 (max (size-of 'type-number) (type-alignment '(unsigned-byte 64))))
387230e8 37
9adccb27 38(defbinding (%gvalue-init "g_value_init") () nil
4d83a8a6 39 (value gvalue)
387230e8 40 (type type-number))
41
68093e26 42(defbinding (gvalue-unset "g_value_unset") () nil
43 (value gvalue))
44
9adccb27 45(defun gvalue-init (gvalue type &optional (value nil value-p))
46 (%gvalue-init gvalue (find-type-number type))
47 (when value-p
48 (funcall (writer-function type) value gvalue +gvalue-value-offset+)))
68093e26 49
3c44ba6c 50(defun gvalue-new (&optional type (value nil value-p))
387230e8 51 (let ((gvalue (allocate-memory +gvalue-size+)))
3c44ba6c 52 (cond
53 (value-p (gvalue-init gvalue type value))
54 (type (gvalue-init gvalue type)))
387230e8 55 gvalue))
56
9adccb27 57(defun gvalue-free (gvalue &optional (unset-p t))
387230e8 58 (unless (null-pointer-p gvalue)
68093e26 59 (when unset-p
60 (gvalue-unset gvalue))
387230e8 61 (deallocate-memory gvalue)))
62
63(defun gvalue-type (gvalue)
4f1fe141 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)
67 (or
68 (type-from-number type)
69 (let ((parent (type-parent type)))
70 (unless (zerop parent)
71 (find-most-specific-known-type parent))))))
72 (or
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))))
387230e8 76
fa30048e 77(defun gvalue-get (gvalue)
9adccb27 78 (funcall (reader-function (gvalue-type gvalue))
fa30048e 79 gvalue +gvalue-value-offset+))
80
81(defun gvalue-peek (gvalue)
82 (funcall (reader-function (gvalue-type gvalue) :ref :peek)
83 gvalue +gvalue-value-offset+))
84
85(defun gvalue-take (gvalue)
86 (funcall (reader-function (gvalue-type gvalue) :ref :get)
87 gvalue +gvalue-value-offset+))
387230e8 88
89(defun gvalue-set (gvalue value)
9adccb27 90 (funcall (writer-function (gvalue-type gvalue))
387230e8 91 value gvalue +gvalue-value-offset+)
92 value)
93
8532ba0a 94(defbinding (gvalue-p "g_type_check_value") () boolean
95 (location pointer))
96
a54e8339 97(defmacro with-gvalue ((gvalue &optional type (value nil value-p)) &body body)
fa30048e 98 `(with-memory (,gvalue +gvalue-size+)
35850cce 99 ,(cond
100 ((and type value-p) `(gvalue-init ,gvalue ,type ,value))
101 (type `(gvalue-init ,gvalue ,type)))
102 ,@body
fa30048e 103 ,(unless value-p `(gvalue-take ,gvalue))))
df0b4e7d 104
4d83a8a6 105
df0b4e7d 106(deftype param-flag-type ()
107 '(flags
4eb73e10 108 (:readable 1)
109 (:writable 2)
110 (:construct 4)
111 (:construct-only 8)
112 (:lax-validation 16)
113 (:private 32)))
df0b4e7d 114
9adccb27 115(eval-when (:compile-toplevel :load-toplevel :execute)
116 (defclass param-spec-class (ginstance-class)
117 ())
118
fa30048e 119 (defmethod shared-initialize ((class param-spec-class) names &rest initargs)
120 (declare (ignore names initargs))
121 (call-next-method)
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)))
126
73572c12 127 (defmethod validate-superclass ((class param-spec-class) (super standard-class))
9adccb27 128 t ;(subtypep (class-name super) 'param)
129))
130
131
132(defbinding %param-spec-ref () pointer
133 (location pointer))
134
135(defbinding %param-spec-unref () nil
136 (location pointer))
137
9adccb27 138
4d83a8a6 139;; TODO: rename to param-spec
9adccb27 140(defclass param (ginstance)
141 ((name
142 :allocation :alien
143 :reader param-name
144 :type string)
145 (flags
146 :allocation :alien
147 :reader param-flags
148 :type param-flag-type)
149 (value-type
150 :allocation :alien
151 :reader param-value-type
152 :type type-number)
153 (owner-type
154 :allocation :alien
155 :reader param-owner-type
156 :type type-number)
157 (nickname
158 :allocation :virtual
159 :getter "g_param_spec_get_nick"
160 :reader param-nickname
9ca5565a 161 :type (copy-of string))
9adccb27 162 (documentation
163 :allocation :virtual
164 :getter "g_param_spec_get_blurb"
165 :reader param-documentation
9ca5565a 166 :type (copy-of string)))
dfa4f314 167 (:metaclass param-spec-class)
168 (:gtype "GParam"))
df0b4e7d 169
170
171(defclass param-char (param)
172 ((minimum
173 :allocation :alien
fa30048e 174 :reader param-minimum
df0b4e7d 175 :type char)
176 (maximum
177 :allocation :alien
fa30048e 178 :reader param-maximum
df0b4e7d 179 :type char)
180 (default-value
181 :allocation :alien
fa30048e 182 :reader param-default-value
df0b4e7d 183 :type char))
dfa4f314 184 (:metaclass param-spec-class)
185 (:gtype "GParamChar"))
df0b4e7d 186
187(defclass param-unsigned-char (param)
188 (
189; (minimum
190; :allocation :alien
191; :reader param-unsigned-char-minimum
192; :type unsigned-char)
193; (maximum
194; :allocation :alien
195; :reader param-unsigned-char-maximum
196; :type unsigned-char)
197; (default-value
198; :allocation :alien
199; :reader param-unsigned-char-default-value
200; :type unsigned-char)
201 )
9adccb27 202 (:metaclass param-spec-class)
dfa4f314 203 (:gtype "GParamUChar"))
df0b4e7d 204
205(defclass param-boolean (param)
206 ((default-value
207 :allocation :alien
fa30048e 208 :reader param-default-value
df0b4e7d 209 :type boolean))
dfa4f314 210 (:metaclass param-spec-class)
211 (:gtype "GParamBoolean"))
df0b4e7d 212
213(defclass param-int (param)
214 ((minimum
215 :allocation :alien
fa30048e 216 :reader param-minimum
df0b4e7d 217 :type int)
218 (maximum
219 :allocation :alien
fa30048e 220 :reader param-maximum
df0b4e7d 221 :type int)
222 (default-value
223 :allocation :alien
fa30048e 224 :reader param-default-value
df0b4e7d 225 :type int))
dfa4f314 226 (:metaclass param-spec-class)
227 (:gtype "GParamInt"))
df0b4e7d 228
229(defclass param-unsigned-int (param)
230 ((minimum
231 :allocation :alien
fa30048e 232 :reader param-minimum
df0b4e7d 233 :type unsigned-int)
234 (maximum
235 :allocation :alien
fa30048e 236 :reader param-maximum
df0b4e7d 237 :type unsigned-int)
238 (default-value
239 :allocation :alien
fa30048e 240 :reader param-default-value
df0b4e7d 241 :type unsigned-int))
9adccb27 242 (:metaclass param-spec-class)
dfa4f314 243 (:gtype "GParamUInt"))
df0b4e7d 244
245(defclass param-long (param)
246 ((minimum
247 :allocation :alien
fa30048e 248 :reader param-minimum
df0b4e7d 249 :type long)
250 (maximum
251 :allocation :alien
fa30048e 252 :reader param-maximum
df0b4e7d 253 :type long)
254 (default-value
255 :allocation :alien
fa30048e 256 :reader param-default-value
df0b4e7d 257 :type long))
dfa4f314 258 (:metaclass param-spec-class)
259 (:gtype "GParam"))
df0b4e7d 260
261(defclass param-unsigned-long (param)
262 ((minimum
263 :allocation :alien
fa30048e 264 :reader param-minimum
df0b4e7d 265 :type unsigned-long)
266 (maximum
267 :allocation :alien
fa30048e 268 :reader param-maximum
df0b4e7d 269 :type unsigned-long)
270 (default-value
271 :allocation :alien
fa30048e 272 :reader param-default-value
df0b4e7d 273 :type unsigned-long))
9adccb27 274 (:metaclass param-spec-class)
dfa4f314 275 (:gtype "GParamULong"))
df0b4e7d 276
277(defclass param-unichar (param)
278 ()
dfa4f314 279 (:metaclass param-spec-class)
280 (:gtype "GParamUnichar"))
df0b4e7d 281
282(defclass param-enum (param)
283 ((class
284 :allocation :alien
285 :reader param-enum-class
286 :type pointer)
287 (default-value
288 :allocation :alien
fa30048e 289 :reader param-default-value
df0b4e7d 290 :type long))
dfa4f314 291 (:metaclass param-spec-class)
292 (:gtype "GParamEnum"))
df0b4e7d 293
294(defclass param-flags (param)
295 ((class
296 :allocation :alien
297 :reader param-flags-class
298 :type pointer)
299 (default-value
300 :allocation :alien
fa30048e 301 :reader param-default-value
df0b4e7d 302 :type long))
dfa4f314 303 (:metaclass param-spec-class)
304 (:gtype "GParamFlags"))
df0b4e7d 305
306(defclass param-single-float (param)
307 ((minimum
308 :allocation :alien
fa30048e 309 :reader param-minimum
df0b4e7d 310 :type single-float)
311 (maximum
312 :allocation :alien
fa30048e 313 :reader param-maximum
df0b4e7d 314 :type single-float)
315 (default-value
316 :allocation :alien
fa30048e 317 :reader param-default-value
df0b4e7d 318 :type single-float)
319 (epsilon
320 :allocation :alien
fa30048e 321 :reader param-float-epsilon
df0b4e7d 322 :type single-float))
9adccb27 323 (:metaclass param-spec-class)
dfa4f314 324 (:gtype "GParamFloat"))
df0b4e7d 325
326(defclass param-double-float (param)
327 ((minimum
328 :allocation :alien
fa30048e 329 :reader param-minimum
df0b4e7d 330 :type double-float)
331 (maximum
332 :allocation :alien
fa30048e 333 :reader param-maximum
df0b4e7d 334 :type double-float)
335 (default-value
336 :allocation :alien
fa30048e 337 :reader param-default-value
df0b4e7d 338 :type double-float)
339 (epsilon
340 :allocation :alien
fa30048e 341 :reader param-float-epsilon
df0b4e7d 342 :type double-float))
9adccb27 343 (:metaclass param-spec-class)
dfa4f314 344 (:gtype "GParamDouble"))
df0b4e7d 345
346(defclass param-string (param)
347 ((default-value
348 :allocation :alien
fa30048e 349 :reader param-default-value
df0b4e7d 350 :type string))
dfa4f314 351 (:metaclass param-spec-class)
352 (:gtype "GParamString"))
df0b4e7d 353
354(defclass param-param (param)
355 ()
dfa4f314 356 (:metaclass param-spec-class)
357 (:gtype "GParamParam"))
df0b4e7d 358
359(defclass param-boxed (param)
360 ()
dfa4f314 361 (:metaclass param-spec-class)
362 (:gtype "GParamBoxed"))
df0b4e7d 363
364(defclass param-pointer (param)
365 ()
dfa4f314 366 (:metaclass param-spec-class)
367 (:gtype "GParamPointer"))
df0b4e7d 368
369(defclass param-value-array (param)
370 ((element-spec
371 :allocation :alien
372 :reader param-value-array-element-spec
373 :type param)
374 (length
375 :allocation :alien
376 :reader param-value-array-length
377 :type unsigned-int))
dfa4f314 378 (:metaclass param-spec-class)
379 (:gtype "GParamValueArray"))
df0b4e7d 380
381(defclass param-object (param)
382 ()
dfa4f314 383 (:metaclass param-spec-class)
384 (:gtype "GParamObject"))
385
386(defclass param-overrride (param)
387 ()
388 (:metaclass param-spec-class)
389 (:gtype "GParamOverride"))