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  std::shared_ptr<CandidateList> candidate_;
24  InputContext *ic_;
25  CustomInputPanelCallback customCallback_ = nullptr;
26  CustomInputPanelCallback customVirtualKeyboardCallback_ = nullptr;
27 };
28 
30  : d_ptr(std::make_unique<InputPanelPrivate>()) {
31  FCITX_D();
32  d->ic_ = ic;
33 }
34 
35 InputPanel::~InputPanel() {}
36 
37 void InputPanel::setAuxDown(const Text &text) {
38  FCITX_D();
39  d->auxDown_ = text;
40 }
41 
42 void InputPanel::setAuxUp(const Text &text) {
43  FCITX_D();
44  d->auxUp_ = text;
45 }
46 
47 void InputPanel::setCandidateList(std::unique_ptr<CandidateList> candidate) {
48  FCITX_D();
49  d->candidate_ = std::move(candidate);
50 }
51 
52 void InputPanel::setClientPreedit(const Text &clientPreedit) {
53  FCITX_D();
54  d->clientPreedit_ = clientPreedit.normalize();
55  // If it is empty preedit, always set cursor to 0.
56  // An empty preedit with hidden cursor would only cause issues.
57  if (d->clientPreedit_.empty()) {
58  d->clientPreedit_.setCursor(0);
59  }
60 }
61 
62 void InputPanel::setPreedit(const Text &text) {
63  FCITX_D();
64  d->preedit_ = text;
65 }
66 
67 const Text &InputPanel::auxDown() const {
68  FCITX_D();
69  return d->auxDown_;
70 }
71 
72 const Text &InputPanel::auxUp() const {
73  FCITX_D();
74  return d->auxUp_;
75 }
76 
78  FCITX_D();
79  return d->clientPreedit_;
80 }
81 
82 const Text &InputPanel::preedit() const {
83  FCITX_D();
84  return d->preedit_;
85 }
86 
87 const CustomInputPanelCallback &InputPanel::customInputPanelCallback() const {
88  FCITX_D();
89  return d->customCallback_;
90 }
91 
93  CustomInputPanelCallback callback) {
94  FCITX_D();
95  d->customCallback_ = std::move(callback);
96 }
97 
98 const CustomInputPanelCallback &
99 InputPanel::customVirtualKeyboardCallback() const {
100  FCITX_D();
101  return d->customVirtualKeyboardCallback_;
102 }
103 
104 void InputPanel::setCustomVirtualKeyboardCallback(
105  CustomInputPanelCallback callback) {
106  FCITX_D();
107  d->customVirtualKeyboardCallback_ = std::move(callback);
108 }
109 
110 void InputPanel::reset() {
111  FCITX_D();
112  d->preedit_.clear();
113  d->clientPreedit_.clear();
114  d->clientPreedit_.setCursor(0);
115  d->candidate_.reset();
116  d->auxUp_.clear();
117  d->auxDown_.clear();
118  d->customCallback_ = nullptr;
119  d->customVirtualKeyboardCallback_ = nullptr;
120 }
121 
122 bool InputPanel::empty() const {
123  FCITX_D();
124  return d->preedit_.empty() && d->clientPreedit_.empty() &&
125  (!d->candidate_ || d->candidate_->size() == 0) &&
126  d->auxUp_.empty() && d->auxDown_.empty();
127 }
128 
129 std::shared_ptr<CandidateList> InputPanel::candidateList() const {
130  FCITX_D();
131  return d->candidate_;
132 }
133 } // namespace fcitx
const Text & clientPreedit() const
The preedit text embedded in client window.
Definition: inputpanel.cpp:77
const CustomInputPanelCallback & customInputPanelCallback() const
Return the current input panel display callback.
Definition: inputpanel.cpp:87
Class for input panel in UI.
Formatted string commonly used in user interface.
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:157
InputPanel(InputContext *ic)
Construct a Input Panel associated with given input context.
Definition: inputpanel.cpp:29
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:122
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:92