1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --                Copyright (C) 2001-2013, 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 generic values as used in the 
  31. --  Glib object model. 
  32. -- 
  33. --  The main type in this package is GValues, which is the 
  34. --  equivalent of the C's (GValue*) array, i.e an array of unions.  This 
  35. --  package provides functions to extract the values from this type. 
  36. --  </description> 
  37. --  <c_version>1.3.15</c_version> 
  38. --  <group>Glib, the general-purpose library</group> 
  39.  
  40. with System; 
  41. with Interfaces.C.Strings; 
  42.  
  43. with Glib.Object; 
  44.  
  45. package Glib.Values is 
  46.  
  47.    --  <doc_ignore>Do not create automatic documentation for this package 
  48.  
  49.    type GValue is private; 
  50.    --  A generic value that can hold any of the types as provided in the 
  51.    --  Set and Get functions below. 
  52.  
  53.    type GValues is private; 
  54.    --  This type represents a table of values. Each argument of the 
  55.    --  table can be of any type. 
  56.    --  The index of the first element is always 1. 
  57.  
  58.    type GValue_Array is array (Gint range <>) of GValue; 
  59.  
  60.    function Make_Values (Nb : Guint) return GValues; 
  61.    --  Create a new GValues structure from scratch. This procedure 
  62.    --  causes the allocation of an underlying C array, and this memory 
  63.    --  should be deallocated after use using procedure Free (see below). 
  64.  
  65.    function Make_Values (Nb : Guint; Val : System.Address) return GValues; 
  66.    --  Build a GValues structure from the given C array. Nb should be the 
  67.    --  number of elements in the Values array. 
  68.  
  69.    procedure Free (Val : in out GValues); 
  70.    --  Deallocate the memory associated with the given Values array. 
  71.  
  72.    function Nth (Val : GValues; Num : Guint) return GValue; 
  73.    --  Return the Num-th element from Values. 
  74.  
  75.    ------------------------------------------------- 
  76.    -- Conversion functions, interfacing to GValue -- 
  77.    ------------------------------------------------- 
  78.  
  79.    procedure Init (Value : in out GValue; G_Type : Glib.GType); 
  80.    --  Set the type of Value to G_Type. This limits the operations you can then 
  81.    --  apply to Value. For instance, Value must have been initialized with 
  82.    --  a GType_Int before you can use Set_Int (see below). 
  83.    --  Note that for enumeration types, you shouldn't use GType_Enum, but 
  84.    --  rather the exact GType corresponding to the enumeration. 
  85.    --  If you need to store a reference-counted type in a GValue, it is 
  86.    --  recommanded that you use a type derived from Boxed (see Set_Boxed below) 
  87.  
  88.    procedure Unset (Value : in out GValue); 
  89.    --  Frees the memory allocate for Value (like strings contents) in the call 
  90.    --  to Init. You only need to call this function in cases where you have 
  91.    --  called Init yourself. 
  92.  
  93.    procedure Set_Char (Value : in out GValue; V_Char : Gchar); 
  94.    function  Get_Char (Value : GValue) return Gchar; 
  95.  
  96.    procedure Set_Uchar (Value : in out GValue; V_Uchar : Guchar); 
  97.    function  Get_Uchar (Value : GValue) return Guchar; 
  98.  
  99.    procedure Set_Boolean (Value : in out GValue; V_Boolean : Boolean); 
  100.    function  Get_Boolean (Value : GValue) return Boolean; 
  101.  
  102.    procedure Set_Int (Value : in out GValue; V_Int : Gint); 
  103.    function  Get_Int (Value : GValue) return Gint; 
  104.  
  105.    procedure Set_Uint (Value : in out GValue; V_Uint : Guint); 
  106.    function  Get_Uint (Value : GValue) return Guint; 
  107.  
  108.    procedure Set_Long (Value : in out GValue; V_Long : Glong); 
  109.    function  Get_Long (Value : GValue) return Glong; 
  110.  
  111.    procedure Set_Ulong (Value : in out GValue; V_Ulong : Gulong); 
  112.    function  Get_Ulong (Value : GValue) return Gulong; 
  113.  
  114.    procedure Set_Float (Value : in out GValue; V_Float : Gfloat); 
  115.    function  Get_Float (Value : GValue) return Gfloat; 
  116.  
  117.    procedure Set_Double (Value : in out GValue; V_Double : Gdouble); 
  118.    function  Get_Double (Value : GValue) return Gdouble; 
  119.  
  120.    procedure Set_String (Value : in out GValue; V_String : String); 
  121.    function  Get_String (Value : GValue) return String; 
  122.    function  Get_String (Value : GValue; Length : Gint) return String; 
  123.  
  124.    function  Get_Chars (Value : GValue) return Interfaces.C.Strings.chars_ptr; 
  125.  
  126.    procedure Set_Proxy (Value : in out GValue; V_Proxy : C_Proxy); 
  127.    function  Get_Proxy (Value : GValue) return C_Proxy; 
  128.  
  129.    procedure Set_Address (Value : in out GValue; V_Address : System.Address); 
  130.    function  Get_Address (Value : GValue) return System.Address; 
  131.  
  132.    procedure Set_Boxed (Value : in out GValue; V_Address : System.Address); 
  133.    function  Get_Boxed (Value : GValue) return System.Address; 
  134.    --  This is similar to Set_Address and Get_Address, except that the boxed 
  135.    --  type might have been associated with some specific initialization and 
  136.    --  finalization functions through Glib.Boxed_Type_Register_Static 
  137.    --  For instance: 
  138.    --    declare 
  139.    --       Typ   : Glib.GType; 
  140.    --       Value : GValue; 
  141.    --       function To_Ref_Counted_Value is new Ada.Unchecked_Conversion 
  142.    --          (System.Address, My_Ref_Counted_Type); 
  143.    --    begin 
  144.    --       Typ := Boxed_Typed_Register_Static 
  145.    --          ("FOO", Copy'Access, Free'Access); 
  146.    --       Init (Value, Typ); 
  147.    --       Set_Boxed (Value, my_ref_counted_value.all'address); 
  148.    -- 
  149.    --       Val := To_Ref_Counted_Value (Get_Boxed (Value)); 
  150.    --       Unset (Value); 
  151.    --    end; 
  152.    -- 
  153.    --  See also Glib.Generic_Properties.Generic_Internal_Boxed_Property. 
  154.  
  155.    procedure Set_Enum (Value : in out GValue; V_Enum : Gint); 
  156.    function Get_Enum (Value : GValue) return Glib.Gint; 
  157.    --  These are used to manipulate the standard GtkAda enumeration types. 
  158.    --  For types that you have redefined yourself, you have access to more 
  159.    --  suitable functions directly in the package Generic_Enumeration_Property. 
  160.  
  161.    procedure Set_Flags (Value : in out GValue; V_Enum : Guint); 
  162.    function Get_Flags (Value : GValue) return Glib.Guint; 
  163.    --  ??? Should really manipulate Glib.Properties.Creation.Flags_Int_Value 
  164.  
  165.    procedure Set_Object (Value : in out GValue; To : Glib.Object.GObject); 
  166.    function Get_Object (Value : GValue) return Glib.Object.GObject; 
  167.    --  These are used to manipulate GObject instances. 
  168.  
  169.    --  Convenience function to Get and Set a Gtk_Text_Iter are 
  170.    --  also provided inside Gtk.Text_Iter. 
  171.  
  172. private 
  173.    type GValue_Data is array (1 .. 2) of Guint64; 
  174.    type GValue is record 
  175.       g_type : GType := GType_Invalid; 
  176.       data   : GValue_Data; 
  177.    end record; 
  178.    pragma Convention (C, GValue); 
  179.  
  180.    type GValues is record 
  181.       Nb  : Guint; 
  182.       Arr : System.Address; 
  183.    end record; 
  184.  
  185.    pragma Import (C, Set_Char, "g_value_set_char"); 
  186.    pragma Import (C, Get_Char, "g_value_get_char"); 
  187.    pragma Import (C, Set_Uchar, "g_value_set_uchar"); 
  188.    pragma Import (C, Get_Uchar, "g_value_get_uchar"); 
  189.    pragma Import (C, Set_Int, "g_value_set_int"); 
  190.    pragma Import (C, Get_Int, "g_value_get_int"); 
  191.    pragma Import (C, Set_Uint, "g_value_set_uint"); 
  192.    pragma Import (C, Get_Uint, "g_value_get_uint"); 
  193.    pragma Import (C, Set_Long, "g_value_set_long"); 
  194.    pragma Import (C, Get_Long, "g_value_get_long"); 
  195.    pragma Import (C, Set_Ulong, "g_value_set_ulong"); 
  196.    pragma Import (C, Get_Ulong, "g_value_get_ulong"); 
  197.    pragma Import (C, Set_Float, "g_value_set_float"); 
  198.    pragma Import (C, Get_Float, "g_value_get_float"); 
  199.    pragma Import (C, Set_Double, "g_value_set_double"); 
  200.    pragma Import (C, Get_Double, "g_value_get_double"); 
  201.    pragma Import (C, Set_Proxy, "g_value_set_pointer"); 
  202.    pragma Import (C, Set_Address, "g_value_set_pointer"); 
  203.    pragma Import (C, Set_Enum, "g_value_set_enum"); 
  204.    pragma Import (C, Get_Enum, "g_value_get_enum"); 
  205.    pragma Import (C, Get_Chars, "g_value_get_string"); 
  206.    pragma Import (C, Set_Flags, "g_value_set_flags"); 
  207.    pragma Import (C, Get_Flags, "g_value_get_flags"); 
  208.    pragma Import (C, Set_Boxed, "g_value_set_boxed"); 
  209.    pragma Import (C, Get_Boxed, "g_value_get_boxed"); 
  210.    pragma Import (C, Unset, "g_value_unset"); 
  211.  
  212.    --  ??? We use our own version here, that doesn't check the type of 
  213.    --  GValue. This is used for signals (Gtk.Handlers), but should be 
  214.    --  cleaned up. 
  215.    pragma Import (C, Get_Address, "ada_gvalue_get_pointer"); 
  216.    pragma Import (C, Get_Proxy, "ada_gvalue_get_pointer"); 
  217.  
  218.    pragma Inline (Make_Values); 
  219.    pragma Inline (Set_Boolean); 
  220.    pragma Inline (Get_Boolean); 
  221.    pragma Inline (Set_String); 
  222.    pragma Inline (Get_String); 
  223.  
  224.    --  </doc_ignore> 
  225. end Glib.Values;