Added documentation about creating GObject classes
[cl-gtk2.git] / doc / gobject.texi
1 \input texinfo  @c -*-texinfo-*-
2 @c %**start of header (This is for running texinfo on a region.)
3 @setfilename gobject.info
4 @settitle CL-Gtk2-GObject
5 @c %**end of header (This is for running texinfo on a region.)
6
7 @c @documentencoding utf-8
8
9 @macro Function {args}
10 @defun \args\
11 @end defun
12 @end macro
13
14 @macro Macro {args}
15 @defmac \args\
16 @end defmac
17 @end macro
18
19 @macro Accessor {args}
20 @deffn {Accessor} \args\
21 @end deffn
22 @end macro
23
24 @macro GenericFunction {args}
25 @deffn {Generic Function} \args\
26 @end deffn
27 @end macro
28
29 @macro ForeignType {args}
30 @deftp {Foreign Type} \args\
31 @end deftp
32 @end macro
33
34 @macro Variable {args}
35 @defvr {Special Variable} \args\
36 @end defvr
37 @end macro
38
39 @macro Condition {args}
40 @deftp {Condition Type} \args\
41 @end deftp
42 @end macro
43
44 @macro cffi
45 @acronym{CFFI}
46 @end macro
47
48 @macro impnote {text}
49 @quotation
50 @strong{Implementor's note:} @emph{\text\}
51 @end quotation
52 @end macro
53
54 @c Info "requires" that x-refs end in a period or comma, or ) in the
55 @c case of @pxref.  So the following implements that requirement for
56 @c the "See also" subheadings that permeate this manual, but only in
57 @c Info mode.
58 @ifinfo
59 @macro seealso {name}
60 @ref{\name\}.
61 @end macro
62 @end ifinfo
63
64 @ifnotinfo
65 @alias seealso = ref
66 @end ifnotinfo
67
68 @c Typeset comments in roman font for the TeX output.
69 @iftex
70 @alias lispcmt = r
71 @end iftex
72 @ifnottex
73 @alias lispcmt = asis
74 @end ifnottex
75
76 @c My copy of makeinfo is not generating any HTML for @result{} for
77 @c some odd reason. (It certainly used to...)
78 @ifhtml
79 @macro result
80 =>
81 @end macro
82 @end ifhtml
83
84 @c Similar macro to @result. Its purpose is to work around the fact
85 @c that ⇒ does not work properly inside @lisp.
86 @ifhtml
87 @macro res
88 @html
89 ⇒
90 @end html
91 @end macro
92 @end ifhtml
93
94 @ifnothtml
95 @alias res = result
96 @end ifnothtml
97
98 @c ============================= Macros =============================
99
100
101 @c Show types, functions, and concepts in the same index.
102 @syncodeindex tp cp
103 @syncodeindex fn cp
104
105 @titlepage
106 @title CL-GTK2
107 @subtitle A Common Lisp binding for Gtk+
108 @subtitle GObject
109 @author Dmitry Kalyanov
110 @end titlepage
111
112 @contents
113
114 @ifnottex
115 @node Top
116 @top cl-gtk2-gobject
117 @end ifnottex
118
119 @menu
120 * Introduction::
121 * Installation::
122 * GType designator::
123 * Type hierarchy and type relations::
124 * Object types information::
125 * Enum types information::
126 * Using GValues::
127 * Stable pointers::
128 * Closures::
129 * GObject low-level::
130 * GObject high-level::
131 * Creating GObjects classes and implementing GInterfaces::
132 * GBoxed::
133 * Generating type definitions by introspection::
134 @end menu
135
136 @node Introduction
137 @chapter Introduction
138
139 GObject is a part of GLib library that implements the type system. The CL-GTK2-GObject is a Common Lisp binding for relevant parts of GObject.
140
141 The purpose of CL-GTK2-GObject is to ease the creation of binding for libraries based on GObject.
142
143 Please bear in mind that this is the documentation for a work-in-progress library and is a snapshot of current situation. API and functionality may (and will) change. Largely unfinished parts are working with GBoxed types, subclassing GObjects and implementing GInterfaces.
144
145 CL-GTK2-GObject is logically split into several layers:
146 @itemize
147 @item FFI code. FFI (foreign functions interface) layer is a glue between Lisp code and @code{libglib}, @code{libgobject}, @code{libgthread}. This code includes basic wrapper around GType designator (it is used everywhere and should be defined first) and definitions of foreign structures and imports foreign functions.
148 @item Low-level GObject integration. These are facilities provided by GObject that capture specific aspects of type system, object system and cross-language runtime. This includes types information, GValues (generic containers for value of any type supported by GObject type system), closures, means to create and use objects. This layer also includes some non-GObject facilities: stable pointers.
149 @item High-level GObject integration. This layer includes support for interoperability between CLOS and GObject and automatic generation of corresponding definitions.
150 @end itemize
151
152 Naturally, users of CL-GTK2-GObject should use the high-level GObject integration, but occasionaly it may be necessary to use lower-level functionality.
153
154 @node Installation
155 @chapter Installation
156
157 CL-GTK2-GObject comes as a part of CL-GTK2 bindings that are avaiable at its @uref{http://common-lisp.net/project/cl-gtk2/,,website}.
158
159 To use the CL-GTK2-GObject, download and install CL-GTK2 bindings and load the ASDF system @code{cl-gtk2-glib}.
160
161 CL-GTK2-GObject defines two packages: @code{gobject} and @code{gobject.ffi}. The @code{gobject.ffi} package contains definitions for low-level CFFI imports. The @code{gobject} package contains symbols for external API of this GObject binding.
162
163 @node GType designator
164 @chapter GType designator
165
166 @menu
167 * g-type-string::
168 * g-type-numeric::
169 * g-type=::
170 * g-type/=::
171 @end menu
172
173 GObject is an object system based on GType type system. Types in it are identified by an integer value of type @code{GType}. In @code{cl-gtk2-gobject}, types are identified by GType designators. GType designator is an integer (equal to corresponding GType identifier) or a string (equal to the name of corresponding type). The important difference between GType and GType designator is that GType values may change between program runs (all GTypes except fundamental GTypes will change values), but string GType designators do not change (because names of types do not change). As such, if ever GType must be saved in a code, string GType designator should be preferred.
174
175 An example of GType designator is a string @code{"GObject"} and the numeric value 80 that corresponds to it.
176
177 Some of the types are fundamental and have constant integer values. They are identified by constants (strings in parentheses are corresponding type names):
178 @itemize
179 @item @code{+g-type-invalid+}. An invalid GType used as error return value in some functions which return a GType.
180 @item @code{+g-type-void+} ("void"). A fundamental type which is used as a replacement for the C @code{void} return type.
181 @item @code{+g-type-interface+} ("GInterface"). The fundamental type from which all interfaces are derived.
182 @item @code{+g-type-char+} ("gchar"). The fundamental type corresponding to gchar. The type designated by @code{+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}.
183 @item @code{+g-type-uchar+} ("guchar"). The fundamental type corresponding to @code{guchar}.
184 @item @code{+g-type-boolean+} ("gboolean"). The fundamental type corresponding to @code{gboolean}.
185 @item @code{+g-type-int+} ("gint"). The fundamental type corresponding to @code{gint}.
186 @item @code{+g-type-uint+} ("guint"). The fundamental type corresponding to @code{guint}.
187 @item @code{+g-type-long+} ("glong"). The fundamental type corresponding to @code{glong}.
188 @item @code{+g-type-ulong+} ("gulong"). The fundamental type corresponding to @code{gulong}.
189 @item @code{+g-type-int64+} ("gint64"). The fundamental type corresponding to @code{gint64}.
190 @item @code{+g-type-uint64+} ("guint64"). The fundamental type corresponding to @code{guint64}.
191 @item @code{+g-type-enum+} ("GEnum"). The fundamental type from which all enumeration types are derived.
192 @item @code{+g-type-flags+} ("GFlags"). The fundamental type from which all flags types are derived.
193 @item @code{+g-type-float+} ("gfloat"). The fundamental type corresponding to @code{gfloat}.
194 @item @code{+g-type-double+} ("gdouble"). The fundamental type corresponding to @code{gdouble}.
195 @item @code{+g-type-string+} ("gchararray"). The fundamental type corresponding to null-terminated C strings.
196 @item @code{+g-type-pointer+} ("gpointer"). The fundamental type corresponding to @code{gpointer}.
197 @item @code{+g-type-boxed+} ("GBoxed"). The fundamental type from which all boxed types are derived.
198 @item @code{+g-type-param+} ("GParam"). The fundamental type from which all GParamSpec types are derived.
199 @item @code{+g-type-object+} ("GObject"). The fundamental type for GObject.
200 @end itemize
201
202 Functions @ref{g-type-string} and @ref{g-type-numeric} return the numeric and string representations of GType designators (given any of them). Functions @ref{g-type=} and @ref{g-type/=} check types for equality.
203
204 Invalid type (the GType that does not exist) is identified as a 0 or @code{NIL}.
205
206 @example
207 (g-type-numeric "GObject") @result{} 80
208 (g-type-numeric 80) @result{} 80
209 (g-type-string "GObject") @result{} "GObject"
210 (g-type-string 80) @result{} "GObject"
211 (g-type-numeric "GtkWidget") @result{} 6905648 ;;Will be different on each run
212 @end example
213
214 @node g-type-string
215 @section g-type-string
216
217 @code{(g-type-string g-type-designator) @result{} name}
218
219 @table @var
220 @item @var{g-type-designator}
221 The GType designator for the GType
222 @item @var{name}
223 The name of GType
224 @end table
225
226 Returns the name of GType.
227
228 @node g-type-numeric
229 @section g-type-numeric
230
231 @code{(g-type-numeric g-type-designator) @result{} GType}
232
233 @table @var
234 @item @var{g-type-designator}.
235 The GType designator for the GType.
236 @item @var{GType}
237 The numeric identifier of GType
238 @end table
239
240 Returns the numeric identifier of GType
241
242 @node g-type=
243 @section g-type=
244
245 @code{(g-type= type-1 type-2) @result{} eq}
246
247 @table @var
248 @item @var{type-1}
249 A GType designator
250 @item @var{type-2}
251 A GType designator
252 @item @var{eq}
253 A boolean that is true if @code{type-1} and @code{type-2} designate the same type.
254 @end table
255
256 @node g-type/=
257 @section g-type/=
258
259 @code{(g-type/= type-1 type-2) @result{} eq}
260
261 @table @var
262 @item @var{type-1}
263 A GType designator
264 @item @var{type-2}
265 A GType designator
266 @item @var{eq}
267 A boolean that is true if @code{type-1} and @code{type-2} designate different types.
268 @end table
269
270 @node Type hierarchy and type relations
271 @chapter Type hierarchy and type relations
272
273 @menu
274 * g-type-children::
275 * g-type-parent::
276 * g-type-fundamental::
277 * g-type-depth::
278 * g-type-next-base::
279 @end menu
280
281 GTypes are organized into hierarchy. Each GType (except fundamental types) has a parent type and zero or more children types. Parent of GType identified by @code{g-type-parent} function and its children are identified by @code{g-type-children} function.
282
283 There are functions to query some specific information:
284 @itemize
285 @item @code{g-type-fundamental} retrieves the fundamental type for given type
286 @item @code{g-type-depth} calculates the depth of the type in type hierarchy
287 @item @code{g-type-next-base} calculates the first step in the path from base type to descendent type
288 @end itemize
289
290 @node g-type-children
291 @section g-type-children
292
293 @code{(g-type-children type) @result{} children}
294 @table @var
295 @item @var{type}
296 A GType designator
297 @item @var{children}
298 A list of GType designators
299 @end table
300
301 Returns the list of descendent types.
302
303 Example:
304 @example
305 (g-type-children "GtkButton")
306 @result{}
307 ("GtkToggleButton" "GtkColorButton" "GtkFontButton" "GtkLinkButton" "GtkScaleButton")
308 @end example
309
310 @node g-type-parent
311 @section g-type-parent
312
313 @code{(g-type-parent type) @result{} parent}
314
315 @table @var
316 @item @var{type}
317 A GType designator
318 @item @var{parent}
319 A GType designator
320 @end table
321
322 Returns the parent of @code{type}.
323
324 Example:
325 @example
326 (g-type-parent "GtkToggleButton")
327 @result{}
328 "GtkButton"
329 @end example
330 @node g-type-fundamental
331 @section g-type-fundamental
332
333 @code{(g-type-fundamental type) @result{} fundamental-type}
334
335 @table @var
336 @item @var{type}
337 A GType designator
338 @item @var{fundamental-type}
339 A GType designator for one of the fundamental types
340 @end table
341
342 Returns the fundamental type that is the ancestor of @code{type}.
343
344 Example:
345 @example
346 (g-type-fundamental "GtkButton") @result{} "GObject"
347
348 (g-type-fundamental "GtkWindowType") @result{} "GEnum"
349
350 (g-type-fundamental "GdkEvent") @result{} "GBoxed"
351 @end example
352
353 @node g-type-depth
354 @section g-type-depth
355
356 @code{(g-type-depth type) @result{} depth}
357
358 @table @var
359 @item @var{type}
360 A GType designator
361 @item @var{depth}
362 An integer
363 @end table
364
365 Returns the depth of the @code{type}. Depth is the number of types between the @code{type} and its fundamental types (including both @code{type} and its fundamental type). Depth of a fundamental type equals to 1.
366
367 Example:
368 @example
369 (g-type-depth "GObject") @result{} 1
370 (g-type-depth "GInitiallyUnowned") @result{} 2
371 @end example
372
373 @node g-type-next-base
374 @section g-type-next-base
375
376 @code{(g-type-next-base leaf-type root-type) @result{} base-type}
377
378 @table @var
379 @item @var{leaf-type}
380 A GType designator
381 @item @var{root-type}
382 A GType designator
383 @item @var{base-type}
384 A GType designator
385 @end table
386
387 Returns the next type that should be traversed from @code{root-type} in order to reach @code{leaf-type}. E.g., given type hierarchy:
388 @example
389 + GObject
390  \
391   + GInitiallyUnowned
392    \
393     + GtkObject
394     |\
395     | + GtkAdjustment
396      \
397       + GtkWidget
398        \
399         + GtkContainer
400          \
401           + GtkTable
402 @end example
403
404 the following will be returned:
405
406 @example
407 (g-type-next-base "GtkTable" "GObject") @result{} "GInitiallyUnowned"
408 (g-type-next-base "GtkTable" "GInitiallyUnowned") @result{} "GtkObject"
409 (g-type-next-base "GtkTable" "GtkObject") @result{} "GtkWidget"
410 (g-type-next-base "GtkTable" "GtkWidget") @result{} "GtkContainer"
411 (g-type-next-base "GtkTable" "GtkContainer") @result{} "GtkTable"
412 @end example
413
414 @node Object types information
415 @chapter Object types information
416 @menu
417 * g-class-property-definition::
418 * class-properties::
419 * class-property-info::
420 * interface-properties::
421 * signal-info::
422 * type-signals::
423 * parse-signal-name::
424 * query-signal-info::
425 * g-type-interfaces::
426 * g-type-interface-prerequisites::
427 @end menu
428
429 GObject classes and interfaces have properties that can be queried with @code{class-properties}, @code{class-property-info} and @code{interface-properties}. These functions represent information about properties with instances of @code{g-class-property-definition} structure.
430
431 Information about signals can be queries with @code{type-signals}, @code{parse-signal-name} and @code{query-signal-info} functions. Information is returned within instances of @code{signal-info} structures.
432
433 @node g-class-property-definition
434 @section g-class-property-definition
435
436 @example
437 (defstruct g-class-property-definition
438   name
439   type
440   readable
441   writable
442   constructor
443   constructor-only
444   owner-type)
445 @end example
446
447 @table @var
448 @item @var{name}
449 A string that names the property
450 @item @var{type}
451 A GType designator. Identifies the type of the property
452 @item @var{readable}
453 A boolean. Identifies whether the property can be read
454 @item @var{writable}
455 A boolean. Identifies whether the property can be assigned
456 @item @var{constructor}
457 A boolean. Identifies whether constructor of object accepts this property
458 @item @var{constructor-only}
459 A boolean. Identifies whether this property may only be set in constructor, not in property setter
460 @item @var{owner-type}
461 A GType designator. Identifies the type on which the property was defined.
462 @end table
463
464 This structure identifies a single property. Its field specify attributes of a property.
465
466 Structures of this type have shortened print syntax:
467 @example
468 #<PROPERTY gchararray GtkButton.label (flags: readable writable constructor)> 
469 @end example
470
471 (When @code{*print-readably*} is T, usual @code{defstruct} print syntax is used)
472
473 This syntax specifies:
474 @itemize
475 @item type of property
476 @item the owner type of property
477 @item name of property
478 @item additional flags of property
479 @end itemize
480
481 @node class-properties
482 @section class-properties
483
484 @code{(class-properties type) @result{} properties}
485
486 @table @var
487 @item @var{type}
488 A GType designator. Specifies the object type (class)
489 @item @var{properties}
490 A list of @code{g-property-definition} structures.
491 @end table
492
493 This function returns the list of properties that are available in class @code{type}.
494
495 Example:
496 @example
497 (class-properties "GtkWidget")
498 @result{}
499 (#<PROPERTY gpointer GtkObject.user-data (flags: readable writable)>
500  #<PROPERTY gchararray GtkWidget.name (flags: readable writable)>
501  #<PROPERTY GtkContainer GtkWidget.parent (flags: readable writable)>
502  #<PROPERTY gint GtkWidget.width-request (flags: readable writable)>
503  #<PROPERTY gint GtkWidget.height-request (flags: readable writable)>
504  #<PROPERTY gboolean GtkWidget.visible (flags: readable writable)>
505  #<PROPERTY gboolean GtkWidget.sensitive (flags: readable writable)>
506  #<PROPERTY gboolean GtkWidget.app-paintable (flags: readable writable)>
507  #<PROPERTY gboolean GtkWidget.can-focus (flags: readable writable)>
508  #<PROPERTY gboolean GtkWidget.has-focus (flags: readable writable)>
509  #<PROPERTY gboolean GtkWidget.is-focus (flags: readable writable)>
510  #<PROPERTY gboolean GtkWidget.can-default (flags: readable writable)>
511  #<PROPERTY gboolean GtkWidget.has-default (flags: readable writable)>
512  #<PROPERTY gboolean GtkWidget.receives-default (flags: readable writable)>
513  #<PROPERTY gboolean GtkWidget.composite-child (flags: readable)>
514  #<PROPERTY GtkStyle GtkWidget.style (flags: readable writable)>
515  #<PROPERTY GdkEventMask GtkWidget.events (flags: readable writable)>
516  #<PROPERTY GdkExtensionMode GtkWidget.extension-events (flags: readable writable)>
517  #<PROPERTY gboolean GtkWidget.no-show-all (flags: readable writable)>
518  #<PROPERTY gboolean GtkWidget.has-tooltip (flags: readable writable)>
519  #<PROPERTY gchararray GtkWidget.tooltip-markup (flags: readable writable)>
520  #<PROPERTY gchararray GtkWidget.tooltip-text (flags: readable writable)>
521  #<PROPERTY GdkWindow GtkWidget.window (flags: readable)>)
522 @end example
523
524 @node class-property-info
525 @section class-property-info
526 @code{(class-property-info type property-name) @result{} property}
527
528 @table @var
529 @item @var{type}
530 A GType designator
531 @item @var{property-name}
532 A string naming the property
533 @item @var{property}
534 An instance of @code{g-property-definition} structure
535 @end table
536
537 Returns the property information for a single property.
538
539 Example:
540 @example
541 (class-property-info "GtkButton" "label")
542 @result{}
543 #<PROPERTY gchararray GtkButton.label (flags: readable writable constructor)>
544 @end example
545
546 @node interface-properties
547 @section interface-properties
548
549 @code{(interface-properties type) @result{} properties}
550
551 @table @var
552 @item @var{type}
553 A GType designator
554 @item @var{properties}
555 A list of @code{g-property-definition} structures
556 @end table
557
558 This function returns the list of properties that are available in interface @code{type}.
559
560 Example:
561 @example
562 (interface-properties "GtkFileChooser")
563 @result{}
564 (#<PROPERTY GtkWidget GtkFileChooser.extra-widget (flags: readable writable)>
565  #<PROPERTY gboolean GtkFileChooser.use-preview-label (flags: readable writable)>
566  #<PROPERTY gboolean GtkFileChooser.preview-widget-active (flags: readable writable)>
567  #<PROPERTY gboolean GtkFileChooser.show-hidden (flags: readable writable)>
568  #<PROPERTY gchararray GtkFileChooser.file-system-backend (flags: writable constructor-only)>
569  #<PROPERTY GtkFileChooserAction GtkFileChooser.action (flags: readable writable)>
570  #<PROPERTY GtkFileFilter GtkFileChooser.filter (flags: readable writable)>
571  #<PROPERTY gboolean GtkFileChooser.select-multiple (flags: readable writable)>
572  #<PROPERTY GtkWidget GtkFileChooser.preview-widget (flags: readable writable)>
573  #<PROPERTY gboolean GtkFileChooser.local-only (flags: readable writable)>
574  #<PROPERTY gboolean GtkFileChooser.do-overwrite-confirmation (flags: readable writable)>)
575 @end example
576
577 @node signal-info
578 @section signal-info
579
580 @example
581 (defstruct signal-info
582   id
583   name
584   owner-type
585   flags
586   return-type
587   param-types
588   detail)
589 @end example
590
591 @table @var
592 @item @var{id}
593 An integer - the identifier of a signal
594 @item @var{name}
595 Name of a signal
596 @item @var{owner-type}
597 A GType designator identifying the type on which the signal was defined
598 @item @var{flags}
599 A list of keywords of type @code{'(member :run-first :run-last :run-cleanup :no-recurse :detailed :action :no-hooks)}. Specifies the attributes of a signals
600 @item @var{return-type}
601 The return type of a signal (and signal handlers)
602 @item @var{param-types}
603 A list of GType designators that specify the types of signal parameters
604 @item @var{detail}
605 A string. Specifies the "detail" part of a signal name. E.g., @code{"label"} for signal @code{"notify::label"}.
606 @end table
607
608 When @code{*print-readably*} is nil, the following print syntax is used:
609 @example
610 #<Signal [#1] void GObject.notify::label(GParam) [RUN-FIRST, NO-RECURSE, DETAILED, ACTION, NO-HOOKS]>
611 #<Signal [#54] gboolean GtkWidget.proximity-in-event(GdkEvent) [RUN-LAST]>
612 #<Signal [#64] void GtkWidget.drag-data-received(GdkDragContext, gint, gint, GtkSelectionData, guint, guint) [RUN-LAST]>
613 #<Signal [#8] void GtkObject.destroy() [RUN-CLEANUP, NO-RECURSE, NO-HOOKS]>
614 @end example
615
616 This syntax specifies:
617 @itemize
618 @item the signal id
619 @item signal return type
620 @item owner type
621 @item signal name
622 @item detail
623 @item list of types of parameters
624 @item flags
625 @end itemize
626
627 @node type-signals
628 @section type-signals
629 @code{(type-signals type &key (include-inherited t)) @result{} signals}
630 @table @var
631 @item @var{type}
632 A GType designator
633 @item @var{signals}
634 A list of @code{signal-info} structures
635 @item @var{include-inherited}
636 A boolean that specifies whether to include signals defined on this type or also on ancestor types.
637 @end table
638
639 Returns the list of signals that are available in type @code{type}.
640
641 Example:
642 @example
643 (type-signals "GtkLabel" :include-inherited nil)
644 @result{}
645 (#<Signal [#138] void GtkLabel.move-cursor(GtkMovementStep, gint, gboolean) [RUN-LAST, ACTION]>
646  #<Signal [#139] void GtkLabel.copy-clipboard() [RUN-LAST, ACTION]>
647  #<Signal [#140] void GtkLabel.populate-popup(GtkMenu) [RUN-LAST]>)
648 @end example
649
650 @node parse-signal-name
651 @section parse-signal-name
652
653 @code{(parse-signal-name type signal-name) @result{} signal}
654
655 @table @var
656 @item @var{type}
657 A GType designator that has the signal.
658 @item @var{signal-name}
659 A string that identifies the signal.
660 @item @var{signal}
661 A list @code{signal-info} structures.
662 @end table
663
664 Parses the signal name and returns the corresponding information. @code{signal-name} may include the detail part.
665
666 Example:
667 @example
668 (parse-signal-name "GObject" "notify::label")
669 @result{}
670 #<Signal [#1] void GObject.notify::label(GParam) [RUN-FIRST, NO-RECURSE, DETAILED, ACTION, NO-HOOKS]>
671 @end example
672
673 @node query-signal-info
674 @section query-signal-info
675 @code{(query-signal-info signal-id) @result{} signal}
676 @table @var
677 @item @var{signal-id}
678 An integer identifying the signal
679 @item @var{signal}
680 An instance of @code{signal-info} structure
681 @end table
682
683 Retrieves the signal information by its id.
684
685 Example:
686 @example
687 (query-signal-info 73)
688 @result{}
689 #<Signal [#73] gboolean GtkWidget.show-help(GtkWidgetHelpType) [RUN-LAST, ACTION]>
690 @end example
691
692 @node g-type-interfaces
693 @section g-type-interfaces
694
695 @code{(g-type-interfaces type) @result{} interfaces}
696
697 @table @var
698 @item @var{type}
699 A GType designator
700 @item @var{interfaces}
701 A list of GType designators
702 @end table
703
704 Returns the list of interfaces that @code{type} implements.
705
706 Example:
707 @example
708 (g-type-interfaces "GtkButton")
709 @result{}
710 ("AtkImplementorIface" "GtkBuildable" "GtkActivatable")
711 @end example
712
713 @node g-type-interface-prerequisites
714 @section g-type-interface-prerequisites
715
716 @code{(g-type-interface-prerequisites type) @result{} types}
717
718 @table @var
719 @item @var{type}
720 A GType designator of interface
721 @item @var{types}
722 A list of GType designators specifying the interface prerequisites
723 @end table
724
725 Returns the prerequisites of an interface @code{type}. Prerequisite is a type that should be an ancestor of a type implementing interface @code{type}.
726
727 Example:
728 @example
729 (g-type-interface-prerequisites "GtkCellEditable")
730 @result{}
731 ("GtkObject" "GtkWidget")
732 @end example
733
734 @node Enum types information
735 @chapter Enum types information
736 @menu
737 * enum-item::
738 * flags-item::
739 * get-enum-items::
740 * get-flags-items::
741 @end menu
742
743 Enum types have items that can be listed with @code{get-enum-items} function. This information is exposed within instances of @code{enum-item} structure.
744
745 Flags types (flags is a kind of enum whose values can be combined) have items that can be queried with @code{get-flags-items} function. This information is exposed within instances of @code{flags-item} structure.
746
747 @node enum-item
748 @section enum-item
749 @example
750 (defstruct enum-item
751   name value nick)
752 @end example
753
754 @table @var
755 @item @var{name}
756 A string - name of enum item
757 @item @var{value}
758 An integer - numeric value of enum item
759 @item @var{nick}
760 A string - short name of an enum item
761 @end table
762
763 Structure @code{enum-item} represents a single item of an enumeration type.
764
765 Example:
766 @example
767 #S(ENUM-ITEM :NAME "GTK_WINDOW_TOPLEVEL" :VALUE 0 :NICK "toplevel")
768 @end example
769
770 @node flags-item
771 @section flags-item
772 @example
773 (defstruct flags-item
774   name value nick)
775 @end example
776
777 @table @var
778 @item @var{name}
779 A string - name of flags item
780 @item @var{value}
781 An integer - numeric value of flags item
782 @item @var{nick}
783 A string - short name of an flags item
784 @end table
785
786 Structure @code{flags-item} represents a single item of an flags type.
787
788 Example:
789 @example
790 #S(FLAGS-ITEM
791    :NAME "GDK_POINTER_MOTION_HINT_MASK"
792    :VALUE 8
793    :NICK "pointer-motion-hint-mask")
794 @end example
795
796 @node get-enum-items
797 @section get-enum-items
798
799 @code{(get-enum-items type) @result{} items}
800
801 @table @var
802 @item @var{type}
803 A GType designator of an enum type
804 @item @var{items}
805 A list of @code{enum-item} structures
806 @end table
807
808 Returns a list of items in an enumeration
809
810 Example:
811 @example
812 (get-enum-items "GtkScrollType")
813 @result{}
814 (#S(ENUM-ITEM :NAME "GTK_SCROLL_NONE" :VALUE 0 :NICK "none")
815  #S(ENUM-ITEM :NAME "GTK_SCROLL_JUMP" :VALUE 1 :NICK "jump")
816  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_BACKWARD" :VALUE 2 :NICK "step-backward")
817  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_FORWARD" :VALUE 3 :NICK "step-forward")
818  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_BACKWARD" :VALUE 4 :NICK "page-backward")
819  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_FORWARD" :VALUE 5 :NICK "page-forward")
820  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_UP" :VALUE 6 :NICK "step-up")
821  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_DOWN" :VALUE 7 :NICK "step-down")
822  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_UP" :VALUE 8 :NICK "page-up")
823  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_DOWN" :VALUE 9 :NICK "page-down")
824  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_LEFT" :VALUE 10 :NICK "step-left")
825  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_RIGHT" :VALUE 11 :NICK "step-right")
826  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_LEFT" :VALUE 12 :NICK "page-left")
827  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_RIGHT" :VALUE 13 :NICK "page-right")
828  #S(ENUM-ITEM :NAME "GTK_SCROLL_START" :VALUE 14 :NICK "start")
829  #S(ENUM-ITEM :NAME "GTK_SCROLL_END" :VALUE 15 :NICK "end"))
830 @end example
831
832 @node get-flags-items
833 @section get-flags-items
834
835 @code{(get-flags-items type) @result{} items}
836
837 @table @var
838 @item @var{type}
839 A GType designator of an flags type
840 @item @var{items}
841 A list of @code{flags-item} structures
842 @end table
843
844 Returns a list of items in an flags type
845
846 Example:
847 @example
848 (get-flags-items "GtkAttachOptions")
849 @result{}
850 (#S(FLAGS-ITEM :NAME "GTK_EXPAND" :VALUE 1 :NICK "expand")
851  #S(FLAGS-ITEM :NAME "GTK_SHRINK" :VALUE 2 :NICK "shrink")
852  #S(FLAGS-ITEM :NAME "GTK_FILL" :VALUE 4 :NICK "fill"))
853 @end example
854
855 @node Using GValues
856 @chapter Using GValues
857 @menu
858 * g-value-zero::
859 * g-value-init::
860 * g-value-unset::
861 * parse-g-value::
862 * set-g-value::
863 * Registering types::
864 @end menu
865
866 GValue is a generic container for arbitrary value of type supported by GType system. Refer to GObject documentation for more detailed information.
867
868 CL-GTK2-GOBJECT works with GValue as a foreign type @code{g-value}. Functions @code{g-value-zero}, @code{g-value-type}, @code{g-value-init}, @code{parse-g-value}, @code{set-g-value} are used to inspect and assign GValues. @code{g-value} is a CFFI foreign type that is used by all these functions. Pointer to foreign instance of this type is passed to them.
869
870 GValue is used whenever a value of unkown type should be passed. It is used in:
871 @itemize
872 @item Closure marshal functions
873 @item Property get and set functions
874 @end itemize
875
876 Example of usage:
877 @example
878 (cffi:with-foreign-object (gval 'g-value)
879   (set-g-value gval "Hello" "gchararray" :zero-g-value t)
880   (format t "~S~%" (parse-g-value gval))
881   (g-value-unset gval))
882 @result{}
883 "Hello"
884 @end example
885
886 @node g-value-zero
887 @section g-value-zero
888 @code{(g-value-zero g-value)}
889 @table @var
890 @item @var{g-value}
891 A foreign pointer to GValue structure.
892 @end table
893
894 Initializes the GValue to "unset" state. Equivalent of the following initializer in C:
895 @example
896 GValue value = @{ 0 @};
897 @end example
898
899 Must be called before other functions that work with GValue (except @code{set-g-value} with keyword argument @code{:zero-g-value} set to true).
900
901 @node g-value-init
902 @section g-value-init
903
904 @code{(g-value-init value type)}
905 @table @var
906 @item @var{value}
907 A foreign pointer to GValue structure
908 @item @var{type}
909 A GType designator
910 @end table
911
912 Initializes the GValue to store instances of type @code{type}. Must be called before other functions operate on GValue (except @code{g-value-zero} and @code{set-g-value} with keyword argument @code{:g-value-init} set to true).
913
914 @node g-value-unset
915 @section g-value-unset
916 @code{(g-value-unset value)}
917 @table @var
918 @item @var{value}
919 A foreign pointer to GValue structure.
920 @end table
921
922 Unsets the GValue. This frees all resources associated with GValue.
923
924 @node parse-g-value
925 @section parse-g-value
926 @code{(parse-g-value value) @result{} object}
927 @table @var
928 @item @var{value}
929 A foreign pointer to GValue structure
930 @item @var{object}
931 A Lisp object
932 @end table
933
934 Retrieves the object from GValue structure.
935
936 @node set-g-value
937 @section set-g-value
938 @code{(set-g-value gvalue object type &key zero-g-value unset-g-value (g-value-init t))}
939
940 @table @var
941 @item @var{gvalue}
942 A foreign pointer to GValue structure
943 @item @var{object}
944 An object that is to be assigned to @code{gvalue}
945 @item @var{type}
946 A GType designator specifying what GType should be set
947 @item @var{unset-g-value}
948 A boolean specifying whether to call @code{g-value-unset} before assigment.
949 @item @var{zero-g-value}
950 A boolean specifying whether to call @code{g-value-zero} before assignment
951 @item @var{g-value-init}
952 A boolean specifying whether to call @code{g-value-init} before assignment
953 @end table
954
955 Assigns the @code{object} to the @code{gvalue}. When GValue is not used, call @code{g-value-unset} to deinitialize the @code{GValue}.
956
957 @node Registering types
958 @section Registering types
959
960 In order to be able to parse GValues and set them, it is necessary for GValue binding to know type mapping between GObject types and Lisp types. Type registration serves to this purpose.
961
962 GEnum and GFlags are mapped to CFFI @code{defcenum} and @code{defbitfield} types. Functions @code{register-enum-type} and @code{register-flags-type} add the type to the mapping.
963
964 @subsection
965 @code{(register-enum-type name type)}
966 @table @var
967 @item @var{name}
968 A string naming the GEnum type
969 @item @var{type}
970 A symbol - name of CFFI foreign enum type
971 @end table
972
973 Registers the @code{type} to be used for passing value of GEnum type @code{name} between GObject and Lisp.
974
975 Example:
976 @example
977 (defcenum text-direction
978   :none :ltr :rtl)
979 (register-enum-type "GtkTextDirection" 'text-direction)
980 @end example
981
982 @subsection
983 @code{(register-flags-type name type)}
984 @table @var
985 @item @var{name}
986 A string naming the GFlags type
987 @item @var{type}
988 A symbol - name of CFFI foreign flags type
989 @end table
990
991 Registers the @code{type} to be used for passing value of GFlags type @code{name} between GObject and Lisp.
992
993 Example:
994 @example
995 (defcenum state-type
996   :normal :active :prelight :selected :insensitive)
997 (register-enum-type "GtkStateType" 'state-type)
998 @end example
999
1000 @node Stable pointers
1001 @chapter Stable pointers
1002 @menu
1003 * allocate-stable-pointer::
1004 * free-stable-pointer::
1005 * stable-pointer-value::
1006 * with-stable-pointer::
1007 @end menu
1008
1009 Sometimes it is necessary to pass arbitrary Lisp object to C code and then receive it back. Stable pointer serve to this purpose. Stable pointer is an integer (that is passed to C code as a @code{void*} pointer) that is created on Lisp side by call to @code{allocate-stable-pointer} and can be dereferenced by Lisp side at any time by calling @code{stable-pointer-value}. Stable pointer exists and does not change its value until explicitly freed by calling @code{free-stable-poitner}. Convenience macro @code{with-stable-pointer} binds the stable pointer for the duration of its body.
1010
1011 @node allocate-stable-pointer
1012 @section allocate-stable-pointer
1013
1014 @code{(allocate-stable-pointer thing) @result{} stable-pointer}
1015
1016 @table @var
1017 @item @var{thing}
1018 An arbitrary Lisp object
1019 @item @var{stable-pointer}
1020 A foreign pointer
1021 @end table
1022
1023 Allocates a stable pointer to @code{thing}.
1024
1025 (Note: @var{stable-pointer} should not be dereferenced with @code{cffi:mem-ref}. It should only be dereferenced with @code{stable-pointer-value})
1026
1027 Example:
1028 @example
1029 (allocate-stable-pointer (lambda (x) (+ x 10)))
1030 @result{}
1031 #.(SB-SYS:INT-SAP #X00000002)
1032
1033 (stable-pointer-value *)
1034 @result{}
1035 #<FUNCTION (LAMBDA (X)) @{1004D016F9@}>
1036
1037 (free-stable-pointer **)
1038 @result{}
1039 NIL
1040 @end example
1041
1042 @node free-stable-pointer
1043 @section free-stable-pointer
1044
1045 @code{(free-stable-pointer stable-pointer)}
1046
1047 @table @var
1048 @item @var{stable-pointer}
1049 A foreign pointer that was created with @code{allocate-stable-pointer}.
1050 @end table
1051
1052 Frees the stable pointer, enabling the garbage collector to reclaim the object.
1053
1054 Example:
1055 @example
1056 (allocate-stable-pointer (lambda (x) (+ x 10)))
1057 @result{}
1058 #.(SB-SYS:INT-SAP #X00000002)
1059
1060 (stable-pointer-value *)
1061 @result{}
1062 #<FUNCTION (LAMBDA (X)) @{1004D016F9@}>
1063
1064 (free-stable-pointer **)
1065 @result{}
1066 NIL
1067 @end example
1068
1069 @node stable-pointer-value
1070 @section stable-pointer-value
1071
1072 @example
1073 (stable-pointer-value stable-pointer) @result{} thing
1074 (setf (stable-pointer-value stable-pointer) thing)
1075 @end example
1076
1077 @table @var
1078 @item @var{stable-pointer}
1079 A foreign pointer created by @code{allocate-stable-pointer}
1080 @item @var{thing}
1081 A Lisp object
1082 @end table
1083
1084 Dereferences a @code{stable-pointer}, returning the stable pointer value. @code{stable-pointer-value} is a SETFable form, SETFing it sets the stable pointer's value to new value.
1085
1086 @node with-stable-pointer
1087 @section with-stable-pointer
1088
1089 @code{(with-stable-pointer (ptr expr) &body body)}
1090
1091 @table @var
1092 @item @var{ptr}
1093 A variable that will be bound to the stable pointer
1094 @item @var{expr}
1095 An expression that will be evaluated once and its value will be bound to stable pointer's value
1096 @end table
1097
1098 Executes the body with the @code{ptr} variable being bound to a stable pointer whose value is determined by @code{expr}.
1099
1100 Example:
1101 @example
1102 (with-stable-pointer (ptr (lambda (x) (+ x 10)))
1103   (print (stable-pointer-value ptr)))
1104 ;;Prints:
1105 #<FUNCTION (LAMBDA (X)) @{1004807E79@}>
1106 @end example
1107
1108 @node Closures
1109 @chapter Closures
1110
1111 Closure are anonymous functions that capture their lexical environment.
1112
1113 GObject supports using closures (as instances of type GClosure) as signal handlers and in some other places where a function is expected. Function @code{create-g-closure} create closure from lisp function. The GClosure is finalized automatically when GObject no longer needs it (e.g., when GClosure is disconnected from signal).
1114
1115 @section create-g-closure
1116 @code{(create-g-closure fn) @result{} closure}
1117
1118 @table @var
1119 @item @var{fn}
1120 A function that will be called by closure invokation
1121 @item @var{closure}
1122 A foreign pointer to allocated closure
1123 @end table
1124
1125 Allocates the closure. The closure is destroyed automatically by GObject.
1126
1127 Example:
1128 @example
1129 (create-g-closure (lambda (x) (+ x 10)))
1130 @result{}
1131 #.(SB-SYS:INT-SAP #X006D7B20)
1132 @end example
1133
1134 Example of usage from GObject binding code:
1135 @example
1136 (defun connect-signal (object signal handler &key after)
1137   (g-signal-connect-closure (ensure-object-pointer object)
1138                             signal
1139                             (create-g-closure handler)
1140                             after))
1141 @end example
1142
1143 (TODO: GObject defines finer closure API: g_closure_ref, g_closure_unref, g_closure_invoke. It should be bound.)
1144
1145 @node GObject low-level
1146 @chapter GObject low-level
1147 @menu
1148 * g-object-call-constructor::
1149 * g-type-from-object::
1150 * g-object-call-get-property::
1151 * g-object-call-set-property::
1152 @end menu
1153
1154 GObject low-level support includes facilities for working with objects as foreign pointers and using explicit function to get and set properties. This low-level support does not deal with integration of GObject with CLOS; GObject high-level support does that.
1155
1156 Function @code{g-type-from-object} identifies the type of the object. Function @code{g-object-call-get-property} retrieves the value of the property and function @code{g-object-call-set-property} sets the value of the property. Function @code{g-object-call-constructor} calls the constructor of the GObject type.
1157
1158 @node g-object-call-constructor
1159 @section g-object-call-constructor
1160
1161 @code{(g-object-call-constructor object-type args-names args-values &optional args-types) @result{} object-ptr}
1162
1163 @table @var
1164 @item @var{object-type}
1165 A GType designator that specifies the object type that is to be created
1166 @item @var{args-names}
1167 A list of strings naming the arguments to constructor
1168 @item @var{args-value}
1169 A list of arguments values (in the same order as args-names)
1170 @item @var{args-types}
1171 Optional list of arguments types (in the same order as args-names). If not specified, it is detected automatically
1172 @item @var{object-ptr}
1173 A foreign pointer to newly created instance
1174 @end table
1175
1176 Creates the object of type @code{object-type} by calling its constructors with arguments specified by @code{args-names}, @code{args-values}, @code{args-types}.
1177
1178 Example:
1179 @example
1180 (g-object-call-constructor "GtkButton" '("label" "use-underline") '("Hello" t) '("gchararray" "gboolean"))
1181 @result{}
1182 #.(SB-SYS:INT-SAP #X006D8900)
1183
1184 (g-object-call-get-property * "label")
1185 @result{}
1186 "Hello"
1187
1188 (g-object-call-get-property ** "use-underline")
1189 @result{}
1190 T
1191 @end example
1192
1193 @node g-type-from-object
1194 @section g-type-from-object
1195
1196 @code{(g-type-from-object object-ptr) @result{} type}
1197
1198 @table @var
1199 @item @var{object-ptr}
1200 A foreign pointer to a GObject instance
1201 @item @var{type}
1202 A GType designator
1203 @end table
1204
1205 Returns the type of an object by a pointer to its instance
1206
1207 Example:
1208 @example
1209 (g-type-from-object (g-object-call-constructor "GtkButton" nil nil))
1210 @result{}
1211 "GtkButton"
1212 @end example
1213
1214 @node g-object-call-get-property
1215 @section g-object-call-get-property
1216
1217 @code{(g-object-call-get-property object-ptr property-name &optional property-type) @result{} property-value}
1218
1219 @table @var
1220 @item @var{object-ptr}
1221 A foreign pointer to a GObject instance
1222 @item @var{property-name}
1223 A string naming the property
1224 @item @var{property-type}
1225 Optional GType designator specifying the type of a property
1226 @item @var{property-value}
1227 The value of a property
1228 @end table
1229
1230 Retrieves the value of a property @code{property-name} of object pointed to by @code{object-ptr}. @code{property-type} specifies the type of a property; it may be omitted.
1231
1232 Example:
1233 @example
1234 (g-object-call-constructor "GtkButton" '("label" "use-underline") '("Hello" t) '("gchararray" "gboolean"))
1235 @result{}
1236 #.(SB-SYS:INT-SAP #X006D8900)
1237
1238 (g-object-call-get-property * "label")
1239 @result{}
1240 "Hello"
1241
1242 (g-object-call-get-property ** "use-underline")
1243 @result{}
1244 T
1245 @end example
1246
1247 @node g-object-call-set-property
1248 @section g-object-call-set-property
1249
1250 @code{(g-object-call-set-property object-ptr property-name new-value &optional property-type)}
1251
1252 @table @var
1253 @item @var{object-ptr}
1254 A foreign pointer to a GObject instance
1255 @item @var{property-name}
1256 A string naming the property
1257 @item @var{new-value}
1258 A new value of a property
1259 @item @var{property-type}
1260 Optional GType designator specifying the type of a property
1261 @end table
1262
1263 Sets the property value of property @code{property-name} of object @code{object-ptr} to @code{new-value}.
1264
1265 Example:
1266 @example
1267 (g-object-call-constructor "GtkButton" nil nil)
1268 @result{}
1269 #.(SB-SYS:INT-SAP #X006D8B40)
1270
1271 (g-object-call-set-property * "label" "Hello")
1272 @result{}
1273 ; No value
1274
1275 (g-object-call-get-property ** "label")
1276 @result{}
1277 "Hello"
1278 @end example
1279
1280 @node GObject high-level
1281 @chapter GObject high-level
1282 @menu
1283 * GObject metaclass::
1284 * Using objects::
1285 * Signals::
1286 * GObject foreign class::
1287 @end menu
1288
1289 GObject high-level support includes integration of GObject and CLOS systems. This enables to use GObjects classes as CLOS classes (with support from @code{gobject-class} metaclass):
1290 @itemize
1291 @item objects are created with @code{make-instance}
1292 @item properties are used as regular slots
1293 @end itemize
1294
1295 GObjects are reference counted, and CL-GTK2-GOBJECT manages its own reference to GObjects. This enables to have transparent garbage collection of unreferenced GObjects.
1296
1297 To be able to use particular GObject class with CLOS, it should be defined and registered. This is accomplished by @code{defclass}'ing it with @code{gobject-class} metaclass. After GObject class is defined, it may be used as CLOS class.
1298
1299 Example GObject class of definition:
1300 @example
1301 (defclass dialog (gtk-window atk-implementor-iface buildable)
1302   ((has-separator :accessor dialog-has-separator
1303                   :initarg :has-separator
1304                   :allocation :gobject-property
1305                   :g-property-type "gboolean"
1306                   :g-property-name "has-separator"))
1307   (:metaclass gobject-class)
1308   (:g-type-name . "GtkDialog")
1309   (:g-type-initializer . "gtk_dialog_get_type"))
1310 @end example
1311
1312 This example defines the CLOS class @code{dialog} that corresponds to GObject class @code{GtkDialog}. Whenever object of GObject type @code{GtkDialog} are to be received from foreign functions or passed to foreign functions, it will be mapped to CLOS class @code{dialog}. Properties that have @code{:allocation} of @code{:gobject-property} are mapped to GObject properties, and reading or writing this slot reads or writes corresponding GObject class property.
1313
1314 GObject does not expose objects methods. Because of this, methods are not automatically mapped to CLOS generic functions and methods. Methods should be manually wrapped with CFFI as foreign functions. Foreign type @code{g-object} aids in it. This type automatically wraps (and unwraps) the GObject class instances and handles the reference counting.
1315
1316 GObject high-level support enables connect signals to signal handlers. Any function may be connected as a signal handler, and GObject will release the reference on signal handler whenever it become unneded (e.g., when object is destroyed or handler is disconnected).
1317
1318 @node GObject metaclass
1319 @section GObject metaclass
1320
1321 See MOP for information what metaclass is and why is it useful.
1322
1323 GObject metaclass @code{gobject-class} bridges two object systems: GObject and CLOS.
1324
1325 Classes that correspond to GObject classes are instances of this class.
1326
1327 Defining the class with metaclass @code{gobject-class} registers the type @code{:g-type-name} for conversions using GValue and CFFI foreign type @code{g-object}.
1328
1329 This class has the following slots:
1330 @itemize
1331 @item @var{g-type-name} (accessor @code{gobject-class-g-type-name}, initarg @code{:g-type-name})
1332
1333 Specifies the name of GObject class
1334 @item @var{g-type-initializer} (accessor @code{gobject-class-g-type-initializer}, initarg @code{:g-type-initializer})
1335
1336 Name of type initializer function. This function initializes the class and returns its GType. Typically it is named @code{class_get_type}.
1337 @item @var{interface-p} (accessor @code{gobject-class-interface-p}, initarg @code{:interface-p})
1338
1339 A boolean specifying whether this CLOS class corresponds to GInterface.
1340 @end itemize
1341
1342 This metaclass defines the GObject classes.
1343
1344 Slots which have @code{:allocation} of @code{:gobject-property} are mapped to GObject properties. Such slots have following attributes:
1345 @itemize
1346 @item @var{:g-property-type}
1347
1348 A string naming GType of property
1349 @item @var{:g-property-name}
1350
1351 A name of a property
1352 @end itemize
1353
1354 Slots which have @code{:allocation} of @code{:gobject-fn} are mapped to a pair of accessor functions (usually named @code{class_get_property} and @code{class_set_property}). This is included because some properties are not exposed as GObject properties. Such slots have following attributes:
1355 @itemize
1356 @item @var{:g-property-type}
1357 A CFFI foreign type of property
1358 @item @var{:g-getter}
1359 A string naming foreign getter function of a property or a symbol designating Lisp getter function. Foreign getter function should have signature @code{type class_get_property(object *)}. Lisp function should be of type @code{(function (class) type)}.
1360 @item @var{:g-setter}
1361 A string naming foreign setter function of a property or a symbol designating Lisp setter function. Foreign setter function should have signature @code{void class_set_property(object *, type)}. Lisp function should be of type @code{(function (class type))}.
1362 @end itemize
1363
1364 Initargs of a slot are used to construct the GObject class.
1365
1366 Example:
1367 @example
1368 (defclass container (widget atk-implementor-iface buildable)
1369     ((border-width :allocation :gobject-property
1370                    :g-property-type "guint"
1371                    :accessor container-border-width
1372                    :initarg :border-width
1373                    :g-property-name "border-width")
1374      (resize-mode :allocation :gobject-property
1375                   :g-property-type "GtkResizeMode"
1376                   :accessor container-resize-mode
1377                   :initarg :resize-mode
1378                   :g-property-name "resize-mode")
1379      (child :allocation :gobject-property
1380             :g-property-type "GtkWidget"
1381             :accessor container-child
1382             :initarg :child
1383             :g-property-name "child")
1384      (focus-child :allocation :gobject-fn
1385                   :g-property-type g-object
1386                   :accessor container-focus-child
1387                   :initarg :focus-child
1388                   :g-getter "gtk_container_get_focus_child"
1389                   :g-setter "gtk_container_set_focus_child")
1390      (focus-vadjustment :allocation :gobject-fn
1391                         :g-property-type (g-object adjustment)
1392                         :accessor container-focus-vadjustment
1393                         :initarg :focus-vadjustment
1394                         :g-getter "gtk_container_get_focus_vadjustment"
1395                         :g-setter "gtk_container_set_focus_vadjustment")
1396      (focus-hadjustment :allocation :gobject-fn
1397                         :g-property-type (g-object adjustment)
1398                         :accessor container-focus-hadjustment
1399                         :initarg :focus-hadjustment
1400                         :g-getter "gtk_container_get_focus_hadjustment"
1401                         :g-setter "gtk_container_set_focus_hadjustment"))
1402     (:metaclass gobject-class)
1403     (:g-type-name . "GtkContainer")
1404     (:g-type-initializer . "gtk_container_get_type"))
1405 @end example
1406 (note the dot in @code{(:g-type-name . "GtkContainer")} and in @code{(:g-type-initializer . "gtk_container_get_type")}. It should be present)
1407
1408 @node Using objects
1409 @section Using objects
1410 Instances are created with @code{make-instance}. If initargs of GObject properties are supplied, they are passed to constructor. Some slots (properties) may only be set at construction time (e.g., @code{type} property of @code{GtkWindow}). Properties may be accessed (read or assigned) with defined @code{:accessor}, @code{:reader} or @code{:writer} functions.
1411
1412 Example:
1413 @example
1414 (make-instance 'gtk:dialog :has-separator t)
1415 @result{}
1416 #<GTK:DIALOG @{10036C5A71@}>
1417
1418 (defvar *d* (make-instance 'gtk:dialog :has-separator t))
1419 @result{}
1420 *D*
1421
1422 (gtk:dialog-has-separator *d*)
1423 @result{}
1424 T
1425
1426 (setf (gtk:dialog-has-separator *d*) nil)
1427 @result{}
1428 NIL
1429
1430 (gtk:dialog-has-separator *d*)
1431 @result{}
1432 NIL
1433 @end example
1434
1435 @node Signals
1436 @section Signals
1437
1438 To connect handler to a signal, @code{connect-signal} function is used.
1439
1440 @code{(connect-signal object signal handler &key after)}
1441
1442 @table @var
1443 @item @var{object}
1444 An instance of GObject object
1445 @item @var{signal}
1446 A signal name
1447 @item @var{handler}
1448 A function
1449 @item @var{after}
1450 A boolean specifying whether the handler should be called after the default handler
1451 @end table
1452
1453 Connects the @code{handler} to signal @code{signal} on object @code{object}. Signature of @code{handler} should comply with signature of a signal. @code{handler} will be called with arguments of type specified by signal with the object (on which the signal was emitted) prepended to them and it should return the value of the signal's return type.
1454
1455 Example:
1456 @example
1457 (defvar *d* (make-instance 'gtk:dialog))
1458 @result{}
1459 *D*
1460
1461 *d*
1462 @result{}
1463 #<GTK:DIALOG @{1002D866F1@}>
1464
1465 (parse-signal-name "GtkDialog" "response")
1466 @result{}
1467 #<Signal [#86] void GtkDialog.response(gint) [RUN-LAST]>
1468
1469 (connect-signal *d* "response" (lambda (dialog response-value) (print dialog) (print response-value)))
1470
1471 (emit-signal *d* "response" 14)
1472 @result{}
1473 ;; Prints:
1474 #<GTK:DIALOG @{1002D866F1@}>
1475 14 
1476 @end example
1477
1478 Function @code{emit-signal} is used to emit signals on objects.
1479
1480 @code{(emit-signal object signal-name &rest args) @result{} return-value}
1481
1482 @table @var
1483 @item @var{object}
1484 An object on which the signal should be emitted
1485 @item @var{signal-name}
1486 A string naming the signal
1487 @item @var{args}
1488 Arguments for a signal
1489 @item @var{return-value}
1490 Return value of a signal
1491 @end table
1492
1493 Emits the signal and calls all handlers of the signal. If signal returns a value, it is returned from @code{emit-signal}.
1494
1495 Example:
1496 @example
1497 (defvar *d* (make-instance 'gtk:dialog))
1498 @result{}
1499 *D*
1500
1501 *d*
1502 @result{}
1503 #<GTK:DIALOG @{1002D866F1@}>
1504
1505 (parse-signal-name "GtkDialog" "response")
1506 @result{}
1507 #<Signal [#86] void GtkDialog.response(gint) [RUN-LAST]>
1508
1509 (connect-signal *d* "response" (lambda (dialog response-value) (print dialog) (print response-value)))
1510
1511 (emit-signal *d* "response" 14)
1512 @result{}
1513 ;; Prints:
1514 #<GTK:DIALOG @{1002D866F1@}>
1515 14 
1516 @end example
1517
1518 @node GObject foreign class
1519 @section GObject foreign class
1520
1521 To enable passing GObject instance between Lisp code and foreign code, @code{g-object} foreign type is introduced.
1522
1523 This type has the following syntax:
1524 @code{(g-object &optional type)} or @code{g-object}.
1525
1526 When the @code{g-object} foreign type is specified as a return type of a function, the value is converted to instance of corresponding CLOS class. If @code{type} is specified then it is checked that object is of this type.
1527
1528 When the @code{g-object} foreign type is specified as a type of function's argument, the value is converted to pointer to GObject. If @code{type} is specified then it is checked that the object is of this type.
1529
1530 This defines the function that may be called with instances of types @code{container} and @code{widget}:
1531 @example
1532 (defcfun (container-add "gtk_container_add") :void
1533   (container (g-object container))
1534   (widget (g-object widget)))
1535
1536 (let ((window (make-instance 'gtk-window))
1537       (widget (make-instance 'button)))
1538   (container-add window widget))
1539 @end example
1540 (@code{gtk-window} is a subclass of @code{container}; @code{button} is a subclass of @code{widget})
1541
1542 This defines the function that returns an instance of GObject class:
1543 @example
1544 (defcfun (bin-child "gtk_bin_get_child") (g-object widget)
1545   (bin (g-object bin)))
1546
1547 (let ((window (make-instance 'gtk-window))
1548       (widget (make-instance 'button)))
1549   (container-add window widget)
1550   (bin-child window))
1551 @result{}
1552 #<GTK:BUTTON @{1002DE74B1@}>
1553 @end example
1554
1555 @node Creating GObjects classes and implementing GInterfaces
1556 @chapter Creating GObjects classes and implementing GInterfaces
1557
1558 @menu
1559 * define-vtable::
1560 * register-object-type-implementation::
1561 @end menu
1562
1563 Creating GObject classes from Lisp is the most complex part of GObject binding.
1564
1565 GObject binding at the moment provides only limited scenarios of creating GObject classes. It lets register GObject class (as a subclass of another class or of GObject), specify its properties and implemented interfaces. Each property is associated with Lisp getter and setter functions. Each interface is associated wth vtable (table of virtual function pointers, see @uref{http://en.wikipedia.org/wiki/Vtable}) that specifies a list of methods and their signatures. If class is ever created from GObject side (not from Lisp side, must be constructable with no parameters).
1566
1567 Each virtual function is mapped to a generic function for which class should provide a specialized method. This function should not be called by user. Rather, user code should call corresponding foreign function.
1568
1569 Practically speaking, creating GObject class requires defining CLOS class that correspond to GObject class and calling @code{register-object-type-implementation} with information about the class (its GType name, superclass, interfaces and properties).
1570
1571 Interface that is implemented by a class should have its vtable defined by @code{define-vtable}. Vtable definitions consists of a list of functions's names and signatures and their locations in vtable.
1572
1573 Unfortunately, GObject does not provide information about vtables, and does not support using GClosures to implement virtual functions. Therefore, implementation for all interface's functions are defined as CFFI foreign callbacks. These callbacks in turn call corresponding generic functions that should be specialized on required objects.
1574
1575 @node define-vtable
1576 @section define-vtable
1577
1578 @example
1579 (define-vtable (type-name cstruct-name)
1580   &body item*)
1581
1582 item ::= (name callback-name return-type &rest arg*)
1583 item ::= (:skip cffi-structure-item)
1584 arg ::= (arg-name arg-type)
1585 @end example
1586
1587 @table @var
1588 @item @var{type-name}
1589 A string naming the GObject type of interface
1590 @item @var{cstruct-name}
1591 A name for a generated CFFI foreign structure
1592 @item @var{name}
1593 A name for implementation generic function
1594 @item @var{callback-name}
1595 A name for generated callback function
1596 @item @var{return-type}
1597 A CFFI specifier for foreign function return type
1598 @item @var{arg-name}
1599 A symbol naming the argument of interface method
1600 @item @var{arg-type}
1601 A CFFI specifier for foreign function argument type
1602 @end table
1603
1604 Macro that specifies the vtable for an interface. This macro defines generic functions (named by @code{name}) that correspond to methods of an interface. On these generic functions methods should be defined that implement the interface method. @code{item}s specify the CFFI foreign structure for vtable. Vtable contains not only function pointers, but other slots. Such slots should be specified here with @code{:skip} prepended to them. This is needed to be able to correctly calculate offsets to function pointers in vtable.
1605
1606 Example:
1607 @example
1608 (define-vtable ("GtkTreeModel" c-gtk-tree-model)
1609   (:skip parent-instance g-type-interface)
1610   ;;some signals
1611   (:skip tree-model-row-changed :pointer)
1612   (:skip tree-model-row-inserted :pointer)
1613   (:skip tree-model-row-has-child-toggled :pointer)
1614   (:skip tree-model-row-deleted :pointer)
1615   (:skip tree-model-rows-reordered :pointer)
1616   ;;methods
1617   (tree-model-get-flags-impl tree-model-get-flags-cb
1618     tree-model-flags (tree-model g-object))
1619   (tree-model-get-n-columns-impl tree-model-get-n-columns-cb
1620     :int (tree-model g-object))
1621   (tree-model-get-column-type-impl tree-model-get-column-type-cb
1622     g-type (tree-model g-object) (index :int))
1623   (tree-model-get-iter-impl tree-model-get-iter-cb
1624     :boolean (tree-model g-object) (iter (g-boxed-ref tree-iter)) (path (g-boxed-ref tree-path)))
1625   (tree-model-get-path-impl tree-model-get-path-cb
1626     (g-boxed-ref tree-path) (tree-model g-object) (iter (g-boxed-ref tree-iter)))
1627   (tree-model-get-value-impl tree-model-get-value-cb
1628     :void (tree-model g-object) (iter (g-boxed-ref tree-iter)) (n :int) (value (:pointer g-value)))
1629   (tree-model-iter-next-impl tree-model-iter-next-cb
1630     :boolean (tree-model g-object) (iter (g-boxed-ref tree-iter)))
1631   (tree-model-iter-children-impl tree-model-iter-children-cb
1632     :boolean (tree-model g-object) (iter (g-boxed-ref tree-iter)) (parent (g-boxed-ref tree-iter)))
1633   (tree-model-iter-has-child-impl tree-model-iter-has-child-cb
1634     :boolean (tree-model g-object) (iter (g-boxed-ref tree-iter)))
1635   (tree-model-iter-n-children-impl tree-model-iter-n-children-cb
1636     :int (tree-model g-object) (iter (g-boxed-ref tree-iter)))
1637   (tree-model-iter-nth-child-impl tree-model-iter-nth-child-cb
1638     :boolean (tree-model g-object) (iter (g-boxed-ref tree-iter)) (parent (g-boxed-ref tree-iter)) (n :int))
1639   (tree-model-iter-parent-impl tree-model-iter-parent-cb
1640     :boolean (tree-model g-object) (iter (g-boxed-ref tree-iter)) (child (g-boxed-ref tree-iter)))
1641   (tree-model-ref-node-impl tree-model-ref-node-cb
1642     :void (tree-model g-object) (iter (g-boxed-ref tree-iter)))
1643   (tree-model-unref-node-impl tree-model-unref-node-cb
1644     :void (tree-model g-object) (iter (g-boxed-ref tree-iter))))
1645 @end example
1646
1647 @node register-object-type-implementation
1648 @section register-object-type-implementation
1649
1650 @code{(register-object-type-implementation name class parent interfaces properties)}
1651
1652 @table @var
1653 @item @var{name}
1654 A string naming the new GObject class.
1655 @item @var{class}
1656 A class name of corresponding CLOS class. It should be inherited from @code{g-object} or its descendants.
1657 @item @var{parent}
1658 A string naming the GObject superclass
1659 @item @var{interfaces}
1660 A list of names of interfaces that this class implements.
1661 @item @var{properties}
1662 A list of properties that this class provides.
1663 Each property is defined as
1664 @example
1665 property ::= (property-name property-type accessor property-get-fn property-set-fn)
1666 @end example
1667 @end table
1668
1669 A macro that creates a new GObject type and registers the Lisp implementation for it.
1670
1671 Example:
1672 @example
1673 (register-object-type-implementation "LispArrayListStore" array-list-store "GObject" ("GtkTreeModel") nil)
1674 @end example
1675
1676 @node GBoxed
1677 @chapter GBoxed
1678 @menu
1679 * define-g-boxed-class::
1680 * define-g-boxed-ref::
1681 @end menu
1682
1683 GObject manual defines this type in the following way:
1684
1685 ``GBoxed is a generic wrapper mechanism for arbitrary C structures. The only thing the type system needs to know about the structures is how to copy and free them, beyond that they are treated as opaque chunks of memory.
1686
1687 Boxed types are useful for simple value-holder structures like rectangles or points. They can also be used for wrapping structures defined in non-GObject based libraries.''
1688
1689 Naturally, it is quite hard to provide support for such structures. At the moment, support for GBoxed is pretty bad.
1690
1691 Basically, two use cases of GBoxed structures are provided:
1692 @itemize
1693 @item structure is mapped to Lisp structure defined with @code{defstruct}. This is complex scenario and it supports inheritance between structure. Its main use is to define the @code{GdkEvent} structure wrapper. Macro @code{define-g-boxed-class} supports this use case.
1694 @item structure is mapped to Lisp wrapper that contains pointer to structure and provides accessor functions (by calling foreign function or calling Lisp function). Macro @code{define-g-boxed-ref} supports this use case.
1695 @end itemize
1696
1697 In both scenarios, foreign functions and GValue type registrations are provided that provide wrapping and unwrapping behaivour (it yet remains to be proven that the behaviour is correct in all cases with regard to issues of memory management, ownership, lifetime). In both cases it is possible to pass the structure by reference, allowing the foreign function (or the callback code) to change the contents of GBoxed.
1698
1699 It is expected that the support for GBoxed structures will be improved.
1700
1701 @node define-g-boxed-class
1702 @section define-g-boxed-class
1703
1704 @example
1705 (define-g-boxed-class g-name-and-c-name name (&optional superclass-and-dispatch (export t))
1706   &body slot*)
1707
1708 g-name-and-c-name ::= nil
1709 g-name-and-c-name ::= (g-name c-name)
1710 superclass-and-dispatch ::= (&optional superclass dispatch-slot dispatch-values)
1711 slot ::= slot-name slot-type &key initform parser unparser
1712 @end example
1713
1714 @table @var
1715 @item @var{g-name}
1716 A string naming the type of this GBoxed; for inherited classes, it should be @code{NIL}
1717 @item @var{c-name}
1718 A symbol naming the generated CFFI foreign structure definition corresponding to this GBoxed. This name should not conflict with other CFFI types.
1719 @item @var{name}
1720 A symbol naming the Lisp structure that will be generated
1721 @item @var{superclass}
1722 A symbol naming the structure defined with @code{define-g-boxed-class} that is the superclass of this structure
1723 @item @var{dispatch-slot}
1724 A slot of the superclass structure that identifies the specific type of structure (``discriminator'')
1725 @item @var{dispatch-values}
1726 A value or a list of values of the @code{dispatch-slot} that correspond to this GBoxed class
1727 @item @var{slot-name}
1728 Name of a slot
1729 @item @var{slot-type}
1730 CFFI foreign type of a slot
1731 @item @var{initform}
1732 An optional initform for @code{defstruct} slot
1733 @item @var{parser}
1734 An optional parser function designator for slot. Parser function is called to get the value for slot when the GBoxed is passed to Lisp with the following arguments: @code{(name pointer)} where the @code{name} is the name of a structure being defined and the @code{pointer} is a foreign pointer to the C structure.
1735 @item @var{unparser}
1736 An optional unparser function designator for a slot. Unparser function is called to write the slot value to GBoxed structure. It is called with arguments @code{(name pointer object)} where @code{name} is the name of a structure being defined, @code{pointer} is the pointer to the C structure and the @code{object} is object whose slot value should be written to structure.
1737 @end table
1738
1739 Defines the @code{defstruct} wrapper for GBoxed type. Various parameters control how the structure is converted between C and Lisp representations.
1740
1741 @code{define-g-boxed-class} supports basic single inheritance. This is provided to support ``generic'' C structures like @code{GdkEvent} that contain a ``type'' field and a @code{union} of other substructures. The natural mapping of such structure to Lisp is not one, but several structures that are inherited one from another. This supports e.g. method dispatching on @code{GdkEvent} types (if it is ever necessary).
1742
1743 The only use of @code{define-g-boxed-class} that involves inheritance is the @code{GdkEvent} structure. It is defined as follows.
1744 @example
1745 (define-g-boxed-class ("GdkEvent" event-struct) event ()
1746   (type event-type)
1747   (window (g-object gdk-window))
1748   (send-event (:boolean :int8)))
1749
1750 (define-g-boxed-class nil event-key ((event type (:key-press :key-release)))
1751   (time :uint32)
1752   (state modifier-type)
1753   (keyval :uint)
1754   (length :int)
1755   (string (:string :free-from-foreign nil :free-to-foreign nil))
1756   (hardware-keycode :uint16)
1757   (group :uint8)
1758   (is-modifier :uint))
1759
1760 (define-g-boxed-class nil event-button ((event type (:button-press :2button-press :3button-press :button-release)))
1761   (time :uint32)
1762   (x :double)
1763   (y :double)
1764   (axes (fixed-array :double 2))
1765   (state :uint)
1766   (button :uint)
1767   (device (g-object device))
1768   (x-root :double)
1769   (y-root :double))
1770 @end example
1771
1772 Some simpler uses include following examples:
1773 @example
1774 (define-g-boxed-class "GdkFont" font ()
1775   (type font-type :initform :font)
1776   (ascent :int :initform 0)
1777   (descent :int :initform 0))
1778
1779 (define-g-boxed-class "GdkColor" color ()
1780   (pixel :uint32 :initform 0)
1781   (red :uint16 :initform 0)
1782   (green :uint16 :initform 0)
1783   (blue :uint16 :initform 0))
1784
1785 (define-g-boxed-class "GdkGeometry" geometry ()
1786   (min-width :int :initform 0)
1787   (min-height :int :initform 0)
1788   (max-width :int :initform 0)
1789   (max-height :int :initform 0)
1790   (base-width :int :initform 0)
1791   (base-height :int :initform 0)
1792   (width-increment :int :initform 0)
1793   (height-increment :int :initform 0)
1794   (min-aspect :double :initform 0.0d0)
1795   (max-aspect :double :initform 0.0d0)
1796   (gravity gravity :initform :north-west))
1797 @end example
1798
1799 @node define-g-boxed-ref
1800 @section define-g-boxed-ref
1801
1802 @code{g-boxed-ref} class is defined:
1803 @example
1804 (defclass g-boxed-ref ()
1805   ((pointer :accessor pointer :initarg :pointer)))
1806 @end example
1807
1808 This class holds the pointer to structure. GBoxed-ref types are subclasses of this class.
1809
1810 @example
1811 (define-g-boxed-ref g-name name
1812   &rest property*)
1813
1814 property ::= (:free-function free-function)
1815 property ::= (:alloc-function alloc-function)
1816 property ::= (:slots &rest slot*)
1817 slot ::= (slot-name &key reader writer type (accessor slot-name))
1818 @end example
1819
1820 @table @var
1821 @item @var{g-name}
1822 A string that names the GBoxed type
1823 @item @var{name}
1824 A symbol that is the name for generated class
1825 @item @var{free-function}
1826 Mandatory designator for a function that frees the allocated object. This function accepts a single argument - CFFI foreign pointer.
1827 @item @var{alloc-function}
1828 Mandatory designator for a function that allocates the object. This function accepts zero arguments and returns CFFI foreign pointer to fresh object.
1829 @item @var{slot-name}
1830 A symbol naming the slot
1831 @item @var{type}
1832 A CFFI foreign type of a slot
1833 @item @var{reader}
1834 @code{NIL} or a string or a function designator. If it is @code{NIL} the the slot is not readable. If it is a string then it names the C function that accepts the pointer to structure and returns the value of a slot of specified CFFI type. If it is a function designator that it designates a function that accepts the Lisp object and returns its slot value.
1835 @item @var{writer}
1836 @code{NIL} or string or a function designator. If it is a @code{NIL} then the slot is not writable. If it is a string then it names the C function that accepts the pointer to C structure and a value (of specified CFFI type) and assigns it to the slot of a structure. If it is a function designator then it specifies a function that accepts the new slot value and a Lisp object and assigns it to the slot.
1837 @item @var{accessor}
1838 A symbol namin the accessor function for slot.
1839 @end table
1840
1841 Defines a class corresponding to GBoxed type that is passed by reference (e.g., @code{GtkTextIter}). Class is made a subclass of @code{g-boxed-ref}.
1842
1843 The memory occupied by this class is managed automatically: after the GC collects the Lisp instance, @code{free-function} is used to free the structure (if the instance was created by lisp code).
1844
1845 Example:
1846 @example
1847 (defcstruct tree-iter
1848   (stamp :int)
1849   (user-data :pointer)
1850   (user-data-2 :pointer)
1851   (user-data-3 :pointer))
1852
1853 (defun tree-iter-get-stamp (i) (foreign-slot-value (pointer i) 'tree-iter 'stamp))
1854 (defun tree-iter-set-stamp (value i) (setf (foreign-slot-value (pointer i) 'tree-iter 'stamp) value))
1855 (defun tree-iter-get-user-data (i) (pointer-address (foreign-slot-value (pointer i) 'tree-iter 'user-data)))
1856 (defun tree-iter-set-user-data (value i) (setf (foreign-slot-value (pointer i) 'tree-iter 'user-data) (make-pointer value)))
1857
1858 (defun tree-iter-alloc () (glib:g-malloc (foreign-type-size 'tree-iter)))
1859 (defun tree-iter-free (v) (glib:g-free v))
1860
1861 (define-g-boxed-ref "GtkTreeIter" tree-iter
1862   (:slots (stamp :reader tree-iter-get-stamp :writer tree-iter-set-stamp :accessor tree-iter-stamp)
1863           (user-data :reader tree-iter-get-user-data :writer tree-iter-set-user-data :accessor tree-iter-user-data))
1864   (:alloc-function tree-iter-alloc)
1865   (:free-function tree-iter-free))
1866 @end example
1867
1868 Another example:
1869 @example
1870 (define-foreign-type unichar ()
1871   ()
1872   (:actual-type :uint32)
1873   (:simple-parser unichar))
1874
1875 (defmethod translate-from-foreign (value (type unichar))
1876   (code-char value))
1877
1878 (defmethod translate-to-foreign (value (type unichar))
1879   (char-code value))
1880
1881 (define-g-boxed-ref "GtkTextIter" text-iter
1882   (:free-function gtk-text-iter-free)
1883   (:alloc-function gtk-text-iter-alloc)
1884   (:slots (text-iter-buffer :reader "gtk_text_iter_get_buffer" :type (g-object text-buffer))
1885           (text-iter-offset :reader "gtk_text_iter_get_offset" :writer "gtk_text_iter_set_offset" :type :int)
1886           (text-iter-line :reader "gtk_text_iter_get_line" :writer "gtk_text_iter_set_line" :type :int)
1887           (text-iter-line-offset :reader "gtk_text_iter_get_line_offset" :writer "gtk_text_iter_set_line_offset" :type :int)
1888           (text-iter-visible-line-offset :reader "gtk_text_iter_get_visible_line_offset" :writer "gtk_text_iter_set_visible_line_offset" :type :int)
1889           (text-iter-char :reader "gtk_text_iter_get_char" :type unichar)
1890           (text-iter-pixbuf :reader "gtk_text_iter_get_pixbuf" :type (g-object pixbuf))
1891           (text-iter-marks :reader "gtk_text_iter_get_marks" :type (gslist (g-object text-mark) :free-from-foreign t))
1892           (text-iter-child-anchor :reader "gtk_text_iter_get_child_anchor" :type (g-object text-child-anchor))
1893           (text-iter-tags :reader "gtk_text_iter_get_tags" :type (gslist (g-object text-tag) :free-from-foreign t))
1894           (text-iter-chars-in-line :reader "gtk_text_iter_get_chars_in_line" :type :int)
1895           (text-iter-language :reader "gtk_text_iter_get_language" :type :pointer)
1896           (text-iter-is-end :reader "gtk_text_iter_is_end" :type :boolean)
1897           (text-iter-is-start :reader "gtk_text_iter_is_start" :type :boolean)
1898           (text-iter-can-insert :reader "gtk_text_iter_can_insert" :type :boolean)
1899           (text-iter-starts-word :reader "gtk_text_iter_starts_word" :type :boolean)
1900           (text-iter-ends-word :reader "gtk_text_iter_ends_word" :type :boolean)
1901           (text-iter-inside-word :reader "gtk_text_iter_inside_word" :type :boolean)
1902           (text-iter-starts-line :reader "gtk_text_iter_starts_line" :type :boolean)
1903           (text-iter-ends-line :reader "gtk_text_iter_ends_line" :type :boolean)
1904           (text-iter-starts-sentence :reader "gtk_text_iter_starts_sentence" :type :boolean)
1905           (text-iter-ends-sentence :reader "gtk_text_iter_ends_sentence" :type :boolean)
1906           (text-iter-inside-sentence :reader "gtk_text_iter_inside_sentence" :type :boolean)
1907           (text-iter-is-cursor-position :reader "gtk_text_iter_is_cursor_position" :type :boolean)))
1908
1909 (defcstruct %text-iter
1910   (dummy1 :pointer)
1911   (dummy2 :pointer)
1912   (dummy3 :int)
1913   (dummy4 :int)
1914   (dummy5 :int)
1915   (dummy6 :int)
1916   (dummy7 :int)
1917   (dummy8 :int)
1918   (dummy9 :pointer)
1919   (dummy10 :pointer)
1920   (dummy11 :int)
1921   (dummy12 :int)
1922   (dummy13 :int)
1923   (dummy14 :pointer))
1924
1925 (defcfun gtk-text-iter-copy :pointer
1926   (iter :pointer))
1927
1928 (defcfun gtk-text-iter-free :void
1929   (iter :pointer))
1930
1931 (defun gtk-text-iter-alloc ()
1932   (with-foreign-object (iter '%text-iter)
1933     (gtk-text-iter-copy iter)))
1934 @end example
1935
1936 @node Generating type definitions by introspection
1937 @chapter Generating type definitions by introspection
1938 @menu
1939 * define-g-object-class::
1940 * define-g-interface::
1941 * define-g-enum::
1942 * define-g-flags::
1943 * get-g-enum-definition::
1944 * get-g-flags-definition::
1945 * get-g-interface-definition::
1946 * get-g-class-definition::
1947 * Specifying additional properties for CLOS classes::
1948 * Generating names for CLOS classes and accessors::
1949 * generate-types-hierarchy-to-file::
1950 @end menu
1951
1952 CL-GTK2-GOBJECT includes facilities for automatically generating parts of bindings for libraries that use GObject type system.
1953
1954 @node define-g-object-class
1955 @section define-g-object-class
1956
1957 @example
1958 (define-g-object-class g-type-name name
1959   (&key (superclass 'g-object) (export t) interfaces type-initializer)
1960   (&rest property*))
1961
1962 property ::= (name accessor gname type readable writable)
1963 property ::= (:cffi name acessor type reader writer)
1964 @end example
1965
1966 Parameters of @code{define-g-object-class}
1967 @table @var
1968 @item @var{superclass}
1969 A symbol naming the superclass of this class
1970 @item @var{export}
1971 Whether to export the name of the class and names of autogenerated properties names from the current package.
1972 @item @var{interfaces}
1973 A list of interfaces the this class implements
1974 @item @var{type-initializer}
1975 A string naming the type initiliazer function. It is usually named @code{class_get_type}.
1976 @item @var{properties}
1977 A list of slots of a class
1978 @end table
1979
1980 Parameters of @code{property}:
1981 @table @var
1982 @item @var{name}
1983 A symbol naming the slot
1984 @item @var{accessor}
1985 A symbol naming the accessor function for this slot
1986 @item @var{gname}
1987 A string naming the property of GObject
1988 @item @var{type}
1989 A string naming the type of property of GObject (for GObject properties); or a symbol naming CFFI foreign type (for slots mapped to foreign accessors)
1990 @item @var{readable}
1991 A boolean specifying whether the slot can be read
1992 @item @var{writable}
1993 A boolean specifying whether the slot can be assigned to
1994 @item @var{reader}
1995 A string or a symbol naming getter function. See description of @code{gobject-class} metaclass for information.
1996 @item @var{writter}
1997 A string or a symbol naming setter function. See description of @code{gobject-class} metaclass for information.
1998 @end table
1999
2000 Macro that expands to @code{defclass} for specified class. Additionally, if @code{export} is true, it exports accessor names and name of a class.
2001
2002 Example:
2003 @example
2004 (define-g-object-class "GtkContainer" container
2005   (:superclass widget :export t :interfaces
2006                ("AtkImplementorIface" "GtkBuildable")
2007                :type-initializer "gtk_container_get_type")
2008   ((border-width container-border-width "border-width" "guint" t t)
2009    (resize-mode container-resize-mode "resize-mode" "GtkResizeMode" t t)
2010    (child container-child "child" "GtkWidget" nil t)
2011    (:cffi focus-child container-focus-child g-object "gtk_container_get_focus_child" "gtk_container_set_focus_child")
2012    (:cffi focus-vadjustment container-focus-vadjustment (g-object adjustment) "gtk_container_get_focus_vadjustment" "gtk_container_set_focus_vadjustment")
2013    (:cffi focus-hadjustment container-focus-hadjustment (g-object adjustment) "gtk_container_get_focus_hadjustment" "gtk_container_set_focus_hadjustment")))
2014 @end example
2015
2016 @node define-g-interface
2017 @section define-g-interface
2018
2019 @example
2020 (define-g-interface g-type-name name (&key (export t) type-initializer)
2021   &body property*)
2022
2023 property ::= (name accessor gname type readable writable)
2024 property ::= (:cffi name acessor type reader writer)
2025 @end example
2026
2027 Parameters of @code{define-g-interface}
2028 @table @var
2029 @item @var{export}
2030 Whether to export the name of the interface and names of autogenerated properties names from the current package.
2031 @item @var{type-initializer}
2032 A string naming the type initiliazer function. It is usually named @code{interface_get_type}.
2033 @item @var{properties}
2034 A list of slots of a interface
2035 @end table
2036
2037 Parameters of @code{property}:
2038 @table @var
2039 @item @var{name}
2040 A symbol naming the slot
2041 @item @var{accessor}
2042 A symbol naming the accessor function for this slot
2043 @item @var{gname}
2044 A string naming the property of GObject
2045 @item @var{type}
2046 A string naming the type of property of GObject (for GObject properties); or a symbol naming CFFI foreign type (for slots mapped to foreign accessors)
2047 @item @var{readable}
2048 A boolean specifying whether the slot can be read
2049 @item @var{writable}
2050 A boolean specifying whether the slot can be assigned to
2051 @item @var{reader}
2052 A string or a symbol naming getter function. See description of @code{gobject-class} metaclass for information.
2053 @item @var{writter}
2054 A string or a symbol naming setter function. See description of @code{gobject-class} metaclass for information.
2055 @end table
2056
2057 Macro that expands to @code{defclass} for specified interface. Additionally, if @code{export} is true, it exports accessor names and name of a interface.
2058
2059 Example:
2060 @example
2061 (define-g-interface "GtkFileChooser" file-chooser
2062   (:export t :type-initializer "gtk_file_chooser_get_type")
2063   (do-overwrite-confirmation file-chooser-do-overwrite-confirmation "do-overwrite-confirmation" "gboolean" t t)
2064   (select-multiple file-chooser-select-multiple "select-multiple" "gboolean" t t)
2065   (filter file-chooser-filter "filter" "GtkFileFilter" t t)
2066   (local-only file-chooser-local-only "local-only" "gboolean" t t)
2067   (preview-widget file-chooser-preview-widget "preview-widget" "GtkWidget" t t)
2068   (use-preview-label file-chooser-use-preview-label "use-preview-label" "gboolean" t t)
2069   (preview-widget-active file-chooser-preview-widget-active "preview-widget-active" "gboolean" t t)
2070   (file-system-backend file-chooser-file-system-backend "file-system-backend" "gchararray" nil nil)
2071   (extra-widget file-chooser-extra-widget "extra-widget" "GtkWidget" t t)
2072   (show-hidden file-chooser-show-hidden "show-hidden" "gboolean" t t)
2073   (action file-chooser-action "action" "GtkFileChooserAction" t t)
2074   (:cffi current-name file-chooser-current-name
2075    (:string :free-to-foreign t :encoding :utf-8) nil "gtk_file_chooser_set_current_name")
2076   (:cffi filename file-chooser-filename
2077    (g-string :free-from-foreign t :free-to-foreign t)
2078    "gtk_file_chooser_get_filename" "gtk_file_chooser_set_filename")
2079   (:cffi current-folder file-chooser-current-folder
2080    (g-string :free-from-foreign t :free-to-foreign t)
2081    "gtk_file_chooser_get_current_folder"
2082    "gtk_file_chooser_set_current_folder")
2083   (:cffi uri file-chooser-uri
2084    (g-string :free-from-foreign t :free-to-foreign t)
2085    "gtk_file_chooser_get_uri" "gtk_file_chooser_set_uri")
2086   (:cffi current-folder-uri file-chooser-current-folder-uri
2087    (g-string :free-from-foreign t :free-to-foreign t)
2088    "gtk_file_chooser_get_current_folder_uri"
2089    "gtk_file_chooser_set_current_folder_uri")
2090   (:cffi preview-filename file-chooser-preview-filename
2091    (g-string :free-from-foreign t :free-to-foreign t)
2092    "gtk_file_chooser_get_preview_filename" nil)
2093   (:cffi preview-uri file-chooser-preview-uri
2094    (g-string :free-from-foreign t :free-to-foreign t)
2095    "gtk_file_chooser_get_preview_uri" nil))
2096 @end example
2097
2098 @node define-g-enum
2099 @section define-g-enum
2100
2101 @example
2102 (define-g-enum g-name name (&key (export t) type-initializer) &body value*)
2103
2104 value ::= :keyword
2105 value ::= (:keyword integer)
2106 @end example
2107
2108 @table @var
2109 @item @var{g-name}
2110 A string naming the GEnum type
2111 @item @var{name}
2112 A symbol naming the CFFI enumeration type
2113 @item @var{export}
2114 A boolean indicating whether to export @code{name}
2115 @item @var{type-initializer}
2116 A string naming the foreign type initializer function. Usually named @code{enum_get_type}.
2117 @end table
2118
2119 Macro that defines CFFI enumeration, registers it with GValue, and calls the type initializer.
2120
2121 Example:
2122 @example
2123 (define-g-enum "GtkTextDirection" text-direction
2124   (:export t :type-initializer "gtk_text_direction_get_type")
2125   (:none 0) (:ltr 1) (:rtl 2))
2126
2127 (define-g-enum "GtkSizeGroupMode" size-group-mode
2128  (:export t :type-initializer "gtk_size_group_mode_get_type")
2129  :none :horizontal :vertical :both)
2130 @end example
2131
2132 @node define-g-flags
2133 @section define-g-flags
2134
2135 @example
2136 (define-g-flags g-name name (&key (export t) type-initializer) &body value*)
2137
2138 value ::= :keyword
2139 value ::= (:keyword integer)
2140 @end example
2141
2142 @table @var
2143 @item @var{g-name}
2144 A string naming the GFlags type
2145 @item @var{name}
2146 A symbol naming the CFFI flags type
2147 @item @var{export}
2148 A boolean indicating whether to export @code{name}
2149 @item @var{type-initializer}
2150 A string naming the foreign type initializer function. Usually named @code{flags_get_type}.
2151 @end table
2152
2153 Macro that defines CFFI bitfield, registers it with GValue, and calls the type initializer.
2154
2155 Example:
2156 @example
2157 (define-g-flags "GtkAttachOptions" attach-options
2158   (:export t :type-initializer "gtk_attach_options_get_type")
2159   (:expand 1) (:shrink 2) (:fill 4))
2160
2161 (define-g-flags "GtkButtonAction" button-action
2162   (:export t :type-initializer "gtk_button_action_get_type")
2163   :ignored :selects :drags :expands)
2164 @end example
2165
2166 @node get-g-enum-definition
2167 @section get-g-enum-definition
2168
2169 @code{(get-g-enum-definition type &optional lisp-name-package) @result{} definition}
2170
2171 @table @var
2172 @item @var{type}
2173 A string naming the GEnum type
2174 @item @var{lisp-name-package}
2175 A package that will be used as a package for generated symbols (enum name). If not specified, symbols are interned in @code{*package*}
2176 @item @var{definition}
2177 A Lisp form that when evaluated defines the GEnum.
2178 @end table
2179
2180 Uses GObject introspection capabilities to automatically produce the definition of GEnum. The foreign library that defines the enum type should be loaded.
2181
2182 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
2183
2184 Example:
2185 @example
2186 (get-g-enum-definition "GtkDirectionType")
2187 @result{}
2188 (DEFINE-G-ENUM "GtkDirectionType" GTK-DIRECTION-TYPE
2189                (:EXPORT T :TYPE-INITIALIZER "gtk_direction_type_get_type")
2190                (:TAB-FORWARD 0) (:TAB-BACKWARD 1) (:UP 2) (:DOWN 3) (:LEFT 4)
2191                (:RIGHT 5))
2192 @end example
2193
2194 @node get-g-flags-definition
2195 @section get-g-flags-definition
2196
2197 @code{(get-g-flags-definition type &optional lisp-name-package) @result{} definition}
2198
2199 @table @var
2200 @item @var{type}
2201 A string naming the GFlags type
2202 @item @var{lisp-name-package}
2203 A package that will be used as a package for generated symbols (flags name). If not specified, symbols are interned in @code{*package*}
2204 @item @var{definition}
2205 A Lisp form that when evaluated defines the GFlags.
2206 @end table
2207
2208 Uses GObject introspection capabilities to automatically produce the definition of GFlags. The foreign library that defines the flags type should be loaded.
2209
2210 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
2211
2212 Example:
2213 @example
2214 (get-g-flags-definition "GtkCalendarDisplayOptions")
2215 @result{}
2216 (DEFINE-G-FLAGS "GtkCalendarDisplayOptions" GTK-CALENDAR-DISPLAY-OPTIONS
2217                 (:EXPORT T :TYPE-INITIALIZER
2218                  "gtk_calendar_display_options_get_type")
2219                 (:SHOW-HEADING 1) (:SHOW-DAY-NAMES 2) (:NO-MONTH-CHANGE 4)
2220                 (:SHOW-WEEK-NUMBERS 8) (:WEEK-START-MONDAY 16)
2221                 (:SHOW-DETAILS 32))
2222 @end example
2223
2224 @node get-g-interface-definition
2225 @section get-g-interface-definition
2226
2227 @code{get-g-interface-definition type &optional lisp-name-package) @result{} definition}
2228
2229 @table @var
2230 @item @var{type}
2231 A string naming the GInterface type
2232 @item @var{lisp-name-package}
2233 A package that will be used as a package for generated symbols (type name, accessor names). If not specified, symbols are interned in @code{*package*}
2234 @item @var{definition}
2235 A Lisp form that when evaluated defines the GInterface.
2236 @end table
2237
2238 Uses GObject introspection capabilities to automatically produce the definition of GInterface. The foreign library that defines the GInterface type should be loaded.
2239
2240 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
2241
2242 Example:
2243 @example
2244 (get-g-interface-definition "GtkActivatable")
2245 @result{}
2246 (DEFINE-G-INTERFACE "GtkActivatable" GTK-ACTIVATABLE
2247                     (:EXPORT T :TYPE-INITIALIZER "gtk_activatable_get_type")
2248                     (USE-ACTION-APPEARANCE
2249                      GTK-ACTIVATABLE-USE-ACTION-APPEARANCE
2250                      "use-action-appearance" "gboolean" T T)
2251                     (RELATED-ACTION GTK-ACTIVATABLE-RELATED-ACTION
2252                      "related-action" "GtkAction" T T))
2253 @end example
2254
2255 @node get-g-class-definition
2256 @section get-g-class-definition
2257
2258
2259 @code{get-g-class-definition type &optional lisp-name-package) @result{} definition}
2260
2261 @table @var
2262 @item @var{type}
2263 A string naming the GObject type
2264 @item @var{lisp-name-package}
2265 A package that will be used as a package for generated symbols (type name, accessor names). If not specified, symbols are interned in @code{*package*}
2266 @item @var{definition}
2267 A Lisp form that when evaluated defines the GObject.
2268 @end table
2269
2270 Uses GObject introspection capabilities to automatically produce the definition of GClass. The foreign library that defines the GObject type should be loaded.
2271
2272 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
2273
2274 Example:
2275 @example
2276 (get-g-class-definition "GtkButton")
2277 @result{}
2278 (DEFINE-G-OBJECT-CLASS "GtkButton" GTK-BUTTON
2279                        (:SUPERCLASS GTK-BIN :EXPORT T :INTERFACES
2280                         ("AtkImplementorIface" "GtkActivatable" "GtkBuildable")
2281                         :TYPE-INITIALIZER "gtk_button_get_type")
2282                        ((LABEL GTK-BUTTON-LABEL "label" "gchararray" T T)
2283                         (IMAGE GTK-BUTTON-IMAGE "image" "GtkWidget" T T)
2284                         (RELIEF GTK-BUTTON-RELIEF "relief" "GtkReliefStyle" T
2285                          T)
2286                         (USE-UNDERLINE GTK-BUTTON-USE-UNDERLINE "use-underline"
2287                          "gboolean" T T)
2288                         (USE-STOCK GTK-BUTTON-USE-STOCK "use-stock" "gboolean"
2289                          T T)
2290                         (FOCUS-ON-CLICK GTK-BUTTON-FOCUS-ON-CLICK
2291                          "focus-on-click" "gboolean" T T)
2292                         (XALIGN GTK-BUTTON-XALIGN "xalign" "gfloat" T T)
2293                         (YALIGN GTK-BUTTON-YALIGN "yalign" "gfloat" T T)
2294                         (IMAGE-POSITION GTK-BUTTON-IMAGE-POSITION
2295                          "image-position" "GtkPositionType" T T)))
2296 @end example
2297
2298 @node Specifying additional properties for CLOS classes
2299 @section Specifying additional properties for CLOS classes
2300
2301 Some properties are not exposed through GObject introspection facilities, but are rather present as a pair of functions (@code{class_get_property}, @code{class_set_property}). @code{gobject-class} metaclass supports such properties. For these properties to be included in automatically generated class definitions, they should be made known to the generator.
2302
2303 Definitions generator uses variable @code{*additional-properties*} to get this information.
2304
2305 Variable @code{*additional-properties*} contains a plist that maps GType names to a list of properties definitions (See @ref{define-g-object-class} for syntax of properties definitions).
2306
2307 To supply the bindings generator with this information, bind @code{*additional-properties*} to such list when the generator is run.
2308
2309 Example:
2310 @example
2311 (("GtkTreeViewColumn"
2312   (:cffi gtk::tree-view
2313          gtk::tree-view-column-tree-view
2314          g-object "gtk_tree_view_column_get_tree_view" nil)
2315   (:cffi gtk::sort-column-id
2316          gtk::tree-view-column-sort-column-id
2317          :int "gtk_tree_view_column_get_sort_column_id" "gtk_tree_view_column_set_sort_column_id")
2318   (:cffi gtk::cell-renderers
2319          gtk::tree-view-column-cell-renderers
2320          (glist g-object  :free-from-foreign t) "gtk_tree_view_column_get_cell_renderers" nil))
2321  ("GtkTreeSelection"
2322   (:cffi gtk::mode
2323          gtk::tree-selection-mode
2324          gtk::selection-mode "gtk_tree_selection_get_mode" "gtk_tree_selection_set_mode")
2325   (:cffi gtk::select-function
2326          gtk::tree-selection-select-function
2327          nil gtk::tree-selection-get-selection-function gtk::tree-selection-set-select-function)))
2328 @end example
2329
2330 @node Generating names for CLOS classes and accessors
2331 @section Generating names for CLOS classes and accessors
2332
2333 Names of types are generated by mapping @code{CamelCaseNames} to @code{dash-separated-names} and interning them in specified package. Additionally, prefix from beginning of the name may be stripped (@code{"GtkWidget"} has prefix @code{"Gtk"}, after stripping it maps to @code{widget}). Some names may require special processing (e.g., @code{"GObject"}, @code{"GInitiallyUnowned"} should map to class names in @code{gobject} package; @code{"GtkWindow"} and @code{"GdkWindow"} should receive different @code{symbol-name}s so that they can both be imported in one package).
2334
2335 Accessors for slots are generated by concatenating class name, dash and slot name, producing names like @code{class-slot}: @code{container-child}, @code{button-label}, etc.
2336
2337 Name generation affected by following variables:
2338 @itemize
2339 @item @var{*strip-prefix*}
2340 A string variable specifying the prefix that should to be stripped from the names to generate symbols (e.g., if @code{(equal "Gtk" *strip-prefix*)}, then type named @code{"GtkWidget"} will map to class named @code{widget}.
2341 @item @var{*lisp-name-exceptions*}
2342 A plist mapping from strings (type names) to symbols (class names) that have special name processing.
2343 Example:
2344 @example
2345 `(("GObject" gobject:g-object)
2346   ("GtkObject" ,(intern "GTK-OBJECT" (find-package :gtk)))
2347   ("GInitiallyUnowned" gobject::g-initially-unowned)
2348   ("GtkWindow" ,(intern "GTK-WINDOW" (find-package :gtk)))
2349   ("GtkUIManager" ,(intern "UI-MANAGER" (find-package :gtk)))
2350   ("GtkUIManagerItemType" ,(intern "UI-MANAGER-ITEM-TYPE" (find-package :gtk))))
2351 @end example
2352 @end itemize
2353
2354 @node generate-types-hierarchy-to-file
2355 @section generate-types-hierarchy-to-file
2356
2357 @example
2358 (generate-types-hierarchy-to-file file
2359                                   root-type
2360                                   &key include-referenced
2361                                   prefix
2362                                   package
2363                                   exceptions
2364                                   prologue
2365                                   interfaces
2366                                   enums
2367                                   flags
2368                                   objects
2369                                   exclusions
2370                                   additional-properties)
2371 @end example
2372
2373 @table @var
2374 @item @var{file}
2375 A string or pathname naming the file, or a stream.
2376 @item @var{root-type}
2377 A GType designator for a root type. All types that inherit from this type will be defined.
2378 @item @var{&key include-referenced}
2379 A boolean. Specifies whether referenced types should be included. Type is referenced if it is an interface or a type of property of type included in generation
2380 @item @var{prefix}
2381 A string naming the prefix that should be removed from the beginning of names
2382 @item @var{package}
2383 A package which will contain generated names of types, slots and accessors. It will also be the current package when the definitions are written to file
2384 @item @var{exceptions}
2385 A plist that maps GType names to their Lisp names.
2386 See @ref{Generating names for CLOS classes and accessors} for more info on exceptions from name generation mechanism
2387 @item @var{prologue}
2388 A string that will be included verbatim in generated code file
2389 @item @var{interfaces}
2390 Additional list of interfaces that will also be included in generation
2391 @item @var{enums}
2392 Additional list of enums that will also be included in generation
2393 @item @var{flags}
2394 Additional list of flags that will also be included in generation
2395 @item @var{objects}
2396 Additional list of object types that will also be included in generation
2397 @item @var{exclusions}
2398 A list of GType names that will be excluded from generation
2399 @item @var{additional-properties}
2400 A plist of properties definitions that will be added to generated classes.
2401 See @ref{Specifying additional properties for CLOS classes} for more information.
2402 @end table
2403
2404 Generates definitions for all types in a type hierarchy. Recursively scan types hierarchy (starting from @code{root} and @code{objects} and @code{interfaces}) (except types that were specifically excluded) and generate defintion for every mentioned type. Parameters control various aspects of definition generation.
2405
2406 Example of usage:
2407 @example
2408 (generate-types-hierarchy-to-file
2409  "gtk.generated-classes.lisp"
2410  "GtkObject"
2411  :include-referenced t
2412  :prefix "Gtk"
2413  :package (or (find-package :gtk) (make-package :gtk))
2414  :exceptions `(("GObject" gobject:g-object)
2415                ("GtkObject" ,(intern "GTK-OBJECT" (find-package :gtk)))
2416                ("GInitiallyUnowned" gobject::g-initially-unowned)
2417                ("GtkWindow" ,(intern "GTK-WINDOW" (find-package :gtk)))
2418                ("GtkUIManager" ,(intern "UI-MANAGER" (find-package :gtk)))
2419                ("GtkUIManagerItemType" ,(intern "UI-MANAGER-ITEM-TYPE" (find-package :gtk))))
2420  :prologue (format nil "(in-package :gtk)")
2421  :interfaces '("GtkBuildable" "GtkCellEditable" ...)
2422  :objects '("GtkSettings" "GtkRcStyle" ...)
2423  :flags '("GtkTextSearchFlags" "GtkAccelFlags" ...)
2424  :enums '("GtkTextDirection" "GtkSizeGroupMode" ...)
2425  :exclusions '("PangoStretch" "PangoVariant" ...)
2426  :additional-properties
2427  '(("GtkTreeViewColumn"
2428     (:cffi
2429      gtk::tree-view
2430      gtk::tree-view-column-tree-view
2431      g-object
2432      "gtk_tree_view_column_get_tree_view"
2433      nil)
2434     ...)
2435    ...))
2436 @end example
2437
2438 @bye
2439