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