W Wrapl, The Programming Language

Libraries:Gtk:Gtk:Object

Types

T

Inherits from:

Description

T is the base class for all widgets, and for a few non-widget objects such as Gtk.Gtk.Adjustment.T. T predates GObject; non-widgets that derive from T rather than GObject do so for backward compatibility reasons.

Ts are created with a "floating" reference count. This means that the initial reference is not owned by anyone. Calling g_object_unref() on a newly-created T is incorrect, the floating reference has to be removed first. This can be done by anyone at any time, by calling g_object_ref_sink() to convert the floating reference into a regular reference. g_object_ref_sink() returns a new reference if an object is already sunk (has no floating reference).

When you add a widget to its parent container, the parent container will do this:

1
g_object_ref_sink (G_OBJECT (child_widget));

This means that the container now owns a reference to the child widget and the child widget has no floating reference.

The purpose of the floating reference is to keep the child widget alive until you add it to a parent container:

1
2
3
4
button = gtk_button_new ();
/* button has one floating reference to keep it alive */
gtk_container_add (GTK_CONTAINER (container), button);
/* button has one non-floating reference owned by the container */

Gtk.Gtk.Window.T is a special case, because GTK+ itself will ref/sink it on creation. That is, after calling gtk_window_new(), the Gtk.Gtk.Window.T will have one reference which is owned by GTK+, and no floating references.

One more factor comes into play: the "destroy" signal, emitted by the Destroy method. The "destroy" signal asks all code owning a reference to an object to release said reference. So, for example, if you call Destroy on a Gtk.Gtk.Window.T, GTK+ will release the reference count that it owns; if you call Destroy on a Gtk.Gtk.Button.T, then the button will be removed from its parent container and the parent container will release its reference to the button. Because these references are released, calling Destroy should result in freeing all memory associated with an object, unless some buggy code fails to release its references in response to the "destroy" signal. Freeing memory (referred to as finalization only happens if the reference count reaches zero.

Some simple rules for handling T:

  • Never call g_object_unref() unless you have previously called g_object_ref(), even if you created the T. (Note: this is not true for GObject; for GObject, the creator of the object owns a reference.)

  • Call Destroy to get rid of most objects in most cases. In particular, widgets are almost always destroyed in this way.

  • Because of the floating reference count, you don't need to worry about reference counting for widgets and toplevel windows, unless you explicitly call g_object_ref() yourself.



Constants

Nil : T

Functions

AddArgType(arg_name @ Std.String.T, arg_type @ Gtk.GObject.Type.T, arg_flags @ Std.Integer.SmallT, arg_id @ Std.Integer.SmallT) : Std.Object.T

Warning

AddArgType is deprecated and should not be used in newly-written code.



GetType() : Gtk.GObject.Type.T



New(type @ Gtk.GObject.Type.T, first_property_name @ Std.String.T, ... @ Std.Object.T) : Gtk.Gtk.Object.T

Warning

gtk_object_new is deprecated and should not be used in newly-written code. Use g_object_new() instead.



Methods

:Destroy(self @ T) : Std.Object.T

Warning

Destroy has been deprecated since version 2.24 and should not be used in newly-written code. Use Gtk.Gtk.Widget.Destroy instead (if object is a widget)



:Get(self @ T, first_property_name @ Std.String.T, ... @ Std.Object.T) : Std.Object.T

Warning

Get is deprecated and should not be used in newly-written code. Use g_object_get() instead.



:GetDataById(self @ T, data_id @ Std.Integer.SmallT) : Std.Address.T

Warning

GetDataById is deprecated and should not be used in newly-written code. Use g_object_get_qdata() instead.



:GetUserData(self @ T) : Std.Address.T

Warning

GetUserData is deprecated and should not be used in newly-written code. Use g_object_get_data() instead.



:Ref(self @ T) : Gtk.Gtk.Object.T

Warning

Ref is deprecated and should not be used in newly-written code. Use g_object_ref() instead.



:RemoveData(self @ T, key @ Std.String.T) : Std.Object.T

Warning

RemoveData is deprecated and should not be used in newly-written code. Use g_object_set_data() to set the object data to NULL instead.



:RemoveDataById(self @ T, data_id @ Std.Integer.SmallT) : Std.Object.T

Warning

RemoveDataById is deprecated and should not be used in newly-written code. Use g_object_set_qdata() with data of NULL instead.



:RemoveNoNotify(self @ T, key @ Std.String.T) : Std.Object.T

Warning

RemoveNoNotify is deprecated and should not be used in newly-written code. Use g_object_steal_data() instead.



:RemoveNoNotifyById(self @ T, key_id @ Std.Integer.SmallT) : Std.Object.T

Warning

RemoveNoNotifyById is deprecated and should not be used in newly-written code. Use g_object_steal_qdata() instead.



:Set(self @ T, first_property_name @ Std.String.T, ... @ Std.Object.T) : Std.Object.T

Warning

Set is deprecated and should not be used in newly-written code. Use g_object_set() instead.



:SetDataById(self @ T, data_id @ Std.Integer.SmallT, data @ Std.Address.T) : Std.Object.T

Warning

SetDataById is deprecated and should not be used in newly-written code. Use g_object_set_qdata() instead.



:SetDataByIdFull(self @ T, data_id @ Std.Integer.SmallT, data @ Std.Address.T, destroy @ Std.Function.T) : Std.Object.T

Warning

SetDataByIdFull is deprecated and should not be used in newly-written code. Use g_object_set_qdata_full() instead.



:SetDataFull(self @ T, key @ Std.String.T, data @ Std.Address.T, destroy @ Std.Function.T) : Std.Object.T

Warning

SetDataFull is deprecated and should not be used in newly-written code. Use g_object_set_data_full() instead.



:SetUserData(self @ T, data @ Std.Address.T) : Std.Object.T

Warning

SetUserData is deprecated and should not be used in newly-written code. Use g_object_set_data() instead.



:Sink(self @ T) : Std.Object.T

Warning

Sink has been deprecated since version 2.10 and should not be used in newly-written code. Use g_object_ref_sink() instead



:Unref(self @ T) : Std.Object.T

Warning

Unref is deprecated and should not be used in newly-written code. Use g_object_unref() instead.



:Weakref(self @ T, notify @ Std.Function.T, data @ Std.Address.T) : Std.Object.T

Warning

Weakref is deprecated and should not be used in newly-written code. Use g_object_weak_ref() instead.



:Weakunref(self @ T, notify @ Std.Function.T, data @ Std.Address.T) : Std.Object.T

Warning

Weakunref is deprecated and should not be used in newly-written code. Use g_object_weak_unref() instead.