1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --   Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet   -- 
  5. --                Copyright (C) 2000-2013, AdaCore                   -- 
  6. --                                                                   -- 
  7. -- This library is free software; you can redistribute it and/or     -- 
  8. -- modify it under the terms of the GNU General Public               -- 
  9. -- License as published by the Free Software Foundation; either      -- 
  10. -- version 2 of the License, or (at your option) any later version.  -- 
  11. --                                                                   -- 
  12. -- This library is distributed in the hope that it will be useful,   -- 
  13. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  14. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  15. -- General Public License for more details.                          -- 
  16. --                                                                   -- 
  17. -- You should have received a copy of the GNU General Public         -- 
  18. -- License along with this library; if not, write to the             -- 
  19. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  20. -- Boston, MA 02111-1307, USA.                                       -- 
  21. --                                                                   -- 
  22. -- As a special exception, if other files instantiate generics from  -- 
  23. -- this unit, or you link this unit with other files to produce an   -- 
  24. -- executable, this  unit  does not  by itself cause  the resulting  -- 
  25. -- executable to be covered by the GNU General Public License. This  -- 
  26. -- exception does not however invalidate any other reasons why the   -- 
  27. -- executable file  might be covered by the  GNU Public License.     -- 
  28. ----------------------------------------------------------------------- 
  29.  
  30. --  <description> 
  31. --  An accel group represents a group of keyboard accelerators, generally 
  32. --  attached to a toplevel window. Accelerators are different from mnemonics. 
  33. --  Accelerators are shortcuts for activating a menu item. They appear 
  34. --  alongside the menu item they are a shortcut for. Mnemonics are shortcuts 
  35. --  for GUI elements, such as buttons. They appear as underline characters. 
  36. --  Menu items can have both. 
  37. -- 
  38. --  </description> 
  39.  
  40. pragma Warnings (Off, "*is already use-visible*"); 
  41. with Gdk;             use Gdk; 
  42. with Gdk.Types;       use Gdk.Types; 
  43. with Glib;            use Glib; 
  44. with Glib.Object;     use Glib.Object; 
  45. with Glib.Properties; use Glib.Properties; 
  46.  
  47. package Gtk.Accel_Group is 
  48.  
  49.    type Gtk_Accel_Group_Record is new GObject_Record with null record; 
  50.    type Gtk_Accel_Group is access all Gtk_Accel_Group_Record'Class; 
  51.  
  52.    type Gtk_Accel_Flags is new Guint; 
  53.    Accel_Visible : constant Gtk_Accel_Flags := 2 ** 0; 
  54.    Accel_Locked  : constant Gtk_Accel_Flags := 2 ** 1; 
  55.    Accel_Mask    : constant Gtk_Accel_Flags := 16#07#; 
  56.  
  57.    type Gtk_Accel_Key is record 
  58.       Accel_Key  : Gdk.Types.Gdk_Key_Type; 
  59.       Accel_Mods : Gdk.Types.Gdk_Modifier_Type; 
  60.       Flags      : Gtk_Accel_Flags; 
  61.    end record; 
  62.    pragma Convention (C, Gtk_Accel_Key); 
  63.  
  64.    type Gtk_Accel_Group_Activate is access function 
  65.      (Accel_Group   : access Gtk_Accel_Group_Record'Class; 
  66.       Acceleratable : Glib.Object.GObject; 
  67.       Keyval        : Gdk.Types.Gdk_Key_Type; 
  68.       Modifier      : Gdk.Types.Gdk_Modifier_Type) return Boolean; 
  69.  
  70.    type C_Gtk_Accel_Group_Activate is access function 
  71.      (Accel_Group   : System.Address; 
  72.       Acceleratable : System.Address; 
  73.       Keyval        : Gdk.Types.Gdk_Key_Type; 
  74.       Modifier      : Gdk.Types.Gdk_Modifier_Type) return Boolean; 
  75.    pragma Convention (C, C_Gtk_Accel_Group_Activate); 
  76.    --  Same as Gtk_Accel_Group_Activate, but passing directly the C values. 
  77.    --  You must use Get_User_Data to convert to the Ada types. 
  78.  
  79.    type C_Gtk_Accel_Group_Find_Func is access function 
  80.      (Key           : access Gtk_Accel_Key; 
  81.       Closure       : C_Gtk_Accel_Group_Activate; 
  82.       Data          : System.Address) return Boolean; 
  83.    pragma Convention (C, C_Gtk_Accel_Group_Find_Func); 
  84.    --  When a match is found, must return True. 
  85.    --  Must not modify Key 
  86.  
  87.    ------------------ 
  88.    -- Constructors -- 
  89.    ------------------ 
  90.  
  91.    procedure Gtk_New (Accel_Group : out Gtk_Accel_Group); 
  92.    procedure Initialize (Accel_Group : access Gtk_Accel_Group_Record'Class); 
  93.    --  Creates a new Gtk.Accel_Group.Gtk_Accel_Group. Remember to call 
  94.    --  Gtk.Window.Add_Accel_Group to active the group. 
  95.  
  96.    function Get_Type return Glib.GType; 
  97.    pragma Import (C, Get_Type, "gtk_accel_group_get_type"); 
  98.  
  99.    ------------- 
  100.    -- Methods -- 
  101.    ------------- 
  102.  
  103.    function Activate 
  104.       (Accel_Group   : access Gtk_Accel_Group_Record; 
  105.        Accel_Quark   : GQuark; 
  106.        Acceleratable : access Glib.Object.GObject_Record'Class; 
  107.        Accel_Key     : Guint; 
  108.        Accel_Mods    : Gdk.Types.Gdk_Modifier_Type) return Boolean; 
  109.    --  Finds the first accelerator in Accel_Group that matches Accel_Key and 
  110.    --  Accel_Mods, and activates it. 
  111.    --  "accel_quark": the quark for the accelerator name 
  112.    --  "acceleratable": the GObject, usually a Gtk.Window.Gtk_Window, on which 
  113.    --  to activate the accelerator. 
  114.    --  "accel_key": accelerator keyval from a key event 
  115.    --  "accel_mods": keyboard state mask from a key event 
  116.  
  117.    procedure Connect 
  118.       (Accel_Group : access Gtk_Accel_Group_Record; 
  119.        Accel_Key   : Guint; 
  120.        Accel_Mods  : Gdk.Types.Gdk_Modifier_Type; 
  121.        Accel_Flags : Gtk_Accel_Flags; 
  122.        Closure     : C_Gtk_Accel_Group_Activate); 
  123.    --  Installs an accelerator in this group. When Accel_Group is being 
  124.    --  activated in response to a call to 
  125.    --  Gtk.Accel_Group.Accel_Groups_Activate, Closure will be invoked if the 
  126.    --  Accel_Key and Accel_Mods from Gtk.Accel_Group.Accel_Groups_Activate 
  127.    --  match those of this connection. The signature used for the Closure is 
  128.    --  that of GtkAccelGroupActivate. Note that, due to implementation details, 
  129.    --  a single closure can only be connected to one accelerator group. 
  130.    --  "accel_key": key value of the accelerator 
  131.    --  "accel_mods": modifier combination of the accelerator 
  132.    --  "accel_flags": a flag mask to configure this accelerator 
  133.    --  "closure": closure to be executed upon accelerator activation 
  134.  
  135.    procedure Connect_By_Path 
  136.       (Accel_Group : access Gtk_Accel_Group_Record; 
  137.        Accel_Path  : UTF8_String; 
  138.        Closure     : C_Gtk_Accel_Group_Activate); 
  139.    --  Installs an accelerator in this group, using an accelerator path to 
  140.    --  look up the appropriate key and modifiers (see Gtk.Accel_Map.Add_Entry). 
  141.    --  When Accel_Group is being activated in response to a call to 
  142.    --  Gtk.Accel_Group.Accel_Groups_Activate, Closure will be invoked if the 
  143.    --  Accel_Key and for the path. The signature used for the Closure is that 
  144.    --  of GtkAccelGroupActivate. Note that Accel_Path string will be stored in 
  145.    --  a GQuark. Therefore, if you pass a static string, you can save some 
  146.    --  memory by interning it first with g_intern_static_string. 
  147.    --  "accel_path": path used for determining key and modifiers. 
  148.    --  "closure": closure to be executed upon accelerator activation 
  149.  
  150.    function Disconnect 
  151.       (Accel_Group : access Gtk_Accel_Group_Record; 
  152.        Closure     : C_Gtk_Accel_Group_Activate) return Boolean; 
  153.    --  Removes an accelerator previously installed through 
  154.    --  Gtk.Accel_Group.Connect. Since 2.20 Closure can be null. 
  155.    --  "closure": the closure to remove from this accelerator group, or null 
  156.    --  to remove all closures 
  157.  
  158.    function Disconnect_Key 
  159.       (Accel_Group : access Gtk_Accel_Group_Record; 
  160.        Accel_Key   : Guint; 
  161.        Accel_Mods  : Gdk.Types.Gdk_Modifier_Type) return Boolean; 
  162.    --  Removes an accelerator previously installed through 
  163.    --  Gtk.Accel_Group.Connect. 
  164.    --  "accel_key": key value of the accelerator 
  165.    --  "accel_mods": modifier combination of the accelerator 
  166.  
  167.    function Find 
  168.       (Accel_Group : access Gtk_Accel_Group_Record; 
  169.        Find_Func   : C_Gtk_Accel_Group_Find_Func; 
  170.        Data        : System.Address) return Gtk_Accel_Key; 
  171.    --  Finds the first entry in an accelerator group for which 
  172.    --  "find_func": a function to filter the entries of Accel_Group with 
  173.    --  "data": data to pass to Find_Func 
  174.  
  175.    function Get_Is_Locked 
  176.       (Accel_Group : access Gtk_Accel_Group_Record) return Boolean; 
  177.    --  Locks are added and removed using Gtk.Accel_Group.Lock and 
  178.    --  Gtk.Accel_Group.Unlock. False otherwise. 
  179.    --  Since: gtk+ 2.14 
  180.  
  181.    function Get_Modifier_Mask 
  182.       (Accel_Group : access Gtk_Accel_Group_Record) 
  183.        return Gdk.Types.Gdk_Modifier_Type; 
  184.    --  Gets a Gdk.Types.Gdk_Modifier_Type representing the mask for this 
  185.    --  Since: gtk+ 2.14 
  186.  
  187.    procedure Lock (Accel_Group : access Gtk_Accel_Group_Record); 
  188.    --  Locks the given accelerator group. Locking an acelerator group prevents 
  189.    --  the accelerators contained within it to be changed during runtime. Refer 
  190.    --  to Gtk.Accel_Map.Change_Entry about runtime accelerator changes. If 
  191.    --  called more than once, Accel_Group remains locked until 
  192.    --  Gtk.Accel_Group.Unlock has been called an equivalent number of times. 
  193.  
  194.    procedure Unlock (Accel_Group : access Gtk_Accel_Group_Record); 
  195.    --  Undoes the last call to Gtk.Accel_Group.Lock on this Accel_Group. 
  196.  
  197.    --------------- 
  198.    -- Functions -- 
  199.    --------------- 
  200.  
  201.    function From_Accel_Closure 
  202.       (Closure : C_Gtk_Accel_Group_Activate) 
  203.        return Gtk.Accel_Group.Gtk_Accel_Group; 
  204.    --  Finds the Gtk.Accel_Group.Gtk_Accel_Group to which Closure is 
  205.    --  connected; see Gtk.Accel_Group.Connect. 
  206.    --  "closure": a GClosure 
  207.  
  208.    function Accel_Groups_Activate 
  209.       (Object     : access Glib.Object.GObject_Record'Class; 
  210.        Accel_Key  : Gdk.Types.Gdk_Key_Type; 
  211.        Accel_Mods : Gdk.Types.Gdk_Modifier_Type) return Boolean; 
  212.    --  Finds the first accelerator in any Gtk.Accel_Group.Gtk_Accel_Group 
  213.    --  attached to Object that matches Accel_Key and Accel_Mods, and activates 
  214.    --  that accelerator. 
  215.    --  "object": the GObject, usually a Gtk.Window.Gtk_Window, on which to 
  216.    --  activate the accelerator. 
  217.    --  "accel_key": accelerator keyval from a key event 
  218.    --  "accel_mods": keyboard state mask from a key event 
  219.  
  220.    function From_Object 
  221.       (Object : access Glib.Object.GObject_Record'Class) 
  222.        return Glib.Object.Object_List.GSlist; 
  223.    --  Gets a list of all accel groups which are attached to Object. 
  224.    --  "object": a GObject, usually a Gtk.Window.Gtk_Window 
  225.  
  226.    function Accelerator_Valid 
  227.       (Keyval    : Gdk.Types.Gdk_Key_Type; 
  228.        Modifiers : Gdk.Types.Gdk_Modifier_Type) return Boolean; 
  229.    --  Determines whether a given keyval and modifier mask constitute a valid 
  230.    --  keyboard accelerator. For example, the GDK_a keyval plus 
  231.    --  GDK_CONTROL_MASK is valid - this is a "Ctrl+a" accelerator. But, you 
  232.    --  can't, for instance, use the GDK_Control_L keyval as an accelerator. 
  233.    --  "keyval": a GDK keyval 
  234.    --  "modifiers": modifier mask 
  235.  
  236.    procedure Accelerator_Parse 
  237.       (Accelerator      : UTF8_String; 
  238.        Accelerator_Key  : out Gdk.Types.Gdk_Key_Type; 
  239.        Accelerator_Mods : out Gdk.Types.Gdk_Modifier_Type); 
  240.    --  Parses a string representing an accelerator. The format looks like 
  241.    --  "&lt;Control&gt;a" or "&lt;Shift&gt;&lt;Alt&gt;F1" or "&lt;Release&gt;z" 
  242.    --  (the last one is for key release). The parser is fairly liberal and 
  243.    --  allows lower or upper case, and also abbreviations such as "&lt;Ctl&gt;" 
  244.    --  and "&lt;Ctrl&gt;". Key names are parsed using gdk_keyval_from_name. For 
  245.    --  character keys the name is not the symbol, but the lowercase name, e.g. 
  246.    --  one would use "&lt;Ctrl&gt;minus" instead of "&lt;Ctrl&gt;-". If the 
  247.    --  parse fails, Accelerator_Key and Accelerator_Mods will be set to 0 
  248.    --  (zero). 
  249.    --  "accelerator": string representing an accelerator 
  250.    --  "accelerator_key": return location for accelerator keyval 
  251.    --  "accelerator_mods": return location for accelerator modifier mask 
  252.  
  253.    function Accelerator_Name 
  254.       (Accelerator_Key  : Gdk.Types.Gdk_Key_Type; 
  255.        Accelerator_Mods : Gdk.Types.Gdk_Modifier_Type) return UTF8_String; 
  256.    --  Converts an accelerator keyval and modifier mask into a string 
  257.    --  parseable by Gtk.Accel_Group.Accelerator_Parse. For example, if you pass 
  258.    --  in GDK_q and GDK_CONTROL_MASK, this function returns "&lt;Control&gt;q". 
  259.    --  If you need to display accelerators in the user interface, see 
  260.    --  Gtk.Accel_Group.Accelerator_Get_Label. 
  261.    --  "accelerator_key": accelerator keyval 
  262.    --  "accelerator_mods": accelerator modifier mask 
  263.  
  264.    function Accelerator_Get_Label 
  265.       (Accelerator_Key  : Gdk.Types.Gdk_Key_Type; 
  266.        Accelerator_Mods : Gdk.Types.Gdk_Modifier_Type) return UTF8_String; 
  267.    --  Converts an accelerator keyval and modifier mask into a string which 
  268.    --  can be used to represent the accelerator to the user. 
  269.    --  Since: gtk+ 2.6 
  270.    --  "accelerator_key": accelerator keyval 
  271.    --  "accelerator_mods": accelerator modifier mask 
  272.  
  273.    procedure Set_Default_Mod_Mask 
  274.       (Default_Mod_Mask : Gdk.Types.Gdk_Modifier_Type); 
  275.    function Get_Default_Mod_Mask return Gdk.Types.Gdk_Modifier_Type; 
  276.    --  Gets the value set by Gtk.Accel_Group.Set_Default_Mod_Mask. 
  277.  
  278.    ---------------- 
  279.    -- Properties -- 
  280.    ---------------- 
  281.    --  The following properties are defined for this widget. See 
  282.    --  Glib.Properties for more information on properties) 
  283.    -- 
  284.    --  Name: Is_Locked_Property 
  285.    --  Type: Boolean 
  286.    --  Flags: read-write 
  287.    -- 
  288.    --  Name: Modifier_Mask_Property 
  289.    --  Type: Gdk.ModifierType 
  290.    --  Flags: read-write 
  291.  
  292.    Is_Locked_Property : constant Glib.Properties.Property_Boolean; 
  293.    Modifier_Mask_Property : constant Glib.Properties.Property_Boxed; 
  294.  
  295.    ------------- 
  296.    -- Signals -- 
  297.    ------------- 
  298.    --  The following new signals are defined for this widget: 
  299.    -- 
  300.    --  "accel-activate" 
  301.    --     function Handler 
  302.    --       (Self          : access Gtk_Accel_Group_Record'Class; 
  303.    --        Acceleratable : Glib.Object.GObject; 
  304.    --        Keyval        : Guint; 
  305.    --        Modifier      : Gdk.ModifierType) return Boolean; 
  306.    --    --  "acceleratable": the object on which the accelerator was activated 
  307.    --    --  "keyval": the accelerator keyval 
  308.    --    --  "modifier": the modifier combination of the accelerator 
  309.    --  The accel-activate signal is an implementation detail of 
  310.    --  Gtk.Accel_Group.Gtk_Accel_Group and not meant to be used by 
  311.    --  applications. 
  312.    --  Returns True if the accelerator was activated 
  313.    -- 
  314.    --  "accel-changed" 
  315.    --     procedure Handler 
  316.    --       (Self          : access Gtk_Accel_Group_Record'Class; 
  317.    --        Keyval        : Guint; 
  318.    --        Modifier      : Gdk.ModifierType; 
  319.    --        Accel_Closure : System.Address); 
  320.    --    --  "keyval": the accelerator keyval 
  321.    --    --  "modifier": the modifier combination of the accelerator 
  322.    --    --  "accel_closure": the GClosure of the accelerator 
  323.    --  The accel-changed signal is emitted when a GtkAccelGroupEntry is added 
  324.    --  to or removed from the accel group. Widgets like 
  325.    --  Gtk.Accellabel.Gtk_Accellabel which display an associated accelerator 
  326.    --  should connect to this signal, and rebuild their visual representation 
  327.    --  if the Accel_Closure is theirs. 
  328.  
  329.    Signal_Accel_Activate : constant Glib.Signal_Name := "accel-activate"; 
  330.    Signal_Accel_Changed : constant Glib.Signal_Name := "accel-changed"; 
  331.  
  332. private 
  333.    Is_Locked_Property : constant Glib.Properties.Property_Boolean := 
  334.      Glib.Properties.Build ("is-locked"); 
  335.    Modifier_Mask_Property : constant Glib.Properties.Property_Boxed := 
  336.      Glib.Properties.Build ("modifier-mask"); 
  337. end Gtk.Accel_Group;