1. ----------------------------------------------------------------------- 
  2. --              GtkAda - Ada95 binding for Gtk+/Gnome                -- 
  3. --                                                                   -- 
  4. --                Copyright (C) 2006-2013, 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. -- As a special exception, if other files instantiate generics from  -- 
  22. -- this unit, or you link this unit with other files to produce an   -- 
  23. -- executable, this  unit  does not  by itself cause  the resulting  -- 
  24. -- executable to be covered by the GNU General Public License. This  -- 
  25. -- exception does not however invalidate any other reasons why the   -- 
  26. -- executable file  might be covered by the  GNU Public License.     -- 
  27. ----------------------------------------------------------------------- 
  28.  
  29. --  <description> 
  30. --  Actions are organised into groups. An action group is essentially a map 
  31. --  from names to Gtk_Action objects. 
  32. -- 
  33. --  All actions that would make sense to use in a particular context should be 
  34. --  in a single group. Multiple action groups may be used for a particular user 
  35. --  interface. In fact, it is expected that most nontrivial applications will 
  36. --  make use of multiple groups. For example, in an application that can edit 
  37. --  multiple documents, one group holding global actions (e.g. quit, about, 
  38. --  new), and one group per document holding actions that act on that document 
  39. --  (eg. save, cut/copy/paste, etc). Each window's menus would be constructed 
  40. --  from a combination of two action groups. 
  41. -- 
  42. --  Accelerators are handled by the GTK+ accelerator map. All actions are 
  43. --  assigned an accelerator path (which normally has the form 
  44. --  "<Actions>/group-name/action-name") and a shortcut is associated with this 
  45. --  accelerator path. All menu items and tool items take on this accelerator 
  46. --  path. The GTK+ accelerator map code makes sure that the correct shortcut is 
  47. --  displayed next to the menu item. 
  48. --  </description> 
  49. --  <c_version>2.8.17</c_version> 
  50. --  <group>Action-based menus</group> 
  51.  
  52. with Glib.Object; 
  53. with Glib.Properties; 
  54. with Gtk.Action; 
  55. with Interfaces.C.Strings; 
  56. with System; 
  57.  
  58. package Gtk.Action_Group is 
  59.  
  60.    type Gtk_Action_Group_Record is new Glib.Object.GObject_Record with 
  61.      null record; 
  62.    type Gtk_Action_Group is access all Gtk_Action_Group_Record'Class; 
  63.  
  64.    procedure Gtk_New (Group : out Gtk_Action_Group; Name : String); 
  65.    procedure Initialize 
  66.      (Group : access Gtk_Action_Group_Record'Class; Name : String); 
  67.    --  Creates a new Gtk_Action_Group object. The name of the action group 
  68.    --  is used when associating keybindings with the actions. 
  69.  
  70.    function Get_Type return GType; 
  71.    --  Return the internal value associated with a Gtk_Action_Group. 
  72.  
  73.    function Get_Action 
  74.      (Action_Group : access Gtk_Action_Group_Record; 
  75.       Action_Name  : String) return Gtk.Action.Gtk_Action; 
  76.    --  Looks up an action in the action group by name, or null if no such 
  77.    --  action exists. 
  78.  
  79.    function Get_Name 
  80.      (Action_Group : access Gtk_Action_Group_Record) return String; 
  81.    --  Gets the name of the action group. 
  82.  
  83.    procedure Set_Sensitive 
  84.      (Action_Group : access Gtk_Action_Group_Record; Sensitive : Boolean); 
  85.    function Get_Sensitive 
  86.      (Action_Group : access Gtk_Action_Group_Record) return Boolean; 
  87.    --  Returns True if the group is sensitive.  The constituent actions 
  88.    --  can only be logically sensitive (see Gtk.Action.Is_Sensitive) if 
  89.    --  they are sensitive (see Gtk.Action.Get_Sensitive) and their group 
  90.    --  is sensitive. 
  91.  
  92.    procedure Set_Visible 
  93.      (Action_Group : access Gtk_Action_Group_Record; Visible : Boolean); 
  94.    function Get_Visible 
  95.      (Action_Group : access Gtk_Action_Group_Record) return Boolean; 
  96.    --  Returns True if the group is visible.  The constituent actions 
  97.    --  can only be logically visible (see Gtk.Action.Is_Visible) if 
  98.    --  they are visible (see Gtk.Action.Get_Visible) and their group 
  99.    --  is visible. 
  100.  
  101.    function List_Actions 
  102.      (Action_Group : access Gtk_Action_Group_Record) 
  103.      return Glib.Object.Object_Simple_List.Glist; 
  104.    --  Lists the actions in the action group. The returned list must be freed 
  105.    --  by the user. 
  106.  
  107.    procedure Set_Translation_Domain 
  108.      (Action_Group : access Gtk_Action_Group_Record; 
  109.       Domain       : String); 
  110.    --  Sets the translation domain and uses dgettext() for translating the 
  111.    --  Label and Tooltip of Gtk_Action_Entry's added by Add_Actions. 
  112.  
  113.    --------------------------------- 
  114.    -- Adding and removing actions -- 
  115.    --------------------------------- 
  116.  
  117.    type Action_Entry        is private; 
  118.    type Radio_Action_Entry  is private; 
  119.    type Toggle_Action_Entry is private; 
  120.    --  An opaque structure describing an action entry 
  121.  
  122.    type Action_Entry_Array is array (Natural range <>) of Action_Entry; 
  123.    type Radio_Action_Entry_Array 
  124.      is array (Natural range <>) of Radio_Action_Entry; 
  125.    type Toggle_Action_Entry_Array 
  126.      is array (Natural range <>) of Toggle_Action_Entry; 
  127.  
  128.    type Action_Callback is access procedure 
  129.      (Action : System.Address; User_Data : System.Address); 
  130.    pragma Convention (C, Action_Callback); 
  131.    --  Profile of callbacks when an action is activated. You must convert 
  132.    --  Action to a Gtk_Action through: 
  133.    --      Act : constant Gtk_Action := Convert (Action); 
  134.  
  135.    type Radio_Action_Callback is access procedure 
  136.      (Group     : access Gtk.Action.Gtk_Action_Record'Class; 
  137.       Current   : access Gtk.Action.Gtk_Action_Record'Class; 
  138.       User_Data : System.Address); 
  139.    --   Called when an element of the Gtk_Radio_Action group is selected 
  140.  
  141.    function Create 
  142.      (Name        : String; 
  143.       Label       : String := ""; 
  144.       Stock_Id    : String := ""; 
  145.       Accelerator : String := ""; 
  146.       Tooltip     : String := ""; 
  147.       Callback    : Action_Callback := null) return Action_Entry; 
  148.    --  Create a new Action_Entry. The returned value must be freed by the 
  149.    --  caller. 
  150.  
  151.    function Create 
  152.      (Name        : String; 
  153.       Label       : String := ""; 
  154.       Stock_Id    : String := ""; 
  155.       Accelerator : String := ""; 
  156.       Tooltip     : String := ""; 
  157.       Callback    : Action_Callback := null; 
  158.       Is_Active   : Boolean := True) return Toggle_Action_Entry; 
  159.    --  Create a new Action_Entry. The returned value must be freed by the 
  160.    --  caller. Is_Active is the initial state of the button. 
  161.  
  162.    function Create 
  163.      (Name        : String; 
  164.       Label       : String; 
  165.       Stock_Id    : String := ""; 
  166.       Accelerator : String := ""; 
  167.       Tooltip     : String := ""; 
  168.       Value       : Glib.Gint) return Radio_Action_Entry; 
  169.    --  Create a new Radio_Action_Entry. Value is the value set on the radio 
  170.    --  action (see Gtk.Radio_Action.Get_Current_Value) 
  171.  
  172.    procedure Free (Action  : in out Action_Entry); 
  173.    procedure Free (Actions : in out Action_Entry_Array); 
  174.    procedure Free (Action  : in out Radio_Action_Entry); 
  175.    procedure Free (Actions : in out Radio_Action_Entry_Array); 
  176.    procedure Free (Action  : in out Toggle_Action_Entry); 
  177.    procedure Free (Actions : in out Toggle_Action_Entry_Array); 
  178.    --  Free Action and Actions 
  179.  
  180.    procedure Add_Action 
  181.      (Action_Group : access Gtk_Action_Group_Record; 
  182.       Action       : access Gtk.Action.Gtk_Action_Record'Class); 
  183.    --  Adds an action object to the action group. Note that this function 
  184.    --  does not set up the accel path of the action, which can lead to problems 
  185.    --  if a user tries to modify the accelerator of a menuitem associated with 
  186.    --  the action. Therefore you must either set the accel path yourself with 
  187.    --  Gtk.Action.Set_Accel_Path, or use Add_Action_With_Accel. 
  188.  
  189.    procedure Remove_Action 
  190.      (Action_Group : access Gtk_Action_Group_Record; 
  191.       Action       : access Gtk.Action.Gtk_Action_Record'Class); 
  192.    --  Removes an action object from the action group. 
  193.  
  194.    procedure Add_Action_With_Accel 
  195.      (Action_Group : access Gtk_Action_Group_Record; 
  196.       Action       : access Gtk.Action.Gtk_Action_Record'Class; 
  197.       Accelerator  : String := ""); 
  198.    --  Adds an action object to the action group and sets up the accelerator. 
  199.    --  If Accelerator is unspecified, attempts to use the accelerator 
  200.    --  associated with the stock_id of the action. 
  201.    --  Accel paths are set to <Actions>/group-name/action-name. 
  202.  
  203.    procedure Add_Actions 
  204.      (Action_Group : access Gtk_Action_Group_Record; 
  205.       Entries      : Action_Entry_Array; 
  206.       User_Data    : System.Address := System.Null_Address; 
  207.       Destroy      : Glib.G_Destroy_Notify_Address := null); 
  208.    --  This is a convenience function to create a number of actions and add 
  209.    --  them to the action group. 
  210.    --  Destroy is called when User_Data is no longer needed. 
  211.    -- 
  212.    --  The "activate" signals of the actions are connected to the callbacks in 
  213.    --  Entries, and their accel paths are set to 
  214.    --  <Actions>/group-name/action-name. 
  215.  
  216.    procedure Add_Radio_Actions 
  217.      (Action_Group : access Gtk_Action_Group_Record; 
  218.       Entries      : Radio_Action_Entry_Array; 
  219.       Value        : Glib.Gint; 
  220.       On_Change    : Radio_Action_Callback; 
  221.       User_Data    : System.Address := System.Null_Address; 
  222.       Destroy      : Glib.G_Destroy_Notify_Address := null); 
  223.    --  This is a convenience routine to create a group of radio actions and 
  224.    --  add them to the action group. 
  225.    -- 
  226.    --  The "changed" signal of the first radio action is connected to the 
  227.    --  On_Change callback and the accel paths of the actions are set to 
  228.    --    <Actions>/group-name/action-name 
  229.    -- 
  230.    --  Value is the value of the action to activate initially, or -1 if no 
  231.    --  action should be activated. 
  232.    --  Destroy is called when User_Data is no longer necessary. 
  233.  
  234.    procedure Add_Toggle_Actions 
  235.      (Action_Group : access Gtk_Action_Group_Record; 
  236.       Entries      : Toggle_Action_Entry_Array; 
  237.       User_Data    : System.Address := System.Null_Address; 
  238.       Destroy      : Glib.G_Destroy_Notify_Address := null); 
  239.    --  This is a convenience function to create a number of toggle actions and 
  240.    --  add them to the action group. 
  241.    --  The "activate" signals of the actions are connected to the callbacks and 
  242.    --  their accel paths are set to <Actions>/group-name/action-name. 
  243.    --  Destroy is called when User_Data is no longer necessary. 
  244.  
  245.    ---------------- 
  246.    -- Properties -- 
  247.    ---------------- 
  248.  
  249.    --  <properties> 
  250.    --  The following properties are defined for this widget. See 
  251.    --  Glib.Properties for more information on properties. 
  252.    -- 
  253.    --  Name:  Name_Property 
  254.    --  Type:  String 
  255.    --  Descr: A name for the action group. 
  256.    -- 
  257.    --  Name:  Sensitive_Property 
  258.    --  Type:  Boolean 
  259.    --  Descr: Whether the action group is enabled. 
  260.    -- 
  261.    --  Name:  Visible_Property 
  262.    --  Type:  Boolean 
  263.    --  Descr: Whether the action group is visible. 
  264.    -- 
  265.    --  </properties> 
  266.  
  267.    Name_Property      : constant Glib.Properties.Property_String; 
  268.    Sensitive_Property : constant Glib.Properties.Property_Boolean; 
  269.    Visible_Property   : constant Glib.Properties.Property_Boolean; 
  270.  
  271.    ------------- 
  272.    -- Signals -- 
  273.    ------------- 
  274.  
  275.    --  <signals> 
  276.    --  The following new signals are defined for this widget: 
  277.    -- 
  278.    --  - "connect_proxy" 
  279.    --    procedure Handler 
  280.    --       (Group  : access Gtk_Action_Group_Record'Class; 
  281.    --        Action : access Gtk_Action_Record'Class; 
  282.    --        Proxy  : access Gtk_Widget_Record'Class); 
  283.    --    The connect_proxy signal is emitted after connecting a proxy to an 
  284.    --    action in the group. Note that the proxy may have been connected to a 
  285.    --    different action before. 
  286.    --    This is intended for simple customizations for which a custom action 
  287.    --    class would be too clumsy, e.g. showing tooltips for menuitems in the 
  288.    --    statusbar. 
  289.    --    Gtk_UI_Manager proxies the signal and provides global notification 
  290.    --    just before any action is connected to a proxy, which is probably more 
  291.    --    convenient to use. 
  292.    -- 
  293.    --  - "disconnect_proxy" 
  294.    --    procedure Handler 
  295.    --       (Group  : access Gtk_Action_Group_Record'Class; 
  296.    --        Action : access Gtk_Action_Record'Class; 
  297.    --        Proxy  : access Gtk_Widget_Record'Class); 
  298.    --    The disconnect_proxy signal is emitted after disconnecting a proxy 
  299.    --    from an action in the group. 
  300.    --    Gtk_UI_Manager proxies the signal and provides global notification 
  301.    --    just before any action is connected to a proxy, which is probably more 
  302.    --    convenient to use. 
  303.    -- 
  304.    --  - "post_activate" 
  305.    --    procedure Handler 
  306.    --       (Group  : access Gtk_Action_Group_Record'Class; 
  307.    --        Action : access Gtk_Action_Record'Class); 
  308.    --    The post_activate signal is emitted just after the action in the 
  309.    --    action_group is activated 
  310.    --    This is intended for Gtk_UI_Manager to proxy the signal and provide 
  311.    --    global notification just after any action is activated. 
  312.    -- 
  313.    --  - "pre_activate" 
  314.    --    procedure Handler 
  315.    --       (Group  : access Gtk_Action_Group_Record'Class; 
  316.    --        Action : access Gtk_Action_Record'Class); 
  317.    --    The post_activate signal is emitted just before the action in the 
  318.    --    action_group is activated 
  319.    --    This is intended for Gtk_UI_Manager to proxy the signal and provide 
  320.    --    global notification just after any action is activated. 
  321.    --  </signals> 
  322.  
  323.    Signal_Connect_Proxy    : constant Glib.Signal_Name := "connect_proxy"; 
  324.    Signal_Disconnect_Proxy : constant Glib.Signal_Name := "disconnect_proxy"; 
  325.    Signal_Post_Activate    : constant Glib.Signal_Name := "post_activate"; 
  326.    Signal_Pre_Activate     : constant Glib.Signal_Name := "pre_activate"; 
  327.  
  328. private 
  329.    Name_Property : constant Glib.Properties.Property_String := 
  330.      Glib.Properties.Build ("name"); 
  331.    Sensitive_Property : constant Glib.Properties.Property_Boolean := 
  332.      Glib.Properties.Build ("sensitive"); 
  333.    Visible_Property : constant Glib.Properties.Property_Boolean := 
  334.      Glib.Properties.Build ("visible"); 
  335.  
  336.    type Action_Entry is record 
  337.       Name         : Interfaces.C.Strings.chars_ptr; 
  338.       Stock_Id     : Interfaces.C.Strings.chars_ptr; 
  339.       Label        : Interfaces.C.Strings.chars_ptr; 
  340.       Accelerator  : Interfaces.C.Strings.chars_ptr; 
  341.       Tooltip      : Interfaces.C.Strings.chars_ptr; 
  342.       Callback     : Action_Callback; 
  343.    end record; 
  344.    pragma Convention (C, Action_Entry); 
  345.  
  346.    type Radio_Action_Entry is record 
  347.       Name         : Interfaces.C.Strings.chars_ptr; 
  348.       Stock_Id     : Interfaces.C.Strings.chars_ptr; 
  349.       Label        : Interfaces.C.Strings.chars_ptr; 
  350.       Accelerator  : Interfaces.C.Strings.chars_ptr; 
  351.       Tooltip      : Interfaces.C.Strings.chars_ptr; 
  352.       Value        : Glib.Gint; 
  353.    end record; 
  354.    pragma Convention (C, Radio_Action_Entry); 
  355.  
  356.    type Toggle_Action_Entry is record 
  357.       Name         : Interfaces.C.Strings.chars_ptr; 
  358.       Stock_Id     : Interfaces.C.Strings.chars_ptr; 
  359.       Label        : Interfaces.C.Strings.chars_ptr; 
  360.       Accelerator  : Interfaces.C.Strings.chars_ptr; 
  361.       Tooltip      : Interfaces.C.Strings.chars_ptr; 
  362.       Callback     : Action_Callback; 
  363.       Is_Active    : Glib.Gboolean; 
  364.    end record; 
  365.    pragma Convention (C, Toggle_Action_Entry); 
  366.  
  367.    pragma Import (C, Get_Type, "gtk_action_group_get_type"); 
  368. end Gtk.Action_Group; 
  369.  
  370. --  Binding is through *_full 
  371. --  No binding: gtk_action_group_add_actions 
  372. --  No binding: gtk_action_group_add_radio_actions 
  373. --  No binding: gtk_action_group_add_toggle_actions 
  374.  
  375. --  Binding might be needed later 
  376. --  No binding: gtk_action_group_set_translate_func 
  377. --  No binding: gtk_action_group_translate_string