Debian Codegraph @

unikey/unikeyinputcontext.h

raw
1 /*
2 * SPDX-FileCopyrightText: 2018-2018 CSSlayer <[email protected]>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 *
6 */
7 #ifndef _UNIKEY_UNIKEYINPUTCONTEXT_H_
8 #define _UNIKEY_UNIKEYINPUTCONTEXT_H_
9
10 #include "keycons.h"
11 #include "ukengine.h"
12 #include <fcitx-utils/connectableobject.h>
13 #include <memory>
14
15 class UnikeyInputMethod : public fcitx::ConnectableObject {
16 public:
17 UnikeyInputMethod();
18
19 // set input method
20 // im: TELEX_INPUT, VNI_INPUT, VIQR_INPUT, VIQR_STAR_INPUT
21 void setInputMethod(UkInputMethod im);
22 // set output format
23 void setOutputCharset(int charset);
24
25 // set extra options
26 void setOptions(UnikeyOptions *pOpt);
27
28 //--------------------------------------------
29 int loadMacroTable(const char *fileName) {
30 return sharedMem_->macStore.loadFromFile(fileName);
31 }
32
33 UkSharedMem *sharedMem() { return sharedMem_.get(); }
34
35 FCITX_DECLARE_SIGNAL(UnikeyInputMethod, Reset, void());
36
37 private:
38 FCITX_DEFINE_SIGNAL(UnikeyInputMethod, Reset);
39 std::unique_ptr<UkSharedMem> sharedMem_;
40 };
41
42 class UnikeyInputContext {
43 public:
44 UnikeyInputContext(UnikeyInputMethod *im);
45 ~UnikeyInputContext();
46
47 // call this to reset Unikey's state when focus, context is changed or
48 // some control key is pressed
49 void resetBuf();
50
51 // main handler, call every time a character input is received
52 void filter(unsigned int ch);
53 void putChar(unsigned int ch); // put new char without filtering
54
55 // call to rebuild preedit from surrounding char
56 void rebuildChar(VnLexiName ch);
57
58 // call this before UnikeyFilter for correctly processing some TELEX
59 // shortcuts
60 void setCapsState(int shiftPressed, int CapsLockOn);
61
62 // call this when backspace is pressed
63 void backspacePress();
64
65 // call this to restore to original key strokes
66 void restoreKeyStrokes();
67
68 bool isAtWordBeginning() const;
69
70 int backspaces() const { return backspaces_; }
71 int bufChars() const { return bufChars_; }
72 const unsigned char *buf() const { return buf_; }
73
74 private:
75 fcitx::ScopedConnection conn_;
76
77 unsigned char buf_[1024];
78 int backspaces_ = 0;
79 int bufChars_;
80 UkOutputType output_;
81 UkEngine engine_;
82
83 int capsLockOn_ = 0;
84 int shiftPressed_ = 0;
85 };
86
87 #endif // _UNIKEY_UNIKEYINPUTCONTEXT_H_