Work on documentation
[cl-gtk2.git] / doc / gobject.texi
index 638dfa4..9ef0d4c 100644 (file)
 @end defmac
 @end macro
 
+@macro Struct {args}
+@deftp {Structure} \args\
+@end deftp
+@end macro
+
+@macro Class {args}
+@deftp {Class} \args\
+@end deftp
+@end macro
+
 @macro Accessor {args}
 @deffn {Accessor} \args\
 @end deffn
 * Closures::
 * GObject low-level::
 * GObject high-level::
-* Subclassing GObjects and implementing GInterfaces::
+* Creating GObjects classes and implementing GInterfaces::
 * GBoxed::
 * Generating type definitions by introspection::
 @end menu
@@ -166,6 +176,8 @@ CL-GTK2-GObject defines two packages: @code{gobject} and @code{gobject.ffi}. The
 @menu
 * g-type-string::
 * g-type-numeric::
+* g-type=::
+* g-type/=::
 @end menu
 
 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.
@@ -192,27 +204,30 @@ Some of the types are fundamental and have constant integer values. They are ide
 @item @code{+g-type-double+} ("gdouble"). The fundamental type corresponding to @code{gdouble}.
 @item @code{+g-type-string+} ("gchararray"). The fundamental type corresponding to null-terminated C strings.
 @item @code{+g-type-pointer+} ("gpointer"). The fundamental type corresponding to @code{gpointer}.
-@item @code{+g-type-boxed+} ("GBoxed"). The fundamental type from which all boxed types are derived.
-@item @code{+g-type-param+} ("GParam"). The fundamental type from which all GParamSpec types are derived.
+@item @code{+g-type-boxed+} ("GBoxed"). The fundamental type from which all boxed types are derived. Values of this type correspond to by-value structures.
+@item @code{+g-type-param+} ("GParam"). The fundamental type from which all GParamSpec types are derived. Values of this type correspond to instances of structure @code{g-class-property-definition}.
 @item @code{+g-type-object+} ("GObject"). The fundamental type for GObject.
 @end itemize
 
-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-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.
 
 Invalid type (the GType that does not exist) is identified as a 0 or @code{NIL}.
 
-@example
+@lisp
 (g-type-numeric "GObject") @result{} 80
 (g-type-numeric 80) @result{} 80
 (g-type-string "GObject") @result{} "GObject"
 (g-type-string 80) @result{} "GObject"
 (g-type-numeric "GtkWidget") @result{} 6905648 ;;Will be different on each run
-@end example
+@end lisp
 
 @node g-type-string
 @section g-type-string
 
-@code{(g-type-string g-type-designator) @result{} name}
+@Function g-type-string
+@lisp
+(g-type-string g-type-designator) @result{} name
+@end lisp
 
 @table @var
 @item @var{g-type-designator}
@@ -226,7 +241,10 @@ Returns the name of GType.
 @node g-type-numeric
 @section g-type-numeric
 
-@code{(g-type-numeric g-type-designator) @result{} GType}
+@Function g-type-numeric
+@lisp
+(g-type-numeric g-type-designator) @result{} GType
+@end lisp
 
 @table @var
 @item @var{g-type-designator}.
@@ -237,6 +255,40 @@ The numeric identifier of GType
 
 Returns the numeric identifier of GType
 
+@node g-type=
+@section g-type=
+
+@Function g-type=
+@lisp
+(g-type= type-1 type-2) @result{} eq
+@end lisp
+
+@table @var
+@item @var{type-1}
+A GType designator
+@item @var{type-2}
+A GType designator
+@item @var{eq}
+A boolean that is true if @code{type-1} and @code{type-2} designate the same type.
+@end table
+
+@node g-type/=
+@section g-type/=
+
+@Function g-type/=
+@lisp
+(g-type/= type-1 type-2) @result{} eq
+@end lisp
+
+@table @var
+@item @var{type-1}
+A GType designator
+@item @var{type-2}
+A GType designator
+@item @var{eq}
+A boolean that is true if @code{type-1} and @code{type-2} designate different types.
+@end table
+
 @node Type hierarchy and type relations
 @chapter Type hierarchy and type relations
 
@@ -260,7 +312,11 @@ There are functions to query some specific information:
 @node g-type-children
 @section g-type-children
 
-@code{(g-type-children type) @result{} children}
+@Function g-type-children
+@lisp
+(g-type-children type) @result{} children
+@end lisp
+
 @table @var
 @item @var{type}
 A GType designator
@@ -271,16 +327,19 @@ A list of GType designators
 Returns the list of descendent types.
 
 Example:
-@example
+@lisp
 (g-type-children "GtkButton")
 @result{}
 ("GtkToggleButton" "GtkColorButton" "GtkFontButton" "GtkLinkButton" "GtkScaleButton")
-@end example
+@end lisp
 
 @node g-type-parent
 @section g-type-parent
 
-@code{(g-type-parent type) @result{} parent}
+@Function g-type-parent
+@lisp
+(g-type-parent type) @result{} parent
+@end lisp
 
 @table @var
 @item @var{type}
@@ -292,15 +351,19 @@ A GType designator
 Returns the parent of @code{type}.
 
 Example:
-@example
+@lisp
 (g-type-parent "GtkToggleButton")
 @result{}
 "GtkButton"
-@end example
+@end lisp
+
 @node g-type-fundamental
 @section g-type-fundamental
 
-@code{(g-type-fundamental type) @result{} fundamental-type}
+@Function g-type-fundamental
+@lisp
+(g-type-fundamental type) @result{} fundamental-type
+@end lisp
 
 @table @var
 @item @var{type}
@@ -312,18 +375,21 @@ A GType designator for one of the fundamental types
 Returns the fundamental type that is the ancestor of @code{type}.
 
 Example:
-@example
+@lisp
 (g-type-fundamental "GtkButton") @result{} "GObject"
 
 (g-type-fundamental "GtkWindowType") @result{} "GEnum"
 
 (g-type-fundamental "GdkEvent") @result{} "GBoxed"
-@end example
+@end lisp
 
 @node g-type-depth
 @section g-type-depth
 
-@code{(g-type-depth type) @result{} depth}
+@Function g-type-depth
+@lisp
+(g-type-depth type) @result{} depth
+@end lisp
 
 @table @var
 @item @var{type}
@@ -335,15 +401,18 @@ An integer
 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.
 
 Example:
-@example
+@lisp
 (g-type-depth "GObject") @result{} 1
 (g-type-depth "GInitiallyUnowned") @result{} 2
-@end example
+@end lisp
 
 @node g-type-next-base
 @section g-type-next-base
 
-@code{(g-type-next-base leaf-type root-type) @result{} base-type}
+@Function g-type-next-base
+@lisp
+(g-type-next-base leaf-type root-type) @result{} base-type
+@end lisp
 
 @table @var
 @item @var{leaf-type}
@@ -355,7 +424,7 @@ A GType designator
 @end table
 
 Returns the next type that should be traversed from @code{root-type} in order to reach @code{leaf-type}. E.g., given type hierarchy:
-@example
+@lisp
 + GObject
  \
   + GInitiallyUnowned
@@ -369,17 +438,17 @@ Returns the next type that should be traversed from @code{root-type} in order to
         + GtkContainer
          \
           + GtkTable
-@end example
+@end lisp
 
 the following will be returned:
 
-@example
+@lisp
 (g-type-next-base "GtkTable" "GObject") @result{} "GInitiallyUnowned"
 (g-type-next-base "GtkTable" "GInitiallyUnowned") @result{} "GtkObject"
 (g-type-next-base "GtkTable" "GtkObject") @result{} "GtkWidget"
 (g-type-next-base "GtkTable" "GtkWidget") @result{} "GtkContainer"
 (g-type-next-base "GtkTable" "GtkContainer") @result{} "GtkTable"
-@end example
+@end lisp
 
 @node Object types information
 @chapter Object types information
@@ -403,7 +472,8 @@ Information about signals can be queries with @code{type-signals}, @code{parse-s
 @node g-class-property-definition
 @section g-class-property-definition
 
-@example
+@Struct g-class-property-definition
+@lisp
 (defstruct g-class-property-definition
   name
   type
@@ -412,7 +482,7 @@ Information about signals can be queries with @code{type-signals}, @code{parse-s
   constructor
   constructor-only
   owner-type)
-@end example
+@end lisp
 
 @table @var
 @item @var{name}
@@ -434,9 +504,9 @@ A GType designator. Identifies the type on which the property was defined.
 This structure identifies a single property. Its field specify attributes of a property.
 
 Structures of this type have shortened print syntax:
-@example
+@lisp
 #<PROPERTY gchararray GtkButton.label (flags: readable writable constructor)> 
-@end example
+@end lisp
 
 (When @code{*print-readably*} is T, usual @code{defstruct} print syntax is used)
 
@@ -451,7 +521,10 @@ This syntax specifies:
 @node class-properties
 @section class-properties
 
-@code{(class-properties type) @result{} properties}
+@Function class-properties
+@lisp
+(class-properties type) @result{} properties
+@end lisp
 
 @table @var
 @item @var{type}
@@ -463,7 +536,7 @@ A list of @code{g-property-definition} structures.
 This function returns the list of properties that are available in class @code{type}.
 
 Example:
-@example
+@lisp
 (class-properties "GtkWidget")
 @result{}
 (#<PROPERTY gpointer GtkObject.user-data (flags: readable writable)>
@@ -489,11 +562,14 @@ Example:
  #<PROPERTY gchararray GtkWidget.tooltip-markup (flags: readable writable)>
  #<PROPERTY gchararray GtkWidget.tooltip-text (flags: readable writable)>
  #<PROPERTY GdkWindow GtkWidget.window (flags: readable)>)
-@end example
+@end lisp
 
 @node class-property-info
 @section class-property-info
-@code{(class-property-info type property-name) @result{} property}
+@Function class-property-info
+@lisp
+(class-property-info type property-name) @result{} property
+@end lisp
 
 @table @var
 @item @var{type}
@@ -507,16 +583,19 @@ An instance of @code{g-property-definition} structure
 Returns the property information for a single property.
 
 Example:
-@example
+@lisp
 (class-property-info "GtkButton" "label")
 @result{}
 #<PROPERTY gchararray GtkButton.label (flags: readable writable constructor)>
-@end example
+@end lisp
 
 @node interface-properties
 @section interface-properties
 
-@code{(interface-properties type) @result{} properties}
+@Function interface-properties
+@lisp
+(interface-properties type) @result{} properties
+@end lisp
 
 @table @var
 @item @var{type}
@@ -528,7 +607,7 @@ A list of @code{g-property-definition} structures
 This function returns the list of properties that are available in interface @code{type}.
 
 Example:
-@example
+@lisp
 (interface-properties "GtkFileChooser")
 @result{}
 (#<PROPERTY GtkWidget GtkFileChooser.extra-widget (flags: readable writable)>
@@ -542,12 +621,13 @@ Example:
  #<PROPERTY GtkWidget GtkFileChooser.preview-widget (flags: readable writable)>
  #<PROPERTY gboolean GtkFileChooser.local-only (flags: readable writable)>
  #<PROPERTY gboolean GtkFileChooser.do-overwrite-confirmation (flags: readable writable)>)
-@end example
+@end lisp
 
 @node signal-info
 @section signal-info
 
-@example
+@Struct signal-info
+@lisp
 (defstruct signal-info
   id
   name
@@ -556,7 +636,7 @@ Example:
   return-type
   param-types
   detail)
-@end example
+@end lisp
 
 @table @var
 @item @var{id}
@@ -576,12 +656,12 @@ A string. Specifies the "detail" part of a signal name. E.g., @code{"label"} for
 @end table
 
 When @code{*print-readably*} is nil, the following print syntax is used:
-@example
+@lisp
 #<Signal [#1] void GObject.notify::label(GParam) [RUN-FIRST, NO-RECURSE, DETAILED, ACTION, NO-HOOKS]>
 #<Signal [#54] gboolean GtkWidget.proximity-in-event(GdkEvent) [RUN-LAST]>
 #<Signal [#64] void GtkWidget.drag-data-received(GdkDragContext, gint, gint, GtkSelectionData, guint, guint) [RUN-LAST]>
 #<Signal [#8] void GtkObject.destroy() [RUN-CLEANUP, NO-RECURSE, NO-HOOKS]>
-@end example
+@end lisp
 
 This syntax specifies:
 @itemize
@@ -596,7 +676,10 @@ This syntax specifies:
 
 @node type-signals
 @section type-signals
-@code{(type-signals type &key (include-inherited t)) @result{} signals}
+@Function type-signals
+@lisp
+(type-signals type &key (include-inherited t)) @result{} signals
+@end lisp
 @table @var
 @item @var{type}
 A GType designator
@@ -609,18 +692,21 @@ A boolean that specifies whether to include signals defined on this type or also
 Returns the list of signals that are available in type @code{type}.
 
 Example:
-@example
+@lisp
 (type-signals "GtkLabel" :include-inherited nil)
 @result{}
 (#<Signal [#138] void GtkLabel.move-cursor(GtkMovementStep, gint, gboolean) [RUN-LAST, ACTION]>
  #<Signal [#139] void GtkLabel.copy-clipboard() [RUN-LAST, ACTION]>
  #<Signal [#140] void GtkLabel.populate-popup(GtkMenu) [RUN-LAST]>)
-@end example
+@end lisp
 
 @node parse-signal-name
 @section parse-signal-name
 
-@code{(parse-signal-name type signal-name) @result{} signal}
+@Function parse-signal-name
+@lisp
+(parse-signal-name type signal-name) @result{} signal
+@end lisp
 
 @table @var
 @item @var{type}
@@ -634,15 +720,18 @@ A list @code{signal-info} structures.
 Parses the signal name and returns the corresponding information. @code{signal-name} may include the detail part.
 
 Example:
-@example
+@lisp
 (parse-signal-name "GObject" "notify::label")
 @result{}
 #<Signal [#1] void GObject.notify::label(GParam) [RUN-FIRST, NO-RECURSE, DETAILED, ACTION, NO-HOOKS]>
-@end example
+@end lisp
 
 @node query-signal-info
 @section query-signal-info
-@code{(query-signal-info signal-id) @result{} signal}
+@Function query-signal-info
+@lisp
+(query-signal-info signal-id) @result{} signal
+@end lisp
 @table @var
 @item @var{signal-id}
 An integer identifying the signal
@@ -653,16 +742,19 @@ An instance of @code{signal-info} structure
 Retrieves the signal information by its id.
 
 Example:
-@example
+@lisp
 (query-signal-info 73)
 @result{}
 #<Signal [#73] gboolean GtkWidget.show-help(GtkWidgetHelpType) [RUN-LAST, ACTION]>
-@end example
+@end lisp
 
 @node g-type-interfaces
 @section g-type-interfaces
 
-@code{(g-type-interfaces type) @result{} interfaces}
+@Function g-type-interfaces
+@lisp
+(g-type-interfaces type) @result{} interfaces
+@end lisp
 
 @table @var
 @item @var{type}
@@ -674,16 +766,19 @@ A list of GType designators
 Returns the list of interfaces that @code{type} implements.
 
 Example:
-@example
+@lisp
 (g-type-interfaces "GtkButton")
 @result{}
 ("AtkImplementorIface" "GtkBuildable" "GtkActivatable")
-@end example
+@end lisp
 
 @node g-type-interface-prerequisites
 @section g-type-interface-prerequisites
 
-@code{(g-type-interface-prerequisites type) @result{} types}
+@Function g-type-interface-prerequisites
+@lisp
+(g-type-interface-prerequisites type) @result{} types
+@end lisp
 
 @table @var
 @item @var{type}
@@ -695,11 +790,11 @@ A list of GType designators specifying the interface prerequisites
 Returns the prerequisites of an interface @code{type}. Prerequisite is a type that should be an ancestor of a type implementing interface @code{type}.
 
 Example:
-@example
+@lisp
 (g-type-interface-prerequisites "GtkCellEditable")
 @result{}
 ("GtkObject" "GtkWidget")
-@end example
+@end lisp
 
 @node Enum types information
 @chapter Enum types information
@@ -716,10 +811,11 @@ Flags types (flags is a kind of enum whose values can be combined) have items th
 
 @node enum-item
 @section enum-item
-@example
+@Struct enum-item
+@lisp
 (defstruct enum-item
   name value nick)
-@end example
+@end lisp
 
 @table @var
 @item @var{name}
@@ -733,16 +829,17 @@ A string - short name of an enum item
 Structure @code{enum-item} represents a single item of an enumeration type.
 
 Example:
-@example
+@lisp
 #S(ENUM-ITEM :NAME "GTK_WINDOW_TOPLEVEL" :VALUE 0 :NICK "toplevel")
-@end example
+@end lisp
 
 @node flags-item
 @section flags-item
-@example
+@Struct flags-item
+@lisp
 (defstruct flags-item
   name value nick)
-@end example
+@end lisp
 
 @table @var
 @item @var{name}
@@ -756,17 +853,20 @@ A string - short name of an flags item
 Structure @code{flags-item} represents a single item of an flags type.
 
 Example:
-@example
+@lisp
 #S(FLAGS-ITEM
    :NAME "GDK_POINTER_MOTION_HINT_MASK"
    :VALUE 8
    :NICK "pointer-motion-hint-mask")
-@end example
+@end lisp
 
 @node get-enum-items
 @section get-enum-items
 
-@code{(get-enum-items type) @result{} items}
+@Function get-enum-items
+@lisp
+(get-enum-items type) @result{} items
+@end lisp
 
 @table @var
 @item @var{type}
@@ -778,7 +878,7 @@ A list of @code{enum-item} structures
 Returns a list of items in an enumeration
 
 Example:
-@example
+@lisp
 (get-enum-items "GtkScrollType")
 @result{}
 (#S(ENUM-ITEM :NAME "GTK_SCROLL_NONE" :VALUE 0 :NICK "none")
@@ -797,12 +897,15 @@ Example:
  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_RIGHT" :VALUE 13 :NICK "page-right")
  #S(ENUM-ITEM :NAME "GTK_SCROLL_START" :VALUE 14 :NICK "start")
  #S(ENUM-ITEM :NAME "GTK_SCROLL_END" :VALUE 15 :NICK "end"))
-@end example
+@end lisp
 
 @node get-flags-items
 @section get-flags-items
 
-@code{(get-flags-items type) @result{} items}
+@Function get-flags-items
+@lisp
+(get-flags-items type) @result{} items
+@end lisp
 
 @table @var
 @item @var{type}
@@ -814,13 +917,13 @@ A list of @code{flags-item} structures
 Returns a list of items in an flags type
 
 Example:
-@example
+@lisp
 (get-flags-items "GtkAttachOptions")
 @result{}
 (#S(FLAGS-ITEM :NAME "GTK_EXPAND" :VALUE 1 :NICK "expand")
  #S(FLAGS-ITEM :NAME "GTK_SHRINK" :VALUE 2 :NICK "shrink")
  #S(FLAGS-ITEM :NAME "GTK_FILL" :VALUE 4 :NICK "fill"))
-@end example
+@end lisp
 
 @node Using GValues
 @chapter Using GValues
@@ -844,34 +947,40 @@ GValue is used whenever a value of unkown type should be passed. It is used in:
 @end itemize
 
 Example of usage:
-@example
+@lisp
 (cffi:with-foreign-object (gval 'g-value)
   (set-g-value gval "Hello" "gchararray" :zero-g-value t)
   (format t "~S~%" (parse-g-value gval))
   (g-value-unset gval))
 @result{}
 "Hello"
-@end example
+@end lisp
 
 @node g-value-zero
 @section g-value-zero
-@code{(g-value-zero g-value)}
+@Function g-value-zero
+@lisp
+(g-value-zero g-value)
+@end lisp
 @table @var
 @item @var{g-value}
 A foreign pointer to GValue structure.
 @end table
 
 Initializes the GValue to "unset" state. Equivalent of the following initializer in C:
-@example
+@lisp
 GValue value = @{ 0 @};
-@end example
+@end lisp
 
 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).
 
 @node g-value-init
 @section g-value-init
 
-@code{(g-value-init value type)}
+@Function g-value-init
+@lisp
+(g-value-init value type)
+@end lisp
 @table @var
 @item @var{value}
 A foreign pointer to GValue structure
@@ -883,7 +992,10 @@ Initializes the GValue to store instances of type @code{type}. Must be called be
 
 @node g-value-unset
 @section g-value-unset
-@code{(g-value-unset value)}
+@Function g-value-unset
+@lisp
+(g-value-unset value)
+@end lisp
 @table @var
 @item @var{value}
 A foreign pointer to GValue structure.
@@ -893,7 +1005,10 @@ Unsets the GValue. This frees all resources associated with GValue.
 
 @node parse-g-value
 @section parse-g-value
-@code{(parse-g-value value) @result{} object}
+@Function parse-g-value
+@lisp
+(parse-g-value value) @result{} object
+@end lisp
 @table @var
 @item @var{value}
 A foreign pointer to GValue structure
@@ -905,7 +1020,10 @@ Retrieves the object from GValue structure.
 
 @node set-g-value
 @section set-g-value
-@code{(set-g-value gvalue object type &key zero-g-value unset-g-value (g-value-init t))}
+@Function set-g-value
+@lisp
+(set-g-value gvalue object type &key zero-g-value unset-g-value (g-value-init t))
+@end lisp
 
 @table @var
 @item @var{gvalue}
@@ -931,8 +1049,11 @@ In order to be able to parse GValues and set them, it is necessary for GValue bi
 
 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.
 
-@subsection
-@code{(register-enum-type name type)}
+@subsection register-enum-type
+@Function register-enum-type
+@lisp
+(register-enum-type name type)
+@end lisp
 @table @var
 @item @var{name}
 A string naming the GEnum type
@@ -943,14 +1064,17 @@ A symbol - name of CFFI foreign enum type
 Registers the @code{type} to be used for passing value of GEnum type @code{name} between GObject and Lisp.
 
 Example:
-@example
+@lisp
 (defcenum text-direction
   :none :ltr :rtl)
 (register-enum-type "GtkTextDirection" 'text-direction)
-@end example
+@end lisp
 
-@subsection
-@code{(register-flags-type name type)}
+@subsection register-flags-type
+@Function register-flags-type
+@lisp
+(register-flags-type name type)
+@end lisp
 @table @var
 @item @var{name}
 A string naming the GFlags type
@@ -961,11 +1085,11 @@ A symbol - name of CFFI foreign flags type
 Registers the @code{type} to be used for passing value of GFlags type @code{name} between GObject and Lisp.
 
 Example:
-@example
+@lisp
 (defcenum state-type
   :normal :active :prelight :selected :insensitive)
 (register-enum-type "GtkStateType" 'state-type)
-@end example
+@end lisp
 
 @node Stable pointers
 @chapter Stable pointers
@@ -981,7 +1105,10 @@ Sometimes it is necessary to pass arbitrary Lisp object to C code and then recei
 @node allocate-stable-pointer
 @section allocate-stable-pointer
 
-@code{(allocate-stable-pointer thing) @result{} stable-pointer}
+@Function allocate-stable-pointer
+@lisp
+(allocate-stable-pointer thing) @result{} stable-pointer
+@end lisp
 
 @table @var
 @item @var{thing}
@@ -995,7 +1122,7 @@ Allocates a stable pointer to @code{thing}.
 (Note: @var{stable-pointer} should not be dereferenced with @code{cffi:mem-ref}. It should only be dereferenced with @code{stable-pointer-value})
 
 Example:
-@example
+@lisp
 (allocate-stable-pointer (lambda (x) (+ x 10)))
 @result{}
 #.(SB-SYS:INT-SAP #X00000002)
@@ -1007,12 +1134,15 @@ Example:
 (free-stable-pointer **)
 @result{}
 NIL
-@end example
+@end lisp
 
 @node free-stable-pointer
 @section free-stable-pointer
 
-@code{(free-stable-pointer stable-pointer)}
+@Function free-stable-pointer
+@lisp
+(free-stable-pointer stable-pointer)
+@end lisp
 
 @table @var
 @item @var{stable-pointer}
@@ -1022,7 +1152,7 @@ A foreign pointer that was created with @code{allocate-stable-pointer}.
 Frees the stable pointer, enabling the garbage collector to reclaim the object.
 
 Example:
-@example
+@lisp
 (allocate-stable-pointer (lambda (x) (+ x 10)))
 @result{}
 #.(SB-SYS:INT-SAP #X00000002)
@@ -1034,15 +1164,16 @@ Example:
 (free-stable-pointer **)
 @result{}
 NIL
-@end example
+@end lisp
 
 @node stable-pointer-value
 @section stable-pointer-value
 
-@example
+@Accessor stable-pointer-value
+@lisp
 (stable-pointer-value stable-pointer) @result{} thing
 (setf (stable-pointer-value stable-pointer) thing)
-@end example
+@end lisp
 
 @table @var
 @item @var{stable-pointer}
@@ -1056,7 +1187,10 @@ Dereferences a @code{stable-pointer}, returning the stable pointer value. @code{
 @node with-stable-pointer
 @section with-stable-pointer
 
-@code{(with-stable-pointer (ptr expr) &body body)}
+@Macro with-stable-pointer
+@lisp
+(with-stable-pointer (ptr expr) &body body)
+@end lisp
 
 @table @var
 @item @var{ptr}
@@ -1068,12 +1202,12 @@ An expression that will be evaluated once and its value will be bound to stable
 Executes the body with the @code{ptr} variable being bound to a stable pointer whose value is determined by @code{expr}.
 
 Example:
-@example
+@lisp
 (with-stable-pointer (ptr (lambda (x) (+ x 10)))
   (print (stable-pointer-value ptr)))
 ;;Prints:
 #<FUNCTION (LAMBDA (X)) @{1004807E79@}>
-@end example
+@end lisp
 
 @node Closures
 @chapter Closures
@@ -1083,7 +1217,10 @@ Closure are anonymous functions that capture their lexical environment.
 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).
 
 @section create-g-closure
-@code{(create-g-closure fn) @result{} closure}
+@Function create-g-closure
+@lisp
+(create-g-closure fn) @result{} closure
+@end lisp
 
 @table @var
 @item @var{fn}
@@ -1095,20 +1232,20 @@ A foreign pointer to allocated closure
 Allocates the closure. The closure is destroyed automatically by GObject.
 
 Example:
-@example
+@lisp
 (create-g-closure (lambda (x) (+ x 10)))
 @result{}
 #.(SB-SYS:INT-SAP #X006D7B20)
-@end example
+@end lisp
 
 Example of usage from GObject binding code:
-@example
+@lisp
 (defun connect-signal (object signal handler &key after)
   (g-signal-connect-closure (ensure-object-pointer object)
                             signal
                             (create-g-closure handler)
                             after))
-@end example
+@end lisp
 
 (TODO: GObject defines finer closure API: g_closure_ref, g_closure_unref, g_closure_invoke. It should be bound.)
 
@@ -1128,7 +1265,10 @@ Function @code{g-type-from-object} identifies the type of the object. Function @
 @node g-object-call-constructor
 @section g-object-call-constructor
 
-@code{(g-object-call-constructor object-type args-names args-values &optional args-types) @result{} object-ptr}
+@Function g-object-call-constructor
+@lisp
+(g-object-call-constructor object-type args-names args-values &optional args-types) @result{} object-ptr
+@end lisp
 
 @table @var
 @item @var{object-type}
@@ -1146,7 +1286,7 @@ A foreign pointer to newly created instance
 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}.
 
 Example:
-@example
+@lisp
 (g-object-call-constructor "GtkButton" '("label" "use-underline") '("Hello" t) '("gchararray" "gboolean"))
 @result{}
 #.(SB-SYS:INT-SAP #X006D8900)
@@ -1158,12 +1298,15 @@ Example:
 (g-object-call-get-property ** "use-underline")
 @result{}
 T
-@end example
+@end lisp
 
 @node g-type-from-object
 @section g-type-from-object
 
-@code{(g-type-from-object object-ptr) @result{} type}
+@Function g-type-from-object
+@lisp
+(g-type-from-object object-ptr) @result{} type
+@end lisp
 
 @table @var
 @item @var{object-ptr}
@@ -1175,16 +1318,19 @@ A GType designator
 Returns the type of an object by a pointer to its instance
 
 Example:
-@example
+@lisp
 (g-type-from-object (g-object-call-constructor "GtkButton" nil nil))
 @result{}
 "GtkButton"
-@end example
+@end lisp
 
 @node g-object-call-get-property
 @section g-object-call-get-property
 
-@code{(g-object-call-get-property object-ptr property-name &optional property-type) @result{} property-value}
+@Function g-object-call-get-property
+@lisp
+(g-object-call-get-property object-ptr property-name &optional property-type) @result{} property-value
+@end lisp
 
 @table @var
 @item @var{object-ptr}
@@ -1200,7 +1346,7 @@ The value of a property
 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.
 
 Example:
-@example
+@lisp
 (g-object-call-constructor "GtkButton" '("label" "use-underline") '("Hello" t) '("gchararray" "gboolean"))
 @result{}
 #.(SB-SYS:INT-SAP #X006D8900)
@@ -1212,12 +1358,15 @@ Example:
 (g-object-call-get-property ** "use-underline")
 @result{}
 T
-@end example
+@end lisp
 
 @node g-object-call-set-property
 @section g-object-call-set-property
 
-@code{(g-object-call-set-property object-ptr property-name new-value &optional property-type)}
+@Function g-object-call-set-property
+@lisp
+(g-object-call-set-property object-ptr property-name new-value &optional property-type)
+@end lisp
 
 @table @var
 @item @var{object-ptr}
@@ -1233,7 +1382,7 @@ Optional GType designator specifying the type of a property
 Sets the property value of property @code{property-name} of object @code{object-ptr} to @code{new-value}.
 
 Example:
-@example
+@lisp
 (g-object-call-constructor "GtkButton" nil nil)
 @result{}
 #.(SB-SYS:INT-SAP #X006D8B40)
@@ -1245,7 +1394,7 @@ Example:
 (g-object-call-get-property ** "label")
 @result{}
 "Hello"
-@end example
+@end lisp
 
 @node GObject high-level
 @chapter GObject high-level
@@ -1267,7 +1416,7 @@ GObjects are reference counted, and CL-GTK2-GOBJECT manages its own reference to
 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.
 
 Example GObject class of definition:
-@example
+@lisp
 (defclass dialog (gtk-window atk-implementor-iface buildable)
   ((has-separator :accessor dialog-has-separator
                   :initarg :has-separator
@@ -1277,7 +1426,7 @@ Example GObject class of definition:
   (:metaclass gobject-class)
   (:g-type-name . "GtkDialog")
   (:g-type-initializer . "gtk_dialog_get_type"))
-@end example
+@end lisp
 
 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.
 
@@ -1334,7 +1483,7 @@ A string naming foreign setter function of a property or a symbol designating Li
 Initargs of a slot are used to construct the GObject class.
 
 Example:
-@example
+@lisp
 (defclass container (widget atk-implementor-iface buildable)
     ((border-width :allocation :gobject-property
                    :g-property-type "guint"
@@ -1372,7 +1521,7 @@ Example:
     (:metaclass gobject-class)
     (:g-type-name . "GtkContainer")
     (:g-type-initializer . "gtk_container_get_type"))
-@end example
+@end lisp
 (note the dot in @code{(:g-type-name . "GtkContainer")} and in @code{(:g-type-initializer . "gtk_container_get_type")}. It should be present)
 
 @node Using objects
@@ -1380,7 +1529,7 @@ Example:
 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.
 
 Example:
-@example
+@lisp
 (make-instance 'gtk:dialog :has-separator t)
 @result{}
 #<GTK:DIALOG @{10036C5A71@}>
@@ -1400,14 +1549,17 @@ NIL
 (gtk:dialog-has-separator *d*)
 @result{}
 NIL
-@end example
+@end lisp
 
 @node Signals
 @section Signals
 
 To connect handler to a signal, @code{connect-signal} function is used.
 
-@code{(connect-signal object signal handler &key after)}
+@Function connect-signals
+@lisp
+(connect-signal object signal handler &key after)
+@end lisp
 
 @table @var
 @item @var{object}
@@ -1423,7 +1575,7 @@ A boolean specifying whether the handler should be called after the default hand
 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.
 
 Example:
-@example
+@lisp
 (defvar *d* (make-instance 'gtk:dialog))
 @result{}
 *D*
@@ -1443,7 +1595,7 @@ Example:
 ;; Prints:
 #<GTK:DIALOG @{1002D866F1@}>
 14 
-@end example
+@end lisp
 
 Function @code{emit-signal} is used to emit signals on objects.
 
@@ -1463,7 +1615,7 @@ Return value of a signal
 Emits the signal and calls all handlers of the signal. If signal returns a value, it is returned from @code{emit-signal}.
 
 Example:
-@example
+@lisp
 (defvar *d* (make-instance 'gtk:dialog))
 @result{}
 *D*
@@ -1483,7 +1635,7 @@ Example:
 ;; Prints:
 #<GTK:DIALOG @{1002D866F1@}>
 14 
-@end example
+@end lisp
 
 @node GObject foreign class
 @section GObject foreign class
@@ -1498,7 +1650,7 @@ When the @code{g-object} foreign type is specified as a return type of a functio
 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.
 
 This defines the function that may be called with instances of types @code{container} and @code{widget}:
-@example
+@lisp
 (defcfun (container-add "gtk_container_add") :void
   (container (g-object container))
   (widget (g-object widget)))
@@ -1506,11 +1658,11 @@ This defines the function that may be called with instances of types @code{conta
 (let ((window (make-instance 'gtk-window))
       (widget (make-instance 'button)))
   (container-add window widget))
-@end example
+@end lisp
 (@code{gtk-window} is a subclass of @code{container}; @code{button} is a subclass of @code{widget})
 
 This defines the function that returns an instance of GObject class:
-@example
+@lisp
 (defcfun (bin-child "gtk_bin_get_child") (g-object widget)
   (bin (g-object bin)))
 
@@ -1520,13 +1672,510 @@ This defines the function that returns an instance of GObject class:
   (bin-child window))
 @result{}
 #<GTK:BUTTON @{1002DE74B1@}>
-@end example
+@end lisp
+
+@node Creating GObjects classes and implementing GInterfaces
+@chapter Creating GObjects classes and implementing GInterfaces
+
+@menu
+* define-vtable::
+* register-object-type-implementation::
+@end menu
+
+Creating GObject classes from Lisp is the most complex part of GObject binding.
+
+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).
+
+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.
+
+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).
+
+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.
+
+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.
+
+@node define-vtable
+@section define-vtable
+
+@Macro define-vtable
+@lisp
+(define-vtable (type-name cstruct-name)
+  &body item*)
 
-@node Subclassing GObjects and implementing GInterfaces
-@chapter Subclassing GObjects and implementing GInterfaces
+item ::= (name callback-name return-type &rest arg*)
+item ::= (:skip cffi-structure-item)
+arg ::= (arg-name arg-type)
+@end lisp
+
+@table @var
+@item @var{type-name}
+A string naming the GObject type of interface
+@item @var{cstruct-name}
+A name for a generated CFFI foreign structure
+@item @var{name}
+A name for implementation generic function
+@item @var{callback-name}
+A name for generated callback function
+@item @var{return-type}
+A CFFI specifier for foreign function return type
+@item @var{arg-name}
+A symbol naming the argument of interface method
+@item @var{arg-type}
+A CFFI specifier for foreign function argument type
+@end table
+
+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.
+
+Example:
+@lisp
+(define-vtable ("GtkTreeModel" c-gtk-tree-model)
+  (:skip parent-instance g-type-interface)
+  ;;some signals
+  (:skip tree-model-row-changed :pointer)
+  (:skip tree-model-row-inserted :pointer)
+  (:skip tree-model-row-has-child-toggled :pointer)
+  (:skip tree-model-row-deleted :pointer)
+  (:skip tree-model-rows-reordered :pointer)
+  ;;methods
+  (tree-model-get-flags-impl tree-model-get-flags-cb
+    tree-model-flags
+    (tree-model g-object))
+  (tree-model-get-n-columns-impl tree-model-get-n-columns-cb
+    :int
+    (tree-model g-object))
+  (tree-model-get-column-type-impl tree-model-get-column-type-cb
+    g-type-designator
+    (tree-model g-object) (index :int))
+  (tree-model-get-iter-impl tree-model-get-iter-cb
+    :boolean
+    (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (path (g-boxed-foreign tree-path)))
+  (tree-model-get-path-impl tree-model-get-path-cb
+    (g-boxed-foreign tree-path :return)
+    (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
+  (tree-model-get-value-impl tree-model-get-value-cb
+    :void
+    (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (n :int) (value (:pointer g-value)))
+  (tree-model-iter-next-impl tree-model-iter-next-cb
+    :boolean
+    (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
+  (tree-model-iter-children-impl tree-model-iter-children-cb
+    :boolean
+    (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (parent (g-boxed-foreign tree-iter)))
+  (tree-model-iter-has-child-impl tree-model-iter-has-child-cb
+    :boolean
+    (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
+  (tree-model-iter-n-children-impl tree-model-iter-n-children-cb
+    :int
+    (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
+  (tree-model-iter-nth-child-impl tree-model-iter-nth-child-cb
+    :boolean
+    (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (parent (g-boxed-foreign tree-iter)) (n :int))
+  (tree-model-iter-parent-impl tree-model-iter-parent-cb
+    :boolean
+    (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (child (g-boxed-foreign tree-iter)))
+  (tree-model-ref-node-impl tree-model-ref-node-cb
+    :void
+    (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
+  (tree-model-unref-node-impl tree-model-unref-node-cb
+    :void
+    (tree-model g-object) (iter (g-boxed-foreign tree-iter))))
+@end lisp
+
+@node register-object-type-implementation
+@section register-object-type-implementation
+
+@Macro register-object-type-implementation
+@lisp
+(register-object-type-implementation name class parent interfaces properties)
+@end lisp
+
+@table @var
+@item @var{name}
+A string naming the new GObject class.
+@item @var{class}
+A class name of corresponding CLOS class. It should be inherited from @code{g-object} or its descendants.
+@item @var{parent}
+A string naming the GObject superclass
+@item @var{interfaces}
+A list of names of interfaces that this class implements.
+@item @var{properties}
+A list of properties that this class provides.
+Each property is defined as
+@lisp
+property ::= (property-name property-type accessor property-get-fn property-set-fn)
+@end lisp
+@end table
+
+A macro that creates a new GObject type and registers the Lisp implementation for it.
+
+Example:
+@lisp
+(register-object-type-implementation "LispArrayListStore" array-list-store "GObject" ("GtkTreeModel") nil)
+@end lisp
 
 @node GBoxed
 @chapter GBoxed
+@menu
+* define-g-boxed-cstruct::
+* define-g-boxed-variant-cstruct::
+* define-g-boxed-opaque::
+* g-boxed-opaque::
+* define-boxed-opaque-accessor::
+* boxed-related-symbols::
+* GBoxed foreign type::
+@end menu
+
+GObject manual defines this type in the following way:
+
+``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.
+
+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.''
+
+Naturally, it is hard to provide support for ``arbitrary C structures''. We support a few useful use cases of GBoxed types:
+@itemize
+@item Simple C structures. A Lisp structure is a one-to-one correspondence to C structure and is passes to and from foreign code by copying the data it contains. Examples of simple structures are GdkPoint, GdkRectangle.
+@item ``Variant'' C structures. A one common idiom of C is to define a union of structures sharing the same parts in order to implement the polymorphism of structures. These structures are mapped to a hierarchy of Lisp structures (where one structure subclasses another via the @code{:include} @code{defstruct} option).
+
+For example, Gdk has structure GdkEvent which is a union of GdkEventAny, GdkEventExpose and other structures. These structures have common slots: ``type'', ``window'', ``send_event''. By dispatching on ``type'', user or GdkEvent structure knows which of GdkEvent* structures it has and can access other fields.
+@item Opaque C structures. A C structure the has ``hidden'' fields and should only created/destroyed with specific functions and be accessed only with specific accessors. Example of such structures is GtkTreePath.
+@end itemize
+
+@node define-g-boxed-cstruct
+@section define-g-boxed-cstruct
+@Macro define-g-boxed-cstruct
+@lisp
+(define-g-boxed-cstruct name g-type-name
+  &body slot*)
+
+slot ::= (slot-name slot-type &key count initform inline)
+@end lisp
+
+@table @var
+@item @var{name}
+A symbol naming the type being defined
+@item @var{g-type-name}
+A string specifying the GType name of this GBoxed. This may be nil if this type is not registered with GObject type system.
+@item @var{slot-name}
+A symbol naming the slot of a structure
+@item @var{slot-type}
+A foreign type of a slot
+@item @var{count}
+An integer. Corresponds to @code{:count} option of slot in CFFI @code{defcstruct}. If @code{count} is not NIL, then the slot is mapped to Lisp array.
+@item @var{initform}
+A form that is the initform of Lisp structure slot
+@item @var{inline}
+A boolean. If it is true, then the slot contains GBoxed structure whose name is @code{slot-type}.
+@end table
+
+Defines the ``simple'' GBoxed structure corresponding to C structure. The slot specification is analogous to CFFI @code{defstruct} slot specification with the addition of @code{inline} option.
+
+Example of usage:
+@lisp
+(define-g-boxed-cstruct rectangle "GdkRectangle"
+  (left :int :initform 0)
+  (top :int :initform 0)
+  (width :int :initform 0)
+  (height :int :initform 0))
+
+(define-g-boxed-cstruct point nil
+  (x :int :initform 0)
+  (y :int :initform 0))
+
+(define-g-boxed-cstruct vector4 nil
+  (coords :double :count 4 :initform (vector 0d0 0d0 0d0 0d0)))
+
+(define-g-boxed-cstruct segment nil
+  (a point :inline t :initform (make-point))
+  (b point :inline t :initform (make-point)))
+@end lisp
+
+@node define-g-boxed-variant-cstruct
+@section define-g-boxed-variant-cstruct
+
+@Macro define-g-boxed-variant-cstruct
+@lisp
+(define-g-boxed-variant-cstruct name g-type-name
+  &body slot-or-variant-specification*)
+
+slot ::= (slot-name slot-type &key count initform inline)
+variant-specification ::= (:variant dispatching-slot-name structure-variant*)
+structure-variant ::= (dispatching-slot-values structure-name &body slot-or-variant-specification*)
+@end lisp
+
+@table @var
+@item @var{name}
+A symbol naming the type being defined
+@item @var{g-type-name}
+A string specifying the GType name of this GBoxed. This may be nil if this type is not registered with GObject type system.
+@item @var{slot-name}
+A symbol naming the slot of a structure
+@item @var{slot-type}
+A foreign type of a slot
+@item @var{count}
+An integer. Corresponds to @code{:count} option of slot in CFFI @code{defcstruct}. If @code{count} is not NIL, then the slot is mapped to Lisp array.
+@item @var{initform}
+A form that is the initform of Lisp structure slot
+@item @var{inline}
+A boolean. If it is true, then the slot contains GBoxed structure whose name is @code{slot-type}.
+@item @var{dispatching-slot-name}
+A name of the dispatching slot
+@item @var{dispatching-slot-values}
+A single value or a list of values.
+@item @var{structure-name}
+A symbol naming the structure
+@end table
+
+Defines the variant GBoxed structure. Slots of variant structures are defined the same way as the slots of ``simple'' cstructs. After the last slot, @code{variant-specification} may be used to specify the variants of the structure. For this, dispatching slot is specified. The value of this slot specifies which variant of structure is used. Each variant is specified by values of the dispatching slot, by its slots and its variants.
+
+Variant structure is represented in Lisp via a hierarchy on structures. For example, @code{GdkEvent} structure has variants @code{GdkEventAny}, @code{GdkEventButton}, @code{GdkEventMotion}. In Lisp, @code{event} structure is defined with all common fields of these structures and @code{event-button}, @code{event-motion} structures inherit from @code{event} structure.
+
+It is assumed that the variant of structures can be represented as C structures with fields of their ``parent'' structures prepended to them. This assumption breaks when structures include their ``parent'' structure as a first field (this changes the memory alignment and changes offsets of fields).
+
+For example, for these structures this assumption holds:
+@example
+union GdkEvent
+@{
+  GdkEventType   type;
+  GdkEventKey    key;
+  GdkEventButton button;
+@};
+
+struct GdkEventKey @{
+  GdkEventType type; //
+  GdkWindow *window; // These fields are common
+  gint8 send_event;  //
+  guint32 time;
+  guint state;
+  guint keyval;
+  ...
+@};
+
+struct GdkEventButton @{
+  GdkEventType type; //
+  GdkWindow *window; // These fields are common
+  gint8 send_event;  //
+  guint32 time;
+  gdouble x;
+  gdouble y;
+  ...
+@};
+@end example
+
+Example:
+@lisp
+(define-g-boxed-variant-cstruct event "GdkEvent"
+  (type event-type)
+  (window (g-object gdk-window))
+  (send-event (:boolean :int8))
+  (:variant type
+            ((:key-press :key-release) event-key
+             (time :uint32)
+             (state modifier-type)
+             (keyval :uint)
+             (length :int)
+             (string (:string :free-from-foreign nil
+                              :free-to-foreign nil))
+             (hardware-keycode :uint16)
+             (group :uint8)
+             (is-modifier :uint))
+            ((:button-press :2button-press :3button-press
+              :button-release) event-button
+             (time :uint32)
+             (x :double)
+             (y :double)
+             (axes (fixed-array :double 2))
+             (state :uint)
+             (button :uint)
+             (device (g-object device))
+             (x-root :double)
+             (y-root :double))
+             ...))
+@end lisp
+
+This code defines following structures:
+@lisp
+(defstruct event
+  type window send-event)
+
+(defstruct (event-key (:include event))
+  time state keyval length string
+  hardware-keycode group is-modifier)
+
+(defstruct (event-button (:include event))
+  time x y axes state button device x-root y-root)
+@end lisp
+
+@node define-g-boxed-opaque
+@section define-g-boxed-opaque
+
+@Macro define-g-boxed-opaque
+@lisp
+(define-g-boxed-opaque name g-type-name &key alloc)
+@end lisp
+
+@table @var
+@item @var{name}
+A name of boxed type
+@item @var{g-type-name}
+A string; the name of GType
+@item @var{alloc}
+A form that when evaluated produces a pointer to newly allocated structure. This pointer should be copiable with @code{g_boxed_copy} and freeable with @code{g_boxed_free} function.
+@end table
+
+Defines a opaque boxed structure. A class named @var{name} is defined as a subclass of @code{g-boxed-opaque} class. Instances of this class contain pointers to corresponding structures. An @code{:after} method for @code{initialize-instance} generic function is defined that speciales on class @var{name}. This method either accepts a @code{:pointer} initarg or evaluates @var{alloc} form if @code{:pointer} is not specified; the resulting pointer is saved in instance; finalizer is registered to free the pointer when the garbage collectors deletes this object.
+
+Example:
+@lisp
+(defcfun gtk-tree-path-new :pointer)
+
+(define-g-boxed-opaque tree-path "GtkTreePath"
+  :alloc (gtk-tree-path-new))
+@end lisp
+@node g-boxed-opaque
+@section g-boxed-opaque
+@Class g-boxed-opaque
+@lisp
+(defclass g-boxed-opaque ()
+  ((pointer :initarg :pointer
+            :initform nil
+            :accessor g-boxed-opaque-pointer)))
+@end lisp
+
+A class that is the base class for wrappers of opaque structures. Contains a pointer to the wrapped opaque structure.
+
+Accessor function @code{g-boxed-opaque-pointer} is used to access the pointer. Pointer should not be modified directly, only read.
+@node define-boxed-opaque-accessor
+@section define-boxed-opaque-accessor
+@Macro define-boxed-opaque-accessor
+@lisp
+(define-boxed-opaque-accessor
+  boxed-name accessor-name &key type reader writer)
+@end lisp
+
+@table @var
+@item @var{boxed-name}
+A symbol naming the opaque structure type for which the accessor is being defined
+@item @var{accessor-name}
+A symbol naming the accessor
+@item @var{type}
+A CFFI foreign type of the property for which the accessor is being defined
+@item @var{reader}
+A @code{NIL} or a string or a function designator for the reader function
+@item @var{writer}
+A @code{NIL} or a string or a function designator for the writer function
+@end table
+
+Defines the accessor named @var{accessor-name} for property of opaque structure named @var{boxed-name} of type specified by CFFI foreign-type @var{type}.
+
+@var{reader} is a string naming a foreign function of one argument of CFFI foreign-type @code{(g-boxed-foreign @var{boxed-name})} that returns a value of CFFI foreign-type @var{type}; or a function designator for a function that accepts a single argument - an instance of @code{g-boxed-opaque} class and returns the value of a property; or a @code{NIL} if the property is not readable.
+
+@var{writer} is a string naming a foreign function of two arguments: of types @var{type} and @code{(g-boxed-foreign @var{boxed-name})} (with the first argument being the new value and the second being the object); or a function designator for a function of two arguments: a new value and an instance of @code{g-boxed-opaque} class; or a @code{NIL} if the property is not writable.
+
+Example:
+@lisp
+(define-boxed-opaque-accessor text-iter text-iter-child-anchor
+  :reader "gtk_text_iter_get_child_anchor" :type (g-object text-child-anchor))
+
+(define-boxed-opaque-accessor text-iter text-iter-tags
+  :reader "gtk_text_iter_get_tags" :type (gslist (g-object text-tag) :free-from-foreign t))
+
+(define-boxed-opaque-accessor text-iter text-iter-chars-in-line
+  :reader "gtk_text_iter_get_chars_in_line" :type :int)
+
+(define-boxed-opaque-accessor text-iter text-iter-offset
+  :reader "gtk_text_iter_get_offset" :writer "gtk_text_iter_set_offset" :type :int)
+@end lisp
+
+@node boxed-related-symbols
+@section boxed-related-symbols
+
+@Function boxed-related-symbols
+@lisp
+(boxed-related-symbols name) @result{} symbols
+@end lisp
+
+@table @var
+@item @var{name}
+A symbol naming the boxed type
+@item @var{symbols}
+A list of symbols
+@end table
+
+This function returns the list of symbols that are related to GBoxed type @var{name}. These symbols are returned:
+@itemize
+@item name of boxed type
+@item name of all accessors of cstruct and variant-cstruct boxed types
+@item names of all variants of variant-cstruct boxed types
+@item names of constructors and copiers of cstruct and variant-cstruct boxed-types
+@end itemize
+
+Typical usage of this function is to export the symbols related to given boxed type.
+
+Example:
+@lisp
+(define-g-boxed-cstruct rectangle "GdkRectangle"
+  (x :int :initform 0)
+  (y :int :initform 0)
+  (width :int :initform 0)
+  (height :int :initform 0))
+
+(boxed-related-symbols 'rectangle)
+@result{}
+(RECTANGLE MAKE-RECTANGLE COPY-RECTANGLE RECTANGLE-X RECTANGLE-Y
+ RECTANGLE-WIDTH RECTANGLE-HEIGHT)
+@end lisp
+
+@node GBoxed foreign type
+@section GBoxed foreign type
+
+@ForeignType g-boxed-foreign
+@lisp
+(g-boxed-foreign name &rest option*)
+
+option ::= :return
+@end lisp
+
+@table @var
+@item @var{name}
+Name of GBoxed type
+@item @var{option}
+Option of foreign type
+@item @code{:return}
+An option that identifies the foreign type which is used at return position (as foreign function return type or as a callback return type)
+@end table
+
+@code{g-boxed-foreign} type deals with marshaling data between Lisp code and foreign code. The marshaling follows the following principles:
+@itemize
+@item All operations on Lisp objects corresponding to GBoxed types are type-safe and should never lead to any form of memory corruption (if some operation is impossible due to e.g., pointer in opaque pointer wrapper being invalidated, error should be signalled)
+@item Lisp objects should not be manually managed and are properly reclaimed by garbage collector, leaving no memory leaks
+@item Foreign code can change objects that are passed to them as arguments. This is required for functions that operate by modifying their arguments
+@item Lisp code in callbacks can change objects that are passed as arguments. This is required to be able to implement interfaces that have functions that operate by modifying their arguments
+@end itemize
+
+The @code{:return} option is required to be able to properly manage memory of opaque pointer wrappers and propagate changes to foreign and lisp structures.
+
+In order to be able to correctly use @code{g-boxed-foreign} foreign type in callbacks, you should use @code{glib-defcallback}. This macro is a thin wrapper around @code{cffi:defcallback} that adds proper handling of @code{g-boxed-foreign} foreign types.
+
+Examples of usage:
+@lisp
+(define-vtable ("GtkTreeModel" c-gtk-tree-model)
+  ...
+  (tree-model-get-path-impl tree-model-get-path-cb
+    (g-boxed-foreign tree-path :return) (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
+  (tree-model-get-value-impl tree-model-get-value-cb
+    :void (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (n :int) (value (:pointer g-value)))
+  (tree-model-iter-next-impl tree-model-iter-next-cb
+    :boolean (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
+  ...)
+
+(defcfun gtk-text-iter-forward-search :boolean
+  (iter (g-boxed-foreign text-iter))
+  (str (:string :free-to-foreign t))
+  (flags text-search-flags)
+  (match-start (g-boxed-foreign text-iter))
+  (match-end (g-boxed-foreign text-iter))
+  (limit (g-boxed-foreign text-iter)))
+@end lisp
 
 @node Generating type definitions by introspection
 @chapter Generating type definitions by introspection
@@ -1549,14 +2198,15 @@ CL-GTK2-GOBJECT includes facilities for automatically generating parts of bindin
 @node define-g-object-class
 @section define-g-object-class
 
-@example
+@Macro define-g-object-class
+@lisp
 (define-g-object-class g-type-name name
   (&key (superclass 'g-object) (export t) interfaces type-initializer)
   (&rest property*))
 
 property ::= (name accessor gname type readable writable)
 property ::= (:cffi name acessor type reader writer)
-@end example
+@end lisp
 
 Parameters of @code{define-g-object-class}
 @table @var
@@ -1595,7 +2245,7 @@ A string or a symbol naming setter function. See description of @code{gobject-cl
 Macro that expands to @code{defclass} for specified class. Additionally, if @code{export} is true, it exports accessor names and name of a class.
 
 Example:
-@example
+@lisp
 (define-g-object-class "GtkContainer" container
   (:superclass widget :export t :interfaces
                ("AtkImplementorIface" "GtkBuildable")
@@ -1606,18 +2256,19 @@ Example:
    (:cffi focus-child container-focus-child g-object "gtk_container_get_focus_child" "gtk_container_set_focus_child")
    (:cffi focus-vadjustment container-focus-vadjustment (g-object adjustment) "gtk_container_get_focus_vadjustment" "gtk_container_set_focus_vadjustment")
    (:cffi focus-hadjustment container-focus-hadjustment (g-object adjustment) "gtk_container_get_focus_hadjustment" "gtk_container_set_focus_hadjustment")))
-@end example
+@end lisp
 
 @node define-g-interface
 @section define-g-interface
 
-@example
+@Macro define-g-interface
+@lisp
 (define-g-interface g-type-name name (&key (export t) type-initializer)
   &body property*)
 
 property ::= (name accessor gname type readable writable)
 property ::= (:cffi name acessor type reader writer)
-@end example
+@end lisp
 
 Parameters of @code{define-g-interface}
 @table @var
@@ -1652,7 +2303,7 @@ A string or a symbol naming setter function. See description of @code{gobject-cl
 Macro that expands to @code{defclass} for specified interface. Additionally, if @code{export} is true, it exports accessor names and name of a interface.
 
 Example:
-@example
+@lisp
 (define-g-interface "GtkFileChooser" file-chooser
   (:export t :type-initializer "gtk_file_chooser_get_type")
   (do-overwrite-confirmation file-chooser-do-overwrite-confirmation "do-overwrite-confirmation" "gboolean" t t)
@@ -1688,17 +2339,18 @@ Example:
   (:cffi preview-uri file-chooser-preview-uri
    (g-string :free-from-foreign t :free-to-foreign t)
    "gtk_file_chooser_get_preview_uri" nil))
-@end example
+@end lisp
 
 @node define-g-enum
 @section define-g-enum
 
-@example
+@Macro define-g-enum
+@lisp
 (define-g-enum g-name name (&key (export t) type-initializer) &body value*)
 
 value ::= :keyword
 value ::= (:keyword integer)
-@end example
+@end lisp
 
 @table @var
 @item @var{g-name}
@@ -1714,7 +2366,7 @@ A string naming the foreign type initializer function. Usually named @code{enum_
 Macro that defines CFFI enumeration, registers it with GValue, and calls the type initializer.
 
 Example:
-@example
+@lisp
 (define-g-enum "GtkTextDirection" text-direction
   (:export t :type-initializer "gtk_text_direction_get_type")
   (:none 0) (:ltr 1) (:rtl 2))
@@ -1722,17 +2374,18 @@ Example:
 (define-g-enum "GtkSizeGroupMode" size-group-mode
  (:export t :type-initializer "gtk_size_group_mode_get_type")
  :none :horizontal :vertical :both)
-@end example
+@end lisp
 
 @node define-g-flags
 @section define-g-flags
 
-@example
+@Macro define-g-flags
+@lisp
 (define-g-flags g-name name (&key (export t) type-initializer) &body value*)
 
 value ::= :keyword
 value ::= (:keyword integer)
-@end example
+@end lisp
 
 @table @var
 @item @var{g-name}
@@ -1748,7 +2401,7 @@ A string naming the foreign type initializer function. Usually named @code{flags
 Macro that defines CFFI bitfield, registers it with GValue, and calls the type initializer.
 
 Example:
-@example
+@lisp
 (define-g-flags "GtkAttachOptions" attach-options
   (:export t :type-initializer "gtk_attach_options_get_type")
   (:expand 1) (:shrink 2) (:fill 4))
@@ -1756,12 +2409,15 @@ Example:
 (define-g-flags "GtkButtonAction" button-action
   (:export t :type-initializer "gtk_button_action_get_type")
   :ignored :selects :drags :expands)
-@end example
+@end lisp
 
 @node get-g-enum-definition
 @section get-g-enum-definition
 
-@code{(get-g-enum-definition type &optional lisp-name-package) @result{} definition}
+@Function get-g-enum-definition
+@lisp
+(get-g-enum-definition type &optional lisp-name-package) @result{} definition
+@end lisp
 
 @table @var
 @item @var{type}
@@ -1777,19 +2433,22 @@ Uses GObject introspection capabilities to automatically produce the definition
 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
 
 Example:
-@example
+@lisp
 (get-g-enum-definition "GtkDirectionType")
 @result{}
 (DEFINE-G-ENUM "GtkDirectionType" GTK-DIRECTION-TYPE
                (:EXPORT T :TYPE-INITIALIZER "gtk_direction_type_get_type")
                (:TAB-FORWARD 0) (:TAB-BACKWARD 1) (:UP 2) (:DOWN 3) (:LEFT 4)
                (:RIGHT 5))
-@end example
+@end lisp
 
 @node get-g-flags-definition
 @section get-g-flags-definition
 
-@code{(get-g-flags-definition type &optional lisp-name-package) @result{} definition}
+@Function get-g-flags-definition
+@lisp
+(get-g-flags-definition type &optional lisp-name-package) @result{} definition
+@end lisp
 
 @table @var
 @item @var{type}
@@ -1805,7 +2464,7 @@ Uses GObject introspection capabilities to automatically produce the definition
 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
 
 Example:
-@example
+@lisp
 (get-g-flags-definition "GtkCalendarDisplayOptions")
 @result{}
 (DEFINE-G-FLAGS "GtkCalendarDisplayOptions" GTK-CALENDAR-DISPLAY-OPTIONS
@@ -1814,12 +2473,15 @@ Example:
                 (:SHOW-HEADING 1) (:SHOW-DAY-NAMES 2) (:NO-MONTH-CHANGE 4)
                 (:SHOW-WEEK-NUMBERS 8) (:WEEK-START-MONDAY 16)
                 (:SHOW-DETAILS 32))
-@end example
+@end lisp
 
 @node get-g-interface-definition
 @section get-g-interface-definition
 
-@code{get-g-interface-definition type &optional lisp-name-package) @result{} definition}
+@Function get-g-interface-definition
+@lisp
+get-g-interface-definition type &optional lisp-name-package) @result{} definition
+@end lisp
 
 @table @var
 @item @var{type}
@@ -1835,7 +2497,7 @@ Uses GObject introspection capabilities to automatically produce the definition
 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
 
 Example:
-@example
+@lisp
 (get-g-interface-definition "GtkActivatable")
 @result{}
 (DEFINE-G-INTERFACE "GtkActivatable" GTK-ACTIVATABLE
@@ -1845,13 +2507,15 @@ Example:
                      "use-action-appearance" "gboolean" T T)
                     (RELATED-ACTION GTK-ACTIVATABLE-RELATED-ACTION
                      "related-action" "GtkAction" T T))
-@end example
+@end lisp
 
 @node get-g-class-definition
 @section get-g-class-definition
 
-
-@code{get-g-class-definition type &optional lisp-name-package) @result{} definition}
+@Function get-g-class-definition
+@lisp
+(get-g-class-definition type &optional lisp-name-package) @result{} definition
+@end lisp
 
 @table @var
 @item @var{type}
@@ -1867,7 +2531,7 @@ Uses GObject introspection capabilities to automatically produce the definition
 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
 
 Example:
-@example
+@lisp
 (get-g-class-definition "GtkButton")
 @result{}
 (DEFINE-G-OBJECT-CLASS "GtkButton" GTK-BUTTON
@@ -1888,7 +2552,7 @@ Example:
                         (YALIGN GTK-BUTTON-YALIGN "yalign" "gfloat" T T)
                         (IMAGE-POSITION GTK-BUTTON-IMAGE-POSITION
                          "image-position" "GtkPositionType" T T)))
-@end example
+@end lisp
 
 @node Specifying additional properties for CLOS classes
 @section Specifying additional properties for CLOS classes
@@ -1902,7 +2566,7 @@ Variable @code{*additional-properties*} contains a plist that maps GType names t
 To supply the bindings generator with this information, bind @code{*additional-properties*} to such list when the generator is run.
 
 Example:
-@example
+@lisp
 (("GtkTreeViewColumn"
   (:cffi gtk::tree-view
          gtk::tree-view-column-tree-view
@@ -1920,7 +2584,7 @@ Example:
   (:cffi gtk::select-function
          gtk::tree-selection-select-function
          nil gtk::tree-selection-get-selection-function gtk::tree-selection-set-select-function)))
-@end example
+@end lisp
 
 @node Generating names for CLOS classes and accessors
 @section Generating names for CLOS classes and accessors
@@ -1936,20 +2600,21 @@ A string variable specifying the prefix that should to be stripped from the name
 @item @var{*lisp-name-exceptions*}
 A plist mapping from strings (type names) to symbols (class names) that have special name processing.
 Example:
-@example
+@lisp
 `(("GObject" gobject:g-object)
   ("GtkObject" ,(intern "GTK-OBJECT" (find-package :gtk)))
   ("GInitiallyUnowned" gobject::g-initially-unowned)
   ("GtkWindow" ,(intern "GTK-WINDOW" (find-package :gtk)))
   ("GtkUIManager" ,(intern "UI-MANAGER" (find-package :gtk)))
   ("GtkUIManagerItemType" ,(intern "UI-MANAGER-ITEM-TYPE" (find-package :gtk))))
-@end example
+@end lisp
 @end itemize
 
 @node generate-types-hierarchy-to-file
 @section generate-types-hierarchy-to-file
 
-@example
+@Function generate-types-hierarchy-to-file
+@lisp
 (generate-types-hierarchy-to-file file
                                   root-type
                                   &key include-referenced
@@ -1963,7 +2628,7 @@ Example:
                                   objects
                                   exclusions
                                   additional-properties)
-@end example
+@end lisp
 
 @table @var
 @item @var{file}
@@ -1999,7 +2664,7 @@ See @ref{Specifying additional properties for CLOS classes} for more information
 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.
 
 Example of usage:
-@example
+@lisp
 (generate-types-hierarchy-to-file
  "gtk.generated-classes.lisp"
  "GtkObject"
@@ -2028,7 +2693,7 @@ Example of usage:
      nil)
     ...)
    ...))
-@end example
+@end lisp
 
 @bye