2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/input/ubuntu-x11/input-method-context-impl-x.h>
22 #include <dali/public-api/events/key-event.h>
23 #include <dali/public-api/object/type-registry.h>
24 #include <dali/integration-api/debug.h>
27 #include <dali/public-api/adaptor-framework/key.h>
28 #include <dali/integration-api/adaptors/adaptor.h>
29 #include <dali/internal/adaptor/common/adaptor-impl.h>
30 #include <dali/internal/input/common/key-impl.h>
31 #include <dali/internal/input/common/virtual-keyboard-impl.h>
32 #include <dali/internal/input/linux/dali-ecore-imf.h>
33 #include <dali/internal/input/tizen-wayland/ecore-virtual-keyboard.h>
34 #include <dali/internal/input/ubuntu-x11/dali-ecore-input.h>
35 #include <dali/internal/system/common/locale-utils.h>
36 #include <dali/internal/system/common/singleton-service-impl.h>
37 #include <dali/internal/system/linux/dali-ecore.h>
50 #if defined(DEBUG_ENABLED)
51 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_INPUT_METHOD_CONTEXT");
54 // Currently this code is internal to dali/dali/internal/event/text/utf8.h but should be made Public and used from there instead.
55 size_t Utf8SequenceLength(const unsigned char leadByte)
59 if ((leadByte & 0x80) == 0 ) //ASCII character (lead bit zero)
63 else if (( leadByte & 0xe0 ) == 0xc0 ) //110x xxxx
67 else if (( leadByte & 0xf0 ) == 0xe0 ) //1110 xxxx
71 else if (( leadByte & 0xf8 ) == 0xf0 ) //1111 0xxx
79 // Static function calls used by ecore 'c' style callback registration
80 void Commit( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
84 InputMethodContextX* inputMethodContext = static_cast< InputMethodContextX* >( data );
85 inputMethodContext->CommitReceived( data, imfContext, eventInfo );
89 void PreEdit( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
93 InputMethodContextX* inputMethodContext = static_cast< InputMethodContextX* >( data );
94 inputMethodContext->PreEditChanged( data, imfContext, eventInfo );
98 Eina_Bool ImfRetrieveSurrounding(void *data, Ecore_IMF_Context *imfContext, char** text, int* cursorPosition )
102 InputMethodContextX* inputMethodContext = static_cast< InputMethodContextX* >( data );
103 return inputMethodContext->RetrieveSurrounding( data, imfContext, text, cursorPosition );
112 * Called when an InputMethodContext delete surrounding event is received.
113 * Here we tell the application that it should delete a certain range.
115 void ImfDeleteSurrounding( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
119 InputMethodContextX* inputMethodContext = static_cast< InputMethodContextX* >( data );
120 inputMethodContext->DeleteSurrounding( data, imfContext, eventInfo );
124 } // unnamed namespace
126 InputMethodContextPtr InputMethodContextX::New( Dali::Actor actor )
128 InputMethodContextPtr manager;
130 if( actor && Dali::Adaptor::IsAvailable() )
132 manager = new InputMethodContextX( actor );
138 void InputMethodContextX::Finalize()
140 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Finalize\n" );
141 VirtualKeyboard::DisconnectCallbacks( mIMFContext );
142 DisconnectCallbacks();
146 InputMethodContextX::InputMethodContextX( Dali::Actor actor )
149 mIMFCursorPosition( 0 ),
151 mRestoreAfterFocusLost( false ),
152 mIdleCallbackConnected( false ),
153 mPreeditType( Dali::InputMethodContext::PreeditStyle::NONE )
157 actor.OnStageSignal().Connect( this, &InputMethodContextX::OnStaged );
160 InputMethodContextX::~InputMethodContextX()
163 ecore_imf_shutdown();
166 void InputMethodContextX::Initialize()
170 VirtualKeyboard::ConnectCallbacks( mIMFContext );
173 void InputMethodContextX::CreateContext()
175 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::CreateContext\n" );
182 const char *contextId = ecore_imf_context_default_id_get();
185 mIMFContext = ecore_imf_context_add( contextId );
189 ecore_imf_context_client_window_set( mIMFContext, reinterpret_cast<void*>( mEcoreXwin ) );
193 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext Unable to get IMFContext\n");
198 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext Unable to get IMFContext\n");
202 void InputMethodContextX::DeleteContext()
204 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::DeleteContext\n" );
208 ecore_imf_context_del( mIMFContext );
213 // Callbacks for predicitive text support.
214 void InputMethodContextX::ConnectCallbacks()
218 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::ConnectCallbacks\n" );
220 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit, this );
221 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit, this );
222 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding, this );
224 ecore_imf_context_retrieve_surrounding_callback_set( mIMFContext, ImfRetrieveSurrounding, this);
228 void InputMethodContextX::DisconnectCallbacks()
232 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::DisconnectCallbacks\n" );
234 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit );
235 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit );
236 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding );
238 // We do not need to unset the retrieve surrounding callback.
242 void InputMethodContextX::Activate()
244 // Reset mIdleCallbackConnected
245 mIdleCallbackConnected = false;
249 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Activate\n" );
251 ecore_imf_context_focus_in( mIMFContext );
253 // emit keyboard activated signal
254 Dali::InputMethodContext handle( this );
255 mActivatedSignal.Emit( handle );
259 void InputMethodContextX::Deactivate()
263 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Deactivate\n" );
266 ecore_imf_context_focus_out( mIMFContext );
269 // Reset mIdleCallbackConnected
270 mIdleCallbackConnected = false;
273 void InputMethodContextX::Reset()
275 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Reset\n" );
279 ecore_imf_context_reset( mIMFContext );
283 ImfContext* InputMethodContextX::GetContext()
285 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetContext\n" );
290 bool InputMethodContextX::RestoreAfterFocusLost() const
292 return mRestoreAfterFocusLost;
295 void InputMethodContextX::SetRestoreAfterFocusLost( bool toggle )
297 mRestoreAfterFocusLost = toggle;
301 * Called when an InputMethodContext Pre-Edit changed event is received.
302 * We are still predicting what the user is typing. The latest string is what the InputMethodContext module thinks
303 * the user wants to type.
305 void InputMethodContextX::PreEditChanged( void*, ImfContext* imfContext, void* eventInfo )
307 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::PreEditChanged\n" );
308 auto context = static_cast<Ecore_IMF_Context*>( imfContext );
310 char* preEditString( NULL );
311 int cursorPosition( 0 );
312 Eina_List* attrs = NULL;
315 Ecore_IMF_Preedit_Attr* attr;
317 // Retrieves attributes as well as the string the cursor position offset from start of pre-edit string.
318 // the attributes (attrs) is used in languages that use the soft arrows keys to insert characters into a current pre-edit string.
319 ecore_imf_context_preedit_string_with_attributes_get( context, &preEditString, &attrs, &cursorPosition );
323 // iterate through the list of attributes getting the type, start and end position.
324 for ( l = attrs, (attr = static_cast<Ecore_IMF_Preedit_Attr*>( eina_list_data_get(l) ) ); l; l = eina_list_next(l), ( attr = static_cast<Ecore_IMF_Preedit_Attr*>( eina_list_data_get(l) ) ))
326 switch( attr->preedit_type )
328 case ECORE_IMF_PREEDIT_TYPE_NONE:
330 mPreeditType = Dali::InputMethodContext::PreeditStyle::NONE;
333 case ECORE_IMF_PREEDIT_TYPE_SUB1:
335 mPreeditType = Dali::InputMethodContext::PreeditStyle::UNDERLINE;
338 case ECORE_IMF_PREEDIT_TYPE_SUB2:
340 mPreeditType = Dali::InputMethodContext::PreeditStyle::REVERSE;
343 case ECORE_IMF_PREEDIT_TYPE_SUB3:
345 mPreeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT;
354 #ifdef DALI_PROFILE_UBUNTU
355 if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB3 ) // (Ecore_IMF)
356 #else // DALI_PROFILE_UBUNTU
357 if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB4 ) // (Ecore_IMF)
358 #endif // DALI_PROFILE_UBUNTU
360 // check first byte so know how many bytes a character is represented by as keyboard returns cursor position in bytes. Which is different for some languages.
362 size_t visualCharacterIndex = 0;
363 size_t byteIndex = 0;
365 // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).
366 const char leadByte = preEditString[byteIndex];
367 while( leadByte != '\0' )
369 // attr->end_index is provided as a byte position not character and we need to know the character position.
370 const size_t currentSequenceLength = Utf8SequenceLength( leadByte ); // returns number of bytes used to represent character.
371 if ( byteIndex == attr->end_index )
373 cursorPosition = static_cast<int>( visualCharacterIndex );
375 // end loop as found cursor position that matches byte position
379 byteIndex += currentSequenceLength; // jump to next character
380 visualCharacterIndex++; // increment character count so we know our position for when we get a match
383 DALI_ASSERT_DEBUG( visualCharacterIndex < strlen( preEditString ));
389 if ( Dali::Adaptor::IsAvailable() )
391 Dali::InputMethodContext handle( this );
392 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::PRE_EDIT, preEditString, cursorPosition, 0 );
393 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
395 if( callbackData.update )
397 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
399 NotifyCursorPosition();
402 if( callbackData.preeditResetRequired )
407 free( preEditString );
410 void InputMethodContextX::CommitReceived( void*, ImfContext* imfContext, void* eventInfo )
412 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::CommitReceived\n" );
414 if ( Dali::Adaptor::IsAvailable() )
416 const std::string keyString( static_cast<char*>( eventInfo ) );
418 Dali::InputMethodContext handle( this );
419 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::COMMIT, keyString, 0, 0 );
420 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
422 if( callbackData.update )
424 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
426 NotifyCursorPosition();
432 * Called when an InputMethodContext retrieve surround event is received.
433 * Here the InputMethodContext module wishes to know the string we are working with and where within the string the cursor is
434 * We need to signal the application to tell us this information.
436 bool InputMethodContextX::RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition )
438 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::RetrieveSurrounding\n" );
440 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::GET_SURROUNDING, std::string(), 0, 0 );
441 Dali::InputMethodContext handle( this );
442 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
444 if( callbackData.update )
448 *text = strdup( callbackData.currentText.c_str() );
453 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
454 *cursorPosition = mIMFCursorPosition;
462 * Called when an InputMethodContext delete surrounding event is received.
463 * Here we tell the application that it should delete a certain range.
465 void InputMethodContextX::DeleteSurrounding( void* data, ImfContext* imfContext, void* eventInfo )
467 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::DeleteSurrounding\n" );
469 if( Dali::Adaptor::IsAvailable() )
471 Ecore_IMF_Event_Delete_Surrounding* deleteSurroundingEvent = static_cast<Ecore_IMF_Event_Delete_Surrounding*>( eventInfo );
473 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::DELETE_SURROUNDING, std::string(), deleteSurroundingEvent->offset, deleteSurroundingEvent->n_chars );
474 Dali::InputMethodContext handle( this );
475 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
477 if( callbackData.update )
479 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
481 NotifyCursorPosition();
486 void InputMethodContextX::NotifyCursorPosition()
488 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::NotifyCursorPosition\n" );
492 ecore_imf_context_cursor_position_set( mIMFContext, mIMFCursorPosition );
496 void InputMethodContextX::SetCursorPosition( unsigned int cursorPosition )
498 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetCursorPosition\n" );
500 mIMFCursorPosition = static_cast<int>( cursorPosition );
503 unsigned int InputMethodContextX::GetCursorPosition() const
505 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetCursorPosition\n" );
507 return static_cast<unsigned int>( mIMFCursorPosition );
510 void InputMethodContextX::SetSurroundingText( const std::string& text )
512 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetSurroundingText\n" );
514 mSurroundingText = text;
517 const std::string& InputMethodContextX::GetSurroundingText() const
519 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetSurroundingText\n" );
521 return mSurroundingText;
524 void InputMethodContextX::NotifyTextInputMultiLine( bool multiLine )
528 Dali::InputMethodContext::TextDirection InputMethodContextX::GetTextDirection()
530 Dali::InputMethodContext::TextDirection direction ( Dali::InputMethodContext::LeftToRight );
534 char* locale( NULL );
535 ecore_imf_context_input_panel_language_locale_get( mIMFContext, &locale );
539 direction = static_cast< Dali::InputMethodContext::TextDirection >( Locale::GetDirection( std::string( locale ) ) );
547 Rect<int> InputMethodContextX::GetInputMethodArea()
549 int xPos, yPos, width, height;
551 width = height = xPos = yPos = 0;
555 ecore_imf_context_input_panel_geometry_get( mIMFContext, &xPos, &yPos, &width, &height );
559 DALI_LOG_WARNING("VKB Unable to get InputMethodContext Context so GetSize unavailable\n");
562 return Rect<int>(xPos,yPos,width,height);
565 void InputMethodContextX::ApplyOptions( const InputMethodOptions& options )
567 using namespace Dali::InputMethod::Category;
571 if (mIMFContext == NULL)
573 DALI_LOG_WARNING("VKB Unable to excute ApplyOptions with Null ImfContext\n");
577 if ( mOptions.CompareAndSet(PANEL_LAYOUT, options, index) )
580 if ( mOptions.CompareAndSet(BUTTON_ACTION, options, index) )
583 if ( mOptions.CompareAndSet(AUTO_CAPITALIZE, options, index) )
586 if ( mOptions.CompareAndSet(VARIATION, options, index) )
591 void InputMethodContextX::SetInputPanelData( const std::string& data )
593 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelData\n" );
597 int length = data.length();
598 ecore_imf_context_input_panel_imdata_set( mIMFContext, data.c_str(), length );
602 void InputMethodContextX::GetInputPanelData( std::string& data )
604 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelData\n" );
608 int length = 4096; // The max length is 4096 bytes
609 Dali::Vector< char > buffer;
610 buffer.Resize( length );
611 ecore_imf_context_input_panel_imdata_get( mIMFContext, &buffer[0], &length );
612 data = std::string( buffer.Begin(), buffer.End() );
616 Dali::InputMethodContext::State InputMethodContextX::GetInputPanelState()
618 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelState\n" );
623 value = ecore_imf_context_input_panel_state_get( mIMFContext );
627 case ECORE_IMF_INPUT_PANEL_STATE_SHOW:
629 return Dali::InputMethodContext::SHOW;
633 case ECORE_IMF_INPUT_PANEL_STATE_HIDE:
635 return Dali::InputMethodContext::HIDE;
639 case ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW:
641 return Dali::InputMethodContext::WILL_SHOW;
647 return Dali::InputMethodContext::DEFAULT;
651 return Dali::InputMethodContext::DEFAULT;
654 void InputMethodContextX::SetReturnKeyState( bool visible )
656 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetReturnKeyState\n" );
660 ecore_imf_context_input_panel_return_key_disabled_set( mIMFContext, !visible );
664 void InputMethodContextX::AutoEnableInputPanel( bool enabled )
666 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::AutoEnableInputPanel\n" );
670 ecore_imf_context_input_panel_enabled_set( mIMFContext, enabled );
674 void InputMethodContextX::ShowInputPanel()
676 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::ShowInputPanel\n" );
680 ecore_imf_context_input_panel_show( mIMFContext );
684 void InputMethodContextX::HideInputPanel()
686 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::HideInputPanel\n" );
690 ecore_imf_context_input_panel_hide( mIMFContext );
694 Dali::InputMethodContext::KeyboardType InputMethodContextX::GetKeyboardType()
696 return Dali::InputMethodContext::KeyboardType::SOFTWARE_KEYBOARD;
699 std::string InputMethodContextX::GetInputPanelLocale()
701 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelLocale\n" );
703 std::string locale = "";
708 ecore_imf_context_input_panel_language_locale_get( mIMFContext, &value );
712 std::string valueCopy( value );
715 // The locale string retrieved must be freed with free().
722 void InputMethodContextX::SetContentMIMETypes( const std::string& mimeTypes )
724 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetContentMIMETypes\n" );
725 // ecore_imf_context_mime_type_accept_set() is supported from ecore-imf 1.20.0 version.
728 bool InputMethodContextX::FilterEventKey( const Dali::KeyEvent& keyEvent )
730 bool eventHandled( false );
732 // If a device key then skip ecore_imf_context_filter_event.
733 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ))
735 //check whether it's key down or key up event
736 if ( keyEvent.state == KeyEvent::Down )
738 eventHandled = ProcessEventKeyDown( keyEvent );
740 else if ( keyEvent.state == KeyEvent::Up )
742 eventHandled = ProcessEventKeyUp( keyEvent );
749 void InputMethodContextX::AllowTextPrediction( bool prediction )
751 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::AllowTextPrediction\n" );
755 ecore_imf_context_prediction_allow_set( mIMFContext, prediction );
759 bool InputMethodContextX::IsTextPredictionAllowed() const
761 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::IsTextPredictionAllowed\n" );
762 bool prediction = false;
765 prediction = ecore_imf_context_prediction_allow_get( mIMFContext );
770 void InputMethodContextX::SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language )
772 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelLanguage\n" );
777 case Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC:
779 ecore_imf_context_input_panel_language_set( mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC );
782 case Dali::InputMethodContext::InputPanelLanguage::ALPHABET:
784 ecore_imf_context_input_panel_language_set( mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_ALPHABET );
791 Dali::InputMethodContext::InputPanelLanguage InputMethodContextX::GetInputPanelLanguage() const
793 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelLanguage\n" );
797 value = ecore_imf_context_input_panel_language_get( mIMFContext );
801 case ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC:
803 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
806 case ECORE_IMF_INPUT_PANEL_LANG_ALPHABET:
808 return Dali::InputMethodContext::InputPanelLanguage::ALPHABET;
813 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
816 void InputMethodContextX::SetInputPanelPosition( unsigned int x, unsigned int y )
818 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelPosition\n" );
820 // ecore_imf_context_input_panel_position_set() is supported from ecore-imf 1.21.0 version.
823 Dali::InputMethodContext::PreeditStyle InputMethodContextX::GetPreeditStyle() const
825 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetPreeditStyle\n" );
829 bool InputMethodContextX::ProcessEventKeyDown( const KeyEvent& keyEvent )
831 bool eventHandled( false );
834 Integration::KeyEvent integKeyEvent( keyEvent );
835 std::string key = integKeyEvent.logicalKey;
837 std::string compose = keyEvent.GetCompose();
839 // We're consuming key down event so we have to pass to InputMethodContext so that it can parse it as well.
840 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
841 ecoreKeyDownEvent.keyname = keyEvent.keyPressedName.c_str();
842 ecoreKeyDownEvent.key = key.c_str();
843 ecoreKeyDownEvent.string = keyEvent.keyPressed.c_str();
844 ecoreKeyDownEvent.compose = compose.c_str();
845 ecoreKeyDownEvent.timestamp = keyEvent.time;
846 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
847 ecoreKeyDownEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
849 #if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR)
850 #if (ECORE_VERSION_MINOR >= 14)
851 ecoreKeyDownEvent.dev_name = "";
852 ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
853 ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
854 #endif // Since ecore_imf 1.14 version
855 #if (ECORE_VERSION_MINOR >= 22)
856 ecoreKeyDownEvent.keycode = keyEvent.keyCode;
857 #endif // Since ecore_imf 1.22 version
858 #endif // Since ecore_imf Version 1
860 // If the device is IME and the focused key is the direction keys, then we should send a key event to move a key cursor.
861 if ((keyEvent.GetDeviceName() == "ime") && ((!strncmp(keyEvent.keyPressedName.c_str(), "Left", 4)) ||
862 (!strncmp(keyEvent.keyPressedName.c_str(), "Right", 5)) ||
863 (!strncmp(keyEvent.keyPressedName.c_str(), "Up", 2)) ||
864 (!strncmp(keyEvent.keyPressedName.c_str(), "Down", 4))))
870 eventHandled = ecore_imf_context_filter_event(mIMFContext,
871 ECORE_IMF_EVENT_KEY_DOWN,
872 reinterpret_cast<Ecore_IMF_Event *>( &ecoreKeyDownEvent ));
875 // If the event has not been handled by InputMethodContext then check if we should reset our IMFcontext
878 if (!strcmp(keyEvent.keyPressedName.c_str(), "Escape") ||
879 !strcmp(keyEvent.keyPressedName.c_str(), "Return") ||
880 !strcmp(keyEvent.keyPressedName.c_str(), "KP_Enter"))
882 ecore_imf_context_reset(mIMFContext);
889 bool InputMethodContextX::ProcessEventKeyUp( const KeyEvent& keyEvent )
891 bool eventHandled( false );
894 Integration::KeyEvent integKeyEvent( keyEvent );
895 std::string key = integKeyEvent.logicalKey;
897 std::string compose = keyEvent.GetCompose();
899 // We're consuming key up event so we have to pass to InputMethodContext so that it can parse it as well.
900 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
901 ecoreKeyUpEvent.keyname = keyEvent.keyPressedName.c_str();
902 ecoreKeyUpEvent.key = key.c_str();
903 ecoreKeyUpEvent.string = keyEvent.keyPressed.c_str();
904 ecoreKeyUpEvent.compose = compose.c_str();
905 ecoreKeyUpEvent.timestamp = keyEvent.time;
906 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
907 ecoreKeyUpEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
908 #if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR)
909 #if (ECORE_VERSION_MINOR >= 14)
910 ecoreKeyUpEvent.dev_name = "";
911 #endif // Since ecore_imf 1.14 version
912 #if (ECORE_VERSION_MINOR >= 22)
913 ecoreKeyUpEvent.keycode = keyEvent.keyCode;
914 #endif // Since ecore_imf 1.22 version
915 #endif // Since ecore_imf Version 1
917 eventHandled = ecore_imf_context_filter_event(mIMFContext,
918 ECORE_IMF_EVENT_KEY_UP,
919 reinterpret_cast<Ecore_IMF_Event *>( &ecoreKeyUpEvent ));
924 Ecore_IMF_Keyboard_Modifiers InputMethodContextX::EcoreInputModifierToEcoreIMFModifier( unsigned int ecoreModifier )
926 unsigned int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
928 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
930 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
933 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
935 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
938 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
940 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
943 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
945 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
948 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
950 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
953 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
956 Ecore_IMF_Keyboard_Locks InputMethodContextX::EcoreInputModifierToEcoreIMFLock( unsigned int modifier )
958 unsigned int lock( ECORE_IMF_KEYBOARD_LOCK_NONE ); // If no other matches, returns NONE.
960 if( modifier & ECORE_EVENT_LOCK_NUM )
962 lock |= ECORE_IMF_KEYBOARD_LOCK_NUM; // Num lock is active.
965 if( modifier & ECORE_EVENT_LOCK_CAPS )
967 lock |= ECORE_IMF_KEYBOARD_LOCK_CAPS; // Caps lock is active.
970 if( modifier & ECORE_EVENT_LOCK_SCROLL )
972 lock |= ECORE_IMF_KEYBOARD_LOCK_SCROLL; // Scroll lock is active.
975 return static_cast<Ecore_IMF_Keyboard_Locks>( lock );
978 void InputMethodContextX::OnStaged( Dali::Actor actor )
980 Ecore_X_Window ecoreXwin( AnyCast< Ecore_X_Window >( Dali::Integration::SceneHolder::Get( actor ).GetNativeHandle() ) );
982 if( mEcoreXwin != ecoreXwin )
984 mEcoreXwin = ecoreXwin;