Next: , Previous: g-initially-unowned, Up: GObject high-level


10.3 GObject metaclass

See MOP for information what metaclass is and why is it useful.

GObject metaclass gobject-class bridges two object systems: GObject and CLOS.

Classes that correspond to GObject classes are instances of this class. Each CLOS class of gobject-class metaclass is mapped to one GObject class. Two or more CLOS classes may map into one GObject class. GObject and CLOS inheritance must be consistent: if class X is a subclass or the same class as Y in CLOS, then this relation must hold for X' and Y', where X' is a GObject class to which X class maps to.

For each instance of GObject-related CLOS class there is a corresponding instance of GObject class (of a GObject class to which the CLOS class maps). Whenever the GObject class instance reference enters the Lisp memory (by creating instance with make-instance, as the return value of foreign function or as a slot value of GObject class instance), an instance of CLOS class is created.

Defining the class with metaclass gobject-class registers the type :g-type-name for conversions using GValue and CFFI foreign type g-object.

This class has the following slots:

This metaclass defines the GObject classes.

Slots which have :allocation of :gobject-property are mapped to GObject properties. Such slots have following attributes:

Slots which have :allocation of :gobject-fn are mapped to a pair of accessor functions (usually named class_get_property and class_set_property). This is included because some properties are not exposed as GObject properties. Such slots have following attributes:

Initargs of a slot are used to construct the GObject class.

Example:

     (defclass container (widget atk-implementor-iface buildable)
         ((border-width :allocation :gobject-property
                        :g-property-type "guint"
                        :accessor container-border-width
                        :initarg :border-width
                        :g-property-name "border-width")
          (resize-mode :allocation :gobject-property
                       :g-property-type "GtkResizeMode"
                       :accessor container-resize-mode
                       :initarg :resize-mode
                       :g-property-name "resize-mode")
          (child :allocation :gobject-property
                 :g-property-type "GtkWidget"
                 :accessor container-child
                 :initarg :child
                 :g-property-name "child")
          (focus-child :allocation :gobject-fn
                       :g-property-type g-object
                       :accessor container-focus-child
                       :initarg :focus-child
                       :g-getter "gtk_container_get_focus_child"
                       :g-setter "gtk_container_set_focus_child")
          (focus-vadjustment :allocation :gobject-fn
                             :g-property-type (g-object adjustment)
                             :accessor container-focus-vadjustment
                             :initarg :focus-vadjustment
                             :g-getter "gtk_container_get_focus_vadjustment"
                             :g-setter "gtk_container_set_focus_vadjustment")
          (focus-hadjustment :allocation :gobject-fn
                             :g-property-type (g-object adjustment)
                             :accessor container-focus-hadjustment
                             :initarg :focus-hadjustment
                             :g-getter "gtk_container_get_focus_hadjustment"
                             :g-setter "gtk_container_set_focus_hadjustment"))
         (:metaclass gobject-class)
         (:g-type-name . "GtkContainer")
         (:g-type-initializer . "gtk_container_get_type"))

(note the dot in (:g-type-name . "GtkContainer") and in (:g-type-initializer . "gtk_container_get_type"). It should be present)