1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --   Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet   -- 
  5. --                Copyright (C) 2000-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 definitions for the basic types used in Glib, Cairo, 
  33. --  Gdk and Gtk. 
  34. -- 
  35. --  </description> 
  36. --  <group>Glib, the general-purpose library</group> 
  37.  
  38. with Ada.Unchecked_Deallocation; 
  39. with Ada.Unchecked_Conversion; 
  40. with System; 
  41. with Interfaces.C; 
  42.  
  43. package Glib is 
  44.    pragma Preelaborate; 
  45.  
  46.    package C renames Interfaces.C; 
  47.    use type C.int; 
  48.    use type C.unsigned; 
  49.  
  50.    ------------------------------------- 
  51.    -- The basic types defined by glib -- 
  52.    ------------------------------------- 
  53.  
  54.    type Gshort is new C.short; 
  55.    type Glong  is new C.long; 
  56.    type Gint   is new C.int; 
  57.    type Gchar  is new C.char; 
  58.    type Gboolean is new Gint; 
  59.  
  60.    type Gushort is new C.unsigned_short; 
  61.    type Gulong  is new C.unsigned_long; 
  62.    type Guint   is new C.unsigned; 
  63.    type Guchar  is new C.unsigned_char; 
  64.  
  65.    type Gfloat  is new C.C_float; 
  66.    type Gdouble is new C.double; 
  67.  
  68.    type Gint8  is range -(2 ** 7) .. (2 ** 7 - 1); 
  69.    type Gint16 is range -(2 ** 15) .. (2 ** 15 - 1); 
  70.    type Gint32 is range -(2 ** 31) .. (2 ** 31 - 1); 
  71.    type Gint64 is range -(2 ** 63) .. (2 ** 63 - 1); 
  72.  
  73.    type Guint8  is mod 2 ** 8; 
  74.    type Guint16 is mod 2 ** 16; 
  75.    type Guint32 is mod 2 ** 32; 
  76.    type Guint64 is mod 2 ** 64; 
  77.  
  78.    type Gsize is new C.size_t; 
  79.  
  80.    type Gunichar is new Guint32; 
  81.  
  82.    subtype UTF8_String is String; 
  83.    --  A string that accepts only valid UTF8 sequences. 
  84.    --  Most Gtk+ function expect valid UTF8 strings instead of regular strings. 
  85.  
  86.    type GTime_Val is record 
  87.       TV_Sec  : Glong; 
  88.       TV_Usec : Glong; 
  89.    end record; 
  90.    pragma Convention (C, GTime_Val); 
  91.  
  92.    type GTime_Val_Access is access all GTime_Val; 
  93.    pragma Convention (C, GTime_Val_Access); 
  94.  
  95.    subtype Grange_Float is Gdouble; 
  96.    --  Needed for better compatibility between GtkAda 1.2 and 2.0 
  97.  
  98.    subtype Gcolor_Int is Guint16; 
  99.    --  Provided for better compatibility between GtkAda 1.2 and 2.0 
  100.  
  101.    subtype Allocation_Int is Gint; 
  102.    --  Provided for better compatibility between GtkAda 1.2 and 2.0 
  103.  
  104.    ---------------------- 
  105.    -- Some Array types -- 
  106.    ---------------------- 
  107.  
  108.    type Gboolean_Array is array (Natural range <>) of Gboolean; 
  109.    type Gshort_Array   is array (Natural range <>) of Gshort; 
  110.    type Glong_Array    is array (Natural range <>) of Glong; 
  111.    type Gint_Array     is array (Natural range <>) of Gint; 
  112.    type Guint_Array    is array (Natural range <>) of Guint; 
  113.    type Guint32_Array  is array (Natural range <>) of Guint32; 
  114.    type Gushort_Array  is array (Natural range <>) of Gushort; 
  115.    type Gulong_Array   is array (Natural range <>) of Gulong; 
  116.    type Gfloat_Array   is array (Natural range <>) of Gfloat; 
  117.    type Guchar_Array   is array (Natural range <>) of Guchar; 
  118.    type Gdouble_Array  is array (Natural range <>) of Gdouble; 
  119.  
  120.    type Boolean_Array  is array (Natural range <>) of Boolean; 
  121.  
  122.    type Short_Array    is array (Natural range <>) of C.short; 
  123.    type Long_Array     is array (Natural range <>) of C.long; 
  124.  
  125.    ------------------------- 
  126.    -- Conversion services -- 
  127.    ------------------------- 
  128.  
  129.    function To_Boolean_Array (A : Gboolean_Array) return Boolean_Array; 
  130.    --  Convert a C-style boolean array into an Ada-style array. 
  131.  
  132.    function To_Gint (Bool : Boolean) return Gint; 
  133.    --  Convert an Ada boolean into a C int. 
  134.  
  135.    ----------------------- 
  136.    -- Some Access types -- 
  137.    ----------------------- 
  138.  
  139.    type Guchar_Array_Access is access Guchar_Array; 
  140.  
  141.    type String_Ptr is access all String; 
  142.  
  143.    --  <doc_ignore> 
  144.    procedure Free is new Ada.Unchecked_Deallocation 
  145.      (Object => Guchar_Array, Name => Guchar_Array_Access); 
  146.  
  147.    procedure Free is new Ada.Unchecked_Deallocation 
  148.      (Object => String, Name => String_Ptr); 
  149.    --  </doc_ignore> 
  150.  
  151.    --  <doc_ignore> 
  152.    type C_Dummy is limited private; 
  153.    --  </doc_ignore> 
  154.  
  155.    type C_Proxy is access all C_Dummy; 
  156.    --  General proxy for C structures. 
  157.    --  This type is used instead of System.Address so that the variables are 
  158.    --  automatically initialized to 'null'. 
  159.    --  The value pointed to is irrelevant, and in fact should not be accessed. 
  160.    --  It has thus been made limited private with no subprogram to access it. 
  161.    --  C_Proxy is a public type so that one can compare directly the value 
  162.    --  of the variables with 'null'. 
  163.  
  164.    --  <doc_ignore> 
  165.    pragma Convention (C, C_Proxy); 
  166.  
  167.    function To_Proxy is new Ada.Unchecked_Conversion (System.Address, C_Proxy); 
  168.    function To_Address is new 
  169.      Ada.Unchecked_Conversion (C_Proxy, System.Address); 
  170.    --  Converts from a System.Address returned by a C function to an 
  171.    --  internal C_Proxy. 
  172.  
  173.    --  </doc_ignore> 
  174.  
  175.    type G_Destroy_Notify_Address is 
  176.      access procedure (Data : System.Address); 
  177.    pragma Convention (C, G_Destroy_Notify_Address); 
  178.  
  179.    type G_Destroy_Notify is access procedure (Data : Glib.C_Proxy); 
  180.    pragma Convention (C, G_Destroy_Notify); 
  181.    --  Callback used when some named data associated with an object is 
  182.    --  destroyed. 
  183.  
  184.    ------------ 
  185.    -- Quarks -- 
  186.    ------------ 
  187.  
  188.    type GQuark is new Guint32; 
  189.    --  Represents a string internally in GtkAda. Once you know the 
  190.    --  equivalent for a string, you can always use it instead of the string, 
  191.    --  which provides a faster access for all the functions that use htables 
  192.    --  in GtkAda. 
  193.    --  There is a global htable that contains all the quarks defined in 
  194.    --  your application and GtkAda itself. 
  195.  
  196.    Unknown_Quark : constant GQuark := 0; 
  197.  
  198.    function Quark_From_String (Id : String) return GQuark; 
  199.    --  Return, or create the quark associated with the string. 
  200.    --  Note that if the quark does not already exist, an entry is created for 
  201.    --  it in the global htable for quarks. 
  202.  
  203.    function Quark_Try_String (Id : String) return GQuark; 
  204.    --  Return the quark associated with the string, if it exists. 
  205.    --  If it does not exist, return Unknown_Quark. 
  206.  
  207.    ------------- 
  208.    -- Signals -- 
  209.    ------------- 
  210.  
  211.    type Signal_Id is private; 
  212.    --  This uniquely identifies a connection widget<->signal. 
  213.  
  214.    type Signal_Name is new String; 
  215.    --  A signal name as used in connect, shared type between the Gtk 
  216.    --  and Glib layer. 
  217.  
  218.    Invalid_Signal_Id : constant Signal_Id; 
  219.    Null_Signal_Id : constant Signal_Id; 
  220.  
  221.    type G_Connect_Flags is mod 2 ** C.int'Size; 
  222.    G_Connect_After   : constant G_Connect_Flags := 2 ** 0; 
  223.    G_Connect_Swapped : constant G_Connect_Flags := 2 ** 1; 
  224.    --  Used to specify the behavior of a signal's connection. 
  225.  
  226.    ---------------- 
  227.    -- Properties -- 
  228.    ---------------- 
  229.    --  This is only the definition of the property types. See Glib.Properties 
  230.    --  on how to get and set the value of properties for specific objects, or 
  231.    --  the package Glib.Properties.Creation for information on how to create 
  232.    --  new properties in your own widgets. 
  233.    --  Introspection is available, ie from an existing object you can find out 
  234.    --  the list of properties it supports. See the functions 
  235.    --  Glib.Object.Interface_List_Properties and 
  236.    --  Glib.Object.Class_List_Properties 
  237.  
  238.    type Property (<>) is private; 
  239.  
  240.    function Build (Name : String) return Property; 
  241.    --  You should use this function only if you are creating new widgets, and 
  242.    --  their properties. Normal usage of properties doesn't require the use 
  243.    --  of this function. 
  244.    --  An ASCII.NUL character is automatically appended if necessary 
  245.  
  246.    function Property_Name (Prop : Property) return String; 
  247.    --  Return the name of the property. 
  248.    --  This name includes the trailing ASCII.Nul, and thus can be passed as is 
  249.    --  to C. 
  250.  
  251.    type Param_Spec is new Glib.C_Proxy; 
  252.    type Param_Spec_Array is array (Natural range <>) of Param_Spec; 
  253.    --  See Glib.Properties.Creation for more information on this type 
  254.  
  255.    type Param_Flags is mod 2 ** 6; 
  256.    Param_Readable       : constant Param_Flags := 2 ** 0; 
  257.    Param_Writable       : constant Param_Flags := 2 ** 1; 
  258.    Param_Construct      : constant Param_Flags := 2 ** 2; 
  259.    Param_Construct_Only : constant Param_Flags := 2 ** 3; 
  260.    Param_Lax_Validation : constant Param_Flags := 2 ** 4; 
  261.    Param_Private        : constant Param_Flags := 2 ** 5; 
  262.    --  These are the various flags that help define if, and when, a property 
  263.    --  can be read and modified. 
  264.  
  265.    ----------- 
  266.    -- GType -- 
  267.    ----------- 
  268.  
  269.    type GType is new Gsize; 
  270.    --  This type describes an internal type in Glib. 
  271.    --  You shouldn't have to use it in your own applications, however it might 
  272.    --  be useful sometimes. 
  273.    --  Every object type is associated with a specific value, created 
  274.    --  dynamically at run time the first time you instantiate an object of that 
  275.    --  type (thus if you have never used e.g a Gtk_File_Selection, it won't 
  276.    --  have any GType associated with it). 
  277.    --  You can get the exact type value for each type by using the functions 
  278.    --  Get_Type provided in all the packages in GtkAda. 
  279.    --  You can get the specific value for an existing widget by using the 
  280.    --  function Glib.Object.Get_Type. 
  281.  
  282.    type GType_Class is private; 
  283.    --  An opaque structure used as the base for all classes in glib and gtk+. 
  284.    --  See also Glib.Object.GObject_Class for a more useful child of this 
  285.    --  type. 
  286.  
  287.    type GType_Array is array (Guint range <>) of Glib.GType; 
  288.  
  289.    function Parent (Typ : GType) return GType; 
  290.    --  Return the parent type of Typ (eg if Typ is associated with a Gtk 
  291.    --  widget, it returns the typ of its parent). 
  292.  
  293.    function Fundamental (Typ : GType) return GType; 
  294.    --  Return the fundamental type for Type.  In gtk+, the types are organized 
  295.    --  into several hierarchies, similar to what is done for widgets. 
  296.    --  All of these hierarchies are based on one of the fundamental types 
  297.    --  defined below. 
  298.    --  This function returns that fundamental type. 
  299.    -- 
  300.    --  For instance, each enumeration type in gtk+ has its own GType. 
  301.    --  However, Fundamental will return GType_Enum in all of these cases. 
  302.  
  303.    function Type_Name (Type_Num : GType) return String; 
  304.    --  Return the name of the type (enumeration,...) associated with Typ. 
  305.    --  If Fundamental (Typ) return GType_Enum, this returns the name of 
  306.    --  the enumeration type that Typ represents. 
  307.    --  This might be useful in debug messages. 
  308.  
  309.    function Type_From_Name (Name : String) return GType; 
  310.    --  Convert a string to the matching type. 
  311.    --  Name should be the C GObject name rather than the Ada name: thus, 
  312.    --  use names such as GtkScrollbar or GtkButton for widgets. 
  313.  
  314.    function Get_Qdata (Typ : GType; Quark : GQuark) return Glib.C_Proxy; 
  315.    --  Return the user data set for Typ 
  316.  
  317.    procedure Set_Qdata 
  318.      (Typ     : GType; 
  319.       Quark   : GQuark; 
  320.       Data    : Glib.C_Proxy); 
  321.    --  Associate some named data with Typ. 
  322.  
  323.    --  The list of fundamental types defined in Glib. As opposed to most other 
  324.    --  types (for instance the ones used for widgets), the types have static 
  325.    --  values, always the same. 
  326.  
  327.    GType_Fundamental_Shift : constant Integer := 2; 
  328.  
  329.    GType_Invalid   : constant GType := 0 * (2 ** GType_Fundamental_Shift); 
  330.    GType_None      : constant GType := 1 * (2 ** GType_Fundamental_Shift); 
  331.    GType_Interface : constant GType := 2 * (2 ** GType_Fundamental_Shift); 
  332.  
  333.    GType_Char      : constant GType := 3 * (2 ** GType_Fundamental_Shift); 
  334.    GType_Uchar     : constant GType := 4 * (2 ** GType_Fundamental_Shift); 
  335.    GType_Boolean   : constant GType := 5 * (2 ** GType_Fundamental_Shift); 
  336.    GType_Int       : constant GType := 6 * (2 ** GType_Fundamental_Shift); 
  337.    GType_Uint      : constant GType := 7 * (2 ** GType_Fundamental_Shift); 
  338.    GType_Long      : constant GType := 8 * (2 ** GType_Fundamental_Shift); 
  339.    GType_Ulong     : constant GType := 9 * (2 ** GType_Fundamental_Shift); 
  340.    GType_Int64     : constant GType := 10 * (2 ** GType_Fundamental_Shift); 
  341.    GType_UInt64    : constant GType := 11 * (2 ** GType_Fundamental_Shift); 
  342.    GType_Enum      : constant GType := 12 * (2 ** GType_Fundamental_Shift); 
  343.    GType_Flags     : constant GType := 13 * (2 ** GType_Fundamental_Shift); 
  344.    GType_Float     : constant GType := 14 * (2 ** GType_Fundamental_Shift); 
  345.    GType_Double    : constant GType := 15 * (2 ** GType_Fundamental_Shift); 
  346.    GType_String    : constant GType := 16 * (2 ** GType_Fundamental_Shift); 
  347.    --  Null terminated string. 
  348.  
  349.    GType_Pointer   : constant GType := 17 * (2 ** GType_Fundamental_Shift); 
  350.    --  A general pointer type. 
  351.  
  352.    GType_Param     : constant GType := 19 * (2 ** GType_Fundamental_Shift); 
  353.    GType_Object    : constant GType := 20 * (2 ** GType_Fundamental_Shift); 
  354.    --  One of the widgets/objects 
  355.  
  356.    ----------------- 
  357.    -- Boxed types -- 
  358.    ----------------- 
  359.    --  Boxed types are a convenient way to encapsulate Ada types through a C 
  360.    --  layer. An initialization and a finalization function can be provided. 
  361.    --  The most frequent usage of such types is in argument to signals and 
  362.    --  handlers (See the functions in Glib.Values), or to store such types 
  363.    --  in a Gtk_Tree_Model. This allows you for instance to store reference 
  364.    --  counted types where you want to be able to control what should happen 
  365.    --  when the cell is removed from the tree. 
  366.    -- 
  367.    --  See an example with the subprogram Glib.Values.Set_Boxed 
  368.  
  369.    GType_Boxed     : constant GType := 18 * (2 ** GType_Fundamental_Shift); 
  370.    --  The base type for all boxed types. In tree models, you should use the 
  371.    --  actual type returned by Boxed_Type_Register_Static. 
  372.  
  373.    type Boxed_Copy is access 
  374.       function (Boxed : System.Address) return System.Address; 
  375.    pragma Convention (C, Boxed_Copy); 
  376.    type Boxed_Free is access procedure (Boxed : System.Address); 
  377.    pragma Convention (C, Boxed_Free); 
  378.  
  379.    function Boxed_Type_Register_Static 
  380.      (Name : String; 
  381.       Copy : Boxed_Copy; 
  382.       Free : Boxed_Free) return GType; 
  383.    --  Create a new boxed type 
  384.  
  385. private 
  386.    type C_Dummy is record 
  387.       Dummy1 : System.Address; 
  388.    end record; 
  389.    pragma Convention (C, C_Dummy); 
  390.    --  This array can contain anything, since it is never used on the Ada side 
  391.    --  anyway. Pretend it contains an address so that the compiler a 
  392.    --  reasonable default alignment, compatible with most types. 
  393.  
  394.    type GType_Class is new System.Address; 
  395.  
  396.    type Property is new String; 
  397.  
  398.    type Signal_Id is new Guint; 
  399.    Invalid_Signal_Id : constant Signal_Id := -1; 
  400.    Null_Signal_Id : constant Signal_Id := 0; 
  401.  
  402.    pragma Import (C, Fundamental, "ada_gtype_fundamental"); 
  403.    pragma Import (C, Parent, "g_type_parent"); 
  404.    pragma Import (C, Get_Qdata, "g_type_get_qdata"); 
  405.    pragma Import (C, Set_Qdata, "g_type_set_qdata"); 
  406.    pragma Inline (Build); 
  407.  
  408. end Glib;