X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=adaptors%2Fx11%2Fimf-manager-impl-x.cpp;h=1d9294fdec9fc386231008a109b75fa04b5c3a3d;hb=refs%2Fchanges%2F83%2F154783%2F1;hp=ff67cb3e08c374621134d8ce040a148ee49af0b9;hpb=3ecc22df7975e9ee686cf1765a712d3388ab770e;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 old mode 100644 new mode 100755 index ff67cb3..1d9294f --- a/adaptors/x11/imf-manager-impl-x.cpp +++ b/adaptors/x11/imf-manager-impl-x.cpp @@ -27,8 +27,12 @@ #include #include #include +#include #include #include +// Ecore is littered with C style cast +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" #include "ecore-virtual-keyboard.h" namespace Dali @@ -118,6 +122,19 @@ void ImfDeleteSurrounding( void *data, Ecore_IMF_Context *imfContext, void *even } // unnamed namespace +void ImfManager::Finalize() +{ + DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::Finalize\n" ); + if ( mInited ) + { + VirtualKeyboard::DisconnectCallbacks( mIMFContext ); + DisconnectCallbacks(); + DeleteContext(); + ecore_imf_shutdown(); + mInited = false; + } +} + bool ImfManager::IsAvailable() { bool available( false ); @@ -134,6 +151,7 @@ bool ImfManager::IsAvailable() Dali::ImfManager ImfManager::Get() { Dali::ImfManager manager; + ImfManager *imfManager = NULL; Dali::SingletonService service( SingletonService::Get() ); if ( service ) @@ -143,7 +161,8 @@ Dali::ImfManager ImfManager::Get() if( handle ) { // If so, downcast the handle - manager = Dali::ImfManager( dynamic_cast< ImfManager* >( handle.GetObjectPtr() ) ); + imfManager = dynamic_cast< ImfManager* >( handle.GetObjectPtr() ); + manager = Dali::ImfManager( imfManager ); } else if ( Adaptor::IsAvailable() ) { @@ -154,14 +173,14 @@ Dali::ImfManager ImfManager::Get() // The Ecore_X_Window needs to use the ImfManager. // Only when the render surface is window, we can get the Ecore_X_Window. - Ecore_X_Window ecoreXwin( AnyCast(nativeWindow) ); - if (ecoreXwin) + Ecore_X_Window *ecoreXwin( AnyCast< Ecore_X_Window* >( nativeWindow ) ); + if ( ecoreXwin ) { // If we fail to get Ecore_X_Window, we can't use the ImfManager correctly. // Thus you have to call "ecore_imf_context_client_window_set" somewhere. // In EvasPlugIn, this function is called in EvasPlugin::ConnectEcoreEvent(). - - manager = Dali::ImfManager( new ImfManager( ecoreXwin ) ); + imfManager = new ImfManager( ecoreXwin ); + manager = Dali::ImfManager( imfManager ); service.Register( typeid( manager ), manager ); } else @@ -171,33 +190,36 @@ Dali::ImfManager ImfManager::Get() } } + if ( ( imfManager != NULL ) !imfManager->mInited ) + { + ecore_imf_init(); + imfManager->CreateContext( imfManager->mEcoreXWin ); + + imfManager->ConnectCallbacks(); + VirtualKeyboard::ConnectCallbacks( mIMFContext ); + imfManager->mInited = true; + } + return manager; } -ImfManager::ImfManager( Ecore_X_Window ecoreXwin ) +ImfManager::ImfManager( Ecore_X_Window* ecoreXwin ) : mIMFContext(), + mEcoreXWin( ecoreXwin ), mIMFCursorPosition( 0 ), mSurroundingText(), + mInited( false ), mRestoreAfterFocusLost( false ), mIdleCallbackConnected( false ) { - ecore_imf_init(); - CreateContext( ecoreXwin ); - - ConnectCallbacks(); - VirtualKeyboard::ConnectCallbacks( mIMFContext ); } ImfManager::~ImfManager() { - VirtualKeyboard::DisconnectCallbacks( mIMFContext ); - DisconnectCallbacks(); - - DeleteContext(); - ecore_imf_shutdown(); + Finalize(); } -void ImfManager::CreateContext( Ecore_X_Window ecoreXwin ) +void ImfManager::CreateContext( Ecore_X_Window* ecoreXwin ) { DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::CreateContext\n" ); @@ -230,6 +252,7 @@ void ImfManager::DeleteContext() if ( mIMFContext ) { + ecore_imf_context_del( mIMFContext ); mIMFContext = NULL; } } @@ -520,8 +543,206 @@ void ImfManager::NotifyTextInputMultiLine( bool multiLine ) { } +Dali::ImfManager::TextDirection ImfManager::GetTextDirection() +{ + Dali::ImfManager::TextDirection direction ( Dali::ImfManager::LeftToRight ); + + if ( ImfManager::IsAvailable() /* We do not want to create an instance of ImfManager */ ) + { + if ( mIMFContext ) + { + char* locale( NULL ); + ecore_imf_context_input_panel_language_locale_get( mIMFContext, &locale ); + + if ( locale ) + { + direction = static_cast< Dali::ImfManager::TextDirection >( Locale::GetDirection( std::string( locale ) ) ); + free( locale ); + } + } + } + return direction; +} + +Rect ImfManager::GetInputMethodArea() +{ + int xPos, yPos, width, height; + + width = height = xPos = yPos = 0; + + if( mIMFContext ) + { + ecore_imf_context_input_panel_geometry_get( mIMFContext, &xPos, &yPos, &width, &height ); + } + else + { + DALI_LOG_WARNING("VKB Unable to get IMF Context so GetSize unavailable\n"); + } + + return Rect(xPos,yPos,width,height); +} + +void ImfManager::ApplyOptions( const InputMethodOptions& options ) +{ + using namespace Dali::InputMethod::Category; + + int index; + + if (mIMFContext == NULL) + { + DALI_LOG_WARNING("VKB Unable to excute ApplyOptions with Null ImfContext\n"); + return; + } + + if ( mOptions.CompareAndSet(PANEL_LAYOUT, options, index) ) + { + } + if ( mOptions.CompareAndSet(AUTO_CAPITALISE, options, index) ) + { + } + if ( mOptions.CompareAndSet(ACTION_BUTTON_TITLE, options, index) ) + { + } + if ( mOptions.CompareAndSet(VARIATION, options, index) ) + { + } +} + +void ImfManager::SetInputPanelData( const std::string& data ) +{ + DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::SetInputPanelData\n" ); + + if( mIMFContext ) + { + int length = data.length(); + ecore_imf_context_input_panel_imdata_set( mIMFContext, data.c_str(), length ); + } +} + +void ImfManager::GetInputPanelData( std::string& data ) +{ + DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::GetInputPanelData\n" ); + + if( mIMFContext ) + { + int length = 4096; // The max length is 4096 bytes + Dali::Vector< char > buffer; + buffer.Resize( length ); + ecore_imf_context_input_panel_imdata_get( mIMFContext, &buffer[0], &length ); + data = std::string( buffer.Begin(), buffer.End() ); + } +} + +Dali::ImfManager::State ImfManager::GetInputPanelState() +{ + DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::GetInputPanelState\n" ); + + if( mIMFContext ) + { + int value; + value = ecore_imf_context_input_panel_state_get( mIMFContext ); + + switch (value) + { + case ECORE_IMF_INPUT_PANEL_STATE_SHOW: + { + return Dali::ImfManager::SHOW; + break; + } + + case ECORE_IMF_INPUT_PANEL_STATE_HIDE: + { + return Dali::ImfManager::HIDE; + break; + } + + case ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW: + { + return Dali::ImfManager::WILL_SHOW; + break; + } + + default: + { + return Dali::ImfManager::DEFAULT; + } + } + } + return Dali::ImfManager::DEFAULT; +} + +void ImfManager::SetReturnKeyState( bool visible ) +{ + DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::SetReturnKeyState\n" ); + + if( mIMFContext ) + { + ecore_imf_context_input_panel_return_key_disabled_set( mIMFContext, !visible ); + } +} + +void ImfManager::AutoEnableInputPanel( bool enabled ) +{ + DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::AutoEnableInputPanel\n" ); + + if( mIMFContext ) + { + ecore_imf_context_input_panel_enabled_set( mIMFContext, enabled ); + } +} + +void ImfManager::ShowInputPanel() +{ + DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::ShowInputPanel\n" ); + + if( mIMFContext ) + { + ecore_imf_context_input_panel_show( mIMFContext ); + } +} + +void ImfManager::HideInputPanel() +{ + DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::HideInputPanel\n" ); + + if( mIMFContext ) + { + ecore_imf_context_input_panel_hide( mIMFContext ); + } +} + +Dali::ImfManager::KeyboardType ImfManager::GetKeyboardType() +{ + return Dali::ImfManager::KeyboardType::SOFTWARE_KEYBOARD; +} + +std::string ImfManager::GetInputPanelLocale() +{ + DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::GetInputPanelLocale\n" ); + + std::string locale = ""; + + if( mIMFContext ) + { + char* value = NULL; + ecore_imf_context_input_panel_language_locale_get( mIMFContext, &value ); + + if( value ) + { + std::string valueCopy( value ); + locale = valueCopy; + + // The locale string retrieved must be freed with free(). + free( value ); + } + } + return locale; +} + } // Adaptor } // Internal } // Dali + +#pragma GCC diagnostic pop