Class key_binding is a subclass of class recogniser. It accepts keyboard events and maps them onto messages.
Class key_binding deals with
<-prefix)
<-argument).
<-saved_column).
Key_binding objects are used by various classes that are sensitive to keyboard events: editor, text, text_item and list_browser.
The following example shows how a key_binding object may be used to make a graphical object editable using the mouse:
send(new(P, picture('Graphical editor')), open),
send(P, display, new(B, box(100,100))), send(B, recogniser,
new(K, key_binding(@nil,
argument))), send(K, function,’TAB’, message(@receiver,
inverted,
@receiver?inverted?negate)),
send(K, function,’\C-d’, free), send(K,
function,’\C-p’, pen).
Typing TAB (= control-I), the box is inverted; typing control-d will
delete the graphical; typing META-3 control-p will make the pen
(thickness) of the line 3. See key_binding<-argument
on how to specify the universal numeric argument.
How a key_binding parses a keyboard event is described with key_binding->typed;
The specification of symbolic key-names is described with key_binding->function;
Resolution of a binding from a symbolic key is described with<-function;
Predefined binding tables are described with key_binding->initialise.
See also
@key_bindings.
The PCE/Prolog library file keybinding.pl
defines the predicate
show_key_bindings/1, which dumps the
key_binding of objects or plain tables.
\e0 .. \e9 and \e- are bound
to the function digit_argument the universal argument may be composed by
typing its value with the META-key held down.
universal_argument,
followed by the digits to construct its value.
The predefined key_binding name argument binds \e0
.. \e9 and \e- to
digit_argument and \C-u to universal_argument.
Using this table, the following sequences are examples for entering a
universal_argument:
Sequence Value \e1\e414 \C-u5656
->function.
The function is either a name, in which case the key-binding will invoke
the named method on the
event-receiver,
or a code object.
|code*<-bindings
nor one of the key_binding<-defaults
key_bindings define a binding for the typed key.
A common way to use this facility is to declare key_binding<->default_function
to
alert. Any unknown keys will then be mapped onto the method
graphical->alert.
prefix
this variable is set to this key.
The predefined table emacs_special binds \e, \C-c
and \C-x to the function prefix.
->event.->bind_resources,
which applies modifications from class-variables as defined in the XPCE
Defaults file.name is not
specified the key_binding<-name
of the binding table is used. For example, to bind ^S to save
in editor objects use
the following line in ~/.xpce/Defaults:
key_binding.editor = \
[ '\\C-s' = save \
]
->event
method.
If the event is a subtype of event-type keyboard this
method invokes
key_binding->typed: event<-id, event<-receiver.
->fill_arguments_and_execute.
It simply invokes the method selector on receiver
with the given arguments. This method may be redefined to take action
before or after invoking a method on the receiver:
execute(KB, Rec:object, Sel:name, Args:any ...) :->
<before-refinement>
send(KB, send_super_vector, execute, Rec, Sel, Args),
<after-refinement>.
See also object->send_super_vector.
->typed.
The key_binding
object should send a message to receiver named selector.
arguments is a partial argument list. This method collects
possible additional arguments:
If an argument of the send-method does not accept @default,
<-receiver defines
the method key_binding<-interactive_argument,
this method will be invoked using the following arguments:
1-st: Behaviour object implementing the method 2-nd: Ordinal number of the argument required
This method should return a value for the argument or fail.
If no argument can be found, the error no_argument is raised.
When all arguments are gathered, key_binding->execute
is activated.
|event_id,
action=name|codeWhen an event_id is passed it will be converted into the corresponding symbolic key-name. The symbolic key-names for the characters
Symbolic name ASCII Description \C-@ ...\C-h0..8 Control-characters TAB 9 The tab-key or control-I LFD 10 The linefeed-key or control-J \C-k ..\C-l11..12 Control-characters RET 13 The return-key or control-M \C-n ...\C-z14..26 Control-characters \e27 The escape-key or control-[ \C-\...\C-_28..31 Control-characters SPC 32 The space-bar @ ... ~33..126 Normal printable characters DEL 127 The delete-key
The meta-characters (ASCII 128..255) are mapped onto \e,
followed by the
-bindings
<-defaults). PCE predefines
some names. If a table with a predefined name is created the table will
be initialised according to this name. Tables that do not have a
predefined name are initially empty.
The predefined table-name are:
insert_self to all printable
characters and the TAB, LFD and RET keys.
digit_argument to \e0 ... \e9
and \e-; assigns
universal_argument to \C-u.
prefix to \e, \C-c and \C-x;‘keyboard_quit
to \C-g
\C-v; \ev; \C-l
<-receiver to the
argument graphical; key_binding<-prefix
to” and
key_binding<-argument
to @default.
Defaults: When no graphical is specified, key_binding<-receiver
is set to @nil.
|event_id,
for=[object]event(-id) of a keyboard event
object arrived on the given graphical. It performs the following steps:
graphical is specified and not equal to key_binding<-receiver,
invoke key_binding->reset
and set key_binding<-receiver to graphical.
key by appending the symbolic name of the
typed character to the current key_binding<-prefix.
Determine the binding of this key using key_binding<-function.
<-prefix
with the current key.
->reset
to clear key_binding<-prefix
and key_binding<-argument
next_line , previous_line<-saved_column
equals @default,
set it to the current column by invoking key_binding<-column
on the receiver.
\e0 ... \e9 or \e-,
set the key_binding<-argument.
<-argument.
First time: set
key_binding<-argument
to 4; afterwards: multiply key_binding<-argument
by
<-send_method.
Next specify the arguments according to their argument-type:
<-argument
when specified
Finally, key_binding->typed
invokes key_binding->fill_arguments_and_execute
to fill additional arguments, which in turn calls key_binding->execute
to send a message to the key_binding<-receiver.
If the key-binding is a code
object, key_binding->forward this code
object with the following arguments:
@receiver key_binding <-receiver@arg1 key_binding <-argument@arg2 the argument event -id
Finally on behalf of uniting Emacs and Windows users with the editor,
if a key is bound to the function prefix_or_copy or prefix_or_cut, the
system invokes editor->cua_key_as_prefix
on the receiver. If this method succeeds the key acts as prefix and
otherwise it is mapped to the functions cut or copy.
Defaults: If no graphical is specified, key_binding<-receiver
left unmodified.
If the name cannot be found in @key_bindings
but it is the name of a predefined table (see key_binding<-initialise), key_binding<-convert
will create a table and initialise it.
|name|event_id -> name|code->typed.
It performs the following steps:
<-bindings.
Return the result if found.
<-bindings
of the key_binding<-defaults tables
(recursively). If found somewhere return the result.
<-default_function
when not @nil.
<-default_function
in the key_binding<-defaults tables.
->typed