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) 2001-2013, AdaCore                   -- 
  6. --                                                                   -- 
  7. -- This library is free software; you can redistribute it and/or     -- 
  8. -- modify it under the terms of the GNU General Public               -- 
  9. -- License as published by the Free Software Foundation; either      -- 
  10. -- version 2 of the License, or (at your option) any later version.  -- 
  11. --                                                                   -- 
  12. -- This library is distributed in the hope that it will be useful,   -- 
  13. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  14. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  15. -- General Public License for more details.                          -- 
  16. --                                                                   -- 
  17. -- You should have received a copy of the GNU General Public         -- 
  18. -- License along with this library; if not, write to the             -- 
  19. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  20. -- Boston, MA 02111-1307, USA.                                       -- 
  21. --                                                                   -- 
  22. -- As a special exception, if other files instantiate generics from  -- 
  23. -- this unit, or you link this unit with other files to produce an   -- 
  24. -- executable, this  unit  does not  by itself cause  the resulting  -- 
  25. -- executable to be covered by the GNU General Public License. This  -- 
  26. -- exception does not however invalidate any other reasons why the   -- 
  27. -- executable file  might be covered by the  GNU Public License.     -- 
  28. ----------------------------------------------------------------------- 
  29.  
  30. --  <description> 
  31. -- 
  32. --  This package provides an implementation for hooks used in 
  33. --  Gtk.Type_Conversion. These hooks should be used when you import a new 
  34. --  C GObject, so that GtkAda can recreate the Ada structure from the 
  35. --  underlying C structure. 
  36. --  Note that when you create a GObject directly in Ada, you do not need to 
  37. --  provide any hook. 
  38. -- 
  39. --  Implementation note: This is a separate package from Gtk.Type_Conversion 
  40. --  so that adding a hook does not necessarily mean the user has to 'with' 
  41. --  Gtk.Type_Conversion, and thus all the packages from GtkAda. 
  42. -- 
  43. --  Note that this package is not thread safe. You should call the 
  44. --  function Add_Hook from the elaboration part of your packages. 
  45. -- 
  46. --  </description> 
  47. --  <group>Glib, the general-purpose library</group> 
  48.  
  49. with Glib.Object; use Glib.Object; 
  50.  
  51. package Glib.Type_Conversion_Hooks is 
  52.  
  53.    --  <doc_ignore> 
  54.  
  55.    function Conversion_Function 
  56.      (Obj : System.Address; Stub : GObject_Record'Class) return GObject; 
  57.    --  This function has to convert a C object to an Ada object. 
  58.    --  It will first try all the registered functions (in 
  59.    --  Glib.Type_Conversion_Hooks). If no match is found, then it will try 
  60.    --  recursively all parents of the C object. If no match is found at all, 
  61.    --  it will create an object of type Expected_Type, no matter what the real 
  62.    --  C type is. 
  63.  
  64.    type Get_GType_Func is access function return Glib.GType; 
  65.    pragma Convention (C, Get_GType_Func); 
  66.    --  Type used during the type conversion process 
  67.  
  68.    type Conversion_Creator_Hook_Type is 
  69.      access function (Expected_Object : GObject_Record'Class) return GObject; 
  70.  
  71.    --  </doc_ignore> 
  72.  
  73.    --  This package is used to allow automatic conversion from a C gtk object 
  74.    --  to Ada. 
  75.    --  To allow GtkAda to automatically bind an incoming externally created 
  76.    --  widget to the correct Ada type, you just need to instantiate this 
  77.    --  package, that will then automatically register the appropriate 
  78.    --  conversion methods. 
  79.    generic 
  80.       Get_GType : Get_GType_Func; 
  81.       --  This function returns the GType assiciated with the type we want to 
  82.       --  convert to. Usually, all widgets have a class-wide Get_Type that can 
  83.       --  directly be used here. 
  84.  
  85.       type Handled_Type is new GObject_Record with private; 
  86.       --  The type we want to convert to. 
  87.  
  88.    package Hook_Registrator is 
  89.  
  90.       function Creator (Expected_Object : GObject_Record'Class) return GObject; 
  91.       --  This function will create an Ada type corresponding to Handled_Type. 
  92.       --  In case Expected_Object is a child type of Handled_Type, an Ada 
  93.       --  object of type Expected_Object is returned instead. 
  94.       -- 
  95.       --  This allows convertion of types we know are expected, but don't have 
  96.       --  registered conversion hook functions. 
  97.  
  98.    private 
  99.       Creator_Access : constant Conversion_Creator_Hook_Type := Creator'Access; 
  100.       --  We need to create this access type here because of RM 3.10.2(28) 
  101.       --  It should go to the body, but conversion of Creator'Access to 
  102.       --  Conversion_Creator_Hook_Type is only allowed in the private section. 
  103.    end Hook_Registrator; 
  104.  
  105. end Glib.Type_Conversion_Hooks;