librime: key_binding_processor.h Source File

| librime 1.2 Rime Input Method Engine, the core library

key_binding_processor.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5#ifndef RIME_KEY_BINDING_PROCESSOR_H_
6#define RIME_KEY_BINDING_PROCESSOR_H_
7
8#include <rime/common.h>
9#include <rime/config.h>
10#include <rime/context.h>
11#include <rime/key_event.h>
12#include <rime/processor.h>
13
14namespace rime {
15
16template <class T, int N = 1>
17 class KeyBindingProcessor {
18 public:
19 typedef bool Handler(Context* ctx);
20 using HandlerPtr = bool (T::*)(Context* ctx);
21
22 enum FallbackOptions {
23 None = 0,
24 ShiftAsControl = (1 << 0),
25 IgnoreShift = (1 << 1),
26 All = ShiftAsControl | IgnoreShift,
27 };
28
29 struct ActionDef {
30 const char* name;
31 HandlerPtr action;
32 };
33
34 static const ActionDef kActionNoop;
35
36 explicit KeyBindingProcessor(ActionDef* action_definitions)
37 : action_definitions_(action_definitions) {}
38
39 ProcessResult ProcessKeyEvent(const KeyEvent& key_event,
40 Context* ctx,
41 int keymap_selector = 0,
42 int fallback_options = FallbackOptions::None);
43 void LoadConfig(Config* config,
44 const string& section,
45 int kemap_selector = 0);
46
47 protected:
48 struct Keymap : map<KeyEvent, HandlerPtr> {
49 void Bind(KeyEvent key_event, HandlerPtr action);
50 };
51
52 Keymap& get_keymap(int keymap_selector = 0);
53
54 bool Accept(const KeyEvent& key_event, Context* ctx, Keymap& keymap);
55
56 private:
57 ActionDef* action_definitions_;
58 Keymap keymaps_[N];
59};
60
61} // namespace rime
62
63#include <rime/gear/key_binding_processor_impl.h>
64
65#endif // RIME_KEY_BINDING_PROCESSOR_H_
common.h
context.h
config.h
processor.h
key_event.h
key_binding_processor_impl.h
rime
Definition algebra.cc:12
rime::ProcessResult
ProcessResult
Definition processor.h:18
rime::Config
Definition config_component.h:21
rime::Context
Definition context.h:19
rime::KeyBindingProcessor::Accept
bool Accept(const KeyEvent &key_event, Context *ctx, Keymap &keymap)
Definition key_binding_processor_impl.h:56
rime::KeyBindingProcessor::get_keymap
Keymap & get_keymap(int keymap_selector=0)
Definition key_binding_processor_impl.h:50
rime::KeyBindingProcessor::HandlerPtr
bool(T::*)(Context *ctx) HandlerPtr
Definition key_binding_processor.h:20
rime::KeyBindingProcessor::LoadConfig
void LoadConfig(Config *config, const string &section, int kemap_selector=0)
Definition key_binding_processor_impl.h:81
rime::KeyBindingProcessor::KeyBindingProcessor
KeyBindingProcessor(ActionDef *action_definitions)
Definition key_binding_processor.h:36
rime::KeyBindingProcessor::FallbackOptions
FallbackOptions
Definition key_binding_processor.h:22
rime::KeyBindingProcessor::ShiftAsControl
@ ShiftAsControl
Definition key_binding_processor.h:24
rime::KeyBindingProcessor::IgnoreShift
@ IgnoreShift
Definition key_binding_processor.h:25
rime::KeyBindingProcessor::None
@ None
Definition key_binding_processor.h:23
rime::KeyBindingProcessor::All
@ All
Definition key_binding_processor.h:26
rime::KeyBindingProcessor::Handler
bool Handler(Context *ctx)
Definition key_binding_processor.h:19
rime::KeyBindingProcessor::kActionNoop
static const ActionDef kActionNoop
Definition key_binding_processor.h:34
rime::KeyBindingProcessor::ProcessKeyEvent
ProcessResult ProcessKeyEvent(const KeyEvent &key_event, Context *ctx, int keymap_selector=0, int fallback_options=FallbackOptions::None)
Definition key_binding_processor_impl.h:13
rime::KeyBindingProcessor::ActionDef
Definition key_binding_processor.h:29
rime::KeyBindingProcessor::ActionDef::action
HandlerPtr action
Definition key_binding_processor.h:31
rime::KeyBindingProcessor::ActionDef::name
const char * name
Definition key_binding_processor.h:30
rime::KeyBindingProcessor::Keymap
Definition key_binding_processor.h:48
rime::KeyBindingProcessor::Keymap::Bind
void Bind(KeyEvent key_event, HandlerPtr action)
Definition key_binding_processor_impl.h:71
rime::KeyEvent
Definition key_event.h:17