Fcitx
inputpanel.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2017-2017 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 #ifndef _FCITX_INPUTPANEL_H_
8 #define _FCITX_INPUTPANEL_H_
9 
10 #include <functional>
11 #include <memory>
12 #include <fcitx-utils/macros.h>
13 #include <fcitx/candidatelist.h>
14 #include <fcitx/fcitxcore_export.h>
15 #include <fcitx/text.h>
16 
17 /// \addtogroup FcitxCore
18 /// \{
19 /// \file
20 /// \brief Class for input panel in UI.
21 
22 namespace fcitx {
23 
24 class InputPanelPrivate;
25 class InputContext;
26 
27 using CustomInputPanelCallback = std::function<void(InputContext *)>;
28 
29 /**
30  * Input Panel is usually a floating window that is display at the cursor of
31  * input.
32  *
33  * But it can also be a embedded fixed window. The actual representation is
34  * implementation-defined. In certain cases, all the information input panel is
35  * forwarded to client and will be drawn by client.
36  *
37  * A common input panel is shown as
38  *
39  * | Aux Up | Preedit |
40  * |----------|------------------|
41  * | Aux down | Candidate 1, 2.. |
42  * Or
43  * | Aux Up | Preedit |
44  * |--------|--------------------|
45  * | Aux down ||
46  * | Candidate 1 ||
47  * | Candidate 2 ||
48  * | ... ||
49  * | Candidate n ||
50  */
51 class FCITXCORE_EXPORT InputPanel {
52 public:
53  /// Construct a Input Panel associated with given input context.
55  virtual ~InputPanel();
56 
57  const Text &preedit() const;
58  void setPreedit(const Text &text);
59 
60  const Text &auxUp() const;
61  void setAuxUp(const Text &text);
62 
63  const Text &auxDown() const;
64  void setAuxDown(const Text &text);
65 
66  /// The preedit text embedded in client window.
67  const Text &clientPreedit() const;
68  void setClientPreedit(const Text &clientPreedit);
69 
70  std::shared_ptr<CandidateList> candidateList() const;
71  void setCandidateList(std::unique_ptr<CandidateList> candidate);
72 
73  /**
74  * An text message that allows the input method to display a message on top
75  * of the input panel.
76  *
77  * When not empty, it should behave as if it is displayed in aux up.
78  *
79  * If you just need a naive implementation with timeout, consider using
80  * Instance::showCustomInputMethodInformation.
81  *
82  * This is intended to be used by a third party to display some message when
83  * engine/temp mode is controlling the input panel.
84  *
85  * This message should still be considered as temporary and
86  * InputPanel::reset will still clear it when the input panel current owner
87  * want to reset.
88  *
89  * @see Instance::showInputMethodInformation
90  * @see Instance::showCustomInputMethodInformation
91  *
92  * @since 5.1.22
93  */
94  const Text &overlayMessage() const;
95 
96  /**
97  * Set an overlay message on the input panel.
98  *
99  * It will not be shown if input panel has content, otherwise it will be
100  * shown as if it is in aux up.
101  *
102  * @param text the message to display.
103  *
104  * @since 5.1.22
105  */
106  void setOverlayMessage(Text text);
107 
108  /**
109  * Return the current input panel display callback.
110  *
111  * @see setCustomInputPanelCallback
112  * @return current custom ui callback
113  * @since 5.0.24
114  */
115  const CustomInputPanelCallback &customInputPanelCallback() const;
116 
117  /**
118  * Set a custom callback to display the input panel.
119  *
120  * When this is set,
121  * Instance::updateUserInterface(UserInterfaceComponent::InputPanel) will
122  * trigger a call to the callback function instead. The capability flag
123  * ClientSideInputPanel will not be respected, but the clientPreedit will
124  * still be sent if InputContext::updatePreedit is called.
125  *
126  * All the UI display batching logic still applies. The actual update that
127  * triggers this callback will be called as a deferred event after current
128  * event. If you need UI update right away (rare), you can still true as
129  * immediate to Instance::updateUserInterface.
130  *
131  * @param callback callback to display input panel.
132  *
133  * @since 5.0.24
134  */
135  void setCustomInputPanelCallback(CustomInputPanelCallback callback);
136 
137  const CustomInputPanelCallback &customVirtualKeyboardCallback() const;
138 
139  void setCustomVirtualKeyboardCallback(CustomInputPanelCallback callback);
140 
141  void reset();
142 
143  /// Whether input panel is totally empty.
144  bool empty() const;
145 
146 private:
147  std::unique_ptr<InputPanelPrivate> d_ptr;
148  FCITX_DECLARE_PRIVATE(InputPanel);
149 };
150 } // namespace fcitx
151 
152 #endif // _FCITX_INPUTPANEL_H_
Formatted string commonly used in user interface.
Definition: action.cpp:17
A class represents a formatted string.
Definition: text.h:27
Input Panel is usually a floating window that is display at the cursor of input.
Definition: inputpanel.h:51
An input context represents a client of Fcitx.
Definition: inputcontext.h:50