4 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/object/base-object.h>
24 #include <dali/devel-api/adaptor-framework/input-method-context.h>
25 #include <dali/internal/input/common/input-method-context-impl.h>
38 class InputMethodContextCocoa : public Dali::Internal::Adaptor::InputMethodContext, public Dali::ConnectionTracker
42 * @brief Creates a new InputMethodContext handle
44 * @param[in] actor The actor that uses the new InputMethodContext instance.
45 * @return InputMethodContext pointer
47 static InputMethodContextPtr New( Dali::Actor actor );
51 * @param[in] win32Window, The window is created by application.
53 explicit InputMethodContextCocoa( 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
136 * @copydoc Dali::InputMethodContext::SendCommitContent()
138 void SendCommitContent( void* data, ImfContext* imfContext, void* eventInfo ) override
143 * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
145 void NotifyCursorPosition() override;
148 * @copydoc Dali::InputMethodContext::SetCursorPosition()
150 void SetCursorPosition( unsigned int cursorPosition ) override;
153 * @copydoc Dali::InputMethodContext::GetCursorPosition()
155 unsigned int GetCursorPosition() const override;
158 * @copydoc Dali::InputMethodContext::SetSurroundingText()
160 void SetSurroundingText( const std::string& text ) override;
163 * @copydoc Dali::InputMethodContext::GetSurroundingText()
165 const std::string& GetSurroundingText() const override;
168 * @copydoc Dali::InputMethodContext::NotifyTextInputMultiLine()
170 void NotifyTextInputMultiLine( bool multiLine ) override;
173 * @copydoc Dali::InputMethodContext::GetTextDirection()
175 Dali::InputMethodContext::TextDirection GetTextDirection() override;
178 * @copydoc Dali::InputMethodContext::GetInputMethodArea()
180 Dali::Rect<int> GetInputMethodArea() override;
183 * @copydoc Dali::InputMethodContext::ApplyOptions()
185 void ApplyOptions( const InputMethodOptions& options ) override;
188 * @copydoc Dali::InputMethodContext::SetInputPanelData()
190 void SetInputPanelData( const std::string& data ) override;
193 * @copydoc Dali::InputMethodContext::GetInputPanelData()
195 void GetInputPanelData( std::string& data ) override;
198 * @copydoc Dali::InputMethodContext::GetInputPanelState()
200 Dali::InputMethodContext::State GetInputPanelState() override;
203 * @copydoc Dali::InputMethodContext::SetReturnKeyState()
205 void SetReturnKeyState( bool visible ) override;
208 * @copydoc Dali::InputMethodContext::AutoEnableInputPanel()
210 void AutoEnableInputPanel( bool enabled ) override;
213 * @copydoc Dali::InputMethodContext::ShowInputPanel()
215 void ShowInputPanel() override;
218 * @copydoc Dali::InputMethodContext::HideInputPanel()
220 void HideInputPanel() override;
223 * @copydoc Dali::InputMethodContext::GetKeyboardType()
225 Dali::InputMethodContext::KeyboardType GetKeyboardType() override;
228 * @copydoc Dali::InputMethodContext::GetInputPanelLocale()
230 std::string GetInputPanelLocale() override;
233 * @copydoc Dali::InputMethodContext::SetContentMIMETypes()
235 void SetContentMIMETypes( const std::string& mimeTypes ) override;
238 * @copydoc Dali::InputMethodContext::FilterEventKey()
240 bool FilterEventKey( const Dali::KeyEvent& keyEvent ) override;
243 * @copydoc Dali::InputMethodContext::SetInputPanelLanguage()
245 void SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language ) override;
248 * @copydoc Dali::InputMethodContext::GetInputPanelLanguage()
250 Dali::InputMethodContext::InputPanelLanguage GetInputPanelLanguage() const override;
253 * @copydoc Dali::InputMethodContext::SetInputPanelPosition()
255 void SetInputPanelPosition( unsigned int x, unsigned int y ) override;
258 * @copydoc Dali::InputMethodContext::GetPreeditStyle()
260 void GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const override;
265 * @brief Process event key down, whether filter a key to isf.
267 * @param[in] keyEvent The event key to be handled.
268 * @return Whether the event key is handled.
270 bool ProcessEventKeyDown( const Dali::KeyEvent& keyEvent );
273 * @brief Process event key up, whether filter a key to isf.
275 * @param[in] keyEvent The event key to be handled.
276 * @return Whether the event key is handled.
278 bool ProcessEventKeyUp( const Dali::KeyEvent& keyEvent );
281 * Called when the binded actor is added to a window.
283 void OnStaged( Dali::Actor actor );
290 virtual ~InputMethodContextCocoa();
294 // Undefined copy constructor
295 InputMethodContextCocoa( const InputMethodContextCocoa& inputMethodContext) = delete;
297 // Undefined assignment operator
298 InputMethodContextCocoa& operator=( const InputMethodContextCocoa& inputMethodContext ) = delete;
301 int mIMFCursorPosition;
302 std::string mSurroundingText;
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
310 } // namespace Adaptor
312 } // namespace Internal