1 #ifndef DALI_INTERNAL_INPUT_METHOD_CONTEXT_IMPL_X_H
2 #define DALI_INTERNAL_INPUT_METHOD_CONTEXT_IMPL_X_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/internal/input/linux/dali-ecore-imf.h>
23 #include <dali/internal/system/linux/dali-ecore-x.h>
25 #include <dali/public-api/object/base-object.h>
28 #include <dali/devel-api/adaptor-framework/input-method-context.h>
29 #include <dali/internal/input/common/input-method-context-impl.h>
39 class InputMethodContextX : public Dali::Internal::Adaptor::InputMethodContext, public Dali::ConnectionTracker
43 * @brief Creates a new InputMethodContext handle
45 * @param[in] actor The actor that uses the new InputMethodContext instance.
46 * @return InputMethodContext pointer
48 static InputMethodContextPtr New(Dali::Actor actor);
52 * @param[in] actor The actor that uses the new InputMethodContext instance.
54 explicit InputMethodContextX(Dali::Actor actor);
58 * @brief Initializes member data.
60 void Initialize() override;
63 * Connect Callbacks required for InputMethodContext.
64 * If you don't connect InputMethodContext callbacks, you can't get the key events.
65 * The events are PreeditChanged, Commit and DeleteSurrounding.
67 void ConnectCallbacks() override;
70 * Disconnect Callbacks attached to input method context.
72 void DisconnectCallbacks() override;
75 * @copydoc Dali::InputMethodContext::Finalize()
77 void Finalize() override;
80 * @copydoc Dali::InputMethodContext::Activate()
82 void Activate() override;
85 * @copydoc Dali::InputMethodContext::Deactivate()
87 void Deactivate() override;
90 * @copydoc Dali::InputMethodContext::Reset()
92 void Reset() override;
95 * @copydoc Dali::InputMethodContext::GetContext()
97 ImfContext* GetContext() override;
100 * @copydoc Dali::InputMethodContext::RestoreAfterFocusLost()
102 bool RestoreAfterFocusLost() const override;
105 * @copydoc Dali::InputMethodContext::SetRestoreAfterFocusLost()
107 void SetRestoreAfterFocusLost(bool toggle) override;
110 * @copydoc Dali::InputMethodContext::PreEditChanged()
112 void PreEditChanged(void* data, ImfContext* imfContext, void* eventInfo) override;
115 * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
117 void CommitReceived(void* data, ImfContext* imfContext, void* eventInfo) override;
120 * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
122 bool RetrieveSurrounding(void* data, ImfContext* imfContext, char** text, int* cursorPosition) override;
125 * @copydoc Dali::InputMethodContext::DeleteSurrounding()
127 void DeleteSurrounding(void* data, ImfContext* imfContext, void* eventInfo) override;
130 * @copydoc Dali::InputMethodContext::SendPrivateCommand()
132 void SendPrivateCommand(void* data, ImfContext* imfContext, void* eventInfo) override
137 * @copydoc Dali::InputMethodContext::SendCommitContent()
139 void SendCommitContent(void* data, ImfContext* imfContext, void* eventInfo) override
145 * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
147 void NotifyCursorPosition() override;
150 * @copydoc Dali::InputMethodContext::SetCursorPosition()
152 void SetCursorPosition(unsigned int cursorPosition) override;
155 * @copydoc Dali::InputMethodContext::GetCursorPosition()
157 unsigned int GetCursorPosition() const override;
160 * @copydoc Dali::InputMethodContext::SetSurroundingText()
162 void SetSurroundingText(const std::string& text) override;
165 * @copydoc Dali::InputMethodContext::GetSurroundingText()
167 const std::string& GetSurroundingText() const override;
170 * @copydoc Dali::InputMethodContext::NotifyTextInputMultiLine()
172 void NotifyTextInputMultiLine(bool multiLine) override;
175 * @copydoc Dali::InputMethodContext::GetTextDirection()
177 Dali::InputMethodContext::TextDirection GetTextDirection() override;
180 * @copydoc Dali::InputMethodContext::GetInputMethodArea()
182 Dali::Rect<int> GetInputMethodArea() override;
185 * @copydoc Dali::InputMethodContext::ApplyOptions()
187 void ApplyOptions(const InputMethodOptions& options) override;
190 * @copydoc Dali::InputMethodContext::SetInputPanelData()
192 void SetInputPanelData(const std::string& data) override;
195 * @copydoc Dali::InputMethodContext::GetInputPanelData()
197 void GetInputPanelData(std::string& data) override;
200 * @copydoc Dali::InputMethodContext::GetInputPanelState()
202 Dali::InputMethodContext::State GetInputPanelState() override;
205 * @copydoc Dali::InputMethodContext::SetReturnKeyState()
207 void SetReturnKeyState(bool visible) override;
210 * @copydoc Dali::InputMethodContext::AutoEnableInputPanel()
212 void AutoEnableInputPanel(bool enabled) override;
215 * @copydoc Dali::InputMethodContext::ShowInputPanel()
217 void ShowInputPanel() override;
220 * @copydoc Dali::InputMethodContext::HideInputPanel()
222 void HideInputPanel() override;
225 * @copydoc Dali::InputMethodContext::GetKeyboardType()
227 Dali::InputMethodContext::KeyboardType GetKeyboardType() override;
230 * @copydoc Dali::InputMethodContext::GetInputPanelLocale()
232 std::string GetInputPanelLocale() override;
235 * @copydoc Dali::InputMethodContext::SetContentMIMETypes()
237 void SetContentMIMETypes(const std::string& mimeTypes) override;
240 * @copydoc Dali::InputMethodContext::FilterEventKey()
242 bool FilterEventKey(const Dali::KeyEvent& keyEvent) override;
245 * @copydoc Dali::InputMethodContext::AllowTextPrediction()
247 void AllowTextPrediction(bool prediction) override;
250 * @copydoc Dali::InputMethodContext::IsTextPredictionAllowed()
252 bool IsTextPredictionAllowed() const override;
255 * @copydoc Dali::InputMethodContext::SetInputPanelLanguage()
257 void SetInputPanelLanguage(Dali::InputMethodContext::InputPanelLanguage language) override;
260 * @copydoc Dali::InputMethodContext::GetInputPanelLanguage()
262 Dali::InputMethodContext::InputPanelLanguage GetInputPanelLanguage() const override;
265 * @copydoc Dali::InputMethodContext::SetInputPanelPosition()
267 void SetInputPanelPosition(unsigned int x, unsigned int y) override;
270 * @copydoc Dali::InputMethodContext::GetPreeditStyle()
272 void GetPreeditStyle(Dali::InputMethodContext::PreEditAttributeDataContainer& attrs) const override;
276 * Context created the first time and kept until deleted.
278 void CreateContext();
281 * @copydoc Dali::InputMethodContext::DeleteContext()
283 void DeleteContext();
287 * @brief Process event key down, whether filter a key to isf.
289 * @param[in] keyEvent The event key to be handled.
290 * @return Whether the event key is handled.
292 bool ProcessEventKeyDown(const Dali::KeyEvent& keyEvent);
295 * @brief Process event key up, whether filter a key to isf.
297 * @param[in] keyEvent The event key to be handled.
298 * @return Whether the event key is handled.
300 bool ProcessEventKeyUp(const Dali::KeyEvent& keyEvent);
303 * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
304 * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
305 * @param[in] ecoreModifier the Ecore_Event_Modifier input.
306 * @return the Ecore_IMF_Keyboard_Modifiers output.
308 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier);
311 * EcoreInputModifierToEcoreIMFLock function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Locks enums.
312 * @param[in] modifier the Ecore_Event_Modifier input.
313 * @return the Ecore_IMF_Keyboard_Locks output.
315 Ecore_IMF_Keyboard_Locks EcoreInputModifierToEcoreIMFLock(unsigned int modifier);
318 * Called when the binded actor is added to a window.
320 void OnStaged(Dali::Actor actor);
326 virtual ~InputMethodContextX();
329 // Undefined copy constructor
330 InputMethodContextX(const InputMethodContextX& inputMethodContext) = delete;
332 // Undefined assignment operator
333 InputMethodContextX& operator=(const InputMethodContextX& inputMethodContext) = delete;
336 Ecore_IMF_Context* mIMFContext;
337 Ecore_X_Window mEcoreXwin;
338 int mIMFCursorPosition;
339 std::string mSurroundingText;
341 bool mRestoreAfterFocusLost : 1; ///< Whether the keyboard needs to be restored (activated ) after focus regained.
342 bool mIdleCallbackConnected : 1; ///< Whether the idle callback is already connected.
343 InputMethodOptions mOptions;
345 Dali::InputMethodContext::PreEditAttributeDataContainer mPreeditAttrs; ///< Stores preedit attribute data
348 } // namespace Adaptor
350 } // namespace Internal
354 #endif // DALI_INTERNAL_INPUT_METHOD_CONTEXT_IMPL_X_H