Guile-GNOME: GObject
********************

This manual is for Guile-GNOME: GObject (version 2.15.93, updated 25 August 2007)

Copyright 2003,2004,2005,2006,2007 Free Software Foundation

     Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation.

(gnome gobject gtype)
*********************

Overview
========

Base support for the GLib type system.

The GLib runtime type system is broken into a number of modules, of which GType is the base. A <gtype> is a named type that has a number of properties. Some types are fundamental and cannot be subclassed, such as integers. Others can form the root of complicated object hierarchies, such as <gobject>.

One can obtain the <gtype> object for a type if you know its name. For example,

       (gtype-from-name "guint64") => #<gtype guint64>

<gtype> objects are low-level constructs. In Scheme, it is more usual to work with GOOPS type objects. Each <gtype> corresponds to one GOOPS object, which may be obtained programmatically using gtype->class.

A more detailed reference on the GLib type system may be had at http://library.gnome.org/devel/gobject/stable/.

Usage
=====

Primitive gtype? type Returns #t if TYPE is a GType and #f if not.

Primitive gtype-is-a? type is_a_type Returns #t if TYPE is a subtype of IS_A_TYPE.

Primitive gtype-basic? type Returns #t if TYPE is a basic type. Basic types have only one possible representation in Scheme. Unless the user means to deal in GValues, values of basic types should be manipulated as Scheme values.

Primitive gtype-classed? type Returns #t if TYPE is a classed type.

Primitive gtype-instantiatable? type Returns #t if TYPE is an instantiatable type.

Primitive gtype-fundamental? type Returns #t if TYPE is a fundamental type and #f if not. This is the same as (eq? type (gtype->fundamental type)), but slightly faster.

Primitive gtype->fundamental type Returns the fundamental type of TYPE (possibly TYPE itself).

Primitive gtype-parent type Returns the parent type of TYPE (possibly TYPE itself).

Primitive gtype-children type Returns the <gtype>'s of TYPE's direct children, as a list.

Primitive gtype-interfaces type Returns the set of <gtype>'s that TYPE implements, as a list.

Primitive gtype-name type Returns the name of TYPE.

Primitive gtype-from-name name Returns the type named NAME, or #f if none exists.

Primitive gtype-from-instance instance Returns the type of INSTANCE, which should be a primitive <%gtype-instance>.

Primitive %gtype-instance-primitive-destroy! instance Release all references that the Scheme wrapper INSTANCE has on the underlying C value, and release pointers associated with the C value that point back to Scheme.

Normally not necessary. Used by the implementations of some instantiatable types that have destroy methods, notably <gtk-object>.

Primitive gtype-instance-primitive->type instance Retrieve the <gtype> object associated with the primitive <%gtype-instance> value, INSTANCE.

Primitive especify-metaclass! class metaclass A terrible hack that takes a class CLASS and sets its metaclass, in-place, to METACLASS. METACLASS must be a subclass of CLASS' existing metaclass.

This method is useful if you want to define a method that on a particular <gtype-class>, such as make-instance. However, it would be cleaner to devise a way of making these ``class methods'' without molesting GOOPS in this way.

Class <gtype-class> The metaclass of all GType classes. Ensures that GType classes have gtype and gtype-class slots, which point to the primitive <gtype> and <%gtype-class> objects that wrap the C values.

Class <gtype-instance-class> The metaclass of all instantiatable GType classes.

Class <gtype-instance> The root class of all instantiatable GType classes. Adds a slot, gtype-instance, to instances. This slot will point to the primitive <%gtype-instance> object that wraps the C value.

gtype->class type If there is already a GOOPS class associated with the GType TYPE, return this class.

Otherwise, create a new GOOPS class and bind it to this type. The created class is an immortal, persistent object which is bound in some magic way to its GType.

gtype-class->type class Returns the <gtype> associated with a <gtype-class>.

Primitive %gtype-lookup-class type Returns the <gtype-class> registered for TYPE, or #f if none has been registered.

Primitive %gtype-bind-to-class class type A low-level procedure to bind the newly-created <gtype-class> CLASS to TYPE. Users should not need to call this function.

Generic gtype-instance:write Generic function, defined so we can define write functions for instances of <gtype-class> in Scheme. A bit of a hack.

 -- Method: gtype-instance:write ( CLASS <gtype-class> ) ( OBJ <%gtype-instance> ) ( FILE <top> )

gruntime-error format-string  .  args Signal a runtime error. The error will be thrown to the key gruntime-error.

class-name->gtype-name class-name Convert the name of a class into a suitable name for a GType. For example:

      (class-name->gtype-name '<foo-bar>) => "FooBar"

gtype:genum

gtype:gflags

gtype:ginterface

gtype:gobject

gtype:gparam

gtype:void

(gnome gobject gvalue)
**********************

Overview
========

GLib supports generic typed values via its GValue module. These values are wrapped in Scheme as instances of <gvalue-class> classes, such as <gint>, <gfloat>, etc.

In most cases, use of <gvalue> are transparent to the Scheme user. Values which can be represented directly as Scheme values are normally given to the user in their Scheme form, e.g. #\a instead of #<gvalue <gchar> 3020c708 a>. However, when dealing with low-level routines it is sometimes necessary to have values in <gvalue> form. The conversion between the two is performed via the scm->gvalue and gvalue->scm functions.

The other set of useful procedures exported by this module are those dealing with enumerated values and flags. These objects are normally represented on the C side with integers, but they have symbolic representations registered in the GLib type system.

On the Scheme side, enumerated and flags values are canonically expressed as <gvalue> objects. They can be converted to integers or symbols using the conversion procedures exported by this module. It is conventional for Scheme procedures that take enumerated values to accept any form for the values, which can be canonicalized using (make <your-enum-type> #:value VALUE), where VALUE can be an integer, a symbol (or symbol list in the case of flags), or the string ``nickname'' (or string list) of the enumerated/flags value.

Usage
=====

Primitive gvalue? value Returns #t if VALUE is a <gvalue>, #f otherwise.

Primitive gvalue->type value Returns the <gtype> of the value held by VALUE.

Class <gboolean> A <gvalue> class for boolean values.

Class <gchar> A <gvalue> class for signed 8-bit values.

Class <guchar> A <gvalue> class for unsigned 8-bit values.

Class <gint> A <gvalue> class for signed 32-bit values.

Class <guint> A <gvalue> class for unsigned 32-bit values.

Class <glong> A <gvalue> class for signed ``long'' (32- or 64-bit) values.

Class <gulong> A <gvalue> class for unsigned ``long'' (32- or 64-bit) values.

Class <gint64> A <gvalue> class for signed 64-bit values.

Class <guint64> A <gvalue> class for unsigned 64-bit values.

Class <gfloat> A <gvalue> class for 32-bit floating-point values.

Class <gdouble> A <gvalue> class for 64-bit floating-point values.

Class <gchararray> A <gvalue> class for arrays of 8-bit values (C strings).

Class <gboxed> A <gvalue> class for ``boxed'' types, a way of wrapping generic C structures. Use gvalue->type on an instance of this class to determine what type it holds.

Class <gboxed-scm> A <gboxed> class for holding arbitrary Scheme objects.

Class <gvalue-array> A <gvalue> class for arrays of <gvalue>.

Class <genum> A <gvalue> base class for enumerated values. Users may define new enumerated value types via subclssing from <genum>, passing #:vtable TABLE as an initarg, where TABLE should be in a format suitable for passing to genum-register-static.

Class <gflags> A <gvalue> base class for flag values. Users may define new flag value types via subclssing from <gflags>, passing #:vtable TABLE as an initarg, where TABLE should be in a format suitable for passing to gflags-register-static.

Primitive genum-register-static name vtable Creates and registers a new enumerated type with name NAME with the C runtime. There must be no type with name NAME when this function is called.

The new type can be accessed from C either by passing the returned <gtype> object back to a C function or by using g-type-from-name.

VTABLE is a vector describing the new enum type. Each vector element describes one enum element and must be a list of 3 elements: the element's nick name as a symbol, its name as a string, and its integer value.

     (genum-register-static "Test"
       #((foo "Foo" 1) (bar "Bar" 2) (baz "Long name of baz" 4)))

Primitive gflags-register-static name vtable Creates and registers a new flags <gtype> with name var{name} with the C runtime.

See genum-register-static for details.

genum-class->value-table class Return the vtable of possible values for CLASS. The same as genum-type-get-values, but operates on classes.

gflags-class->value-table class Return the vtable of possible values for CLASS. The same as gflags-type-get-values, but operates on classes.

Primitive genum-type-get-values type Return a vtable of the values supported by the enumerated <gtype> TYPE. The return value will be in the format described in genum-register-static.

Primitive gflags-type-get-values type Return a vtable of the values supported by the flag <gtype> TYPE. The return value will be in the format described in gflags-register-static.

Primitive scm->gvalue type scm Convert a Scheme value into a <gvalue> of type TYPE. If the conversion is not possible, raise a gruntime-error.

Primitive gvalue->scm value Convert a <gvalue> into it normal scheme representation, for example unboxing characters into Scheme characters. Note that the Scheme form for some values is the <gvalue> form, for example with boxed or enumerated values.

genum->symbol obj Convert the enumerated value OBJ from a <gvalue> to its symbol representation (its ``nickname'').

genum->name obj Convert the enumerated value OBJ from a <gvalue> to its representation as a string (its ``name'').

genum->value obj Convert the enumerated value OBJ from a <gvalue> to its representation as an integer.

gflags->symbol-list obj Convert the flags value OBJ from a <gvalue> to a list of the symbols that it represents.

gflags->name-list obj Convert the flags value OBJ from a <gvalue> to a list of strings, the names of the values it represents.

gflags->value-list obj Convert the flags value OBJ from a <gvalue> to a list of integers, which when logand'd together yield the flags' value.

gtype:gboolean

gtype:gboxed

gtype:gboxed-scm

gtype:gchar

gtype:gchararray

gtype:gdouble

gtype:gfloat

gtype:gint

gtype:gint64

gtype:glong

gtype:gpointer

gtype:guchar

gtype:guint

gtype:guint64

gtype:gulong

gtype:gvalue-array

(gnome gobject gparameter)
**************************

Overview
========

Parameters are constraints for values, both in type and in range. This module wraps the parameters code of the GLib type system, defining C classes such that parameters may be manipulated and created from Scheme.

As a technical detail, the C structure GParamSpec is wrapped at two levels. One is a mapping of the C structure to a Guile structure. The other is a GOOPS representation. The low level is called gparam-struct, and the high level is called <gparam>. gparam-struct is a generic container of any type. <gparam> has subclasses for the various kinds of parameter types: <gparam-int>, <gparam-object>, etc.

Usage
=====

Class <gparam> The base class for GLib parameter objects.

Class <gparam-char> Parameter for <gchar> values. 3 arguments: minimum, maximum, and default values.

Class <gparam-uchar> Parameter for <guchar> values. 3 arguments: minimum, maximum, and default values.

Class <gparam-boolean> Parameter for <gboolean> values. 1 argument: default value.

Class <gparam-int> Parameter for <gint> values. 3 arguments: minimum, maximum, and default values.

Class <gparam-uint> Parameter for <guint> values. 3 arguments: minimum, maximum, and default values.

Class <gparam-long> Parameter for <glong> values. 3 arguments: minimum, maximum, and default values.

Class <gparam-ulong> Parameter for <gulong> values. 3 arguments: minimum, maximum, and default values.

Class <gparam-int64> Parameter for <gint64> values. 3 arguments: minimum, maximum, and default values.

Class <gparam-uint64> Parameter for <guint64> values. 3 arguments: minimum, maximum, and default values.

Class <gparam-float> Parameter for <gfloat> values. 3 arguments: minimum, maximum, and default values.

Class <gparam-double> Parameter for <gdouble> values. 3 arguments: minimum, maximum, and default values.

Class <gparam-pointer> Parameter for <gpointer> values. No arguments.

Class <gparam-string> Parameter for <gchararray> values. 1 argument: the default value, which may be #f.

Class <gparam-object> Parameter for <gobject> values. 1 argument: the <gtype> of the value.

Class <gparam-boxed> Parameter for <gboxed> values. 1 argument: the <gtype> of the value.

Class <gparam-enum> Parameter for <genum> values. 2 arguments: the <gtype> of the value, and the default value.

Class <gparam-flags> Parameter for <gflags> values. 2 arguments: the <gtype> of the value, and the default value.

Class <gparam-spec-flags> A <gflags> type for the flags allowable on a <gparam>: read, write, construct, construct-only, and lax-validation.

gparam-struct:name param-struct Retrieve the name from a gparam-struct.

gparam-struct:nick param-struct Retrieve the `nickname' from a gparam-struct.

gparam-struct:blurb param-struct Retrieve the `blurb', a short descriptive string, from a gparam-struct.

gparam-struct:flags param-struct Retrieve the flags from a gparam-struct.

gparam-struct:param-type param-struct Retrieve the GParam type from a gparam-struct, for example gtype:gparam-uint64.

gparam-struct:value-type param-struct Retrieve the value type from a gparam-struct, for example gtype:guint64.

gparam-struct:owner-type param-struct Retrieve the `owner type' from a gparam-struct. Appears to be stored into GLib param specs, but never used.

gparam-struct:args param-struct Retrieve the arguments from a gparam-struct, as a list. The length and composition of the arguments depends on the parameter type.

Primitive gparam->param-struct param Retrieve the primitive gparam-struct for the GOOPS parameter object, PARAM.

Primitive gparam->value-type param Retrieve the value type of the <gparam> object PARAM.

gparameter:uint-max

gparameter:int-min

gparameter:int-max

gparameter:ulong-max

gparameter:long-min

gparameter:long-max

gparameter:uint64-max

gparameter:int64-min

gparameter:int64-max

gparameter:float-max

gparameter:float-min

gparameter:double-max

gparameter:double-min

gparameter:byte-order

gtype:gparam-boolean

gtype:gparam-boxed

gtype:gparam-char

gtype:gparam-double

gtype:gparam-enum

gtype:gparam-flags

gtype:gparam-float

gtype:gparam-int

gtype:gparam-int64

gtype:gparam-long

gtype:gparam-object

gtype:gparam-pointer

gtype:gparam-string

gtype:gparam-uchar

gtype:gparam-uint

gtype:gparam-uint64

gtype:gparam-ulong

(gnome gobject gclosure)
************************

Overview
========

The GLib type system supports the creation and invocation of ``closures'', objects which can be invoked like procedures. Its infrastructure allows one to pass a Scheme function to C, and have C call into Scheme, and vice versa. This module exports a GOOPS class wrapping closures on the Scheme level, <gclosure>. <gclosure> holds a Scheme procedure, the <gtype> of its return value, and a list of the <gtype>'s of its arguments. Closures can be invoked with gclosure-invoke. For example:

      (gclosure-invoke (make <gclosure>
                        #:return-type <gint>
                        #:param-types (list <gulong>)
                        #:func (lambda (x) (* x x)))
                       10)
      => 100

Usage
=====

Class <gclosure> The Scheme representation of a GLib closure: a typed procedure object that can be passed to other languages.

gclosure-invoke closure  .  args Invoke a closure. The arguments ARGS will be converted to <gvalue> objects of the appropriate type, and the return value will be run through gvalue->scm. For all practical purposes, this function is like apply.

gtype:gclosure

(gnome gobject gsignal)
***********************

Overview
========

GSignal is a mechanism by which code, normally written in C, may expose extension points to which closures can be connected, much like Guile's hooks. Instantiatable types can have signals associated with them; for example, <gtk-widget> has an expose signal that will be ``fired'' at certain well-documented points.

Signals are typed. They specify the types of their return value, and the types of their arguments.

This module defines routines for instrospecting, emitting, connecting to, disconnecting from, blocking, and unblocking signals. Additionally it defines routines to define new signal types on instantiatable types.

Usage
=====

<gsignal> The structure vtable for <gsignal> instances.

gsignal:id signal Access the ``id'' of a <gsignal> structure, an integer.

gsignal:name signal Access the name of a <gsignal> structure, a string.

gsignal:interface-type signal Access the type to which a <gsignal> structure is associated, a <gtype>.

gsignal:return-type signal Access the return type from a a <gsignal> structure, a <gtype>.

gsignal:param-types signal Access the parameter types from a a <gsignal> structure, a list of <gtype>.

Primitive gtype-get-signals type Returns a vector of signal names belonging to TYPE and all parent types.

gtype-class-get-signals class Returns a vector of signals belonging to CLASS and all parent classes.

gtype-class-get-signal-names class Returns a vector of signal names belonging to CLASS and all parent classes.

gtype-instance-signal-emit object   name  .  args Emits signal NAME with arguments ARGS on the <gtype-instance> OBJECT. NAME should be a symbol.

gtype-instance-signal-connect-data object   name   func   after Connects FUNC as handler for the <gtype-instance> OBJECT's signal NAME.

NAME should be a symbol. AFTER is boolean specifying whether the handler is run before (#f) or after (#t) the signal's default handler.

Returns an integer number which can be used as arugment of gsignal-handler-block, gsignal-handler-unblock, gsignal-handler-disconnect and gsignal-handler-connected?.

gtype-instance-signal-connect object   name   func Convenience function for calling gtype-instance-signal-connect-data with AFTER = #f.

gtype-instance-signal-connect-after object   name   func Convenience function for calling gtype-instance-signal-connect-data with AFTER = #t.

gsignal-handler-block obj   id Block invocation of the signal handler identified by ID from high-level GOOPS object OBJECT.

gsignal-handler-unblock obj   id Unblock invocation of the signal handler identified by ID from high-level GOOPS object OBJECT.

gsignal-handler-disconnect obj   id Disconnect the signal handler identified by ID from high-level GOOPS object OBJECT.

gsignal-handler-connected? obj   id Returns #t if the signal handler identified by ID is connected on the high-level GOOPS object OBJECT, or #f otherwise.

gtype-class-create-signal class   name   return-type   param-types Create a new signal associated with the <gtype-class> CLASS.

NAME should be a symbol, the name of the signal. RETURN-TYPE should be either a <gtype> or a <gtype-class> object. Similarly, PARAM-TYPES should be a list of either <gtype> or <gtype-class> objects.

In a bit of an odd interface, this function will return a new generic function, which will be run as the signal's default handler, whose default method will silently return an unspecified value. The user may define new methods on this generic to provide alternative default handler implementations.

gtype-class-define-signal A macro invoked as:

      (gtype-class-define-signal CLASS NAME RETURN-TYPE
                                 . PARAM-TYPES)

All arguments will be passed to gtype-class-create-signal.

This form is a macro because it will actually take the generic returned from gtype-class-create-signal and bind it to a name in the toplevel environment.

The name of the new generic function is the concatenation of the type name, a colon, and the signal name.

For example:

      (gtype-class-define-signal <foo> 'roswell #f)
      (define-method (foo:roswell (obj <foo>))
        *unspecified*)

      (gtype-class-define-signal <foo> 'berlin <glong> <gint>)
      (define-method (foo:berlin (obj <foo>) (x <number>))
        85)

(gnome gobject gobject)
***********************

Overview
========

GObject is what is commonly understood as the object system for GLib. This is not strictly true. GObject is one implementation of an object system, built on the other modules: GType, GValue, GParameter, GClosure, and GSignal.

Similarly, this Guile module provides integration with the GObject object system, built on the Guile modules that support GType, GValue, GParameter, GClosure, and GSignal.

The main class exported by this module is <gobject>. <gobject> classes can be subclassed by the user, which will register new subtypes with the GType runtime type system. <gobject> classes are are also created as needed when wrapping GObjects that come from C, for example from a function's return value.

Besides supporting derivation, and signals like other <gtype-instance> implementations, <gobject> has the concept of properties, which are <gvalue>'s associated with the object. The values are constrained by <gparam>'s, which are associated with the object's class. This module exports the necessary routines to query, get, and set <gobject> properties.

In addition, this module defines the <ginterface> base class, whose subclasses may be present as mixins of <gobject> classes. For example:

      (use-modules (gnome gtk) (oop goops))
      (class-direct-supers <gtk-widget>) =>
         (#<<gobject-class> <atk-implementor-iface> 3033bad0>
          #<<gobject-class> <gtk-object> 3034bc90>)

In this example, we see that <gtk-widget> has two superclasses, <gtk-object> and <atk-implementor-iface>. The second is an interface implemented by the <gtk-widget> class. See gtype-interfaces for more details.

Usage
=====

Class <gobject> The base class for GLib's default object system.

<gobject>'s metaclass understands a new slot option, #:gparam, which will export a slot as a <gobject> property. The default implementation will set and access the value from the slot, but you can customize this by writing your own methods for gobject:set-property and gobject:get-property.

In addition, the metaclass also understands #:gsignal arguments, which define signals on the class, and define the generics for the default signal handler. See gtype-class-define-signal for more information.

For example:

      ;; deriving from <gobject>
      (define-class <test> (<gobject>)
       ;; a normal object slot
       my-data

       ;; an object slot exported as a gobject property
       (pub-data #:gparam (list <gparam-long> #:name 'test))

       ;; likewise, using non-default parameter settings
       (foo-data #:gparam (list <gparam-long> #:name 'foo
                                #:minimum -3 #:maximum 1000
                                #:default-value 42))

       ;; a signal with no arguments and no return value
       #:gsignal '(frobate #f)

       ;; a signal with arguments and a return value
       #:gsignal (list 'frobate <gboolean> <gint> <glong>))

      ;; deriving from <test> -- also inherits properties and signals
      (define-class <hungry> (<test>))

Class <ginterface> The base class for GLib's interface types. Not derivable in Scheme.

Primitive gtype-register-static name parent_type Derive a new type named NAME from PARENT_TYPE. Returns the new <gtype>. This function is called when deriving from <gobject>; users do not normally call this function directly.

Generic gobject:get-property Called to get a gobject property. Only properties directly belonging to the object's class will come through this function; superclasses handle their own properties.

Takes two arguments: the object and the property name.

Call (next-method) in your methods to invoke the default handler

 -- Method: gobject:get-property ( OBJECT <gobject> ) ( NAME <symbol> )
     The default implementation of gobject:get-property, which calls (slot-ref obj name).

Generic gobject:set-property Called to set a gobject property. Only properties directly belonging to the object's class will come through this function; superclasses handle their own properties.

Takes three arguments: the object, the property name, and the value.

Call (next-method) in your methods to invoke the default handler.

 -- Method: gobject:set-property ( OBJECT <gobject> ) ( NAME <symbol> ) ( VALUE <top> )
     The default implementation of gobject:set-property, which sets slots on the object.

Generic make-gobject-instance A generic defined to initialize a newly created <gobject> instance. make-gobject-instance takes four arguments: the class of the object, its <gtype>, the object itself, and the options, which is a list of keyword arguments.

This operation is a generic function so that subclasses can override it, e.g. so that <gtk-object> can implement explicit destruction.

 -- Method: make-gobject-instance ( CLASS <top> ) ( TYPE <top> ) ( OBJECT <top> ) ( OPTIONS <top> )
     The default implementation of make-gobject-instance.

gobject-class-get-properties class Returns a vector of properties belonging to CLASS and all parent classes.

gobject-class-find-property class   name Returns a property named NAME (a symbol), belonging to CLASS or one of its parent classes, or #f if not found.

gobject-class-get-property-names class Returns a vector of property names belonging to CLASS and all parent classes.

gobject-interface-get-properties class Returns a vector of properties belonging to CLASS and all parent classes.

gobject-interface-find-property class   name Returns a property named NAME (a symbol), belonging to CLASS or one of its parent classes, or #f if not found.

gobject-interface-get-property-names class Returns a vector of property names belonging to CLASS and all parent classes.

gobject-get-property object   name Gets a the property named NAME (a symbol) from OBJECT.

gobject-set-property object   name   init-value Sets the property named NAME (a symbol) on OBJECT to INIT-VALUE.

(gnome gobject generics)
************************

Overview
========

Generic functions for procedures in the (gnome gobject) module.

Mapping class libraries to Scheme
---------------------------------

Guile-GNOME exists to wrap a C library, libgobject, its types, and the set of libraries that based themselves on the GLib types.

Procedure invocation feels very similar in Scheme and in C. For example, the C gtk_widget_show (widget) transliterates almost exactly to the Scheme (gtk-widget-show widget).

GLib-based libraries are not random collections of functions, however. GLib-based libraries also implement classes and methods, insofar that it is possible in C. For example, in the above example, show may be seen to be a method on instances of the <gtk-widget> class.

Indeed, other object-oriented languages such as Python express this pattern directly, translating the show operation as the pleasantly brief widget.show(). However this representation of methods as being bound to instances, while common, has a number of drawbacks.

The largest drawback is that the method itself is not bound to a generic operation. For example, mapping the show operation across a set of widgets cannot be done with the straightforward map(show, set), because there is no object for the show operation. Instead the user must locally bind each widget to a variable in order to access a method of the abstract show operation: map(lambda widget: widget.show(), set).

Additionally, most languages which express methods as bound to instances only select the method via the type of the first (implicit) argument. The rule for these lanugages is, ``gtk-widget-show is an applicable method of the show operation when the first argument to show is a <gtk-widget>.'' Note the lack of specification for other arguments; the same object cannot have two applicable methods of the show operation. A more complete specification would be, ``gtk-widget-show is an applicable method of the show operation when applied to one argument, a <gtk-widget>.'' It is a fine difference, but sometimes important.

For these and other reasons, the conventional way to implement generic operations in Lisp has been to define generic functions, and then associate specific methods with those functions. For example, one would write the following:

      ;; defining a generic function, and one method implementation
      (define-generic show)
      (define-method (show (widget <gtk-widget>))
        (gtk-widget-show))

      ;; invoking the generic function
      (show my-widget)

One benefit of this approach is that method definitions can be made far away in space and time from type definitions. This leads to a more dynamic environment, in which methods can be added to existing types at runtime, which then can apply to existing instances.

The semantics of generic functions in Guile-GNOME
-------------------------------------------------

Naturally, there is an impedance mismatch between the conventions used in the C libraries and their Scheme equivalents. Operations in GLib-based libraries do not form a coherent whole, in the sense that there is no place that defines the meaning of an abstract show operation. For example, gtk-widget-set-state, which can make a widget become uneditable, and gst-element-set-state, which can start a video player, would both map to the generic function set-state, even though they have nothing to do with each other besides their name.

There is no conflict here; the methods apply on disjoint types. However there is a problem of modularity, in that both methods must be defined on the same generic function, so that (set-state foo bar) picks the correct method, depending on the types of FOO and BAR.

This point leads to the conclusion that generic functions in Guile-GNOME have no abstract meaning, apart from their names. Semantically, generics in Guile-GNOME are abbreviations to save typing, not abstract operations with defined meanings.

Practicalities
--------------

This module defines a number of ``abbreviations'', in the form of generic functions, for operations on types defined in the (gnome gobject) modules. Generic functions for generated bindings like (gnome gtk) are defined in another module, (gnome gw generics), which re-exports the public bindings from this module.

Usage
=====

Generic get

 -- Method: get ( OBJECT <gobject> ) ( NAME <symbol> )
     A shorthand for gobject-get-property.

Generic set

 -- Method: set ( OBJECT <gobject> ) ( NAME <symbol> ) ( VALUE <top> )
     A shorthand for gobject-set-property.

Generic emit

 -- Method: emit ( OBJECT <gtype-instance> ) ( NAME <symbol> ) ( ARGS <top> ) ...
     A shorthand for gtype-instance-signal-emit.

Generic connect

 -- Method: connect ( OBJECT <gtype-instance> ) ( NAME <symbol> ) ( FUNC <procedure> )
     A shorthand for gtype-instance-signal-connect.

 -- Method: connect ( ARGS <top> ) ...
     The core Guile implementation of the connect(2) POSIX call

Generic connect-after

 -- Method: connect-after ( OBJECT <gtype-instance> ) ( NAME <symbol> ) ( FUNC <procedure> )
     A shorthand for gtype-instance-signal-connect-after.

Generic block

 -- Method: block ( OBJECT <gtype-instance> ) ( ID <top> )
     A shorthand for gsignal-handler-block.

Generic unblock

 -- Method: unblock ( OBJECT <gtype-instance> ) ( ID <top> )
     A shorthand for gsignal-handler-unblock.

Generic disconnect

 -- Method: disconnect ( OBJECT <gtype-instance> ) ( ID <top> )
     A shorthand for gsignal-handler-disconnect.

Generic connected?

 -- Method: connected? ( OBJECT <gtype-instance> ) ( ID <top> )
     A shorthand for gsignal-handler-connected?.

Generic invoke

 -- Method: invoke ( CLOSURE <gclosure> ) ( ARGS <top> ) ...
     A shorthand for gclosure-invoke.

Generic create-signal

 -- Method: create-signal ( CLASS <gtype-class> ) ( NAME <symbol> ) ( RETURN-TYPE <top> ) ( PARAM-TYPES <top> )
     A shorthand for gtype-class-create-signal.

Generic get-signals

 -- Method: get-signals ( CLASS <gtype-class> )
     A shorthand for gtype-class-get-signals.

Generic get-properties

 -- Method: get-properties ( CLASS <gtype-class> )
     A shorthand for gobject-class-get-properties.

Generic get-property-names

 -- Method: get-property-names ( CLASS <gtype-class> )
     A shorthand for gobject-class-get-property-names.

Generic find-property

 -- Method: find-property ( CLASS <gtype-class> ) ( NAME <symbol> )
     A shorthand for gobject-class-find-property.

(gnome gobject utils)
*********************

Overview
========

Common utility routines.

Usage
=====

GStudlyCapsExpand nstr Expand the StudlyCaps NSTR to a more schemey-form, according to the conventions of GLib libraries. For example:

      (GStudlyCapsExpand "GSource") => g-source
      (GStudlyCapsExpand "GtkIMContext") => gtk-im-context
      (GStudlyCapsExpand "GtkHBox") => gtk-hbox

gtype-name->scheme-name-alist An alist of exceptions to the name transformation algorithm implemented in GStudlyCapsExpand.

gtype-name->scheme-name type-name Transform a name of a <gtype>, such as "GtkWindow", to a scheme form, such as gtk-window, taking into account the exceptions in gtype-name->scheme-name-alist, and trimming trailing dashes if any.

gtype-name->class-name type-name Transform a name of a <gtype>, such as "GtkWindow", to a suitable name of a Scheme class, such as <gtk-window>. Uses gtype-name->scheme-name.

gtype-name->method-name type-name   name Generate the name of a method given the name of a <gtype> and the name of the operation. For example:

      (gtype-name->method-name "GtkFoo" "bar") => gtk-foo:bar

Uses gtype-name->scheme-name.

re-export-modules  .  args Re-export the public interface of a module or modules. Invoked as (re-export-modules (mod1) (mod2)...).

define-macro-with-docs form   docs  .  body

define-with-docs name   docs   val Define NAME as VAL, documenting the value with DOCS.

define-generic-with-docs name   documentation Define a generic named NAME, with documentation DOCUMENTATION.

define-class-with-docs name   supers   docs  .  rest Define a class named NAME, with superclasses SUPERS, with documentation DOCS.

(gnome gw generics)
*******************

Overview
========

This module exists so that all (gnome gw) modules have a common place to put their generic functions. Whenever a wrapset is loaded, it adds method definitions to generics defined in this module.

See the documentation for (gnome gobject generics) for more notes about generic functions in Guile-GNOME. This module re-exports bindings from (gnome gobject generics), so there is no need to import them both.

Usage
=====

(gnome gw support gobject)
**************************

Overview
========

G-Wrap support for (gnome gobject) types. Code in this module is only loaded when generating wrapsets; as such, it is not for end users.

Usage
=====

Class <gobject-wrapset-base> The base class for G-Wrap wrapsets that use <gobject> types.

Generic add-type-alias!

 -- Method: add-type-alias! ( WRAPSET <gobject-wrapset-base> ) ( ALIAS <string> ) ( NAME <symbol> )
     Add a type alias to WRAPSET, that the string ALIAS is associated with the type named SYMBOL. For example, "GtkWindow*" might be associated with a type named <gtk-window>. See lookup-type-by-alias.

Generic lookup-type-by-alias

 -- Method: lookup-type-by-alias ( WRAPSET <gobject-wrapset-base> ) ( NAME <string> )
     Lookup a type aliased NAME in WRAPSET, and all wrapsets on which WRAPSET depends. This interface is used by load-defs to associate G-Wrap types with the strings parsed out of the C header files.

Generic add-type-rule!

 -- Method: add-type-rule! ( SELF <gobject-wrapset-base> ) ( PARAM-TYPE <string> ) ( TYPESPEC <top> )
     Add a type rule to WRAPSET, that the string PARAM-TYPE maps directly to the g-wrap typespec TYPESPEC. For example, "int*" might map to the typespec (int out). See find-type-rule.

Generic find-type-rule

 -- Method: find-type-rule ( SELF <gobject-wrapset-base> ) ( PARAM-TYPE <string> )
     See if the parameter type PARAM-TYPE has a type rule present in WRAPSET or in any wrapset on which WRAPSET depends. This interface is used by load-defs to associate G-Wrap typespecs with the strings parsed out of the C header files.

Class <gobject-type-base> A base G-Wrap type class for GLib types.

Class <gobject-classed-type> A base G-Wrap type class for classed GLib types (see gtype-classed?).

Generic gtype-id

 -- Method: gtype-id ( O <gobject-custom-gvalue-type> )

 -- Method: gtype-id ( O <gobject-custom-boxed-type> )

 -- Method: gtype-id ( O <gobject-class-type> )

 -- Method: gtype-id ( O <gobject-flags-type> )

 -- Method: gtype-id ( O <gobject-enum-type> )

 -- Method: gtype-id ( O <gobject-interface-type> )

 -- Method: gtype-id ( O <gobject-pointer-type> )

 -- Method: gtype-id ( O <gobject-boxed-type> )

 -- Method: gtype-id ( O <gobject-object-type> )

 -- Method: gtype-id ( O <gobject-classed-pointer-type> )

 -- Method: gtype-id ( O <gobject-classed-type> )

Class <gobject-classed-pointer-type> A base G-Wrap type class for for classed GLib types whose values are pointers.

Generic unwrap-null-checked

 -- Method: unwrap-null-checked ( VALUE <gw-value> ) ( STATUS-VAR <top> ) ( CODE <top> )
     Unwrap a value into a C pointer, optionally unwrapping #f as NULL.

     This function checks the typespec options on VALUE, which should be a <gw-value>. If the null-ok option is set (which is only the case for value classes with null-ok in its #:allowed-options), this function generates code that unwraps #f as NULL. If null-ok is unset, or the value is not #f, CODE is run instead.

Generic wrap-object!

 -- Method: wrap-object! ( WS <gobject-wrapset-base> ) ( ARGS <top> ) ...
     Define a wrapper for a specific <gobject>-derived type in WS. Required keyword arguments are #:ctype and #:gtype-id. For example,

           (wrap-object! ws #:ctype "GtkWidget"
                         #:gtype-id "GTK_TYPE_WIDGET")

     Normally only called from load-defs.

Generic wrap-boxed!

 -- Method: wrap-boxed! ( WS <gobject-wrapset-base> ) ( ARGS <top> ) ...
     Define a wrapper for a specific boxed type in WS. Required keyword arguments are #:ctype and #:gtype-id, as in wrap-object!.

Generic wrap-pointer!

 -- Method: wrap-pointer! ( WS <gobject-wrapset-base> ) ( ARGS <top> ) ...
     Define a wrapper for a specific pointer type in WS. Required keyword arguments are #:ctype and #:gtype-id, as in wrap-object!.

wrap-opaque-pointer! ws   ctype Define a wrapper for an opaque pointer with the C type CTYPE. It will not be possible to create these types from Scheme, but they can be received from a library, and passed as arguments to other calls into the library.

Generic wrap-interface!

 -- Method: wrap-interface! ( WS <gobject-wrapset-base> ) ( ARGS <top> ) ...
     Define a wrapper for an interface type in WS. Required keyword arguments are #:ctype and #:gtype-id, as in wrap-object!.

Generic wrap-flags!

 -- Method: wrap-flags! ( WS <gobject-wrapset-base> ) ( ARGS <top> ) ...
     Define a wrapper for a flags type in WS. Required keyword arguments are #:ctype and #:gtype-id or #:values, as in wrap-enum!.

Generic wrap-gobject-class!

 -- Method: wrap-gobject-class! ( WS <gobject-wrapset-base> ) ( ARGS <top> ) ...
     Define a wrapper for GObject class values WS. Required keyword arguments are #:ctype and #:gtype-id, as in wrap-object!.

     #:ctype should refer to the type of the class and not the instance; e.g. "GtkWidgetClass" and not "GtkWidget". This function will not be called by load-defs, and should be invoked manually in a wrapset as needed.

wrap-custom-boxed! ctype   gtype   wrap   unwrap Wrap a boxed type using custom wrappers and unwrappers.

FIXME: missing a wrapset argument!

CTYPE and GTYPE are as #:ctype and #:gtype-id in wrap-object!. WRAP and UNWRAP are G-Wrap forms in which scm-var and c-var will be bound to the names of the SCM and C values, respectively. For example:

       (wrap-custom-boxed!
        "GdkRectangle" "GDK_TYPE_RECTANGLE"
        (list scm-var " = "
              c-var " ?  scm_gdk_rectangle_to_scm (" c-var ")"
              " : SCM_BOOL_F;")
        (list c-var " = scm_scm_to_gdk_rectangle (" scm-var ");"))

wrap-custom-gvalue! ctype   gtype   wrap-func   unwrap-func Wrap a GValue type using custom wrap and unwrap functions.

FIXME: missing a wrapset argument!

CTYPE and GTYPE are as #:ctype and #:gtype-id in wrap-object!. WRAP-FUNC and UNWRAP-FUNC are names of functions to convert to and from Scheme values, respectively. For example:

      (wrap-custom-gvalue! "GstFraction" "GST_TYPE_FRACTION"
                           "scm_from_gst_fraction"
                           "scm_to_gst_fraction")

(gnome gw support defs)
***********************

Overview
========

Support for populating G-Wrap wrapsets using information parsed out of .defs files. See the API scanner script, h2defs.py, included in the Guile-GNOME source distribution.

Code in this module is only loaded when generating wrapsets; as such, it is not for end users.

Usage
=====

load-defs ws   file   [overrides = #f] Load G-Wrap type and function information from FILE into the G-Wrap wrapset WS.

FILE should be a relative path, which will be searched in the vicinity of Guile's %load-path. include directives in the file will be searched relative to the absolute path of the file.

The following forms are understood: define-enum, define-flags, define-object, define-interface, define-pointer, define-boxed, define-function, define-method, ignore, ignore-glob, and ignore-types.

The optional argument, OVERRIDES, specifies the location of an overrides file that will be spliced into the .defs file at the point of an (include overrides) form.

load-defs-with-overrides ws   defs Equivalent to:

       (load-defs ws defs
                  (string-append "gnome/overrides/"
                                 (basename defs)))

(gnome gw support gtk-doc)
**************************

Overview
========

Parsing a subset of the docbook emitted by gtk-doc into stexi.

Usage
=====

docbook->sdocbook docbook-fragment Parse a docbook file DOCBOOK-FRAGMENT into SXML. Simply calls SSAX's xml->sxml, but having made sure that &nbsp; elements are interpreted correctly. Does not deal with XInclude.

gtk-doc-sdocbook-title sdocbook Extract the title from a fragment of docbook, as produced by gtk-doc. May return #f if the title is not found.

gtk-doc-sdocbook-subtitle sdocbook Extract the subtitle from a fragment of docbook, as produced by gtk-doc. May return #f if the subtitle is not found.

gtk-doc-sdocbook->description-fragment sdocbook Extract the "description" of a module from a fragment of docbook, as produced by gtk-doc, translated into texinfo.

gtk-doc-sdocbook->def-list sdocbook   process-def Extract documentation for all functions defined in the docbook nodeset SDOCBOOK.

When a function is found and translated into texinfo, PROCESS-DEF will be called with two arguments, the name of the procedure as a symbol, and the documentation as a deffn. PROCESS-DEF may return #f to indicate that the function should not be included in the documentation; otherwise, the return value of PROCESS-DEF will be used as the documentation.

This mechanism allows the caller of gtk-doc-sdocbook->def-list to perform further processing on the documentation, including the possiblity of replacing it completely with documenation from another source, for example a file of hand-written documentation overrides.

(gnome gw support modules)
**************************

Overview
========

Support routines for automatically-generated scheme G-Wrap modules.

Usage
=====

export-all-lazy! symbols Export the SYMBOLS from the current module.

Most generic functions and classes that G-Wrap defines are bound lazily, as needed in evaluation. This is done by placing module binder procedures on the generated modules. However, if we export all symbols by name, this will force the binding eagerly for all values, which is slow.

This procedure exports all bindings named in SYMBOLS that are already bound in the current module, and then installs a module binder procedure on the public interface, which allows lazy binding to work.

re-export-modules  .  args Re-export the public interface of a module; used like use-modules.