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. --  A Glib.Simple_Action.Gsimple_Action is the obvious simple implementation 
  26. --  of the Glib.Action.Gaction interface. This is the easiest way to create an 
  27. --  action for purposes of adding it to a 
  28. --  Glib.Simple_Action_Group.Gsimple_Action_Group. 
  29. -- 
  30. --  See also Gtk.Action.Gtk_Action. 
  31. -- 
  32. --  </description> 
  33. pragma Ada_2005; 
  34.  
  35. pragma Warnings (Off, "*is already use-visible*"); 
  36. with Glib;            use Glib; 
  37. with Glib.Action;     use Glib.Action; 
  38. with Glib.Object;     use Glib.Object; 
  39. with Glib.Properties; use Glib.Properties; 
  40. with Glib.Types;      use Glib.Types; 
  41. with Glib.Variant;    use Glib.Variant; 
  42.  
  43. package Glib.Simple_Action is 
  44.  
  45.    type Gsimple_Action_Record is new GObject_Record with null record; 
  46.    type Gsimple_Action is access all Gsimple_Action_Record'Class; 
  47.  
  48.    ------------------ 
  49.    -- Constructors -- 
  50.    ------------------ 
  51.  
  52.    procedure G_New 
  53.       (Self           : out Gsimple_Action; 
  54.        Name           : UTF8_String; 
  55.        Parameter_Type : Glib.Variant.Gvariant_Type); 
  56.    --  Creates a new action. 
  57.    --  The created action is stateless. See Glib.Simple_Action.G_New_Stateful. 
  58.    --  Since: gtk+ 2.28 
  59.    --  "name": the name of the action 
  60.    --  "parameter_type": the type of parameter to the activate function 
  61.  
  62.    procedure Initialize 
  63.       (Self           : not null access Gsimple_Action_Record'Class; 
  64.        Name           : UTF8_String; 
  65.        Parameter_Type : Glib.Variant.Gvariant_Type); 
  66.    --  Creates a new action. 
  67.    --  The created action is stateless. See Glib.Simple_Action.G_New_Stateful. 
  68.    --  Since: gtk+ 2.28 
  69.    --  "name": the name of the action 
  70.    --  "parameter_type": the type of parameter to the activate function 
  71.  
  72.    function Gsimple_Action_New 
  73.       (Name           : UTF8_String; 
  74.        Parameter_Type : Glib.Variant.Gvariant_Type) return Gsimple_Action; 
  75.    --  Creates a new action. 
  76.    --  The created action is stateless. See Glib.Simple_Action.G_New_Stateful. 
  77.    --  Since: gtk+ 2.28 
  78.    --  "name": the name of the action 
  79.    --  "parameter_type": the type of parameter to the activate function 
  80.  
  81.    procedure G_New_Stateful 
  82.       (Self           : out Gsimple_Action; 
  83.        Name           : UTF8_String; 
  84.        Parameter_Type : Glib.Variant.Gvariant_Type; 
  85.        State          : Glib.Variant.Gvariant); 
  86.    --  Creates a new stateful action. 
  87.    --  State is the initial state of the action. All future state values must 
  88.    --  have the same Glib.Variant.Gvariant_Type as the initial state. 
  89.    --  If the State GVariant is floating, it is consumed. 
  90.    --  Since: gtk+ 2.28 
  91.    --  "name": the name of the action 
  92.    --  "parameter_type": the type of the parameter to the activate function 
  93.    --  "state": the initial state of the action 
  94.  
  95.    procedure Initialize_Stateful 
  96.       (Self           : not null access Gsimple_Action_Record'Class; 
  97.        Name           : UTF8_String; 
  98.        Parameter_Type : Glib.Variant.Gvariant_Type; 
  99.        State          : Glib.Variant.Gvariant); 
  100.    --  Creates a new stateful action. 
  101.    --  State is the initial state of the action. All future state values must 
  102.    --  have the same Glib.Variant.Gvariant_Type as the initial state. 
  103.    --  If the State GVariant is floating, it is consumed. 
  104.    --  Since: gtk+ 2.28 
  105.    --  "name": the name of the action 
  106.    --  "parameter_type": the type of the parameter to the activate function 
  107.    --  "state": the initial state of the action 
  108.  
  109.    function Gsimple_Action_New_Stateful 
  110.       (Name           : UTF8_String; 
  111.        Parameter_Type : Glib.Variant.Gvariant_Type; 
  112.        State          : Glib.Variant.Gvariant) return Gsimple_Action; 
  113.    --  Creates a new stateful action. 
  114.    --  State is the initial state of the action. All future state values must 
  115.    --  have the same Glib.Variant.Gvariant_Type as the initial state. 
  116.    --  If the State GVariant is floating, it is consumed. 
  117.    --  Since: gtk+ 2.28 
  118.    --  "name": the name of the action 
  119.    --  "parameter_type": the type of the parameter to the activate function 
  120.    --  "state": the initial state of the action 
  121.  
  122.    function Get_Type return Glib.GType; 
  123.    pragma Import (C, Get_Type, "g_simple_action_get_type"); 
  124.  
  125.    ------------- 
  126.    -- Methods -- 
  127.    ------------- 
  128.  
  129.    procedure Set_Enabled 
  130.       (Self    : not null access Gsimple_Action_Record; 
  131.        Enabled : Boolean); 
  132.    --  Sets the action as enabled or not. 
  133.    --  An action must be enabled in order to be activated or in order to have 
  134.    --  its state changed from outside callers. 
  135.    --  This should only be called by the implementor of the action. Users of 
  136.    --  the action should not attempt to modify its enabled flag. 
  137.    --  Since: gtk+ 2.28 
  138.    --  "enabled": whether the action is enabled 
  139.  
  140.    procedure Set_State 
  141.       (Self  : not null access Gsimple_Action_Record; 
  142.        Value : Glib.Variant.Gvariant); 
  143.    --  Sets the state of the action. 
  144.    --  This directly updates the 'state' property to the given value. 
  145.    --  This should only be called by the implementor of the action. Users of 
  146.    --  the action should not attempt to directly modify the 'state' property. 
  147.    --  Instead, they should call Glib.Action.Change_State to request the 
  148.    --  change. 
  149.    --  Since: gtk+ 2.30 
  150.    --  "value": the new Glib.Variant.Gvariant for the state 
  151.  
  152.    --------------------------------------------- 
  153.    -- Inherited subprograms (from interfaces) -- 
  154.    --------------------------------------------- 
  155.  
  156.    procedure Activate 
  157.       (Self      : not null access Gsimple_Action_Record; 
  158.        Parameter : Glib.Variant.Gvariant); 
  159.  
  160.    procedure Change_State 
  161.       (Self  : not null access Gsimple_Action_Record; 
  162.        Value : Glib.Variant.Gvariant); 
  163.  
  164.    function Get_Enabled 
  165.       (Self : not null access Gsimple_Action_Record) return Boolean; 
  166.  
  167.    function Get_Name 
  168.       (Self : not null access Gsimple_Action_Record) return UTF8_String; 
  169.  
  170.    function Get_Parameter_Type 
  171.       (Self : not null access Gsimple_Action_Record) 
  172.        return Glib.Variant.Gvariant_Type; 
  173.  
  174.    function Get_State 
  175.       (Self : not null access Gsimple_Action_Record) 
  176.        return Glib.Variant.Gvariant; 
  177.  
  178.    function Get_State_Hint 
  179.       (Self : not null access Gsimple_Action_Record) 
  180.        return Glib.Variant.Gvariant; 
  181.  
  182.    function Get_State_Type 
  183.       (Self : not null access Gsimple_Action_Record) 
  184.        return Glib.Variant.Gvariant_Type; 
  185.  
  186.    ---------------- 
  187.    -- Properties -- 
  188.    ---------------- 
  189.    --  The following properties are defined for this widget. See 
  190.    --  Glib.Properties for more information on properties) 
  191.  
  192.    Enabled_Property : constant Glib.Properties.Property_Boolean; 
  193.    --  If Action is currently enabled. 
  194.    -- 
  195.    --  If the action is disabled then calls to Glib.Action.Activate and 
  196.    --  Glib.Action.Change_State have no effect. 
  197.  
  198.    Name_Property : constant Glib.Properties.Property_String; 
  199.    --  The name of the action. This is mostly meaningful for identifying the 
  200.    --  action once it has been added to a 
  201.    --  Glib.Simple_Action_Group.Gsimple_Action_Group. 
  202.  
  203.    Parameter_Type_Property : constant Glib.Properties.Property_Boxed; 
  204.    --  Type: GLib.Variant_Type 
  205.    --  The type of the parameter that must be given when activating the 
  206.    --  action. 
  207.  
  208.    State_Property : constant Glib.Properties.Property_Object; 
  209.    --  Type: Glib.Variant.Gvariant 
  210.    --  The state of the action, or null if the action is stateless. 
  211.  
  212.    State_Type_Property : constant Glib.Properties.Property_Boxed; 
  213.    --  Type: GLib.Variant_Type 
  214.    --  The Glib.Variant.Gvariant_Type of the state that the action has, or 
  215.    --  null if the action is stateless. 
  216.  
  217.    ------------- 
  218.    -- Signals -- 
  219.    ------------- 
  220.  
  221.    type Cb_Gsimple_Action_Gvariant_Void is not null access procedure 
  222.      (Self      : access Gsimple_Action_Record'Class; 
  223.       Parameter : Glib.Variant.Gvariant); 
  224.  
  225.    type Cb_GObject_Gvariant_Void is not null access procedure 
  226.      (Self      : access Glib.Object.GObject_Record'Class; 
  227.       Parameter : Glib.Variant.Gvariant); 
  228.  
  229.    Signal_Activate : constant Glib.Signal_Name := "activate"; 
  230.    procedure On_Activate 
  231.       (Self  : not null access Gsimple_Action_Record; 
  232.        Call  : Cb_Gsimple_Action_Gvariant_Void; 
  233.        After : Boolean := False); 
  234.    procedure On_Activate 
  235.       (Self  : not null access Gsimple_Action_Record; 
  236.        Call  : Cb_GObject_Gvariant_Void; 
  237.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  238.        After : Boolean := False); 
  239.    --  Indicates that the action was just activated. 
  240.    -- 
  241.    --  Parameter will always be of the expected type. In the event that an 
  242.    --  incorrect type was given, no signal will be emitted. 
  243.  
  244.    Signal_Change_State : constant Glib.Signal_Name := "change-state"; 
  245.    procedure On_Change_State 
  246.       (Self  : not null access Gsimple_Action_Record; 
  247.        Call  : Cb_Gsimple_Action_Gvariant_Void; 
  248.        After : Boolean := False); 
  249.    procedure On_Change_State 
  250.       (Self  : not null access Gsimple_Action_Record; 
  251.        Call  : Cb_GObject_Gvariant_Void; 
  252.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  253.        After : Boolean := False); 
  254.    --  Indicates that the action just received a request to change its state. 
  255.    -- 
  256.    --  Value will always be of the correct state type. In the event that an 
  257.    --  incorrect type was given, no signal will be emitted. 
  258.    -- 
  259.    --  If no handler is connected to this signal then the default behaviour is 
  260.    --  to call Glib.Simple_Action.Set_State to set the state to the requested 
  261.    --  value. If you connect a signal handler then no default action is taken. 
  262.    --  If the state should change then you must call 
  263.    --  Glib.Simple_Action.Set_State from the handler. 
  264.    -- 
  265.    --  == Example 'change-state' handler == 
  266.    -- 
  267.    --    static void 
  268.    --    change_volume_state (GSimpleAction *action, 
  269.    --       GVariant      *value, 
  270.    --       gpointer       user_data) 
  271.    --    { 
  272.    --       gint requested; 
  273.    --       requested = g_variant_get_int32 (value); 
  274.    --       // Volume only goes from 0 to 10 
  275.    --       if (0 <= requested && requested <= 10) 
  276.    --       g_simple_action_set_state (action, value); 
  277.    --    } 
  278.    -- 
  279.    --  The handler need not set the state to the requested value. It could set 
  280.    --  it to any value at all, or take some other action. 
  281.  
  282.    ---------------- 
  283.    -- Interfaces -- 
  284.    ---------------- 
  285.    --  This class implements several interfaces. See Glib.Types 
  286.    -- 
  287.    --  - "Action" 
  288.  
  289.    package Implements_Gaction is new Glib.Types.Implements 
  290.      (Glib.Action.Gaction, Gsimple_Action_Record, Gsimple_Action); 
  291.    function "+" 
  292.      (Widget : access Gsimple_Action_Record'Class) 
  293.    return Glib.Action.Gaction 
  294.    renames Implements_Gaction.To_Interface; 
  295.    function "-" 
  296.      (Interf : Glib.Action.Gaction) 
  297.    return Gsimple_Action 
  298.    renames Implements_Gaction.To_Object; 
  299.  
  300. private 
  301.    State_Type_Property : constant Glib.Properties.Property_Boxed := 
  302.      Glib.Properties.Build ("state-type"); 
  303.    State_Property : constant Glib.Properties.Property_Object := 
  304.      Glib.Properties.Build ("state"); 
  305.    Parameter_Type_Property : constant Glib.Properties.Property_Boxed := 
  306.      Glib.Properties.Build ("parameter-type"); 
  307.    Name_Property : constant Glib.Properties.Property_String := 
  308.      Glib.Properties.Build ("name"); 
  309.    Enabled_Property : constant Glib.Properties.Property_Boolean := 
  310.      Glib.Properties.Build ("enabled"); 
  311. end Glib.Simple_Action;