Merge "Add to set MIME type to the input panel and add the callback" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / common / input-method-context-impl.h
1 #ifndef DALI_INTERNAL_INPUT_COMMON_INPUT_METHOD_CONTEXT_IMPL_H
2 #define DALI_INTERNAL_INPUT_COMMON_INPUT_METHOD_CONTEXT_IMPL_H
3
4 /*
5  * Copyright (c) 2019 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 <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/integration-api/events/key-event-integ.h>
25
26 // INTERNAL INCLUDES
27 #include <dali/devel-api/adaptor-framework/input-method-context.h>
28
29 #include <memory>
30
31 namespace Dali
32 {
33
34 class RenderSurface;
35
36 namespace Internal
37 {
38
39 namespace Adaptor
40 {
41 class InputMethodContext;
42 typedef IntrusivePtr< InputMethodContext > InputMethodContextPtr;
43 using ImfContext = void;
44
45 class InputMethodContext : public Dali::BaseObject
46 {
47
48 public:
49
50   using ActivatedSignalType = Dali::InputMethodContext::ActivatedSignalType;
51   using KeyboardEventSignalType = Dali::InputMethodContext::KeyboardEventSignalType;
52   using StatusSignalType = Dali::InputMethodContext::StatusSignalType;
53   using VoidSignalType = Dali::InputMethodContext::VoidSignalType;
54   using KeyboardTypeSignalType = Dali::InputMethodContext::KeyboardTypeSignalType;
55   using LanguageChangedSignalType = Dali::InputMethodContext::LanguageChangedSignalType;
56   using KeyboardResizedSignalType = Dali::InputMethodContext::KeyboardResizedSignalType;
57   using ContentReceivedSignalType = Dali::InputMethodContext::ContentReceivedSignalType;
58
59 public:
60
61   /**
62    * Create a new input method context instance.
63    */
64   static InputMethodContextPtr New();
65
66   /**
67    * Initialize the object.
68    */
69   virtual void Initialize() {}
70
71   /**
72    * Connect Callbacks required for InputMethodContext.
73    * If you don't connect InputMethodContext callbacks, you can't get the key events.
74    * The events are PreeditChanged, Commit, DeleteSurrounding and PrivateCommand.
75    */
76   virtual void ConnectCallbacks() {}
77
78   /**
79    * Disconnect Callbacks attached to input method context.
80    */
81   virtual void DisconnectCallbacks() {}
82
83   /**
84    * @copydoc Dali::InputMethodContext::Finalize()
85    */
86   virtual void Finalize() {}
87
88   /**
89    * @copydoc Dali::InputMethodContext::Activate()
90    */
91   virtual void Activate() {}
92
93   /**
94    * @copydoc Dali::InputMethodContext::Deactivate()
95    */
96   virtual void Deactivate() {}
97
98   /**
99    * @copydoc Dali::InputMethodContext::Reset()
100    */
101   virtual void Reset() {}
102
103   /**
104    * @copydoc Dali::InputMethodContext::GetContext()
105    */
106   virtual ImfContext* GetContext() { return nullptr; }
107
108   /**
109    * @copydoc Dali::InputMethodContext::RestoreAfterFocusLost()
110    */
111   virtual bool RestoreAfterFocusLost() const { return false; }
112
113   /**
114    * @copydoc Dali::InputMethodContext::SetRestoreAfterFocusLost()
115    */
116   virtual void SetRestoreAfterFocusLost( bool toggle ) {}
117
118   /**
119    * @copydoc Dali::InputMethodContext::PreEditChanged()
120    */
121   virtual void PreEditChanged( void *data, ImfContext* imfContext, void *eventInfo ) {}
122
123   /**
124    * @copydoc Dali::InputMethodContext::CommitReceived()
125    */
126   virtual void CommitReceived( void *data, ImfContext* imfContext, void *eventInfo ) {}
127
128   /**
129    * @copydoc Dali::InputMethodContext::RetrieveSurrounding()
130    */
131   /*Eina_Bool*/
132   virtual bool RetrieveSurrounding( void *data, ImfContext* imfContext, char** text, int* cursorPosition ) { return false; }
133
134   /**
135    * @copydoc Dali::InputMethodContext::DeleteSurrounding()
136    */
137   virtual void DeleteSurrounding( void *data, ImfContext* imfContext, void *eventInfo ) {}
138
139   /**
140    * @copydoc Dali::InputMethodContext::SendPrivateCommand()
141    */
142   virtual void SendPrivateCommand( void* data, ImfContext* imfContext, void* eventInfo ) {}
143
144   /**
145    * @copydoc Dali::InputMethodContext::SendCommitContent()
146    */
147   virtual void SendCommitContent( void* data, ImfContext* imfContext, void* eventInfo ) {}
148
149   // Cursor related
150   /**
151    * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
152    */
153   virtual void NotifyCursorPosition() {}
154
155   /**
156    * @copydoc Dali::InputMethodContext::SetCursorPosition()
157    */
158   virtual void SetCursorPosition( unsigned int cursorPosition ) {}
159
160   /**
161    * @copydoc Dali::InputMethodContext::GetCursorPosition()
162    */
163   virtual unsigned int GetCursorPosition() const { return 0; }
164
165   /**
166    * @copydoc Dali::InputMethodContext::SetSurroundingText()
167    */
168   virtual void SetSurroundingText( const std::string& text ) {}
169
170   /**
171    * @copydoc Dali::InputMethodContext::GetSurroundingText()
172    */
173   virtual const std::string& GetSurroundingText() const;
174
175   /**
176   * @copydoc Dali::InputMethodContext::NotifyTextInputMultiLine()
177   */
178   virtual void NotifyTextInputMultiLine( bool multiLine ) {}
179
180   /**
181   * @copydoc Dali::InputMethodContext::GetTextDirection()
182   */
183   virtual Dali::InputMethodContext::TextDirection GetTextDirection() { return Dali::InputMethodContext::TextDirection(); }
184
185   /**
186   * @copydoc Dali::InputMethodContext::GetInputMethodArea()
187   */
188   virtual Dali::Rect<int> GetInputMethodArea() { return Dali::Rect<int>(); }
189
190   /**
191   * @copydoc Dali::InputMethodContext::ApplyOptions()
192   */
193   virtual void ApplyOptions( const InputMethodOptions& options ) {}
194
195   /**
196    * @copydoc Dali::InputMethodContext::SetInputPanelData()
197    */
198   virtual void SetInputPanelData( const std::string& data ) {}
199
200   /**
201    * @copydoc Dali::InputMethodContext::GetInputPanelData()
202    */
203   virtual void GetInputPanelData( std::string& data ) {}
204
205   /**
206    * @copydoc Dali::InputMethodContext::GetInputPanelState()
207    */
208   virtual Dali::InputMethodContext::State GetInputPanelState() { return Dali::InputMethodContext::State(); }
209
210   /**
211    * @copydoc Dali::InputMethodContext::SetReturnKeyState()
212    */
213   virtual void SetReturnKeyState( bool visible ) {}
214
215   /**
216    * @copydoc Dali::InputMethodContext::AutoEnableInputPanel()
217    */
218   virtual void AutoEnableInputPanel( bool enabled ) {}
219
220   /**
221    * @copydoc Dali::InputMethodContext::ShowInputPanel()
222    */
223   virtual void ShowInputPanel() {}
224
225   /**
226    * @copydoc Dali::InputMethodContext::HideInputPanel()
227    */
228   virtual void HideInputPanel() {}
229
230   /**
231    * @copydoc Dali::InputMethodContext::GetKeyboardType()
232    */
233   virtual Dali::InputMethodContext::KeyboardType GetKeyboardType() { return Dali::InputMethodContext::KeyboardType(); }
234
235   /**
236    * @copydoc Dali::InputMethodContext::GetInputPanelLocale()
237    */
238   virtual std::string GetInputPanelLocale() { return std::string(); }
239
240   /**
241    * @copydoc Dali::InputMethodContext::SetContentMIMETypes()
242    */
243   virtual void SetContentMIMETypes( const std::string& mimeTypes ) {}
244
245   /**
246    * @copydoc Dali::InputMethodContext::FilterEventKey()
247    */
248   virtual bool FilterEventKey( const Dali::KeyEvent& keyEvent ) { return false; }
249
250   /**
251    * @copydoc Dali::InputMethodContext::AllowTextPrediction()
252    */
253   virtual void AllowTextPrediction( bool prediction ) {}
254
255   /**
256    * @copydoc Dali::InputMethodContext::IsTextPredictionAllowed()
257    */
258   virtual bool IsTextPredictionAllowed() const { return false; }
259
260   /**
261    * @copydoc Dali::InputMethodContext::SetInputPanelLanguage()
262    */
263   virtual void SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language ) {}
264
265   /**
266    * @copydoc Dali::InputMethodContext::GetInputPanelLanguage()
267    */
268   virtual Dali::InputMethodContext::InputPanelLanguage GetInputPanelLanguage() const { return Dali::InputMethodContext::InputPanelLanguage(); }
269
270 public:  // Signals
271
272   /**
273    * @copydoc Dali::InputMethodContext::ActivatedSignal()
274    */
275   ActivatedSignalType& ActivatedSignal() { return mActivatedSignal; }
276
277   /**
278    * @copydoc Dali::InputMethodContext::EventReceivedSignal()
279    */
280   KeyboardEventSignalType& EventReceivedSignal() { return mEventSignal; }
281
282   /**
283    * @copydoc Dali::InputMethodContext::StatusChangedSignal()
284    */
285   StatusSignalType& StatusChangedSignal() { return mKeyboardStatusSignal; }
286
287   /**
288    * @copydoc Dali::InputMethodContext::ResizedSignal()
289    */
290   KeyboardResizedSignalType& ResizedSignal()  { return mKeyboardResizeSignal; }
291
292   /**
293    * @copydoc Dali::InputMethodContext::LanguageChangedSignal()
294    */
295   LanguageChangedSignalType& LanguageChangedSignal() { return mKeyboardLanguageChangedSignal; }
296
297   /**
298    * @copydoc Dali::InputMethodContext::KeyboardTypeChangedSignal()
299    */
300   KeyboardTypeSignalType& KeyboardTypeChangedSignal() { return mKeyboardTypeChangedSignal; }
301
302   /**
303    * @copydoc Dali::InputMethodContext::ContentReceivedSignal()
304    */
305   ContentReceivedSignalType& ContentReceivedSignal() { return mContentReceivedSignal; }
306
307 public:
308
309   /**
310    * Constructor
311    */
312   InputMethodContext() = default;
313
314   /**
315    * Destructor
316    */
317   ~InputMethodContext() override = default;
318
319 private:
320
321   InputMethodContext( const InputMethodContext& ) = delete;
322   InputMethodContext& operator=( InputMethodContext& )  = delete;
323
324 protected:
325
326   ActivatedSignalType        mActivatedSignal;
327   KeyboardEventSignalType    mEventSignal;
328   StatusSignalType           mKeyboardStatusSignal;
329   KeyboardResizedSignalType  mKeyboardResizeSignal;
330   LanguageChangedSignalType  mKeyboardLanguageChangedSignal;
331   KeyboardTypeSignalType     mKeyboardTypeChangedSignal;
332   ContentReceivedSignalType  mContentReceivedSignal;
333
334 public:
335
336   inline static Internal::Adaptor::InputMethodContext& GetImplementation(Dali::InputMethodContext& inputMethodContext)
337   {
338     DALI_ASSERT_ALWAYS( inputMethodContext && "InputMethodContext handle is empty" );
339
340     BaseObject& handle = inputMethodContext.GetBaseObject();
341
342     return static_cast<Internal::Adaptor::InputMethodContext&>(handle);
343   }
344
345   inline static const Internal::Adaptor::InputMethodContext& GetImplementation(const Dali::InputMethodContext& inputMethodContext)
346   {
347     DALI_ASSERT_ALWAYS( inputMethodContext && "InputMethodContext handle is empty" );
348
349     const BaseObject& handle = inputMethodContext.GetBaseObject();
350
351     return static_cast<const Internal::Adaptor::InputMethodContext&>(handle);
352   }
353
354 };
355
356
357 } // namespace Adaptor
358
359 } // namespace Internal
360
361 } // namespace Dali
362
363 #endif // DALI_INTERNAL_INPUT_COMMON_INPUT_METHOD_CONTEXT_IMPL_H