X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=adaptors%2Fx11%2Fimf-manager-impl-x.cpp;h=5aa868f28770cae192f41b14f6a9d5b11ba5d648;hb=71fcd55c5cef78bcc01ca9880cb394474e9f2bcd;hp=f64fdd0a1114892a73a8e8bc7d5bbb65ffd02086;hpb=ecca9a6b2bab7cdeac8763d2f6be63e1b371d768;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/adaptors/x11/imf-manager-impl-x.cpp b/adaptors/x11/imf-manager-impl-x.cpp index f64fdd0..5aa868f 100644 --- a/adaptors/x11/imf-manager-impl-x.cpp +++ b/adaptors/x11/imf-manager-impl-x.cpp @@ -29,6 +29,7 @@ #include #include #include +#include "ecore-virtual-keyboard.h" namespace Dali { @@ -41,7 +42,6 @@ namespace Adaptor namespace { - #if defined(DEBUG_ENABLED) Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_IMF_MANAGER"); #endif @@ -116,13 +116,6 @@ void ImfDeleteSurrounding( void *data, Ecore_IMF_Context *imfContext, void *even } } -BaseHandle Create() -{ - return ImfManager::Get(); -} - -TypeRegistration IMF_MANAGER_TYPE( typeid(Dali::ImfManager), typeid(Dali::BaseHandle), Create ); - } // unnamed namespace bool ImfManager::IsAvailable() @@ -184,10 +177,9 @@ Dali::ImfManager ImfManager::Get() ImfManager::ImfManager( Ecore_X_Window ecoreXwin ) : mIMFContext(), mIMFCursorPosition( 0 ), - mSurroundingText(""), + mSurroundingText(), mRestoreAfterFocusLost( false ), - mIdleCallbackConnected( false ), - mKeyEvents() + mIdleCallbackConnected( false ) { ecore_imf_init(); CreateContext( ecoreXwin ); @@ -334,16 +326,16 @@ void ImfManager::SetRestoreAfterFocusLost( bool toggle ) * We are still predicting what the user is typing. The latest string is what the IMF module thinks * the user wants to type. */ -void ImfManager::PreEditChanged( void *, Ecore_IMF_Context *imfContext, void *event_info ) +void ImfManager::PreEditChanged( void*, Ecore_IMF_Context* imfContext, void* event_info ) { DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::PreEditChanged\n" ); - char *preEditString( NULL ); + char* preEditString( NULL ); int cursorPosition( 0 ); - Eina_List *attrs = NULL; - Eina_List *l = NULL; + Eina_List* attrs = NULL; + Eina_List* l = NULL; - Ecore_IMF_Preedit_Attr *attr; + Ecore_IMF_Preedit_Attr* attr; // Retrieves attributes as well as the string the cursor position offset from start of pre-edit string. // the attributes (attrs) is used in languages that use the soft arrows keys to insert characters into a current pre-edit string. @@ -352,7 +344,7 @@ void ImfManager::PreEditChanged( void *, Ecore_IMF_Context *imfContext, void *ev if ( attrs ) { // iterate through the list of attributes getting the type, start and end position. - for ( l = attrs, (attr = (Ecore_IMF_Preedit_Attr*)eina_list_data_get(l) ); l; l = eina_list_next(l), ( attr = (Ecore_IMF_Preedit_Attr*)eina_list_data_get(l) )) + for ( l = attrs, (attr = static_cast( eina_list_data_get(l) ) ); l; l = eina_list_next(l), ( attr = static_cast( eina_list_data_get(l) ) )) { #ifdef DALI_PROFILE_UBUNTU if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB3 ) // (Ecore_IMF) @@ -366,10 +358,11 @@ void ImfManager::PreEditChanged( void *, Ecore_IMF_Context *imfContext, void *ev size_t byteIndex = 0; // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ). - while ( preEditString[byteIndex] != '\0' ) + const char leadByte = preEditString[byteIndex]; + while( leadByte != '\0' ) { // attr->end_index is provided as a byte position not character and we need to know the character position. - size_t currentSequenceLength = Utf8SequenceLength(preEditString[byteIndex]); // returns number of bytes used to represent character. + const size_t currentSequenceLength = Utf8SequenceLength( leadByte ); // returns number of bytes used to represent character. if ( byteIndex == attr->end_index ) { cursorPosition = visualCharacterIndex; @@ -390,22 +383,18 @@ void ImfManager::PreEditChanged( void *, Ecore_IMF_Context *imfContext, void *ev if ( Dali::Adaptor::IsAvailable() ) { - std::string keyString ( preEditString ); - int numberOfChars( 0 ); - Dali::ImfManager handle( this ); - Dali::ImfManager::ImfEventData imfEventData ( Dali::ImfManager::PREEDIT, keyString, cursorPosition, numberOfChars ); + Dali::ImfManager::ImfEventData imfEventData( Dali::ImfManager::PREEDIT, preEditString, cursorPosition, 0 ); Dali::ImfManager::ImfCallbackData callbackData = mEventSignal.Emit( handle, imfEventData ); - if ( callbackData.update ) + if( callbackData.update ) { - SetCursorPosition( callbackData.cursorPosition ); - SetSurroundingText( callbackData.currentText ); + mIMFCursorPosition = static_cast( callbackData.cursorPosition ); NotifyCursorPosition(); } - if ( callbackData.preeditResetRequired ) + if( callbackData.preeditResetRequired ) { Reset(); } @@ -413,24 +402,21 @@ void ImfManager::PreEditChanged( void *, Ecore_IMF_Context *imfContext, void *ev free( preEditString ); } -void ImfManager::CommitReceived( void *, Ecore_IMF_Context *imfContext, void *event_info ) +void ImfManager::CommitReceived( void*, Ecore_IMF_Context* imfContext, void* event_info ) { DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::CommitReceived\n" ); if ( Dali::Adaptor::IsAvailable() ) { - const std::string keyString( (char *)event_info ); - const int cursorOffset( 0 ); - const int numberOfChars( 0 ); + const std::string keyString( static_cast( event_info ) ); Dali::ImfManager handle( this ); - Dali::ImfManager::ImfEventData imfEventData ( Dali::ImfManager::COMMIT, keyString, cursorOffset, numberOfChars ); + Dali::ImfManager::ImfEventData imfEventData( Dali::ImfManager::COMMIT, keyString, 0, 0 ); Dali::ImfManager::ImfCallbackData callbackData = mEventSignal.Emit( handle, imfEventData ); - if ( callbackData.update ) + if( callbackData.update ) { - SetCursorPosition( callbackData.cursorPosition ); - SetSurroundingText( callbackData.currentText ); + mIMFCursorPosition = static_cast( callbackData.cursorPosition ); NotifyCursorPosition(); } @@ -442,38 +428,28 @@ void ImfManager::CommitReceived( void *, Ecore_IMF_Context *imfContext, void *ev * Here the IMF module wishes to know the string we are working with and where within the string the cursor is * We need to signal the application to tell us this information. */ -Eina_Bool ImfManager::RetrieveSurrounding( void *data, Ecore_IMF_Context *imfContext, char** text, int* cursorPosition ) +Eina_Bool ImfManager::RetrieveSurrounding( void* data, Ecore_IMF_Context* imfContext, char** text, int* cursorPosition ) { DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::RetrieveSurrounding\n" ); - std::string keyString ( "" ); - int cursorOffset( 0 ); - int numberOfChars( 0 ); - - Dali::ImfManager::ImfEventData imfData ( Dali::ImfManager::GETSURROUNDING , keyString, cursorOffset, numberOfChars ); + Dali::ImfManager::ImfEventData imfData( Dali::ImfManager::GETSURROUNDING, std::string(), 0, 0 ); Dali::ImfManager handle( this ); - mEventSignal.Emit( handle, imfData ); + Dali::ImfManager::ImfCallbackData callbackData = mEventSignal.Emit( handle, imfData ); - if ( text ) + if( callbackData.update ) { - std::string surroundingText( GetSurroundingText() ); - - if ( !surroundingText.empty() ) + if( text ) { - *text = strdup( surroundingText.c_str() ); + *text = strdup( callbackData.currentText.c_str() ); } - else + + if( cursorPosition ) { - *text = strdup( "" ); + mIMFCursorPosition = static_cast( callbackData.cursorPosition ); + *cursorPosition = mIMFCursorPosition; } } - if ( cursorPosition ) - { - *cursorPosition = GetCursorPosition(); - } - - return EINA_TRUE; } @@ -481,21 +457,24 @@ Eina_Bool ImfManager::RetrieveSurrounding( void *data, Ecore_IMF_Context *imfCon * Called when an IMF delete surrounding event is received. * Here we tell the application that it should delete a certain range. */ -void ImfManager::DeleteSurrounding( void *data, Ecore_IMF_Context *imfContext, void *event_info ) +void ImfManager::DeleteSurrounding( void* data, Ecore_IMF_Context* imfContext, void* event_info ) { DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::DeleteSurrounding\n" ); - if ( Dali::Adaptor::IsAvailable() ) + if( Dali::Adaptor::IsAvailable() ) { - Ecore_IMF_Event_Delete_Surrounding* deleteSurroundingEvent = (Ecore_IMF_Event_Delete_Surrounding*) event_info; + Ecore_IMF_Event_Delete_Surrounding* deleteSurroundingEvent = static_cast( event_info ); - const std::string keyString( "" ); - const int cursorOffset( deleteSurroundingEvent->offset ); - const int numberOfChars( deleteSurroundingEvent->n_chars ); - - Dali::ImfManager::ImfEventData imfData ( Dali::ImfManager::DELETESURROUNDING , keyString, cursorOffset, numberOfChars ); + Dali::ImfManager::ImfEventData imfData( Dali::ImfManager::DELETESURROUNDING, std::string(), deleteSurroundingEvent->offset, deleteSurroundingEvent->n_chars ); Dali::ImfManager handle( this ); - mEventSignal.Emit( handle, imfData ); + Dali::ImfManager::ImfCallbackData callbackData = mEventSignal.Emit( handle, imfData ); + + if( callbackData.update ) + { + mIMFCursorPosition = static_cast( callbackData.cursorPosition ); + + NotifyCursorPosition(); + } } } @@ -503,34 +482,34 @@ void ImfManager::NotifyCursorPosition() { DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::NotifyCursorPosition\n" ); - if ( mIMFContext ) + if( mIMFContext ) { ecore_imf_context_cursor_position_set( mIMFContext, mIMFCursorPosition ); } } -int ImfManager::GetCursorPosition() +void ImfManager::SetCursorPosition( unsigned int cursorPosition ) { - DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::GetCursorPosition\n" ); + DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::SetCursorPosition\n" ); - return mIMFCursorPosition; + mIMFCursorPosition = static_cast( cursorPosition ); } -void ImfManager::SetCursorPosition( unsigned int cursorPosition ) +unsigned int ImfManager::GetCursorPosition() const { - DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::SetCursorPosition\n" ); + DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::GetCursorPosition\n" ); - mIMFCursorPosition = ( int )cursorPosition; + return static_cast( mIMFCursorPosition ); } -void ImfManager::SetSurroundingText( std::string text ) +void ImfManager::SetSurroundingText( const std::string& text ) { DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::SetSurroundingText\n" ); mSurroundingText = text; } -std::string ImfManager::GetSurroundingText() +const std::string& ImfManager::GetSurroundingText() const { DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::GetSurroundingText\n" );