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