700bd9a9cf071544232df7f8c8f667b378fe3c6d
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / tizen-wayland / ecore-wl2 / imf-manager-impl-ecore-wl2.h
1 #ifndef DALI_INTERNAL_INPUT_COMMON_IMF_MANAGER_IMPL_ECORE_WL2_H
2 #define DALI_INTERNAL_INPUT_COMMON_IMF_MANAGER_IMPL_ECORE_WL2_H
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <Ecore_IMF.h>
23 #include <Ecore.h>
24 //TIZEN_MIGRATION
25 #include <Ecore_Wl2.h>
26 //
27
28
29 #include <dali/public-api/common/vector-wrapper.h>
30 #include <dali/public-api/object/base-object.h>
31 #include <dali/integration-api/events/key-event-integ.h>
32
33 // INTERNAL INCLUDES
34 #include <dali/internal/input/common/imf-manager-impl.h>
35
36 namespace Dali
37 {
38
39 class RenderSurface;
40
41 namespace Internal
42 {
43
44 namespace Adaptor
45 {
46
47 class ImfManagerEcoreWl : public Dali::Internal::Adaptor::ImfManager
48 {
49 public:
50
51   /**
52    * Check whether the ImfManager is available.
53    * @return true if available, false otherwise
54    */
55   static bool IsAvailable();
56
57   /**
58    * Get the IMF manager instance, it creates the instance if it has not already been created.
59    * Internally, a check should be made using IsAvailable() before this is called as we do not want
60    * to create an instance if not needed by applications.
61    * @see IsAvailable()
62    */
63   static Dali::ImfManager Get();
64
65   /**
66    * Connect Callbacks required for IMF.
67    * If you don't connect imf callbacks, you can't get the key events.
68    * The events are PreeditChanged, Commit, DeleteSurrounding and PrivateCommand.
69    */
70   void ConnectCallbacks() override;
71
72   /**
73    * Disconnect Callbacks attached to imf context.
74    */
75   void DisconnectCallbacks() override;
76
77   /**
78    * @copydoc Dali::ImfManager::Activate()
79    */
80   void Activate() override;
81
82   /**
83    * @copydoc Dali::ImfManager::Deactivate()
84    */
85   void Deactivate() override;
86
87   /**
88    * @copydoc Dali::ImfManager::Reset()
89    */
90   void Reset() override;
91
92   /**
93    * @copydoc Dali::ImfManager::GetContext()
94    */
95   ImfContext* GetContext() override;
96
97   /**
98    * @copydoc Dali::ImfManager::RestoreAfterFocusLost()
99    */
100   bool RestoreAfterFocusLost() const override;
101
102   /**
103    * @copydoc Dali::ImfManager::SetRestoreAfterFocusLost()
104    */
105   void SetRestoreAfterFocusLost( bool toggle ) override;
106
107   /**
108    * @copydoc Dali::ImfManager::PreEditChanged()
109    */
110   void PreEditChanged( void *data, Ecore_IMF_Context *imfContext, void *event_info );
111
112   /**
113    * @copydoc Dali::ImfManager::NotifyCursorPosition()
114    */
115   void CommitReceived( void *data, Ecore_IMF_Context *imfContext, void *event_info );
116
117   /**
118    * @copydoc Dali::ImfManager::NotifyCursorPosition()
119    */
120   Eina_Bool RetrieveSurrounding( void *data, Ecore_IMF_Context *imfContext, char** text, int* cursorPosition );
121
122   /**
123    * @copydoc Dali::ImfManager::DeleteSurrounding()
124    */
125   void DeleteSurrounding( void *data, Ecore_IMF_Context *imfContext, void *event_info );
126
127   /**
128    * @copydoc Dali::ImfManager::SendPrivateCommand()
129    */
130   void SendPrivateCommand( void* data, Ecore_IMF_Context* imfContext, void* event_info );
131
132   // Cursor related
133   /**
134    * @copydoc Dali::ImfManager::NotifyCursorPosition()
135    */
136   void NotifyCursorPosition() override;
137
138   /**
139    * @copydoc Dali::ImfManager::SetCursorPosition()
140    */
141   void SetCursorPosition( unsigned int cursorPosition ) override;
142
143   /**
144    * @copydoc Dali::ImfManager::GetCursorPosition()
145    */
146   unsigned int GetCursorPosition() const override;
147
148   /**
149    * @copydoc Dali::ImfManager::SetSurroundingText()
150    */
151   void SetSurroundingText( const std::string& text ) override;
152
153   /**
154    * @copydoc Dali::ImfManager::GetSurroundingText()
155    */
156   const std::string& GetSurroundingText() const override;
157
158   /**
159   * @copydoc Dali::ImfManager::NotifyTextInputMultiLine()
160   */
161   void NotifyTextInputMultiLine( bool multiLine ) override;
162
163   /**
164   * @copydoc Dali::ImfManager::GetTextDirection()
165   */
166   Dali::ImfManager::TextDirection GetTextDirection() override;
167
168   /**
169   * @copydoc Dali::ImfManager::GetInputMethodArea()
170   */
171   Dali::Rect<int> GetInputMethodArea() override;
172
173   /**
174   * @copydoc Dali::ImfManager::ApplyOptions()
175   */
176   void ApplyOptions( const InputMethodOptions& options ) override;
177
178   /**
179    * @copydoc Dali::ImfManager::SetInputPanelData()
180    */
181   void SetInputPanelData( const std::string& data ) override;
182
183   /**
184    * @copydoc Dali::ImfManager::GetInputPanelData()
185    */
186   void GetInputPanelData( std::string& data ) override;
187
188   /**
189    * @copydoc Dali::ImfManager::GetInputPanelState()
190    */
191   Dali::ImfManager::State GetInputPanelState() override;
192
193   /**
194    * @copydoc Dali::ImfManager::SetReturnKeyState()
195    */
196   void SetReturnKeyState( bool visible ) override;
197
198   /**
199    * @copydoc Dali::ImfManager::AutoEnableInputPanel()
200    */
201   void AutoEnableInputPanel( bool enabled ) override;
202
203   /**
204    * @copydoc Dali::ImfManager::ShowInputPanel()
205    */
206   void ShowInputPanel() override;
207
208   /**
209    * @copydoc Dali::ImfManager::HideInputPanel()
210    */
211   void HideInputPanel() override;
212
213   /**
214    * @copydoc Dali::ImfManager::GetKeyboardType()
215    */
216   Dali::ImfManager::KeyboardType GetKeyboardType() override;
217
218   /**
219    * @copydoc Dali::ImfManager::GetInputPanelLocale()
220    */
221   std::string GetInputPanelLocale() override;
222
223 protected:
224
225   /**
226    * Destructor.
227    */
228   virtual ~ImfManagerEcoreWl() override;
229
230 private:
231   /**
232    * Context created the first time and kept until deleted.
233    * @param[in] ecoreWlwin, The window is created by application.
234    */
235   void CreateContext( Ecore_Wl2_Window *ecoreWlwin );
236
237   /**
238    * @copydoc Dali::ImfManager::DeleteContext()
239    */
240   void DeleteContext();
241
242 private:
243   // Undefined
244   explicit ImfManagerEcoreWl( Ecore_Wl2_Window *ecoreWlwin );
245   explicit ImfManagerEcoreWl( const ImfManager& ) = delete;
246   ImfManagerEcoreWl& operator=( ImfManager& ) = delete;
247
248 private:
249   Ecore_IMF_Context* mIMFContext;
250   int mIMFCursorPosition;
251   std::string mSurroundingText;
252
253   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
254   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
255
256   std::vector<Dali::Integration::KeyEvent> mKeyEvents; ///< Stores key events to be sent from idle call-back.
257   InputMethodOptions        mOptions;
258 };
259
260
261 } // namespace Adaptor
262
263 } // namespace Internal
264
265 } // namespace Dali
266
267 #endif // DALI_INTERNAL_INPUT_COMMON_IMF_MANAGER_IMPL_ECORE_WL2_H