docstrings and g-type-designator
[cl-gtk2.git] / glib / gobject.type.lisp
1 (in-package :gobject)
2
3 (define-foreign-type g-type-designator ()
4   ()
5   (:documentation "Values of this type identify the GType. GType is designated by a its name (a string) or a numeric identifier. Functions accept GType designators as a string or integer and return them as a string. Functions @fun{g-type-name} and @fun{g-type-from-name} are used to convert between name and numeric identifier.")
6   (:actual-type g-type)
7   (:simple-parser g-type-designator))
8
9 (defmethod translate-from-foreign (value (type g-type-designator))
10   (g-type-name value))
11
12 (defmethod translate-to-foreign (value (type g-type-designator))
13   (etypecase value
14     (string (g-type-from-name value))
15     (integer value)
16     (null +g-type-invalid+)))
17
18 (defcfun (g-type-fundamental "g_type_fundamental") g-type-designator
19   "Returns the fundamental type which is the ancestor of @code{type}.
20 @arg[type]{GType designator (see @class{g-type-fundamental})}
21 @return{GType designator}"
22   (type g-type-designator))
23
24 (defcfun (%g-type-init "g_type_init") :void)
25
26 (at-init () (%g-type-init))
27
28 (defcfun (g-type-name "g_type_name") :string
29   "Returns the name of a GType.
30
31 @arg[type]{GType designator (see @class{g-type-designator})}
32 @return{a string}"
33   (type g-type-designator))
34
35 (defcfun (g-type-from-name "g_type_from_name") g-type
36   "Returns the numeric identifier of a GType by its name
37
38 @arg[name]{a string - name of GType}
39 @return{an integer}"
40   (name :string))
41
42 (defcfun g-type-parent g-type-designator
43   "Returns the parent of a GType
44
45 @arg[type]{GType designator (see @class{g-type-designator})}
46 @return{GType designator}"
47   (type g-type-designator))
48
49 (defcfun g-type-depth :uint
50   "Returns the length of the ancestry of @code{type}. This includes the @code{type} itself, so that e.g. a fundamental type has depth 1.
51 @arg[type]{GType designator (see @class{g-type-designator})}
52 @return{an integer}"
53   (type g-type-designator))
54
55 (defcfun g-type-next-base g-type-designator
56   "Determines the type that is derived directly from @code{root-type} which is also a base class of @code{leaf-type}.
57 @arg[leaf-type]{GType designator (see @class{g-type-designator})}
58 @arg[root-type]{GType designator}
59 @return{GType designator}"
60   (leaf-type g-type-designator)
61   (root-type g-type-designator))
62
63 (defcfun g-type-is-a :boolean
64   "If @code{is-a-type} is a derivable type, check whether type is a descendant of @code{is-a-type}. If @code{is-a-type} is an interface, check whether type conforms to it.
65 @arg[type]{GType designator (see @class{g-type-designator})}
66 @arg[is-a-type]{GType designator}
67 @return{boolean}"
68   (type g-type-designator)
69   (is-a-type g-type-designator))
70
71 (defcfun g-type-class-ref (:pointer g-type-class)
72   (type g-type-designator))
73
74 (defcfun g-type-class-unref :void
75   (class (:pointer g-type-class)))
76
77 (defcfun g-type-class-add-private :void
78   (class (:pointer g-type-class))
79   (private-size gsize))
80
81 (defcfun g-type-default-interface-ref :pointer
82   (type g-type-designator))
83
84 (defcfun g-type-default-interface-unref :void
85   (interface :pointer))
86
87 (defcfun (%g-type-children "g_type_children") (:pointer g-type)
88   (type g-type-designator)
89   (n-children (:pointer :uint)))
90
91 (defun g-type-children (g-type)
92   "Returns the list of types inherited from @code{g-type}.
93
94 @arg[g-type]{GType designator (see @class{g-type-designator})}
95 @return{list of GType designators}"
96   (with-foreign-object (n-children :uint)
97     (let ((g-types-ptr (%g-type-children g-type n-children)))
98       (prog1
99           (loop
100              for i from 0 below (mem-ref n-children :uint)
101              collect (mem-aref g-types-ptr 'g-type-designator i))
102         (g-free g-types-ptr)))))
103
104 (defcfun (%g-type-interfaces "g_type_interfaces") (:pointer g-type)
105   (type g-type-designator)
106   (n-interfaces (:pointer :uint)))
107
108 (defun g-type-interfaces (g-type)
109   "Returns the list of interfaces the @code{g-type} conforms to.
110
111 @arg[g-type]{GType designator (see @class{g-type-designator})}
112 @return{list of GType designators}"
113   (with-foreign-object (n-interfaces :uint)
114     (let ((g-types-ptr (%g-type-interfaces g-type n-interfaces)))
115       (prog1
116           (loop
117              for i from 0 below (mem-ref n-interfaces :uint)
118              collect (mem-aref g-types-ptr 'g-type-designator i))
119         (g-free g-types-ptr)))))
120
121 (defcfun (%g-type-interface-prerequisites "g_type_interface_prerequisites") (:pointer g-type)
122   (type g-type-designator)
123   (n-interface-prerequisites (:pointer :uint)))
124
125 (defun g-type-interface-prerequisites (g-type)
126   "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.
127 @arg[g-type]{GType designator (see @class{g-type-designator})}
128 @return{list of GType designators}"
129   (with-foreign-object (n-interface-prerequisites :uint)
130     (let ((g-types-ptr (%g-type-interface-prerequisites g-type n-interface-prerequisites)))
131       (prog1
132           (loop
133              for i from 0 below (mem-ref n-interface-prerequisites :uint)
134              collect (mem-aref g-types-ptr 'g-type-designator i))
135         (g-free g-types-ptr)))))
136
137 (defcfun g-type-register-static g-type-designator
138   (parent-type g-type-designator)
139   (type-name :string)
140   (info (:pointer g-type-info))
141   (flags g-type-flags))
142
143 (defcfun g-type-register-static-simple g-type-designator
144   (parent-type g-type-designator)
145   (type-name :string)
146   (class-size :uint)
147   (class-init :pointer)
148   (instance-size :uint)
149   (instance-init :pointer)
150   (flags g-type-flags))
151
152 (defcfun g-type-add-interface-static :void
153   (instance-type g-type-designator)
154   (interface-type g-type-designator)
155   (info (:pointer g-interface-info)))
156
157 (defcfun g-type-interface-add-prerequisite :void
158   (interface-type g-type-designator)
159   (prerequisite-type g-type-designator))
160
161 (defun g-type-from-object (object)
162   "Returns the GType of an @code{object}
163
164 @arg[object]{C pointer to an object}
165 @return{GType designator (see @class{g-type-designator})}"
166   (g-type-from-instance object))
167
168 (defun g-type-from-class (g-class)
169   (g-type-name (foreign-slot-value g-class 'g-type-class 'type)))
170
171 (defun g-type-from-instance (type-instance)
172   (g-type-from-class (foreign-slot-value type-instance 'g-type-instance 'class)))
173
174 (defun g-type-from-interface (type-interface)
175   (g-type-name (foreign-slot-value type-interface 'g-type-interface 'type)))
176
177 (defcfun g-strv-get-type g-type-designator)
178
179 (at-init nil (g-strv-get-type))
180
181 (defcfun g-closure-get-type g-type-designator)
182
183 (at-init nil (g-closure-get-type))
184
185 (defcfun g-type-query :void
186   (type g-type-designator)
187   (query (:pointer g-type-query)))