5 * Type hierarchy and type relations::
6 * Object types information::
7 * Enum types information::
12 * GObject high-level::
13 * Creating GObjects classes and implementing GInterfaces::
15 * Generating type definitions by introspection::
21 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.
23 The purpose of CL-GTK2-GObject is to ease the creation of binding for libraries based on GObject.
25 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.
27 CL-GTK2-GObject is logically split into several layers:
29 @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.
30 @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.
31 @item High-level GObject integration. This layer includes support for interoperability between CLOS and GObject and automatic generation of corresponding definitions.
34 Naturally, users of CL-GTK2-GObject should use the high-level GObject integration, but occasionaly it may be necessary to use lower-level functionality.
36 @node GType designator
37 @chapter GType designator
46 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.
48 An example of GType designator is a string @code{"GObject"} and the numeric value 80 that corresponds to it.
50 Some of the types are fundamental and have constant integer values. They are identified by constants (strings in parentheses are corresponding type names):
52 @item @code{+g-type-invalid+}. An invalid GType used as error return value in some functions which return a GType.
53 @item @code{+g-type-void+} ("void"). A fundamental type which is used as a replacement for the C @code{void} return type.
54 @item @code{+g-type-interface+} ("GInterface"). The fundamental type from which all interfaces are derived.
55 @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}.
56 @item @code{+g-type-uchar+} ("guchar"). The fundamental type corresponding to @code{guchar}.
57 @item @code{+g-type-boolean+} ("gboolean"). The fundamental type corresponding to @code{gboolean}.
58 @item @code{+g-type-int+} ("gint"). The fundamental type corresponding to @code{gint}.
59 @item @code{+g-type-uint+} ("guint"). The fundamental type corresponding to @code{guint}.
60 @item @code{+g-type-long+} ("glong"). The fundamental type corresponding to @code{glong}.
61 @item @code{+g-type-ulong+} ("gulong"). The fundamental type corresponding to @code{gulong}.
62 @item @code{+g-type-int64+} ("gint64"). The fundamental type corresponding to @code{gint64}.
63 @item @code{+g-type-uint64+} ("guint64"). The fundamental type corresponding to @code{guint64}.
64 @item @code{+g-type-enum+} ("GEnum"). The fundamental type from which all enumeration types are derived.
65 @item @code{+g-type-flags+} ("GFlags"). The fundamental type from which all flags types are derived.
66 @item @code{+g-type-float+} ("gfloat"). The fundamental type corresponding to @code{gfloat}.
67 @item @code{+g-type-double+} ("gdouble"). The fundamental type corresponding to @code{gdouble}.
68 @item @code{+g-type-string+} ("gchararray"). The fundamental type corresponding to null-terminated C strings.
69 @item @code{+g-type-pointer+} ("gpointer"). The fundamental type corresponding to @code{gpointer}.
70 @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.
71 @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}.
72 @item @code{+g-type-object+} ("GObject"). The fundamental type for GObject.
75 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.
77 Invalid type (the GType that does not exist) is identified as a 0 or @code{NIL}.
80 (g-type-numeric "GObject") @result{} 80
81 (g-type-numeric 80) @result{} 80
82 (g-type-string "GObject") @result{} "GObject"
83 (g-type-string 80) @result{} "GObject"
84 (g-type-numeric "GtkWidget") @result{} 6905648 ;;Will be different on each run
88 @section g-type-string
90 @Function g-type-string
92 (g-type-string g-type-designator) @result{} name
96 @item @var{g-type-designator}
97 The GType designator for the GType
102 Returns the name of GType.
105 @section g-type-numeric
107 @Function g-type-numeric
109 (g-type-numeric g-type-designator) @result{} GType
113 @item @var{g-type-designator}.
114 The GType designator for the GType.
116 The numeric identifier of GType
119 Returns the numeric identifier of GType
126 (g-type= type-1 type-2) @result{} eq
135 A boolean that is true if @code{type-1} and @code{type-2} designate the same type.
143 (g-type/= type-1 type-2) @result{} eq
152 A boolean that is true if @code{type-1} and @code{type-2} designate different types.
155 @node Type hierarchy and type relations
156 @chapter Type hierarchy and type relations
161 * g-type-fundamental::
166 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.
168 There are functions to query some specific information:
170 @item @code{g-type-fundamental} retrieves the fundamental type for given type
171 @item @code{g-type-depth} calculates the depth of the type in type hierarchy
172 @item @code{g-type-next-base} calculates the first step in the path from base type to descendent type
175 @node g-type-children
176 @section g-type-children
178 @Function g-type-children
180 (g-type-children type) @result{} children
187 A list of GType designators
190 Returns the list of descendent types.
194 (g-type-children "GtkButton")
196 ("GtkToggleButton" "GtkColorButton" "GtkFontButton" "GtkLinkButton" "GtkScaleButton")
200 @section g-type-parent
202 @Function g-type-parent
204 (g-type-parent type) @result{} parent
214 Returns the parent of @code{type}.
218 (g-type-parent "GtkToggleButton")
223 @node g-type-fundamental
224 @section g-type-fundamental
226 @Function g-type-fundamental
228 (g-type-fundamental type) @result{} fundamental-type
234 @item @var{fundamental-type}
235 A GType designator for one of the fundamental types
238 Returns the fundamental type that is the ancestor of @code{type}.
242 (g-type-fundamental "GtkButton") @result{} "GObject"
244 (g-type-fundamental "GtkWindowType") @result{} "GEnum"
246 (g-type-fundamental "GdkEvent") @result{} "GBoxed"
250 @section g-type-depth
252 @Function g-type-depth
254 (g-type-depth type) @result{} depth
264 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.
268 (g-type-depth "GObject") @result{} 1
269 (g-type-depth "GInitiallyUnowned") @result{} 2
272 @node g-type-next-base
273 @section g-type-next-base
275 @Function g-type-next-base
277 (g-type-next-base leaf-type root-type) @result{} base-type
281 @item @var{leaf-type}
283 @item @var{root-type}
285 @item @var{base-type}
289 Returns the next type that should be traversed from @code{root-type} in order to reach @code{leaf-type}. E.g., given type hierarchy:
306 the following will be returned:
309 (g-type-next-base "GtkTable" "GObject") @result{} "GInitiallyUnowned"
310 (g-type-next-base "GtkTable" "GInitiallyUnowned") @result{} "GtkObject"
311 (g-type-next-base "GtkTable" "GtkObject") @result{} "GtkWidget"
312 (g-type-next-base "GtkTable" "GtkWidget") @result{} "GtkContainer"
313 (g-type-next-base "GtkTable" "GtkContainer") @result{} "GtkTable"
316 @node Object types information
317 @chapter Object types information
319 * g-class-property-definition::
321 * class-property-info::
322 * interface-properties::
325 * parse-signal-name::
326 * query-signal-info::
327 * g-type-interfaces::
328 * g-type-interface-prerequisites::
331 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.
333 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.
335 @node g-class-property-definition
336 @section g-class-property-definition
338 @Struct g-class-property-definition
340 (defstruct g-class-property-definition
352 A string that names the property
354 A GType designator. Identifies the type of the property
356 A boolean. Identifies whether the property can be read
358 A boolean. Identifies whether the property can be assigned
359 @item @var{constructor}
360 A boolean. Identifies whether constructor of object accepts this property
361 @item @var{constructor-only}
362 A boolean. Identifies whether this property may only be set in constructor, not in property setter
363 @item @var{owner-type}
364 A GType designator. Identifies the type on which the property was defined.
367 This structure identifies a single property. Its field specify attributes of a property.
369 Structures of this type have shortened print syntax:
371 #<PROPERTY gchararray GtkButton.label (flags: readable writable constructor)>
374 (When @code{*print-readably*} is T, usual @code{defstruct} print syntax is used)
376 This syntax specifies:
378 @item type of property
379 @item the owner type of property
380 @item name of property
381 @item additional flags of property
384 @node class-properties
385 @section class-properties
387 @Function class-properties
389 (class-properties type) @result{} properties
394 A GType designator. Specifies the object type (class)
395 @item @var{properties}
396 A list of @code{g-property-definition} structures.
399 This function returns the list of properties that are available in class @code{type}.
403 (class-properties "GtkWidget")
405 (#<PROPERTY gpointer GtkObject.user-data (flags: readable writable)>
406 #<PROPERTY gchararray GtkWidget.name (flags: readable writable)>
407 #<PROPERTY GtkContainer GtkWidget.parent (flags: readable writable)>
408 #<PROPERTY gint GtkWidget.width-request (flags: readable writable)>
409 #<PROPERTY gint GtkWidget.height-request (flags: readable writable)>
410 #<PROPERTY gboolean GtkWidget.visible (flags: readable writable)>
411 #<PROPERTY gboolean GtkWidget.sensitive (flags: readable writable)>
412 #<PROPERTY gboolean GtkWidget.app-paintable (flags: readable writable)>
413 #<PROPERTY gboolean GtkWidget.can-focus (flags: readable writable)>
414 #<PROPERTY gboolean GtkWidget.has-focus (flags: readable writable)>
415 #<PROPERTY gboolean GtkWidget.is-focus (flags: readable writable)>
416 #<PROPERTY gboolean GtkWidget.can-default (flags: readable writable)>
417 #<PROPERTY gboolean GtkWidget.has-default (flags: readable writable)>
418 #<PROPERTY gboolean GtkWidget.receives-default (flags: readable writable)>
419 #<PROPERTY gboolean GtkWidget.composite-child (flags: readable)>
420 #<PROPERTY GtkStyle GtkWidget.style (flags: readable writable)>
421 #<PROPERTY GdkEventMask GtkWidget.events (flags: readable writable)>
422 #<PROPERTY GdkExtensionMode GtkWidget.extension-events (flags: readable writable)>
423 #<PROPERTY gboolean GtkWidget.no-show-all (flags: readable writable)>
424 #<PROPERTY gboolean GtkWidget.has-tooltip (flags: readable writable)>
425 #<PROPERTY gchararray GtkWidget.tooltip-markup (flags: readable writable)>
426 #<PROPERTY gchararray GtkWidget.tooltip-text (flags: readable writable)>
427 #<PROPERTY GdkWindow GtkWidget.window (flags: readable)>)
430 @node class-property-info
431 @section class-property-info
432 @Function class-property-info
434 (class-property-info type property-name) @result{} property
440 @item @var{property-name}
441 A string naming the property
443 An instance of @code{g-property-definition} structure
446 Returns the property information for a single property.
450 (class-property-info "GtkButton" "label")
452 #<PROPERTY gchararray GtkButton.label (flags: readable writable constructor)>
455 @node interface-properties
456 @section interface-properties
458 @Function interface-properties
460 (interface-properties type) @result{} properties
466 @item @var{properties}
467 A list of @code{g-property-definition} structures
470 This function returns the list of properties that are available in interface @code{type}.
474 (interface-properties "GtkFileChooser")
476 (#<PROPERTY GtkWidget GtkFileChooser.extra-widget (flags: readable writable)>
477 #<PROPERTY gboolean GtkFileChooser.use-preview-label (flags: readable writable)>
478 #<PROPERTY gboolean GtkFileChooser.preview-widget-active (flags: readable writable)>
479 #<PROPERTY gboolean GtkFileChooser.show-hidden (flags: readable writable)>
480 #<PROPERTY gchararray GtkFileChooser.file-system-backend (flags: writable constructor-only)>
481 #<PROPERTY GtkFileChooserAction GtkFileChooser.action (flags: readable writable)>
482 #<PROPERTY GtkFileFilter GtkFileChooser.filter (flags: readable writable)>
483 #<PROPERTY gboolean GtkFileChooser.select-multiple (flags: readable writable)>
484 #<PROPERTY GtkWidget GtkFileChooser.preview-widget (flags: readable writable)>
485 #<PROPERTY gboolean GtkFileChooser.local-only (flags: readable writable)>
486 #<PROPERTY gboolean GtkFileChooser.do-overwrite-confirmation (flags: readable writable)>)
494 (defstruct signal-info
506 An integer - the identifier of a signal
509 @item @var{owner-type}
510 A GType designator identifying the type on which the signal was defined
512 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
513 @item @var{return-type}
514 The return type of a signal (and signal handlers)
515 @item @var{param-types}
516 A list of GType designators that specify the types of signal parameters
518 A string. Specifies the "detail" part of a signal name. E.g., @code{"label"} for signal @code{"notify::label"}.
521 When @code{*print-readably*} is nil, the following print syntax is used:
523 #<Signal [#1] void GObject.notify::label(GParam) [RUN-FIRST, NO-RECURSE, DETAILED, ACTION, NO-HOOKS]>
524 #<Signal [#54] gboolean GtkWidget.proximity-in-event(GdkEvent) [RUN-LAST]>
525 #<Signal [#64] void GtkWidget.drag-data-received(GdkDragContext, gint, gint, GtkSelectionData, guint, guint) [RUN-LAST]>
526 #<Signal [#8] void GtkObject.destroy() [RUN-CLEANUP, NO-RECURSE, NO-HOOKS]>
529 This syntax specifies:
532 @item signal return type
536 @item list of types of parameters
541 @section type-signals
542 @Function type-signals
544 (type-signals type &key (include-inherited t)) @result{} signals
550 A list of @code{signal-info} structures
551 @item @var{include-inherited}
552 A boolean that specifies whether to include signals defined on this type or also on ancestor types.
555 Returns the list of signals that are available in type @code{type}.
559 (type-signals "GtkLabel" :include-inherited nil)
561 (#<Signal [#138] void GtkLabel.move-cursor(GtkMovementStep, gint, gboolean) [RUN-LAST, ACTION]>
562 #<Signal [#139] void GtkLabel.copy-clipboard() [RUN-LAST, ACTION]>
563 #<Signal [#140] void GtkLabel.populate-popup(GtkMenu) [RUN-LAST]>)
566 @node parse-signal-name
567 @section parse-signal-name
569 @Function parse-signal-name
571 (parse-signal-name type signal-name) @result{} signal
576 A GType designator that has the signal.
577 @item @var{signal-name}
578 A string that identifies the signal.
580 A list @code{signal-info} structures.
583 Parses the signal name and returns the corresponding information. @code{signal-name} may include the detail part.
587 (parse-signal-name "GObject" "notify::label")
589 #<Signal [#1] void GObject.notify::label(GParam) [RUN-FIRST, NO-RECURSE, DETAILED, ACTION, NO-HOOKS]>
592 @node query-signal-info
593 @section query-signal-info
594 @Function query-signal-info
596 (query-signal-info signal-id) @result{} signal
599 @item @var{signal-id}
600 An integer identifying the signal
602 An instance of @code{signal-info} structure
605 Retrieves the signal information by its id.
609 (query-signal-info 73)
611 #<Signal [#73] gboolean GtkWidget.show-help(GtkWidgetHelpType) [RUN-LAST, ACTION]>
614 @node g-type-interfaces
615 @section g-type-interfaces
617 @Function g-type-interfaces
619 (g-type-interfaces type) @result{} interfaces
625 @item @var{interfaces}
626 A list of GType designators
629 Returns the list of interfaces that @code{type} implements.
633 (g-type-interfaces "GtkButton")
635 ("AtkImplementorIface" "GtkBuildable" "GtkActivatable")
638 @node g-type-interface-prerequisites
639 @section g-type-interface-prerequisites
641 @Function g-type-interface-prerequisites
643 (g-type-interface-prerequisites type) @result{} types
648 A GType designator of interface
650 A list of GType designators specifying the interface prerequisites
653 Returns the prerequisites of an interface @code{type}. Prerequisite is a type that should be an ancestor of a type implementing interface @code{type}.
657 (g-type-interface-prerequisites "GtkCellEditable")
659 ("GtkObject" "GtkWidget")
662 @node Enum types information
663 @chapter Enum types information
671 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.
673 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.
685 A string - name of enum item
687 An integer - numeric value of enum item
689 A string - short name of an enum item
692 Structure @code{enum-item} represents a single item of an enumeration type.
696 #S(ENUM-ITEM :NAME "GTK_WINDOW_TOPLEVEL" :VALUE 0 :NICK "toplevel")
703 (defstruct flags-item
709 A string - name of flags item
711 An integer - numeric value of flags item
713 A string - short name of an flags item
716 Structure @code{flags-item} represents a single item of an flags type.
721 :NAME "GDK_POINTER_MOTION_HINT_MASK"
723 :NICK "pointer-motion-hint-mask")
727 @section get-enum-items
729 @Function get-enum-items
731 (get-enum-items type) @result{} items
736 A GType designator of an enum type
738 A list of @code{enum-item} structures
741 Returns a list of items in an enumeration
745 (get-enum-items "GtkScrollType")
747 (#S(ENUM-ITEM :NAME "GTK_SCROLL_NONE" :VALUE 0 :NICK "none")
748 #S(ENUM-ITEM :NAME "GTK_SCROLL_JUMP" :VALUE 1 :NICK "jump")
749 #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_BACKWARD" :VALUE 2 :NICK "step-backward")
750 #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_FORWARD" :VALUE 3 :NICK "step-forward")
751 #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_BACKWARD" :VALUE 4 :NICK "page-backward")
752 #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_FORWARD" :VALUE 5 :NICK "page-forward")
753 #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_UP" :VALUE 6 :NICK "step-up")
754 #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_DOWN" :VALUE 7 :NICK "step-down")
755 #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_UP" :VALUE 8 :NICK "page-up")
756 #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_DOWN" :VALUE 9 :NICK "page-down")
757 #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_LEFT" :VALUE 10 :NICK "step-left")
758 #S(ENUM-ITEM :NAME "GTK_SCROLL_STEP_RIGHT" :VALUE 11 :NICK "step-right")
759 #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_LEFT" :VALUE 12 :NICK "page-left")
760 #S(ENUM-ITEM :NAME "GTK_SCROLL_PAGE_RIGHT" :VALUE 13 :NICK "page-right")
761 #S(ENUM-ITEM :NAME "GTK_SCROLL_START" :VALUE 14 :NICK "start")
762 #S(ENUM-ITEM :NAME "GTK_SCROLL_END" :VALUE 15 :NICK "end"))
765 @node get-flags-items
766 @section get-flags-items
768 @Function get-flags-items
770 (get-flags-items type) @result{} items
775 A GType designator of an flags type
777 A list of @code{flags-item} structures
780 Returns a list of items in an flags type
784 (get-flags-items "GtkAttachOptions")
786 (#S(FLAGS-ITEM :NAME "GTK_EXPAND" :VALUE 1 :NICK "expand")
787 #S(FLAGS-ITEM :NAME "GTK_SHRINK" :VALUE 2 :NICK "shrink")
788 #S(FLAGS-ITEM :NAME "GTK_FILL" :VALUE 4 :NICK "fill"))
792 @chapter Using GValues
799 * Registering types::
802 GValue is a generic container for arbitrary value of type supported by GType system. Refer to GObject documentation for more detailed information.
804 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.
806 GValue is used whenever a value of unkown type should be passed. It is used in:
808 @item Closure marshal functions
809 @item Property get and set functions
814 (cffi:with-foreign-object (gval 'g-value)
815 (set-g-value gval "Hello" "gchararray" :zero-g-value t)
816 (format t "~S~%" (parse-g-value gval))
817 (g-value-unset gval))
823 @section g-value-zero
824 @Function g-value-zero
826 (g-value-zero g-value)
830 A foreign pointer to GValue structure.
833 Initializes the GValue to "unset" state. Equivalent of the following initializer in C:
835 GValue value = @{ 0 @};
838 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).
841 @section g-value-init
843 @Function g-value-init
845 (g-value-init value type)
849 A foreign pointer to GValue structure
854 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).
857 @section g-value-unset
858 @Function g-value-unset
860 (g-value-unset value)
864 A foreign pointer to GValue structure.
867 Unsets the GValue. This frees all resources associated with GValue.
870 @section parse-g-value
871 @Function parse-g-value
873 (parse-g-value value) @result{} object
877 A foreign pointer to GValue structure
882 Retrieves the object from GValue structure.
886 @Function set-g-value
888 (set-g-value gvalue object type &key zero-g-value unset-g-value (g-value-init t))
893 A foreign pointer to GValue structure
895 An object that is to be assigned to @code{gvalue}
897 A GType designator specifying what GType should be set
898 @item @var{unset-g-value}
899 A boolean specifying whether to call @code{g-value-unset} before assigment.
900 @item @var{zero-g-value}
901 A boolean specifying whether to call @code{g-value-zero} before assignment
902 @item @var{g-value-init}
903 A boolean specifying whether to call @code{g-value-init} before assignment
906 Assigns the @code{object} to the @code{gvalue}. When GValue is not used, call @code{g-value-unset} to deinitialize the @code{GValue}.
908 @node Registering types
909 @section Registering types
911 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.
913 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.
915 @subsection register-enum-type
916 @Function register-enum-type
918 (register-enum-type name type)
922 A string naming the GEnum type
924 A symbol - name of CFFI foreign enum type
927 Registers the @code{type} to be used for passing value of GEnum type @code{name} between GObject and Lisp.
931 (defcenum text-direction
933 (register-enum-type "GtkTextDirection" 'text-direction)
936 @subsection register-flags-type
937 @Function register-flags-type
939 (register-flags-type name type)
943 A string naming the GFlags type
945 A symbol - name of CFFI foreign flags type
948 Registers the @code{type} to be used for passing value of GFlags type @code{name} between GObject and Lisp.
953 :normal :active :prelight :selected :insensitive)
954 (register-enum-type "GtkStateType" 'state-type)
957 @node Stable pointers
958 @chapter Stable pointers
960 * allocate-stable-pointer::
961 * free-stable-pointer::
962 * stable-pointer-value::
963 * with-stable-pointer::
966 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.
968 @node allocate-stable-pointer
969 @section allocate-stable-pointer
971 @Function allocate-stable-pointer
973 (allocate-stable-pointer thing) @result{} stable-pointer
978 An arbitrary Lisp object
979 @item @var{stable-pointer}
983 Allocates a stable pointer to @code{thing}.
985 (Note: @var{stable-pointer} should not be dereferenced with @code{cffi:mem-ref}. It should only be dereferenced with @code{stable-pointer-value})
989 (allocate-stable-pointer (lambda (x) (+ x 10)))
991 #.(SB-SYS:INT-SAP #X00000002)
993 (stable-pointer-value *)
995 #<FUNCTION (LAMBDA (X)) @{1004D016F9@}>
997 (free-stable-pointer **)
1002 @node free-stable-pointer
1003 @section free-stable-pointer
1005 @Function free-stable-pointer
1007 (free-stable-pointer stable-pointer)
1011 @item @var{stable-pointer}
1012 A foreign pointer that was created with @code{allocate-stable-pointer}.
1015 Frees the stable pointer, enabling the garbage collector to reclaim the object.
1019 (allocate-stable-pointer (lambda (x) (+ x 10)))
1021 #.(SB-SYS:INT-SAP #X00000002)
1023 (stable-pointer-value *)
1025 #<FUNCTION (LAMBDA (X)) @{1004D016F9@}>
1027 (free-stable-pointer **)
1032 @node stable-pointer-value
1033 @section stable-pointer-value
1035 @Accessor stable-pointer-value
1037 (stable-pointer-value stable-pointer) @result{} thing
1038 (setf (stable-pointer-value stable-pointer) thing)
1042 @item @var{stable-pointer}
1043 A foreign pointer created by @code{allocate-stable-pointer}
1048 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.
1050 @node with-stable-pointer
1051 @section with-stable-pointer
1053 @Macro with-stable-pointer
1055 (with-stable-pointer (ptr expr) &body body)
1060 A variable that will be bound to the stable pointer
1062 An expression that will be evaluated once and its value will be bound to stable pointer's value
1065 Executes the body with the @code{ptr} variable being bound to a stable pointer whose value is determined by @code{expr}.
1069 (with-stable-pointer (ptr (lambda (x) (+ x 10)))
1070 (print (stable-pointer-value ptr)))
1072 #<FUNCTION (LAMBDA (X)) @{1004807E79@}>
1078 Closure are anonymous functions that capture their lexical environment.
1080 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).
1082 @section create-g-closure
1083 @Function create-g-closure
1085 (create-g-closure fn) @result{} closure
1090 A function that will be called by closure invokation
1092 A foreign pointer to allocated closure
1095 Allocates the closure. The closure is destroyed automatically by GObject.
1099 (create-g-closure (lambda (x) (+ x 10)))
1101 #.(SB-SYS:INT-SAP #X006D7B20)
1104 Example of usage from GObject binding code:
1106 (defun connect-signal (object signal handler &key after)
1107 (g-signal-connect-closure (ensure-object-pointer object)
1109 (create-g-closure handler)
1113 (TODO: GObject defines finer closure API: g_closure_ref, g_closure_unref, g_closure_invoke. It should be bound.)
1115 @node GObject low-level
1116 @chapter GObject low-level
1118 * g-object-call-constructor::
1119 * g-type-from-object::
1120 * g-object-call-get-property::
1121 * g-object-call-set-property::
1124 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.
1126 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.
1128 @node g-object-call-constructor
1129 @section g-object-call-constructor
1131 @Function g-object-call-constructor
1133 (g-object-call-constructor object-type args-names args-values &optional args-types) @result{} object-ptr
1137 @item @var{object-type}
1138 A GType designator that specifies the object type that is to be created
1139 @item @var{args-names}
1140 A list of strings naming the arguments to constructor
1141 @item @var{args-value}
1142 A list of arguments values (in the same order as args-names)
1143 @item @var{args-types}
1144 Optional list of arguments types (in the same order as args-names). If not specified, it is detected automatically
1145 @item @var{object-ptr}
1146 A foreign pointer to newly created instance
1149 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}.
1153 (g-object-call-constructor "GtkButton" '("label" "use-underline") '("Hello" t) '("gchararray" "gboolean"))
1155 #.(SB-SYS:INT-SAP #X006D8900)
1157 (g-object-call-get-property * "label")
1161 (g-object-call-get-property ** "use-underline")
1166 @node g-type-from-object
1167 @section g-type-from-object
1169 @Function g-type-from-object
1171 (g-type-from-object object-ptr) @result{} type
1175 @item @var{object-ptr}
1176 A foreign pointer to a GObject instance
1181 Returns the type of an object by a pointer to its instance
1185 (g-type-from-object (g-object-call-constructor "GtkButton" nil nil))
1190 @node g-object-call-get-property
1191 @section g-object-call-get-property
1193 @Function g-object-call-get-property
1195 (g-object-call-get-property object-ptr property-name &optional property-type) @result{} property-value
1199 @item @var{object-ptr}
1200 A foreign pointer to a GObject instance
1201 @item @var{property-name}
1202 A string naming the property
1203 @item @var{property-type}
1204 Optional GType designator specifying the type of a property
1205 @item @var{property-value}
1206 The value of a property
1209 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.
1213 (g-object-call-constructor "GtkButton" '("label" "use-underline") '("Hello" t) '("gchararray" "gboolean"))
1215 #.(SB-SYS:INT-SAP #X006D8900)
1217 (g-object-call-get-property * "label")
1221 (g-object-call-get-property ** "use-underline")
1226 @node g-object-call-set-property
1227 @section g-object-call-set-property
1229 @Function g-object-call-set-property
1231 (g-object-call-set-property object-ptr property-name new-value &optional property-type)
1235 @item @var{object-ptr}
1236 A foreign pointer to a GObject instance
1237 @item @var{property-name}
1238 A string naming the property
1239 @item @var{new-value}
1240 A new value of a property
1241 @item @var{property-type}
1242 Optional GType designator specifying the type of a property
1245 Sets the property value of property @code{property-name} of object @code{object-ptr} to @code{new-value}.
1249 (g-object-call-constructor "GtkButton" nil nil)
1251 #.(SB-SYS:INT-SAP #X006D8B40)
1253 (g-object-call-set-property * "label" "Hello")
1257 (g-object-call-get-property ** "label")
1262 @node GObject high-level
1263 @chapter GObject high-level
1266 * GObject metaclass::
1269 * GObject foreign class::
1272 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):
1274 @item objects are created with @code{make-instance}
1275 @item properties are used as regular slots
1278 GObjects are reference counted, and CL-GTK2-GOBJECT manages its own reference to GObjects. This enables to have transparent garbage collection of unreferenced GObjects.
1280 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.
1282 Example GObject class of definition:
1284 (defclass dialog (gtk-window atk-implementor-iface buildable)
1285 ((has-separator :accessor dialog-has-separator
1286 :initarg :has-separator
1287 :allocation :gobject-property
1288 :g-property-type "gboolean"
1289 :g-property-name "has-separator"))
1290 (:metaclass gobject-class)
1291 (:g-type-name . "GtkDialog")
1292 (:g-type-initializer . "gtk_dialog_get_type"))
1295 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.
1297 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.
1299 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).
1306 A base class for all GObject classes.
1308 @Accessor pointer g-object
1310 An accessor that accesses the foreign pointer to object.
1312 @node GObject metaclass
1313 @section GObject metaclass
1315 See MOP for information what metaclass is and why is it useful.
1317 GObject metaclass @code{gobject-class} bridges two object systems: GObject and CLOS.
1319 Classes that correspond to GObject classes are instances of this class.
1321 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}.
1323 This class has the following slots:
1325 @item @var{g-type-name} (accessor @code{gobject-class-g-type-name}, initarg @code{:g-type-name})
1327 Specifies the name of GObject class
1328 @item @var{g-type-initializer} (accessor @code{gobject-class-g-type-initializer}, initarg @code{:g-type-initializer})
1330 Name of type initializer function. This function initializes the class and returns its GType. Typically it is named @code{class_get_type}.
1331 @item @var{interface-p} (accessor @code{gobject-class-interface-p}, initarg @code{:interface-p})
1333 A boolean specifying whether this CLOS class corresponds to GInterface.
1336 This metaclass defines the GObject classes.
1338 Slots which have @code{:allocation} of @code{:gobject-property} are mapped to GObject properties. Such slots have following attributes:
1340 @item @var{:g-property-type}
1342 A string naming GType of property
1343 @item @var{:g-property-name}
1345 A name of a property
1348 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:
1350 @item @var{:g-property-type}
1351 A CFFI foreign type of property
1352 @item @var{:g-getter}
1353 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)}.
1354 @item @var{:g-setter}
1355 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))}.
1358 Initargs of a slot are used to construct the GObject class.
1362 (defclass container (widget atk-implementor-iface buildable)
1363 ((border-width :allocation :gobject-property
1364 :g-property-type "guint"
1365 :accessor container-border-width
1366 :initarg :border-width
1367 :g-property-name "border-width")
1368 (resize-mode :allocation :gobject-property
1369 :g-property-type "GtkResizeMode"
1370 :accessor container-resize-mode
1371 :initarg :resize-mode
1372 :g-property-name "resize-mode")
1373 (child :allocation :gobject-property
1374 :g-property-type "GtkWidget"
1375 :accessor container-child
1377 :g-property-name "child")
1378 (focus-child :allocation :gobject-fn
1379 :g-property-type g-object
1380 :accessor container-focus-child
1381 :initarg :focus-child
1382 :g-getter "gtk_container_get_focus_child"
1383 :g-setter "gtk_container_set_focus_child")
1384 (focus-vadjustment :allocation :gobject-fn
1385 :g-property-type (g-object adjustment)
1386 :accessor container-focus-vadjustment
1387 :initarg :focus-vadjustment
1388 :g-getter "gtk_container_get_focus_vadjustment"
1389 :g-setter "gtk_container_set_focus_vadjustment")
1390 (focus-hadjustment :allocation :gobject-fn
1391 :g-property-type (g-object adjustment)
1392 :accessor container-focus-hadjustment
1393 :initarg :focus-hadjustment
1394 :g-getter "gtk_container_get_focus_hadjustment"
1395 :g-setter "gtk_container_set_focus_hadjustment"))
1396 (:metaclass gobject-class)
1397 (:g-type-name . "GtkContainer")
1398 (:g-type-initializer . "gtk_container_get_type"))
1400 (note the dot in @code{(:g-type-name . "GtkContainer")} and in @code{(:g-type-initializer . "gtk_container_get_type")}. It should be present)
1403 @section Using objects
1404 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.
1408 (make-instance 'gtk:dialog :has-separator t)
1410 #<GTK:DIALOG @{10036C5A71@}>
1412 (defvar *d* (make-instance 'gtk:dialog :has-separator t))
1416 (gtk:dialog-has-separator *d*)
1420 (setf (gtk:dialog-has-separator *d*) nil)
1424 (gtk:dialog-has-separator *d*)
1432 To connect handler to a signal, @code{connect-signal} function is used.
1434 @Function connect-signals
1436 (connect-signal object signal handler &key after)
1441 An instance of GObject object
1447 A boolean specifying whether the handler should be called after the default handler
1450 Connects the @code{handler} to signal @code{signal} on object @code{object}. Signature of @code{handler} should comply with signature of a signal. @code{handler} will be called with arguments of type specified by signal with the object (on which the signal was emitted) prepended to them and it should return the value of the signal's return type.
1454 (defvar *d* (make-instance 'gtk:dialog))
1460 #<GTK:DIALOG @{1002D866F1@}>
1462 (parse-signal-name "GtkDialog" "response")
1464 #<Signal [#86] void GtkDialog.response(gint) [RUN-LAST]>
1466 (connect-signal *d* "response" (lambda (dialog response-value) (print dialog) (print response-value)))
1468 (emit-signal *d* "response" 14)
1471 #<GTK:DIALOG @{1002D866F1@}>
1475 Function @code{emit-signal} is used to emit signals on objects.
1477 @code{(emit-signal object signal-name &rest args) @result{} return-value}
1481 An object on which the signal should be emitted
1482 @item @var{signal-name}
1483 A string naming the signal
1485 Arguments for a signal
1486 @item @var{return-value}
1487 Return value of a signal
1490 Emits the signal and calls all handlers of the signal. If signal returns a value, it is returned from @code{emit-signal}.
1494 (defvar *d* (make-instance 'gtk:dialog))
1500 #<GTK:DIALOG @{1002D866F1@}>
1502 (parse-signal-name "GtkDialog" "response")
1504 #<Signal [#86] void GtkDialog.response(gint) [RUN-LAST]>
1506 (connect-signal *d* "response" (lambda (dialog response-value) (print dialog) (print response-value)))
1508 (emit-signal *d* "response" 14)
1511 #<GTK:DIALOG @{1002D866F1@}>
1515 @node GObject foreign class
1516 @section GObject foreign class
1518 To enable passing GObject instance between Lisp code and foreign code, @code{g-object} foreign type is introduced.
1520 This type has the following syntax:
1521 @code{(g-object &optional type)} or @code{g-object}.
1523 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.
1525 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.
1527 This defines the function that may be called with instances of types @code{container} and @code{widget}:
1529 (defcfun (container-add "gtk_container_add") :void
1530 (container (g-object container))
1531 (widget (g-object widget)))
1533 (let ((window (make-instance 'gtk-window))
1534 (widget (make-instance 'button)))
1535 (container-add window widget))
1537 (@code{gtk-window} is a subclass of @code{container}; @code{button} is a subclass of @code{widget})
1539 This defines the function that returns an instance of GObject class:
1541 (defcfun (bin-child "gtk_bin_get_child") (g-object widget)
1542 (bin (g-object bin)))
1544 (let ((window (make-instance 'gtk-window))
1545 (widget (make-instance 'button)))
1546 (container-add window widget)
1549 #<GTK:BUTTON @{1002DE74B1@}>
1552 @node Creating GObjects classes and implementing GInterfaces
1553 @chapter Creating GObjects classes and implementing GInterfaces
1557 * register-object-type-implementation::
1560 Creating GObject classes from Lisp is the most complex part of GObject binding.
1562 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).
1564 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.
1566 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).
1568 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.
1570 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.
1573 @section define-vtable
1575 @Macro define-vtable
1577 (define-vtable (type-name cstruct-name)
1580 item ::= (name callback-name return-type &rest arg*)
1581 item ::= (:skip cffi-structure-item)
1582 arg ::= (arg-name arg-type)
1586 @item @var{type-name}
1587 A string naming the GObject type of interface
1588 @item @var{cstruct-name}
1589 A name for a generated CFFI foreign structure
1591 A name for implementation generic function
1592 @item @var{callback-name}
1593 A name for generated callback function
1594 @item @var{return-type}
1595 A CFFI specifier for foreign function return type
1596 @item @var{arg-name}
1597 A symbol naming the argument of interface method
1598 @item @var{arg-type}
1599 A CFFI specifier for foreign function argument type
1602 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.
1606 (define-vtable ("GtkTreeModel" c-gtk-tree-model)
1607 (:skip parent-instance g-type-interface)
1609 (:skip tree-model-row-changed :pointer)
1610 (:skip tree-model-row-inserted :pointer)
1611 (:skip tree-model-row-has-child-toggled :pointer)
1612 (:skip tree-model-row-deleted :pointer)
1613 (:skip tree-model-rows-reordered :pointer)
1615 (tree-model-get-flags-impl tree-model-get-flags-cb
1617 (tree-model g-object))
1618 (tree-model-get-n-columns-impl tree-model-get-n-columns-cb
1620 (tree-model g-object))
1621 (tree-model-get-column-type-impl tree-model-get-column-type-cb
1623 (tree-model g-object) (index :int))
1624 (tree-model-get-iter-impl tree-model-get-iter-cb
1626 (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (path (g-boxed-foreign tree-path)))
1627 (tree-model-get-path-impl tree-model-get-path-cb
1628 (g-boxed-foreign tree-path :return)
1629 (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
1630 (tree-model-get-value-impl tree-model-get-value-cb
1632 (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (n :int) (value (:pointer g-value)))
1633 (tree-model-iter-next-impl tree-model-iter-next-cb
1635 (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
1636 (tree-model-iter-children-impl tree-model-iter-children-cb
1638 (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (parent (g-boxed-foreign tree-iter)))
1639 (tree-model-iter-has-child-impl tree-model-iter-has-child-cb
1641 (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
1642 (tree-model-iter-n-children-impl tree-model-iter-n-children-cb
1644 (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
1645 (tree-model-iter-nth-child-impl tree-model-iter-nth-child-cb
1647 (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (parent (g-boxed-foreign tree-iter)) (n :int))
1648 (tree-model-iter-parent-impl tree-model-iter-parent-cb
1650 (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (child (g-boxed-foreign tree-iter)))
1651 (tree-model-ref-node-impl tree-model-ref-node-cb
1653 (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
1654 (tree-model-unref-node-impl tree-model-unref-node-cb
1656 (tree-model g-object) (iter (g-boxed-foreign tree-iter))))
1659 @node register-object-type-implementation
1660 @section register-object-type-implementation
1662 @Macro register-object-type-implementation
1664 (register-object-type-implementation name class parent interfaces properties)
1669 A string naming the new GObject class.
1671 A class name of corresponding CLOS class. It should be inherited from @code{g-object} or its descendants.
1673 A string naming the GObject superclass
1674 @item @var{interfaces}
1675 A list of names of interfaces that this class implements.
1676 @item @var{properties}
1677 A list of properties that this class provides.
1678 Each property is defined as
1680 property ::= (property-name property-type accessor property-get-fn property-set-fn)
1684 A macro that creates a new GObject type and registers the Lisp implementation for it.
1688 (register-object-type-implementation "LispArrayListStore" array-list-store "GObject" ("GtkTreeModel") nil)
1694 * define-g-boxed-cstruct::
1695 * define-g-boxed-variant-cstruct::
1696 * define-g-boxed-opaque::
1698 * define-boxed-opaque-accessor::
1699 * boxed-related-symbols::
1700 * GBoxed foreign type::
1703 GObject manual defines this type in the following way:
1705 ``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.
1707 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.''
1709 Naturally, it is hard to provide support for ``arbitrary C structures''. We support a few useful use cases of GBoxed types:
1711 @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.
1712 @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).
1714 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.
1715 @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.
1718 @node define-g-boxed-cstruct
1719 @section define-g-boxed-cstruct
1720 @Macro define-g-boxed-cstruct
1722 (define-g-boxed-cstruct name g-type-name
1725 slot ::= (slot-name slot-type &key count initform inline)
1730 A symbol naming the type being defined
1731 @item @var{g-type-name}
1732 A string specifying the GType name of this GBoxed. This may be nil if this type is not registered with GObject type system.
1733 @item @var{slot-name}
1734 A symbol naming the slot of a structure
1735 @item @var{slot-type}
1736 A foreign type of a slot
1738 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.
1739 @item @var{initform}
1740 A form that is the initform of Lisp structure slot
1742 A boolean. If it is true, then the slot contains GBoxed structure whose name is @code{slot-type}.
1745 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.
1749 (define-g-boxed-cstruct rectangle "GdkRectangle"
1750 (left :int :initform 0)
1751 (top :int :initform 0)
1752 (width :int :initform 0)
1753 (height :int :initform 0))
1755 (define-g-boxed-cstruct point nil
1756 (x :int :initform 0)
1757 (y :int :initform 0))
1759 (define-g-boxed-cstruct vector4 nil
1760 (coords :double :count 4 :initform (vector 0d0 0d0 0d0 0d0)))
1762 (define-g-boxed-cstruct segment nil
1763 (a point :inline t :initform (make-point))
1764 (b point :inline t :initform (make-point)))
1767 @node define-g-boxed-variant-cstruct
1768 @section define-g-boxed-variant-cstruct
1770 @Macro define-g-boxed-variant-cstruct
1772 (define-g-boxed-variant-cstruct name g-type-name
1773 &body slot-or-variant-specification*)
1775 slot ::= (slot-name slot-type &key count initform inline)
1776 variant-specification ::= (:variant dispatching-slot-name structure-variant*)
1777 structure-variant ::= (dispatching-slot-values structure-name &body slot-or-variant-specification*)
1782 A symbol naming the type being defined
1783 @item @var{g-type-name}
1784 A string specifying the GType name of this GBoxed. This may be nil if this type is not registered with GObject type system.
1785 @item @var{slot-name}
1786 A symbol naming the slot of a structure
1787 @item @var{slot-type}
1788 A foreign type of a slot
1790 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.
1791 @item @var{initform}
1792 A form that is the initform of Lisp structure slot
1794 A boolean. If it is true, then the slot contains GBoxed structure whose name is @code{slot-type}.
1795 @item @var{dispatching-slot-name}
1796 A name of the dispatching slot
1797 @item @var{dispatching-slot-values}
1798 A single value or a list of values.
1799 @item @var{structure-name}
1800 A symbol naming the structure
1803 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.
1805 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.
1807 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).
1809 For example, for these structures this assumption holds:
1815 GdkEventButton button;
1818 struct GdkEventKey @{
1819 GdkEventType type; //
1820 GdkWindow *window; // These fields are common
1821 gint8 send_event; //
1828 struct GdkEventButton @{
1829 GdkEventType type; //
1830 GdkWindow *window; // These fields are common
1831 gint8 send_event; //
1841 (define-g-boxed-variant-cstruct event "GdkEvent"
1843 (window (g-object gdk-window))
1844 (send-event (:boolean :int8))
1846 ((:key-press :key-release) event-key
1848 (state modifier-type)
1851 (string (:string :free-from-foreign nil
1852 :free-to-foreign nil))
1853 (hardware-keycode :uint16)
1855 (is-modifier :uint))
1856 ((:button-press :2button-press :3button-press
1857 :button-release) event-button
1861 (axes (fixed-array :double 2))
1864 (device (g-object device))
1870 This code defines following structures:
1873 type window send-event)
1875 (defstruct (event-key (:include event))
1876 time state keyval length string
1877 hardware-keycode group is-modifier)
1879 (defstruct (event-button (:include event))
1880 time x y axes state button device x-root y-root)
1883 @node define-g-boxed-opaque
1884 @section define-g-boxed-opaque
1886 @Macro define-g-boxed-opaque
1888 (define-g-boxed-opaque name g-type-name &key alloc)
1893 A name of boxed type
1894 @item @var{g-type-name}
1895 A string; the name of GType
1897 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.
1900 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.
1904 (defcfun gtk-tree-path-new :pointer)
1906 (define-g-boxed-opaque tree-path "GtkTreePath"
1907 :alloc (gtk-tree-path-new))
1909 @node g-boxed-opaque
1910 @section g-boxed-opaque
1911 @Class g-boxed-opaque
1913 (defclass g-boxed-opaque ()
1914 ((pointer :initarg :pointer
1916 :accessor g-boxed-opaque-pointer)))
1919 A class that is the base class for wrappers of opaque structures. Contains a pointer to the wrapped opaque structure.
1921 Accessor function @code{g-boxed-opaque-pointer} is used to access the pointer. Pointer should not be modified directly, only read.
1922 @node define-boxed-opaque-accessor
1923 @section define-boxed-opaque-accessor
1924 @Macro define-boxed-opaque-accessor
1926 (define-boxed-opaque-accessor
1927 boxed-name accessor-name &key type reader writer)
1931 @item @var{boxed-name}
1932 A symbol naming the opaque structure type for which the accessor is being defined
1933 @item @var{accessor-name}
1934 A symbol naming the accessor
1936 A CFFI foreign type of the property for which the accessor is being defined
1938 A @code{NIL} or a string or a function designator for the reader function
1940 A @code{NIL} or a string or a function designator for the writer function
1943 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}.
1945 @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.
1947 @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.
1951 (define-boxed-opaque-accessor text-iter text-iter-child-anchor
1952 :reader "gtk_text_iter_get_child_anchor" :type (g-object text-child-anchor))
1954 (define-boxed-opaque-accessor text-iter text-iter-tags
1955 :reader "gtk_text_iter_get_tags" :type (gslist (g-object text-tag) :free-from-foreign t))
1957 (define-boxed-opaque-accessor text-iter text-iter-chars-in-line
1958 :reader "gtk_text_iter_get_chars_in_line" :type :int)
1960 (define-boxed-opaque-accessor text-iter text-iter-offset
1961 :reader "gtk_text_iter_get_offset" :writer "gtk_text_iter_set_offset" :type :int)
1964 @node boxed-related-symbols
1965 @section boxed-related-symbols
1967 @Function boxed-related-symbols
1969 (boxed-related-symbols name) @result{} symbols
1974 A symbol naming the boxed type
1979 This function returns the list of symbols that are related to GBoxed type @var{name}. These symbols are returned:
1981 @item name of boxed type
1982 @item name of all accessors of cstruct and variant-cstruct boxed types
1983 @item names of all variants of variant-cstruct boxed types
1984 @item names of constructors and copiers of cstruct and variant-cstruct boxed-types
1987 Typical usage of this function is to export the symbols related to given boxed type.
1991 (define-g-boxed-cstruct rectangle "GdkRectangle"
1992 (x :int :initform 0)
1993 (y :int :initform 0)
1994 (width :int :initform 0)
1995 (height :int :initform 0))
1997 (boxed-related-symbols 'rectangle)
1999 (RECTANGLE MAKE-RECTANGLE COPY-RECTANGLE RECTANGLE-X RECTANGLE-Y
2000 RECTANGLE-WIDTH RECTANGLE-HEIGHT)
2003 @node GBoxed foreign type
2004 @section GBoxed foreign type
2006 @ForeignType g-boxed-foreign
2008 (g-boxed-foreign name &rest option*)
2017 Option of foreign type
2018 @item @code{:return}
2019 An option that identifies the foreign type which is used at return position (as foreign function return type or as a callback return type)
2022 @code{g-boxed-foreign} type deals with marshaling data between Lisp code and foreign code. The marshaling follows the following principles:
2024 @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)
2025 @item Lisp objects should not be manually managed and are properly reclaimed by garbage collector, leaving no memory leaks
2026 @item Foreign code can change objects that are passed to them as arguments. This is required for functions that operate by modifying their arguments
2027 @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
2030 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.
2032 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.
2036 (define-vtable ("GtkTreeModel" c-gtk-tree-model)
2038 (tree-model-get-path-impl tree-model-get-path-cb
2039 (g-boxed-foreign tree-path :return) (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
2040 (tree-model-get-value-impl tree-model-get-value-cb
2041 :void (tree-model g-object) (iter (g-boxed-foreign tree-iter)) (n :int) (value (:pointer g-value)))
2042 (tree-model-iter-next-impl tree-model-iter-next-cb
2043 :boolean (tree-model g-object) (iter (g-boxed-foreign tree-iter)))
2046 (defcfun gtk-text-iter-forward-search :boolean
2047 (iter (g-boxed-foreign text-iter))
2048 (str (:string :free-to-foreign t))
2049 (flags text-search-flags)
2050 (match-start (g-boxed-foreign text-iter))
2051 (match-end (g-boxed-foreign text-iter))
2052 (limit (g-boxed-foreign text-iter)))
2055 @node Generating type definitions by introspection
2056 @chapter Generating type definitions by introspection
2058 * define-g-object-class::
2059 * define-g-interface::
2062 * get-g-enum-definition::
2063 * get-g-flags-definition::
2064 * get-g-interface-definition::
2065 * get-g-class-definition::
2066 * Specifying additional properties for CLOS classes::
2067 * Generating names for CLOS classes and accessors::
2068 * generate-types-hierarchy-to-file::
2071 CL-GTK2-GOBJECT includes facilities for automatically generating parts of bindings for libraries that use GObject type system.
2073 @node define-g-object-class
2074 @section define-g-object-class
2076 @Macro define-g-object-class
2078 (define-g-object-class g-type-name name
2079 (&key (superclass 'g-object) (export t) interfaces type-initializer)
2082 property ::= (name accessor gname type readable writable)
2083 property ::= (:cffi name acessor type reader writer)
2086 Parameters of @code{define-g-object-class}
2088 @item @var{superclass}
2089 A symbol naming the superclass of this class
2091 Whether to export the name of the class and names of autogenerated properties names from the current package.
2092 @item @var{interfaces}
2093 A list of interfaces the this class implements
2094 @item @var{type-initializer}
2095 A string naming the type initiliazer function. It is usually named @code{class_get_type}.
2096 @item @var{properties}
2097 A list of slots of a class
2100 Parameters of @code{property}:
2103 A symbol naming the slot
2104 @item @var{accessor}
2105 A symbol naming the accessor function for this slot
2107 A string naming the property of GObject
2109 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)
2110 @item @var{readable}
2111 A boolean specifying whether the slot can be read
2112 @item @var{writable}
2113 A boolean specifying whether the slot can be assigned to
2115 A string or a symbol naming getter function. See description of @code{gobject-class} metaclass for information.
2117 A string or a symbol naming setter function. See description of @code{gobject-class} metaclass for information.
2120 Macro that expands to @code{defclass} for specified class. Additionally, if @code{export} is true, it exports accessor names and name of a class.
2124 (define-g-object-class "GtkContainer" container
2125 (:superclass widget :export t :interfaces
2126 ("AtkImplementorIface" "GtkBuildable")
2127 :type-initializer "gtk_container_get_type")
2128 ((border-width container-border-width "border-width" "guint" t t)
2129 (resize-mode container-resize-mode "resize-mode" "GtkResizeMode" t t)
2130 (child container-child "child" "GtkWidget" nil t)
2131 (:cffi focus-child container-focus-child g-object "gtk_container_get_focus_child" "gtk_container_set_focus_child")
2132 (:cffi focus-vadjustment container-focus-vadjustment (g-object adjustment) "gtk_container_get_focus_vadjustment" "gtk_container_set_focus_vadjustment")
2133 (:cffi focus-hadjustment container-focus-hadjustment (g-object adjustment) "gtk_container_get_focus_hadjustment" "gtk_container_set_focus_hadjustment")))
2136 @node define-g-interface
2137 @section define-g-interface
2139 @Macro define-g-interface
2141 (define-g-interface g-type-name name (&key (export t) type-initializer)
2144 property ::= (name accessor gname type readable writable)
2145 property ::= (:cffi name acessor type reader writer)
2148 Parameters of @code{define-g-interface}
2151 Whether to export the name of the interface and names of autogenerated properties names from the current package.
2152 @item @var{type-initializer}
2153 A string naming the type initiliazer function. It is usually named @code{interface_get_type}.
2154 @item @var{properties}
2155 A list of slots of a interface
2158 Parameters of @code{property}:
2161 A symbol naming the slot
2162 @item @var{accessor}
2163 A symbol naming the accessor function for this slot
2165 A string naming the property of GObject
2167 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)
2168 @item @var{readable}
2169 A boolean specifying whether the slot can be read
2170 @item @var{writable}
2171 A boolean specifying whether the slot can be assigned to
2173 A string or a symbol naming getter function. See description of @code{gobject-class} metaclass for information.
2175 A string or a symbol naming setter function. See description of @code{gobject-class} metaclass for information.
2178 Macro that expands to @code{defclass} for specified interface. Additionally, if @code{export} is true, it exports accessor names and name of a interface.
2182 (define-g-interface "GtkFileChooser" file-chooser
2183 (:export t :type-initializer "gtk_file_chooser_get_type")
2184 (do-overwrite-confirmation file-chooser-do-overwrite-confirmation "do-overwrite-confirmation" "gboolean" t t)
2185 (select-multiple file-chooser-select-multiple "select-multiple" "gboolean" t t)
2186 (filter file-chooser-filter "filter" "GtkFileFilter" t t)
2187 (local-only file-chooser-local-only "local-only" "gboolean" t t)
2188 (preview-widget file-chooser-preview-widget "preview-widget" "GtkWidget" t t)
2189 (use-preview-label file-chooser-use-preview-label "use-preview-label" "gboolean" t t)
2190 (preview-widget-active file-chooser-preview-widget-active "preview-widget-active" "gboolean" t t)
2191 (file-system-backend file-chooser-file-system-backend "file-system-backend" "gchararray" nil nil)
2192 (extra-widget file-chooser-extra-widget "extra-widget" "GtkWidget" t t)
2193 (show-hidden file-chooser-show-hidden "show-hidden" "gboolean" t t)
2194 (action file-chooser-action "action" "GtkFileChooserAction" t t)
2195 (:cffi current-name file-chooser-current-name
2196 (:string :free-to-foreign t :encoding :utf-8) nil "gtk_file_chooser_set_current_name")
2197 (:cffi filename file-chooser-filename
2198 (g-string :free-from-foreign t :free-to-foreign t)
2199 "gtk_file_chooser_get_filename" "gtk_file_chooser_set_filename")
2200 (:cffi current-folder file-chooser-current-folder
2201 (g-string :free-from-foreign t :free-to-foreign t)
2202 "gtk_file_chooser_get_current_folder"
2203 "gtk_file_chooser_set_current_folder")
2204 (:cffi uri file-chooser-uri
2205 (g-string :free-from-foreign t :free-to-foreign t)
2206 "gtk_file_chooser_get_uri" "gtk_file_chooser_set_uri")
2207 (:cffi current-folder-uri file-chooser-current-folder-uri
2208 (g-string :free-from-foreign t :free-to-foreign t)
2209 "gtk_file_chooser_get_current_folder_uri"
2210 "gtk_file_chooser_set_current_folder_uri")
2211 (:cffi preview-filename file-chooser-preview-filename
2212 (g-string :free-from-foreign t :free-to-foreign t)
2213 "gtk_file_chooser_get_preview_filename" nil)
2214 (:cffi preview-uri file-chooser-preview-uri
2215 (g-string :free-from-foreign t :free-to-foreign t)
2216 "gtk_file_chooser_get_preview_uri" nil))
2220 @section define-g-enum
2222 @Macro define-g-enum
2224 (define-g-enum g-name name (&key (export t) type-initializer) &body value*)
2227 value ::= (:keyword integer)
2232 A string naming the GEnum type
2234 A symbol naming the CFFI enumeration type
2236 A boolean indicating whether to export @code{name}
2237 @item @var{type-initializer}
2238 A string naming the foreign type initializer function. Usually named @code{enum_get_type}.
2241 Macro that defines CFFI enumeration, registers it with GValue, and calls the type initializer.
2245 (define-g-enum "GtkTextDirection" text-direction
2246 (:export t :type-initializer "gtk_text_direction_get_type")
2247 (:none 0) (:ltr 1) (:rtl 2))
2249 (define-g-enum "GtkSizeGroupMode" size-group-mode
2250 (:export t :type-initializer "gtk_size_group_mode_get_type")
2251 :none :horizontal :vertical :both)
2254 @node define-g-flags
2255 @section define-g-flags
2257 @Macro define-g-flags
2259 (define-g-flags g-name name (&key (export t) type-initializer) &body value*)
2262 value ::= (:keyword integer)
2267 A string naming the GFlags type
2269 A symbol naming the CFFI flags type
2271 A boolean indicating whether to export @code{name}
2272 @item @var{type-initializer}
2273 A string naming the foreign type initializer function. Usually named @code{flags_get_type}.
2276 Macro that defines CFFI bitfield, registers it with GValue, and calls the type initializer.
2280 (define-g-flags "GtkAttachOptions" attach-options
2281 (:export t :type-initializer "gtk_attach_options_get_type")
2282 (:expand 1) (:shrink 2) (:fill 4))
2284 (define-g-flags "GtkButtonAction" button-action
2285 (:export t :type-initializer "gtk_button_action_get_type")
2286 :ignored :selects :drags :expands)
2289 @node get-g-enum-definition
2290 @section get-g-enum-definition
2292 @Function get-g-enum-definition
2294 (get-g-enum-definition type &optional lisp-name-package) @result{} definition
2299 A string naming the GEnum type
2300 @item @var{lisp-name-package}
2301 A package that will be used as a package for generated symbols (enum name). If not specified, symbols are interned in @code{*package*}
2302 @item @var{definition}
2303 A Lisp form that when evaluated defines the GEnum.
2306 Uses GObject introspection capabilities to automatically produce the definition of GEnum. The foreign library that defines the enum type should be loaded.
2308 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
2312 (get-g-enum-definition "GtkDirectionType")
2314 (DEFINE-G-ENUM "GtkDirectionType" GTK-DIRECTION-TYPE
2315 (:EXPORT T :TYPE-INITIALIZER "gtk_direction_type_get_type")
2316 (:TAB-FORWARD 0) (:TAB-BACKWARD 1) (:UP 2) (:DOWN 3) (:LEFT 4)
2320 @node get-g-flags-definition
2321 @section get-g-flags-definition
2323 @Function get-g-flags-definition
2325 (get-g-flags-definition type &optional lisp-name-package) @result{} definition
2330 A string naming the GFlags type
2331 @item @var{lisp-name-package}
2332 A package that will be used as a package for generated symbols (flags name). If not specified, symbols are interned in @code{*package*}
2333 @item @var{definition}
2334 A Lisp form that when evaluated defines the GFlags.
2337 Uses GObject introspection capabilities to automatically produce the definition of GFlags. The foreign library that defines the flags type should be loaded.
2339 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
2343 (get-g-flags-definition "GtkCalendarDisplayOptions")
2345 (DEFINE-G-FLAGS "GtkCalendarDisplayOptions" GTK-CALENDAR-DISPLAY-OPTIONS
2346 (:EXPORT T :TYPE-INITIALIZER
2347 "gtk_calendar_display_options_get_type")
2348 (:SHOW-HEADING 1) (:SHOW-DAY-NAMES 2) (:NO-MONTH-CHANGE 4)
2349 (:SHOW-WEEK-NUMBERS 8) (:WEEK-START-MONDAY 16)
2353 @node get-g-interface-definition
2354 @section get-g-interface-definition
2356 @Function get-g-interface-definition
2358 get-g-interface-definition type &optional lisp-name-package) @result{} definition
2363 A string naming the GInterface type
2364 @item @var{lisp-name-package}
2365 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*}
2366 @item @var{definition}
2367 A Lisp form that when evaluated defines the GInterface.
2370 Uses GObject introspection capabilities to automatically produce the definition of GInterface. The foreign library that defines the GInterface type should be loaded.
2372 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
2376 (get-g-interface-definition "GtkActivatable")
2378 (DEFINE-G-INTERFACE "GtkActivatable" GTK-ACTIVATABLE
2379 (:EXPORT T :TYPE-INITIALIZER "gtk_activatable_get_type")
2380 (USE-ACTION-APPEARANCE
2381 GTK-ACTIVATABLE-USE-ACTION-APPEARANCE
2382 "use-action-appearance" "gboolean" T T)
2383 (RELATED-ACTION GTK-ACTIVATABLE-RELATED-ACTION
2384 "related-action" "GtkAction" T T))
2387 @node get-g-class-definition
2388 @section get-g-class-definition
2390 @Function get-g-class-definition
2392 (get-g-class-definition type &optional lisp-name-package) @result{} definition
2397 A string naming the GObject type
2398 @item @var{lisp-name-package}
2399 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*}
2400 @item @var{definition}
2401 A Lisp form that when evaluated defines the GObject.
2404 Uses GObject introspection capabilities to automatically produce the definition of GClass. The foreign library that defines the GObject type should be loaded.
2406 See @ref{Generating names for CLOS classes and accessors} for information about used method for generating names.
2410 (get-g-class-definition "GtkButton")
2412 (DEFINE-G-OBJECT-CLASS "GtkButton" GTK-BUTTON
2413 (:SUPERCLASS GTK-BIN :EXPORT T :INTERFACES
2414 ("AtkImplementorIface" "GtkActivatable" "GtkBuildable")
2415 :TYPE-INITIALIZER "gtk_button_get_type")
2416 ((LABEL GTK-BUTTON-LABEL "label" "gchararray" T T)
2417 (IMAGE GTK-BUTTON-IMAGE "image" "GtkWidget" T T)
2418 (RELIEF GTK-BUTTON-RELIEF "relief" "GtkReliefStyle" T
2420 (USE-UNDERLINE GTK-BUTTON-USE-UNDERLINE "use-underline"
2422 (USE-STOCK GTK-BUTTON-USE-STOCK "use-stock" "gboolean"
2424 (FOCUS-ON-CLICK GTK-BUTTON-FOCUS-ON-CLICK
2425 "focus-on-click" "gboolean" T T)
2426 (XALIGN GTK-BUTTON-XALIGN "xalign" "gfloat" T T)
2427 (YALIGN GTK-BUTTON-YALIGN "yalign" "gfloat" T T)
2428 (IMAGE-POSITION GTK-BUTTON-IMAGE-POSITION
2429 "image-position" "GtkPositionType" T T)))
2432 @node Specifying additional properties for CLOS classes
2433 @section Specifying additional properties for CLOS classes
2435 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.
2437 Definitions generator uses variable @code{*additional-properties*} to get this information.
2439 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).
2441 To supply the bindings generator with this information, bind @code{*additional-properties*} to such list when the generator is run.
2445 (("GtkTreeViewColumn"
2446 (:cffi gtk::tree-view
2447 gtk::tree-view-column-tree-view
2448 g-object "gtk_tree_view_column_get_tree_view" nil)
2449 (:cffi gtk::sort-column-id
2450 gtk::tree-view-column-sort-column-id
2451 :int "gtk_tree_view_column_get_sort_column_id" "gtk_tree_view_column_set_sort_column_id")
2452 (:cffi gtk::cell-renderers
2453 gtk::tree-view-column-cell-renderers
2454 (glist g-object :free-from-foreign t) "gtk_tree_view_column_get_cell_renderers" nil))
2457 gtk::tree-selection-mode
2458 gtk::selection-mode "gtk_tree_selection_get_mode" "gtk_tree_selection_set_mode")
2459 (:cffi gtk::select-function
2460 gtk::tree-selection-select-function
2461 nil gtk::tree-selection-get-selection-function gtk::tree-selection-set-select-function)))
2464 @node Generating names for CLOS classes and accessors
2465 @section Generating names for CLOS classes and accessors
2467 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).
2469 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.
2471 Name generation affected by following variables:
2473 @item @var{*strip-prefix*}
2474 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}.
2475 @item @var{*lisp-name-exceptions*}
2476 A plist mapping from strings (type names) to symbols (class names) that have special name processing.
2479 `(("GObject" gobject:g-object)
2480 ("GtkObject" ,(intern "GTK-OBJECT" (find-package :gtk)))
2481 ("GInitiallyUnowned" gobject::g-initially-unowned)
2482 ("GtkWindow" ,(intern "GTK-WINDOW" (find-package :gtk)))
2483 ("GtkUIManager" ,(intern "UI-MANAGER" (find-package :gtk)))
2484 ("GtkUIManagerItemType" ,(intern "UI-MANAGER-ITEM-TYPE" (find-package :gtk))))
2488 @node generate-types-hierarchy-to-file
2489 @section generate-types-hierarchy-to-file
2491 @Function generate-types-hierarchy-to-file
2493 (generate-types-hierarchy-to-file file
2495 &key include-referenced
2505 additional-properties)
2510 A string or pathname naming the file, or a stream.
2511 @item @var{root-type}
2512 A GType designator for a root type. All types that inherit from this type will be defined.
2513 @item @var{&key include-referenced}
2514 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
2516 A string naming the prefix that should be removed from the beginning of names
2518 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
2519 @item @var{exceptions}
2520 A plist that maps GType names to their Lisp names.
2521 See @ref{Generating names for CLOS classes and accessors} for more info on exceptions from name generation mechanism
2522 @item @var{prologue}
2523 A string that will be included verbatim in generated code file
2524 @item @var{interfaces}
2525 Additional list of interfaces that will also be included in generation
2527 Additional list of enums that will also be included in generation
2529 Additional list of flags that will also be included in generation
2531 Additional list of object types that will also be included in generation
2532 @item @var{exclusions}
2533 A list of GType names that will be excluded from generation
2534 @item @var{additional-properties}
2535 A plist of properties definitions that will be added to generated classes.
2536 See @ref{Specifying additional properties for CLOS classes} for more information.
2539 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.
2543 (generate-types-hierarchy-to-file
2544 "gtk.generated-classes.lisp"
2546 :include-referenced t
2548 :package (or (find-package :gtk) (make-package :gtk))
2549 :exceptions `(("GObject" gobject:g-object)
2550 ("GtkObject" ,(intern "GTK-OBJECT" (find-package :gtk)))
2551 ("GInitiallyUnowned" gobject::g-initially-unowned)
2552 ("GtkWindow" ,(intern "GTK-WINDOW" (find-package :gtk)))
2553 ("GtkUIManager" ,(intern "UI-MANAGER" (find-package :gtk)))
2554 ("GtkUIManagerItemType" ,(intern "UI-MANAGER-ITEM-TYPE" (find-package :gtk))))
2555 :prologue (format nil "(in-package :gtk)")
2556 :interfaces '("GtkBuildable" "GtkCellEditable" ...)
2557 :objects '("GtkSettings" "GtkRcStyle" ...)
2558 :flags '("GtkTextSearchFlags" "GtkAccelFlags" ...)
2559 :enums '("GtkTextDirection" "GtkSizeGroupMode" ...)
2560 :exclusions '("PangoStretch" "PangoVariant" ...)
2561 :additional-properties
2562 '(("GtkTreeViewColumn"
2565 gtk::tree-view-column-tree-view
2567 "gtk_tree_view_column_get_tree_view"