Added --disable-debugger to sbcl invokation for html colorization
[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. Values of this type correspond to by-value structures.
198 @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}.
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 @lisp
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 lisp
213
214 @node g-type-string
215 @section g-type-string
216
217 @lisp
218 (g-type-string g-type-designator) @result{} name
219 @end lisp
220
221 @table @var
222 @item @var{g-type-designator}
223 The GType designator for the GType
224 @item @var{name}
225 The name of GType
226 @end table
227
228 Returns the name of GType.
229
230 @node g-type-numeric
231 @section g-type-numeric
232
233 @lisp
234 (g-type-numeric g-type-designator) @result{} GType
235 @end lisp
236
237 @table @var
238 @item @var{g-type-designator}.
239 The GType designator for the GType.
240 @item @var{GType}
241 The numeric identifier of GType
242 @end table
243
244 Returns the numeric identifier of GType
245
246 @node g-type=
247 @section g-type=
248
249 @lisp
250 (g-type= type-1 type-2) @result{} eq
251 @end lisp
252
253 @table @var
254 @item @var{type-1}
255 A GType designator
256 @item @var{type-2}
257 A GType designator
258 @item @var{eq}
259 A boolean that is true if @code{type-1} and @code{type-2} designate the same type.
260 @end table
261
262 @node g-type/=
263 @section g-type/=
264
265 @lisp
266 (g-type/= type-1 type-2) @result{} eq
267 @end lisp
268
269 @table @var
270 @item @var{type-1}
271 A GType designator
272 @item @var{type-2}
273 A GType designator
274 @item @var{eq}
275 A boolean that is true if @code{type-1} and @code{type-2} designate different types.
276 @end table
277
278 @node Type hierarchy and type relations
279 @chapter Type hierarchy and type relations
280
281 @menu
282 * g-type-children::
283 * g-type-parent::
284 * g-type-fundamental::
285 * g-type-depth::
286 * g-type-next-base::
287 @end menu
288
289 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.
290
291 There are functions to query some specific information:
292 @itemize
293 @item @code{g-type-fundamental} retrieves the fundamental type for given type
294 @item @code{g-type-depth} calculates the depth of the type in type hierarchy
295 @item @code{g-type-next-base} calculates the first step in the path from base type to descendent type
296 @end itemize
297
298 @node g-type-children
299 @section g-type-children
300
301 @lisp
302 (g-type-children type) @result{} children
303 @end lisp
304
305 @table @var
306 @item @var{type}
307 A GType designator
308 @item @var{children}
309 A list of GType designators
310 @end table
311
312 Returns the list of descendent types.
313
314 Example:
315 @lisp
316 (g-type-children "GtkButton")
317 @result{}
318 ("GtkToggleButton" "GtkColorButton" "GtkFontButton" "GtkLinkButton" "GtkScaleButton")
319 @end lisp
320
321 @node g-type-parent
322 @section g-type-parent
323
324 @lisp
325 (g-type-parent type) @result{} parent
326 @end lisp
327
328 @table @var
329 @item @var{type}
330 A GType designator
331 @item @var{parent}
332 A GType designator
333 @end table
334
335 Returns the parent of @code{type}.
336
337 Example:
338 @lisp
339 (g-type-parent "GtkToggleButton")
340 @result{}
341 "GtkButton"
342 @end lisp
343
344 @node g-type-fundamental
345 @section g-type-fundamental
346
347 @lisp
348 (g-type-fundamental type) @result{} fundamental-type
349 @end lisp
350
351 @table @var
352 @item @var{type}
353 A GType designator
354 @item @var{fundamental-type}
355 A GType designator for one of the fundamental types
356 @end table
357
358 Returns the fundamental type that is the ancestor of @code{type}.
359
360 Example:
361 @lisp
362 (g-type-fundamental "GtkButton") @result{} "GObject"
363
364 (g-type-fundamental "GtkWindowType") @result{} "GEnum"
365
366 (g-type-fundamental "GdkEvent") @result{} "GBoxed"
367 @end lisp
368
369 @node g-type-depth
370 @section g-type-depth
371
372 @lisp
373 (g-type-depth type) @result{} depth
374 @end lisp
375
376 @table @var
377 @item @var{type}
378 A GType designator
379 @item @var{depth}
380 An integer
381 @end table
382
383 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.
384
385 Example:
386 @lisp
387 (g-type-depth "GObject") @result{} 1
388 (g-type-depth "GInitiallyUnowned") @result{} 2
389 @end lisp
390
391 @node g-type-next-base
392 @section g-type-next-base
393
394 @lisp
395 (g-type-next-base leaf-type root-type) @result{} base-type
396 @end lisp
397
398 @table @var
399 @item @var{leaf-type}
400 A GType designator
401 @item @var{root-type}
402 A GType designator
403 @item @var{base-type}
404 A GType designator
405 @end table
406
407 Returns the next type that should be traversed from @code{root-type} in order to reach @code{leaf-type}. E.g., given type hierarchy:
408 @lisp
409 + GObject
410  \
411   + GInitiallyUnowned
412    \
413     + GtkObject
414     |\
415     | + GtkAdjustment
416      \
417       + GtkWidget
418        \
419         + GtkContainer
420          \
421           + GtkTable
422 @end lisp
423
424 the following will be returned:
425
426 @lisp
427 (g-type-next-base "GtkTable" "GObject") @result{} "GInitiallyUnowned"
428 (g-type-next-base "GtkTable" "GInitiallyUnowned") @result{} "GtkObject"
429 (g-type-next-base "GtkTable" "GtkObject") @result{} "GtkWidget"
430 (g-type-next-base "GtkTable" "GtkWidget") @result{} "GtkContainer"
431 (g-type-next-base "GtkTable" "GtkContainer") @result{} "GtkTable"
432 @end lisp
433
434 @node Object types information
435 @chapter Object types information
436 @menu
437 * g-class-property-definition::
438 * class-properties::
439 * class-property-info::
440 * interface-properties::
441 * signal-info::
442 * type-signals::
443 * parse-signal-name::
444 * query-signal-info::
445 * g-type-interfaces::
446 * g-type-interface-prerequisites::
447 @end menu
448
449 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.
450
451 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.
452
453 @node g-class-property-definition
454 @section g-class-property-definition
455
456 @lisp
457 (defstruct g-class-property-definition
458   name
459   type
460   readable
461   writable
462   constructor
463   constructor-only
464   owner-type)
465 @end lisp
466
467 @table @var
468 @item @var{name}
469 A string that names the property
470 @item @var{type}
471 A GType designator. Identifies the type of the property
472 @item @var{readable}
473 A boolean. Identifies whether the property can be read
474 @item @var{writable}
475 A boolean. Identifies whether the property can be assigned
476 @item @var{constructor}
477 A boolean. Identifies whether constructor of object accepts this property
478 @item @var{constructor-only}
479 A boolean. Identifies whether this property may only be set in constructor, not in property setter
480 @item @var{owner-type}
481 A GType designator. Identifies the type on which the property was defined.
482 @end table
483
484 This structure identifies a single property. Its field specify attributes of a property.
485
486 Structures of this type have shortened print syntax:
487 @lisp
488 #<PROPERTY gchararray GtkButton.label (flags: readable writable constructor)> 
489 @end lisp
490
491 (When @code{*print-readably*} is T, usual @code{defstruct} print syntax is used)
492
493 This syntax specifies:
494 @itemize
495 @item type of property
496 @item the owner type of property
497 @item name of property
498 @item additional flags of property
499 @end itemize
500
501 @node class-properties
502 @section class-properties
503
504 @lisp
505 (class-properties type) @result{} properties
506 @end lisp
507
508 @table @var
509 @item @var{type}
510 A GType designator. Specifies the object type (class)
511 @item @var{properties}
512 A list of @code{g-property-definition} structures.
513 @end table
514
515 This function returns the list of properties that are available in class @code{type}.
516
517 Example:
518 @lisp
519 (class-properties "GtkWidget")
520 @result{}
521 (#<PROPERTY gpointer GtkObject.user-data (flags: readable writable)>
522  #<PROPERTY gchararray GtkWidget.name (flags: readable writable)>
523  #<PROPERTY GtkContainer GtkWidget.parent (flags: readable writable)>
524  #<PROPERTY gint GtkWidget.width-request (flags: readable writable)>
525  #<PROPERTY gint GtkWidget.height-request (flags: readable writable)>
526  #<PROPERTY gboolean GtkWidget.visible (flags: readable writable)>
527  #<PROPERTY gboolean GtkWidget.sensitive (flags: readable writable)>
528  #<PROPERTY gboolean GtkWidget.app-paintable (flags: readable writable)>
529  #<PROPERTY gboolean GtkWidget.can-focus (flags: readable writable)>
530  #<PROPERTY gboolean GtkWidget.has-focus (flags: readable writable)>
531  #<PROPERTY gboolean GtkWidget.is-focus (flags: readable writable)>
532  #<PROPERTY gboolean GtkWidget.can-default (flags: readable writable)>
533  #<PROPERTY gboolean GtkWidget.has-default (flags: readable writable)>
534  #<PROPERTY gboolean GtkWidget.receives-default (flags: readable writable)>
535  #<PROPERTY gboolean GtkWidget.composite-child (flags: readable)>
536  #<PROPERTY GtkStyle GtkWidget.style (flags: readable writable)>
537  #<PROPERTY GdkEventMask GtkWidget.events (flags: readable writable)>
538  #<PROPERTY GdkExtensionMode GtkWidget.extension-events (flags: readable writable)>
539  #<PROPERTY gboolean GtkWidget.no-show-all (flags: readable writable)>
540  #<PROPERTY gboolean GtkWidget.has-tooltip (flags: readable writable)>
541  #<PROPERTY gchararray GtkWidget.tooltip-markup (flags: readable writable)>
542  #<PROPERTY gchararray GtkWidget.tooltip-text (flags: readable writable)>
543  #<PROPERTY GdkWindow GtkWidget.window (flags: readable)>)
544 @end lisp
545
546 @node class-property-info
547 @section class-property-info
548 @lisp
549 (class-property-info type property-name) @result{} property
550 @end lisp
551
552 @table @var
553 @item @var{type}
554 A GType designator
555 @item @var{property-name}
556 A string naming the property
557 @item @var{property}
558 An instance of @code{g-property-definition} structure
559 @end table
560
561 Returns the property information for a single property.
562
563 Example:
564 @lisp
565 (class-property-info "GtkButton" "label")
566 @result{}
567 #<PROPERTY gchararray GtkButton.label (flags: readable writable constructor)>
568 @end lisp
569
570 @node interface-properties
571 @section interface-properties
572
573 @lisp
574 (interface-properties type) @result{} properties
575 @end lisp
576
577 @table @var
578 @item @var{type}
579 A GType designator
580 @item @var{properties}
581 A list of @code{g-property-definition} structures
582 @end table
583
584 This function returns the list of properties that are available in interface @code{type}.
585
586 Example:
587 @lisp
588 (interface-properties "GtkFileChooser")
589 @result{}
590 (#<PROPERTY GtkWidget GtkFileChooser.extra-widget (flags: readable writable)>
591  #<PROPERTY gboolean GtkFileChooser.use-preview-label (flags: readable writable)>
592  #<PROPERTY gboolean GtkFileChooser.preview-widget-active (flags: readable writable)>
593  #<PROPERTY gboolean GtkFileChooser.show-hidden (flags: readable writable)>
594  #<PROPERTY gchararray GtkFileChooser.file-system-backend (flags: writable constructor-only)>
595  #<PROPERTY GtkFileChooserAction GtkFileChooser.action (flags: readable writable)>
596  #<PROPERTY GtkFileFilter GtkFileChooser.filter (flags: readable writable)>
597  #<PROPERTY gboolean GtkFileChooser.select-multiple (flags: readable writable)>
598  #<PROPERTY GtkWidget GtkFileChooser.preview-widget (flags: readable writable)>
599  #<PROPERTY gboolean GtkFileChooser.local-only (flags: readable writable)>
600  #<PROPERTY gboolean GtkFileChooser.do-overwrite-confirmation (flags: readable writable)>)
601 @end lisp
602
603 @node signal-info
604 @section signal-info
605
606 @lisp
607 (defstruct signal-info
608   id
609   name
610   owner-type
611   flags
612   return-type
613   param-types
614   detail)
615 @end lisp
616
617 @table @var
618 @item @var{id}
619 An integer - the identifier of a signal
620 @item @var{name}
621 Name of a signal
622 @item @var{owner-type}
623 A GType designator identifying the type on which the signal was defined
624 @item @var{flags}
625 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
626 @item @var{return-type}
627 The return type of a signal (and signal handlers)
628 @item @var{param-types}
629 A list of GType designators that specify the types of signal parameters
630 @item @var{detail}
631 A string. Specifies the "detail" part of a signal name. E.g., @code{"label"} for signal @code{"notify::label"}.
632 @end table
633
634 When @code{*print-readably*} is nil, the following print syntax is used:
635 @lisp
636 #<Signal [#1] void GObject.notify::label(GParam) [RUN-FIRST, NO-RECURSE, DETAILED, ACTION, NO-HOOKS]>
637 #<Signal [#54] gboolean GtkWidget.proximity-in-event(GdkEvent) [RUN-LAST]>
638 #<Signal [#64] void GtkWidget.drag-data-received(GdkDragContext, gint, gint, GtkSelectionData, guint, guint) [RUN-LAST]>
639 #<Signal [#8] void GtkObject.destroy() [RUN-CLEANUP, NO-RECURSE, NO-HOOKS]>
640 @end lisp
641
642 This syntax specifies:
643 @itemize
644 @item the signal id
645 @item signal return type
646 @item owner type
647 @item signal name
648 @item detail
649 @item list of types of parameters
650 @item flags
651 @end itemize
652
653 @node type-signals
654 @section type-signals
655 @lisp
656 (type-signals type &key (include-inherited t)) @result{} signals
657 @end lisp
658 @table @var
659 @item @var{type}
660 A GType designator
661 @item @var{signals}
662 A list of @code{signal-info} structures
663 @item @var{include-inherited}
664 A boolean that specifies whether to include signals defined on this type or also on ancestor types.
665 @end table
666
667 Returns the list of signals that are available in type @code{type}.
668
669 Example:
670 @lisp
671 (type-signals "GtkLabel" :include-inherited nil)
672 @result{}
673 (#<Signal [#138] void GtkLabel.move-cursor(GtkMovementStep, gint, gboolean) [RUN-LAST, ACTION]>
674  #<Signal [#139] void GtkLabel.copy-clipboard() [RUN-LAST, ACTION]>
675  #<Signal [#140] void GtkLabel.populate-popup(GtkMenu) [RUN-LAST]>)
676 @end lisp
677
678 @node parse-signal-name
679 @section parse-signal-name
680
681 @lisp
682 (parse-signal-name type signal-name) @result{} signal
683 @end lisp
684
685 @table @var
686 @item @var{type}
687 A GType designator that has the signal.
688 @item @var{signal-name}
689 A string that identifies the signal.
690 @item @var{signal}
691 A list @code{signal-info} structures.
692 @end table
693
694 Parses the signal name and returns the corresponding information. @code{signal-name} may include the detail part.
695
696 Example:
697 @lisp
698 (parse-signal-name "GObject" "notify::label")
699 @result{}
700 #<Signal [#1] void GObject.notify::label(GParam) [RUN-FIRST, NO-RECURSE, DETAILED, ACTION, NO-HOOKS]>
701 @end lisp
702
703 @node query-signal-info
704 @section query-signal-info
705 @lisp
706 (query-signal-info signal-id) @result{} signal
707 @end lisp
708 @table @var
709 @item @var{signal-id}
710 An integer identifying the signal
711 @item @var{signal}
712 An instance of @code{signal-info} structure
713 @end table
714
715 Retrieves the signal information by its id.
716
717 Example:
718 @lisp
719 (query-signal-info 73)
720 @result{}
721 #<Signal [#73] gboolean GtkWidget.show-help(GtkWidgetHelpType) [RUN-LAST, ACTION]>
722 @end lisp
723
724 @node g-type-interfaces
725 @section g-type-interfaces
726
727 @lisp
728 (g-type-interfaces type) @result{} interfaces
729 @end lisp
730
731 @table @var
732 @item @var{type}
733 A GType designator
734 @item @var{interfaces}
735 A list of GType designators
736 @end table
737
738 Returns the list of interfaces that @code{type} implements.
739
740 Example:
741 @lisp
742 (g-type-interfaces "GtkButton")
743 @result{}
744 ("AtkImplementorIface" "GtkBuildable" "GtkActivatable")
745 @end lisp
746
747 @node g-type-interface-prerequisites
748 @section g-type-interface-prerequisites
749
750 @lisp
751 (g-type-interface-prerequisites type) @result{} types
752 @end lisp
753
754 @table @var
755 @item @var{type}
756 A GType designator of interface
757 @item @var{types}
758 A list of GType designators specifying the interface prerequisites
759 @end table
760
761 Returns the prerequisites of an interface @code{type}. Prerequisite is a type that should be an ancestor of a type implementing interface @code{type}.
762
763 Example:
764 @lisp
765 (g-type-interface-prerequisites "GtkCellEditable")
766 @result{}
767 ("GtkObject" "GtkWidget")
768 @end lisp
769
770 @node Enum types information
771 @chapter Enum types information
772 @menu
773 * enum-item::
774 * flags-item::
775 * get-enum-items::
776 * get-flags-items::
777 @end menu
778
779 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.
780
781 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.
782
783 @node enum-item
784 @section enum-item
785 @lisp
786 (defstruct enum-item
787   name value nick)
788 @end lisp
789
790 @table @var
791 @item @var{name}
792 A string - name of enum item
793 @item @var{value}
794 An integer - numeric value of enum item
795 @item @var{nick}
796 A string - short name of an enum item
797 @end table
798
799 Structure @code{enum-item} represents a single item of an enumeration type.
800
801 Example:
802 @lisp
803 #S(ENUM-ITEM :NAME "GTK_WINDOW_TOPLEVEL" :VALUE 0 :NICK "toplevel")
804 @end lisp
805
806 @node flags-item
807 @section flags-item
808 @lisp
809 (defstruct flags-item
810   name value nick)
811 @end lisp
812
813 @table @var
814 @item @var{name}
815 A string - name of flags item
816 @item @var{value}
817 An integer - numeric value of flags item
818 @item @var{nick}
819 A string - short name of an flags item
820 @end table
821
822 Structure @code{flags-item} represents a single item of an flags type.
823
824 Example:
825 @lisp
826 #S(FLAGS-ITEM
827    :NAME "GDK_POINTER_MOTION_HINT_MASK"
828    :VALUE 8
829    :NICK "pointer-motion-hint-mask")
830 @end lisp
831
832 @node get-enum-items
833 @section get-enum-items
834
835 @lisp
836 (get-enum-items type) @result{} items
837 @end lisp
838
839 @table @var
840 @item @var{type}
841 A GType designator of an enum type
842 @item @var{items}
843 A list of @code{enum-item} structures
844 @end table
845
846 Returns a list of items in an enumeration
847
848 Example:
849 @lisp
850 (get-enum-items "GtkScrollType")
851 @result{}
852 (#S(ENUM-ITEM :NAME "GTK_SCROLL_NONE" :VALUE 0 :NICK "none")
853  #S(ENUM-ITEM :NAME "GTK_SCROLL_JUMP" :VALUE 1 :NICK "jump")
854  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_BACKWARD" :VALUE 2 :NICK "step-backward")
855  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_FORWARD" :VALUE 3 :NICK "step-forward")
856  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_BACKWARD" :VALUE 4 :NICK "page-backward")
857  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_FORWARD" :VALUE 5 :NICK "page-forward")
858  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_UP" :VALUE 6 :NICK "step-up")
859  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_DOWN" :VALUE 7 :NICK "step-down")
860  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_UP" :VALUE 8 :NICK "page-up")
861  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_DOWN" :VALUE 9 :NICK "page-down")
862  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_LEFT" :VALUE 10 :NICK "step-left")
863  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_RIGHT" :VALUE 11 :NICK "step-right")
864  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_LEFT" :VALUE 12 :NICK "page-left")
865  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_RIGHT" :VALUE 13 :NICK "page-right")
866  #S(ENUM-ITEM :NAME "GTK_SCROLL_START" :VALUE 14 :NICK "start")
867  #S(ENUM-ITEM :NAME "GTK_SCROLL_END" :VALUE 15 :NICK "end"))
868 @end lisp
869
870 @node get-flags-items
871 @section get-flags-items
872
873 @lisp
874 (get-flags-items type) @result{} items
875 @end lisp
876
877 @table @var
878 @item @var{type}
879 A GType designator of an flags type
880 @item @var{items}
881 A list of @code{flags-item} structures
882 @end table
883
884 Returns a list of items in an flags type
885
886 Example:
887 @lisp
888 (get-flags-items "GtkAttachOptions")
889 @result{}
890 (#S(FLAGS-ITEM :NAME "GTK_EXPAND" :VALUE 1 :NICK "expand")
891  #S(FLAGS-ITEM :NAME "GTK_SHRINK" :VALUE 2 :NICK "shrink")
892  #S(FLAGS-ITEM :NAME "GTK_FILL" :VALUE 4 :NICK "fill"))
893 @end lisp
894
895 @node Using GValues
896 @chapter Using GValues
897 @menu
898 * g-value-zero::
899 * g-value-init::
900 * g-value-unset::
901 * parse-g-value::
902 * set-g-value::
903 * Registering types::
904 @end menu
905
906 GValue is a generic container for arbitrary value of type supported by GType system. Refer to GObject documentation for more detailed information.
907
908 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.
909
910 GValue is used whenever a value of unkown type should be passed. It is used in:
911 @itemize
912 @item Closure marshal functions
913 @item Property get and set functions
914 @end itemize
915
916 Example of usage:
917 @lisp
918 (cffi:with-foreign-object (gval 'g-value)
919   (set-g-value gval "Hello" "gchararray" :zero-g-value t)
920   (format t "~S~%" (parse-g-value gval))
921   (g-value-unset gval))
922 @result{}
923 "Hello"
924 @end lisp
925
926 @node g-value-zero
927 @section g-value-zero
928 @lisp
929 (g-value-zero g-value)
930 @end lisp
931 @table @var
932 @item @var{g-value}
933 A foreign pointer to GValue structure.
934 @end table
935
936 Initializes the GValue to "unset" state. Equivalent of the following initializer in C:
937 @lisp
938 GValue value = @{ 0 @};
939 @end lisp
940
941 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).
942
943 @node g-value-init
944 @section g-value-init
945
946 @lisp
947 (g-value-init value type)
948 @end lisp
949 @table @var
950 @item @var{value}
951 A foreign pointer to GValue structure
952 @item @var{type}
953 A GType designator
954 @end table
955
956 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).
957
958 @node g-value-unset
959 @section g-value-unset
960 @lisp
961 (g-value-unset value)
962 @end lisp
963 @table @var
964 @item @var{value}
965 A foreign pointer to GValue structure.
966 @end table
967
968 Unsets the GValue. This frees all resources associated with GValue.
969
970 @node parse-g-value
971 @section parse-g-value
972 @lisp
973 (parse-g-value value) @result{} object
974 @end lisp
975 @table @var
976 @item @var{value}
977 A foreign pointer to GValue structure
978 @item @var{object}
979 A Lisp object
980 @end table
981
982 Retrieves the object from GValue structure.
983
984 @node set-g-value
985 @section set-g-value
986 @lisp
987 (set-g-value gvalue object type &key zero-g-value unset-g-value (g-value-init t))
988 @end lisp
989
990 @table @var
991 @item @var{gvalue}
992 A foreign pointer to GValue structure
993 @item @var{object}
994 An object that is to be assigned to @code{gvalue}
995 @item @var{type}
996 A GType designator specifying what GType should be set
997 @item @var{unset-g-value}
998 A boolean specifying whether to call @code{g-value-unset} before assigment.
999 @item @var{zero-g-value}
1000 A boolean specifying whether to call @code{g-value-zero} before assignment
1001 @item @var{g-value-init}
1002 A boolean specifying whether to call @code{g-value-init} before assignment
1003 @end table
1004
1005 Assigns the @code{object} to the @code{gvalue}. When GValue is not used, call @code{g-value-unset} to deinitialize the @code{GValue}.
1006
1007 @node Registering types
1008 @section Registering types
1009
1010 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.
1011
1012 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.
1013
1014 @subsection
1015 @code{(register-enum-type name type)}
1016 @table @var
1017 @item @var{name}
1018 A string naming the GEnum type
1019 @item @var{type}
1020 A symbol - name of CFFI foreign enum type
1021 @end table
1022
1023 Registers the @code{type} to be used for passing value of GEnum type @code{name} between GObject and Lisp.
1024
1025 Example:
1026 @lisp
1027 (defcenum text-direction
1028   :none :ltr :rtl)
1029 (register-enum-type "GtkTextDirection" 'text-direction)
1030 @end lisp
1031
1032 @subsection
1033 @code{(register-flags-type name type)}
1034 @table @var
1035 @item @var{name}
1036 A string naming the GFlags type
1037 @item @var{type}
1038 A symbol - name of CFFI foreign flags type
1039 @end table
1040
1041 Registers the @code{type} to be used for passing value of GFlags type @code{name} between GObject and Lisp.
1042
1043 Example:
1044 @lisp
1045 (defcenum state-type
1046   :normal :active :prelight :selected :insensitive)
1047 (register-enum-type "GtkStateType" 'state-type)
1048 @end lisp
1049
1050 @node Stable pointers
1051 @chapter Stable pointers
1052 @menu
1053 * allocate-stable-pointer::
1054 * free-stable-pointer::
1055 * stable-pointer-value::
1056 * with-stable-pointer::
1057 @end menu
1058
1059 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.
1060
1061 @node allocate-stable-pointer
1062 @section allocate-stable-pointer
1063
1064 @lisp
1065 (allocate-stable-pointer thing) @result{} stable-pointer
1066 @end lisp
1067
1068 @table @var
1069 @item @var{thing}
1070 An arbitrary Lisp object
1071 @item @var{stable-pointer}
1072 A foreign pointer
1073 @end table
1074
1075 Allocates a stable pointer to @code{thing}.
1076
1077 (Note: @var{stable-pointer} should not be dereferenced with @code{cffi:mem-ref}. It should only be dereferenced with @code{stable-pointer-value})
1078
1079 Example:
1080 @lisp
1081 (allocate-stable-pointer (lambda (x) (+ x 10)))
1082 @result{}
1083 #.(SB-SYS:INT-SAP #X00000002)
1084
1085 (stable-pointer-value *)
1086 @result{}
1087 #<FUNCTION (LAMBDA (X)) @{1004D016F9@}>
1088
1089 (free-stable-pointer **)
1090 @result{}
1091 NIL
1092 @end lisp
1093
1094 @node free-stable-pointer
1095 @section free-stable-pointer
1096
1097 @lisp
1098 (free-stable-pointer stable-pointer)
1099 @end lisp
1100
1101 @table @var
1102 @item @var{stable-pointer}
1103 A foreign pointer that was created with @code{allocate-stable-pointer}.
1104 @end table
1105
1106 Frees the stable pointer, enabling the garbage collector to reclaim the object.
1107
1108 Example:
1109 @lisp
1110 (allocate-stable-pointer (lambda (x) (+ x 10)))
1111 @result{}
1112 #.(SB-SYS:INT-SAP #X00000002)
1113
1114 (stable-pointer-value *)
1115 @result{}
1116 #<FUNCTION (LAMBDA (X)) @{1004D016F9@}>
1117
1118 (free-stable-pointer **)
1119 @result{}
1120 NIL
1121 @end lisp
1122
1123 @node stable-pointer-value
1124 @section stable-pointer-value
1125
1126 @lisp
1127 (stable-pointer-value stable-pointer) @result{} thing
1128 (setf (stable-pointer-value stable-pointer) thing)
1129 @end lisp
1130
1131 @table @var
1132 @item @var{stable-pointer}
1133 A foreign pointer created by @code{allocate-stable-pointer}
1134 @item @var{thing}
1135 A Lisp object
1136 @end table
1137
1138 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.
1139
1140 @node with-stable-pointer
1141 @section with-stable-pointer
1142
1143 @lisp
1144 (with-stable-pointer (ptr expr) &body body)
1145 @end lisp
1146
1147 @table @var
1148 @item @var{ptr}
1149 A variable that will be bound to the stable pointer
1150 @item @var{expr}
1151 An expression that will be evaluated once and its value will be bound to stable pointer's value
1152 @end table
1153
1154 Executes the body with the @code{ptr} variable being bound to a stable pointer whose value is determined by @code{expr}.
1155
1156 Example:
1157 @lisp
1158 (with-stable-pointer (ptr (lambda (x) (+ x 10)))
1159   (print (stable-pointer-value ptr)))
1160 ;;Prints:
1161 #<FUNCTION (LAMBDA (X)) @{1004807E79@}>
1162 @end lisp
1163
1164 @node Closures
1165 @chapter Closures
1166
1167 Closure are anonymous functions that capture their lexical environment.
1168
1169 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).
1170
1171 @section create-g-closure
1172 @code{(create-g-closure fn) @result{} closure}
1173
1174 @table @var
1175 @item @var{fn}
1176 A function that will be called by closure invokation
1177 @item @var{closure}
1178 A foreign pointer to allocated closure
1179 @end table
1180
1181 Allocates the closure. The closure is destroyed automatically by GObject.
1182
1183 Example:
1184 @lisp
1185 (create-g-closure (lambda (x) (+ x 10)))
1186 @result{}
1187 #.(SB-SYS:INT-SAP #X006D7B20)
1188 @end lisp
1189
1190 Example of usage from GObject binding code:
1191 @lisp
1192 (defun connect-signal (object signal handler &key after)
1193   (g-signal-connect-closure (ensure-object-pointer object)
1194                             signal
1195                             (create-g-closure handler)
1196                             after))
1197 @end lisp
1198
1199 (TODO: GObject defines finer closure API: g_closure_ref, g_closure_unref, g_closure_invoke. It should be bound.)
1200
1201 @node GObject low-level
1202 @chapter GObject low-level
1203 @menu
1204 * g-object-call-constructor::
1205 * g-type-from-object::
1206 * g-object-call-get-property::
1207 * g-object-call-set-property::
1208 @end menu
1209
1210 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.
1211
1212 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.
1213
1214 @node g-object-call-constructor
1215 @section g-object-call-constructor
1216
1217 @lisp
1218 (g-object-call-constructor object-type args-names args-values &optional args-types) @result{} object-ptr
1219 @end lisp
1220
1221 @table @var
1222 @item @var{object-type}
1223 A GType designator that specifies the object type that is to be created
1224 @item @var{args-names}
1225 A list of strings naming the arguments to constructor
1226 @item @var{args-value}
1227 A list of arguments values (in the same order as args-names)
1228 @item @var{args-types}
1229 Optional list of arguments types (in the same order as args-names). If not specified, it is detected automatically
1230 @item @var{object-ptr}
1231 A foreign pointer to newly created instance
1232 @end table
1233
1234 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}.
1235
1236 Example:
1237 @lisp
1238 (g-object-call-constructor "GtkButton" '("label" "use-underline") '("Hello" t) '("gchararray" "gboolean"))
1239 @result{}
1240 #.(SB-SYS:INT-SAP #X006D8900)
1241
1242 (g-object-call-get-property * "label")
1243 @result{}
1244 "Hello"
1245
1246 (g-object-call-get-property ** "use-underline")
1247 @result{}
1248 T
1249 @end lisp
1250
1251 @node g-type-from-object
1252 @section g-type-from-object
1253
1254 @lisp
1255 (g-type-from-object object-ptr) @result{} type
1256 @end lisp
1257
1258 @table @var
1259 @item @var{object-ptr}
1260 A foreign pointer to a GObject instance
1261 @item @var{type}
1262 A GType designator
1263 @end table
1264
1265 Returns the type of an object by a pointer to its instance
1266
1267 Example:
1268 @lisp
1269 (g-type-from-object (g-object-call-constructor "GtkButton" nil nil))
1270 @result{}
1271 "GtkButton"
1272 @end lisp
1273
1274 @node g-object-call-get-property
1275 @section g-object-call-get-property
1276
1277 @lisp
1278 (g-object-call-get-property object-ptr property-name &optional property-type) @result{} property-value
1279 @end lisp
1280
1281 @table @var
1282 @item @var{object-ptr}
1283 A foreign pointer to a GObject instance
1284 @item @var{property-name}
1285 A string naming the property
1286 @item @var{property-type}
1287 Optional GType designator specifying the type of a property
1288 @item @var{property-value}
1289 The value of a property
1290 @end table
1291
1292 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.
1293
1294 Example:
1295 @lisp
1296 (g-object-call-constructor "GtkButton" '("label" "use-underline") '("Hello" t) '("gchararray" "gboolean"))
1297 @result{}
1298 #.(SB-SYS:INT-SAP #X006D8900)
1299
1300 (g-object-call-get-property * "label")
1301 @result{}
1302 "Hello"
1303
1304 (g-object-call-get-property ** "use-underline")
1305 @result{}
1306 T
1307 @end lisp
1308
1309 @node g-object-call-set-property
1310 @section g-object-call-set-property
1311
1312 @lisp
1313 (g-object-call-set-property object-ptr property-name new-value &optional property-type)
1314 @end lisp
1315
1316 @table @var
1317 @item @var{object-ptr}
1318 A foreign pointer to a GObject instance
1319 @item @var{property-name}
1320 A string naming the property
1321 @item @var{new-value}
1322 A new value of a property
1323 @item @var{property-type}
1324 Optional GType designator specifying the type of a property
1325 @end table
1326
1327 Sets the property value of property @code{property-name} of object @code{object-ptr} to @code{new-value}.
1328
1329 Example:
1330 @lisp
1331 (g-object-call-constructor "GtkButton" nil nil)
1332 @result{}
1333 #.(SB-SYS:INT-SAP #X006D8B40)
1334
1335 (g-object-call-set-property * "label" "Hello")
1336 @result{}
1337 ; No value
1338
1339 (g-object-call-get-property ** "label")
1340 @result{}
1341 "Hello"
1342 @end lisp
1343
1344 @node GObject high-level
1345 @chapter GObject high-level
1346 @menu
1347 * GObject metaclass::
1348 * Using objects::
1349 * Signals::
1350 * GObject foreign class::
1351 @end menu
1352
1353 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):
1354 @itemize
1355 @item objects are created with @code{make-instance}
1356 @item properties are used as regular slots
1357 @end itemize
1358
1359 GObjects are reference counted, and CL-GTK2-GOBJECT manages its own reference to GObjects. This enables to have transparent garbage collection of unreferenced GObjects.
1360
1361 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.
1362
1363 Example GObject class of definition:
1364 @lisp
1365 (defclass dialog (gtk-window atk-implementor-iface buildable)
1366   ((has-separator :accessor dialog-has-separator
1367                   :initarg :has-separator
1368                   :allocation :gobject-property
1369                   :g-property-type "gboolean"
1370                   :g-property-name "has-separator"))
1371   (:metaclass gobject-class)
1372   (:g-type-name . "GtkDialog")
1373   (:g-type-initializer . "gtk_dialog_get_type"))
1374 @end lisp
1375
1376 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.
1377
1378 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.
1379
1380 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).
1381
1382 @node GObject metaclass
1383 @section GObject metaclass
1384
1385 See MOP for information what metaclass is and why is it useful.
1386
1387 GObject metaclass @code{gobject-class} bridges two object systems: GObject and CLOS.
1388
1389 Classes that correspond to GObject classes are instances of this class.
1390
1391 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}.
1392
1393 This class has the following slots:
1394 @itemize
1395 @item @var{g-type-name} (accessor @code{gobject-class-g-type-name}, initarg @code{:g-type-name})
1396
1397 Specifies the name of GObject class
1398 @item @var{g-type-initializer} (accessor @code{gobject-class-g-type-initializer}, initarg @code{:g-type-initializer})
1399
1400 Name of type initializer function. This function initializes the class and returns its GType. Typically it is named @code{class_get_type}.
1401 @item @var{interface-p} (accessor @code{gobject-class-interface-p}, initarg @code{:interface-p})
1402
1403 A boolean specifying whether this CLOS class corresponds to GInterface.
1404 @end itemize
1405
1406 This metaclass defines the GObject classes.
1407
1408 Slots which have @code{:allocation} of @code{:gobject-property} are mapped to GObject properties. Such slots have following attributes:
1409 @itemize
1410 @item @var{:g-property-type}
1411
1412 A string naming GType of property
1413 @item @var{:g-property-name}
1414
1415 A name of a property
1416 @end itemize
1417
1418 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:
1419 @itemize
1420 @item @var{:g-property-type}
1421 A CFFI foreign type of property
1422 @item @var{:g-getter}
1423 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)}.
1424 @item @var{:g-setter}
1425 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))}.
1426 @end itemize
1427
1428 Initargs of a slot are used to construct the GObject class.
1429
1430 Example:
1431 @lisp
1432 (defclass container (widget atk-implementor-iface buildable)
1433     ((border-width :allocation :gobject-property
1434                    :g-property-type "guint"
1435                    :accessor container-border-width
1436                    :initarg :border-width
1437                    :g-property-name "border-width")
1438      (resize-mode :allocation :gobject-property
1439                   :g-property-type "GtkResizeMode"
1440                   :accessor container-resize-mode
1441                   :initarg :resize-mode
1442                   :g-property-name "resize-mode")
1443      (child :allocation :gobject-property
1444             :g-property-type "GtkWidget"
1445             :accessor container-child
1446             :initarg :child
1447             :g-property-name "child")
1448      (focus-child :allocation :gobject-fn
1449                   :g-property-type g-object
1450                   :accessor container-focus-child
1451                   :initarg :focus-child
1452                   :g-getter "gtk_container_get_focus_child"
1453                   :g-setter "gtk_container_set_focus_child")
1454      (focus-vadjustment :allocation :gobject-fn
1455                         :g-property-type (g-object adjustment)
1456                         :accessor container-focus-vadjustment
1457                         :initarg :focus-vadjustment
1458                         :g-getter "gtk_container_get_focus_vadjustment"
1459                         :g-setter "gtk_container_set_focus_vadjustment")
1460      (focus-hadjustment :allocation :gobject-fn
1461                         :g-property-type (g-object adjustment)
1462                         :accessor container-focus-hadjustment
1463                         :initarg :focus-hadjustment
1464                         :g-getter "gtk_container_get_focus_hadjustment"
1465                         :g-setter "gtk_container_set_focus_hadjustment"))
1466     (:metaclass gobject-class)
1467     (:g-type-name . "GtkContainer")
1468     (:g-type-initializer . "gtk_container_get_type"))
1469 @end lisp
1470 (note the dot in @code{(:g-type-name . "GtkContainer")} and in @code{(:g-type-initializer . "gtk_container_get_type")}. It should be present)
1471
1472 @node Using objects
1473 @section Using objects
1474 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.
1475
1476 Example:
1477 @lisp
1478 (make-instance 'gtk:dialog :has-separator t)
1479 @result{}
1480 #<GTK:DIALOG @{10036C5A71@}>
1481
1482 (defvar *d* (make-instance 'gtk:dialog :has-separator t))
1483 @result{}
1484 *D*
1485
1486 (gtk:dialog-has-separator *d*)
1487 @result{}
1488 T
1489
1490 (setf (gtk:dialog-has-separator *d*) nil)
1491 @result{}
1492 NIL
1493
1494 (gtk:dialog-has-separator *d*)
1495 @result{}
1496 NIL
1497 @end lisp
1498
1499 @node Signals
1500 @section Signals
1501
1502 To connect handler to a signal, @code{connect-signal} function is used.
1503
1504 @code{(connect-signal object signal handler &key after)}
1505
1506 @table @var
1507 @item @var{object}
1508 An instance of GObject object
1509 @item @var{signal}
1510 A signal name
1511 @item @var{handler}
1512 A function
1513 @item @var{after}
1514 A boolean specifying whether the handler should be called after the default handler
1515 @end table
1516
1517 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.
1518
1519 Example:
1520 @lisp
1521 (defvar *d* (make-instance 'gtk:dialog))
1522 @result{}
1523 *D*
1524
1525 *d*
1526 @result{}
1527 #<GTK:DIALOG @{1002D866F1@}>
1528
1529 (parse-signal-name "GtkDialog" "response")
1530 @result{}
1531 #<Signal [#86] void GtkDialog.response(gint) [RUN-LAST]>
1532
1533 (connect-signal *d* "response" (lambda (dialog response-value) (print dialog) (print response-value)))
1534
1535 (emit-signal *d* "response" 14)
1536 @result{}
1537 ;; Prints:
1538 #<GTK:DIALOG @{1002D866F1@}>
1539 14 
1540 @end lisp
1541
1542 Function @code{emit-signal} is used to emit signals on objects.
1543
1544 @code{(emit-signal object signal-name &rest args) @result{} return-value}
1545
1546 @table @var
1547 @item @var{object}
1548 An object on which the signal should be emitted
1549 @item @var{signal-name}
1550 A string naming the signal
1551 @item @var{args}
1552 Arguments for a signal
1553 @item @var{return-value}
1554 Return value of a signal
1555 @end table
1556
1557 Emits the signal and calls all handlers of the signal. If signal returns a value, it is returned from @code{emit-signal}.
1558
1559 Example:
1560 @lisp
1561 (defvar *d* (make-instance 'gtk:dialog))
1562 @result{}
1563 *D*
1564
1565 *d*
1566 @result{}
1567 #<GTK:DIALOG @{1002D866F1@}>
1568
1569 (parse-signal-name "GtkDialog" "response")
1570 @result{}
1571 #<Signal [#86] void GtkDialog.response(gint) [RUN-LAST]>
1572
1573 (connect-signal *d* "response" (lambda (dialog response-value) (print dialog) (print response-value)))
1574
1575 (emit-signal *d* "response" 14)
1576 @result{}
1577 ;; Prints:
1578 #<GTK:DIALOG @{1002D866F1@}>
1579 14 
1580 @end lisp
1581
1582 @node GObject foreign class
1583 @section GObject foreign class
1584
1585 To enable passing GObject instance between Lisp code and foreign code, @code{g-object} foreign type is introduced.
1586
1587 This type has the following syntax:
1588 @code{(g-object &optional type)} or @code{g-object}.
1589
1590 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.
1591
1592 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.
1593
1594 This defines the function that may be called with instances of types @code{container} and @code{widget}:
1595 @lisp
1596 (defcfun (container-add "gtk_container_add") :void
1597   (container (g-object container))
1598   (widget (g-object widget)))
1599
1600 (let ((window (make-instance 'gtk-window))
1601       (widget (make-instance 'button)))
1602   (container-add window widget))
1603 @end lisp
1604 (@code{gtk-window} is a subclass of @code{container}; @code{button} is a subclass of @code{widget})
1605
1606 This defines the function that returns an instance of GObject class:
1607 @lisp
1608 (defcfun (bin-child "gtk_bin_get_child") (g-object widget)
1609   (bin (g-object bin)))
1610
1611 (let ((window (make-instance 'gtk-window))
1612       (widget (make-instance 'button)))
1613   (container-add window widget)
1614   (bin-child window))
1615 @result{}
1616 #<GTK:BUTTON @{1002DE74B1@}>
1617 @end lisp
1618
1619 @node Creating GObjects classes and implementing GInterfaces
1620 @chapter Creating GObjects classes and implementing GInterfaces
1621
1622 @menu
1623 * define-vtable::
1624 * register-object-type-implementation::
1625 @end menu
1626
1627 Creating GObject classes from Lisp is the most complex part of GObject binding.
1628
1629 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).
1630
1631 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.
1632
1633 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).
1634
1635 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.
1636
1637 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.
1638
1639 @node define-vtable
1640 @section define-vtable
1641
1642 @lisp
1643 (define-vtable (type-name cstruct-name)
1644   &body item*)
1645
1646 item ::= (name callback-name return-type &rest arg*)
1647 item ::= (:skip cffi-structure-item)
1648 arg ::= (arg-name arg-type)
1649 @end lisp
1650
1651 @table @var
1652 @item @var{type-name}
1653 A string naming the GObject type of interface
1654 @item @var{cstruct-name}
1655 A name for a generated CFFI foreign structure
1656 @item @var{name}
1657 A name for implementation generic function
1658 @item @var{callback-name}
1659 A name for generated callback function
1660 @item @var{return-type}
1661 A CFFI specifier for foreign function return type
1662 @item @var{arg-name}
1663 A symbol naming the argument of interface method
1664 @item @var{arg-type}
1665 A CFFI specifier for foreign function argument type
1666 @end table
1667
1668 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.
1669
1670 Example:
1671 @lisp
1672 (define-vtable ("GtkTreeModel" c-gtk-tree-model)
1673   (:skip parent-instance g-type-interface)
1674   ;;some signals
1675   (:skip tree-model-row-changed :pointer)
1676   (:skip tree-model-row-inserted :pointer)
1677   (:skip tree-model-row-has-child-toggled :pointer)
1678   (:skip tree-model-row-deleted :pointer)
1679   (:skip tree-model-rows-reordered :pointer)
1680   ;;methods
1681   (tree-model-get-flags-impl tree-model-get-flags-cb
1682     tree-model-flags
1683     (tree-model g-object))
1684   (tree-model-get-n-columns-impl tree-model-get-n-columns-cb
1685     :int
1686     (tree-model g-object))
1687   (tree-model-get-column-type-impl tree-model-get-column-type-cb
1688     g-type-designator
1689     (tree-model g-object) (index :int))
1690   (tree-model-get-iter-impl tree-model-get-iter-cb
1691     :boolean
1692     (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (path (g-boxed-foreign tree-path)))
1693   (tree-model-get-path-impl tree-model-get-path-cb
1694     (g-boxed-foreign tree-path :return)
1695     (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
1696   (tree-model-get-value-impl tree-model-get-value-cb
1697     :void
1698     (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (n :int) (value (:pointer g-value)))
1699   (tree-model-iter-next-impl tree-model-iter-next-cb
1700     :boolean
1701     (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
1702   (tree-model-iter-children-impl tree-model-iter-children-cb
1703     :boolean
1704     (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (parent (g-boxed-foreign tree-iter)))
1705   (tree-model-iter-has-child-impl tree-model-iter-has-child-cb
1706     :boolean
1707     (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
1708   (tree-model-iter-n-children-impl tree-model-iter-n-children-cb
1709     :int
1710     (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
1711   (tree-model-iter-nth-child-impl tree-model-iter-nth-child-cb
1712     :boolean
1713     (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (parent (g-boxed-foreign tree-iter)) (n :int))
1714   (tree-model-iter-parent-impl tree-model-iter-parent-cb
1715     :boolean
1716     (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (child (g-boxed-foreign tree-iter)))
1717   (tree-model-ref-node-impl tree-model-ref-node-cb
1718     :void
1719     (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
1720   (tree-model-unref-node-impl tree-model-unref-node-cb
1721     :void
1722     (tree-model g-object) (iter (g-boxed-foreign tree-iter))))
1723 @end lisp
1724
1725 @node register-object-type-implementation
1726 @section register-object-type-implementation
1727
1728 @lisp
1729 (register-object-type-implementation name class parent interfaces properties)
1730 @end lisp
1731
1732 @table @var
1733 @item @var{name}
1734 A string naming the new GObject class.
1735 @item @var{class}
1736 A class name of corresponding CLOS class. It should be inherited from @code{g-object} or its descendants.
1737 @item @var{parent}
1738 A string naming the GObject superclass
1739 @item @var{interfaces}
1740 A list of names of interfaces that this class implements.
1741 @item @var{properties}
1742 A list of properties that this class provides.
1743 Each property is defined as
1744 @lisp
1745 property ::= (property-name property-type accessor property-get-fn property-set-fn)
1746 @end lisp
1747 @end table
1748
1749 A macro that creates a new GObject type and registers the Lisp implementation for it.
1750
1751 Example:
1752 @lisp
1753 (register-object-type-implementation "LispArrayListStore" array-list-store "GObject" ("GtkTreeModel") nil)
1754 @end lisp
1755
1756 @node GBoxed
1757 @chapter GBoxed
1758 @menu
1759 * define-g-boxed-cstruct::
1760 * define-g-boxed-variant-cstruct::
1761 * define-g-boxed-opaque::
1762 * g-boxed-opaque::
1763 * define-boxed-opaque-accessor::
1764 * boxed-related-symbols::
1765 * GBoxed foreign type::
1766 @end menu
1767
1768 GObject manual defines this type in the following way:
1769
1770 ``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.
1771
1772 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.''
1773
1774 Naturally, it is hard to provide support for ``arbitrary C structures''. We support a few useful use cases of GBoxed types:
1775 @itemize
1776 @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.
1777 @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).
1778
1779 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.
1780 @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.
1781 @end itemize
1782
1783 @node define-g-boxed-cstruct
1784 @section define-g-boxed-cstruct
1785 @lisp
1786 (define-g-boxed-cstruct name g-type-name
1787   &body slot*)
1788
1789 slot ::= (slot-name slot-type &key count initform inline)
1790 @end lisp
1791
1792 @table @var
1793 @item @var{name}
1794 A symbol naming the type being defined
1795 @item @var{g-type-name}
1796 A string specifying the GType name of this GBoxed. This may be nil if this type is not registered with GObject type system.
1797 @item @var{slot-name}
1798 A symbol naming the slot of a structure
1799 @item @var{slot-type}
1800 A foreign type of a slot
1801 @item @var{count}
1802 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.
1803 @item @var{initform}
1804 A form that is the initform of Lisp structure slot
1805 @item @var{inline}
1806 A boolean. If it is true, then the slot contains GBoxed structure whose name is @code{slot-type}.
1807 @end table
1808
1809 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.
1810
1811 Example of usage:
1812 @lisp
1813 (define-g-boxed-cstruct rectangle "GdkRectangle"
1814   (left :int :initform 0)
1815   (top :int :initform 0)
1816   (width :int :initform 0)
1817   (height :int :initform 0))
1818
1819 (define-g-boxed-cstruct point nil
1820   (x :int :initform 0)
1821   (y :int :initform 0))
1822
1823 (define-g-boxed-cstruct vector4 nil
1824   (coords :double :count 4 :initform (vector 0d0 0d0 0d0 0d0)))
1825
1826 (define-g-boxed-cstruct segment nil
1827   (a point :inline t :initform (make-point))
1828   (b point :inline t :initform (make-point)))
1829 @end lisp
1830
1831 @node define-g-boxed-variant-cstruct
1832 @section define-g-boxed-variant-cstruct
1833
1834 @lisp
1835 (define-g-boxed-variant-cstruct name g-type-name
1836   &body slot-or-variant-specification*)
1837
1838 slot ::= (slot-name slot-type &key count initform inline)
1839 variant-specification ::= (:variant dispatching-slot-name structure-variant*)
1840 structure-variant ::= (dispatching-slot-values structure-name &body slot-or-variant-specification*)
1841 @end lisp
1842
1843 @table @var
1844 @item @var{name}
1845 A symbol naming the type being defined
1846 @item @var{g-type-name}
1847 A string specifying the GType name of this GBoxed. This may be nil if this type is not registered with GObject type system.
1848 @item @var{slot-name}
1849 A symbol naming the slot of a structure
1850 @item @var{slot-type}
1851 A foreign type of a slot
1852 @item @var{count}
1853 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.
1854 @item @var{initform}
1855 A form that is the initform of Lisp structure slot
1856 @item @var{inline}
1857 A boolean. If it is true, then the slot contains GBoxed structure whose name is @code{slot-type}.
1858 @item @var{dispatching-slot-name}
1859 A name of the dispatching slot
1860 @item @var{dispatching-slot-values}
1861 A single value or a list of values.
1862 @item @var{structure-name}
1863 A symbol naming the structure
1864 @end table
1865
1866 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.
1867
1868 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.
1869
1870 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).
1871
1872 For example, for these structures this assumption holds:
1873 @example
1874 union GdkEvent
1875 @{
1876   GdkEventType   type;
1877   GdkEventKey    key;
1878   GdkEventButton button;
1879 @};
1880
1881 struct GdkEventKey @{
1882   GdkEventType type; //
1883   GdkWindow *window; // These fields are common
1884   gint8 send_event;  //
1885   guint32 time;
1886   guint state;
1887   guint keyval;
1888   ...
1889 @};
1890
1891 struct GdkEventButton @{
1892   GdkEventType type; //
1893   GdkWindow *window; // These fields are common
1894   gint8 send_event;  //
1895   guint32 time;
1896   gdouble x;
1897   gdouble y;
1898   ...
1899 @};
1900 @end example
1901
1902 Example:
1903 @lisp
1904 (define-g-boxed-variant-cstruct event "GdkEvent"
1905   (type event-type)
1906   (window (g-object gdk-window))
1907   (send-event (:boolean :int8))
1908   (:variant type
1909             ((:key-press :key-release) event-key
1910              (time :uint32)
1911              (state modifier-type)
1912              (keyval :uint)
1913              (length :int)
1914              (string (:string :free-from-foreign nil
1915                               :free-to-foreign nil))
1916              (hardware-keycode :uint16)
1917              (group :uint8)
1918              (is-modifier :uint))
1919             ((:button-press :2button-press :3button-press
1920               :button-release) event-button
1921              (time :uint32)
1922              (x :double)
1923              (y :double)
1924              (axes (fixed-array :double 2))
1925              (state :uint)
1926              (button :uint)
1927              (device (g-object device))
1928              (x-root :double)
1929              (y-root :double))
1930              ...))
1931 @end lisp
1932
1933 This code defines following structures:
1934 @lisp
1935 (defstruct event
1936   type window send-event)
1937
1938 (defstruct (event-key (:include event))
1939   time state keyval length string
1940   hardware-keycode group is-modifier)
1941
1942 (defstruct (event-button (:include event))
1943   time x y axes state button device x-root y-root)
1944 @end lisp
1945
1946 @node define-g-boxed-opaque
1947 @section define-g-boxed-opaque
1948
1949 @lisp
1950 (define-g-boxed-opaque name g-type-name &key alloc)
1951 @end lisp
1952
1953 @table @var
1954 @item @var{name}
1955 A name of boxed type
1956 @item @var{g-type-name}
1957 A string; the name of GType
1958 @item @var{alloc}
1959 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.
1960 @end table
1961
1962 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.
1963
1964 Example:
1965 @lisp
1966 (defcfun gtk-tree-path-new :pointer)
1967
1968 (define-g-boxed-opaque tree-path "GtkTreePath"
1969   :alloc (gtk-tree-path-new))
1970 @end lisp
1971 @node g-boxed-opaque
1972 @section g-boxed-opaque
1973 @lisp
1974 (defclass g-boxed-opaque ()
1975   ((pointer :initarg :pointer
1976             :initform nil
1977             :accessor g-boxed-opaque-pointer)))
1978 @end lisp
1979
1980 A class that is the base class for wrappers of opaque structures. Contains a pointer to the wrapped opaque structure.
1981
1982 Accessor function @code{g-boxed-opaque-pointer} is used to access the pointer. Pointer should not be modified directly, only read.
1983 @node define-boxed-opaque-accessor
1984 @section define-boxed-opaque-accessor
1985 @lisp
1986 (define-boxed-opaque-accessor
1987   boxed-name accessor-name &key type reader writer)
1988 @end lisp
1989
1990 @table @var
1991 @item @var{boxed-name}
1992 A symbol naming the opaque structure type for which the accessor is being defined
1993 @item @var{accessor-name}
1994 A symbol naming the accessor
1995 @item @var{type}
1996 A CFFI foreign type of the property for which the accessor is being defined
1997 @item @var{reader}
1998 A @code{NIL} or a string or a function designator for the reader function
1999 @item @var{writer}
2000 A @code{NIL} or a string or a function designator for the writer function
2001 @end table
2002
2003 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}.
2004
2005 @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.
2006
2007 @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.
2008
2009 Example:
2010 @lisp
2011 (define-boxed-opaque-accessor text-iter text-iter-child-anchor
2012   :reader "gtk_text_iter_get_child_anchor" :type (g-object text-child-anchor))
2013
2014 (define-boxed-opaque-accessor text-iter text-iter-tags
2015   :reader "gtk_text_iter_get_tags" :type (gslist (g-object text-tag) :free-from-foreign t))
2016
2017 (define-boxed-opaque-accessor text-iter text-iter-chars-in-line
2018   :reader "gtk_text_iter_get_chars_in_line" :type :int)
2019
2020 (define-boxed-opaque-accessor text-iter text-iter-offset
2021   :reader "gtk_text_iter_get_offset" :writer "gtk_text_iter_set_offset" :type :int)
2022 @end lisp
2023
2024 @node boxed-related-symbols
2025 @section boxed-related-symbols
2026
2027 @lisp
2028 (boxed-related-symbols name) @result{} symbols
2029 @end lisp
2030
2031 @table @var
2032 @item @var{name}
2033 A symbol naming the boxed type
2034 @item @var{symbols}
2035 A list of symbols
2036 @end table
2037
2038 This function returns the list of symbols that are related to GBoxed type @var{name}. These symbols are returned:
2039 @itemize
2040 @item name of boxed type
2041 @item name of all accessors of cstruct and variant-cstruct boxed types
2042 @item names of all variants of variant-cstruct boxed types
2043 @item names of constructors and copiers of cstruct and variant-cstruct boxed-types
2044 @end itemize
2045
2046 Typical usage of this function is to export the symbols related to given boxed type.
2047
2048 Example:
2049 @lisp
2050 (define-g-boxed-cstruct rectangle "GdkRectangle"
2051   (x :int :initform 0)
2052   (y :int :initform 0)
2053   (width :int :initform 0)
2054   (height :int :initform 0))
2055
2056 (boxed-related-symbols 'rectangle)
2057 @result{}
2058 (RECTANGLE MAKE-RECTANGLE COPY-RECTANGLE RECTANGLE-X RECTANGLE-Y
2059  RECTANGLE-WIDTH RECTANGLE-HEIGHT)
2060 @end lisp
2061
2062 @node GBoxed foreign type
2063 @section GBoxed foreign type
2064
2065 @lisp
2066 (g-boxed-foreign name &rest option*)
2067
2068 option ::= :return
2069 @end lisp
2070
2071 @table @var
2072 @item @var{name}
2073 Name of GBoxed type
2074 @item @var{option}
2075 Option of foreign type
2076 @item @code{:return}
2077 An option that identifies the foreign type which is used at return position (as foreign function return type or as a callback return type)
2078 @end table
2079
2080 @code{g-boxed-foreign} type deals with marshaling data between Lisp code and foreign code. The marshaling follows the following principles:
2081 @itemize
2082 @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)
2083 @item Lisp objects should not be manually managed and are properly reclaimed by garbage collector, leaving no memory leaks
2084 @item Foreign code can change objects that are passed to them as arguments. This is required for functions that operate by modifying their arguments
2085 @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
2086 @end itemize
2087
2088 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.
2089
2090 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.
2091
2092 Examples of usage:
2093 @lisp
2094 (define-vtable ("GtkTreeModel" c-gtk-tree-model)
2095   ...
2096   (tree-model-get-path-impl tree-model-get-path-cb
2097     (g-boxed-foreign tree-path :return) (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
2098   (tree-model-get-value-impl tree-model-get-value-cb
2099     :void (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (n :int) (value (:pointer g-value)))
2100   (tree-model-iter-next-impl tree-model-iter-next-cb
2101     :boolean (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
2102   ...)
2103
2104 (defcfun gtk-text-iter-forward-search :boolean
2105   (iter (g-boxed-foreign text-iter))
2106   (str (:string :free-to-foreign t))
2107   (flags text-search-flags)
2108   (match-start (g-boxed-foreign text-iter))
2109   (match-end (g-boxed-foreign text-iter))
2110   (limit (g-boxed-foreign text-iter)))
2111 @end lisp
2112
2113 @node Generating type definitions by introspection
2114 @chapter Generating type definitions by introspection
2115 @menu
2116 * define-g-object-class::
2117 * define-g-interface::
2118 * define-g-enum::
2119 * define-g-flags::
2120 * get-g-enum-definition::
2121 * get-g-flags-definition::
2122 * get-g-interface-definition::
2123 * get-g-class-definition::
2124 * Specifying additional properties for CLOS classes::
2125 * Generating names for CLOS classes and accessors::
2126 * generate-types-hierarchy-to-file::
2127 @end menu
2128
2129 CL-GTK2-GOBJECT includes facilities for automatically generating parts of bindings for libraries that use GObject type system.
2130
2131 @node define-g-object-class
2132 @section define-g-object-class
2133
2134 @lisp
2135 (define-g-object-class g-type-name name
2136   (&key (superclass 'g-object) (export t) interfaces type-initializer)
2137   (&rest property*))
2138
2139 property ::= (name accessor gname type readable writable)
2140 property ::= (:cffi name acessor type reader writer)
2141 @end lisp
2142
2143 Parameters of @code{define-g-object-class}
2144 @table @var
2145 @item @var{superclass}
2146 A symbol naming the superclass of this class
2147 @item @var{export}
2148 Whether to export the name of the class and names of autogenerated properties names from the current package.
2149 @item @var{interfaces}
2150 A list of interfaces the this class implements
2151 @item @var{type-initializer}
2152 A string naming the type initiliazer function. It is usually named @code{class_get_type}.
2153 @item @var{properties}
2154 A list of slots of a class
2155 @end table
2156
2157 Parameters of @code{property}:
2158 @table @var
2159 @item @var{name}
2160 A symbol naming the slot
2161 @item @var{accessor}
2162 A symbol naming the accessor function for this slot
2163 @item @var{gname}
2164 A string naming the property of GObject
2165 @item @var{type}
2166 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)
2167 @item @var{readable}
2168 A boolean specifying whether the slot can be read
2169 @item @var{writable}
2170 A boolean specifying whether the slot can be assigned to
2171 @item @var{reader}
2172 A string or a symbol naming getter function. See description of @code{gobject-class} metaclass for information.
2173 @item @var{writter}
2174 A string or a symbol naming setter function. See description of @code{gobject-class} metaclass for information.
2175 @end table
2176
2177 Macro that expands to @code{defclass} for specified class. Additionally, if @code{export} is true, it exports accessor names and name of a class.
2178
2179 Example:
2180 @lisp
2181 (define-g-object-class "GtkContainer" container
2182   (:superclass widget :export t :interfaces
2183                ("AtkImplementorIface" "GtkBuildable")
2184                :type-initializer "gtk_container_get_type")
2185   ((border-width container-border-width "border-width" "guint" t t)
2186    (resize-mode container-resize-mode "resize-mode" "GtkResizeMode" t t)
2187    (child container-child "child" "GtkWidget" nil t)
2188    (:cffi focus-child container-focus-child g-object "gtk_container_get_focus_child" "gtk_container_set_focus_child")
2189    (:cffi focus-vadjustment container-focus-vadjustment (g-object adjustment) "gtk_container_get_focus_vadjustment" "gtk_container_set_focus_vadjustment")
2190    (:cffi focus-hadjustment container-focus-hadjustment (g-object adjustment) "gtk_container_get_focus_hadjustment" "gtk_container_set_focus_hadjustment")))
2191 @end lisp
2192
2193 @node define-g-interface
2194 @section define-g-interface
2195
2196 @lisp
2197 (define-g-interface g-type-name name (&key (export t) type-initializer)
2198   &body property*)
2199
2200 property ::= (name accessor gname type readable writable)
2201 property ::= (:cffi name acessor type reader writer)
2202 @end lisp
2203
2204 Parameters of @code{define-g-interface}
2205 @table @var
2206 @item @var{export}
2207 Whether to export the name of the interface and names of autogenerated properties names from the current package.
2208 @item @var{type-initializer}
2209 A string naming the type initiliazer function. It is usually named @code{interface_get_type}.
2210 @item @var{properties}
2211 A list of slots of a interface
2212 @end table
2213
2214 Parameters of @code{property}:
2215 @table @var
2216 @item @var{name}
2217 A symbol naming the slot
2218 @item @var{accessor}
2219 A symbol naming the accessor function for this slot
2220 @item @var{gname}
2221 A string naming the property of GObject
2222 @item @var{type}
2223 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)
2224 @item @var{readable}
2225 A boolean specifying whether the slot can be read
2226 @item @var{writable}
2227 A boolean specifying whether the slot can be assigned to
2228 @item @var{reader}
2229 A string or a symbol naming getter function. See description of @code{gobject-class} metaclass for information.
2230 @item @var{writter}
2231 A string or a symbol naming setter function. See description of @code{gobject-class} metaclass for information.
2232 @end table
2233
2234 Macro that expands to @code{defclass} for specified interface. Additionally, if @code{export} is true, it exports accessor names and name of a interface.
2235
2236 Example:
2237 @lisp
2238 (define-g-interface "GtkFileChooser" file-chooser
2239   (:export t :type-initializer "gtk_file_chooser_get_type")
2240   (do-overwrite-confirmation file-chooser-do-overwrite-confirmation "do-overwrite-confirmation" "gboolean" t t)
2241   (select-multiple file-chooser-select-multiple "select-multiple" "gboolean" t t)
2242   (filter file-chooser-filter "filter" "GtkFileFilter" t t)
2243   (local-only file-chooser-local-only "local-only" "gboolean" t t)
2244   (preview-widget file-chooser-preview-widget "preview-widget" "GtkWidget" t t)
2245   (use-preview-label file-chooser-use-preview-label "use-preview-label" "gboolean" t t)
2246   (preview-widget-active file-chooser-preview-widget-active "preview-widget-active" "gboolean" t t)
2247   (file-system-backend file-chooser-file-system-backend "file-system-backend" "gchararray" nil nil)
2248   (extra-widget file-chooser-extra-widget "extra-widget" "GtkWidget" t t)
2249   (show-hidden file-chooser-show-hidden "show-hidden" "gboolean" t t)
2250   (action file-chooser-action "action" "GtkFileChooserAction" t t)
2251   (:cffi current-name file-chooser-current-name
2252    (:string :free-to-foreign t :encoding :utf-8) nil "gtk_file_chooser_set_current_name")
2253   (:cffi filename file-chooser-filename
2254    (g-string :free-from-foreign t :free-to-foreign t)
2255    "gtk_file_chooser_get_filename" "gtk_file_chooser_set_filename")
2256   (:cffi current-folder file-chooser-current-folder
2257    (g-string :free-from-foreign t :free-to-foreign t)
2258    "gtk_file_chooser_get_current_folder"
2259    "gtk_file_chooser_set_current_folder")
2260   (:cffi uri file-chooser-uri
2261    (g-string :free-from-foreign t :free-to-foreign t)
2262    "gtk_file_chooser_get_uri" "gtk_file_chooser_set_uri")
2263   (:cffi current-folder-uri file-chooser-current-folder-uri
2264    (g-string :free-from-foreign t :free-to-foreign t)
2265    "gtk_file_chooser_get_current_folder_uri"
2266    "gtk_file_chooser_set_current_folder_uri")
2267   (:cffi preview-filename file-chooser-preview-filename
2268    (g-string :free-from-foreign t :free-to-foreign t)
2269    "gtk_file_chooser_get_preview_filename" nil)
2270   (:cffi preview-uri file-chooser-preview-uri
2271    (g-string :free-from-foreign t :free-to-foreign t)
2272    "gtk_file_chooser_get_preview_uri" nil))
2273 @end lisp
2274
2275 @node define-g-enum
2276 @section define-g-enum
2277
2278 @lisp
2279 (define-g-enum g-name name (&key (export t) type-initializer) &body value*)
2280
2281 value ::= :keyword
2282 value ::= (:keyword integer)
2283 @end lisp
2284
2285 @table @var
2286 @item @var{g-name}
2287 A string naming the GEnum type
2288 @item @var{name}
2289 A symbol naming the CFFI enumeration type
2290 @item @var{export}
2291 A boolean indicating whether to export @code{name}
2292 @item @var{type-initializer}
2293 A string naming the foreign type initializer function. Usually named @code{enum_get_type}.
2294 @end table
2295
2296 Macro that defines CFFI enumeration, registers it with GValue, and calls the type initializer.
2297
2298 Example:
2299 @lisp
2300 (define-g-enum "GtkTextDirection" text-direction
2301   (:export t :type-initializer "gtk_text_direction_get_type")
2302   (:none 0) (:ltr 1) (:rtl 2))
2303
2304 (define-g-enum "GtkSizeGroupMode" size-group-mode
2305  (:export t :type-initializer "gtk_size_group_mode_get_type")
2306  :none :horizontal :vertical :both)
2307 @end lisp
2308
2309 @node define-g-flags
2310 @section define-g-flags
2311
2312 @lisp
2313 (define-g-flags g-name name (&key (export t) type-initializer) &body value*)
2314
2315 value ::= :keyword
2316 value ::= (:keyword integer)
2317 @end lisp
2318
2319 @table @var
2320 @item @var{g-name}
2321 A string naming the GFlags type
2322 @item @var{name}
2323 A symbol naming the CFFI flags type
2324 @item @var{export}
2325 A boolean indicating whether to export @code{name}
2326 @item @var{type-initializer}
2327 A string naming the foreign type initializer function. Usually named @code{flags_get_type}.
2328 @end table
2329
2330 Macro that defines CFFI bitfield, registers it with GValue, and calls the type initializer.
2331
2332 Example:
2333 @lisp
2334 (define-g-flags "GtkAttachOptions" attach-options
2335   (:export t :type-initializer "gtk_attach_options_get_type")
2336   (:expand 1) (:shrink 2) (:fill 4))
2337
2338 (define-g-flags "GtkButtonAction" button-action
2339   (:export t :type-initializer "gtk_button_action_get_type")
2340   :ignored :selects :drags :expands)
2341 @end lisp
2342
2343 @node get-g-enum-definition
2344 @section get-g-enum-definition
2345
2346 @lisp
2347 (get-g-enum-definition type &optional lisp-name-package) @result{} definition
2348 @end lisp
2349
2350 @table @var
2351 @item @var{type}
2352 A string naming the GEnum type
2353 @item @var{lisp-name-package}
2354 A package that will be used as a package for generated symbols (enum name). If not specified, symbols are interned in @code{*package*}
2355 @item @var{definition}
2356 A Lisp form that when evaluated defines the GEnum.
2357 @end table
2358
2359 Uses GObject introspection capabilities to automatically produce the definition of GEnum. The foreign library that defines the enum type should be loaded.
2360
2361 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
2362
2363 Example:
2364 @lisp
2365 (get-g-enum-definition "GtkDirectionType")
2366 @result{}
2367 (DEFINE-G-ENUM "GtkDirectionType" GTK-DIRECTION-TYPE
2368                (:EXPORT T :TYPE-INITIALIZER "gtk_direction_type_get_type")
2369                (:TAB-FORWARD 0) (:TAB-BACKWARD 1) (:UP 2) (:DOWN 3) (:LEFT 4)
2370                (:RIGHT 5))
2371 @end lisp
2372
2373 @node get-g-flags-definition
2374 @section get-g-flags-definition
2375
2376 @lisp
2377 (get-g-flags-definition type &optional lisp-name-package) @result{} definition
2378 @end lisp
2379
2380 @table @var
2381 @item @var{type}
2382 A string naming the GFlags type
2383 @item @var{lisp-name-package}
2384 A package that will be used as a package for generated symbols (flags name). If not specified, symbols are interned in @code{*package*}
2385 @item @var{definition}
2386 A Lisp form that when evaluated defines the GFlags.
2387 @end table
2388
2389 Uses GObject introspection capabilities to automatically produce the definition of GFlags. The foreign library that defines the flags type should be loaded.
2390
2391 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
2392
2393 Example:
2394 @lisp
2395 (get-g-flags-definition "GtkCalendarDisplayOptions")
2396 @result{}
2397 (DEFINE-G-FLAGS "GtkCalendarDisplayOptions" GTK-CALENDAR-DISPLAY-OPTIONS
2398                 (:EXPORT T :TYPE-INITIALIZER
2399                  "gtk_calendar_display_options_get_type")
2400                 (:SHOW-HEADING 1) (:SHOW-DAY-NAMES 2) (:NO-MONTH-CHANGE 4)
2401                 (:SHOW-WEEK-NUMBERS 8) (:WEEK-START-MONDAY 16)
2402                 (:SHOW-DETAILS 32))
2403 @end lisp
2404
2405 @node get-g-interface-definition
2406 @section get-g-interface-definition
2407
2408 @lisp
2409 get-g-interface-definition type &optional lisp-name-package) @result{} definition
2410 @end lisp
2411
2412 @table @var
2413 @item @var{type}
2414 A string naming the GInterface type
2415 @item @var{lisp-name-package}
2416 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*}
2417 @item @var{definition}
2418 A Lisp form that when evaluated defines the GInterface.
2419 @end table
2420
2421 Uses GObject introspection capabilities to automatically produce the definition of GInterface. The foreign library that defines the GInterface type should be loaded.
2422
2423 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
2424
2425 Example:
2426 @lisp
2427 (get-g-interface-definition "GtkActivatable")
2428 @result{}
2429 (DEFINE-G-INTERFACE "GtkActivatable" GTK-ACTIVATABLE
2430                     (:EXPORT T :TYPE-INITIALIZER "gtk_activatable_get_type")
2431                     (USE-ACTION-APPEARANCE
2432                      GTK-ACTIVATABLE-USE-ACTION-APPEARANCE
2433                      "use-action-appearance" "gboolean" T T)
2434                     (RELATED-ACTION GTK-ACTIVATABLE-RELATED-ACTION
2435                      "related-action" "GtkAction" T T))
2436 @end lisp
2437
2438 @node get-g-class-definition
2439 @section get-g-class-definition
2440
2441
2442 @lisp
2443 get-g-class-definition type &optional lisp-name-package) @result{} definition
2444 @end lisp
2445
2446 @table @var
2447 @item @var{type}
2448 A string naming the GObject type
2449 @item @var{lisp-name-package}
2450 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*}
2451 @item @var{definition}
2452 A Lisp form that when evaluated defines the GObject.
2453 @end table
2454
2455 Uses GObject introspection capabilities to automatically produce the definition of GClass. The foreign library that defines the GObject type should be loaded.
2456
2457 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
2458
2459 Example:
2460 @lisp
2461 (get-g-class-definition "GtkButton")
2462 @result{}
2463 (DEFINE-G-OBJECT-CLASS "GtkButton" GTK-BUTTON
2464                        (:SUPERCLASS GTK-BIN :EXPORT T :INTERFACES
2465                         ("AtkImplementorIface" "GtkActivatable" "GtkBuildable")
2466                         :TYPE-INITIALIZER "gtk_button_get_type")
2467                        ((LABEL GTK-BUTTON-LABEL "label" "gchararray" T T)
2468                         (IMAGE GTK-BUTTON-IMAGE "image" "GtkWidget" T T)
2469                         (RELIEF GTK-BUTTON-RELIEF "relief" "GtkReliefStyle" T
2470                          T)
2471                         (USE-UNDERLINE GTK-BUTTON-USE-UNDERLINE "use-underline"
2472                          "gboolean" T T)
2473                         (USE-STOCK GTK-BUTTON-USE-STOCK "use-stock" "gboolean"
2474                          T T)
2475                         (FOCUS-ON-CLICK GTK-BUTTON-FOCUS-ON-CLICK
2476                          "focus-on-click" "gboolean" T T)
2477                         (XALIGN GTK-BUTTON-XALIGN "xalign" "gfloat" T T)
2478                         (YALIGN GTK-BUTTON-YALIGN "yalign" "gfloat" T T)
2479                         (IMAGE-POSITION GTK-BUTTON-IMAGE-POSITION
2480                          "image-position" "GtkPositionType" T T)))
2481 @end lisp
2482
2483 @node Specifying additional properties for CLOS classes
2484 @section Specifying additional properties for CLOS classes
2485
2486 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.
2487
2488 Definitions generator uses variable @code{*additional-properties*} to get this information.
2489
2490 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).
2491
2492 To supply the bindings generator with this information, bind @code{*additional-properties*} to such list when the generator is run.
2493
2494 Example:
2495 @lisp
2496 (("GtkTreeViewColumn"
2497   (:cffi gtk::tree-view
2498          gtk::tree-view-column-tree-view
2499          g-object "gtk_tree_view_column_get_tree_view" nil)
2500   (:cffi gtk::sort-column-id
2501          gtk::tree-view-column-sort-column-id
2502          :int "gtk_tree_view_column_get_sort_column_id" "gtk_tree_view_column_set_sort_column_id")
2503   (:cffi gtk::cell-renderers
2504          gtk::tree-view-column-cell-renderers
2505          (glist g-object  :free-from-foreign t) "gtk_tree_view_column_get_cell_renderers" nil))
2506  ("GtkTreeSelection"
2507   (:cffi gtk::mode
2508          gtk::tree-selection-mode
2509          gtk::selection-mode "gtk_tree_selection_get_mode" "gtk_tree_selection_set_mode")
2510   (:cffi gtk::select-function
2511          gtk::tree-selection-select-function
2512          nil gtk::tree-selection-get-selection-function gtk::tree-selection-set-select-function)))
2513 @end lisp
2514
2515 @node Generating names for CLOS classes and accessors
2516 @section Generating names for CLOS classes and accessors
2517
2518 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).
2519
2520 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.
2521
2522 Name generation affected by following variables:
2523 @itemize
2524 @item @var{*strip-prefix*}
2525 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}.
2526 @item @var{*lisp-name-exceptions*}
2527 A plist mapping from strings (type names) to symbols (class names) that have special name processing.
2528 Example:
2529 @lisp
2530 `(("GObject" gobject:g-object)
2531   ("GtkObject" ,(intern "GTK-OBJECT" (find-package :gtk)))
2532   ("GInitiallyUnowned" gobject::g-initially-unowned)
2533   ("GtkWindow" ,(intern "GTK-WINDOW" (find-package :gtk)))
2534   ("GtkUIManager" ,(intern "UI-MANAGER" (find-package :gtk)))
2535   ("GtkUIManagerItemType" ,(intern "UI-MANAGER-ITEM-TYPE" (find-package :gtk))))
2536 @end lisp
2537 @end itemize
2538
2539 @node generate-types-hierarchy-to-file
2540 @section generate-types-hierarchy-to-file
2541
2542 @lisp
2543 (generate-types-hierarchy-to-file file
2544                                   root-type
2545                                   &key include-referenced
2546                                   prefix
2547                                   package
2548                                   exceptions
2549                                   prologue
2550                                   interfaces
2551                                   enums
2552                                   flags
2553                                   objects
2554                                   exclusions
2555                                   additional-properties)
2556 @end lisp
2557
2558 @table @var
2559 @item @var{file}
2560 A string or pathname naming the file, or a stream.
2561 @item @var{root-type}
2562 A GType designator for a root type. All types that inherit from this type will be defined.
2563 @item @var{&key include-referenced}
2564 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
2565 @item @var{prefix}
2566 A string naming the prefix that should be removed from the beginning of names
2567 @item @var{package}
2568 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
2569 @item @var{exceptions}
2570 A plist that maps GType names to their Lisp names.
2571 See @ref{Generating names for CLOS classes and accessors} for more info on exceptions from name generation mechanism
2572 @item @var{prologue}
2573 A string that will be included verbatim in generated code file
2574 @item @var{interfaces}
2575 Additional list of interfaces that will also be included in generation
2576 @item @var{enums}
2577 Additional list of enums that will also be included in generation
2578 @item @var{flags}
2579 Additional list of flags that will also be included in generation
2580 @item @var{objects}
2581 Additional list of object types that will also be included in generation
2582 @item @var{exclusions}
2583 A list of GType names that will be excluded from generation
2584 @item @var{additional-properties}
2585 A plist of properties definitions that will be added to generated classes.
2586 See @ref{Specifying additional properties for CLOS classes} for more information.
2587 @end table
2588
2589 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.
2590
2591 Example of usage:
2592 @lisp
2593 (generate-types-hierarchy-to-file
2594  "gtk.generated-classes.lisp"
2595  "GtkObject"
2596  :include-referenced t
2597  :prefix "Gtk"
2598  :package (or (find-package :gtk) (make-package :gtk))
2599  :exceptions `(("GObject" gobject:g-object)
2600                ("GtkObject" ,(intern "GTK-OBJECT" (find-package :gtk)))
2601                ("GInitiallyUnowned" gobject::g-initially-unowned)
2602                ("GtkWindow" ,(intern "GTK-WINDOW" (find-package :gtk)))
2603                ("GtkUIManager" ,(intern "UI-MANAGER" (find-package :gtk)))
2604                ("GtkUIManagerItemType" ,(intern "UI-MANAGER-ITEM-TYPE" (find-package :gtk))))
2605  :prologue (format nil "(in-package :gtk)")
2606  :interfaces '("GtkBuildable" "GtkCellEditable" ...)
2607  :objects '("GtkSettings" "GtkRcStyle" ...)
2608  :flags '("GtkTextSearchFlags" "GtkAccelFlags" ...)
2609  :enums '("GtkTextDirection" "GtkSizeGroupMode" ...)
2610  :exclusions '("PangoStretch" "PangoVariant" ...)
2611  :additional-properties
2612  '(("GtkTreeViewColumn"
2613     (:cffi
2614      gtk::tree-view
2615      gtk::tree-view-column-tree-view
2616      g-object
2617      "gtk_tree_view_column_get_tree_view"
2618      nil)
2619     ...)
2620    ...))
2621 @end lisp
2622
2623 @bye
2624