1. ------------------------------------------------------------------------------ 
  2. --                                                                          -- 
  3. --      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       -- 
  4. --                     Copyright (C) 2000-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. --  Glib.Action.Gaction represents a single named action. 
  26. -- 
  27. --  The main interface to an action is that it can be activated with 
  28. --  Glib.Action.Activate. This results in the 'activate' signal being emitted. 
  29. --  An activation has a Glib.Variant.Gvariant parameter (which may be null). 
  30. --  The correct type for the parameter is determined by a static parameter type 
  31. --  (which is given at construction time). 
  32. -- 
  33. --  An action may optionally have a state, in which case the state may be set 
  34. --  with Glib.Action.Change_State. This call takes a Glib.Variant.Gvariant. The 
  35. --  correct type for the state is determined by a static state type (which is 
  36. --  given at construction time). 
  37. -- 
  38. --  The state may have a hint associated with it, specifying its valid range. 
  39. -- 
  40. --  Glib.Action.Gaction is merely the interface to the concept of an action, 
  41. --  as described above. Various implementations of actions exist, including 
  42. --  Glib.Simple_Action.Gsimple_Action and Gtk.Action.Gtk_Action. 
  43. -- 
  44. --  In all cases, the implementing class is responsible for storing the name 
  45. --  of the action, the parameter type, the enabled state, the optional state 
  46. --  type and the state and emitting the appropriate signals when these change. 
  47. --  The implementor responsible for filtering calls to Glib.Action.Activate and 
  48. --  Glib.Action.Change_State for type safety and for the state being enabled. 
  49. -- 
  50. --  Probably the only useful thing to do with a Glib.Action.Gaction is to put 
  51. --  it inside of a Glib.Simple_Action_Group.Gsimple_Action_Group. 
  52. -- 
  53. --  </description> 
  54. pragma Ada_2005; 
  55.  
  56. pragma Warnings (Off, "*is already use-visible*"); 
  57. with Glib;            use Glib; 
  58. with Glib.Properties; use Glib.Properties; 
  59. with Glib.Types;      use Glib.Types; 
  60. with Glib.Variant;    use Glib.Variant; 
  61.  
  62. package Glib.Action is 
  63.  
  64.    type Gaction is new Glib.Types.GType_Interface; 
  65.    Null_Gaction : constant Gaction; 
  66.  
  67.    ------------------ 
  68.    -- Constructors -- 
  69.    ------------------ 
  70.  
  71.    function Get_Type return Glib.GType; 
  72.    pragma Import (C, Get_Type, "g_action_get_type"); 
  73.  
  74.    ------------- 
  75.    -- Methods -- 
  76.    ------------- 
  77.  
  78.    procedure Activate (Self : Gaction; Parameter : Glib.Variant.Gvariant); 
  79.    --  Activates the action. 
  80.    --  Parameter must be the correct type of parameter for the action (ie: the 
  81.    --  parameter type given at construction time). If the parameter type was 
  82.    --  null then Parameter must also be null. 
  83.    --  Since: gtk+ 2.28 
  84.    --  "parameter": the parameter to the activation 
  85.  
  86.    procedure Change_State (Self : Gaction; Value : Glib.Variant.Gvariant); 
  87.    --  Request for the state of Action to be changed to Value. 
  88.    --  The action must be stateful and Value must be of the correct type. See 
  89.    --  Glib.Action.Get_State_Type. 
  90.    --  This call merely requests a change. The action may refuse to change its 
  91.    --  state or may change its state to something other than Value. See 
  92.    --  Glib.Action.Get_State_Hint. 
  93.    --  If the Value GVariant is floating, it is consumed. 
  94.    --  Since: gtk+ 2.30 
  95.    --  "value": the new state 
  96.  
  97.    function Get_Enabled (Self : Gaction) return Boolean; 
  98.    --  Checks if Action is currently enabled. 
  99.    --  An action must be enabled in order to be activated or in order to have 
  100.    --  its state changed from outside callers. 
  101.    --  Since: gtk+ 2.28 
  102.  
  103.    function Get_Name (Self : Gaction) return UTF8_String; 
  104.    --  Queries the name of Action. 
  105.    --  Since: gtk+ 2.28 
  106.  
  107.    function Get_Parameter_Type 
  108.       (Self : Gaction) return Glib.Variant.Gvariant_Type; 
  109.    pragma Import (C, Get_Parameter_Type, "g_action_get_parameter_type"); 
  110.    --  Queries the type of the parameter that must be given when activating 
  111.    --  Action. 
  112.    --  When activating the action using Glib.Action.Activate, the 
  113.    --  Glib.Variant.Gvariant given to that function must be of the type 
  114.    --  returned by this function. 
  115.    --  In the case that this function returns null, you must not give any 
  116.    --  Glib.Variant.Gvariant, but null instead. 
  117.    --  Since: gtk+ 2.28 
  118.  
  119.    function Get_State (Self : Gaction) return Glib.Variant.Gvariant; 
  120.    --  Queries the current state of Action. 
  121.    --  If the action is not stateful then null will be returned. If the action 
  122.    --  is stateful then the type of the return value is the type given by 
  123.    --  Glib.Action.Get_State_Type. 
  124.    --  The return value (if non-null) should be freed with Glib.Variant.Unref 
  125.    --  when it is no longer required. 
  126.    --  Since: gtk+ 2.28 
  127.  
  128.    function Get_State_Hint (Self : Gaction) return Glib.Variant.Gvariant; 
  129.    --  Requests a hint about the valid range of values for the state of 
  130.    --  Action. 
  131.    --  If null is returned it either means that the action is not stateful or 
  132.    --  that there is no hint about the valid range of values for the state of 
  133.    --  the action. 
  134.    --  If a Glib.Variant.Gvariant array is returned then each item in the 
  135.    --  array is a possible value for the state. If a Glib.Variant.Gvariant pair 
  136.    --  (ie: two-tuple) is returned then the tuple specifies the inclusive lower 
  137.    --  and upper bound of valid values for the state. 
  138.    --  In any case, the information is merely a hint. It may be possible to 
  139.    --  have a state value outside of the hinted range and setting a value 
  140.    --  within the range may fail. 
  141.    --  The return value (if non-null) should be freed with Glib.Variant.Unref 
  142.    --  when it is no longer required. 
  143.    --  Since: gtk+ 2.28 
  144.  
  145.    function Get_State_Type 
  146.       (Self : Gaction) return Glib.Variant.Gvariant_Type; 
  147.    pragma Import (C, Get_State_Type, "g_action_get_state_type"); 
  148.    --  Queries the type of the state of Action. 
  149.    --  If the action is stateful (e.g. created with 
  150.    --  Glib.Simple_Action.G_New_Stateful) then this function returns the 
  151.    --  Glib.Variant.Gvariant_Type of the state. This is the type of the initial 
  152.    --  value given as the state. All calls to Glib.Action.Change_State must 
  153.    --  give a Glib.Variant.Gvariant of this type and Glib.Action.Get_State will 
  154.    --  return a Glib.Variant.Gvariant of the same type. 
  155.    --  If the action is not stateful (e.g. created with 
  156.    --  Glib.Simple_Action.G_New) then this function will return null. In that 
  157.    --  case, Glib.Action.Get_State will return null and you must not call 
  158.    --  Glib.Action.Change_State. 
  159.    --  Since: gtk+ 2.28 
  160.  
  161.    ---------------- 
  162.    -- Properties -- 
  163.    ---------------- 
  164.    --  The following properties are defined for this widget. See 
  165.    --  Glib.Properties for more information on properties) 
  166.  
  167.    Enabled_Property : constant Glib.Properties.Property_Boolean; 
  168.    --  If Action is currently enabled. 
  169.    -- 
  170.    --  If the action is disabled then calls to Glib.Action.Activate and 
  171.    --  Glib.Action.Change_State have no effect. 
  172.  
  173.    Name_Property : constant Glib.Properties.Property_String; 
  174.    --  The name of the action. This is mostly meaningful for identifying the 
  175.    --  action once it has been added to a Glib.Action_Group.Gaction_Group. 
  176.  
  177.    Parameter_Type_Property : constant Glib.Properties.Property_Boxed; 
  178.    --  Type: GLib.Variant_Type 
  179.    --  The type of the parameter that must be given when activating the 
  180.    --  action. 
  181.  
  182.    State_Property : constant Glib.Properties.Property_Object; 
  183.    --  Type: Glib.Variant.Gvariant 
  184.    --  The state of the action, or null if the action is stateless. 
  185.  
  186.    State_Type_Property : constant Glib.Properties.Property_Boxed; 
  187.    --  Type: GLib.Variant_Type 
  188.    --  The Glib.Variant.Gvariant_Type of the state that the action has, or 
  189.    --  null if the action is stateless. 
  190.  
  191.    ---------------- 
  192.    -- Interfaces -- 
  193.    ---------------- 
  194.    --  This class implements several interfaces. See Glib.Types 
  195.    -- 
  196.    --  - "Gaction" 
  197.  
  198.    function "+" (W : Gaction) return Gaction; 
  199.    pragma Inline ("+"); 
  200.  
  201. private 
  202.    State_Type_Property : constant Glib.Properties.Property_Boxed := 
  203.      Glib.Properties.Build ("state-type"); 
  204.    State_Property : constant Glib.Properties.Property_Object := 
  205.      Glib.Properties.Build ("state"); 
  206.    Parameter_Type_Property : constant Glib.Properties.Property_Boxed := 
  207.      Glib.Properties.Build ("parameter-type"); 
  208.    Name_Property : constant Glib.Properties.Property_String := 
  209.      Glib.Properties.Build ("name"); 
  210.    Enabled_Property : constant Glib.Properties.Property_Boolean := 
  211.      Glib.Properties.Build ("enabled"); 
  212.  
  213. Null_Gaction : constant Gaction := 
  214.    Gaction (Glib.Types.Null_Interface); 
  215. end Glib.Action;