Also remove ImfManager implementation from Wayland as it was not being initialised propertly anyway
(we always returned an empty handle as we never registered the singleton)
Change-Id: I39e44f35ccca8fa193b7a21324ca78027bda76fa
Dali::AccessibilityManager mAccessibilityManager; ///< Pointer to the accessibility manager
Dali::ClipboardEventNotifier mClipboardEventNotifier; ///< Pointer to the clipboard event notifier
Dali::Clipboard mClipboard;///< Pointer to the clipboard
- Dali::ImfManager mImfManager; ///< Pointer to the IMF manager.
struct Impl; ///< Contains Ecore specific information
Impl* mImpl; ///< Created on construction and destroyed on destruction.
void Show()
{
- if( Dali::Adaptor::IsAvailable() )
- {
- Dali::ImfManager imfManager = ImfManager::Get();
- Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
+ Dali::ImfManager imfManager = ImfManager::Get(); // Create ImfManager instance (if required) to show the keyboard
+ Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
- if( imfContext )
- {
- ecore_imf_context_input_panel_show( imfContext );
- }
+ if( imfContext )
+ {
+ ecore_imf_context_input_panel_show( imfContext );
}
}
void Hide()
{
- if( Dali::Adaptor::IsAvailable() )
+ if( ImfManager::IsAvailable() /* We do not want to create an ImfManager instance*/ )
{
Dali::ImfManager imfManager = ImfManager::Get();
Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
bool IsVisible()
{
- if( Dali::Adaptor::IsAvailable() )
+ if( ImfManager::IsAvailable() /* We do not want to create an ImfManager instance */ )
{
DALI_LOG_INFO( gLogFilter, Debug::General, "IsVisible\n" );
void SetReturnKeyType( Dali::VirtualKeyboard::ReturnKeyType type )
{
- if ( Dali::Adaptor::IsAvailable() )
- {
- Dali::ImfManager imfManager = ImfManager::Get();
- Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
+ Dali::ImfManager imfManager = ImfManager::Get(); // Create ImfManager instance (if required) when setting values
+ Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
- if( imfContext )
- {
- DALI_LOG_INFO( gLogFilter, Debug::General, "VKB Retrun key type is changed[%d]\n", type );
+ if( imfContext )
+ {
+ DALI_LOG_INFO( gLogFilter, Debug::General, "VKB Retrun key type is changed[%d]\n", type );
- gReturnKeyType = type;
- ecore_imf_context_input_panel_return_key_type_set( imfContext, static_cast<Ecore_IMF_Input_Panel_Return_Key_Type>( type ) );
- }
+ gReturnKeyType = type;
+ ecore_imf_context_input_panel_return_key_type_set( imfContext, static_cast<Ecore_IMF_Input_Panel_Return_Key_Type>( type ) );
}
}
void EnablePrediction(const bool enable)
{
- if ( Dali::Adaptor::IsAvailable() )
- {
- Dali::ImfManager imfManager = ImfManager::Get();
- Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
+ Dali::ImfManager imfManager = ImfManager::Get(); // Create ImfManager instance (if required) when enabling prediction
+ Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
- if ( imfContext )
- {
- ecore_imf_context_prediction_allow_set( imfContext, (enable)? EINA_TRUE : EINA_FALSE);
- }
+ if ( imfContext )
+ {
+ ecore_imf_context_prediction_allow_set( imfContext, (enable)? EINA_TRUE : EINA_FALSE);
}
}
bool IsPredictionEnabled()
{
- if ( Dali::Adaptor::IsAvailable() )
+ if ( ImfManager::IsAvailable() /* We do not want to create an instance of ImfManger */ )
{
Dali::ImfManager imfManager = ImfManager::Get();
Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
int xPos, yPos, width, height;
width = height = xPos = yPos = 0;
- if ( Dali::Adaptor::IsAvailable() )
- {
- Dali::ImfManager imfManager = ImfManager::Get();
- Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
+ Dali::ImfManager imfManager = ImfManager::Get(); // Create ImfManager instance (if required) as we may need to do some size related setup in the application
+ Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
- if( imfContext )
- {
- ecore_imf_context_input_panel_geometry_get(imfContext, &xPos, &yPos, &width, &height);
- }
- else
- {
- DALI_LOG_WARNING("VKB Unable to get IMF Context so GetSize unavailable\n");
- // return 0 as real size unknown.
- }
+ if( imfContext )
+ {
+ ecore_imf_context_input_panel_geometry_get(imfContext, &xPos, &yPos, &width, &height);
+ }
+ else
+ {
+ DALI_LOG_WARNING("VKB Unable to get IMF Context so GetSize unavailable\n");
+ // return 0 as real size unknown.
}
return Rect<int>(xPos,yPos,width,height);
{
Dali::VirtualKeyboard::TextDirection direction ( Dali::VirtualKeyboard::LeftToRight );
- if ( Dali::Adaptor::IsAvailable() )
+ if ( ImfManager::IsAvailable() /* We do not want to create an instance of ImfManager */ )
{
Dali::ImfManager imfManager = ImfManager::Get();
Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
bool eventHandled( false );
- Ecore_IMF_Context* imfContext = NULL;
- if ( Dali::Adaptor::IsAvailable() && handler->mImfManager )
- {
- imfContext = reinterpret_cast<Ecore_IMF_Context*>( handler->mImfManager.GetContext() );
- }
-
// If a device key then skip ecore_imf_context_filter_event.
- if ( imfContext && !( KeyLookup::IsDeviceButton( keyEvent->keyname ) ) )
+ if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
{
- // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
- Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
- ecoreKeyDownEvent.keyname = keyEvent->keyname;
- ecoreKeyDownEvent.key = keyEvent->key;
- ecoreKeyDownEvent.string = keyEvent->string;
- ecoreKeyDownEvent.compose = keyEvent->compose;
- ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
- ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
- ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
-
- eventHandled = ecore_imf_context_filter_event( imfContext,
- ECORE_IMF_EVENT_KEY_DOWN,
- (Ecore_IMF_Event *) &ecoreKeyDownEvent );
-
- // If the event has not been handled by IMF then check if we should reset our IMF context
- if( !eventHandled )
+ Ecore_IMF_Context* imfContext = NULL;
+ Dali::ImfManager imfManager( ImfManager::Get() );
+ if ( imfManager )
+ {
+ imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
+ }
+
+ if ( imfContext )
{
- if ( !strcmp( keyEvent->keyname, "Escape" ) ||
- !strcmp( keyEvent->keyname, "Return" ) ||
- !strcmp( keyEvent->keyname, "KP_Enter" ) )
+ // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
+ Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
+ ecoreKeyDownEvent.keyname = keyEvent->keyname;
+ ecoreKeyDownEvent.key = keyEvent->key;
+ ecoreKeyDownEvent.string = keyEvent->string;
+ ecoreKeyDownEvent.compose = keyEvent->compose;
+ ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
+ ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
+ ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
+
+ eventHandled = ecore_imf_context_filter_event( imfContext,
+ ECORE_IMF_EVENT_KEY_DOWN,
+ (Ecore_IMF_Event *) &ecoreKeyDownEvent );
+
+ // If the event has not been handled by IMF then check if we should reset our IMF context
+ if( !eventHandled )
{
- ecore_imf_context_reset( imfContext );
+ if ( !strcmp( keyEvent->keyname, "Escape" ) ||
+ !strcmp( keyEvent->keyname, "Return" ) ||
+ !strcmp( keyEvent->keyname, "KP_Enter" ) )
+ {
+ ecore_imf_context_reset( imfContext );
+ }
}
}
}
Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
bool eventHandled( false );
- Ecore_IMF_Context* imfContext = NULL;
- if ( Dali::Adaptor::IsAvailable() && handler->mImfManager )
- {
- imfContext = reinterpret_cast<Ecore_IMF_Context*>( handler->mImfManager.GetContext() );
- }
-
// XF86Stop and XF86Send must skip ecore_imf_context_filter_event.
- if ( imfContext && strcmp( keyEvent->keyname, "XF86Send" ) && strcmp( keyEvent->keyname, "XF86Phone" ) && strcmp( keyEvent->keyname, "XF86Stop" ) )
-
+ if ( strcmp( keyEvent->keyname, "XF86Send" ) &&
+ strcmp( keyEvent->keyname, "XF86Phone" ) &&
+ strcmp( keyEvent->keyname, "XF86Stop" ) )
{
- // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
- Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
- ecoreKeyUpEvent.keyname = keyEvent->keyname;
- ecoreKeyUpEvent.key = keyEvent->key;
- ecoreKeyUpEvent.string = keyEvent->string;
- ecoreKeyUpEvent.compose = keyEvent->compose;
- ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
- ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
- ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
-
- eventHandled = ecore_imf_context_filter_event( imfContext,
- ECORE_IMF_EVENT_KEY_UP,
- (Ecore_IMF_Event *) &ecoreKeyUpEvent );
+ Ecore_IMF_Context* imfContext = NULL;
+ Dali::ImfManager imfManager( ImfManager::Get() );
+ if ( imfManager )
+ {
+ imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
+ }
+
+ if ( imfContext )
+ {
+ // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
+ Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
+ ecoreKeyUpEvent.keyname = keyEvent->keyname;
+ ecoreKeyUpEvent.key = keyEvent->key;
+ ecoreKeyUpEvent.string = keyEvent->string;
+ ecoreKeyUpEvent.compose = keyEvent->compose;
+ ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
+ ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
+ ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
+
+ eventHandled = ecore_imf_context_filter_event( imfContext,
+ ECORE_IMF_EVENT_KEY_UP,
+ (Ecore_IMF_Event *) &ecoreKeyUpEvent );
+ }
}
// If the event wasn't handled then we should send a key event.
{
DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
- if ( handler->mImfManager )
+ if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
{
- ImfManager& imfManager( ImfManager::GetImplementation( handler->mImfManager ) );
- if( imfManager.RestoreAfterFocusLost() )
+ Dali::ImfManager imfManager( ImfManager::Get() );
+ if ( imfManager )
{
- imfManager.Activate();
+ ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
+ if( imfManagerImpl.RestoreAfterFocusLost() )
+ {
+ imfManagerImpl.Activate();
+ }
}
}
// No need to connect callbacks as KeyboardStatusChanged will be called.
// If the window loses focus then hide the keyboard.
if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
{
- if ( handler->mImfManager )
+ if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
{
- ImfManager& imfManager( ImfManager::GetImplementation( handler->mImfManager ) );
- if( imfManager.RestoreAfterFocusLost() )
+ Dali::ImfManager imfManager( ImfManager::Get() );
+ if ( imfManager )
{
- imfManager.Deactivate();
+ ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
+ if( imfManagerImpl.RestoreAfterFocusLost() )
+ {
+ imfManagerImpl.Deactivate();
+ }
}
}
mAccessibilityManager( AccessibilityManager::Get() ),
mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
mClipboard(Clipboard::Get()),
- mImfManager( ImfManager::Get() ),
mImpl( NULL )
{
Ecore_Wl_Window* window = 0;
namespace
{
-#if defined(DEBUG_ENABLED)
-Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_IMF_MANAGER");
-#endif
-
-// Currently this code is internal to dali/dali/internal/event/text/utf8.h but should be made Public and used from there instead.
-size_t Utf8SequenceLength(const unsigned char leadByte)
-{
- size_t length = 0;
-
- if ((leadByte & 0x80) == 0 ) //ASCII character (lead bit zero)
- {
- length = 1;
- }
- else if (( leadByte & 0xe0 ) == 0xc0 ) //110x xxxx
- {
- length = 2;
- }
- else if (( leadByte & 0xf0 ) == 0xe0 ) //1110 xxxx
- {
- length = 3;
- }
- else if (( leadByte & 0xf8 ) == 0xf0 ) //1111 0xxx
- {
- length = 4;
- }
-
- return length;
-}
-
-// Static function calls used by ecore 'c' style callback registration
-void Commit( void *data, Ecore_IMF_Context *imfContext, void *event_info )
-{
- if ( data )
- {
- ImfManager* imfManager = reinterpret_cast< ImfManager* > ( data );
- imfManager->CommitReceived( data, imfContext, event_info );
- }
-}
-
-void PreEdit( void *data, Ecore_IMF_Context *imfContext, void *event_info )
+BaseHandle Create()
{
- if ( data )
- {
- ImfManager* imfManager = reinterpret_cast< ImfManager* > ( data );
- imfManager->PreEditChanged( data, imfContext, event_info );
- }
+ return ImfManager::Get();
}
-Eina_Bool ImfRetrieveSurrounding(void *data, Ecore_IMF_Context *imfContext, char** text, int* cursorPosition )
-{
- if ( data )
- {
- ImfManager* imfManager = reinterpret_cast< ImfManager* > ( data );
- return imfManager->RetrieveSurrounding( data, imfContext, text, cursorPosition );
- }
- else
- {
- return false;
- }
-}
+TypeRegistration IMF_MANAGER_TYPE( typeid(Dali::ImfManager), typeid(Dali::BaseHandle), Create );
-/**
- * Called when an IMF delete surrounding event is received.
- * Here we tell the application that it should delete a certain range.
- */
-void ImfDeleteSurrounding( void *data, Ecore_IMF_Context *imfContext, void *event_info )
-{
- if ( data )
- {
- ImfManager* imfManager = reinterpret_cast< ImfManager* > ( data );
- imfManager->DeleteSurrounding( data, imfContext, event_info );
- }
-}
+} // unnamed namespace
-BaseHandle Create()
+bool ImfManager::IsAvailable()
{
- BaseHandle handle( ImfManager::Get() );
-
- return handle;
+ return false;
}
-TypeRegistration IMF_MANAGER_TYPE( typeid(Dali::ImfManager), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
-
-} // unnamed namespace
-
Dali::ImfManager ImfManager::Get()
{
- Dali::ImfManager manager;
-
- Dali::SingletonService service( SingletonService::Get() );
- if ( service )
- {
- // Check whether the singleton is already created
- Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::ImfManager ) );
- if(handle)
- {
- // If so, downcast the handle
- manager = Dali::ImfManager( dynamic_cast< ImfManager* >( handle.GetObjectPtr() ) );
- }
- }
-
- return manager;
+ // Return empty handle as not supported
+ return Dali::ImfManager();
}
ImfManager::~ImfManager()
{
- VirtualKeyboard::DisconnectCallbacks( mIMFContext );
- DisconnectCallbacks();
-
- DeleteContext();
- ecore_imf_shutdown();
}
void ImfManager::DeleteContext()
{
- DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::DeleteContext\n" );
-
- if ( mIMFContext )
- {
- mIMFContext = NULL;
- }
}
-// Callbacks for predicitive text support.
void ImfManager::ConnectCallbacks()
{
- if ( mIMFContext )
- {
- DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::ConnectCallbacks\n" );
-
- ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit, this );
- ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit, this );
- ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding, this );
-
- ecore_imf_context_retrieve_surrounding_callback_set( mIMFContext, ImfRetrieveSurrounding, this);
- }
}
void ImfManager::DisconnectCallbacks()
{
- if ( mIMFContext )
- {
- DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::DisconnectCallbacks\n" );
-
- ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, PreEdit );
- ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_COMMIT, Commit );
- ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding );
-
- // We do not need to unset the retrieve surrounding callback.
- }
}
void ImfManager::Activate()
{
- // Reset mIdleCallbackConnected
- mIdleCallbackConnected = false;
-
- if ( mIMFContext )
- {
- DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::Activate\n" );
-
- ecore_imf_context_focus_in( mIMFContext );
-
- // emit keyboard activated signal
- Dali::ImfManager handle( this );
- mActivatedSignalV2.Emit( handle );
- }
}
void ImfManager::Deactivate()
{
- if( mIMFContext )
- {
- DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::Deactivate\n" );
-
- Reset();
- ecore_imf_context_focus_out( mIMFContext );
- }
-
- // Reset mIdleCallbackConnected
- mIdleCallbackConnected = false;
}
void ImfManager::Reset()
{
- DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::Reset\n" );
-
- if ( mIMFContext )
- {
- ecore_imf_context_reset( mIMFContext );
- }
}
Ecore_IMF_Context* ImfManager::GetContext()
{
- DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::GetContext\n" );
-
return mIMFContext;
}
mRestoreAfterFocusLost = toggle;
}
-/**
- * Called when an IMF Pre-Edit changed event is received.
- * 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 )
{
- DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::PreEditChanged\n" );
-
- char *preEditString( NULL );
- int cursorPosition( 0 );
- Eina_List *attrs = NULL;
- Eina_List *l = NULL;
-
- 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.
- ecore_imf_context_preedit_string_with_attributes_get( imfContext, &preEditString, &attrs, &cursorPosition );
-
- 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) ))
- {
- if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB4 ) // (Ecore_IMF)
- {
- // 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.
-
- size_t visualCharacterIndex = 0;
- 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' )
- {
- // 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.
- if ( byteIndex == attr->end_index )
- {
- cursorPosition = visualCharacterIndex;
- break;
- // end loop as found cursor position that matches byte position
- }
- else
- {
- byteIndex += currentSequenceLength; // jump to next character
- visualCharacterIndex++; // increment character count so we know our position for when we get a match
- }
-
- DALI_ASSERT_DEBUG( visualCharacterIndex < strlen( preEditString ));
- }
- }
- }
- }
-
- 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::ImfCallbackData callbackData = mEventSignalV2.Emit( handle, imfEventData );
-
- if ( callbackData.update )
- {
- SetCursorPosition( callbackData.cursorPosition );
- SetSurroundingText( callbackData.currentText );
-
- NotifyCursorPosition();
- }
-
- if ( callbackData.preeditResetRequired )
- {
- Reset();
- }
- }
- free( preEditString );
}
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 );
-
- Dali::ImfManager handle( this );
- Dali::ImfManager::ImfEventData imfEventData ( Dali::ImfManager::COMMIT, keyString, cursorOffset, numberOfChars );
- Dali::ImfManager::ImfCallbackData callbackData = mEventSignalV2.Emit( handle, imfEventData );
-
- if ( callbackData.update )
- {
- SetCursorPosition( callbackData.cursorPosition );
- SetSurroundingText( callbackData.currentText );
-
- NotifyCursorPosition();
- }
- }
}
-/**
- * Called when an IMF retrieve surround event is received.
- * 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 )
{
- 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 handle( this );
- mEventSignalV2.Emit( handle, imfData );
-
- if ( text )
- {
- std::string surroundingText( GetSurroundingText() );
-
- if ( !surroundingText.empty() )
- {
- *text = strdup( surroundingText.c_str() );
- }
- else
- {
- *text = strdup( "" );
- }
- }
-
- if ( cursorPosition )
- {
- *cursorPosition = GetCursorPosition();
- }
-
-
return EINA_TRUE;
}
-/**
- * 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 )
{
- DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::DeleteSurrounding\n" );
-
- if ( Dali::Adaptor::IsAvailable() )
- {
- Ecore_IMF_Event_Delete_Surrounding* deleteSurroundingEvent = (Ecore_IMF_Event_Delete_Surrounding*) 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 handle( this );
- mEventSignalV2.Emit( handle, imfData );
- }
}
void ImfManager::NotifyCursorPosition()
{
- DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::NotifyCursorPosition\n" );
-
- if ( mIMFContext )
- {
- ecore_imf_context_cursor_position_set( mIMFContext, mIMFCursorPosition );
- }
}
int ImfManager::GetCursorPosition()
{
- DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::GetCursorPosition\n" );
-
return mIMFCursorPosition;
}
void ImfManager::SetCursorPosition( unsigned int cursorPosition )
{
- DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::SetCursorPosition\n" );
-
mIMFCursorPosition = ( int )cursorPosition;
}
void ImfManager::SetSurroundingText( std::string text )
{
- DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::SetSurroundingText\n" );
-
mSurroundingText = text;
}
std::string ImfManager::GetSurroundingText()
{
- DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::GetSurroundingText\n" );
-
return mSurroundingText;
}
public:
/**
- * Create the IMF manager.
+ * Check whether the ImfManager is available.
+ * @return true if available, false otherwise
+ */
+ static bool IsAvailable();
+
+ /**
+ * Get the IMF manager instance, it creates the instance if it has not already been created.
+ * Internally, a check should be made using IsAvailable() before this is called as we do not want
+ * to create an instance if not needed by applications.
+ * @see IsAvailable()
*/
static Dali::ImfManager Get();
Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
bool eventHandled( false );
- Ecore_IMF_Context* imfContext = NULL;
- if ( Dali::Adaptor::IsAvailable() && handler->mImfManager )
- {
- imfContext = reinterpret_cast<Ecore_IMF_Context*>( handler->mImfManager.GetContext() );
- }
-
// If a device key then skip ecore_imf_context_filter_event.
- if ( imfContext && !( KeyLookup::IsDeviceButton( keyEvent->keyname ) ) )
+ if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
{
- // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
- Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
- ecoreKeyDownEvent.keyname = keyEvent->keyname;
- ecoreKeyDownEvent.key = keyEvent->key;
- ecoreKeyDownEvent.string = keyEvent->string;
- ecoreKeyDownEvent.compose = keyEvent->compose;
- ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
- ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
- ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
-
- eventHandled = ecore_imf_context_filter_event( imfContext,
- ECORE_IMF_EVENT_KEY_DOWN,
- (Ecore_IMF_Event *) &ecoreKeyDownEvent );
-
- // If the event has not been handled by IMF then check if we should reset our IMF context
- if( !eventHandled )
+ Ecore_IMF_Context* imfContext = NULL;
+ Dali::ImfManager imfManager( ImfManager::Get() );
+ if ( imfManager )
+ {
+ imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
+ }
+
+ if ( imfContext )
{
- if ( !strcmp( keyEvent->keyname, "Escape" ) ||
- !strcmp( keyEvent->keyname, "Return" ) ||
- !strcmp( keyEvent->keyname, "KP_Enter" ) )
+ // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
+ Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
+ ecoreKeyDownEvent.keyname = keyEvent->keyname;
+ ecoreKeyDownEvent.key = keyEvent->key;
+ ecoreKeyDownEvent.string = keyEvent->string;
+ ecoreKeyDownEvent.compose = keyEvent->compose;
+ ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
+ ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
+ ecoreKeyDownEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
+
+ eventHandled = ecore_imf_context_filter_event( imfContext,
+ ECORE_IMF_EVENT_KEY_DOWN,
+ (Ecore_IMF_Event *) &ecoreKeyDownEvent );
+
+ // If the event has not been handled by IMF then check if we should reset our IMF context
+ if( !eventHandled )
{
- ecore_imf_context_reset( imfContext );
+ if ( !strcmp( keyEvent->keyname, "Escape" ) ||
+ !strcmp( keyEvent->keyname, "Return" ) ||
+ !strcmp( keyEvent->keyname, "KP_Enter" ) )
+ {
+ ecore_imf_context_reset( imfContext );
+ }
}
}
}
Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
bool eventHandled( false );
- Ecore_IMF_Context* imfContext = NULL;
- if ( Dali::Adaptor::IsAvailable() && handler->mImfManager )
- {
- imfContext = reinterpret_cast<Ecore_IMF_Context*>( handler->mImfManager.GetContext() );
- }
-
// XF86Stop and XF86Send must skip ecore_imf_context_filter_event.
- if ( imfContext && strcmp( keyEvent->keyname, "XF86Send" ) && strcmp( keyEvent->keyname, "XF86Phone" ) && strcmp( keyEvent->keyname, "XF86Stop" ) )
-
+ if ( strcmp( keyEvent->keyname, "XF86Send" ) &&
+ strcmp( keyEvent->keyname, "XF86Phone" ) &&
+ strcmp( keyEvent->keyname, "XF86Stop" ) )
{
- // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
- Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
- ecoreKeyUpEvent.keyname = keyEvent->keyname;
- ecoreKeyUpEvent.key = keyEvent->key;
- ecoreKeyUpEvent.string = keyEvent->string;
- ecoreKeyUpEvent.compose = keyEvent->compose;
- ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
- ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
- ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
-
- eventHandled = ecore_imf_context_filter_event( imfContext,
- ECORE_IMF_EVENT_KEY_UP,
- (Ecore_IMF_Event *) &ecoreKeyUpEvent );
+ Ecore_IMF_Context* imfContext = NULL;
+ Dali::ImfManager imfManager( ImfManager::Get() );
+ if ( imfManager )
+ {
+ imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
+ }
+
+ if ( imfContext )
+ {
+ // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
+ Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
+ ecoreKeyUpEvent.keyname = keyEvent->keyname;
+ ecoreKeyUpEvent.key = keyEvent->key;
+ ecoreKeyUpEvent.string = keyEvent->string;
+ ecoreKeyUpEvent.compose = keyEvent->compose;
+ ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
+ ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
+ ecoreKeyUpEvent.locks = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
+
+ eventHandled = ecore_imf_context_filter_event( imfContext,
+ ECORE_IMF_EVENT_KEY_UP,
+ (Ecore_IMF_Event *) &ecoreKeyUpEvent );
+ }
}
// If the event wasn't handled then we should send a key event.
{
DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
- if ( handler->mImfManager )
+ if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
{
- ImfManager& imfManager( ImfManager::GetImplementation( handler->mImfManager ) );
- if( imfManager.RestoreAfterFocusLost() )
+ Dali::ImfManager imfManager( ImfManager::Get() );
+ if ( imfManager )
{
- imfManager.Activate();
+ ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
+ if( imfManagerImpl.RestoreAfterFocusLost() )
+ {
+ imfManagerImpl.Activate();
+ }
}
}
// No need to connect callbacks as KeyboardStatusChanged will be called.
// If the window loses focus then hide the keyboard.
if ( focusOutEvent->win == handler->mImpl->mWindow )
{
- if ( handler->mImfManager )
+ if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
{
- ImfManager& imfManager( ImfManager::GetImplementation( handler->mImfManager ) );
- if( imfManager.RestoreAfterFocusLost() )
+ Dali::ImfManager imfManager( ImfManager::Get() );
+ if ( imfManager )
{
- imfManager.Deactivate();
+ ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
+ if( imfManagerImpl.RestoreAfterFocusLost() )
+ {
+ imfManagerImpl.Deactivate();
+ }
}
}
mAccessibilityManager( AccessibilityManager::Get() ),
mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
mClipboard(Clipboard::Get()),
- mImfManager( ImfManager::Get() ),
mImpl( NULL )
{
Ecore_X_Window window = 0;
BaseHandle Create()
{
- BaseHandle handle( ImfManager::Get() );
+ return ImfManager::Get();
+}
- Dali::SingletonService service( SingletonService::Get() );
- if ( !handle && Adaptor::IsAvailable() && service )
- {
- Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
+TypeRegistration IMF_MANAGER_TYPE( typeid(Dali::ImfManager), typeid(Dali::BaseHandle), Create );
- // 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( 0 );
- Dali::RenderSurface& surface( adaptorImpl.GetSurface() );
- if( surface.GetType() == Dali::RenderSurface::WINDOW )
- {
- ecoreXwin = AnyCast< Ecore_X_Window >( adaptorImpl.GetSurface().GetSurface() );
- }
+} // unnamed namespace
- // 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().
+bool ImfManager::IsAvailable()
+{
+ bool available( false );
- Dali::ImfManager manager = Dali::ImfManager( new ImfManager( ecoreXwin ) );
- service.Register( typeid( manager ), manager );
- handle = manager;
+ Dali::SingletonService service( SingletonService::Get() );
+ if ( service )
+ {
+ available = service.GetSingleton( typeid( Dali::ImfManager ) );
}
- return handle;
+ return available;
}
-TypeRegistration IMF_MANAGER_TYPE( typeid(Dali::ImfManager), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
-
-} // unnamed namespace
-
Dali::ImfManager ImfManager::Get()
{
Dali::ImfManager manager;
{
// Check whether the singleton is already created
Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::ImfManager ) );
- if(handle)
+ if( handle )
{
// If so, downcast the handle
manager = Dali::ImfManager( dynamic_cast< ImfManager* >( handle.GetObjectPtr() ) );
}
+ else if ( Adaptor::IsAvailable() )
+ {
+ // Create instance and register singleton only if the adaptor is available
+
+ Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::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( 0 );
+ Dali::RenderSurface& surface( adaptorImpl.GetSurface() );
+ if( surface.GetType() == Dali::RenderSurface::WINDOW )
+ {
+ ecoreXwin = AnyCast< Ecore_X_Window >( adaptorImpl.GetSurface().GetSurface() );
+ }
+
+ // 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 ) );
+ service.Register( typeid( manager ), manager );
+ }
}
return manager;
public:
/**
- * Create the IMF manager.
+ * Check whether the ImfManager is available.
+ * @return true if available, false otherwise
+ */
+ static bool IsAvailable();
+
+ /**
+ * Get the IMF manager instance, it creates the instance if it has not already been created.
+ * Internally, a check should be made using IsAvailable() before this is called as we do not want
+ * to create an instance if not needed by applications.
+ * @see IsAvailable()
*/
static Dali::ImfManager Get();