librime: chord_composer.h Source File

| librime 1.2 Rime Input Method Engine, the core library

chord_composer.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2012-06-05 GONG Chen <chen.sst@gmail.com>
6//
7#ifndef RIME_CHORD_COMPOSER_H_
8#define RIME_CHORD_COMPOSER_H_
9
10#include <rime/common.h>
11#include <rime/component.h>
12#include <rime/key_event.h>
13#include <rime/processor.h>
14#include <rime/algo/algebra.h>
15#include <rime/gear/key_binding_processor.h>
16
17namespace rime {
18
19 using Chord = set<int>;
20
21 struct ChordingState {
22 Chord pressed_keys;
23 Chord recognized_chord;
24
25 bool IsPressed(int ch) const {
26 return pressed_keys.find(ch) != pressed_keys.end();
27 }
28
29 bool PressKey(int ch) { return pressed_keys.insert(ch).second; }
30
31 bool ReleaseKey(int ch) { return pressed_keys.erase(ch) != 0; }
32
33 bool AddKeyToChord(int ch) { return recognized_chord.insert(ch).second; }
34
35 void Clear() {
36 pressed_keys.clear();
37 recognized_chord.clear();
38 }
39};
40
41 class ChordComposer : public Processor,
42 public KeyBindingProcessor<ChordComposer> {
43 public:
44 ChordComposer(const Ticket& ticket);
45 ~ChordComposer();
46
47 virtual ProcessResult ProcessKeyEvent(const KeyEvent& key_event);
48
49 Handler CommitRawInput;
50
51 protected:
52 bool FinishChordConditionIsMet() const;
53 ProcessResult ProcessChordingKey(const KeyEvent& key_event);
54 ProcessResult ProcessFunctionKey(const KeyEvent& key_event);
55 string SerializeChord(const Chord& chord);
56 void UpdateChord(const Chord& chord);
57 void FinishChord(const Chord& chord);
58 void ClearChord();
59 bool DeleteLastSyllable();
60 void OnContextUpdate(Context* ctx);
61 void OnUnhandledKey(Context* ctx, const KeyEvent& key);
62
63 KeySequence chording_keys_;
64 string delimiter_;
65 Projection algebra_;
66 Projection output_format_;
67 Projection prompt_format_;
68 bool use_control_ = false;
69 bool use_alt_ = false;
70 bool use_shift_ = false;
71 bool use_super_ = false;
72 bool use_caps_ = false;
73 bool finish_chord_on_first_key_release_ = false;
74
75 ChordingState state_;
76 bool editing_chord_ = false;
77 bool sending_chord_ = false;
78 bool composing_ = false;
79 string raw_sequence_;
80 connection update_connection_;
81 connection unhandled_key_connection_;
82};
83
84} // namespace rime
85
86#endif // RIME_CHORD_COMPOSER_H_
algebra.h
common.h
component.h
key_binding_processor.h
key_event.h
processor.h
rime
Definition algebra.cc:12
rime::Chord
set< int > Chord
Definition chord_composer.h:19
rime::ProcessResult
ProcessResult
Definition processor.h:18
rime::Projection
Definition algebra.h:29
rime::Context
Definition context.h:19
rime::ChordingState
Definition chord_composer.h:21
rime::ChordingState::Clear
void Clear()
Definition chord_composer.h:35
rime::ChordingState::pressed_keys
Chord pressed_keys
Definition chord_composer.h:22
rime::ChordingState::AddKeyToChord
bool AddKeyToChord(int ch)
Definition chord_composer.h:33
rime::ChordingState::PressKey
bool PressKey(int ch)
Definition chord_composer.h:29
rime::ChordingState::recognized_chord
Chord recognized_chord
Definition chord_composer.h:23
rime::ChordingState::ReleaseKey
bool ReleaseKey(int ch)
Definition chord_composer.h:31
rime::ChordingState::IsPressed
bool IsPressed(int ch) const
Definition chord_composer.h:25
rime::ChordComposer::state_
ChordingState state_
Definition chord_composer.h:75
rime::ChordComposer::editing_chord_
bool editing_chord_
Definition chord_composer.h:76
rime::ChordComposer::unhandled_key_connection_
connection unhandled_key_connection_
Definition chord_composer.h:81
rime::ChordComposer::delimiter_
string delimiter_
Definition chord_composer.h:64
rime::ChordComposer::FinishChordConditionIsMet
bool FinishChordConditionIsMet() const
Definition chord_composer.cc:110
rime::ChordComposer::ProcessChordingKey
ProcessResult ProcessChordingKey(const KeyEvent &key_event)
Definition chord_composer.cc:115
rime::ChordComposer::algebra_
Projection algebra_
Definition chord_composer.h:65
rime::ChordComposer::ClearChord
void ClearChord()
Definition chord_composer.cc:237
rime::ChordComposer::ProcessKeyEvent
virtual ProcessResult ProcessKeyEvent(const KeyEvent &key_event)
Definition chord_composer.cc:152
rime::ChordComposer::use_super_
bool use_super_
Definition chord_composer.h:71
rime::ChordComposer::chording_keys_
KeySequence chording_keys_
Definition chord_composer.h:63
rime::ChordComposer::CommitRawInput
Handler CommitRawInput
Definition chord_composer.h:49
rime::ChordComposer::sending_chord_
bool sending_chord_
Definition chord_composer.h:77
rime::ChordComposer::DeleteLastSyllable
bool DeleteLastSyllable()
rime::ChordComposer::SerializeChord
string SerializeChord(const Chord &chord)
Definition chord_composer.cc:179
rime::ChordComposer::OnUnhandledKey
void OnUnhandledKey(Context *ctx, const KeyEvent &key)
Definition chord_composer.cc:265
rime::ChordComposer::use_control_
bool use_control_
Definition chord_composer.h:68
rime::ChordComposer::UpdateChord
void UpdateChord(const Chord &chord)
Definition chord_composer.cc:190
rime::ChordComposer::raw_sequence_
string raw_sequence_
Definition chord_composer.h:79
rime::ChordComposer::FinishChord
void FinishChord(const Chord &chord)
Definition chord_composer.cc:215
rime::ChordComposer::ProcessFunctionKey
ProcessResult ProcessFunctionKey(const KeyEvent &key_event)
Definition chord_composer.cc:73
rime::ChordComposer::use_caps_
bool use_caps_
Definition chord_composer.h:72
rime::ChordComposer::finish_chord_on_first_key_release_
bool finish_chord_on_first_key_release_
Definition chord_composer.h:73
rime::ChordComposer::use_alt_
bool use_alt_
Definition chord_composer.h:69
rime::ChordComposer::update_connection_
connection update_connection_
Definition chord_composer.h:80
rime::ChordComposer::output_format_
Projection output_format_
Definition chord_composer.h:66
rime::ChordComposer::ChordComposer
ChordComposer(const Ticket &ticket)
Definition chord_composer.cc:24
rime::ChordComposer::use_shift_
bool use_shift_
Definition chord_composer.h:70
rime::ChordComposer::OnContextUpdate
void OnContextUpdate(Context *ctx)
Definition chord_composer.cc:253
rime::ChordComposer::prompt_format_
Projection prompt_format_
Definition chord_composer.h:67
rime::ChordComposer::composing_
bool composing_
Definition chord_composer.h:78
rime::KeyBindingProcessor< ChordComposer >::KeyBindingProcessor
KeyBindingProcessor(ActionDef *action_definitions)
Definition key_binding_processor.h:36
rime::KeyBindingProcessor< ChordComposer >::Handler
bool Handler(Context *ctx)
Definition key_binding_processor.h:19
rime::KeyEvent
Definition key_event.h:17
rime::KeySequence
Definition key_event.h:59
rime::Processor::Processor
Processor(const Ticket &ticket)
Definition processor.h:26
rime::Ticket
Definition ticket.h:17