librime: context.h Source File

| librime 1.2 Rime Input Method Engine, the core library

context.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2011-04-24 GONG Chen <chen.sst@gmail.com>
6//
7#ifndef RIME_CONTEXT_H_
8#define RIME_CONTEXT_H_
9
10#include <rime/common.h>
11#include <rime/commit_history.h>
12#include <rime/composition.h>
13
14namespace rime {
15
16class Candidate;
17class KeyEvent;
18
19 class RIME_DLL Context {
20 public:
21 using Notifier = signal<void(Context* ctx)>;
22 using OptionUpdateNotifier = signal<void(Context* ctx, const string& option)>;
23 using PropertyUpdateNotifier =
24 signal<void(Context* ctx, const string& property)>;
25 using KeyEventNotifier =
26 signal<void(Context* ctx, const KeyEvent& key_event)>;
27
28 Context() = default;
29 ~Context() = default;
30
31 bool Commit();
32 string GetCommitText() const;
33 string GetScriptText() const;
34 Preedit GetPreedit() const;
35 bool IsComposing() const;
36 bool HasMenu() const;
37 an<Candidate> GetSelectedCandidate() const;
38
39 bool PushInput(char ch);
40 bool PushInput(const string& str);
41 bool PopInput(size_t len = 1);
42 bool DeleteInput(size_t len = 1);
43 void Clear();
44 // Clear and notify abort
45 void AbortComposition();
46
47 // return false if there is no candidate at index
48 bool Select(size_t index);
49 // return false if the selected index has not changed
50 bool Highlight(size_t index);
51 bool DeleteCandidate(size_t index);
52 // return false if there's no candidate for current segment
53 bool ConfirmCurrentSelection();
54 bool DeleteCurrentSelection();
55 void BeginEditing();
56 bool ConfirmPreviousSelection(); // deprecated
57 bool ReopenPreviousSegment();
58 bool ClearPreviousSegment();
59 bool ReopenPreviousSelection();
60 bool ClearNonConfirmedComposition();
61 bool RefreshNonConfirmedComposition();
62
63 void set_input(const string& value);
64 const string& input() const { return input_; }
65
66 void set_caret_pos(size_t caret_pos);
67 size_t caret_pos() const { return caret_pos_; }
68
69 void set_composition(Composition&& comp);
70 Composition& composition() { return composition_; }
71 const Composition& composition() const { return composition_; }
72 CommitHistory& commit_history() { return commit_history_; }
73 const CommitHistory& commit_history() const { return commit_history_; }
74
75 void set_option(const string& name, bool value);
76 bool get_option(const string& name) const;
77 void set_property(const string& name, const string& value);
78 string get_property(const string& name) const;
79 const map<string, bool>& options() const { return options_; }
80 const map<string, string>& properties() const { return properties_; }
81 // options and properties starting with '_' are local to schema;
82 // others are session scoped.
83 void ClearTransientOptions();
84
85 Notifier& commit_notifier() { return commit_notifier_; }
86 Notifier& select_notifier() { return select_notifier_; }
87 Notifier& update_notifier() { return update_notifier_; }
88 Notifier& delete_notifier() { return delete_notifier_; }
89 Notifier& abort_notifier() { return abort_notifier_; }
90 OptionUpdateNotifier& option_update_notifier() {
91 return option_update_notifier_;
92 }
93 PropertyUpdateNotifier& property_update_notifier() {
94 return property_update_notifier_;
95 }
96 KeyEventNotifier& unhandled_key_notifier() { return unhandled_key_notifier_; }
97
98 private:
99 string GetSoftCursor() const;
100
101 string input_;
102 size_t caret_pos_ = 0;
103 Composition composition_;
104 CommitHistory commit_history_;
105 map<string, bool> options_;
106 map<string, string> properties_;
107
108 Notifier commit_notifier_;
109 Notifier select_notifier_;
110 Notifier update_notifier_;
111 Notifier delete_notifier_;
112 Notifier abort_notifier_;
113 OptionUpdateNotifier option_update_notifier_;
114 PropertyUpdateNotifier property_update_notifier_;
115 KeyEventNotifier unhandled_key_notifier_;
116};
117
118} // namespace rime
119
120#endif // RIME_CONTEXT_H_
RIME_DLL
#define RIME_DLL
Definition rime_api.h:33
common.h
commit_history.h
composition.h
rime
Definition algebra.cc:12
rime::an
std::shared_ptr< T > an
Definition common.h:60
rime::Candidate
Definition candidate.h:14
rime::CommitHistory
Definition commit_history.h:25
rime::Preedit
Definition composition.h:14
rime::Composition
Definition composition.h:21
rime::Context::PushInput
bool PushInput(char ch)
Definition context.cc:65
rime::Context::~Context
~Context()=default
rime::Context::ConfirmPreviousSelection
bool ConfirmPreviousSelection()
Definition context.cc:199
rime::Context::option_update_notifier
OptionUpdateNotifier & option_update_notifier()
Definition context.h:90
rime::Context::caret_pos
size_t caret_pos() const
Definition context.h:67
rime::Context::ConfirmCurrentSelection
bool ConfirmCurrentSelection()
Definition context.cc:168
rime::Context::Notifier
signal< void(Context *ctx)> Notifier
Definition context.h:21
rime::Context::DeleteCandidate
bool DeleteCandidate(size_t index)
Definition context.cc:151
rime::Context::options
const map< string, bool > & options() const
Definition context.h:79
rime::Context::input
const string & input() const
Definition context.h:64
rime::Context::GetCommitText
string GetCommitText() const
Definition context.cc:28
rime::Context::commit_notifier
Notifier & commit_notifier()
Definition context.h:85
rime::Context::RefreshNonConfirmedComposition
bool RefreshNonConfirmedComposition()
Definition context.cc:260
rime::Context::Clear
void Clear()
Definition context.cc:106
rime::Context::HasMenu
bool HasMenu() const
Definition context.cc:52
rime::Context::select_notifier
Notifier & select_notifier()
Definition context.h:86
rime::Context::abort_notifier
Notifier & abort_notifier()
Definition context.h:89
rime::Context::Context
Context()=default
rime::Context::DeleteInput
bool DeleteInput(size_t len=1)
Definition context.cc:98
rime::Context::ReopenPreviousSegment
bool ReopenPreviousSegment()
Definition context.cc:204
rime::Context::Highlight
bool Highlight(size_t index)
Definition context.cc:132
rime::Context::GetSelectedCandidate
an< Candidate > GetSelectedCandidate() const
Definition context.cc:59
rime::Context::ReopenPreviousSelection
bool ReopenPreviousSelection()
Definition context.cc:226
rime::Context::DeleteCurrentSelection
bool DeleteCurrentSelection()
Definition context.cc:161
rime::Context::property_update_notifier
PropertyUpdateNotifier & property_update_notifier()
Definition context.h:93
rime::Context::composition
Composition & composition()
Definition context.h:70
rime::Context::update_notifier
Notifier & update_notifier()
Definition context.h:87
rime::Context::commit_history
CommitHistory & commit_history()
Definition context.h:72
rime::Context::PopInput
bool PopInput(size_t len=1)
Definition context.cc:89
rime::Context::OptionUpdateNotifier
signal< void(Context *ctx, const string &option)> OptionUpdateNotifier
Definition context.h:22
rime::Context::composition
const Composition & composition() const
Definition context.h:71
rime::Context::KeyEventNotifier
signal< void(Context *ctx, const KeyEvent &key_event)> KeyEventNotifier
Definition context.h:25
rime::Context::GetPreedit
Preedit GetPreedit() const
Definition context.cc:44
rime::Context::BeginEditing
void BeginEditing()
Definition context.cc:187
rime::Context::unhandled_key_notifier
KeyEventNotifier & unhandled_key_notifier()
Definition context.h:96
rime::Context::set_input
void set_input(const string &value)
Definition context.cc:280
rime::Context::AbortComposition
void AbortComposition()
Definition context.cc:113
rime::Context::ClearNonConfirmedComposition
bool ClearNonConfirmedComposition()
Definition context.cc:246
rime::Context::delete_notifier
Notifier & delete_notifier()
Definition context.h:88
rime::Context::GetScriptText
string GetScriptText() const
Definition context.cc:34
rime::Context::Select
bool Select(size_t index)
Definition context.cc:118
rime::Context::Commit
bool Commit()
Definition context.cc:18
rime::Context::properties
const map< string, string > & properties() const
Definition context.h:80
rime::Context::commit_history
const CommitHistory & commit_history() const
Definition context.h:73
rime::Context::IsComposing
bool IsComposing() const
Definition context.cc:48
rime::Context::ClearPreviousSegment
bool ClearPreviousSegment()
Definition context.cc:216
rime::Context::PropertyUpdateNotifier
signal< void(Context *ctx, const string &property)> PropertyUpdateNotifier
Definition context.h:23
rime::KeyEvent
Definition key_event.h:17