Fcitx
inputpanel.cpp
1 /*
2  * SPDX-FileCopyrightText: 2017-2017 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 
8 #include "inputpanel.h"
9 
10 namespace fcitx {
11 
13 public:
14  Text auxDown_;
15  Text auxUp_;
16  Text preedit_;
17  Text clientPreedit_;
18  std::shared_ptr<CandidateList> candidate_;
19  InputContext *ic_;
20  CustomInputPanelCallback customCallback_ = nullptr;
21  CustomInputPanelCallback customVirtualKeyboardCallback_ = nullptr;
22 };
23 
25  : d_ptr(std::make_unique<InputPanelPrivate>()) {
26  FCITX_D();
27  d->ic_ = ic;
28 }
29 
30 InputPanel::~InputPanel() {}
31 
32 void InputPanel::setAuxDown(const Text &text) {
33  FCITX_D();
34  d->auxDown_ = text;
35 }
36 
37 void InputPanel::setAuxUp(const Text &text) {
38  FCITX_D();
39  d->auxUp_ = text;
40 }
41 
42 void InputPanel::setCandidateList(std::unique_ptr<CandidateList> candidate) {
43  FCITX_D();
44  d->candidate_ = std::move(candidate);
45 }
46 
47 void InputPanel::setClientPreedit(const Text &clientPreedit) {
48  FCITX_D();
49  d->clientPreedit_ = clientPreedit.normalize();
50  // If it is empty preedit, always set cursor to 0.
51  // An empty preedit with hidden cursor would only cause issues.
52  if (d->clientPreedit_.empty()) {
53  d->clientPreedit_.setCursor(0);
54  }
55 }
56 
57 void InputPanel::setPreedit(const Text &text) {
58  FCITX_D();
59  d->preedit_ = text;
60 }
61 
62 const Text &InputPanel::auxDown() const {
63  FCITX_D();
64  return d->auxDown_;
65 }
66 
67 const Text &InputPanel::auxUp() const {
68  FCITX_D();
69  return d->auxUp_;
70 }
71 
73  FCITX_D();
74  return d->clientPreedit_;
75 }
76 
77 const Text &InputPanel::preedit() const {
78  FCITX_D();
79  return d->preedit_;
80 }
81 
82 const CustomInputPanelCallback &InputPanel::customInputPanelCallback() const {
83  FCITX_D();
84  return d->customCallback_;
85 }
86 
88  CustomInputPanelCallback callback) {
89  FCITX_D();
90  d->customCallback_ = std::move(callback);
91 }
92 
93 const CustomInputPanelCallback &
94 InputPanel::customVirtualKeyboardCallback() const {
95  FCITX_D();
96  return d->customVirtualKeyboardCallback_;
97 }
98 
99 void InputPanel::setCustomVirtualKeyboardCallback(
100  CustomInputPanelCallback callback) {
101  FCITX_D();
102  d->customVirtualKeyboardCallback_ = std::move(callback);
103 }
104 
105 void InputPanel::reset() {
106  FCITX_D();
107  d->preedit_.clear();
108  d->clientPreedit_.clear();
109  d->clientPreedit_.setCursor(0);
110  d->candidate_.reset();
111  d->auxUp_.clear();
112  d->auxDown_.clear();
113  d->customCallback_ = nullptr;
114  d->customVirtualKeyboardCallback_ = nullptr;
115 }
116 
117 bool InputPanel::empty() const {
118  FCITX_D();
119  return d->preedit_.empty() && d->clientPreedit_.empty() &&
120  (!d->candidate_ || d->candidate_->size() == 0) &&
121  d->auxUp_.empty() && d->auxDown_.empty();
122 }
123 
124 std::shared_ptr<CandidateList> InputPanel::candidateList() const {
125  FCITX_D();
126  return d->candidate_;
127 }
128 } // namespace fcitx
const Text & clientPreedit() const
The preedit text embedded in client window.
Definition: inputpanel.cpp:72
const CustomInputPanelCallback & customInputPanelCallback() const
Return the current input panel display callback.
Definition: inputpanel.cpp:82
Class for input panel in UI.
Definition: action.cpp:17
Definition: matchrule.h:78
A class represents a formatted string.
Definition: text.h:27
Text normalize() const
Remove empty string piece and merge the string with same format.
Definition: text.cpp:152
InputPanel(InputContext *ic)
Construct a Input Panel associated with given input context.
Definition: inputpanel.cpp:24
void setCursor(int pos=-1)
Set cursor by byte.
Definition: text.cpp:46
bool empty() const
Whether input panel is totally empty.
Definition: inputpanel.cpp:117
An input context represents a client of Fcitx.
Definition: inputcontext.h:47
void setCustomInputPanelCallback(CustomInputPanelCallback callback)
Set a custom callback to display the input panel.
Definition: inputpanel.cpp:87