/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
// CLASS HEADER
+// Ecore is littered with C style cast
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
#include <imf-manager-impl.h>
// EXTERNAL INCLUDES
}
ImfManager* imfManager = reinterpret_cast< ImfManager* > ( data );
// Emit the signal that the language has changed
- imfManager->LanguageChangedSignal().Emit();
+ imfManager->LanguageChangedSignal().Emit( value );
}
void InputPanelGeometryChangedCallback ( void *data, Ecore_IMF_Context *context, int value )
}
ImfManager* imfManager = reinterpret_cast< ImfManager* > ( data );
// Emit signal that the keyboard is resized
- imfManager->ResizedSignal().Emit();
+ imfManager->ResizedSignal().Emit( value );
+}
+
+void InputPanelKeyboardTypeChangedCallback( void *data, Ecore_IMF_Context *context, int value )
+{
+ if( !data )
+ {
+ return;
+ }
+
+ ImfManager* imfManager = reinterpret_cast< ImfManager* > ( data );
+ switch (value)
+ {
+ case ECORE_IMF_INPUT_PANEL_SW_KEYBOARD_MODE:
+ {
+ // Emit Signal that the keyboard type is changed to Software Keyboard
+ imfManager->KeyboardTypeChangedSignal().Emit( Dali::ImfManager::KeyboardType::SOFTWARE_KEYBOARD );
+ break;
+ }
+ case ECORE_IMF_INPUT_PANEL_HW_KEYBOARD_MODE:
+ {
+ // Emit Signal that the keyboard type is changed to Hardware Keyboard
+ imfManager->KeyboardTypeChangedSignal().Emit( Dali::ImfManager::KeyboardType::HARDWARE_KEYBOARD );
+ break;
+ }
+ }
}
/**
}
}
+/**
+ * Called when the input method sends a private command.
+ */
+void PrivateCommand( void *data, Ecore_IMF_Context *imfContext, void *event_info )
+{
+ if ( data )
+ {
+ ImfManager* imfManager = reinterpret_cast< ImfManager* > ( data );
+ imfManager->SendPrivateCommand( data, imfContext, event_info );
+ }
+}
+
BaseHandle Create()
{
return ImfManager::Get();
} // unnamed namespace
+void ImfManager::Finalize()
+{
+ DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::Finalize\n" );
+ if ( mInited )
+ {
+ DisconnectCallbacks();
+ DeleteContext();
+ mInited = false;
+ }
+}
+
bool ImfManager::IsAvailable()
{
bool available( false );
Dali::ImfManager ImfManager::Get()
{
Dali::ImfManager manager;
+ ImfManager *imfManager = NULL;
Dali::SingletonService service( SingletonService::Get() );
if ( service )
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() )
{
// Create instance and register singleton only if the adaptor is available
-
Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
Any nativeWindow = adaptorImpl.GetNativeWindowHandle();
// If we fail to get Ecore_Wl_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( ecoreWwin ) );
+ imfManager = new ImfManager( ecoreWwin );
+ manager = Dali::ImfManager( imfManager );
service.Register( typeid( manager ), manager );
}
else
}
}
+ if ( ( imfManager != NULL ) && !imfManager->mInited )
+ {
+ imfManager->SetDefaultOptions();
+ imfManager->CreateContext( imfManager->mEcoreWlwin );
+ imfManager->ConnectCallbacks();
+ imfManager->mInited = true;
+ }
+
return manager;
}
ImfManager::ImfManager( Ecore_Wl_Window *ecoreWlwin )
: mIMFContext(),
+ mEcoreWlwin( ecoreWlwin ),
mIMFCursorPosition( 0 ),
mSurroundingText(),
+ mInited( false ),
mRestoreAfterFocusLost( false ),
mIdleCallbackConnected( false )
{
ecore_imf_init();
- CreateContext( ecoreWlwin );
-
- ConnectCallbacks();
}
ImfManager::~ImfManager()
{
- DisconnectCallbacks();
-
- DeleteContext();
+ Finalize();
ecore_imf_shutdown();
}
-
void ImfManager::CreateContext( Ecore_Wl_Window *ecoreWlwin )
{
DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::CreateContext\n" );
-
const char *contextId = ecore_imf_context_default_id_get();
if( contextId )
{
if ( mIMFContext )
{
+ ecore_imf_context_del( mIMFContext );
mIMFContext = NULL;
}
}
+void ImfManager::SetDefaultOptions()
+{
+ DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::SetDefaultOptions\n" );
+ Property::Map map;
+ map.Insert( "PANEL_LAYOUT", InputMethod::PanelLayout::NORMAL );
+ map.Insert( "AUTO_CAPITALISE", InputMethod::AutoCapital::SENTENCE );
+ map.Insert( "ACTION_BUTTON", InputMethod::ActionButtonTitle::DEFAULT );
+ map.Insert( "VARIATION", InputMethod::NormalLayout::NORMAL );
+ mOptions.ApplyProperty( map );
+}
+
// Callbacks for predicitive text support.
void ImfManager::ConnectCallbacks()
{
{
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_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_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_PRIVATE_COMMAND_SEND, PrivateCommand, this );
ecore_imf_context_input_panel_event_callback_add( mIMFContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, InputPanelStateChangeCallback, this );
ecore_imf_context_input_panel_event_callback_add( mIMFContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, InputPanelLanguageChangeCallback, this );
ecore_imf_context_input_panel_event_callback_add( mIMFContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, InputPanelGeometryChangedCallback, this );
+ ecore_imf_context_input_panel_event_callback_add( mIMFContext, ECORE_IMF_INPUT_PANEL_KEYBOARD_MODE_EVENT, InputPanelKeyboardTypeChangedCallback, this );
ecore_imf_context_retrieve_surrounding_callback_set( mIMFContext, ImfRetrieveSurrounding, this);
}
{
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 );
+ 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 );
+ ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_PRIVATE_COMMAND_SEND, PrivateCommand );
ecore_imf_context_input_panel_event_callback_del( mIMFContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, InputPanelStateChangeCallback );
ecore_imf_context_input_panel_event_callback_del( mIMFContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, InputPanelLanguageChangeCallback );
ecore_imf_context_input_panel_event_callback_del( mIMFContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, InputPanelGeometryChangedCallback );
+ ecore_imf_context_input_panel_event_callback_del( mIMFContext, ECORE_IMF_INPUT_PANEL_KEYBOARD_MODE_EVENT, InputPanelKeyboardTypeChangedCallback );
// We do not need to unset the retrieve surrounding callback.
}
Reset();
ecore_imf_context_focus_out( mIMFContext );
- ecore_imf_context_input_panel_hide( mIMFContext );
}
// Reset mIdleCallbackConnected
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 )
{
- *text = strdup( mSurroundingText.c_str() );
- }
+ if( text )
+ {
+ // The memory allocated by strdup() can be freed by ecore_imf_context_surrounding_get() internally.
+ *text = strdup( callbackData.currentText.c_str() );
+ }
- if( cursorPosition )
- {
- *cursorPosition = mIMFCursorPosition;
+ if( cursorPosition )
+ {
+ mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
+ *cursorPosition = mIMFCursorPosition;
+ }
}
return EINA_TRUE;
}
}
+/**
+ * Called when the input method sends a private command.
+ */
+void ImfManager::SendPrivateCommand( void* data, Ecore_IMF_Context* imfContext, void* event_info )
+{
+ DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::SendPrivateCommand\n" );
+
+ if( Dali::Adaptor::IsAvailable() )
+ {
+ const char* privateCommandSendEvent = static_cast<const char*>( event_info );
+
+ Dali::ImfManager::ImfEventData imfData( Dali::ImfManager::PRIVATECOMMAND, privateCommandSendEvent, 0, 0 );
+ Dali::ImfManager handle( this );
+ mEventSignal.Emit( handle, imfData );
+ }
+}
+
void ImfManager::NotifyCursorPosition()
{
DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::NotifyCursorPosition\n" );
void ImfManager::NotifyTextInputMultiLine( bool multiLine )
{
Ecore_IMF_Input_Hints currentHint = ecore_imf_context_input_hint_get(mIMFContext);
- ecore_imf_context_input_hint_set(mIMFContext, (Ecore_IMF_Input_Hints)(multiLine ?
- (currentHint | ECORE_IMF_INPUT_HINT_MULTILINE) :
- (currentHint & ~ECORE_IMF_INPUT_HINT_MULTILINE)));
+ ecore_imf_context_input_hint_set( mIMFContext,
+ static_cast< Ecore_IMF_Input_Hints >( multiLine ?
+ (currentHint | ECORE_IMF_INPUT_HINT_MULTILINE) :
+ (currentHint & ~ECORE_IMF_INPUT_HINT_MULTILINE)));
}
Dali::ImfManager::TextDirection ImfManager::GetTextDirection()
if ( locale )
{
- direction = Locale::GetTextDirection( std::string( locale ) );
+ direction = static_cast< Dali::ImfManager::TextDirection >( Locale::GetDirection( std::string( locale ) ) );
free( locale );
}
}
void ImfManager::ApplyOptions( const InputMethodOptions& options )
{
using namespace Dali::InputMethod::Category;
-
int index;
if (mIMFContext == NULL)
}
}
+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()
+{
+ DALI_LOG_INFO( gLogFilter, Debug::General, "ImfManager::GetKeyboardType\n" );
+
+#ifdef OVER_TIZEN_VERSION_4
+ if( mIMFContext )
+ {
+ int value;
+ value = ecore_imf_context_keyboard_mode_get( mIMFContext );
+
+ switch (value)
+ {
+ case ECORE_IMF_INPUT_PANEL_SW_KEYBOARD_MODE:
+ {
+ return Dali::ImfManager::SOFTWARE_KEYBOARD;
+ break;
+ }
+ case ECORE_IMF_INPUT_PANEL_HW_KEYBOARD_MODE:
+ {
+ return Dali::ImfManager::HARDWARE_KEYBOARD;
+ break;
+ }
+ }
+ }
+#endif // OVER_TIZEN_VERSION_4
+ 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