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 #include <memory>
10 #include <utility>
11 #include "fcitx-utils/macros.h"
12 #include "candidatelist.h"
13 #include "text.h"
14 
15 namespace fcitx {
16 
18 public:
19  Text auxDown_;
20  Text auxUp_;
21  Text preedit_;
22  Text clientPreedit_;
23  Text overlayMessage_;
24  std::shared_ptr<CandidateList> candidate_;
25  InputContext *ic_;
26  CustomInputPanelCallback customCallback_ = nullptr;
27  CustomInputPanelCallback customVirtualKeyboardCallback_ = nullptr;
28 };
29 
31  : d_ptr(std::make_unique<InputPanelPrivate>()) {
32  FCITX_D();
33  d->ic_ = ic;
34 }
35 
36 InputPanel::~InputPanel() {}
37 
38 void InputPanel::setAuxDown(const Text &text) {
39  FCITX_D();
40  d->auxDown_ = text;
41 }
42 
43 void InputPanel::setAuxUp(const Text &text) {
44  FCITX_D();
45  d->auxUp_ = text;
46 }
47 
48 void InputPanel::setCandidateList(std::unique_ptr<CandidateList> candidate) {
49  FCITX_D();
50  d->candidate_ = std::move(candidate);
51 }
52 
53 void InputPanel::setClientPreedit(const Text &clientPreedit) {
54  FCITX_D();
55  d->clientPreedit_ = clientPreedit.normalize();
56  // If it is empty preedit, always set cursor to 0.
57  // An empty preedit with hidden cursor would only cause issues.
58  if (d->clientPreedit_.empty()) {
59  d->clientPreedit_.setCursor(0);
60  }
61 }
62 
63 void InputPanel::setPreedit(const Text &text) {
64  FCITX_D();
65  d->preedit_ = text;
66 }
67 
68 const Text &InputPanel::auxDown() const {
69  FCITX_D();
70  return d->auxDown_;
71 }
72 
73 const Text &InputPanel::auxUp() const {
74  FCITX_D();
75  return d->auxUp_;
76 }
77 
79  FCITX_D();
80  return d->clientPreedit_;
81 }
82 
83 const Text &InputPanel::preedit() const {
84  FCITX_D();
85  return d->preedit_;
86 }
87 
89  FCITX_D();
90  return d->overlayMessage_;
91 }
92 
94  FCITX_D();
95  d->overlayMessage_ = std::move(text);
96 }
97 
98 const CustomInputPanelCallback &InputPanel::customInputPanelCallback() const {
99  FCITX_D();
100  return d->customCallback_;
101 }
102 
104  CustomInputPanelCallback callback) {
105  FCITX_D();
106  d->customCallback_ = std::move(callback);
107 }
108 
109 const CustomInputPanelCallback &
110 InputPanel::customVirtualKeyboardCallback() const {
111  FCITX_D();
112  return d->customVirtualKeyboardCallback_;
113 }
114 
115 void InputPanel::setCustomVirtualKeyboardCallback(
116  CustomInputPanelCallback callback) {
117  FCITX_D();
118  d->customVirtualKeyboardCallback_ = std::move(callback);
119 }
120 
121 void InputPanel::reset() {
122  FCITX_D();
123  d->preedit_.clear();
124  d->clientPreedit_.clear();
125  d->clientPreedit_.setCursor(0);
126  d->candidate_.reset();
127  d->auxUp_.clear();
128  d->auxDown_.clear();
129  d->overlayMessage_.clear();
130  d->customCallback_ = nullptr;
131  d->customVirtualKeyboardCallback_ = nullptr;
132 }
133 
134 bool InputPanel::empty() const {
135  FCITX_D();
136  return d->preedit_.empty() && d->clientPreedit_.empty() &&
137  (!d->candidate_ || d->candidate_->size() == 0) &&
138  d->auxUp_.empty() && d->auxDown_.empty();
139 }
140 
141 std::shared_ptr<CandidateList> InputPanel::candidateList() const {
142  FCITX_D();
143  return d->candidate_;
144 }
145 } // namespace fcitx
const Text & clientPreedit() const
The preedit text embedded in client window.
Definition: inputpanel.cpp:78
const CustomInputPanelCallback & customInputPanelCallback() const
Return the current input panel display callback.
Definition: inputpanel.cpp:98
Class for input panel in UI.
Formatted string commonly used in user interface.
Definition: action.cpp:17
Definition: matchrule.h:78
const Text & overlayMessage() const
An text message that allows the input method to display a message on top of the input panel...
Definition: inputpanel.cpp:88
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:157
InputPanel(InputContext *ic)
Construct a Input Panel associated with given input context.
Definition: inputpanel.cpp:30
void setCursor(int pos=-1)
Set cursor by byte.
Definition: text.cpp:53
bool empty() const
Whether input panel is totally empty.
Definition: inputpanel.cpp:134
An input context represents a client of Fcitx.
Definition: inputcontext.h:50
void setCustomInputPanelCallback(CustomInputPanelCallback callback)
Set a custom callback to display the input panel.
Definition: inputpanel.cpp:103
void setOverlayMessage(Text text)
Set an overlay message on the input panel.
Definition: inputpanel.cpp:93