Support for mangled GTypes in g-type-designator foreign type; conversion g-type-desig...
[cl-gtk2.git] / glib / gobject.type-info.lisp
1 (defpackage :gobject.type-info
2   (:use :cl :iter :cffi :glib :gobject.ffi)
3   (:export #:+g-type-invalid+
4            #:+g-type-void+
5            #:+g-type-interface+
6            #:+g-type-char+
7            #:+g-type-uchar+
8            #:+g-type-boolean+
9            #:+g-type-int+
10            #:+g-type-uint+
11            #:+g-type-long+
12            #:+g-type-ulong+
13            #:+g-type-int64+
14            #:+g-type-uint64+
15            #:+g-type-enum+
16            #:+g-type-flags+
17            #:+g-type-float+
18            #:+g-type-double+
19            #:+g-type-string+
20            #:+g-type-pointer+
21            #:+g-type-boxed+
22            #:+g-type-param+
23            #:+g-type-object+
24            #:g-type-name
25            #:g-type-from-name
26            #:g-type
27            #:g-type-children
28            #:g-type-parent
29            #:g-type-designator
30            #:g-type-fundamental
31            #:g-type-depth
32            #:g-type-next-base
33            #:g-type-is-a
34            #:g-type-interfaces
35            #:g-type-interface-prerequisites
36            #:g-strv-get-type
37            #:g-closure-get-type
38            #:g-class-property-definition
39            #:g-class-property-definition-name
40            #:g-class-property-definition-type
41            #:g-class-property-definition-readable
42            #:g-class-property-definition-writable
43            #:g-class-property-definition-constructor
44            #:g-class-property-definition-constructor-only
45            #:g-class-property-definition-owner-type
46            #:parse-g-param-spec
47            #:class-properties
48            #:interface-properties
49            #:enum-item
50            #:enum-item-name
51            #:enum-item-value
52            #:enum-item-nick
53            #:get-enum-items
54            #:flags-item
55            #:flags-item-name
56            #:flags-item-value
57            #:flags-item-nick
58            #:get-flags-items
59            #:signal-info
60            #:signal-info-id
61            #:signal-info-name
62            #:signal-info-owner-type
63            #:signal-info-flags
64            #:signal-info-return-type
65            #:signal-info-param-types
66            #:signal-info-detail
67            #:query-signal-info
68            #:type-signals
69            #:parse-signal-name)
70   (:documentation
71 "This package contains functions for querying the basic type information from GObject type system. For an overview of GObject type system, see @a[http://library.gnome.org/devel/gobject/stable/index.html]{GObject documentation}
72
73 Types are identified by GType designators that are specified in @class{g-type-designator}. Functions of this package provide means to query basic information about type.
74
75 @begin{itemize}
76 @item{@fun{g-type-name} and @fun{g-type-from-name} convert between numeric and string representation of GType.}
77 @item{@fun{g-type-parent}, @fun{g-type-children} and @fun{g-type-interfaces} traverse across the type hierarchy.}
78 @item{@fun{g-type-depth}, @fun{g-type-fundamental}, @fun{g-type-is-a}, @fun{g-type-next-base} are convenience functions that provide useful information from type hierarchy}
79 @end{itemize}
80
81 This is a list of variables and functions that correspond to basic types:
82 @begin{itemize}
83 @item{@fun{g-closure-get-type}}
84 @item{@fun{g-strv-get-type}}
85 @item{@variable{+g-type-invalid+}}
86 @item{@variable{+g-type-void+}}
87 @item{@variable{+g-type-interface+}}
88 @item{@variable{+g-type-char+}}
89 @item{@variable{+g-type-uchar+}}
90 @item{@variable{+g-type-boolean+}}
91 @item{@variable{+g-type-int+}}
92 @item{@variable{+g-type-uint+}}
93 @item{@variable{+g-type-long+}}
94 @item{@variable{+g-type-ulong+}}
95 @item{@variable{+g-type-int64+}}
96 @item{@variable{+g-type-uint64+}}
97 @item{@variable{+g-type-enum+}}
98 @item{@variable{+g-type-flags+}}
99 @item{@variable{+g-type-float+}}
100 @item{@variable{+g-type-double+}}
101 @item{@variable{+g-type-string+}}
102 @item{@variable{+g-type-pointer+}}
103 @item{@variable{+g-type-boxed+}}
104 @item{@variable{+g-type-param+}}
105 @item{@variable{+g-type-object+}}
106 @end{itemize}
107 "))
108
109 (in-package :gobject.type-info)
110
111 (defctype g-type gsize)
112
113 (eval-when (:load-toplevel :compile-toplevel)
114   (defun gtype-make-fundamental-type (x)
115     (ash x 2)))
116
117 (defconstant +g-type-invalid+ (gtype-make-fundamental-type 0) "An invalid GType used as error return value in some functions which return a GType.")
118 (defconstant +g-type-void+ (gtype-make-fundamental-type 1) "A fundamental type which is used as a replacement for the C @code{void} return type.")
119 (defconstant +g-type-interface+ (gtype-make-fundamental-type 2) "The fundamental type from which all interfaces are derived.")
120 (defconstant +g-type-char+ (gtype-make-fundamental-type 3) "The fundamental type corresponding to gchar. The type designated by @variable{+g-type-char+} is unconditionally an 8-bit signed integer. This may or may not be the same type a the C type @code{gchar}.")
121 (defconstant +g-type-uchar+ (gtype-make-fundamental-type 4) "The fundamental type corresponding to @code{guchar}.")
122 (defconstant +g-type-boolean+ (gtype-make-fundamental-type 5) "The fundamental type corresponding to @code{gboolean}.")
123 (defconstant +g-type-int+ (gtype-make-fundamental-type 6) "The fundamental type corresponding to @code{gint}.")
124 (defconstant +g-type-uint+ (gtype-make-fundamental-type 7) "The fundamental type corresponding to @code{guint}.")
125 (defconstant +g-type-long+ (gtype-make-fundamental-type 8) "The fundamental type corresponding to @code{glong}.")
126 (defconstant +g-type-ulong+ (gtype-make-fundamental-type 9) "The fundamental type corresponding to @code{gulong}.")
127 (defconstant +g-type-int64+ (gtype-make-fundamental-type 10) "The fundamental type corresponding to @code{gint64}.")
128 (defconstant +g-type-uint64+ (gtype-make-fundamental-type 11) "The fundamental type corresponding to @code{guint64}.")
129 (defconstant +g-type-enum+ (gtype-make-fundamental-type 12) "The fundamental type from which all enumeration types are derived.")
130 (defconstant +g-type-flags+ (gtype-make-fundamental-type 13) "The fundamental type from which all flags types are derived.")
131 (defconstant +g-type-float+ (gtype-make-fundamental-type 14) "The fundamental type corresponding to @code{gfloat}.")
132 (defconstant +g-type-double+ (gtype-make-fundamental-type 15) "The fundamental type corresponding to @code{gdouble}.")
133 (defconstant +g-type-string+ (gtype-make-fundamental-type 16) "The fundamental type corresponding to null-terminated C strings.")
134 (defconstant +g-type-pointer+ (gtype-make-fundamental-type 17) "The fundamental type corresponding to @code{gpointer}.")
135 (defconstant +g-type-boxed+ (gtype-make-fundamental-type 18) "The fundamental type from which all boxed types are derived.")
136 (defconstant +g-type-param+ (gtype-make-fundamental-type 19) "The fundamental type from which all GParamSpec types are derived.")
137 (defconstant +g-type-object+ (gtype-make-fundamental-type 20) "The fundamental type for GObject.")
138
139 (defun g-type-children (g-type)
140   "Returns the list of types inherited from @code{g-type}.@see{g-type-parent}
141
142 Example:
143 @pre{
144 \(g-type-children \"GtkObject\")
145 => (\"GtkWidget\" \"GtkAdjustment\" \"GtkTreeViewColumn\" \"GtkCellRenderer\"
146     \"GtkFileFilter\" \"GtkRecentFilter\" \"GtkTooltips\")
147 }
148 @arg[g-type]{GType designator (see @class{g-type-designator})}
149 @return{list of GType designators}"
150   (with-foreign-object (n-children :uint)
151     (let ((g-types-ptr (%g-type-children g-type n-children)))
152       (prog1
153           (loop
154              for i from 0 below (mem-ref n-children :uint)
155              collect (mem-aref g-types-ptr 'g-type-designator i))
156         (g-free g-types-ptr)))))
157
158 (defun g-type-interfaces (g-type)
159   "Returns the list of interfaces the @code{g-type} conforms to.
160
161 Example:
162 @pre{
163 \(g-type-interfaces \"GtkButton\")
164 => (\"AtkImplementorIface\" \"GtkBuildable\" \"GtkActivatable\")
165 }
166 @arg[g-type]{GType designator (see @class{g-type-designator})}
167 @return{list of GType designators}"
168   (with-foreign-object (n-interfaces :uint)
169     (let ((g-types-ptr (%g-type-interfaces g-type n-interfaces)))
170       (prog1
171           (loop
172              for i from 0 below (mem-ref n-interfaces :uint)
173              collect (mem-aref g-types-ptr 'g-type-designator i))
174         (g-free g-types-ptr)))))
175
176 (defun g-type-interface-prerequisites (g-type)
177   "Returns the prerequisites of an interface type. Prerequisite is a type that must be a superclass of an implementing class or an interface that the object must also implement.
178
179 Example:
180 @pre{
181 \(g-type-interface-prerequisites \"GtkTreeModel\")
182 => (\"GObject\")
183 }
184 @arg[g-type]{GType designator (see @class{g-type-designator})}
185 @return{list of GType designators}"
186   (with-foreign-object (n-interface-prerequisites :uint)
187     (let ((g-types-ptr (%g-type-interface-prerequisites g-type n-interface-prerequisites)))
188       (prog1
189           (loop
190              for i from 0 below (mem-ref n-interface-prerequisites :uint)
191              collect (mem-aref g-types-ptr 'g-type-designator i))
192         (g-free g-types-ptr)))))
193