Support for the macOS platform
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / macos / input-method-context-impl-mac.h
1 #pragma once
2
3 /*
4  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/object/base-object.h>
22
23 // INTERNAL INCLUDES
24 #include <dali/devel-api/adaptor-framework/input-method-context.h>
25 #include <dali/internal/input/common/input-method-context-impl.h>
26
27 namespace Dali
28 {
29
30 class RenderSurface;
31
32 namespace Internal
33 {
34
35 namespace Adaptor
36 {
37
38 class InputMethodContextCocoa : public Dali::Internal::Adaptor::InputMethodContext, public Dali::ConnectionTracker
39 {
40 public:
41   /**
42    * @brief Creates a new InputMethodContext handle
43    *
44    * @param[in] actor The actor that uses the new InputMethodContext instance.
45    * @return InputMethodContext pointer
46    */
47   static InputMethodContextPtr New( Dali::Actor actor );
48
49   /**
50    * Constructor
51    * @param[in] win32Window, The window is created by application.
52    */
53   explicit InputMethodContextCocoa( Dali::Actor actor );
54
55 public:
56
57   /**
58    * @brief Initializes member data.
59    */
60   void Initialize() override;
61
62   /**
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.
66    */
67   void ConnectCallbacks() override;
68
69   /**
70    * Disconnect Callbacks attached to input method context.
71    */
72   void DisconnectCallbacks() override;
73
74   /**
75    * @copydoc Dali::InputMethodContext::Finalize()
76    */
77   void Finalize() override;
78
79   /**
80    * @copydoc Dali::InputMethodContext::Activate()
81    */
82   void Activate() override;
83
84   /**
85    * @copydoc Dali::InputMethodContext::Deactivate()
86    */
87   void Deactivate() override;
88
89   /**
90    * @copydoc Dali::InputMethodContext::Reset()
91    */
92   void Reset() override;
93
94   /**
95    * @copydoc Dali::InputMethodContext::GetContext()
96    */
97   ImfContext* GetContext() override;
98
99   /**
100    * @copydoc Dali::InputMethodContext::RestoreAfterFocusLost()
101    */
102   bool RestoreAfterFocusLost() const override;
103
104   /**
105    * @copydoc Dali::InputMethodContext::SetRestoreAfterFocusLost()
106    */
107   void SetRestoreAfterFocusLost( bool toggle ) override;
108
109   /**
110    * @copydoc Dali::InputMethodContext::PreEditChanged()
111    */
112   void PreEditChanged( void* data, ImfContext* imfContext, void* eventInfo ) override;
113
114   /**
115    * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
116    */
117   void CommitReceived( void* data, ImfContext* imfContext, void* eventInfo ) override;
118
119   /**
120    * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
121    */
122   bool RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition ) override;
123
124   /**
125    * @copydoc Dali::InputMethodContext::DeleteSurrounding()
126    */
127   void DeleteSurrounding( void* data, ImfContext* imfContext, void* eventInfo ) override;
128
129   /**
130    * @copydoc Dali::InputMethodContext::SendPrivateCommand()
131    */
132   void SendPrivateCommand( void* data, ImfContext* imfContext, void* eventInfo ) override
133   {}
134
135   /**
136    * @copydoc Dali::InputMethodContext::SendCommitContent()
137    */
138   void SendCommitContent( void* data, ImfContext* imfContext, void* eventInfo ) override
139   {}
140
141   // Cursor related
142   /**
143    * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
144    */
145   void NotifyCursorPosition() override;
146
147   /**
148    * @copydoc Dali::InputMethodContext::SetCursorPosition()
149    */
150   void SetCursorPosition( unsigned int cursorPosition ) override;
151
152   /**
153    * @copydoc Dali::InputMethodContext::GetCursorPosition()
154    */
155   unsigned int GetCursorPosition() const override;
156
157   /**
158    * @copydoc Dali::InputMethodContext::SetSurroundingText()
159    */
160   void SetSurroundingText( const std::string& text ) override;
161
162   /**
163    * @copydoc Dali::InputMethodContext::GetSurroundingText()
164    */
165   const std::string& GetSurroundingText() const override;
166
167   /**
168   * @copydoc Dali::InputMethodContext::NotifyTextInputMultiLine()
169   */
170   void NotifyTextInputMultiLine( bool multiLine ) override;
171
172   /**
173   * @copydoc Dali::InputMethodContext::GetTextDirection()
174   */
175   Dali::InputMethodContext::TextDirection GetTextDirection() override;
176
177   /**
178   * @copydoc Dali::InputMethodContext::GetInputMethodArea()
179   */
180   Dali::Rect<int> GetInputMethodArea() override;
181
182   /**
183   * @copydoc Dali::InputMethodContext::ApplyOptions()
184   */
185   void ApplyOptions( const InputMethodOptions& options ) override;
186
187   /**
188    * @copydoc Dali::InputMethodContext::SetInputPanelData()
189    */
190   void SetInputPanelData( const std::string& data ) override;
191
192   /**
193    * @copydoc Dali::InputMethodContext::GetInputPanelData()
194    */
195   void GetInputPanelData( std::string& data ) override;
196
197   /**
198    * @copydoc Dali::InputMethodContext::GetInputPanelState()
199    */
200   Dali::InputMethodContext::State GetInputPanelState() override;
201
202   /**
203    * @copydoc Dali::InputMethodContext::SetReturnKeyState()
204    */
205   void SetReturnKeyState( bool visible ) override;
206
207   /**
208    * @copydoc Dali::InputMethodContext::AutoEnableInputPanel()
209    */
210   void AutoEnableInputPanel( bool enabled ) override;
211
212   /**
213    * @copydoc Dali::InputMethodContext::ShowInputPanel()
214    */
215   void ShowInputPanel() override;
216
217   /**
218    * @copydoc Dali::InputMethodContext::HideInputPanel()
219    */
220   void HideInputPanel() override;
221
222   /**
223    * @copydoc Dali::InputMethodContext::GetKeyboardType()
224    */
225   Dali::InputMethodContext::KeyboardType GetKeyboardType() override;
226
227   /**
228    * @copydoc Dali::InputMethodContext::GetInputPanelLocale()
229    */
230   std::string GetInputPanelLocale() override;
231
232   /**
233    * @copydoc Dali::InputMethodContext::SetContentMIMETypes()
234    */
235   void SetContentMIMETypes( const std::string& mimeTypes ) override;
236
237   /**
238    * @copydoc Dali::InputMethodContext::FilterEventKey()
239    */
240   bool FilterEventKey( const Dali::KeyEvent& keyEvent ) override;
241
242   /**
243    * @copydoc Dali::InputMethodContext::SetInputPanelLanguage()
244    */
245   void SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language ) override;
246
247   /**
248    * @copydoc Dali::InputMethodContext::GetInputPanelLanguage()
249    */
250   Dali::InputMethodContext::InputPanelLanguage GetInputPanelLanguage() const override;
251
252   /**
253    * @copydoc Dali::InputMethodContext::SetInputPanelPosition()
254    */
255   void SetInputPanelPosition( unsigned int x, unsigned int y ) override;
256
257   /**
258    * @copydoc Dali::InputMethodContext::GetPreeditStyle()
259    */
260   void GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const override;
261
262 private:
263
264   /**
265    * @brief Process event key down, whether filter a key to isf.
266    *
267    * @param[in] keyEvent The event key to be handled.
268    * @return Whether the event key is handled.
269    */
270   bool ProcessEventKeyDown( const Dali::KeyEvent& keyEvent );
271
272   /**
273    * @brief Process event key up, whether filter a key to isf.
274    *
275    * @param[in] keyEvent The event key to be handled.
276    * @return Whether the event key is handled.
277    */
278   bool ProcessEventKeyUp( const Dali::KeyEvent& keyEvent );
279
280   /**
281    * Called when the binded actor is added to a window.
282    */
283   void OnStaged( Dali::Actor actor );
284
285 public:
286
287   /**
288    * Destructor.
289    */
290   virtual ~InputMethodContextCocoa();
291
292 private:
293
294   // Undefined copy constructor
295   InputMethodContextCocoa( const InputMethodContextCocoa& inputMethodContext) = delete;
296
297   // Undefined assignment operator
298   InputMethodContextCocoa& operator=( const InputMethodContextCocoa& inputMethodContext ) = delete;
299
300 private:
301   int mIMFCursorPosition;
302   std::string mSurroundingText;
303
304   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
305   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
306   InputMethodOptions        mOptions;
307   Dali::InputMethodContext::PreEditAttributeDataContainer mPreeditAttrs; ///< Stores preedit attribute data
308 };
309
310 } // namespace Adaptor
311
312 } // namespace Internal
313
314 } // namespace Dali