b9be3e8d1e5b4b3cac1a55276e9b1015c633d023
[cl-gtk2.git] / glib / gobject.package.lisp
1 (defpackage :gobject
2   (:use :c2cl :glib :cffi :tg :bordeaux-threads :iter :closer-mop :gobject.ffi)
3   (:export #:g-type
4            #:g-type-string
5            #:g-type-numeric
6            #:g-type-children
7            #:g-type-parent
8            #:g-type-designator
9            #:g-type-fundamental
10            #:g-type-depth
11            #:g-type-next-base
12            #:g-type-is-a
13            #:g-type-interfaces
14            #:g-type-interface-prerequisites
15            #:g-strv-get-type
16            #:g-closure-get-type
17            #:g-class-property-definition
18            #:g-class-property-definition-name
19            #:g-class-property-definition-type
20            #:g-class-property-definition-readable
21            #:g-class-property-definition-writable
22            #:g-class-property-definition-constructor
23            #:g-class-property-definition-constructor-only
24            #:g-class-property-definition-owner-type
25            #:parse-g-param-spec
26            #:class-properties
27            #:interface-properties
28            #:enum-item
29            #:enum-item-name
30            #:enum-item-value
31            #:enum-item-nick
32            #:get-enum-items
33            #:flags-item
34            #:flags-item-name
35            #:flags-item-value
36            #:flags-item-nick
37            #:get-flags-items
38            #:signal-info
39            #:signal-info-id
40            #:signal-info-name
41            #:signal-info-owner-type
42            #:signal-info-flags
43            #:signal-info-return-type
44            #:signal-info-param-types
45            #:signal-info-detail
46            #:query-signal-info
47            #:type-signals
48            #:parse-signal-name
49            #:class-property-info
50            #:+g-type-invalid+
51            #:+g-type-void+
52            #:+g-type-interface+
53            #:+g-type-char+
54            #:+g-type-uchar+
55            #:+g-type-boolean+
56            #:+g-type-int+
57            #:+g-type-uint+
58            #:+g-type-long+
59            #:+g-type-ulong+
60            #:+g-type-int64+
61            #:+g-type-uint64+
62            #:+g-type-enum+
63            #:+g-type-flags+
64            #:+g-type-float+
65            #:+g-type-double+
66            #:+g-type-string+
67            #:+g-type-pointer+
68            #:+g-type-boxed+
69            #:+g-type-param+
70            #:+g-type-object+
71            #:g-object
72            #:pointer
73            #:g-type-from-object
74            #:g-type-name
75            #:g-type-from-name
76            #:g-signal-connect
77            #:define-g-object-class
78            #:g-initially-unowned
79            #:define-g-enum
80            #:*lisp-name-package*
81            #:define-g-flags
82            #:fixed-array
83            #:g-boxed-inline
84            #:g-boxed-ptr
85            #:define-g-interface
86            #:release
87            #:using
88            #:using*
89            #:g-boxed-ref
90            #:allocate-stable-pointer
91            #:free-stable-pointer
92            #:get-stable-pointer-value
93            #:with-stable-pointer
94            #:release*
95            #:disown-boxed-ref
96            #:g-type-interface
97            #:g-value
98            #:register-object-type-implementation
99            #:ensure-g-type
100            #:define-vtable
101            #:g-type
102            #:set-g-value
103            #:parse-g-value
104            #:emit-signal
105            #:g-value-unset
106            #:g-value-zero
107            #:g-value-init
108            #:g-type-class-ref
109            #:g-object-class
110            #:gobject-class
111            #:g-param-spec
112            #:type-instance
113            #:g-type-class-unref
114            #:registered-object-type-by-name
115            #:g-type-children
116            #:g-signal-lookup
117            #:g-type-parent
118            #:connect-signal
119            #:boxed-c-structure-name
120            #:g-type-designator
121            #:g-type-fundamental
122            #:g-type-depth
123            #:g-type-next-base
124            #:g-type-is-a
125            #:g-type-interfaces
126            #:g-type-interface-prerequisites
127            #:g-type-name
128            #:g-type-from-name
129            #:g-type
130            #:g-type-children
131            #:g-type-parent
132            #:g-type-designator
133            #:g-type-fundamental
134            #:g-type-depth
135            #:g-type-next-base
136            #:g-type-is-a
137            #:g-type-interfaces
138            #:g-type-interface-prerequisites
139            #:g-strv-get-type
140            #:g-closure-get-type
141            #:g-class-property-definition
142            #:g-class-property-definition-name
143            #:g-class-property-definition-type
144            #:g-class-property-definition-readable
145            #:g-class-property-definition-writable
146            #:g-class-property-definition-constructor
147            #:g-class-property-definition-constructor-only
148            #:g-class-property-definition-owner-type
149            #:parse-g-param-spec
150            #:class-properties
151            #:interface-properties
152            #:enum-item
153            #:enum-item-name
154            #:enum-item-value
155            #:enum-item-nick
156            #:get-enum-items
157            #:flags-item
158            #:flags-item-name
159            #:flags-item-value
160            #:flags-item-nick
161            #:get-flags-items
162            #:stable-pointer-value
163            #:g-value-type
164            #:g-object-call-constructor
165            #:g-object-call-get-property
166            #:g-object-call-set-property
167            #:register-enum-type
168            #:register-flags-type
169            #:register-object-type
170            #:generate-types-hierarchy-to-file
171            #:get-g-flags-definition
172            #:get-g-enum-definition
173            #:get-g-interface-definition
174            #:get-g-class-definition
175            #:*strip-prefix*
176            #:*lisp-name-exceptions*
177            #:*additional-properties*
178            #:g-type=
179            #:g-type/=
180            #:define-g-boxed-cstruct
181            #:define-g-boxed-opaque
182            #:g-boxed-opaque
183            #:g-boxed-opaque-pointer
184            #:define-g-boxed-variant-cstruct
185            #:g-boxed-foreign
186            #:boxed-related-symbols
187            #:define-boxed-opaque-accessor
188            #:glib-defcallback
189            #:create-signal-handler-closure
190            #:save-handler-to-object
191            #:retrieve-handler-from-object
192            #:delete-handler-from-object
193            #:disconnect-signal
194            #:define-cb-methods
195            #:create-fn-ref
196            #:copy-boxed-slots-to-foreign
197            #:with-foreign-boxed-array
198            #:get-g-type-definition)
199   (:documentation
200    "CL-GTK2-GOBJECT is a binding to GObject type system.
201 For information on GObject, see its @a[http://library.gnome.org/devel/gobject/stable/]{documentation}.
202
203 CL-GTK2-GOBJECT is structured as follows:
204 @itemize{
205 @item{Binding to GObject API, providing low-level means to use functionality of GObject. This includes introspection facilities and means to invoke functionality of GObject.}
206 @item{GObject wrapper that bridges Lisp language with GObject API.}
207 }
208
209 @begin[GObject instrospection API]{section}
210 The base of GObject type system is GType. GType is a numerical value that is the unique identifier of a registered type.
211 Each GType has a name that is retrieved with @fun{g-type-name}. Conversely, GType can be retrieved from its name via @fun{g-type-from-name}.
212
213 There are several predefined GType values that correspond to fundamental or base types.
214 @begin{itemize}
215 @item{@variable{+g-type-invalid+}}
216 @item{@variable{+g-type-void+}}
217 @item{@variable{+g-type-interface+}}
218 @item{@variable{+g-type-char+}}
219 @item{@variable{+g-type-uchar+}}
220 @item{@variable{+g-type-boolean+}}
221 @item{@variable{+g-type-int+}}
222 @item{@variable{+g-type-uint+}}
223 @item{@variable{+g-type-long+}}
224 @item{@variable{+g-type-ulong+}}
225 @item{@variable{+g-type-int64+}}
226 @item{@variable{+g-type-uint64+}}
227 @item{@variable{+g-type-enum+}}
228 @item{@variable{+g-type-flags+}}
229 @item{@variable{+g-type-float+}}
230 @item{@variable{+g-type-double+}}
231 @item{@variable{+g-type-string+}}
232 @item{@variable{+g-type-pointer+}}
233 @item{@variable{+g-type-boxed+}}
234 @item{@variable{+g-type-param+}}
235 @item{@variable{+g-type-object+}}
236 @end{itemize}
237
238 GType values form type hierarchies via signle inheritance. Functions @fun{g-type-parent} and @fun{g-type-children} enable to traverse through the type hierarchy.
239
240 For some types, additional information is available. Functions @fun{class-properties} and @fun{interface-properties} return properties of classes and interfaces. Functions @fun{get-enum-items} and @fun{get-flags-items} return members of enum and flags types.
241
242 //TODO: document and refactor signals
243
244 @end{section}
245
246 @begin[GValue]{section}
247 GObject uses GValues as a generic way to pass values. It is used when calling closures, emitting signals, setting and getting properties' values, passing values to object constructors. @class{g-value} foreign structure is used for holding GValue. It used like all foreign structures: either with @code{cffi:foreign-alloc} or with @code{cffi:with-foreign-object}. Before first use, @class{g-value} should be zeroed with @fun{g-value-zero}. Zeroed @class{g-value} may be configured to hold a GValue of a given type with @fun{g-value-init}. @fun{parse-g-value} retrieves the Lisp object corresponding to the value stored in GValue. @fun{set-g-value} sets the GValue from Lisp object.
248 @end{section}"))
249
250 (in-package :gobject)
251
252 (defvar *gobject-debug* nil)
253
254 (defvar *debug-gc* nil)
255 (defvar *debug-subclass* nil)
256
257 (defvar *debug-stream* t)
258
259 (defmacro log-for (categories control-string &rest args)
260   (let ((vars (iter (for sym in (if (listp categories) categories (list categories)))
261                     (collect (intern (format nil "*DEBUG-~A*" (symbol-name sym)) (find-package :gobject))))))
262     `(progn
263        (when (or ,@vars)
264          (format *debug-stream* ,control-string ,@args))
265        nil)))