chiark / gitweb /
Removed comment about setting up logical pathname translation
[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
86e998ca 23;; $Id: gparam.lisp,v 1.26 2007-08-20 10:50:25 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
86e998ca 45(defun gvalue-init (gvalue type &optional (value nil value-p) temp-p)
9adccb27 46 (%gvalue-init gvalue (find-type-number type))
47 (when value-p
86e998ca 48 (funcall (writer-function type :temp temp-p) 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))))))
ae462d0e 72 (let ((type-number (ref-type-number gvalue)))
73 (unless (zerop type-number)
74 (or
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))))))
387230e8 78
fa30048e 79(defun gvalue-get (gvalue)
9adccb27 80 (funcall (reader-function (gvalue-type gvalue))
fa30048e 81 gvalue +gvalue-value-offset+))
82
83(defun gvalue-peek (gvalue)
84 (funcall (reader-function (gvalue-type gvalue) :ref :peek)
85 gvalue +gvalue-value-offset+))
86
87(defun gvalue-take (gvalue)
88 (funcall (reader-function (gvalue-type gvalue) :ref :get)
89 gvalue +gvalue-value-offset+))
387230e8 90
91(defun gvalue-set (gvalue value)
9adccb27 92 (funcall (writer-function (gvalue-type gvalue))
387230e8 93 value gvalue +gvalue-value-offset+)
94 value)
95
8532ba0a 96(defbinding (gvalue-p "g_type_check_value") () boolean
97 (location pointer))
98
a54e8339 99(defmacro with-gvalue ((gvalue &optional type (value nil value-p)) &body body)
fa30048e 100 `(with-memory (,gvalue +gvalue-size+)
35850cce 101 ,(cond
86e998ca 102 ((and type value-p) `(gvalue-init ,gvalue ,type ,value t))
35850cce 103 (type `(gvalue-init ,gvalue ,type)))
104 ,@body
fa30048e 105 ,(unless value-p `(gvalue-take ,gvalue))))
df0b4e7d 106
4d83a8a6 107
df0b4e7d 108(deftype param-flag-type ()
109 '(flags
4eb73e10 110 (:readable 1)
111 (:writable 2)
112 (:construct 4)
113 (:construct-only 8)
114 (:lax-validation 16)
115 (:private 32)))
df0b4e7d 116
9adccb27 117(eval-when (:compile-toplevel :load-toplevel :execute)
118 (defclass param-spec-class (ginstance-class)
119 ())
120
fa30048e 121 (defmethod shared-initialize ((class param-spec-class) names &rest initargs)
122 (declare (ignore names initargs))
123 (call-next-method)
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)))
128
73572c12 129 (defmethod validate-superclass ((class param-spec-class) (super standard-class))
9adccb27 130 t ;(subtypep (class-name super) 'param)
131))
132
133
134(defbinding %param-spec-ref () pointer
135 (location pointer))
136
137(defbinding %param-spec-unref () nil
138 (location pointer))
139
9adccb27 140
4d83a8a6 141;; TODO: rename to param-spec
9adccb27 142(defclass param (ginstance)
143 ((name
144 :allocation :alien
145 :reader param-name
146 :type string)
147 (flags
148 :allocation :alien
149 :reader param-flags
150 :type param-flag-type)
151 (value-type
152 :allocation :alien
153 :reader param-value-type
154 :type type-number)
155 (owner-type
156 :allocation :alien
157 :reader param-owner-type
158 :type type-number)
159 (nickname
160 :allocation :virtual
161 :getter "g_param_spec_get_nick"
162 :reader param-nickname
9ca5565a 163 :type (copy-of string))
9adccb27 164 (documentation
165 :allocation :virtual
166 :getter "g_param_spec_get_blurb"
167 :reader param-documentation
9ca5565a 168 :type (copy-of string)))
dfa4f314 169 (:metaclass param-spec-class)
170 (:gtype "GParam"))
df0b4e7d 171
172
173(defclass param-char (param)
174 ((minimum
175 :allocation :alien
fa30048e 176 :reader param-minimum
df0b4e7d 177 :type char)
178 (maximum
179 :allocation :alien
fa30048e 180 :reader param-maximum
df0b4e7d 181 :type char)
182 (default-value
183 :allocation :alien
fa30048e 184 :reader param-default-value
df0b4e7d 185 :type char))
dfa4f314 186 (:metaclass param-spec-class)
187 (:gtype "GParamChar"))
df0b4e7d 188
189(defclass param-unsigned-char (param)
190 (
191; (minimum
192; :allocation :alien
193; :reader param-unsigned-char-minimum
194; :type unsigned-char)
195; (maximum
196; :allocation :alien
197; :reader param-unsigned-char-maximum
198; :type unsigned-char)
199; (default-value
200; :allocation :alien
201; :reader param-unsigned-char-default-value
202; :type unsigned-char)
203 )
9adccb27 204 (:metaclass param-spec-class)
dfa4f314 205 (:gtype "GParamUChar"))
df0b4e7d 206
207(defclass param-boolean (param)
208 ((default-value
209 :allocation :alien
fa30048e 210 :reader param-default-value
df0b4e7d 211 :type boolean))
dfa4f314 212 (:metaclass param-spec-class)
213 (:gtype "GParamBoolean"))
df0b4e7d 214
215(defclass param-int (param)
216 ((minimum
217 :allocation :alien
fa30048e 218 :reader param-minimum
df0b4e7d 219 :type int)
220 (maximum
221 :allocation :alien
fa30048e 222 :reader param-maximum
df0b4e7d 223 :type int)
224 (default-value
225 :allocation :alien
fa30048e 226 :reader param-default-value
df0b4e7d 227 :type int))
dfa4f314 228 (:metaclass param-spec-class)
229 (:gtype "GParamInt"))
df0b4e7d 230
231(defclass param-unsigned-int (param)
232 ((minimum
233 :allocation :alien
fa30048e 234 :reader param-minimum
df0b4e7d 235 :type unsigned-int)
236 (maximum
237 :allocation :alien
fa30048e 238 :reader param-maximum
df0b4e7d 239 :type unsigned-int)
240 (default-value
241 :allocation :alien
fa30048e 242 :reader param-default-value
df0b4e7d 243 :type unsigned-int))
9adccb27 244 (:metaclass param-spec-class)
dfa4f314 245 (:gtype "GParamUInt"))
df0b4e7d 246
247(defclass param-long (param)
248 ((minimum
249 :allocation :alien
fa30048e 250 :reader param-minimum
df0b4e7d 251 :type long)
252 (maximum
253 :allocation :alien
fa30048e 254 :reader param-maximum
df0b4e7d 255 :type long)
256 (default-value
257 :allocation :alien
fa30048e 258 :reader param-default-value
df0b4e7d 259 :type long))
dfa4f314 260 (:metaclass param-spec-class)
261 (:gtype "GParam"))
df0b4e7d 262
263(defclass param-unsigned-long (param)
264 ((minimum
265 :allocation :alien
fa30048e 266 :reader param-minimum
df0b4e7d 267 :type unsigned-long)
268 (maximum
269 :allocation :alien
fa30048e 270 :reader param-maximum
df0b4e7d 271 :type unsigned-long)
272 (default-value
273 :allocation :alien
fa30048e 274 :reader param-default-value
df0b4e7d 275 :type unsigned-long))
9adccb27 276 (:metaclass param-spec-class)
dfa4f314 277 (:gtype "GParamULong"))
df0b4e7d 278
279(defclass param-unichar (param)
280 ()
dfa4f314 281 (:metaclass param-spec-class)
282 (:gtype "GParamUnichar"))
df0b4e7d 283
284(defclass param-enum (param)
285 ((class
286 :allocation :alien
287 :reader param-enum-class
288 :type pointer)
289 (default-value
290 :allocation :alien
fa30048e 291 :reader param-default-value
df0b4e7d 292 :type long))
dfa4f314 293 (:metaclass param-spec-class)
294 (:gtype "GParamEnum"))
df0b4e7d 295
296(defclass param-flags (param)
297 ((class
298 :allocation :alien
299 :reader param-flags-class
300 :type pointer)
301 (default-value
302 :allocation :alien
fa30048e 303 :reader param-default-value
df0b4e7d 304 :type long))
dfa4f314 305 (:metaclass param-spec-class)
306 (:gtype "GParamFlags"))
df0b4e7d 307
308(defclass param-single-float (param)
309 ((minimum
310 :allocation :alien
fa30048e 311 :reader param-minimum
df0b4e7d 312 :type single-float)
313 (maximum
314 :allocation :alien
fa30048e 315 :reader param-maximum
df0b4e7d 316 :type single-float)
317 (default-value
318 :allocation :alien
fa30048e 319 :reader param-default-value
df0b4e7d 320 :type single-float)
321 (epsilon
322 :allocation :alien
fa30048e 323 :reader param-float-epsilon
df0b4e7d 324 :type single-float))
9adccb27 325 (:metaclass param-spec-class)
dfa4f314 326 (:gtype "GParamFloat"))
df0b4e7d 327
328(defclass param-double-float (param)
329 ((minimum
330 :allocation :alien
fa30048e 331 :reader param-minimum
df0b4e7d 332 :type double-float)
333 (maximum
334 :allocation :alien
fa30048e 335 :reader param-maximum
df0b4e7d 336 :type double-float)
337 (default-value
338 :allocation :alien
fa30048e 339 :reader param-default-value
df0b4e7d 340 :type double-float)
341 (epsilon
342 :allocation :alien
fa30048e 343 :reader param-float-epsilon
df0b4e7d 344 :type double-float))
9adccb27 345 (:metaclass param-spec-class)
dfa4f314 346 (:gtype "GParamDouble"))
df0b4e7d 347
348(defclass param-string (param)
349 ((default-value
350 :allocation :alien
fa30048e 351 :reader param-default-value
df0b4e7d 352 :type string))
dfa4f314 353 (:metaclass param-spec-class)
354 (:gtype "GParamString"))
df0b4e7d 355
356(defclass param-param (param)
357 ()
dfa4f314 358 (:metaclass param-spec-class)
359 (:gtype "GParamParam"))
df0b4e7d 360
361(defclass param-boxed (param)
362 ()
dfa4f314 363 (:metaclass param-spec-class)
364 (:gtype "GParamBoxed"))
df0b4e7d 365
366(defclass param-pointer (param)
367 ()
dfa4f314 368 (:metaclass param-spec-class)
369 (:gtype "GParamPointer"))
df0b4e7d 370
371(defclass param-value-array (param)
372 ((element-spec
373 :allocation :alien
374 :reader param-value-array-element-spec
375 :type param)
376 (length
377 :allocation :alien
378 :reader param-value-array-length
379 :type unsigned-int))
dfa4f314 380 (:metaclass param-spec-class)
381 (:gtype "GParamValueArray"))
df0b4e7d 382
383(defclass param-object (param)
384 ()
dfa4f314 385 (:metaclass param-spec-class)
386 (:gtype "GParamObject"))
387
388(defclass param-overrride (param)
389 ()
390 (:metaclass param-spec-class)
391 (:gtype "GParamOverride"))