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. --  The GActionMap interface is implemented by Glib.Action_Group.Gaction_Group 
  26. --  implementations that operate by containing a number of named 
  27. --  Glib.Action.Gaction instances, such as 
  28. --  Glib.Simple_Action_Group.Gsimple_Action_Group. 
  29. -- 
  30. --  One useful application of this interface is to map the names of actions 
  31. --  from various action groups to unique, prefixed names (e.g. by prepending 
  32. --  "app." or "win."). This is the motivation for the 'Map' part of the 
  33. --  interface name. 
  34. -- 
  35. --  </description> 
  36. pragma Ada_2005; 
  37.  
  38. pragma Warnings (Off, "*is already use-visible*"); 
  39. with Glib;                 use Glib; 
  40. with Glib.Action;          use Glib.Action; 
  41. with Glib.Simple_Action;   use Glib.Simple_Action; 
  42. with Glib.Types;           use Glib.Types; 
  43. with Glib.Variant;         use Glib.Variant; 
  44. with Interfaces.C.Strings; use Interfaces.C.Strings; 
  45.  
  46. package Glib.Action_Map is 
  47.  
  48.    type Gaction_Map is new Glib.Types.GType_Interface; 
  49.    Null_Gaction_Map : constant Gaction_Map; 
  50.  
  51.    type GAction_Entry is private; 
  52.    function From_Object_Free (B : access GAction_Entry) return GAction_Entry; 
  53.    pragma Inline (From_Object_Free); 
  54.    --  This struct defines a single action. It is for use with 
  55.    --  Glib.Action_Map.Add_Action_Entries. 
  56.    -- 
  57.    --  The order of the items in the structure are intended to reflect 
  58.    --  frequency of use. It is permissible to use an incomplete initialiser in 
  59.    --  order to leave some of the later values as null. All values after Name 
  60.    --  are optional. Additional optional fields may be added in the future. 
  61.    -- 
  62.    --  See Glib.Action_Map.Add_Action_Entries for an example. 
  63.  
  64.    type GAction_Entry_Array is array (Natural range <>) of GAction_Entry; 
  65.  
  66.    ------------------ 
  67.    -- Constructors -- 
  68.    ------------------ 
  69.  
  70.    function Get_Type return Glib.GType; 
  71.    pragma Import (C, Get_Type, "g_action_map_get_type"); 
  72.  
  73.    ------------- 
  74.    -- Methods -- 
  75.    ------------- 
  76.  
  77.    procedure Add_Action (Self : Gaction_Map; Action : Glib.Action.Gaction); 
  78.    pragma Import (C, Add_Action, "g_action_map_add_action"); 
  79.    --  Adds an action to the Action_Map. 
  80.    --  If the action map already contains an action with the same name as 
  81.    --  Action then the old action is dropped from the action map. 
  82.    --  The action map takes its own reference on Action. 
  83.    --  Since: gtk+ 2.32 
  84.    --  "action": a Glib.Action.Gaction 
  85.  
  86.    procedure Add_Action_Entries 
  87.       (Self      : Gaction_Map; 
  88.        Entries   : GAction_Entry_Array; 
  89.        User_Data : System.Address := System.Null_Address); 
  90.    --  A convenience function for creating multiple 
  91.    --  Glib.Simple_Action.Gsimple_Action instances and adding them to a 
  92.    --  Glib.Action_Map.Gaction_Map. 
  93.    --  Each action is constructed as per one Glib.Action_Map.GAction_Entry. 
  94.    --  == Using Glib.Action_Map.Add_Action_Entries == 
  95.    --    static void 
  96.    --    activate_quit (GSimpleAction *simple, 
  97.    --       GVariant      *parameter, 
  98.    --       gpointer       user_data) 
  99.    --    { 
  100.    --       exit (0); 
  101.    --    } 
  102.    --    static void 
  103.    --    activate_print_string (GSimpleAction *simple, 
  104.    --       GVariant      *parameter, 
  105.    --       gpointer       user_data) 
  106.    --    { 
  107.    --       g_print ("%s\n", g_variant_get_string (parameter, NULL)); 
  108.    --    } 
  109.    --    static GActionGroup * 
  110.    --    create_action_group (void) 
  111.    --    { 
  112.    --       const GActionEntry entries[] = { 
  113.    --          { "quit",         activate_quit              }, 
  114.    --          { "print-string", activate_print_string, "s" } 
  115.    --       }; 
  116.    --       GSimpleActionGroup *group; 
  117.    --       group = g_simple_action_group_new (); 
  118.    --       g_action_map_add_action_entries (G_ACTION_MAP (group), entries, G_N_ELEMENTS (entries), NULL); 
  119.    --       return G_ACTION_GROUP (group); 
  120.    --    } 
  121.    --  Since: gtk+ 2.32 
  122.    --  "entries": a pointer to the first item in an array of 
  123.    --  Glib.Action_Map.GAction_Entry structs 
  124.    --  "user_data": the user data for signal connections 
  125.  
  126.    function Lookup_Action 
  127.       (Self        : Gaction_Map; 
  128.        Action_Name : UTF8_String) return Glib.Action.Gaction; 
  129.    --  Looks up the action with the name Action_Name in Action_Map. 
  130.    --  If no such action exists, returns null. 
  131.    --  Since: gtk+ 2.32 
  132.    --  "action_name": the name of an action 
  133.  
  134.    procedure Remove_Action (Self : Gaction_Map; Action_Name : UTF8_String); 
  135.    --  Removes the named action from the action map. 
  136.    --  If no action of this name is in the map then nothing happens. 
  137.    --  Since: gtk+ 2.32 
  138.    --  "action_name": the name of the action 
  139.  
  140.    ---------------------- 
  141.    -- GtkAda additions -- 
  142.    ---------------------- 
  143.  
  144.    type Activate_Callback is access procedure 
  145.      (Action    : access Glib.Simple_Action.Gsimple_Action; 
  146.       Parameter : Glib.Variant.Gvariant; 
  147.       Data      : System.Address); 
  148.    pragma Convention (C, Activate_Callback); 
  149.  
  150.    type Change_State_Callback is access procedure 
  151.      (Action    : access Glib.Simple_Action.Gsimple_Action; 
  152.       Parameter : Glib.Variant.Gvariant; 
  153.       Data      : System.Address); 
  154.    pragma Convention (C, Change_State_Callback); 
  155.  
  156.    function Build 
  157.      (Name           : String; 
  158.       Activate       : Activate_Callback := null; 
  159.       Parameter_Type : String := ""; 
  160.       State          : String := ""; 
  161.       Change_State   : Change_State_Callback := null) 
  162.    return GAction_Entry; 
  163.    --  Return a newly allocation action entry. 
  164.    --  This will be freed by the the action_map when needed. 
  165.    -- 
  166.    --  Name is the name of the action. 
  167.    --  Activate is the callback to connect to the "activate" signal of 
  168.    --  the action. 
  169.    --  Parameter_Type is the type of the parameter that must be passed 
  170.    --  to the activate function for this action, given as a single 
  171.    --  Gvariant (or the empty string for no parameter). 
  172.    --  State is the initial state of this action, given in Gvariant 
  173.    --  text format. The state is parsed with no extra type information 
  174.    --  so type tags must be added to the string if they are necessary. 
  175.    --  Change_State is the callback for the "change-state" signal. 
  176.  
  177.    ---------------- 
  178.    -- Interfaces -- 
  179.    ---------------- 
  180.    --  This class implements several interfaces. See Glib.Types 
  181.    -- 
  182.    --  - "Gaction_Map" 
  183.  
  184.    function "+" (W : Gaction_Map) return Gaction_Map; 
  185.    pragma Inline ("+"); 
  186.  
  187. private 
  188. type GAction_Entry is record 
  189.    Name : Interfaces.C.Strings.chars_ptr; 
  190.    Activate : System.Address; 
  191.    Parameter_Type : Interfaces.C.Strings.chars_ptr; 
  192.    State : Interfaces.C.Strings.chars_ptr; 
  193.    Change_State : System.Address; 
  194.    Padding : array_of_gsize (1 .. 3); 
  195. end record; 
  196. pragma Convention (C, GAction_Entry); 
  197.  
  198.  
  199. Null_Gaction_Map : constant Gaction_Map := 
  200.    Gaction_Map (Glib.Types.Null_Interface); 
  201. end Glib.Action_Map;