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