1 #ifndef DALI_INTERNAL_INPUT_COMMON_INPUT_METHOD_CONTEXT_IMPL_H
2 #define DALI_INTERNAL_INPUT_COMMON_INPUT_METHOD_CONTEXT_IMPL_H
5 * Copyright (c) 2019 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.
24 #include <dali/public-api/actors/actor.h>
25 #include <dali/public-api/common/vector-wrapper.h>
26 #include <dali/public-api/object/base-object.h>
27 #include <dali/integration-api/events/key-event-integ.h>
30 #include <dali/devel-api/adaptor-framework/input-method-context.h>
42 class InputMethodContext;
43 typedef IntrusivePtr< InputMethodContext > InputMethodContextPtr;
44 using ImfContext = void;
46 class InputMethodContext : public Dali::BaseObject
51 using ActivatedSignalType = Dali::InputMethodContext::ActivatedSignalType;
52 using KeyboardEventSignalType = Dali::InputMethodContext::KeyboardEventSignalType;
53 using StatusSignalType = Dali::InputMethodContext::StatusSignalType;
54 using VoidSignalType = Dali::InputMethodContext::VoidSignalType;
55 using KeyboardTypeSignalType = Dali::InputMethodContext::KeyboardTypeSignalType;
56 using LanguageChangedSignalType = Dali::InputMethodContext::LanguageChangedSignalType;
57 using KeyboardResizedSignalType = Dali::InputMethodContext::KeyboardResizedSignalType;
58 using ContentReceivedSignalType = Dali::InputMethodContext::ContentReceivedSignalType;
63 * Create a new input method context instance.
65 static InputMethodContextPtr New( Dali::Actor actor );
68 * Initialize the object.
70 virtual void Initialize() {}
73 * Connect Callbacks required for InputMethodContext.
74 * If you don't connect InputMethodContext callbacks, you can't get the key events.
75 * The events are PreeditChanged, Commit, DeleteSurrounding and PrivateCommand.
77 virtual void ConnectCallbacks() {}
80 * Disconnect Callbacks attached to input method context.
82 virtual void DisconnectCallbacks() {}
85 * @copydoc Dali::InputMethodContext::Finalize()
87 virtual void Finalize() {}
90 * @copydoc Dali::InputMethodContext::Activate()
92 virtual void Activate() {}
95 * @copydoc Dali::InputMethodContext::Deactivate()
97 virtual void Deactivate() {}
100 * @copydoc Dali::InputMethodContext::Reset()
102 virtual void Reset() {}
105 * @copydoc Dali::InputMethodContext::GetContext()
107 virtual ImfContext* GetContext() { return nullptr; }
110 * @copydoc Dali::InputMethodContext::RestoreAfterFocusLost()
112 virtual bool RestoreAfterFocusLost() const { return false; }
115 * @copydoc Dali::InputMethodContext::SetRestoreAfterFocusLost()
117 virtual void SetRestoreAfterFocusLost( bool toggle ) {}
120 * @copydoc Dali::InputMethodContext::PreEditChanged()
122 virtual void PreEditChanged( void *data, ImfContext* imfContext, void *eventInfo ) {}
125 * @copydoc Dali::InputMethodContext::CommitReceived()
127 virtual void CommitReceived( void *data, ImfContext* imfContext, void *eventInfo ) {}
130 * @copydoc Dali::InputMethodContext::RetrieveSurrounding()
133 virtual bool RetrieveSurrounding( void *data, ImfContext* imfContext, char** text, int* cursorPosition ) { return false; }
136 * @copydoc Dali::InputMethodContext::DeleteSurrounding()
138 virtual void DeleteSurrounding( void *data, ImfContext* imfContext, void *eventInfo ) {}
141 * @copydoc Dali::InputMethodContext::SendPrivateCommand()
143 virtual void SendPrivateCommand( void* data, ImfContext* imfContext, void* eventInfo ) {}
146 * @copydoc Dali::InputMethodContext::SendCommitContent()
148 virtual void SendCommitContent( void* data, ImfContext* imfContext, void* eventInfo ) {}
152 * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
154 virtual void NotifyCursorPosition() {}
157 * @copydoc Dali::InputMethodContext::SetCursorPosition()
159 virtual void SetCursorPosition( unsigned int cursorPosition ) {}
162 * @copydoc Dali::InputMethodContext::GetCursorPosition()
164 virtual unsigned int GetCursorPosition() const { return 0; }
167 * @copydoc Dali::InputMethodContext::SetSurroundingText()
169 virtual void SetSurroundingText( const std::string& text ) {}
172 * @copydoc Dali::InputMethodContext::GetSurroundingText()
174 virtual const std::string& GetSurroundingText() const;
177 * @copydoc Dali::InputMethodContext::NotifyTextInputMultiLine()
179 virtual void NotifyTextInputMultiLine( bool multiLine ) {}
182 * @copydoc Dali::InputMethodContext::GetTextDirection()
184 virtual Dali::InputMethodContext::TextDirection GetTextDirection() { return Dali::InputMethodContext::TextDirection(); }
187 * @copydoc Dali::InputMethodContext::GetInputMethodArea()
189 virtual Dali::Rect<int> GetInputMethodArea() { return Dali::Rect<int>(); }
192 * @copydoc Dali::InputMethodContext::ApplyOptions()
194 virtual void ApplyOptions( const InputMethodOptions& options ) {}
197 * @copydoc Dali::InputMethodContext::SetInputPanelData()
199 virtual void SetInputPanelData( const std::string& data ) {}
202 * @copydoc Dali::InputMethodContext::GetInputPanelData()
204 virtual void GetInputPanelData( std::string& data ) {}
207 * @copydoc Dali::InputMethodContext::GetInputPanelState()
209 virtual Dali::InputMethodContext::State GetInputPanelState() { return Dali::InputMethodContext::State(); }
212 * @copydoc Dali::InputMethodContext::SetReturnKeyState()
214 virtual void SetReturnKeyState( bool visible ) {}
217 * @copydoc Dali::InputMethodContext::AutoEnableInputPanel()
219 virtual void AutoEnableInputPanel( bool enabled ) {}
222 * @copydoc Dali::InputMethodContext::ShowInputPanel()
224 virtual void ShowInputPanel() {}
227 * @copydoc Dali::InputMethodContext::HideInputPanel()
229 virtual void HideInputPanel() {}
232 * @copydoc Dali::InputMethodContext::GetKeyboardType()
234 virtual Dali::InputMethodContext::KeyboardType GetKeyboardType() { return Dali::InputMethodContext::KeyboardType(); }
237 * @copydoc Dali::InputMethodContext::GetInputPanelLocale()
239 virtual std::string GetInputPanelLocale() { return std::string(); }
242 * @copydoc Dali::InputMethodContext::SetContentMIMETypes()
244 virtual void SetContentMIMETypes( const std::string& mimeTypes ) {}
247 * @copydoc Dali::InputMethodContext::FilterEventKey()
249 virtual bool FilterEventKey( const Dali::KeyEvent& keyEvent ) { return false; }
252 * @copydoc Dali::InputMethodContext::AllowTextPrediction()
254 virtual void AllowTextPrediction( bool prediction ) {}
257 * @copydoc Dali::InputMethodContext::IsTextPredictionAllowed()
259 virtual bool IsTextPredictionAllowed() const { return false; }
262 * @copydoc Dali::InputMethodContext::SetInputPanelLanguage()
264 virtual void SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language ) {}
267 * @copydoc Dali::InputMethodContext::GetInputPanelLanguage()
269 virtual Dali::InputMethodContext::InputPanelLanguage GetInputPanelLanguage() const { return Dali::InputMethodContext::InputPanelLanguage(); }
272 * @copydoc Dali::InputMethodContext::SetInputPanelPosition()
274 virtual void SetInputPanelPosition( unsigned int x, unsigned int y ) {}
277 * @copydoc Dali::InputMethodContext::GetPreeditStyle()
279 virtual void GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttributeData >& attrs ) const {}
284 * @copydoc Dali::InputMethodContext::ActivatedSignal()
286 ActivatedSignalType& ActivatedSignal() { return mActivatedSignal; }
289 * @copydoc Dali::InputMethodContext::EventReceivedSignal()
291 KeyboardEventSignalType& EventReceivedSignal() { return mEventSignal; }
294 * @copydoc Dali::InputMethodContext::StatusChangedSignal()
296 StatusSignalType& StatusChangedSignal() { return mKeyboardStatusSignal; }
299 * @copydoc Dali::InputMethodContext::ResizedSignal()
301 KeyboardResizedSignalType& ResizedSignal() { return mKeyboardResizeSignal; }
304 * @copydoc Dali::InputMethodContext::LanguageChangedSignal()
306 LanguageChangedSignalType& LanguageChangedSignal() { return mKeyboardLanguageChangedSignal; }
309 * @copydoc Dali::InputMethodContext::KeyboardTypeChangedSignal()
311 KeyboardTypeSignalType& KeyboardTypeChangedSignal() { return mKeyboardTypeChangedSignal; }
314 * @copydoc Dali::InputMethodContext::ContentReceivedSignal()
316 ContentReceivedSignalType& ContentReceivedSignal() { return mContentReceivedSignal; }
323 InputMethodContext();
328 ~InputMethodContext() override = default;
332 InputMethodContext( const InputMethodContext& ) = delete;
333 InputMethodContext& operator=( InputMethodContext& ) = delete;
337 * @brief Struct for providing Operation enumeration
343 ALLOW_TEXT_PREDICTION = 0,
344 AUTO_ENABLE_INPUT_PANEL,
345 NOTIFY_TEXT_INPUT_MULTILINE,
346 SET_CONTENT_MIME_TYPES,
347 SET_INPUT_PANEL_DATA,
348 SET_INPUT_PANEL_LANGUAGE,
349 SET_INPUT_PANEL_POSITION,
350 SET_RETURN_KEY_STATE,
355 using OperationList = std::vector< std::function<void()> >;
358 * @brief Apply backup operations to the InputMethodContext
360 void ApplyBackupOperations();
364 ActivatedSignalType mActivatedSignal;
365 KeyboardEventSignalType mEventSignal;
366 StatusSignalType mKeyboardStatusSignal;
367 KeyboardResizedSignalType mKeyboardResizeSignal;
368 LanguageChangedSignalType mKeyboardLanguageChangedSignal;
369 KeyboardTypeSignalType mKeyboardTypeChangedSignal;
370 ContentReceivedSignalType mContentReceivedSignal;
371 OperationList mBackupOperations;
375 inline static Internal::Adaptor::InputMethodContext& GetImplementation(Dali::InputMethodContext& inputMethodContext)
377 DALI_ASSERT_ALWAYS( inputMethodContext && "InputMethodContext handle is empty" );
379 BaseObject& handle = inputMethodContext.GetBaseObject();
381 return static_cast<Internal::Adaptor::InputMethodContext&>(handle);
384 inline static const Internal::Adaptor::InputMethodContext& GetImplementation(const Dali::InputMethodContext& inputMethodContext)
386 DALI_ASSERT_ALWAYS( inputMethodContext && "InputMethodContext handle is empty" );
388 const BaseObject& handle = inputMethodContext.GetBaseObject();
390 return static_cast<const Internal::Adaptor::InputMethodContext&>(handle);
396 } // namespace Adaptor
398 } // namespace Internal
402 #endif // DALI_INTERNAL_INPUT_COMMON_INPUT_METHOD_CONTEXT_IMPL_H