Added documentation of GObject high-level layer
[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 * Subclassing GObjects 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 @node Installation
142 @chapter Installation
143
144 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}.
145
146 To use the CL-GTK2-GObject, download and install CL-GTK2 bindings and load the ASDF system @code{cl-gtk2-glib}.
147
148 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.
149
150 @node GType designator
151 @chapter GType designator
152
153 @menu
154 * g-type-string::
155 * g-type-numeric::
156 @end menu
157
158 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.
159
160 An example of GType designator is a string @code{"GObject"} and the numeric value 80 that corresponds to it.
161
162 Some of the types are fundamental and have constant integer values. They are identified by constants:
163 @itemize
164 @item @code{+g-type-invalid+}. An invalid GType used as error return value in some functions which return a GType.
165 @item @code{+g-type-void+}. A fundamental type which is used as a replacement for the C @code{void} return type.
166 @item @code{+g-type-interface+}. The fundamental type from which all interfaces are derived.
167 @item @code{+g-type-char+}. 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}.
168 @item @code{+g-type-uchar+}. The fundamental type corresponding to @code{guchar}.
169 @item @code{+g-type-boolean+}. The fundamental type corresponding to @code{gboolean}.
170 @item @code{+g-type-int+}. The fundamental type corresponding to @code{gint}.
171 @item @code{+g-type-uint+}. The fundamental type corresponding to @code{guint}.
172 @item @code{+g-type-long+}. The fundamental type corresponding to @code{glong}.
173 @item @code{+g-type-ulong+}. The fundamental type corresponding to @code{gulong}.
174 @item @code{+g-type-int64+}. The fundamental type corresponding to @code{gint64}.
175 @item @code{+g-type-uint64+}. The fundamental type corresponding to @code{guint64}.
176 @item @code{+g-type-enum+}. The fundamental type from which all enumeration types are derived.
177 @item @code{+g-type-flags+}. The fundamental type from which all flags types are derived.
178 @item @code{+g-type-float+}. The fundamental type corresponding to @code{gfloat}.
179 @item @code{+g-type-double+}. The fundamental type corresponding to @code{gdouble}.
180 @item @code{+g-type-string+}. The fundamental type corresponding to null-terminated C strings.
181 @item @code{+g-type-pointer+}. The fundamental type corresponding to @code{gpointer}.
182 @item @code{+g-type-boxed+}. The fundamental type from which all boxed types are derived.
183 @item @code{+g-type-param+}. The fundamental type from which all GParamSpec types are derived.
184 @item @code{+g-type-object+}. The fundamental type for GObject.
185 @end itemize
186
187 Functions @ref{g-type-string} and @ref{g-type-numeric} return the numeric and string representations of GType designators (given any of them).
188
189 Invalid type (the GType that does not exist) is identified as a 0 or @code{NIL}.
190
191 @example
192 (g-type-numeric "GObject") @result{} 80
193 (g-type-numeric 80) @result{} 80
194 (g-type-string "GObject") @result{} "GObject"
195 (g-type-string 80) @result{} "GObject"
196 (g-type-numeric "GtkWidget") @result{} 6905648 ;;Will be different on each run
197 @end example
198
199 @node g-type-string
200 @section g-type-string
201
202 @code{(g-type-string g-type-designator) @result{} name}
203
204 @table @var
205 @item @var{g-type-designator}
206 The GType designator for the GType
207 @item @var{name}
208 The name of GType
209 @end table
210
211 Returns the name of GType.
212
213 @node g-type-numeric
214 @section g-type-numeric
215
216 @code{(g-type-numeric g-type-designator) @result{} GType}
217
218 @table @var
219 @item @var{g-type-designator}.
220 The GType designator for the GType.
221 @item @var{GType}
222 The numeric identifier of GType
223 @end table
224
225 Returns the numeric identifier of GType
226
227 @node Type hierarchy and type relations
228 @chapter Type hierarchy and type relations
229
230 @menu
231 * g-type-children::
232 * g-type-parent::
233 * g-type-fundamental::
234 * g-type-depth::
235 * g-type-next-base::
236 @end menu
237
238 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.
239
240 There are functions to query some specific information:
241 @itemize
242 @item @code{g-type-fundamental} retrieves the fundamental type for given type
243 @item @code{g-type-depth} calculates the depth of the type in type hierarchy
244 @item @code{g-type-next-base} calculates the first step in the path from base type to descendent type
245 @end itemize
246
247 @node g-type-children
248 @section g-type-children
249
250 @code{(g-type-children type) @result{} children}
251 @table @var
252 @item @var{type}
253 A GType designator
254 @item @var{children}
255 A list of GType designators
256 @end table
257
258 Returns the list of descendent types.
259
260 Example:
261 @example
262 (g-type-children "GtkButton")
263 @result{}
264 ("GtkToggleButton" "GtkColorButton" "GtkFontButton" "GtkLinkButton" "GtkScaleButton")
265 @end example
266
267 @node g-type-parent
268 @section g-type-parent
269
270 @code{(g-type-parent type) @result{} parent}
271
272 @table @var
273 @item @var{type}
274 A GType designator
275 @item @var{parent}
276 A GType designator
277 @end table
278
279 Returns the parent of @code{type}.
280
281 Example:
282 @example
283 (g-type-parent "GtkToggleButton")
284 @result{}
285 "GtkButton"
286 @end example
287 @node g-type-fundamental
288 @section g-type-fundamental
289
290 @code{(g-type-fundamental type) @result{} fundamental-type}
291
292 @table @var
293 @item @var{type}
294 A GType designator
295 @item @var{fundamental-type}
296 A GType designator for one of the fundamental types
297 @end table
298
299 Returns the fundamental type that is the ancestor of @code{type}.
300
301 Example:
302 @example
303 (g-type-fundamental "GtkButton") @result{} "GObject"
304
305 (g-type-fundamental "GtkWindowType") @result{} "GEnum"
306
307 (g-type-fundamental "GdkEvent") @result{} "GBoxed"
308 @end example
309
310 @node g-type-depth
311 @section g-type-depth
312
313 @code{(g-type-depth type) @result{} depth}
314
315 @table @var
316 @item @var{type}
317 A GType designator
318 @item @var{depth}
319 An integer
320 @end table
321
322 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.
323
324 Example:
325 @example
326 (g-type-depth "GObject") @result{} 1
327 (g-type-depth "GInitiallyUnowned") @result{} 2
328 @end example
329
330 @node g-type-next-base
331 @section g-type-next-base
332
333 @code{(g-type-next-base leaf-type root-type) @result{} base-type}
334
335 @table @var
336 @item @var{leaf-type}
337 A GType designator
338 @item @var{root-type}
339 A GType designator
340 @item @var{base-type}
341 A GType designator
342 @end table
343
344 Returns the next type that should be traversed from @code{root-type} in order to reach @code{leaf-type}. E.g., given type hierarchy:
345 @example
346 + GObject
347  \
348   + GInitiallyUnowned
349    \
350     + GtkObject
351     |\
352     | + GtkAdjustment
353      \
354       + GtkWidget
355        \
356         + GtkContainer
357          \
358           + GtkTable
359 @end example
360
361 the following will be returned:
362
363 @example
364 (g-type-next-base "GtkTable" "GObject") @result{} "GInitiallyUnowned"
365 (g-type-next-base "GtkTable" "GInitiallyUnowned") @result{} "GtkObject"
366 (g-type-next-base "GtkTable" "GtkObject") @result{} "GtkWidget"
367 (g-type-next-base "GtkTable" "GtkWidget") @result{} "GtkContainer"
368 (g-type-next-base "GtkTable" "GtkContainer") @result{} "GtkTable"
369 @end example
370
371 @node Object types information
372 @chapter Object types information
373 @menu
374 * g-class-property-definition::
375 * class-properties::
376 * class-property-info::
377 * interface-properties::
378 * signal-info::
379 * type-signals::
380 * parse-signal-name::
381 * query-signal-info::
382 * g-type-interfaces::
383 * g-type-interface-prerequisites::
384 @end menu
385
386 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.
387
388 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.
389
390 @node g-class-property-definition
391 @section g-class-property-definition
392
393 @example
394 (defstruct g-class-property-definition
395   name
396   type
397   readable
398   writable
399   constructor
400   constructor-only
401   owner-type)
402 @end example
403
404 @table @var
405 @item @var{name}
406 A string that names the property
407 @item @var{type}
408 A GType designator. Identifies the type of the property
409 @item @var{readable}
410 A boolean. Identifies whether the property can be read
411 @item @var{writable}
412 A boolean. Identifies whether the property can be assigned
413 @item @var{constructor}
414 A boolean. Identifies whether constructor of object accepts this property
415 @item @var{constructor-only}
416 A boolean. Identifies whether this property may only be set in constructor, not in property setter
417 @item @var{owner-type}
418 A GType designator. Identifies the type on which the property was defined.
419 @end table
420
421 This structure identifies a single property. Its field specify attributes of a property.
422
423 Structures of this type have shortened print syntax:
424 @example
425 #<PROPERTY gchararray GtkButton.label (flags: readable writable constructor)> 
426 @end example
427
428 (When @code{*print-readably*} is T, usual @code{defstruct} print syntax is used)
429
430 This syntax specifies:
431 @itemize
432 @item type of property
433 @item the owner type of property
434 @item name of property
435 @item additional flags of property
436 @end itemize
437
438 @node class-properties
439 @section class-properties
440
441 @code{(class-properties type) @result{} properties}
442
443 @table @var
444 @item @var{type}
445 A GType designator. Specifies the object type (class)
446 @item @var{properties}
447 A list of @code{g-property-definition} structures.
448 @end table
449
450 This function returns the list of properties that are available in class @code{type}.
451
452 Example:
453 @example
454 (class-properties "GtkWidget")
455 @result{}
456 (#<PROPERTY gpointer GtkObject.user-data (flags: readable writable)>
457  #<PROPERTY gchararray GtkWidget.name (flags: readable writable)>
458  #<PROPERTY GtkContainer GtkWidget.parent (flags: readable writable)>
459  #<PROPERTY gint GtkWidget.width-request (flags: readable writable)>
460  #<PROPERTY gint GtkWidget.height-request (flags: readable writable)>
461  #<PROPERTY gboolean GtkWidget.visible (flags: readable writable)>
462  #<PROPERTY gboolean GtkWidget.sensitive (flags: readable writable)>
463  #<PROPERTY gboolean GtkWidget.app-paintable (flags: readable writable)>
464  #<PROPERTY gboolean GtkWidget.can-focus (flags: readable writable)>
465  #<PROPERTY gboolean GtkWidget.has-focus (flags: readable writable)>
466  #<PROPERTY gboolean GtkWidget.is-focus (flags: readable writable)>
467  #<PROPERTY gboolean GtkWidget.can-default (flags: readable writable)>
468  #<PROPERTY gboolean GtkWidget.has-default (flags: readable writable)>
469  #<PROPERTY gboolean GtkWidget.receives-default (flags: readable writable)>
470  #<PROPERTY gboolean GtkWidget.composite-child (flags: readable)>
471  #<PROPERTY GtkStyle GtkWidget.style (flags: readable writable)>
472  #<PROPERTY GdkEventMask GtkWidget.events (flags: readable writable)>
473  #<PROPERTY GdkExtensionMode GtkWidget.extension-events (flags: readable writable)>
474  #<PROPERTY gboolean GtkWidget.no-show-all (flags: readable writable)>
475  #<PROPERTY gboolean GtkWidget.has-tooltip (flags: readable writable)>
476  #<PROPERTY gchararray GtkWidget.tooltip-markup (flags: readable writable)>
477  #<PROPERTY gchararray GtkWidget.tooltip-text (flags: readable writable)>
478  #<PROPERTY GdkWindow GtkWidget.window (flags: readable)>)
479 @end example
480
481 @node class-property-info
482 @section class-property-info
483 @code{(class-property-info type property-name) @result{} property}
484
485 @table @var
486 @item @var{type}
487 A GType designator
488 @item @var{property-name}
489 A string naming the property
490 @item @var{property}
491 An instance of @code{g-property-definition} structure
492 @end table
493
494 Returns the property information for a single property.
495
496 Example:
497 @example
498 (class-property-info "GtkButton" "label")
499 @result{}
500 #<PROPERTY gchararray GtkButton.label (flags: readable writable constructor)>
501 @end example
502
503 @node interface-properties
504 @section interface-properties
505
506 @code{(interface-properties type) @result{} properties}
507
508 @table @var
509 @item @var{type}
510 A GType designator
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 interface @code{type}.
516
517 Example:
518 @example
519 (interface-properties "GtkFileChooser")
520 @result{}
521 (#<PROPERTY GtkWidget GtkFileChooser.extra-widget (flags: readable writable)>
522  #<PROPERTY gboolean GtkFileChooser.use-preview-label (flags: readable writable)>
523  #<PROPERTY gboolean GtkFileChooser.preview-widget-active (flags: readable writable)>
524  #<PROPERTY gboolean GtkFileChooser.show-hidden (flags: readable writable)>
525  #<PROPERTY gchararray GtkFileChooser.file-system-backend (flags: writable constructor-only)>
526  #<PROPERTY GtkFileChooserAction GtkFileChooser.action (flags: readable writable)>
527  #<PROPERTY GtkFileFilter GtkFileChooser.filter (flags: readable writable)>
528  #<PROPERTY gboolean GtkFileChooser.select-multiple (flags: readable writable)>
529  #<PROPERTY GtkWidget GtkFileChooser.preview-widget (flags: readable writable)>
530  #<PROPERTY gboolean GtkFileChooser.local-only (flags: readable writable)>
531  #<PROPERTY gboolean GtkFileChooser.do-overwrite-confirmation (flags: readable writable)>)
532 @end example
533
534 @node signal-info
535 @section signal-info
536
537 @example
538 (defstruct signal-info
539   id
540   name
541   owner-type
542   flags
543   return-type
544   param-types
545   detail)
546 @end example
547
548 @table @var
549 @item @var{id}
550 An integer - the identifier of a signal
551 @item @var{name}
552 Name of a signal
553 @item @var{owner-type}
554 A GType designator identifying the type on which the signal was defined
555 @item @var{flags}
556 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
557 @item @var{return-type}
558 The return type of a signal (and signal handlers)
559 @item @var{param-types}
560 A list of GType designators that specify the types of signal parameters
561 @item @var{detail}
562 A string. Specifies the "detail" part of a signal name. E.g., @code{"label"} for signal @code{"notify::label"}.
563 @end table
564
565 When @code{*print-readably*} is nil, the following print syntax is used:
566 @example
567 #<Signal [#1] void GObject.notify::label(GParam) [RUN-FIRST, NO-RECURSE, DETAILED, ACTION, NO-HOOKS]>
568 #<Signal [#54] gboolean GtkWidget.proximity-in-event(GdkEvent) [RUN-LAST]>
569 #<Signal [#64] void GtkWidget.drag-data-received(GdkDragContext, gint, gint, GtkSelectionData, guint, guint) [RUN-LAST]>
570 #<Signal [#8] void GtkObject.destroy() [RUN-CLEANUP, NO-RECURSE, NO-HOOKS]>
571 @end example
572
573 This syntax specifies:
574 @itemize
575 @item the signal id
576 @item signal return type
577 @item owner type
578 @item signal name
579 @item detail
580 @item list of types of parameters
581 @item flags
582 @end itemize
583
584 @node type-signals
585 @section type-signals
586 @code{(type-signals type &key (include-inherited t)) @result{} signals}
587 @table @var
588 @item @var{type}
589 A GType designator
590 @item @var{signals}
591 A list of @code{signal-info} structures
592 @item @var{include-inherited}
593 A boolean that specifies whether to include signals defined on this type or also on ancestor types.
594 @end table
595
596 Returns the list of signals that are available in type @code{type}.
597
598 Example:
599 @example
600 (type-signals "GtkLabel" :include-inherited nil)
601 @result{}
602 (#<Signal [#138] void GtkLabel.move-cursor(GtkMovementStep, gint, gboolean) [RUN-LAST, ACTION]>
603  #<Signal [#139] void GtkLabel.copy-clipboard() [RUN-LAST, ACTION]>
604  #<Signal [#140] void GtkLabel.populate-popup(GtkMenu) [RUN-LAST]>)
605 @end example
606
607 @node parse-signal-name
608 @section parse-signal-name
609
610 @code{(parse-signal-name type signal-name) @result{} signal}
611
612 @table @var
613 @item @var{type}
614 A GType designator that has the signal.
615 @item @var{signal-name}
616 A string that identifies the signal.
617 @item @var{signal}
618 A list @code{signal-info} structures.
619 @end table
620
621 Parses the signal name and returns the corresponding information. @code{signal-name} may include the detail part.
622
623 Example:
624 @example
625 (parse-signal-name "GObject" "notify::label")
626 @result{}
627 #<Signal [#1] void GObject.notify::label(GParam) [RUN-FIRST, NO-RECURSE, DETAILED, ACTION, NO-HOOKS]>
628 @end example
629
630 @node query-signal-info
631 @section query-signal-info
632 @code{(query-signal-info signal-id) @result{} signal}
633 @table @var
634 @item @var{signal-id}
635 An integer identifying the signal
636 @item @var{signal}
637 An instance of @code{signal-info} structure
638 @end table
639
640 Retrieves the signal information by its id.
641
642 Example:
643 @example
644 (query-signal-info 73)
645 @result{}
646 #<Signal [#73] gboolean GtkWidget.show-help(GtkWidgetHelpType) [RUN-LAST, ACTION]>
647 @end example
648
649 @node g-type-interfaces
650 @section g-type-interfaces
651
652 @code{(g-type-interfaces type) @result{} interfaces}
653
654 @table @var
655 @item @var{type}
656 A GType designator
657 @item @var{interfaces}
658 A list of GType designators
659 @end table
660
661 Returns the list of interfaces that @code{type} implements.
662
663 Example:
664 @example
665 (g-type-interfaces "GtkButton")
666 @result{}
667 ("AtkImplementorIface" "GtkBuildable" "GtkActivatable")
668 @end example
669
670 @node g-type-interface-prerequisites
671 @section g-type-interface-prerequisites
672
673 @code{(g-type-interface-prerequisites type) @result{} types}
674
675 @table @var
676 @item @var{type}
677 A GType designator of interface
678 @item @var{types}
679 A list of GType designators specifying the interface prerequisites
680 @end table
681
682 Returns the prerequisites of an interface @code{type}. Prerequisite is a type that should be an ancestor of a type implementing interface @code{type}.
683
684 Example:
685 @example
686 (g-type-interface-prerequisites "GtkCellEditable")
687 @result{}
688 ("GtkObject" "GtkWidget")
689 @end example
690
691 @node Enum types information
692 @chapter Enum types information
693 @menu
694 * enum-item::
695 * flags-item::
696 * get-enum-items::
697 * get-flags-items::
698 @end menu
699
700 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.
701
702 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.
703
704 @node enum-item
705 @section enum-item
706 @example
707 (defstruct enum-item
708   name value nick)
709 @end example
710
711 @table @var
712 @item @var{name}
713 A string - name of enum item
714 @item @var{value}
715 An integer - numeric value of enum item
716 @item @var{nick}
717 A string - short name of an enum item
718 @end table
719
720 Structure @code{enum-item} represents a single item of an enumeration type.
721
722 Example:
723 @example
724 #S(ENUM-ITEM :NAME "GTK_WINDOW_TOPLEVEL" :VALUE 0 :NICK "toplevel")
725 @end example
726
727 @node flags-item
728 @section flags-item
729 @example
730 (defstruct flags-item
731   name value nick)
732 @end example
733
734 @table @var
735 @item @var{name}
736 A string - name of flags item
737 @item @var{value}
738 An integer - numeric value of flags item
739 @item @var{nick}
740 A string - short name of an flags item
741 @end table
742
743 Structure @code{flags-item} represents a single item of an flags type.
744
745 Example:
746 @example
747 #S(FLAGS-ITEM
748    :NAME "GDK_POINTER_MOTION_HINT_MASK"
749    :VALUE 8
750    :NICK "pointer-motion-hint-mask")
751 @end example
752
753 @node get-enum-items
754 @section get-enum-items
755
756 @code{(get-enum-items type) @result{} items}
757
758 @table @var
759 @item @var{type}
760 A GType designator of an enum type
761 @item @var{items}
762 A list of @code{enum-item} structures
763 @end table
764
765 Returns a list of items in an enumeration
766
767 Example:
768 @example
769 (get-enum-items "GtkScrollType")
770 @result{}
771 (#S(ENUM-ITEM :NAME "GTK_SCROLL_NONE" :VALUE 0 :NICK "none")
772  #S(ENUM-ITEM :NAME "GTK_SCROLL_JUMP" :VALUE 1 :NICK "jump")
773  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_BACKWARD" :VALUE 2 :NICK "step-backward")
774  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_FORWARD" :VALUE 3 :NICK "step-forward")
775  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_BACKWARD" :VALUE 4 :NICK "page-backward")
776  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_FORWARD" :VALUE 5 :NICK "page-forward")
777  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_UP" :VALUE 6 :NICK "step-up")
778  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_DOWN" :VALUE 7 :NICK "step-down")
779  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_UP" :VALUE 8 :NICK "page-up")
780  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_DOWN" :VALUE 9 :NICK "page-down")
781  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_LEFT" :VALUE 10 :NICK "step-left")
782  #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_RIGHT" :VALUE 11 :NICK "step-right")
783  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_LEFT" :VALUE 12 :NICK "page-left")
784  #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_RIGHT" :VALUE 13 :NICK "page-right")
785  #S(ENUM-ITEM :NAME "GTK_SCROLL_START" :VALUE 14 :NICK "start")
786  #S(ENUM-ITEM :NAME "GTK_SCROLL_END" :VALUE 15 :NICK "end"))
787 @end example
788
789 @node get-flags-items
790 @section get-flags-items
791
792 @code{(get-flags-items type) @result{} items}
793
794 @table @var
795 @item @var{type}
796 A GType designator of an flags type
797 @item @var{items}
798 A list of @code{flags-item} structures
799 @end table
800
801 Returns a list of items in an flags type
802
803 Example:
804 @example
805 (get-flags-items "GtkAttachOptions")
806 @result{}
807 (#S(FLAGS-ITEM :NAME "GTK_EXPAND" :VALUE 1 :NICK "expand")
808  #S(FLAGS-ITEM :NAME "GTK_SHRINK" :VALUE 2 :NICK "shrink")
809  #S(FLAGS-ITEM :NAME "GTK_FILL" :VALUE 4 :NICK "fill"))
810 @end example
811
812 @node Using GValues
813 @chapter Using GValues
814 @menu
815 * g-value-zero::
816 * g-value-init::
817 * g-value-unset::
818 * parse-g-value::
819 * set-g-value::
820 @end menu
821
822 GValue is a generic container for arbitrary value of type supported by GType system. Refer to GObject documentation for more detailed information.
823
824 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.
825
826 GValue is used whenever a value of unkown type should be passed. It is used in:
827 @itemize
828 @item Closure marshal functions
829 @item Property get and set functions
830 @end itemize
831
832 Example of usage:
833 @example
834 (cffi:with-foreign-object (gval 'g-value)
835   (set-g-value gval "Hello" "gchararray" :zero-g-value t)
836   (format t "~S~%" (parse-g-value gval))
837   (g-value-unset gval))
838 @result{}
839 "Hello"
840 @end example
841
842 @node g-value-zero
843 @section g-value-zero
844 @code{(g-value-zero g-value)}
845 @table @var
846 @item @var{g-value}
847 A foreign pointer to GValue structure.
848 @end table
849
850 Initializes the GValue to "unset" state. Equivalent of the following initializer in C:
851 @example
852 GValue value = @{ 0 @};
853 @end example
854
855 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).
856
857 @node g-value-init
858 @section g-value-init
859
860 @code{(g-value-init value type)}
861 @table @var
862 @item @var{value}
863 A foreign pointer to GValue structure
864 @item @var{type}
865 A GType designator
866 @end table
867
868 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).
869
870 @node g-value-unset
871 @section g-value-unset
872 @code{(g-value-unset value)}
873 @table @var
874 @item @var{value}
875 A foreign pointer to GValue structure.
876 @end table
877
878 Unsets the GValue. This frees all resources associated with GValue.
879
880 @node parse-g-value
881 @section parse-g-value
882 @code{(parse-g-value value) @result{} object}
883 @table @var
884 @item @var{value}
885 A foreign pointer to GValue structure
886 @item @var{object}
887 A Lisp object
888 @end table
889
890 Retrieves the object from GValue structure.
891
892 @node set-g-value
893 @section set-g-value
894 @code{(set-g-value gvalue object type &key zero-g-value unset-g-value (g-value-init t))}
895
896 @table @var
897 @item @var{gvalue}
898 A foreign pointer to GValue structure
899 @item @var{object}
900 An object that is to be assigned to @code{gvalue}
901 @item @var{type}
902 A GType designator specifying what GType should be set
903 @item @var{unset-g-value}
904 A boolean specifying whether to call @code{g-value-unset} before assigment.
905 @item @var{zero-g-value}
906 A boolean specifying whether to call @code{g-value-zero} before assignment
907 @item @var{g-value-init}
908 A boolean specifying whether to call @code{g-value-init} before assignment
909 @end table
910
911 Assigns the @code{object} to the @code{gvalue}. When GValue is not used, call @code{g-value-unset} to deinitialize the @code{GValue}.
912
913 @node Stable pointers
914 @chapter Stable pointers
915 @menu
916 * allocate-stable-pointer::
917 * free-stable-pointer::
918 * stable-pointer-value::
919 * with-stable-pointer::
920 @end menu
921
922 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.
923
924 @node allocate-stable-pointer
925 @section allocate-stable-pointer
926
927 @code{(allocate-stable-pointer thing) @result{} stable-pointer}
928
929 @table @var
930 @item @var{thing}
931 An arbitrary Lisp object
932 @item @var{stable-pointer}
933 A foreign pointer
934 @end table
935
936 Allocates a stable pointer to @code{thing}.
937
938 (Note: @var{stable-pointer} should not be dereferenced with @code{cffi:mem-ref}. It should only be dereferenced with @code{stable-pointer-value})
939
940 Example:
941 @example
942 (allocate-stable-pointer (lambda (x) (+ x 10)))
943 @result{}
944 #.(SB-SYS:INT-SAP #X00000002)
945
946 (stable-pointer-value *)
947 @result{}
948 #<FUNCTION (LAMBDA (X)) @{1004D016F9@}>
949
950 (free-stable-pointer **)
951 @result{}
952 NIL
953 @end example
954
955 @node free-stable-pointer
956 @section free-stable-pointer
957
958 @code{(free-stable-pointer stable-pointer)}
959
960 @table @var
961 @item @var{stable-pointer}
962 A foreign pointer that was created with @code{allocate-stable-pointer}.
963 @end table
964
965 Frees the stable pointer, enabling the garbage collector to reclaim the object.
966
967 Example:
968 @example
969 (allocate-stable-pointer (lambda (x) (+ x 10)))
970 @result{}
971 #.(SB-SYS:INT-SAP #X00000002)
972
973 (stable-pointer-value *)
974 @result{}
975 #<FUNCTION (LAMBDA (X)) @{1004D016F9@}>
976
977 (free-stable-pointer **)
978 @result{}
979 NIL
980 @end example
981
982 @node stable-pointer-value
983 @section stable-pointer-value
984
985 @example
986 (stable-pointer-value stable-pointer) @result{} thing
987 (setf (stable-pointer-value stable-pointer) thing)
988 @end example
989
990 @table @var
991 @item @var{stable-pointer}
992 A foreign pointer created by @code{allocate-stable-pointer}
993 @item @var{thing}
994 A Lisp object
995 @end table
996
997 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.
998
999 @node with-stable-pointer
1000 @section with-stable-pointer
1001
1002 @code{(with-stable-pointer (ptr expr) &body body)}
1003
1004 @table @var
1005 @item @var{ptr}
1006 A variable that will be bound to the stable pointer
1007 @item @var{expr}
1008 An expression that will be evaluated once and its value will be bound to stable pointer's value
1009 @end table
1010
1011 Executes the body with the @code{ptr} variable being bound to a stable pointer whose value is determined by @code{expr}.
1012
1013 Example:
1014 @example
1015 (with-stable-pointer (ptr (lambda (x) (+ x 10)))
1016   (print (stable-pointer-value ptr)))
1017 ;;Prints:
1018 #<FUNCTION (LAMBDA (X)) @{1004807E79@}>
1019 @end example
1020
1021 @node Closures
1022 @chapter Closures
1023
1024 Closure are anonymous functions that capture their lexical environment.
1025
1026 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).
1027
1028 @section create-g-closure
1029 @code{(create-g-closure fn) @result{} closure}
1030
1031 @table @var
1032 @item @var{fn}
1033 A function that will be called by closure invokation
1034 @item @var{closure}
1035 A foreign pointer to allocated closure
1036 @end table
1037
1038 Allocates the closure. The closure is destroyed automatically by GObject.
1039
1040 Example:
1041 @example
1042 (create-g-closure (lambda (x) (+ x 10)))
1043 @result{}
1044 #.(SB-SYS:INT-SAP #X006D7B20)
1045 @end example
1046
1047 Example of usage from GObject binding code:
1048 @example
1049 (defun connect-signal (object signal handler &key after)
1050   (g-signal-connect-closure (ensure-object-pointer object)
1051                             signal
1052                             (create-g-closure handler)
1053                             after))
1054 @end example
1055
1056 (TODO: GObject defines finer closure API: g_closure_ref, g_closure_unref, g_closure_invoke. It should be bound.)
1057
1058 @node GObject low-level
1059 @chapter GObject low-level
1060 @menu
1061 * g-object-call-constructor::
1062 * g-type-from-object::
1063 * g-object-call-get-property::
1064 * g-object-call-set-property::
1065 @end menu
1066
1067 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.
1068
1069 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.
1070
1071 @node g-object-call-constructor
1072 @section g-object-call-constructor
1073
1074 @code{(g-object-call-constructor object-type args-names args-values &optional args-types) @result{} object-ptr}
1075
1076 @table @var
1077 @item @var{object-type}
1078 A GType designator that specifies the object type that is to be created
1079 @item @var{args-names}
1080 A list of strings naming the arguments to constructor
1081 @item @var{args-value}
1082 A list of arguments values (in the same order as args-names)
1083 @item @var{args-types}
1084 Optional list of arguments types (in the same order as args-names). If not specified, it is detected automatically
1085 @item @var{object-ptr}
1086 A foreign pointer to newly created instance
1087 @end table
1088
1089 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}.
1090
1091 Example:
1092 @example
1093 (g-object-call-constructor "GtkButton" '("label" "use-underline") '("Hello" t) '("gchararray" "gboolean"))
1094 @result{}
1095 #.(SB-SYS:INT-SAP #X006D8900)
1096
1097 (g-object-call-get-property * "label")
1098 @result{}
1099 "Hello"
1100
1101 (g-object-call-get-property ** "use-underline")
1102 @result{}
1103 T
1104 @end example
1105
1106 @node g-type-from-object
1107 @section g-type-from-object
1108
1109 @code{(g-type-from-object object-ptr) @result{} type}
1110
1111 @table @var
1112 @item @var{object-ptr}
1113 A foreign pointer to a GObject instance
1114 @item @var{type}
1115 A GType designator
1116 @end table
1117
1118 Returns the type of an object by a pointer to its instance
1119
1120 Example:
1121 @example
1122 (g-type-from-object (g-object-call-constructor "GtkButton" nil nil))
1123 @result{}
1124 "GtkButton"
1125 @end example
1126
1127 @node g-object-call-get-property
1128 @section g-object-call-get-property
1129
1130 @code{(g-object-call-get-property object-ptr property-name &optional property-type) @result{} property-value}
1131
1132 @table @var
1133 @item @var{object-ptr}
1134 A foreign pointer to a GObject instance
1135 @item @var{property-name}
1136 A string naming the property
1137 @item @var{property-type}
1138 Optional GType designator specifying the type of a property
1139 @item @var{property-value}
1140 The value of a property
1141 @end table
1142
1143 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.
1144
1145 Example:
1146 @example
1147 (g-object-call-constructor "GtkButton" '("label" "use-underline") '("Hello" t) '("gchararray" "gboolean"))
1148 @result{}
1149 #.(SB-SYS:INT-SAP #X006D8900)
1150
1151 (g-object-call-get-property * "label")
1152 @result{}
1153 "Hello"
1154
1155 (g-object-call-get-property ** "use-underline")
1156 @result{}
1157 T
1158 @end example
1159
1160 @node g-object-call-set-property
1161 @section g-object-call-set-property
1162
1163 @code{(g-object-call-set-property object-ptr property-name new-value &optional property-type)}
1164
1165 @table @var
1166 @item @var{object-ptr}
1167 A foreign pointer to a GObject instance
1168 @item @var{property-name}
1169 A string naming the property
1170 @item @var{new-value}
1171 A new value of a property
1172 @item @var{property-type}
1173 Optional GType designator specifying the type of a property
1174 @end table
1175
1176 Sets the property value of property @code{property-name} of object @code{object-ptr} to @code{new-value}.
1177
1178 Example:
1179 @example
1180 (g-object-call-constructor "GtkButton" nil nil)
1181 @result{}
1182 #.(SB-SYS:INT-SAP #X006D8B40)
1183
1184 (g-object-call-set-property * "label" "Hello")
1185 @result{}
1186 ; No value
1187
1188 (g-object-call-get-property ** "label")
1189 @result{}
1190 "Hello"
1191 @end example
1192
1193 @node GObject high-level
1194 @chapter GObject high-level
1195 @menu
1196 * GObject metaclass::
1197 * Using objects::
1198 * Signals::
1199 * GObject foreign class::
1200 @end menu
1201
1202 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):
1203 @itemize
1204 @item objects are created with @code{make-instance}
1205 @item properties are used as regular slots
1206 @end itemize
1207
1208 GObjects are reference counted, and CL-GTK2-GOBJECT manages its own reference to GObjects. This enables to have transparent garbage collection of unreferenced GObjects.
1209
1210 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.
1211
1212 Example GObject class of definition:
1213 @example
1214 (defclass dialog (gtk-window atk-implementor-iface buildable)
1215   ((has-separator :accessor dialog-has-separator
1216                   :initarg :has-separator
1217                   :allocation :gobject-property
1218                   :g-property-type "gboolean"
1219                   :g-property-name "has-separator"))
1220   (:metaclass gobject-class)
1221   (:g-type-name . "GtkDialog")
1222   (:g-type-initializer . "gtk_dialog_get_type"))
1223 @end example
1224
1225 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.
1226
1227 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.
1228
1229 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).
1230
1231 @node GObject metaclass
1232 @section GObject metaclass
1233
1234 See MOP for information what metaclass is and why is it useful.
1235
1236 GObject metaclass @code{gobject-class} bridges two object systems: GObject and CLOS.
1237
1238 Classes that correspond to GObject classes are instances of this class.
1239
1240 This class has the following slots:
1241 @itemize
1242 @item @var{g-type-name} (accessor @code{gobject-class-g-type-name}, initarg @code{:g-type-name})
1243
1244 Specifies the name of GObject class
1245 @item @var{g-type-initializer} (accessor @code{gobject-class-g-type-initializer}, initarg @code{:g-type-initializer})
1246
1247 Name of type initializer function. This function initializes the class and returns its GType. Typically it is named @code{class_get_type}.
1248 @item @var{interface-p} (accessor @code{gobject-class-interface-p}, initarg @code{:interface-p})
1249 @end itemize
1250
1251 This metaclass defines the GObject classes.
1252
1253 Slots which have @code{:allocation} of @code{:gobject-property} are mapped to GObject properties. This metaclass defines the following attributes for slots:
1254 @itemize
1255 @item @var{:g-property-type}
1256
1257 A name of a type of property
1258 @item @var{:g-property-name}
1259
1260 A name of a property
1261 @end itemize
1262
1263 Initargs of a slot are used to construct the GObject class.
1264
1265 Example:
1266 @example
1267 (defclass dialog (gtk-window atk-implementor-iface buildable)
1268   ((has-separator :accessor dialog-has-separator
1269                   :initarg :has-separator
1270                   :allocation :gobject-property
1271                   :g-property-type "gboolean"
1272                   :g-property-name "has-separator"))
1273   (:metaclass gobject-class)
1274   (:g-type-name . "GtkDialog")
1275   (:g-type-initializer . "gtk_dialog_get_type"))
1276 @end example
1277 (note the dot in @code{(:g-type-name . "GtkDialog")} and in @code{(:g-type-initializer . "gtk_dialog_get_type")}. It should be present)
1278
1279 @node Using objects
1280 @section Using objects
1281 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.
1282
1283 Example:
1284 @example
1285 (make-instance 'gtk:dialog :has-separator t)
1286 @result{}
1287 #<GTK:DIALOG @{10036C5A71@}>
1288
1289 (defvar *d* (make-instance 'gtk:dialog :has-separator t))
1290 @result{}
1291 *D*
1292
1293 (gtk:dialog-has-separator *d*)
1294 @result{}
1295 T
1296
1297 (setf (gtk:dialog-has-separator *d*) nil)
1298 @result{}
1299 NIL
1300
1301 (gtk:dialog-has-separator *d*)
1302 @result{}
1303 NIL
1304 @end example
1305
1306 @node Signals
1307 @section Signals
1308
1309 To connect handler to a signal, @code{connect-signal} function is used.
1310
1311 @code{(connect-signal object signal handler &key after)}
1312
1313 @table @var
1314 @item @var{object}
1315 An instance of GObject object
1316 @item @var{signal}
1317 A signal name
1318 @item @var{handler}
1319 A function
1320 @item @var{after}
1321 A boolean specifying whether the handler should be called after the default handler
1322 @end table
1323
1324 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.
1325
1326 Example:
1327 @example
1328 (defvar *d* (make-instance 'gtk:dialog))
1329 @result{}
1330 *D*
1331
1332 *d*
1333 @result{}
1334 #<GTK:DIALOG @{1002D866F1@}>
1335
1336 (parse-signal-name "GtkDialog" "response")
1337 @result{}
1338 #<Signal [#86] void GtkDialog.response(gint) [RUN-LAST]>
1339
1340 (connect-signal *d* "response" (lambda (dialog response-value) (print dialog) (print response-value)))
1341
1342 (emit-signal *d* "response" 14)
1343 @result{}
1344 ;; Prints:
1345 #<GTK:DIALOG @{1002D866F1@}>
1346 14 
1347 @end example
1348
1349 Function @code{emit-signal} is used to emit signals on objects.
1350
1351 @code{(emit-signal object signal-name &rest args) @result{} return-value}
1352
1353 @table @var
1354 @item @var{object}
1355 An object on which the signal should be emitted
1356 @item @var{signal-name}
1357 A string naming the signal
1358 @item @var{args}
1359 Arguments for a signal
1360 @item @var{return-value}
1361 Return value of a signal
1362 @end table
1363
1364 Emits the signal and calls all handlers of the signal. If signal returns a value, it is returned from @code{emit-signal}.
1365
1366 Example:
1367 @example
1368 (defvar *d* (make-instance 'gtk:dialog))
1369 @result{}
1370 *D*
1371
1372 *d*
1373 @result{}
1374 #<GTK:DIALOG @{1002D866F1@}>
1375
1376 (parse-signal-name "GtkDialog" "response")
1377 @result{}
1378 #<Signal [#86] void GtkDialog.response(gint) [RUN-LAST]>
1379
1380 (connect-signal *d* "response" (lambda (dialog response-value) (print dialog) (print response-value)))
1381
1382 (emit-signal *d* "response" 14)
1383 @result{}
1384 ;; Prints:
1385 #<GTK:DIALOG @{1002D866F1@}>
1386 14 
1387 @end example
1388
1389 @node GObject foreign class
1390 @section GObject foreign class
1391
1392 To enable passing GObject instance between Lisp code and foreign code, @code{g-object} foreign type is introduced.
1393
1394 This type has the following syntax:
1395 @code{(g-object &optional type)} or @code{g-object}.
1396
1397 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.
1398
1399 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.
1400
1401 This defines the function that may be called with instances of types @code{container} and @code{widget}:
1402 @example
1403 (defcfun (container-add "gtk_container_add") :void
1404   (container (g-object container))
1405   (widget (g-object widget)))
1406
1407 (let ((window (make-instance 'gtk-window))
1408       (widget (make-instance 'button)))
1409   (container-add window widget))
1410 @end example
1411 (@code{gtk-window} is a subclass of @code{container}; @code{button} is a subclass of @code{widget})
1412
1413 This defines the function that returns an instance of GObject class:
1414 @example
1415 (defcfun (bin-child "gtk_bin_get_child") (g-object widget)
1416   (bin (g-object bin)))
1417
1418 (let ((window (make-instance 'gtk-window))
1419       (widget (make-instance 'button)))
1420   (container-add window widget)
1421   (bin-child window))
1422 @result{}
1423 #<GTK:BUTTON @{1002DE74B1@}>
1424 @end example
1425
1426 @node Subclassing GObjects and implementing GInterfaces
1427 @chapter Subclassing GObjects and implementing GInterfaces
1428
1429 @node GBoxed
1430 @chapter GBoxed
1431
1432 @node Generating type definitions by introspection
1433 @chapter Generating type definitions by introspection
1434
1435
1436 @bye
1437