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/internal/input/linux/dali-ecore-imf.h>
23 #include <dali/internal/input/ubuntu-x11/dali-ecore-input.h>
24 #include <dali/public-api/events/key-event.h>
25 #include <dali/public-api/adaptor-framework/key.h>
26 #include <dali/public-api/object/type-registry.h>
27 #include <dali/integration-api/debug.h>
30 #include <dali/integration-api/adaptor.h>
31 #include <dali/internal/adaptor/common/adaptor-impl.h>
32 #include <dali/internal/system/common/locale-utils.h>
33 #include <dali/internal/system/common/singleton-service-impl.h>
34 #include <dali/internal/input/common/virtual-keyboard-impl.h>
35 #include <dali/internal/input/common/key-impl.h>
36 #include <dali/internal/input/tizen-wayland/ecore-virtual-keyboard.h>
49 #if defined(DEBUG_ENABLED)
50 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_INPUT_METHOD_CONTEXT");
53 // Currently this code is internal to dali/dali/internal/event/text/utf8.h but should be made Public and used from there instead.
54 size_t Utf8SequenceLength(const unsigned char leadByte)
58 if ((leadByte & 0x80) == 0 ) //ASCII character (lead bit zero)
62 else if (( leadByte & 0xe0 ) == 0xc0 ) //110x xxxx
66 else if (( leadByte & 0xf0 ) == 0xe0 ) //1110 xxxx
70 else if (( leadByte & 0xf8 ) == 0xf0 ) //1111 0xxx
78 // Static function calls used by ecore 'c' style callback registration
79 void Commit( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
83 InputMethodContextX* inputMethodContext = reinterpret_cast< InputMethodContextX* > ( data );
84 inputMethodContext->CommitReceived( data, imfContext, eventInfo );
88 void PreEdit( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
92 InputMethodContextX* inputMethodContext = reinterpret_cast< InputMethodContextX* > ( data );
93 inputMethodContext->PreEditChanged( data, imfContext, eventInfo );
97 Eina_Bool ImfRetrieveSurrounding(void *data, Ecore_IMF_Context *imfContext, char** text, int* cursorPosition )
101 InputMethodContextX* inputMethodContext = reinterpret_cast< InputMethodContextX* > ( data );
102 return inputMethodContext->RetrieveSurrounding( data, imfContext, text, cursorPosition );
111 * Called when an InputMethodContext delete surrounding event is received.
112 * Here we tell the application that it should delete a certain range.
114 void ImfDeleteSurrounding( void *data, Ecore_IMF_Context *imfContext, void *eventInfo )
118 InputMethodContextX* inputMethodContext = reinterpret_cast< InputMethodContextX* > ( data );
119 inputMethodContext->DeleteSurrounding( data, imfContext, eventInfo );
123 } // unnamed namespace
125 InputMethodContextPtr InputMethodContextX::New()
127 InputMethodContextPtr manager;
129 if ( Adaptor::IsAvailable() )
131 // Create instance and register singleton only if the adaptor is available
132 Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
133 Any nativeWindow = adaptorImpl.GetNativeWindowHandle();
135 // The Ecore_X_Window needs to use the InputMethodContext.
136 // Only when the render surface is window, we can get the Ecore_X_Window.
137 Ecore_X_Window ecoreXwin( AnyCast<Ecore_X_Window>(nativeWindow) );
140 // If we fail to get Ecore_X_Window, we can't use the InputMethodContext correctly.
141 // Thus you have to call "ecore_imf_context_client_window_set" somewhere.
142 // In EvasPlugIn, this function is called in EvasPlugin::ConnectEcoreEvent().
144 manager = new InputMethodContextX( ecoreXwin );
148 DALI_LOG_ERROR("Failed to get native window handle\n");
155 void InputMethodContextX::Finalize()
157 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Finalize\n" );
158 VirtualKeyboard::DisconnectCallbacks( mIMFContext );
159 DisconnectCallbacks();
163 InputMethodContextX::InputMethodContextX( Ecore_X_Window ecoreXwin )
165 mEcoreXwin( ecoreXwin ),
166 mIMFCursorPosition( 0 ),
168 mRestoreAfterFocusLost( false ),
169 mIdleCallbackConnected( false )
174 InputMethodContextX::~InputMethodContextX()
177 ecore_imf_shutdown();
180 void InputMethodContextX::Initialize()
182 CreateContext( mEcoreXwin );
184 VirtualKeyboard::ConnectCallbacks( mIMFContext );
187 void InputMethodContextX::CreateContext( Ecore_X_Window ecoreXwin )
189 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::CreateContext\n" );
191 const char *contextId = ecore_imf_context_default_id_get();
194 mIMFContext = ecore_imf_context_add( contextId );
200 ecore_imf_context_client_window_set( mIMFContext, reinterpret_cast<void*>( ecoreXwin ) );
205 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext Unable to get IMFContext\n");
210 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext Unable to get IMFContext\n");
214 void InputMethodContextX::DeleteContext()
216 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::DeleteContext\n" );
220 ecore_imf_context_del( mIMFContext );
225 // Callbacks for predicitive text support.
226 void InputMethodContextX::ConnectCallbacks()
230 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::ConnectCallbacks\n" );
232 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit, this );
233 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit, this );
234 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding, this );
236 ecore_imf_context_retrieve_surrounding_callback_set( mIMFContext, ImfRetrieveSurrounding, this);
240 void InputMethodContextX::DisconnectCallbacks()
244 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::DisconnectCallbacks\n" );
246 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit );
247 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit );
248 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding );
250 // We do not need to unset the retrieve surrounding callback.
254 void InputMethodContextX::Activate()
256 // Reset mIdleCallbackConnected
257 mIdleCallbackConnected = false;
261 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Activate\n" );
263 ecore_imf_context_focus_in( mIMFContext );
265 // emit keyboard activated signal
266 Dali::InputMethodContext handle( this );
267 mActivatedSignal.Emit( handle );
271 void InputMethodContextX::Deactivate()
275 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Deactivate\n" );
278 ecore_imf_context_focus_out( mIMFContext );
281 // Reset mIdleCallbackConnected
282 mIdleCallbackConnected = false;
285 void InputMethodContextX::Reset()
287 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Reset\n" );
291 ecore_imf_context_reset( mIMFContext );
295 ImfContext* InputMethodContextX::GetContext()
297 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetContext\n" );
302 bool InputMethodContextX::RestoreAfterFocusLost() const
304 return mRestoreAfterFocusLost;
307 void InputMethodContextX::SetRestoreAfterFocusLost( bool toggle )
309 mRestoreAfterFocusLost = toggle;
313 * Called when an InputMethodContext Pre-Edit changed event is received.
314 * We are still predicting what the user is typing. The latest string is what the InputMethodContext module thinks
315 * the user wants to type.
317 void InputMethodContextX::PreEditChanged( void*, ImfContext* imfContext, void* eventInfo )
319 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::PreEditChanged\n" );
320 auto context = reinterpret_cast<Ecore_IMF_Context*>(imfContext);
322 char* preEditString( NULL );
323 int cursorPosition( 0 );
324 Eina_List* attrs = NULL;
327 Ecore_IMF_Preedit_Attr* attr;
329 // Retrieves attributes as well as the string the cursor position offset from start of pre-edit string.
330 // the attributes (attrs) is used in languages that use the soft arrows keys to insert characters into a current pre-edit string.
331 ecore_imf_context_preedit_string_with_attributes_get( context, &preEditString, &attrs, &cursorPosition );
335 // iterate through the list of attributes getting the type, start and end position.
336 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) ) ))
338 #ifdef DALI_PROFILE_UBUNTU
339 if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB3 ) // (Ecore_IMF)
340 #else // DALI_PROFILE_UBUNTU
341 if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB4 ) // (Ecore_IMF)
342 #endif // DALI_PROFILE_UBUNTU
344 // 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.
346 size_t visualCharacterIndex = 0;
347 size_t byteIndex = 0;
349 // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).
350 const char leadByte = preEditString[byteIndex];
351 while( leadByte != '\0' )
353 // attr->end_index is provided as a byte position not character and we need to know the character position.
354 const size_t currentSequenceLength = Utf8SequenceLength( leadByte ); // returns number of bytes used to represent character.
355 if ( byteIndex == attr->end_index )
357 cursorPosition = static_cast<int>( visualCharacterIndex );
359 // end loop as found cursor position that matches byte position
363 byteIndex += currentSequenceLength; // jump to next character
364 visualCharacterIndex++; // increment character count so we know our position for when we get a match
367 DALI_ASSERT_DEBUG( visualCharacterIndex < strlen( preEditString ));
373 if ( Dali::Adaptor::IsAvailable() )
375 Dali::InputMethodContext handle( this );
376 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::PRE_EDIT, preEditString, cursorPosition, 0 );
377 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
379 if( callbackData.update )
381 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
383 NotifyCursorPosition();
386 if( callbackData.preeditResetRequired )
391 free( preEditString );
394 void InputMethodContextX::CommitReceived( void*, ImfContext* imfContext, void* eventInfo )
396 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::CommitReceived\n" );
398 if ( Dali::Adaptor::IsAvailable() )
400 const std::string keyString( static_cast<char*>( eventInfo ) );
402 Dali::InputMethodContext handle( this );
403 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::COMMIT, keyString, 0, 0 );
404 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
406 if( callbackData.update )
408 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
410 NotifyCursorPosition();
416 * Called when an InputMethodContext retrieve surround event is received.
417 * Here the InputMethodContext module wishes to know the string we are working with and where within the string the cursor is
418 * We need to signal the application to tell us this information.
420 bool InputMethodContextX::RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition )
422 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::RetrieveSurrounding\n" );
424 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::GET_SURROUNDING, std::string(), 0, 0 );
425 Dali::InputMethodContext handle( this );
426 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
428 if( callbackData.update )
432 *text = strdup( callbackData.currentText.c_str() );
437 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
438 *cursorPosition = mIMFCursorPosition;
446 * Called when an InputMethodContext delete surrounding event is received.
447 * Here we tell the application that it should delete a certain range.
449 void InputMethodContextX::DeleteSurrounding( void* data, ImfContext* imfContext, void* eventInfo )
451 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::DeleteSurrounding\n" );
453 if( Dali::Adaptor::IsAvailable() )
455 Ecore_IMF_Event_Delete_Surrounding* deleteSurroundingEvent = static_cast<Ecore_IMF_Event_Delete_Surrounding*>( eventInfo );
457 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::DELETE_SURROUNDING, std::string(), deleteSurroundingEvent->offset, deleteSurroundingEvent->n_chars );
458 Dali::InputMethodContext handle( this );
459 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
461 if( callbackData.update )
463 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
465 NotifyCursorPosition();
470 void InputMethodContextX::NotifyCursorPosition()
472 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::NotifyCursorPosition\n" );
476 ecore_imf_context_cursor_position_set( mIMFContext, mIMFCursorPosition );
480 void InputMethodContextX::SetCursorPosition( unsigned int cursorPosition )
482 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetCursorPosition\n" );
484 mIMFCursorPosition = static_cast<int>( cursorPosition );
487 unsigned int InputMethodContextX::GetCursorPosition() const
489 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetCursorPosition\n" );
491 return static_cast<unsigned int>( mIMFCursorPosition );
494 void InputMethodContextX::SetSurroundingText( const std::string& text )
496 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetSurroundingText\n" );
498 mSurroundingText = text;
501 const std::string& InputMethodContextX::GetSurroundingText() const
503 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetSurroundingText\n" );
505 return mSurroundingText;
508 void InputMethodContextX::NotifyTextInputMultiLine( bool multiLine )
512 Dali::InputMethodContext::TextDirection InputMethodContextX::GetTextDirection()
514 Dali::InputMethodContext::TextDirection direction ( Dali::InputMethodContext::LeftToRight );
518 char* locale( NULL );
519 ecore_imf_context_input_panel_language_locale_get( mIMFContext, &locale );
523 direction = static_cast< Dali::InputMethodContext::TextDirection >( Locale::GetDirection( std::string( locale ) ) );
531 Rect<int> InputMethodContextX::GetInputMethodArea()
533 int xPos, yPos, width, height;
535 width = height = xPos = yPos = 0;
539 ecore_imf_context_input_panel_geometry_get( mIMFContext, &xPos, &yPos, &width, &height );
543 DALI_LOG_WARNING("VKB Unable to get InputMethodContext Context so GetSize unavailable\n");
546 return Rect<int>(xPos,yPos,width,height);
549 void InputMethodContextX::ApplyOptions( const InputMethodOptions& options )
551 using namespace Dali::InputMethod::Category;
555 if (mIMFContext == NULL)
557 DALI_LOG_WARNING("VKB Unable to excute ApplyOptions with Null ImfContext\n");
561 if ( mOptions.CompareAndSet(PANEL_LAYOUT, options, index) )
564 if ( mOptions.CompareAndSet(BUTTON_ACTION, options, index) )
567 if ( mOptions.CompareAndSet(AUTO_CAPITALIZE, options, index) )
570 if ( mOptions.CompareAndSet(VARIATION, options, index) )
575 void InputMethodContextX::SetInputPanelData( const std::string& data )
577 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelData\n" );
581 int length = data.length();
582 ecore_imf_context_input_panel_imdata_set( mIMFContext, data.c_str(), length );
586 void InputMethodContextX::GetInputPanelData( std::string& data )
588 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelData\n" );
592 int length = 4096; // The max length is 4096 bytes
593 Dali::Vector< char > buffer;
594 buffer.Resize( length );
595 ecore_imf_context_input_panel_imdata_get( mIMFContext, &buffer[0], &length );
596 data = std::string( buffer.Begin(), buffer.End() );
600 Dali::InputMethodContext::State InputMethodContextX::GetInputPanelState()
602 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelState\n" );
607 value = ecore_imf_context_input_panel_state_get( mIMFContext );
611 case ECORE_IMF_INPUT_PANEL_STATE_SHOW:
613 return Dali::InputMethodContext::SHOW;
617 case ECORE_IMF_INPUT_PANEL_STATE_HIDE:
619 return Dali::InputMethodContext::HIDE;
623 case ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW:
625 return Dali::InputMethodContext::WILL_SHOW;
631 return Dali::InputMethodContext::DEFAULT;
635 return Dali::InputMethodContext::DEFAULT;
638 void InputMethodContextX::SetReturnKeyState( bool visible )
640 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetReturnKeyState\n" );
644 ecore_imf_context_input_panel_return_key_disabled_set( mIMFContext, !visible );
648 void InputMethodContextX::AutoEnableInputPanel( bool enabled )
650 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::AutoEnableInputPanel\n" );
654 ecore_imf_context_input_panel_enabled_set( mIMFContext, enabled );
658 void InputMethodContextX::ShowInputPanel()
660 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::ShowInputPanel\n" );
664 ecore_imf_context_input_panel_show( mIMFContext );
668 void InputMethodContextX::HideInputPanel()
670 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::HideInputPanel\n" );
674 ecore_imf_context_input_panel_hide( mIMFContext );
678 Dali::InputMethodContext::KeyboardType InputMethodContextX::GetKeyboardType()
680 return Dali::InputMethodContext::KeyboardType::SOFTWARE_KEYBOARD;
683 std::string InputMethodContextX::GetInputPanelLocale()
685 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelLocale\n" );
687 std::string locale = "";
692 ecore_imf_context_input_panel_language_locale_get( mIMFContext, &value );
696 std::string valueCopy( value );
699 // The locale string retrieved must be freed with free().
706 void InputMethodContextX::SetContentMIMETypes( const std::string& mimeTypes )
708 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetContentMIMETypes\n" );
709 // ecore_imf_context_mime_type_accept_set() is supported from ecore-imf 1.20.0 version.
712 bool InputMethodContextX::FilterEventKey( const Dali::KeyEvent& keyEvent )
714 bool eventHandled( false );
716 // If a device key then skip ecore_imf_context_filter_event.
717 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ))
719 //check whether it's key down or key up event
720 if ( keyEvent.state == KeyEvent::Down )
722 eventHandled = ProcessEventKeyDown( keyEvent );
724 else if ( keyEvent.state == KeyEvent::Up )
726 eventHandled = ProcessEventKeyUp( keyEvent );
733 void InputMethodContextX::AllowTextPrediction( bool prediction )
735 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::AllowTextPrediction\n" );
739 ecore_imf_context_prediction_allow_set( mIMFContext, prediction );
743 bool InputMethodContextX::IsTextPredictionAllowed() const
745 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::IsTextPredictionAllowed\n" );
746 bool prediction = false;
749 prediction = ecore_imf_context_prediction_allow_get( mIMFContext );
754 void InputMethodContextX::SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language )
756 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelLanguage\n" );
761 case Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC:
763 ecore_imf_context_input_panel_language_set( mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC );
766 case Dali::InputMethodContext::InputPanelLanguage::ALPHABET:
768 ecore_imf_context_input_panel_language_set( mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_ALPHABET );
775 Dali::InputMethodContext::InputPanelLanguage InputMethodContextX::GetInputPanelLanguage() const
777 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelLanguage\n" );
781 value = ecore_imf_context_input_panel_language_get( mIMFContext );
785 case ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC:
787 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
790 case ECORE_IMF_INPUT_PANEL_LANG_ALPHABET:
792 return Dali::InputMethodContext::InputPanelLanguage::ALPHABET;
797 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
800 bool InputMethodContextX::ProcessEventKeyDown( const KeyEvent& keyEvent )
802 bool eventHandled( false );
805 Integration::KeyEvent integKeyEvent( keyEvent );
806 std::string key = integKeyEvent.logicalKey;
808 std::string compose = keyEvent.GetCompose();
810 // We're consuming key down event so we have to pass to InputMethodContext so that it can parse it as well.
811 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
812 ecoreKeyDownEvent.keyname = keyEvent.keyPressedName.c_str();
813 ecoreKeyDownEvent.key = key.c_str();
814 ecoreKeyDownEvent.string = keyEvent.keyPressed.c_str();
815 ecoreKeyDownEvent.compose = compose.c_str();
816 ecoreKeyDownEvent.timestamp = keyEvent.time;
817 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
818 ecoreKeyDownEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
819 #ifdef ECORE_IMF_1_13
820 ecoreKeyDownEvent.dev_name = "";
821 ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
822 ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
823 #endif // ECORE_IMF_1_13
825 // 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.
826 if ((keyEvent.GetDeviceName() == "ime") && ((!strncmp(keyEvent.keyPressedName.c_str(), "Left", 4)) ||
827 (!strncmp(keyEvent.keyPressedName.c_str(), "Right", 5)) ||
828 (!strncmp(keyEvent.keyPressedName.c_str(), "Up", 2)) ||
829 (!strncmp(keyEvent.keyPressedName.c_str(), "Down", 4))))
835 eventHandled = ecore_imf_context_filter_event(mIMFContext,
836 ECORE_IMF_EVENT_KEY_DOWN,
837 reinterpret_cast<Ecore_IMF_Event *>( &ecoreKeyDownEvent ));
840 // If the event has not been handled by InputMethodContext then check if we should reset our IMFcontext
843 if (!strcmp(keyEvent.keyPressedName.c_str(), "Escape") ||
844 !strcmp(keyEvent.keyPressedName.c_str(), "Return") ||
845 !strcmp(keyEvent.keyPressedName.c_str(), "KP_Enter"))
847 ecore_imf_context_reset(mIMFContext);
854 bool InputMethodContextX::ProcessEventKeyUp( const KeyEvent& keyEvent )
856 bool eventHandled( false );
859 Integration::KeyEvent integKeyEvent( keyEvent );
860 std::string key = integKeyEvent.logicalKey;
862 std::string compose = keyEvent.GetCompose();
864 // We're consuming key up event so we have to pass to InputMethodContext so that it can parse it as well.
865 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
866 ecoreKeyUpEvent.keyname = keyEvent.keyPressedName.c_str();
867 ecoreKeyUpEvent.key = key.c_str();
868 ecoreKeyUpEvent.string = keyEvent.keyPressed.c_str();
869 ecoreKeyUpEvent.compose = compose.c_str();
870 ecoreKeyUpEvent.timestamp = keyEvent.time;
871 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
872 ecoreKeyUpEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
873 #ifdef ECORE_IMF_1_13
874 ecoreKeyUpEvent.dev_name = "";
875 #endif // ECORE_IMF_1_13
877 eventHandled = ecore_imf_context_filter_event(mIMFContext,
878 ECORE_IMF_EVENT_KEY_UP,
879 reinterpret_cast<Ecore_IMF_Event *>( &ecoreKeyUpEvent ));
884 Ecore_IMF_Keyboard_Modifiers InputMethodContextX::EcoreInputModifierToEcoreIMFModifier( unsigned int ecoreModifier )
886 unsigned int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
888 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
890 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
893 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
895 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
898 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
900 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
903 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
905 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
908 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
910 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
913 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
916 Ecore_IMF_Keyboard_Locks InputMethodContextX::EcoreInputModifierToEcoreIMFLock( unsigned int modifier )
918 unsigned int lock( ECORE_IMF_KEYBOARD_LOCK_NONE ); // If no other matches, returns NONE.
920 if( modifier & ECORE_EVENT_LOCK_NUM )
922 lock |= ECORE_IMF_KEYBOARD_LOCK_NUM; // Num lock is active.
925 if( modifier & ECORE_EVENT_LOCK_CAPS )
927 lock |= ECORE_IMF_KEYBOARD_LOCK_CAPS; // Caps lock is active.
930 if( modifier & ECORE_EVENT_LOCK_SCROLL )
932 lock |= ECORE_IMF_KEYBOARD_LOCK_SCROLL; // Scroll lock is active.
935 return static_cast<Ecore_IMF_Keyboard_Locks>( lock );