chiark / gitweb /
Fix compilation for Gtk with the new, stricter inheritance
[clg] / glib / genums.lisp
CommitLineData
112ac1d3 1;; Common Lisp bindings for GTK+ v2.x
2;; Copyright 2000-2005 Espen S. Johnsen <espen@users.sf.net>
94f15c3c 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:
94f15c3c 11;;
112ac1d3 12;; The above copyright notice and this permission notice shall be
13;; included in all copies or substantial portions of the Software.
94f15c3c 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.
94f15c3c 22
80bf1b7a 23;; $Id: genums.lisp,v 1.22 2006-09-28 10:20:12 espen Exp $
94f15c3c 24
25(in-package "GLIB")
d4b21b08 26
de549f6e 27;;;; Definition of enums and flags by introspection
28
29(eval-when (:compile-toplevel :load-toplevel :execute)
30 (defclass enum-value (struct)
31 ((value :allocation :alien :type int)
32 (name :allocation :alien :type string)
33 (nickname :allocation :alien :type string))
34 (:metaclass struct-class)))
35
bb4d662e 36(defun map-enum-values (values symbolic-p)
de549f6e 37 (map 'list
38 #'(lambda (enum-value)
bb4d662e 39 (with-slots (nickname name value) enum-value
de549f6e 40 (list
80bf1b7a 41 (cond
42 ((eq symbolic-p :nickname) nickname)
43 (symbolic-p
44 (intern (substitute #\- #\_ (string-upcase nickname)) "KEYWORD"))
45 (t name))
de549f6e 46 value)))
47 values))
48
49(defbinding enum-class-values () (static (vector (inlined enum-value) n-values))
33939600 50 (class pointer)
51 (n-values unsigned-int :out))
52
de549f6e 53(defbinding flags-class-values () (static (vector (inlined enum-value) n-values))
33939600 54 (class pointer)
55 (n-values unsigned-int :out))
56
bb4d662e 57(defun query-enum-values (type &optional (symbolic-p t))
de549f6e 58 (let ((class (type-class-ref type)))
59 (map-enum-values (if (eq (supertype type) 'enum)
60 (enum-class-values class)
bb4d662e 61 (flags-class-values class))
62 symbolic-p)))
33939600 63
62f12808 64(defun expand-enum-type (type-number forward-p options)
466cf192 65 (declare (ignore forward-p))
de549f6e 66 (let* ((type (type-from-number type-number))
b0bb0027 67 (mappings (getf options :mappings))
d4b21b08 68 (expanded-mappings
69 (append
70 (delete-if
71 #'(lambda (mapping)
72 (or
73 (assoc (first mapping) mappings)
74 (rassoc (cdr mapping) mappings :test #'equal)))
de549f6e 75 (query-enum-values type-number))
d4b21b08 76 (remove-if
77 #'(lambda (mapping) (eq (second mapping) nil)) mappings))))
78 `(progn
dfa4f314 79 (register-type ',type ',(find-type-init-function type-number))
de549f6e 80 ,(ecase (supertype type-number)
bdd137d2 81 (enum `(define-enum-type ,type ,@expanded-mappings))
82 (flags `(define-flags-type ,type ,@expanded-mappings))))))
d4b21b08 83
84
b0bb0027 85(register-derivable-type 'enum "GEnum" 'expand-enum-type)
86(register-derivable-type 'flags "GFlags" 'expand-enum-type)
94f15c3c 87