1. ------------------------------------------------------------------------------ 
  2. --               GtkAda - Ada95 binding for the Gimp Toolkit                -- 
  3. --                                                                          -- 
  4. --      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       -- 
  5. --                     Copyright (C) 1998-2014, AdaCore                     -- 
  6. --                                                                          -- 
  7. -- This library is free software;  you can redistribute it and/or modify it -- 
  8. -- under terms of the  GNU General Public License  as published by the Free -- 
  9. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  10. -- version. This library is distributed in the hope that it will be useful, -- 
  11. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  12. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  13. --                                                                          -- 
  14. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  15. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  16. -- version 3.1, as published by the Free Software Foundation.               -- 
  17. --                                                                          -- 
  18. -- You should have received a copy of the GNU General Public License and    -- 
  19. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  20. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  21. -- <http://www.gnu.org/licenses/>.                                          -- 
  22. --                                                                          -- 
  23. ------------------------------------------------------------------------------ 
  24.  
  25. --  <description> 
  26. -- 
  27. --  This package provides an implementation for hooks used in 
  28. --  Gtk.Type_Conversion. These hooks should be used when you import a new 
  29. --  C GObject, so that GtkAda can recreate the Ada structure from the 
  30. --  underlying C structure. 
  31. --  Note that when you create a GObject directly in Ada, you do not need to 
  32. --  provide any hook. 
  33. -- 
  34. --  Implementation note: This is a separate package from Gtk.Type_Conversion 
  35. --  so that adding a hook does not necessarily mean the user has to 'with' 
  36. --  Gtk.Type_Conversion, and thus all the packages from GtkAda. 
  37. -- 
  38. --  Note that this package is not thread safe. You should call the 
  39. --  function Add_Hook from the elaboration part of your packages. 
  40. -- 
  41. --  </description> 
  42. --  <group>Glib, the general-purpose library</group> 
  43.  
  44. with Glib.Object; use Glib.Object; 
  45.  
  46. package Glib.Type_Conversion_Hooks is 
  47.  
  48.    --  <doc_ignore> 
  49.  
  50.    function Conversion_Function 
  51.      (Obj : System.Address; Stub : GObject_Record'Class) return GObject; 
  52.    --  This function has to convert a C object to an Ada object. 
  53.    --  It will first try all the registered functions (in 
  54.    --  Glib.Type_Conversion_Hooks). If no match is found, then it will try 
  55.    --  recursively all parents of the C object. If no match is found at all, 
  56.    --  it will create an object of type Expected_Type, no matter what the real 
  57.    --  C type is. 
  58.  
  59.    type Get_GType_Func is access function return Glib.GType; 
  60.    pragma Convention (C, Get_GType_Func); 
  61.    --  Type used during the type conversion process 
  62.  
  63.    type Conversion_Creator_Hook_Type is 
  64.      access function (Expected_Object : GObject_Record'Class) return GObject; 
  65.  
  66.    --  </doc_ignore> 
  67.  
  68.    --  This package is used to allow automatic conversion from a C gtk object 
  69.    --  to Ada. 
  70.    --  To allow GtkAda to automatically bind an incoming externally created 
  71.    --  widget to the correct Ada type, you just need to instantiate this 
  72.    --  package, that will then automatically register the appropriate 
  73.    --  conversion methods. 
  74.    generic 
  75.       Get_GType : Get_GType_Func; 
  76.       --  This function returns the GType assiciated with the type we want to 
  77.       --  convert to. Usually, all widgets have a class-wide Get_Type that can 
  78.       --  directly be used here. 
  79.  
  80.       type Handled_Type is new GObject_Record with private; 
  81.       --  The type we want to convert to. 
  82.  
  83.    package Hook_Registrator is 
  84.  
  85.       function Creator (Expected_Object : GObject_Record'Class) return GObject; 
  86.       --  This function will create an Ada type corresponding to Handled_Type. 
  87.       --  In case Expected_Object is a child type of Handled_Type, an Ada 
  88.       --  object of type Expected_Object is returned instead. 
  89.       -- 
  90.       --  This allows convertion of types we know are expected, but don't have 
  91.       --  registered conversion hook functions. 
  92.  
  93.    private 
  94.       Creator_Access : constant Conversion_Creator_Hook_Type := Creator'Access; 
  95.       --  We need to create this access type here because of RM 3.10.2(28) 
  96.       --  It should go to the body, but conversion of Creator'Access to 
  97.       --  Conversion_Creator_Hook_Type is only allowed in the private section. 
  98.    end Hook_Registrator; 
  99.  
  100. end Glib.Type_Conversion_Hooks;