~ubuntu-branches/ubuntu/intrepid/libgtkada2/intrepid

« back to all changes in this revision

Viewing changes to src/gtk-bindings.ads

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-08-11 09:46:51 UTC
  • mfrom: (6.1.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20080811094651-9mjd6acwa98ffw5c
Tags: 2.12.0-2ubuntu1
Add lpia to supported architectures.

Show diffs side-by-side

added added

removed removed

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