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/adaptor-framework/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 )
156 actor.OnStageSignal().Connect( this, &InputMethodContextX::OnStaged );
159 InputMethodContextX::~InputMethodContextX()
162 ecore_imf_shutdown();
165 void InputMethodContextX::Initialize()
169 VirtualKeyboard::ConnectCallbacks( mIMFContext );
172 void InputMethodContextX::CreateContext()
174 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::CreateContext\n" );
181 const char *contextId = ecore_imf_context_default_id_get();
184 mIMFContext = ecore_imf_context_add( contextId );
188 ecore_imf_context_client_window_set( mIMFContext, reinterpret_cast<void*>( mEcoreXwin ) );
192 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext Unable to get IMFContext\n");
197 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext Unable to get IMFContext\n");
201 void InputMethodContextX::DeleteContext()
203 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::DeleteContext\n" );
207 ecore_imf_context_del( mIMFContext );
212 // Callbacks for predicitive text support.
213 void InputMethodContextX::ConnectCallbacks()
217 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::ConnectCallbacks\n" );
219 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit, this );
220 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit, this );
221 ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding, this );
223 ecore_imf_context_retrieve_surrounding_callback_set( mIMFContext, ImfRetrieveSurrounding, this);
227 void InputMethodContextX::DisconnectCallbacks()
231 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::DisconnectCallbacks\n" );
233 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit );
234 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit );
235 ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding );
237 // We do not need to unset the retrieve surrounding callback.
241 void InputMethodContextX::Activate()
243 // Reset mIdleCallbackConnected
244 mIdleCallbackConnected = false;
248 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Activate\n" );
250 ecore_imf_context_focus_in( mIMFContext );
252 // emit keyboard activated signal
253 Dali::InputMethodContext handle( this );
254 mActivatedSignal.Emit( handle );
258 void InputMethodContextX::Deactivate()
262 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Deactivate\n" );
265 ecore_imf_context_focus_out( mIMFContext );
268 // Reset mIdleCallbackConnected
269 mIdleCallbackConnected = false;
272 void InputMethodContextX::Reset()
274 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::Reset\n" );
278 ecore_imf_context_reset( mIMFContext );
282 ImfContext* InputMethodContextX::GetContext()
284 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetContext\n" );
289 bool InputMethodContextX::RestoreAfterFocusLost() const
291 return mRestoreAfterFocusLost;
294 void InputMethodContextX::SetRestoreAfterFocusLost( bool toggle )
296 mRestoreAfterFocusLost = toggle;
300 * Called when an InputMethodContext Pre-Edit changed event is received.
301 * We are still predicting what the user is typing. The latest string is what the InputMethodContext module thinks
302 * the user wants to type.
304 void InputMethodContextX::PreEditChanged( void*, ImfContext* imfContext, void* eventInfo )
306 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::PreEditChanged\n" );
307 auto context = static_cast<Ecore_IMF_Context*>( imfContext );
309 char* preEditString( NULL );
310 int cursorPosition( 0 );
311 Eina_List* attrs = NULL;
314 Ecore_IMF_Preedit_Attr* attr;
316 mPreeditAttrs.Clear();
318 // Retrieves attributes as well as the string the cursor position offset from start of pre-edit string.
319 // the attributes (attrs) is used in languages that use the soft arrows keys to insert characters into a current pre-edit string.
320 ecore_imf_context_preedit_string_with_attributes_get( context, &preEditString, &attrs, &cursorPosition );
324 // iterate through the list of attributes getting the type, start and end position.
325 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) ) ))
327 Dali::InputMethodContext::PreeditAttributeData data;
331 size_t visualCharacterIndex = 0;
332 size_t byteIndex = 0;
334 // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).
335 const char leadByte = preEditString[byteIndex];
336 while( leadByte != '\0' )
338 // attr->end_index is provided as a byte position not character and we need to know the character position.
339 const size_t currentSequenceLength = Utf8SequenceLength( leadByte ); // returns number of bytes used to represent character.
340 if( byteIndex <= attr->start_index )
342 data.startIndex = visualCharacterIndex;
344 if ( byteIndex >= attr->end_index )
346 data.endIndex = visualCharacterIndex;
348 // end loop as found cursor position that matches byte position
352 byteIndex += currentSequenceLength; // jump to next character
353 visualCharacterIndex++; // increment character count so we know our position for when we get a match
357 switch( attr->preedit_type )
359 case ECORE_IMF_PREEDIT_TYPE_NONE:
361 data.preeditType = Dali::InputMethodContext::PreeditStyle::NONE;
364 case ECORE_IMF_PREEDIT_TYPE_SUB1:
366 data.preeditType = Dali::InputMethodContext::PreeditStyle::UNDERLINE;
369 case ECORE_IMF_PREEDIT_TYPE_SUB2:
371 data.preeditType = Dali::InputMethodContext::PreeditStyle::REVERSE;
374 case ECORE_IMF_PREEDIT_TYPE_SUB3:
376 data.preeditType = Dali::InputMethodContext::PreeditStyle::HIGHLIGHT;
379 case ECORE_IMF_PREEDIT_TYPE_SUB4:
381 data.preeditType = Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_1;
384 case ECORE_IMF_PREEDIT_TYPE_SUB5:
386 data.preeditType = Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_2;
389 case ECORE_IMF_PREEDIT_TYPE_SUB6:
391 data.preeditType = Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_3;
394 case ECORE_IMF_PREEDIT_TYPE_SUB7:
396 data.preeditType = Dali::InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_4;
401 data.preeditType = Dali::InputMethodContext::PreeditStyle::NONE;
405 mPreeditAttrs.PushBack( data );
409 if ( Dali::Adaptor::IsAvailable() )
411 Dali::InputMethodContext handle( this );
412 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::PRE_EDIT, preEditString, cursorPosition, 0 );
413 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
415 if( callbackData.update )
417 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
419 NotifyCursorPosition();
422 if( callbackData.preeditResetRequired )
427 free( preEditString );
430 void InputMethodContextX::CommitReceived( void*, ImfContext* imfContext, void* eventInfo )
432 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::CommitReceived\n" );
434 if ( Dali::Adaptor::IsAvailable() )
436 const std::string keyString( static_cast<char*>( eventInfo ) );
438 Dali::InputMethodContext handle( this );
439 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::COMMIT, keyString, 0, 0 );
440 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
442 if( callbackData.update )
444 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
446 NotifyCursorPosition();
452 * Called when an InputMethodContext retrieve surround event is received.
453 * Here the InputMethodContext module wishes to know the string we are working with and where within the string the cursor is
454 * We need to signal the application to tell us this information.
456 bool InputMethodContextX::RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition )
458 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::RetrieveSurrounding\n" );
460 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::GET_SURROUNDING, std::string(), 0, 0 );
461 Dali::InputMethodContext handle( this );
462 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
464 if( callbackData.update )
468 *text = strdup( callbackData.currentText.c_str() );
473 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
474 *cursorPosition = mIMFCursorPosition;
482 * Called when an InputMethodContext delete surrounding event is received.
483 * Here we tell the application that it should delete a certain range.
485 void InputMethodContextX::DeleteSurrounding( void* data, ImfContext* imfContext, void* eventInfo )
487 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::DeleteSurrounding\n" );
489 if( Dali::Adaptor::IsAvailable() )
491 Ecore_IMF_Event_Delete_Surrounding* deleteSurroundingEvent = static_cast<Ecore_IMF_Event_Delete_Surrounding*>( eventInfo );
493 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::DELETE_SURROUNDING, std::string(), deleteSurroundingEvent->offset, deleteSurroundingEvent->n_chars );
494 Dali::InputMethodContext handle( this );
495 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
497 if( callbackData.update )
499 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
501 NotifyCursorPosition();
506 void InputMethodContextX::NotifyCursorPosition()
508 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::NotifyCursorPosition\n" );
512 ecore_imf_context_cursor_position_set( mIMFContext, mIMFCursorPosition );
516 void InputMethodContextX::SetCursorPosition( unsigned int cursorPosition )
518 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetCursorPosition\n" );
520 mIMFCursorPosition = static_cast<int>( cursorPosition );
523 unsigned int InputMethodContextX::GetCursorPosition() const
525 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetCursorPosition\n" );
527 return static_cast<unsigned int>( mIMFCursorPosition );
530 void InputMethodContextX::SetSurroundingText( const std::string& text )
532 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetSurroundingText\n" );
534 mSurroundingText = text;
537 const std::string& InputMethodContextX::GetSurroundingText() const
539 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetSurroundingText\n" );
541 return mSurroundingText;
544 void InputMethodContextX::NotifyTextInputMultiLine( bool multiLine )
548 Dali::InputMethodContext::TextDirection InputMethodContextX::GetTextDirection()
550 Dali::InputMethodContext::TextDirection direction ( Dali::InputMethodContext::LeftToRight );
554 char* locale( NULL );
555 ecore_imf_context_input_panel_language_locale_get( mIMFContext, &locale );
559 direction = static_cast< Dali::InputMethodContext::TextDirection >( Locale::GetDirection( std::string( locale ) ) );
567 Rect<int> InputMethodContextX::GetInputMethodArea()
569 int xPos, yPos, width, height;
571 width = height = xPos = yPos = 0;
575 ecore_imf_context_input_panel_geometry_get( mIMFContext, &xPos, &yPos, &width, &height );
579 DALI_LOG_WARNING("VKB Unable to get InputMethodContext Context so GetSize unavailable\n");
582 return Rect<int>(xPos,yPos,width,height);
585 void InputMethodContextX::ApplyOptions( const InputMethodOptions& options )
587 using namespace Dali::InputMethod::Category;
591 if (mIMFContext == NULL)
593 DALI_LOG_WARNING("VKB Unable to excute ApplyOptions with Null ImfContext\n");
597 if ( mOptions.CompareAndSet(PANEL_LAYOUT, options, index) )
600 if ( mOptions.CompareAndSet(BUTTON_ACTION, options, index) )
603 if ( mOptions.CompareAndSet(AUTO_CAPITALIZE, options, index) )
606 if ( mOptions.CompareAndSet(VARIATION, options, index) )
611 void InputMethodContextX::SetInputPanelData( const std::string& data )
613 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelData\n" );
617 int length = data.length();
618 ecore_imf_context_input_panel_imdata_set( mIMFContext, data.c_str(), length );
622 void InputMethodContextX::GetInputPanelData( std::string& data )
624 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelData\n" );
628 int length = 4096; // The max length is 4096 bytes
629 Dali::Vector< char > buffer;
630 buffer.Resize( length );
631 ecore_imf_context_input_panel_imdata_get( mIMFContext, &buffer[0], &length );
632 data = std::string( buffer.Begin(), buffer.End() );
636 Dali::InputMethodContext::State InputMethodContextX::GetInputPanelState()
638 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelState\n" );
643 value = ecore_imf_context_input_panel_state_get( mIMFContext );
647 case ECORE_IMF_INPUT_PANEL_STATE_SHOW:
649 return Dali::InputMethodContext::SHOW;
653 case ECORE_IMF_INPUT_PANEL_STATE_HIDE:
655 return Dali::InputMethodContext::HIDE;
659 case ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW:
661 return Dali::InputMethodContext::WILL_SHOW;
667 return Dali::InputMethodContext::DEFAULT;
671 return Dali::InputMethodContext::DEFAULT;
674 void InputMethodContextX::SetReturnKeyState( bool visible )
676 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetReturnKeyState\n" );
680 ecore_imf_context_input_panel_return_key_disabled_set( mIMFContext, !visible );
684 void InputMethodContextX::AutoEnableInputPanel( bool enabled )
686 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::AutoEnableInputPanel\n" );
690 ecore_imf_context_input_panel_enabled_set( mIMFContext, enabled );
694 void InputMethodContextX::ShowInputPanel()
696 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::ShowInputPanel\n" );
700 ecore_imf_context_input_panel_show( mIMFContext );
704 void InputMethodContextX::HideInputPanel()
706 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::HideInputPanel\n" );
710 ecore_imf_context_input_panel_hide( mIMFContext );
714 Dali::InputMethodContext::KeyboardType InputMethodContextX::GetKeyboardType()
716 return Dali::InputMethodContext::KeyboardType::SOFTWARE_KEYBOARD;
719 std::string InputMethodContextX::GetInputPanelLocale()
721 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelLocale\n" );
723 std::string locale = "";
728 ecore_imf_context_input_panel_language_locale_get( mIMFContext, &value );
732 std::string valueCopy( value );
735 // The locale string retrieved must be freed with free().
742 void InputMethodContextX::SetContentMIMETypes( const std::string& mimeTypes )
744 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetContentMIMETypes\n" );
745 // ecore_imf_context_mime_type_accept_set() is supported from ecore-imf 1.20.0 version.
748 bool InputMethodContextX::FilterEventKey( const Dali::KeyEvent& keyEvent )
750 bool eventHandled( false );
752 // If a device key then skip ecore_imf_context_filter_event.
753 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ))
755 //check whether it's key down or key up event
756 if ( keyEvent.state == KeyEvent::Down )
758 eventHandled = ProcessEventKeyDown( keyEvent );
760 else if ( keyEvent.state == KeyEvent::Up )
762 eventHandled = ProcessEventKeyUp( keyEvent );
769 void InputMethodContextX::AllowTextPrediction( bool prediction )
771 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::AllowTextPrediction\n" );
775 ecore_imf_context_prediction_allow_set( mIMFContext, prediction );
779 bool InputMethodContextX::IsTextPredictionAllowed() const
781 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::IsTextPredictionAllowed\n" );
782 bool prediction = false;
785 prediction = ecore_imf_context_prediction_allow_get( mIMFContext );
790 void InputMethodContextX::SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language )
792 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelLanguage\n" );
797 case Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC:
799 ecore_imf_context_input_panel_language_set( mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC );
802 case Dali::InputMethodContext::InputPanelLanguage::ALPHABET:
804 ecore_imf_context_input_panel_language_set( mIMFContext, ECORE_IMF_INPUT_PANEL_LANG_ALPHABET );
811 Dali::InputMethodContext::InputPanelLanguage InputMethodContextX::GetInputPanelLanguage() const
813 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetInputPanelLanguage\n" );
817 value = ecore_imf_context_input_panel_language_get( mIMFContext );
821 case ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC:
823 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
826 case ECORE_IMF_INPUT_PANEL_LANG_ALPHABET:
828 return Dali::InputMethodContext::InputPanelLanguage::ALPHABET;
833 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
836 void InputMethodContextX::SetInputPanelPosition( unsigned int x, unsigned int y )
838 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::SetInputPanelPosition\n" );
840 // ecore_imf_context_input_panel_position_set() is supported from ecore-imf 1.21.0 version.
843 void InputMethodContextX::GetPreeditStyle( Vector< Dali::InputMethodContext::PreeditAttributeData >& attrs ) const
845 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::GetPreeditStyle\n" );
846 attrs = mPreeditAttrs;
849 bool InputMethodContextX::ProcessEventKeyDown( const KeyEvent& keyEvent )
851 bool eventHandled( false );
854 Integration::KeyEvent integKeyEvent( keyEvent );
855 std::string key = integKeyEvent.logicalKey;
857 std::string compose = keyEvent.GetCompose();
859 // We're consuming key down event so we have to pass to InputMethodContext so that it can parse it as well.
860 Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
861 ecoreKeyDownEvent.keyname = keyEvent.keyPressedName.c_str();
862 ecoreKeyDownEvent.key = key.c_str();
863 ecoreKeyDownEvent.string = keyEvent.keyPressed.c_str();
864 ecoreKeyDownEvent.compose = compose.c_str();
865 ecoreKeyDownEvent.timestamp = keyEvent.time;
866 ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
867 ecoreKeyDownEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
869 #if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR)
870 #if (ECORE_VERSION_MINOR >= 14)
871 ecoreKeyDownEvent.dev_name = "";
872 ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
873 ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
874 #endif // Since ecore_imf 1.14 version
875 #if (ECORE_VERSION_MINOR >= 22)
876 ecoreKeyDownEvent.keycode = keyEvent.keyCode;
877 #endif // Since ecore_imf 1.22 version
878 #endif // Since ecore_imf Version 1
880 // 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.
881 if ((keyEvent.GetDeviceName() == "ime") && ((!strncmp(keyEvent.keyPressedName.c_str(), "Left", 4)) ||
882 (!strncmp(keyEvent.keyPressedName.c_str(), "Right", 5)) ||
883 (!strncmp(keyEvent.keyPressedName.c_str(), "Up", 2)) ||
884 (!strncmp(keyEvent.keyPressedName.c_str(), "Down", 4))))
890 eventHandled = ecore_imf_context_filter_event(mIMFContext,
891 ECORE_IMF_EVENT_KEY_DOWN,
892 reinterpret_cast<Ecore_IMF_Event *>( &ecoreKeyDownEvent ));
895 // If the event has not been handled by InputMethodContext then check if we should reset our IMFcontext
898 if (!strcmp(keyEvent.keyPressedName.c_str(), "Escape") ||
899 !strcmp(keyEvent.keyPressedName.c_str(), "Return") ||
900 !strcmp(keyEvent.keyPressedName.c_str(), "KP_Enter"))
902 ecore_imf_context_reset(mIMFContext);
909 bool InputMethodContextX::ProcessEventKeyUp( const KeyEvent& keyEvent )
911 bool eventHandled( false );
914 Integration::KeyEvent integKeyEvent( keyEvent );
915 std::string key = integKeyEvent.logicalKey;
917 std::string compose = keyEvent.GetCompose();
919 // We're consuming key up event so we have to pass to InputMethodContext so that it can parse it as well.
920 Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
921 ecoreKeyUpEvent.keyname = keyEvent.keyPressedName.c_str();
922 ecoreKeyUpEvent.key = key.c_str();
923 ecoreKeyUpEvent.string = keyEvent.keyPressed.c_str();
924 ecoreKeyUpEvent.compose = compose.c_str();
925 ecoreKeyUpEvent.timestamp = keyEvent.time;
926 ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );
927 ecoreKeyUpEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );
928 #if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR)
929 #if (ECORE_VERSION_MINOR >= 14)
930 ecoreKeyUpEvent.dev_name = "";
931 #endif // Since ecore_imf 1.14 version
932 #if (ECORE_VERSION_MINOR >= 22)
933 ecoreKeyUpEvent.keycode = keyEvent.keyCode;
934 #endif // Since ecore_imf 1.22 version
935 #endif // Since ecore_imf Version 1
937 eventHandled = ecore_imf_context_filter_event(mIMFContext,
938 ECORE_IMF_EVENT_KEY_UP,
939 reinterpret_cast<Ecore_IMF_Event *>( &ecoreKeyUpEvent ));
944 Ecore_IMF_Keyboard_Modifiers InputMethodContextX::EcoreInputModifierToEcoreIMFModifier( unsigned int ecoreModifier )
946 unsigned int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE ); // If no other matches returns NONE.
948 if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT ) // enums from ecore_input/Ecore_Input.h
950 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT; // enums from ecore_imf/ecore_imf.h
953 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
955 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
958 if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
960 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
963 if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
965 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
968 if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
970 modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
973 return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
976 Ecore_IMF_Keyboard_Locks InputMethodContextX::EcoreInputModifierToEcoreIMFLock( unsigned int modifier )
978 unsigned int lock( ECORE_IMF_KEYBOARD_LOCK_NONE ); // If no other matches, returns NONE.
980 if( modifier & ECORE_EVENT_LOCK_NUM )
982 lock |= ECORE_IMF_KEYBOARD_LOCK_NUM; // Num lock is active.
985 if( modifier & ECORE_EVENT_LOCK_CAPS )
987 lock |= ECORE_IMF_KEYBOARD_LOCK_CAPS; // Caps lock is active.
990 if( modifier & ECORE_EVENT_LOCK_SCROLL )
992 lock |= ECORE_IMF_KEYBOARD_LOCK_SCROLL; // Scroll lock is active.
995 return static_cast<Ecore_IMF_Keyboard_Locks>( lock );
998 void InputMethodContextX::OnStaged( Dali::Actor actor )
1000 Ecore_X_Window ecoreXwin( AnyCast< Ecore_X_Window >( Dali::Integration::SceneHolder::Get( actor ).GetNativeHandle() ) );
1002 if( mEcoreXwin != ecoreXwin )
1004 mEcoreXwin = ecoreXwin;