Fcitx
inputmethodengine.h
1 /*
2  * SPDX-FileCopyrightText: 2016-2016 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 #ifndef _FCITX_INPUTMETHODENGINE_H_
8 #define _FCITX_INPUTMETHODENGINE_H_
9 
10 #include <fcitx/addoninstance.h>
11 #include <fcitx/event.h>
12 #include <fcitx/inputmethodentry.h>
13 #include "fcitxcore_export.h"
14 
15 namespace fcitx {
16 
17 class FCITXCORE_EXPORT InputMethodEngine : public AddonInstance {
18 public:
19  virtual ~InputMethodEngine() {}
20 
21  /**
22  * List the input methods provided by this engine.
23  *
24  * If OnDemand=True, the input method will be provided by configuration file
25  * instead. Additional input method may be provided by configuration file.
26  */
27  virtual std::vector<InputMethodEntry> listInputMethods() { return {}; }
28 
29  /**
30  * Main function where the input method handles a key event.
31  *
32  * @param entry input method entry
33  * @param event key event
34  */
35  virtual void keyEvent(const InputMethodEntry &entry,
36  KeyEvent &keyEvent) = 0;
37  /**
38  * Called when the input context is switched to this input method.
39  *
40  * @param entry input method entry
41  * @param event event
42  */
43  virtual void activate(const InputMethodEntry &entry,
44  InputContextEvent &event) {
45  FCITX_UNUSED(entry);
46  FCITX_UNUSED(event);
47  }
48 
49  /**
50  * Called when input context switch its input method.
51  *
52  * By default it will call reset.
53  *
54  * @param entry input method entry
55  * @param event event
56  */
57  virtual void deactivate(const InputMethodEntry &entry,
58  InputContextEvent &event) {
59  reset(entry, event);
60  }
61  /**
62  * Being called when the input context need to reset it state.
63  *
64  * reset will only be called if ic is focused
65  *
66  * @param entry input method entry
67  * @param event event
68  */
69  virtual void reset(const InputMethodEntry &entry,
70  InputContextEvent &event) {
71  FCITX_UNUSED(entry);
72  FCITX_UNUSED(event);
73  }
74 
75  /**
76  * If a key event is not handled by all other handler, it will be passed to
77  * this function.
78  *
79  * This is useful for input method to block all the keys that it doesn't
80  * want to handle.
81  *
82  * @param entry input method entry
83  * @param event key event
84  */
85  virtual void filterKey(const InputMethodEntry &entry, KeyEvent &event) {
86  FCITX_UNUSED(entry);
87  FCITX_UNUSED(event);
88  }
89 
90  FCITXCORE_DEPRECATED virtual void
91  updateSurroundingText(const InputMethodEntry &) {}
92 
93  /**
94  * Return a localized name for the sub mode of input method.
95  *
96  * @param entry input method entry
97  * @param inputContext input context
98  * @return name of the sub mode.
99  */
100  virtual std::string subMode(const InputMethodEntry &entry,
101  InputContext &inputContext) {
102  FCITX_UNUSED(entry);
103  FCITX_UNUSED(inputContext);
104  return {};
105  }
106 
107  /**
108  * Return an alternative icon for entry.
109  *
110  * @param entry input method entry
111  * @return icon name
112  *
113  * @see InputMethodEngine::subModeIcon
114  */
115  virtual std::string overrideIcon(const InputMethodEntry &) { return {}; }
116 
117  /**
118  * Return the configuration for this input method entry.
119  *
120  * The entry need to have Configurable=True
121  * By default it will return the addon's config.
122  *
123  * @param entry input method entry
124  * @return pointer to the configuration
125  */
126  virtual const Configuration *
128  FCITX_UNUSED(entry);
129  return getConfig();
130  }
131 
132  /**
133  * Update the configuration for this input method entry.
134  *
135  * The entry need to have Configurable=True
136  * By default it will set the addon's config.
137  *
138  * @param entry input method entry
139  */
140  virtual void setConfigForInputMethod(const InputMethodEntry &entry,
141  const RawConfig &config) {
142  FCITX_UNUSED(entry);
143  setConfig(config);
144  }
145  /**
146  * Return the icon name for the sub mode.
147  *
148  * Prefer subclass this method from InputMethodEngineV2 over overrideIcon.
149  *
150  * @param entry input method entry
151  * @param ic input context
152  * @return std::string
153  *
154  * @see overrideIcon
155  */
156  std::string subModeIcon(const InputMethodEntry &entry, InputContext &ic);
157 
158  /**
159  * Return the label for the sub mode.
160  *
161  * @param entry input method entry
162  * @param ic input context
163  * @return std::string
164  */
165  std::string subModeLabel(const InputMethodEntry &entry, InputContext &ic);
166 
167  /**
168  * Process InvokeActionEvent.
169  *
170  * @param entry input method entry
171  * @param event Invoke action event
172  * @since 5.0.11
173  */
174  void invokeAction(const InputMethodEntry &entry, InvokeActionEvent &event);
175 
176  /**
177  * Process virtual keyboard event
178  *
179  * @param entry input method entry
180  * @param event virtual keyboard event
181  * @since 5.1.0
182  */
183  void virtualKeyboardEvent(const InputMethodEntry &entry,
185 };
186 
187 class FCITXCORE_EXPORT InputMethodEngineV2 : public InputMethodEngine {
188 public:
189  virtual std::string subModeIconImpl(const InputMethodEntry &,
190  InputContext &);
191  virtual std::string subModeLabelImpl(const InputMethodEntry &,
192  InputContext &);
193 };
194 
195 class FCITXCORE_EXPORT InputMethodEngineV3 : public InputMethodEngineV2 {
196 public:
197  virtual void invokeActionImpl(const InputMethodEntry &entry,
198  InvokeActionEvent &event);
199 };
200 
201 class FCITXCORE_EXPORT InputMethodEngineV4 : public InputMethodEngineV3 {
202 public:
203  virtual void
204  virtualKeyboardEventImpl(const InputMethodEntry &entry,
206 };
207 
208 } // namespace fcitx
209 
210 #endif // _FCITX_INPUTMETHODENGINE_H_
virtual const Configuration * getConfigForInputMethod(const InputMethodEntry &entry) const
Return the configuration for this input method entry.
virtual std::vector< InputMethodEntry > listInputMethods()
List the input methods provided by this engine.
virtual void reset(const InputMethodEntry &entry, InputContextEvent &event)
Being called when the input context need to reset it state.
virtual void filterKey(const InputMethodEntry &entry, KeyEvent &event)
If a key event is not handled by all other handler, it will be passed to this function.
Definition: action.cpp:12
virtual std::string overrideIcon(const InputMethodEntry &)
Return an alternative icon for entry.
virtual std::string subMode(const InputMethodEntry &entry, InputContext &inputContext)
Return a localized name for the sub mode of input method.
virtual void activate(const InputMethodEntry &entry, InputContextEvent &event)
Called when the input context is switched to this input method.
virtual void deactivate(const InputMethodEntry &entry, InputContextEvent &event)
Called when input context switch its input method.
Base class for any addon in fcitx.
Definition: addoninstance.h:71
virtual void setConfigForInputMethod(const InputMethodEntry &entry, const RawConfig &config)
Update the configuration for this input method entry.
Input Method event for Fcitx.
Addon For fcitx.
An input context represents a client of Fcitx.
Definition: inputcontext.h:45