1. ----------------------------------------------------------------------- 
  2. --              GtkAda - Ada95 binding for Gtk+/Gnome                -- 
  3. --                                                                   -- 
  4. --                Copyright (C) 2006-2009, 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. --  Gtk_Bindings provides a mechanism for configuring Gtk+ key bindings through 
  26. --  RC files. This eases key binding adjustments for application developers as 
  27. --  well as users and provides Gtk+ users or administrators with high key 
  28. --  binding configurability which requires no application or toolkit side 
  29. --  changes. 
  30. -- 
  31. --  Installing a key binding 
  32. --  ======================== 
  33. -- 
  34. --  A resource file binding consists of a 'binding' definition and a match 
  35. --  statement to apply the binding to specific widget types. Details on the 
  36. --  matching mechanism are described under Pathnames and patterns. Inside the 
  37. --  binding definition, key combinations are bound to specific signal emissions 
  38. --  on the target widget. Key combinations are strings consisting of an 
  39. --  optional Gdk_Modifier_Type name and key names such as those defined in 
  40. --  Gdk.Types.Keysyms or returned from gdk_keyval_name(), they have to be 
  41. --  parsable by gtk_accelerator_parse(). Specifications of signal emissions 
  42. --  consist of a string identifying the signal name, and a list of signal 
  43. --  specific arguments in parenthesis. For example for binding Control and the 
  44. --  left or right cursor keys of a Gtk_Entry widget to the 
  45. --  Gtk_Entry::move-cursor signal, so movement occurs in 3 letter steps, the 
  46. --  following binding can be used: 
  47. -- 
  48. --  binding "MoveCursor3" { 
  49. --     bind "<Control>Right" { 
  50. --       "move-cursor" (visual-positions, 3, 0) 
  51. --     } 
  52. --     bind "<Control>Left" { 
  53. --       "move-cursor" (visual-positions, -3, 0) 
  54. --     } 
  55. --  } 
  56. --  class "GtkEntry" binding "MoveCursor3" 
  57. -- 
  58. --  Unbinding existing key bindings 
  59. --  =============================== 
  60. -- 
  61. --  Gtk+ already defines a number of useful bindings for the widgets it 
  62. --  provides. Because custom bindings set up in RC files take precedence over 
  63. --  the default bindings shipped with Gtk+, overriding existing bindings as 
  64. --  demonstrated in Installing a key binding works as expected. The same 
  65. --  mechanism can not be used to "unbind" existing bindings, however. 
  66. -- 
  67. --  binding "MoveCursor3" { 
  68. --     bind "<Control>Right" { } 
  69. --     bind "<Control>Left" { } 
  70. --  } 
  71. --  class "GtkEntry" binding "MoveCursor3" 
  72. -- 
  73. --  The above example will not have the desired effect of causing 
  74. --  "<Control>Right" and "<Control>Left" key presses to be ignored by Gtk+. 
  75. --  Instead, it just causes any existing bindings from the bindings set 
  76. --  "MoveCursor3" to be deleted, so when "<Control>Right" or "<Control>Left" 
  77. --  are pressed, no binding for these keys is found in binding set 
  78. --  "MoveCursor3". Gtk+ will thus continue to search for matching key bindings, 
  79. --  and will eventually lookup and find the default Gtk+ bindings for entries 
  80. --  which implement word movement. To keep Gtk+ from activating its default 
  81. --  bindings, the "unbind" keyword can be used like this: 
  82. -- 
  83. --  binding "MoveCursor3" { 
  84. --     unbind "<Control>Right" 
  85. --     unbind "<Control>Left" 
  86. --  } 
  87. --  class "GtkEntry" binding "MoveCursor3" 
  88. -- 
  89. --  Now, Gtk+ will find a match when looking up "<Control>Right" and 
  90. --  "<Control>Left" key presses before it resorts to its default bindings, and 
  91. --  the match instructs it to abort ("unbind") the search, so the key presses 
  92. --  are not consumed by this widget. As usual, further processing of the key 
  93. --  presses, e.g. by an entries parent widget, is now possible. 
  94. --  </description> 
  95. --  <c_version>2.14</c_version> 
  96. --  <group>Configuration and Themes</group> 
  97.  
  98. with Gdk.Event; 
  99. with Gdk.Types; 
  100. with Glib.Object; 
  101. with Gtk.Object; 
  102.  
  103. package Gtk.Bindings is 
  104.  
  105.    type Gtk_Binding_Set is new Glib.C_Proxy; 
  106.    --  A binding set maintains a list of activatable key bindings. A single 
  107.    --  binding set can match multiple types of widgets. Similar to styles, 
  108.    --  widgets can be mapped by widget name paths, widget class paths or widget 
  109.    --  class types. When a binding within a set is matched upon activation, an 
  110.    --  action signal is emitted on the target widget to carry out the actual 
  111.    --  activation. 
  112.  
  113.    function Binding_Set_New (Set_Name : String) return Gtk_Binding_Set; 
  114.    --  Gtk+ maintains a global list of binding sets. Each binding set has a 
  115.    --  unique name which needs to be specified upon creation. 
  116.  
  117.    function Binding_Set_By_Class 
  118.      (Object_Class : Glib.Object.GObject_Class) return Gtk_Binding_Set; 
  119.    --  This function returns the binding set named after the type name of the 
  120.    --  passed in class structure. New binding sets are created on demand by 
  121.    --  this function. 
  122.  
  123.    function Binding_Set_Find (Set_Name : String) return Gtk_Binding_Set; 
  124.    --  Find a binding set by its globally unique name. The set_name can either 
  125.    --  be a name used for Binding_Set_New or the type name of a class 
  126.    --  used in Binding_Set_By_Class. 
  127.  
  128.    function Activate 
  129.      (Object    : access Gtk.Object.Gtk_Object_Record'Class; 
  130.       Keyval    : Guint; 
  131.       Modifiers : Gdk.Types.Gdk_Modifier_Type) 
  132.       return Boolean; 
  133.    --  Find a key binding matching keyval and modifiers and activate the 
  134.    --  binding on object. 
  135.  
  136.    function Activate_Event 
  137.      (Object : access Gtk.Object.Gtk_Object_Record; 
  138.       Event  : Gdk.Event.Gdk_Event_Key) 
  139.       return Boolean; 
  140.    --  Looks up key bindings for Object to find one matching 
  141.    --  Event, and if one was found, activate it. 
  142.    --  Return value: True if a matching key binding was found 
  143.  
  144.    function Binding_Set_Activate 
  145.      (Binding_Set : Gtk_Binding_Set; 
  146.       Keyval      : Guint; 
  147.       Modifiers   : Gdk.Types.Gdk_Modifier_Type; 
  148.       Object      : access Gtk.Object.Gtk_Object_Record'Class) 
  149.       return Boolean; 
  150.    --  Find a key binding matching keyval and modifiers within binding_set and 
  151.    --  activate the binding on object. 
  152.  
  153.    procedure Binding_Entry_Skip 
  154.      (Binding_Set : Gtk_Binding_Set; 
  155.       Keyval      : Guint; 
  156.       Modifiers   : Gdk.Types.Gdk_Modifier_Type); 
  157.    --  Install a binding on Binding_Set which causes key lookups 
  158.    --  to be aborted, to prevent bindings from lower priority sets 
  159.    --  to be activated. 
  160.    --  Since: 2.12 
  161.  
  162.    procedure Add_Signal 
  163.      (Binding_Set : Gtk_Binding_Set; 
  164.       Keyval      : Guint; 
  165.       Modifiers   : Gdk.Types.Gdk_Modifier_Type; 
  166.       Signal_Name : String); 
  167.    procedure Add_Signal 
  168.      (Binding_Set : Gtk_Binding_Set; 
  169.       Keyval      : Guint; 
  170.       Modifiers   : Gdk.Types.Gdk_Modifier_Type; 
  171.       Signal_Name : String; 
  172.       Arg1        : Gint); 
  173.    procedure Add_Signal 
  174.      (Binding_Set : Gtk_Binding_Set; 
  175.       Keyval      : Guint; 
  176.       Modifiers   : Gdk.Types.Gdk_Modifier_Type; 
  177.       Signal_Name : String; 
  178.       Arg1        : Boolean); 
  179.    procedure Add_Signal 
  180.      (Binding_Set : Gtk_Binding_Set; 
  181.       Keyval      : Guint; 
  182.       Modifiers   : Gdk.Types.Gdk_Modifier_Type; 
  183.       Signal_Name : String; 
  184.       Arg1        : Gint; 
  185.       Arg2        : Gint); 
  186.    --  Override or install a new key binding for keyval with modifiers on 
  187.    --  binding_set. When the binding is activated, signal_name will be emitted 
  188.    --  on the target widget, with the given arguments as argument. 
  189.  
  190. private 
  191.    pragma Import (C, Binding_Set_By_Class, "gtk_binding_set_by_class"); 
  192.    pragma Import (C, Binding_Entry_Skip,   "gtk_binding_entry_skip"); 
  193. end Gtk.Bindings; 
  194.  
  195. --  These are bound through our own C wrappers: 
  196. --  No binding: gtk_binding_entry_add_signal 
  197.  
  198. --  These are internal gtk+ functions 
  199. --  No binding: gtk_binding_entry_add_signall 
  200. --  No binding: gtk_binding_entry_clear 
  201. --  No binding: gtk_binding_entry_remove 
  202. --  No binding: gtk_binding_parse_binding 
  203. --  No binding: gtk_binding_set_add_path