package Object_SList is new Glib.GSlist.Generic_SList (Gtk_Object);
type Gtk_Object_Record is new Glib.Object.GObject_Record with private;
type Gtk_Object is access all Gtk_Object_Record'Class;
subtype GObject_Class is Glib.Object.GObject_Class;
subtype Signal_Parameter_Types is Glib.Object.Signal_Parameter_Types;
Uninitialized_Class : GObject_Class renames Glib.Object.Uninitialized_Class;
Null_Parameter_Types : Signal_Parameter_Types renames Glib.Object.Null_Parameter_Types;
User_Data_Property : constant Glib.Properties.Property_Address;
Signal_Destroy : constant Glib.Signal_Name := "destroy";
procedure Sink
( | Object | : access Gtk_Object_Record); |
procedure Destroy
( | Object | : access Gtk_Object_Record); |
function Get_Type return Gtk.Gtk_Type;
function Get_Type
( | Object | : access Gtk_Object_Record) return Gtk_Type; |
function Convert
( | W | : Gtk_Object) return System.Address; |
function Convert
( | W | : System.Address) return Gtk_Object; |
function Flags
( | Object | : access Gtk_Object_Record) return Guint32; |
procedure Set_Flags
( | Object | : access Gtk_Object_Record; |
Flags | : Guint32); |
procedure Unset_Flags
( | Object | : access Gtk_Object_Record; |
Flags | : Guint32); |
function Flag_Is_Set
( | Object | : access Gtk_Object_Record; |
Flag | : Guint32) return Boolean; |
function In_Destruction_Is_Set
( | Object | : access Gtk_Object_Record'Class) return Boolean; |
function Destroyed_Is_Set
( | Object | : access Gtk_Object_Record'Class) return Boolean renames In_Destruction_Is_Set; |
function Floating_Is_Set
( | Object | : access Gtk_Object_Record'Class) return Boolean; |
procedure Initialize_Class_Record
( | Object | : access GObject_Record'Class; |
Signals | : Gtkada.Types.Chars_Ptr_Array; | |
Class_Record | : in out GObject_Class; | |
Type_Name | : String; | |
Parameters | : Signal_Parameter_Types := Null_Parameter_Types) renames Glib.Object.Initialize_Class_Record; |
This is the base class of the widget hierarchy.
Everything in GtkAda inherits from this class Gtk_Object, except for a few structures in the Gdk.* packages (low-level drawing routines).
This class provides a set of handful features that you can choose to reuse in your applications:
- Reference counting: an object is not deleted while there exists at least one reference to it. Although GtkAda mostly takes care of that aspect transparently, you might need in some obscure cases to increment or decrement the reference counting for a widget manually, so that it is not removed from memory while you still need it.
- User data: any number of data can be attached to a Gtk_Object or one of its children. Theses data are referenced by a String, in a hash-table. GtkAda itself uses this feature to provide an easy conversion between C and Ada widgets. Although you might prefer to have a completely object-oriented application (and thus associate data through class inheritance), it might be convenient to directly attach some data to your objects.
- It also contains the basic structures and subprograms required for signal emission. This is of course used to implement the signal mechanism in GtkAda itself, but can also be used to implement a Model/View/Controller framework.
Note that a lot of functions provided in the C interface are not provided here. They are used to emulate an object-oriented language in C, which can of course be done much more conveniently in Ada. Therefore most of these functions are not needed.
Here is a brief explanation on how the reference counting and destruction process work. You should not have to understand all this to use GtkAda, but it might help anyway.
When an object (descendant of Gtk.Object) is created, it has initially a ref_count of 1. A flag is set to say the object is "floating". See the Flags functions in this package for how to retrieve the status of this flag.
When the object gets a parent (ie Gtk.Widget.Set_Parent is called, possibly from other subprograms like Gtk.Container.Add, Gtk.Box.Pack_Start, ...), the ref_count of the object is incremented to 2.
If the object was still "floating", it is also "sinked", ie its ref_count is decremented to 1, and the "floating" flag is cleared.
The same behavior as above happens when the object is registered as a top-level widget (i.e. we know it won't have any parent).
Thus the normal life cycle of an object is to have a ref_count to 1, and not be a "floating" object.
When the object is destroyed, the following happens: A temporary reference to the object is created (call to Ref), and ref_count to 2. The object is shutdown: It is removed from its parent (if any), and its ref_count is decremented to 1. The "destroy" signal is emitted, the user's handlers are called, and then all the handlers connected to the object are destroyed. The object is unref-ed. If its ref_count goes down to 0 (normal case), the memory used by the object and its user_data is freed.
Binding from C File version 2.8.17