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