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