1. ------------------------------------------------------------------------------ 
  2. --                  GtkAda - Ada95 binding for Gtk+/Gnome                   -- 
  3. --                                                                          -- 
  4. --                     Copyright (C) 2006-2014, AdaCore                     -- 
  5. --                                                                          -- 
  6. -- This library is free software;  you can redistribute it and/or modify it -- 
  7. -- under terms of the  GNU General Public License  as published by the Free -- 
  8. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  9. -- version. This library is distributed in the hope that it will be useful, -- 
  10. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  11. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  12. --                                                                          -- 
  13. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  14. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  15. -- version 3.1, as published by the Free Software Foundation.               -- 
  16. --                                                                          -- 
  17. -- You should have received a copy of the GNU General Public License and    -- 
  18. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  19. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  20. -- <http://www.gnu.org/licenses/>.                                          -- 
  21. --                                                                          -- 
  22. ------------------------------------------------------------------------------ 
  23.  
  24. --  <description> 
  25. --  This package provides an interface to the type system in Glib. These types 
  26. --  provide an object-oriented framework (through inheritance and interfaces), 
  27. --  as well as reference-counting, signals and properties on these types. 
  28. -- 
  29. --  Most of the time, you DO NOT need to use this package, only when you are 
  30. --  working with the introspection capabilities of glib. 
  31. -- 
  32. --  See the other glib packages for more subprograms to manipulate these types. 
  33. --  In particular, Glib.Properties describes the properties system, that 
  34. --  provide the base for dynamic introspection. See also Glib itself, which 
  35. --  contains several general subprograms, and Glib.Object that provides the 
  36. --  root object for any type hierarchy based on glib. 
  37. --  </description> 
  38. --  <group>Glib, the general-purpose library</group> 
  39.  
  40. with Glib.Object; 
  41. with System; 
  42.  
  43. package Glib.Types is 
  44.  
  45.    function Class_Peek (T : GType) return Glib.Object.GObject_Class; 
  46.    function Class_Ref  (T : GType) return Glib.Object.GObject_Class; 
  47.    --  Return the class structure encapsulated in T. 
  48.    --  Class_Ref will create the class on-demand if it doesn't exist yet, but 
  49.    --  Class_Peek might return null if the class hasn't been referenced before. 
  50.    --  Class_Ref also increments the reference counting for the returned value 
  51.  
  52.    procedure Class_Unref (T : GType); 
  53.    --  Decrement the reference counting on the associated class. When it 
  54.    --  reaches 0, the class may be finalized by the type system. 
  55.  
  56.    function Depth (T : GType) return Guint; 
  57.    --  Returns the length of the ancestry of the passed in type. This includes 
  58.    --  the type itself, so that e.g. a fundamental type has depth 1. 
  59.  
  60.    function Is_A (T : GType; Is_A_Type : GType) return Boolean; 
  61.    --  If Is_A_Type is a derivable type, check whether type is a descendant of 
  62.    --  Is_A_Type. If Is_A_Type is an interface, check whether type conforms to 
  63.    --  it. 
  64.  
  65.    ---------------- 
  66.    -- Interfaces -- 
  67.    ---------------- 
  68.    --  Interfaces are similar, in concept, to those found in Ada 2005 or in 
  69.    --  Java. They define a set of subprograms that any type implementing the 
  70.    --  interface must also define. They are different from standard inheritance 
  71.    --  since no implementation of these subprograms can be provided in the 
  72.    --  interface itself. 
  73.    -- 
  74.    --  Whereas an object can only derive from one other object, it can 
  75.    --  implement any number of interfaces. 
  76.    -- 
  77.    --  Some of the standard gtk+ objects implement interfaces. In this case, 
  78.    --  their Ada package contains one or more functions to convert from the 
  79.    --  object itself to the interface, for instance: 
  80.    -- 
  81.    --      package Implements_Cell_Layout is new Glib.Types.Implements (...); 
  82.    --      function "+" (...) renames Implements_Cell_Layout.To_Interface; 
  83.    --      function "-" (...) renames Implements_Cell_Layout.To_Object; 
  84.    -- 
  85.    --  The two unary operators "+" and "-" can be used to convert to and from 
  86.    --  the interface, for instance calling: 
  87.    --        View : Gtk_Cell_View; 
  88.    --        Gtk.Cell_Layout.Pack_Start (+View, Cell, Expand); 
  89.  
  90.    type GType_Interface is new System.Address; 
  91.    Null_Interface : constant GType_Interface; 
  92.  
  93.    --  <doc_ignore> 
  94.    generic 
  95.       type Interface_Type is new GType_Interface; 
  96.       type Object_Type_Record is new Glib.Object.GObject_Record with private; 
  97.       type Object_Type is access all Object_Type_Record'Class; 
  98.    package Implements is 
  99.       function To_Object (Interf : Interface_Type) return Object_Type; 
  100.       function To_Interface 
  101.         (Object : access Object_Type_Record'Class) return Interface_Type; 
  102.       --  These subprograms can be used to convert from an object to one of 
  103.       --  the interfaces it implements, and from an interface to the object 
  104.       --  itself. 
  105.    end Implements; 
  106.    --  </doc_ignore> 
  107.  
  108.    function To_Object 
  109.      (Interf : GType_Interface) return Glib.Object.GObject; 
  110.    --  Return the object that the interface represents. This is slightly 
  111.    --  different from using Implements.To_Object, in the case when the object 
  112.    --  wasn't created through Ada. In such a case, GtkAda needs to create an 
  113.    --  Ada wrapper around the object, and will choose a different tagged type: 
  114.    --     - Implements.To_Object creates a tagged type of type Object_Type. 
  115.    --     - This function creates a GObject, which you cannot cast easily 
  116.    --       to some other tagged type afterward. 
  117.    --  Both behave the same when the object was created from Ada. 
  118.  
  119.    function Interfaces (T : GType) return GType_Array; 
  120.    --  Return the list of interfaces implemented by objects of a given type. 
  121.  
  122.    function Is_Interface (T : GType) return Boolean; 
  123.    --  Whether T represents an interface type description 
  124.  
  125.    function Default_Interface_Peek 
  126.      (T : GType) return Glib.Object.Interface_Vtable; 
  127.    function Default_Interface_Ref 
  128.      (T : GType) return Glib.Object.Interface_Vtable; 
  129.    --  If the interface type T is currently in use, returns its default 
  130.    --  interface vtable. 
  131.    --  Default_Interface_Ref will create the default vtable for the type if the 
  132.    --  type is not currently in use. This is useful when you want to make sure 
  133.    --  that signals and properties for an interface have been installed. 
  134.  
  135. private 
  136.    Null_Interface : constant GType_Interface := GType_Interface 
  137.      (System.Null_Address); 
  138.  
  139.    pragma Import (C, Depth,                  "g_type_depth"); 
  140.    pragma Import (C, Class_Peek,             "g_type_class_peek"); 
  141.    pragma Import (C, Class_Ref,              "g_type_class_ref"); 
  142.    pragma Import (C, Class_Unref,            "g_type_class_unref"); 
  143.    pragma Import (C, Default_Interface_Peek, "g_type_default_interface_peek"); 
  144.    pragma Import (C, Default_Interface_Ref,  "g_type_default_interface_ref"); 
  145. end Glib.Types;