class GObject::Object

Overview

The base object type.

All the fields in the GObject structure are private to the implementation and should never be accessed directly.

Since GLib 2.72, all #GObjects are guaranteed to be aligned to at least the alignment of the largest basic GLib type (typically this is #guint64 or #gdouble). If you need larger alignment for an element in a #GObject, you should allocate it on the heap (aligned), or arrange for your #GObject to be appropriately padded. This guarantee applies to the #GObject (or derived) struct, the #GObjectClass (or derived) struct, and any private data allocated by G_ADD_PRIVATE().

Direct Known Subclasses

Defined in:

lib/gi-crystal/src/auto/g_object-2.0/object.cr
lib/gi-crystal/src/bindings/g_object/object.cr

Constructors

Class Method Summary

Macro Summary

Instance Method Summary

Constructor Detail

def self.cast(obj : GObject::Object) : self #

Cast a GObject::Object to self, throws a TypeCastError if the cast can't be made.


[View source]
def self.new(pointer : Pointer(Void), transfer : GICrystal::Transfer) #

[View source]
def self.new #

[View source]
def self.newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self #

Creates a new instance of a #GObject subtype and sets its properties.

Construction parameters (see %G_PARAM_CONSTRUCT, %G_PARAM_CONSTRUCT_ONLY) which are not explicitly specified are set to their default values.

DEPRECATED


[View source]

Class Method Detail

def self.cast?(obj : GObject::Object) : self | Nil #

Cast a GObject::Object to self, returns nil if the cast can't be made.


[View source]
def self.compat_control(what : UInt64, data : Pointer(Void) | Nil) : UInt64 #

[View source]
def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


[View source]
def self.interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec #

Find the #GParamSpec with the given name for an interface. Generally, the interface vtable passed in as g_iface will be the default vtable from g_type_default_interface_ref(), or, if you know the interface has already been loaded, g_type_default_interface_peek().


[View source]
def self.interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) #

Lists the properties of an interface.Generally, the interface vtable passed in as g_iface will be the default vtable from g_type_default_interface_ref(), or, if you know the interface has already been loaded, g_type_default_interface_peek().


[View source]

Macro Detail

macro previous_vfunc(*args) #

To be used inside a vfunc (re)-implementation. Has the same meaning of super, but works with GObject virtual functions.

Do nothing is the current vfunc doesn't have any previous implementation.


[View source]
macro previous_vfunc!(*args) #

To be used inside a vfunc (re)-implementation. Has the same meaning of super, but works with GObject virtual functions.

Raises NilAssertionError if the current vfunc doesn't have any previous implementation.


[View source]
macro signal(signature) #

Declares a GObject signal.

Supported signal parameter types are:

  • Integer types
  • Float types

[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


def bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding #

Creates a binding between source_property on source and target_property on target.

Whenever the source_property is changed the target_property is updated using the same value. For instance:

|[ g_object_bind_property (action, "active", widget, "sensitive", 0); ]|

Will result in the "sensitive" property of the widget #GObject instance to be updated with the same value of the "active" property of the action #GObject instance.

If flags contains %G_BINDING_BIDIRECTIONAL then the binding will be mutual: if target_property on target changes then the source_property on source will be updated as well.

The binding will automatically be removed when either the source or the target instances are finalized. To remove the binding without affecting the source and the target you can just call g_object_unref() on the returned #GBinding instance.

Removing the binding by calling g_object_unref() on it must only be done if the binding, source and target are only used from a single thread and it is clear that both source and target outlive the binding. Especially it is not safe to rely on this if the binding, source or target can be finalized from different threads. Keep another reference to the binding and use g_binding_unbind() instead to be on the safe side.

A #GObject can have multiple bindings.


[View source]
def bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding #

Complete version of g_object_bind_property().

Creates a binding between source_property on source and target_property on target, allowing you to set the transformation functions to be used by the binding.

If flags contains %G_BINDING_BIDIRECTIONAL then the binding will be mutual: if target_property on target changes then the source_property on source will be updated as well. The transform_from function is only used in case of bidirectional bindings, otherwise it will be ignored

The binding will automatically be removed when either the source or the target instances are finalized. This will release the reference that is being held on the #GBinding instance; if you want to hold on to the #GBinding instance, you will need to hold a reference to it.

To remove the binding, call g_binding_unbind().

A #GObject can have multiple bindings.

The same user_data parameter will be used for both transform_to and transform_from transformation functions; the notify function will be called once, when the binding is removed. If you need different data for each transformation function, please use g_object_bind_property_with_closures() instead.


[View source]
def data(key : String) : Pointer(Void) | Nil #

Gets a named field from the objects table of associations (see g_object_set_data()).


[View source]
def finalize #

Called by the garbage collector. Decreases the reference count of object. (i.e. its memory is freed).


[View source]
def freeze_notify : Nil #

Increases the freeze count on object. If the freeze count is non-zero, the emission of "notify" signals on object is stopped. The signals are queued until the freeze count is decreased to zero. Duplicate notifications are squashed so that at most one #GObject::notify signal is emitted for each property modified while the object is frozen.

This is necessary for accessors that modify multiple properties to prevent premature notification while the object is still being modified.


[View source]
def getv(names : Enumerable(String), values : Enumerable(_)) : Nil #

Gets n_properties properties for an object. Obtained properties will be set to values. All properties must be valid. Warnings will be emitted and undefined behaviour may result if invalid properties are passed in.


[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


def notify(property_name : String) : Nil #

Emits a "notify" signal for the property property_name on object.

When possible, eg. when signaling a property change from within the class that registered the property, you should use g_object_notify_by_pspec() instead.

Note that emission of the notify signal may be blocked with g_object_freeze_notify(). In this case, the signal emissions are queued and will be emitted (in reverse order) when g_object_thaw_notify() is called.


[View source]
def notify_by_pspec(pspec : GObject::ParamSpec) : Nil #

Emits a "notify" signal for the property specified by pspec on object.

This function omits the property name lookup, hence it is faster than g_object_notify().

One way to avoid using g_object_notify() from within the class that registered the properties, and using g_object_notify_by_pspec() instead, is to store the GParamSpec used with g_object_class_install_property() inside a static array, e.g.:

|[ enum { PROP_0, PROP_FOO, PROP_LAST };

static GParamSpec *properties[PROP_LAST];

static void my_object_class_init (MyObjectClass *klass) { properties[PROP_FOO] = g_param_spec_int ("foo", "Foo", "The foo", 0, 100, 50, G_PARAM_READWRITE); g_object_class_install_property (gobject_class, PROP_FOO, properties[PROP_FOO]); } ]|

and then notify a change on the "foo" property with:

|[ g_object_notify_by_pspec (self, properties[PROP_FOO]); ]|


[View source]
def notify_signal #

[View source]
def property(property_name : String, value : _) : Nil #

Gets a property of an object.

The value can be:

  • an empty #GValue initialized by %G_VALUE_INIT, which will be automatically initialized with the expected type of the property (since GLib 2.60)
  • a #GValue initialized with the expected type of the property
  • a #GValue initialized with a type to which the expected type of the property can be transformed

In general, a copy is made of the property contents and the caller is responsible for freeing the memory by calling g_value_unset().

Note that g_object_get_property() is really intended for language bindings, g_object_get() is much more convenient for C programming.


[View source]
def qdata(quark : UInt32) : Pointer(Void) | Nil #

This function gets back user data pointers stored via g_object_set_qdata().


[View source]
def ref_count : UInt32 #

Returns GObject reference counter.


[View source]
def run_dispose : Nil #

Releases all references to other objects. This can be used to break reference cycles.

This function should only be called from object system implementations.


[View source]
def set_data(key : String, data : Pointer(Void) | Nil) : Nil #

Each object carries around a table of associations from strings to pointers. This function lets you set an association.

If the object already had an association with that name, the old association will be destroyed.

Internally, the key is converted to a #GQuark using g_quark_from_string(). This means a copy of key is kept permanently (even after object has been finalized) — so it is recommended to only use a small, bounded set of values for key in your program, to avoid the #GQuark storage growing unbounded.


[View source]
def set_property(property_name : String, value : _) : Nil #

Sets a property on an object.


[View source]
def steal_data(key : String) : Pointer(Void) | Nil #

Remove a specified datum from the object's data associations, without invoking the association's destroy handler.


[View source]
def steal_qdata(quark : UInt32) : Pointer(Void) | Nil #

This function gets back user data pointers stored via g_object_set_qdata() and removes the data from object without invoking its destroy() function (if any was set). Usually, calling this function is only required to update user data pointers with a destroy notifier, for example: |[ void object_add_to_user_list (GObject *object, const gchar *new_string) { // the quark, naming the object data GQuark quark_string_list = g_quark_from_static_string ("my-string-list"); // retrieve the old string list GList *list = g_object_steal_qdata (object, quark_string_list);

// prepend new string list = g_list_prepend (list, g_strdup (new_string)); // this changed 'list', so we need to set it again g_object_set_qdata_full (object, quark_string_list, list, free_string_list); } static void free_string_list (gpointer data) { GList *node, *list = data;

for (node = list; node; node = node->next) g_free (node->data); g_list_free (list); } ]| Using g_object_get_qdata() in the above example, instead of g_object_steal_qdata() would have left the destroy function set, and thus the partial string list would have been freed upon g_object_set_qdata_full().


[View source]
def thaw_notify : Nil #

Reverts the effect of a previous call to g_object_freeze_notify(). The freeze count is decreased on object and when it reaches zero, queued "notify" signals are emitted.

Duplicate notifications for each property are squashed so that at most one #GObject::notify signal is emitted for each property, in the reverse order in which they have been queued.

It is an error to call this function when the freeze count is zero.


[View source]
def to_unsafe : Pointer(Void) #

Returns a pointer to the C object.


[View source]
def watch_closure(closure : GObject::Closure) : Nil #

This function essentially limits the life time of the closure to the life time of the object. That is, when the object is finalized, the closure is invalidated by calling g_closure_invalidate() on it, in order to prevent invocations of the closure with a finalized (nonexisting) object. Also, g_object_ref() and g_object_unref() are added as marshal guards to the closure, to ensure that an extra reference count is held on object during invocation of the closure. Usually, this function will be called on closures that use this object as closure data.


[View source]