| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#ifndef _FCITX5_QUWEI_QUWEI_H_ |
| 8 |
#define _FCITX5_QUWEI_QUWEI_H_ |
| 9 |
|
| 10 |
#include <fcitx-utils/inputbuffer.h> |
| 11 |
#include <fcitx/addonfactory.h> |
| 12 |
#include <fcitx/addonmanager.h> |
| 13 |
#include <fcitx/inputcontext.h> |
| 14 |
#include <fcitx/inputcontextproperty.h> |
| 15 |
#include <fcitx/inputmethodengine.h> |
| 16 |
#include <fcitx/inputpanel.h> |
| 17 |
#include <fcitx/instance.h> |
| 18 |
#include <iconv.h> |
| 19 |
|
| 20 |
class QuweiEngine; |
| 21 |
|
| 22 |
class QuweiState : public fcitx::InputContextProperty { |
| 23 |
public: |
| 24 |
QuweiState(QuweiEngine *engine, fcitx::InputContext *ic) |
| 25 |
: engine_(engine), ic_(ic) {} |
| 26 |
|
| 27 |
void keyEvent(fcitx::KeyEvent &keyEvent); |
| 28 |
void setCode(int code); |
| 29 |
void updateUI(); |
| 30 |
void reset() { |
| 31 |
buffer_.clear(); |
| 32 |
updateUI(); |
| 33 |
} |
| 34 |
|
| 35 |
private: |
| 36 |
QuweiEngine *engine_; |
| 37 |
fcitx::InputContext *ic_; |
| 38 |
fcitx::InputBuffer buffer_{{fcitx::InputBufferOption::AsciiOnly, |
| 39 |
fcitx::InputBufferOption::FixedCursor}}; |
| 40 |
}; |
| 41 |
|
| 42 |
class QuweiEngine : public fcitx::InputMethodEngineV2 { |
| 43 |
public: |
| 44 |
QuweiEngine(fcitx::Instance *instance); |
| 45 |
|
| 46 |
void activate(const fcitx::InputMethodEntry &entry, |
| 47 |
fcitx::InputContextEvent &event) override; |
| 48 |
void keyEvent(const fcitx::InputMethodEntry &entry, |
| 49 |
fcitx::KeyEvent &keyEvent) override; |
| 50 |
|
| 51 |
void reset(const fcitx::InputMethodEntry &, |
| 52 |
fcitx::InputContextEvent &event) override; |
| 53 |
|
| 54 |
auto factory() const { return &factory_; } |
| 55 |
auto conv() const { return conv_; } |
| 56 |
auto instance() const { return instance_; } |
| 57 |
|
| 58 |
FCITX_ADDON_DEPENDENCY_LOADER(quickphrase, instance_->addonManager()); |
| 59 |
FCITX_ADDON_DEPENDENCY_LOADER(punctuation, instance_->addonManager()); |
| 60 |
|
| 61 |
private: |
| 62 |
FCITX_ADDON_DEPENDENCY_LOADER(chttrans, instance_->addonManager()); |
| 63 |
FCITX_ADDON_DEPENDENCY_LOADER(fullwidth, instance_->addonManager()); |
| 64 |
|
| 65 |
fcitx::Instance *instance_; |
| 66 |
fcitx::FactoryFor<QuweiState> factory_; |
| 67 |
iconv_t conv_; |
| 68 |
}; |
| 69 |
|
| 70 |
class QuweiEngineFactory : public fcitx::AddonFactory { |
| 71 |
fcitx::AddonInstance *create(fcitx::AddonManager *manager) override { |
| 72 |
FCITX_UNUSED(manager); |
| 73 |
return new QuweiEngine(manager->instance()); |
| 74 |
} |
| 75 |
}; |
| 76 |
|
| 77 |
#endif |