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