Moved GObject code
[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            #:class-property-info)
71   (:documentation
72 "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}
73
74 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.
75
76 @begin{itemize}
77 @item{@fun{g-type-name} and @fun{g-type-from-name} convert between numeric and string representation of GType.}
78 @item{@fun{g-type-parent}, @fun{g-type-children} and @fun{g-type-interfaces} traverse across the type hierarchy.}
79 @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}
80 @end{itemize}
81
82 This is a list of variables and functions that correspond to basic types:
83 @begin{itemize}
84 @item{@fun{g-closure-get-type}}
85 @item{@fun{g-strv-get-type}}
86 @item{@variable{+g-type-invalid+}}
87 @item{@variable{+g-type-void+}}
88 @item{@variable{+g-type-interface+}}
89 @item{@variable{+g-type-char+}}
90 @item{@variable{+g-type-uchar+}}
91 @item{@variable{+g-type-boolean+}}
92 @item{@variable{+g-type-int+}}
93 @item{@variable{+g-type-uint+}}
94 @item{@variable{+g-type-long+}}
95 @item{@variable{+g-type-ulong+}}
96 @item{@variable{+g-type-int64+}}
97 @item{@variable{+g-type-uint64+}}
98 @item{@variable{+g-type-enum+}}
99 @item{@variable{+g-type-flags+}}
100 @item{@variable{+g-type-float+}}
101 @item{@variable{+g-type-double+}}
102 @item{@variable{+g-type-string+}}
103 @item{@variable{+g-type-pointer+}}
104 @item{@variable{+g-type-boxed+}}
105 @item{@variable{+g-type-param+}}
106 @item{@variable{+g-type-object+}}
107 @end{itemize}
108 "))
109
110 (in-package :gobject.type-info)
111
112 (defctype g-type gsize)
113
114 (eval-when (:load-toplevel :compile-toplevel)
115   (defun gtype-make-fundamental-type (x)
116     (ash x 2)))
117
118 (defconstant +g-type-invalid+ (gtype-make-fundamental-type 0) "An invalid GType used as error return value in some functions which return a GType.")
119 (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.")
120 (defconstant +g-type-interface+ (gtype-make-fundamental-type 2) "The fundamental type from which all interfaces are derived.")
121 (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}.")
122 (defconstant +g-type-uchar+ (gtype-make-fundamental-type 4) "The fundamental type corresponding to @code{guchar}.")
123 (defconstant +g-type-boolean+ (gtype-make-fundamental-type 5) "The fundamental type corresponding to @code{gboolean}.")
124 (defconstant +g-type-int+ (gtype-make-fundamental-type 6) "The fundamental type corresponding to @code{gint}.")
125 (defconstant +g-type-uint+ (gtype-make-fundamental-type 7) "The fundamental type corresponding to @code{guint}.")
126 (defconstant +g-type-long+ (gtype-make-fundamental-type 8) "The fundamental type corresponding to @code{glong}.")
127 (defconstant +g-type-ulong+ (gtype-make-fundamental-type 9) "The fundamental type corresponding to @code{gulong}.")
128 (defconstant +g-type-int64+ (gtype-make-fundamental-type 10) "The fundamental type corresponding to @code{gint64}.")
129 (defconstant +g-type-uint64+ (gtype-make-fundamental-type 11) "The fundamental type corresponding to @code{guint64}.")
130 (defconstant +g-type-enum+ (gtype-make-fundamental-type 12) "The fundamental type from which all enumeration types are derived.")
131 (defconstant +g-type-flags+ (gtype-make-fundamental-type 13) "The fundamental type from which all flags types are derived.")
132 (defconstant +g-type-float+ (gtype-make-fundamental-type 14) "The fundamental type corresponding to @code{gfloat}.")
133 (defconstant +g-type-double+ (gtype-make-fundamental-type 15) "The fundamental type corresponding to @code{gdouble}.")
134 (defconstant +g-type-string+ (gtype-make-fundamental-type 16) "The fundamental type corresponding to null-terminated C strings.")
135 (defconstant +g-type-pointer+ (gtype-make-fundamental-type 17) "The fundamental type corresponding to @code{gpointer}.")
136 (defconstant +g-type-boxed+ (gtype-make-fundamental-type 18) "The fundamental type from which all boxed types are derived.")
137 (defconstant +g-type-param+ (gtype-make-fundamental-type 19) "The fundamental type from which all GParamSpec types are derived.")
138 (defconstant +g-type-object+ (gtype-make-fundamental-type 20) "The fundamental type for GObject.")
139
140 (defun g-type-children (g-type)
141   "Returns the list of types inherited from @code{g-type}.@see{g-type-parent}
142
143 Example:
144 @pre{
145 \(g-type-children \"GtkObject\")
146 => (\"GtkWidget\" \"GtkAdjustment\" \"GtkTreeViewColumn\" \"GtkCellRenderer\"
147     \"GtkFileFilter\" \"GtkRecentFilter\" \"GtkTooltips\")
148 }
149 @arg[g-type]{GType designator (see @class{g-type-designator})}
150 @return{list of GType designators}"
151   (with-foreign-object (n-children :uint)
152     (let ((g-types-ptr (%g-type-children g-type n-children)))
153       (prog1
154           (loop
155              for i from 0 below (mem-ref n-children :uint)
156              collect (mem-aref g-types-ptr 'g-type-designator i))
157         (g-free g-types-ptr)))))
158
159 (defun g-type-interfaces (g-type)
160   "Returns the list of interfaces the @code{g-type} conforms to.
161
162 Example:
163 @pre{
164 \(g-type-interfaces \"GtkButton\")
165 => (\"AtkImplementorIface\" \"GtkBuildable\" \"GtkActivatable\")
166 }
167 @arg[g-type]{GType designator (see @class{g-type-designator})}
168 @return{list of GType designators}"
169   (with-foreign-object (n-interfaces :uint)
170     (let ((g-types-ptr (%g-type-interfaces g-type n-interfaces)))
171       (prog1
172           (loop
173              for i from 0 below (mem-ref n-interfaces :uint)
174              collect (mem-aref g-types-ptr 'g-type-designator i))
175         (g-free g-types-ptr)))))
176
177 (defun g-type-interface-prerequisites (g-type)
178   "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.
179
180 Example:
181 @pre{
182 \(g-type-interface-prerequisites \"GtkTreeModel\")
183 => (\"GObject\")
184 }
185 @arg[g-type]{GType designator (see @class{g-type-designator})}
186 @return{list of GType designators}"
187   (with-foreign-object (n-interface-prerequisites :uint)
188     (let ((g-types-ptr (%g-type-interface-prerequisites g-type n-interface-prerequisites)))
189       (prog1
190           (loop
191              for i from 0 below (mem-ref n-interface-prerequisites :uint)
192              collect (mem-aref g-types-ptr 'g-type-designator i))
193         (g-free g-types-ptr)))))
194