InputMethodContext InputMethodContext::New()
{
- Internal::Adaptor::InputMethodContextPtr inputMethodContext = Internal::Adaptor::InputMethodContext::New();
+ return InputMethodContext::New( Actor() );
+}
+
+InputMethodContext InputMethodContext::New( Actor actor )
+{
+ Internal::Adaptor::InputMethodContextPtr inputMethodContext = Internal::Adaptor::InputMethodContext::New( actor );
if( inputMethodContext )
{
}
}
+class Actor;
+
/**
* @brief The InputMethodContext class
*
static InputMethodContext New();
/**
+ * @brief Create a new instance of an InputMethodContext.
+ *
+ * @param[in] actor The actor that uses the new InputMethodContext instance.
+ */
+ static InputMethodContext New( Actor actor );
+
+ /**
* @brief Copy constructor.
*
* @param[in] inputMethodContext InputMethodContext to copy. The copied inputMethodContext will point at the same implementation.
Any GetNativeWindowHandle();
/**
+ * @brief Retrieve native window handle that the given actor is added to.
+ *
+ * @param[in] actor The actor
+ * @return native window handle
+ */
+ Any GetNativeWindowHandle( Actor actor );
+
+ /**
* @brief Get the native display associated with the graphics backend
*
* @return A handle to the native display
mAdaptor->ProcessCoreEvents();
}
+Dali::Integration::SceneHolder SceneHolder::Get( Dali::Actor actor )
+{
+ SceneHolder* sceneHolderImpl = nullptr;
+
+ if ( Internal::Adaptor::Adaptor::IsAvailable() )
+ {
+ Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation( Internal::Adaptor::Adaptor::Get() );
+ sceneHolderImpl = adaptor.GetWindow( actor );
+ }
+
+ return Dali::Integration::SceneHolder( sceneHolderImpl );
+}
+
void SceneHolder::Reset()
{
mCombiner.Reset();
*/
void FeedKeyEvent( Dali::Integration::KeyEvent& keyEvent );
+ /**
+ * @copydoc Dali::Integration::SceneHolder::Get()
+ */
+ static Dali::Integration::SceneHolder Get( Dali::Actor actor );
+
public: // The following methods can be overridden if required
/**
return GetImplementation(*this).GetBackgroundColor();
}
+Any SceneHolder::GetNativeHandle() const
+{
+ return GetImplementation(*this).GetNativeHandle();
+}
+
void SceneHolder::FeedTouchPoint( Dali::TouchPoint& point, int timeStamp )
{
Integration::Point convertedPoint( point );
GetImplementation(*this).FeedKeyEvent( convertedEvent );
}
+SceneHolder SceneHolder::Get( Actor actor )
+{
+ return Internal::Adaptor::SceneHolder::Get( actor );
+}
+
}// Integration
} // Dali
*/
void FeedKeyEvent( Dali::KeyEvent& keyEvent );
+ /**
+ * @brief Retrieve the SceneHolder that the given actor is added to.
+ *
+ * @param[in] actor The actor
+ * @return The SceneHolder the actor is added to or an empty handle if the actor is not added to any SceneHolder.
+ */
+ static SceneHolder Get( Actor actor );
+
public: // Not intended for application developers
/**
return mWindows.front()->GetNativeHandle();
}
+Any Adaptor::GetNativeWindowHandle( Dali::Actor actor )
+{
+ Any nativeWindowHandle;
+
+ Dali::Integration::Scene scene = Dali::Integration::Scene::Get( actor );
+
+ for( auto sceneHolder : mWindows )
+ {
+ if ( scene == sceneHolder->GetScene() )
+ {
+ nativeWindowHandle = sceneHolder->GetNativeHandle();
+ break;
+ }
+ }
+
+ return nativeWindowHandle;
+}
+
Any Adaptor::GetGraphicsDisplay()
{
Any display;
Any GetNativeWindowHandle();
/**
+ * @brief Retrieve native window handle that the given actor is added to.
+ *
+ * @param[in] actor The actor
+ * @return native window handle
+ */
+ Any GetNativeWindowHandle( Dali::Actor actor );
+
+ /**
* Get the native display associated with the graphics backend
*
* @return A handle to the native display
return mImpl->GetNativeWindowHandle();
}
+Any Adaptor::GetNativeWindowHandle( Actor actor )
+{
+ return mImpl->GetNativeWindowHandle( actor );
+}
+
Any Adaptor::GetGraphicsDisplay()
{
return mImpl->GetGraphicsDisplay();
// Factory function creating new InputMethodContext
// Symbol exists but may be overriden during linking
-InputMethodContextPtr CreateInputMethodContext();
+InputMethodContextPtr CreateInputMethodContext( Dali::Actor actor );
}
}
namespace Adaptor
{
-InputMethodContextPtr InputMethodContext::New()
+InputMethodContextPtr InputMethodContext::New( Dali::Actor actor )
{
- return Dali::Internal::Adaptor::InputMethodContextFactory::CreateInputMethodContext();
+ return Dali::Internal::Adaptor::InputMethodContextFactory::CreateInputMethodContext( actor );
}
const std::string& InputMethodContext::GetSurroundingText() const
*/
// EXTERNAL INCLUDES
+#include <dali/public-api/actors/actor.h>
#include <dali/public-api/common/vector-wrapper.h>
#include <dali/public-api/object/base-object.h>
#include <dali/integration-api/events/key-event-integ.h>
/**
* Create a new input method context instance.
*/
- static InputMethodContextPtr New();
+ static InputMethodContextPtr New( Dali::Actor actor );
/**
* Initialize the object.
{
// InputMethodContext Factory to be implemented by the platform
-InputMethodContextPtr CreateInputMethodContext()
+InputMethodContextPtr CreateInputMethodContext( Dali::Actor actor )
{
- return Dali::Internal::Adaptor::InputMethodContextEcoreWl::New();
+ return Dali::Internal::Adaptor::InputMethodContextEcoreWl::New( actor );
}
}
// INTERNAL INCLUDES
#include <dali/integration-api/adaptor.h>
+#include <dali/integration-api/scene-holder.h>
#include <dali/internal/system/common/locale-utils.h>
#include <dali/internal/system/common/singleton-service-impl.h>
#include <dali/public-api/adaptor-framework/input-method.h>
Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_INPUT_METHOD_CONTEXT");
#endif
+const int kUninitializedWindowId = 0;
+
// 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)
{
}
}
+int GetWindowIdFromActor( Dali::Actor actor )
+{
+ int windowId = kUninitializedWindowId;
+
+ if( actor.OnStage() )
+ {
+ Any nativeWindowHandle = Dali::Integration::SceneHolder::Get( actor ).GetNativeHandle();
+
+#ifdef ECORE_WAYLAND2
+ windowId = ecore_wl2_window_id_get( AnyCast< Ecore_Wl2_Window* >( nativeWindowHandle ) );
+#else
+ windowId = ecore_wl_window_id_get( AnyCast< Ecore_Wl_Window* >( nativeWindowHandle ) );
+#endif
+ }
+
+ return windowId;
+}
+
BaseHandle Create()
{
- return Dali::InputMethodContext::New();
+ return Dali::InputMethodContext::New( Dali::Actor() );
}
Dali::TypeRegistration type( typeid(Dali::InputMethodContext), typeid(Dali::BaseHandle), Create );
} // unnamed namespace
-InputMethodContextPtr InputMethodContextEcoreWl::New()
+InputMethodContextPtr InputMethodContextEcoreWl::New( Dali::Actor actor )
{
InputMethodContextPtr inputMethodContext;
- // Create instance only if the adaptor is available
- if ( Dali::Adaptor::IsAvailable() )
+ // Create instance only if the adaptor is available and the valid actor exists
+ if ( actor && Dali::Adaptor::IsAvailable() )
{
- Any nativeWindow = Dali::Adaptor::Get().GetNativeWindowHandle();
-
- // The window needs to use the InputMethodContext.
- if( !nativeWindow.Empty() )
- {
- inputMethodContext = new InputMethodContextEcoreWl();
- }
- else
- {
- DALI_LOG_ERROR("Failed to get native window handle, can't create InputMethodContext instance.\n");
- }
+ inputMethodContext = new InputMethodContextEcoreWl( actor );
}
return inputMethodContext;
}
DeleteContext();
}
-InputMethodContextEcoreWl::InputMethodContextEcoreWl()
+InputMethodContextEcoreWl::InputMethodContextEcoreWl( Dali::Actor actor )
: mIMFContext(),
mIMFCursorPosition( 0 ),
mSurroundingText(),
mRestoreAfterFocusLost( false ),
- mIdleCallbackConnected( false )
+ mIdleCallbackConnected( false ),
+ mWindowId( GetWindowIdFromActor( actor ) )
{
ecore_imf_init();
+
+ actor.OnStageSignal().Connect( this, &InputMethodContextEcoreWl::OnStaged );
}
InputMethodContextEcoreWl::~InputMethodContextEcoreWl()
{
DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext::CreateContext\n" );
+ if( mWindowId == kUninitializedWindowId )
+ {
+ return;
+ }
+
const char *contextId = ecore_imf_context_default_id_get();
if( contextId )
{
if( mIMFContext )
{
- // If we fail to get window id, we can't use the InputMethodContext correctly.
- // Thus you have to call "ecore_imf_context_client_window_set" somewhere.
-
- Any nativeWindowHandle = Dali::Adaptor::Get().GetNativeWindowHandle();
-
-#ifdef ECORE_WAYLAND2
- int windowId = ecore_wl2_window_id_get( AnyCast< Ecore_Wl2_Window* >( nativeWindowHandle ) );
-#else
- int windowId = ecore_wl_window_id_get( AnyCast< Ecore_Wl_Window* >( nativeWindowHandle ) );
-#endif
-
- if( windowId != 0 )
- {
- ecore_imf_context_client_window_set( mIMFContext, reinterpret_cast< void* >( windowId ) );
- }
+ ecore_imf_context_client_window_set( mIMFContext, reinterpret_cast< void* >( mWindowId ) );
}
else
{
- DALI_LOG_WARNING("InputMethodContext Unable to get IMFContext\n");
+ DALI_LOG_WARNING( "InputMethodContext Unable to get IMFContext\n" );
}
}
else
{
- DALI_LOG_WARNING("InputMethodContext Unable to get IMFContext\n");
+ DALI_LOG_WARNING( "InputMethodContext Unable to get IMFContext\n" );
}
}
void InputMethodContextEcoreWl::NotifyTextInputMultiLine( bool multiLine )
{
- Ecore_IMF_Input_Hints currentHint = ecore_imf_context_input_hint_get(mIMFContext);
- 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)));
+ if( mIMFContext )
+ {
+ Ecore_IMF_Input_Hints currentHint = ecore_imf_context_input_hint_get(mIMFContext);
+ 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::InputMethodContext::TextDirection InputMethodContextEcoreWl::GetTextDirection()
return static_cast<Ecore_IMF_Keyboard_Locks>( lock );
}
+void InputMethodContextEcoreWl::OnStaged( Dali::Actor actor )
+{
+ int windowId = GetWindowIdFromActor( actor );
+
+ if( mWindowId != windowId )
+ {
+ mWindowId = windowId;
+
+ // Reset
+ Finalize();
+ Initialize();
+ }
+}
+
} // Adaptor
} // Internal
namespace Adaptor
{
-class InputMethodContextEcoreWl : public Dali::Internal::Adaptor::InputMethodContext
+class InputMethodContextEcoreWl : public Dali::Internal::Adaptor::InputMethodContext, public Dali::ConnectionTracker
{
public:
/**
* @brief Creates a new InputMethodContext handle
*
+ * @param[in] actor The actor that uses the new InputMethodContext instance.
* @return InputMethodContext pointer
*/
- static InputMethodContextPtr New();
+ static InputMethodContextPtr New( Dali::Actor actor );
/**
* @brief Initializes member data.
*/
Ecore_IMF_Keyboard_Locks EcoreInputModifierToEcoreIMFLock( unsigned int modifier );
+ /**
+ * Called when the binded actor is added to a window.
+ */
+ void OnStaged( Dali::Actor actor );
+
private:
/**
* @brief Constructor.
*/
- explicit InputMethodContextEcoreWl();
+ explicit InputMethodContextEcoreWl( Dali::Actor actor );
protected:
/**
bool mIdleCallbackConnected:1; ///< Whether the idle callback is already connected.
std::vector<Dali::Integration::KeyEvent> mKeyEvents; ///< Stores key events to be sent from idle call-back.
- InputMethodOptions mOptions;
+ InputMethodOptions mOptions;
+
+ int mWindowId;
};
{
// InputMethodContext Factory to be implemented by the platform
-InputMethodContextPtr CreateInputMethodContext()
+InputMethodContextPtr CreateInputMethodContext( Dali::Actor actor )
{
- return Dali::Internal::Adaptor::InputMethodContextX::New();
+ return Dali::Internal::Adaptor::InputMethodContextX::New( actor );
}
}
} // unnamed namespace
-InputMethodContextPtr InputMethodContextX::New()
+InputMethodContextPtr InputMethodContextX::New( Dali::Actor actor )
{
InputMethodContextPtr manager;
- if ( Adaptor::IsAvailable() )
+ if( actor && Dali::Adaptor::IsAvailable() )
{
- // Create instance and register singleton only if the adaptor is available
- Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
- Any nativeWindow = adaptorImpl.GetNativeWindowHandle();
-
- // The Ecore_X_Window needs to use the InputMethodContext.
- // Only when the render surface is window, we can get the Ecore_X_Window.
- Ecore_X_Window ecoreXwin( AnyCast<Ecore_X_Window>(nativeWindow) );
- if (ecoreXwin)
- {
- // If we fail to get Ecore_X_Window, we can't use the InputMethodContext correctly.
- // Thus you have to call "ecore_imf_context_client_window_set" somewhere.
- // In EvasPlugIn, this function is called in EvasPlugin::ConnectEcoreEvent().
-
- manager = new InputMethodContextX( ecoreXwin );
- }
- else
- {
- DALI_LOG_ERROR("Failed to get native window handle\n");
- }
+ manager = new InputMethodContextX( actor );
}
return manager;
DeleteContext();
}
-InputMethodContextX::InputMethodContextX( Ecore_X_Window ecoreXwin )
+InputMethodContextX::InputMethodContextX( Dali::Actor actor )
: mIMFContext(),
- mEcoreXwin( ecoreXwin ),
+ mEcoreXwin( 0 ),
mIMFCursorPosition( 0 ),
mSurroundingText(),
mRestoreAfterFocusLost( false ),
mIdleCallbackConnected( false )
{
ecore_imf_init();
+
+ actor.OnStageSignal().Connect( this, &InputMethodContextX::OnStaged );
}
InputMethodContextX::~InputMethodContextX()
void InputMethodContextX::Initialize()
{
- CreateContext( mEcoreXwin );
+ CreateContext();
ConnectCallbacks();
VirtualKeyboard::ConnectCallbacks( mIMFContext );
}
-void InputMethodContextX::CreateContext( Ecore_X_Window ecoreXwin )
+void InputMethodContextX::CreateContext()
{
DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextX::CreateContext\n" );
+ if( !mEcoreXwin )
+ {
+ return;
+ }
+
const char *contextId = ecore_imf_context_default_id_get();
if( contextId )
{
if( mIMFContext )
{
- if( ecoreXwin )
- {
- ecore_imf_context_client_window_set( mIMFContext, reinterpret_cast<void*>( ecoreXwin ) );
- }
+ ecore_imf_context_client_window_set( mIMFContext, reinterpret_cast<void*>( mEcoreXwin ) );
}
else
{
return static_cast<Ecore_IMF_Keyboard_Locks>( lock );
}
+void InputMethodContextX::OnStaged( Dali::Actor actor )
+{
+ Ecore_X_Window ecoreXwin( AnyCast< Ecore_X_Window >( Dali::Integration::SceneHolder::Get( actor ).GetNativeHandle() ) );
+
+ if( mEcoreXwin != ecoreXwin )
+ {
+ mEcoreXwin = ecoreXwin;
+
+ // Reset
+ Finalize();
+ Initialize();
+ }
+}
+
} // Adaptor
} // Internal
namespace Adaptor
{
-class InputMethodContextX : public Dali::Internal::Adaptor::InputMethodContext
+class InputMethodContextX : public Dali::Internal::Adaptor::InputMethodContext, public Dali::ConnectionTracker
{
public:
/**
* @brief Creates a new InputMethodContext handle
*
+ * @param[in] actor The actor that uses the new InputMethodContext instance.
* @return InputMethodContext pointer
*/
- static InputMethodContextPtr New();
+ static InputMethodContextPtr New( Dali::Actor actor );
/**
* Constructor
- * @param[in] ecoreXwin, The window is created by application.
+ * @param[in] actor The actor that uses the new InputMethodContext instance.
*/
- explicit InputMethodContextX( Ecore_X_Window ecoreXwin );
+ explicit InputMethodContextX( Dali::Actor actor );
public:
private:
/**
* Context created the first time and kept until deleted.
- * @param[in] ecoreXwin, The window is created by application.
*/
- void CreateContext( Ecore_X_Window ecoreXwin );
+ void CreateContext();
/**
* @copydoc Dali::InputMethodContext::DeleteContext()
*/
Ecore_IMF_Keyboard_Locks EcoreInputModifierToEcoreIMFLock( unsigned int modifier );
+ /**
+ * Called when the binded actor is added to a window.
+ */
+ void OnStaged( Dali::Actor actor );
+
public:
/**
{
// InputMethodContext Factory to be implemented by the platform
-InputMethodContextPtr CreateInputMethodContext()
+InputMethodContextPtr CreateInputMethodContext( Dali::Actor actor )
{
- return Dali::Internal::Adaptor::InputMethodContextWin::New();
+ return Dali::Internal::Adaptor::InputMethodContextWin::New( actor );
}
}
namespace Adaptor\r
{\r
\r
-InputMethodContextPtr InputMethodContextWin::New()\r
+InputMethodContextPtr InputMethodContextWin::New( Dali::Actor actor )\r
{\r
InputMethodContextPtr manager;\r
\r
- if ( Adaptor::IsAvailable() )\r
+ if ( actor && Adaptor::IsAvailable() )\r
{\r
- // Create instance and register singleton only if the adaptor is available\r
- Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );\r
- Any nativeWindow = adaptorImpl.GetNativeWindowHandle();\r
-\r
- // The Win_Window_Handle needs to use the InputMethodContext.\r
- // Only when the render surface is window, we can get the Win_Window_Handle.\r
- WinWindowHandle winWindow( AnyCast<WinWindowHandle>(nativeWindow) );\r
- if ( winWindow )\r
- {\r
- manager = new InputMethodContextWin( winWindow );\r
- }\r
- else\r
- {\r
- DALI_LOG_ERROR("Failed to get native window handle\n");\r
- }\r
+ manager = new InputMethodContextWin( actor );\r
}\r
\r
return manager;\r
{\r
}\r
\r
-InputMethodContextWin::InputMethodContextWin( WinWindowHandle winWindow )\r
-: mWin32Window( winWindow ),\r
+InputMethodContextWin::InputMethodContextWin( Dali::Actor actor )\r
+: mWin32Window( 0 ),\r
mIMFCursorPosition( 0 ),\r
mSurroundingText(),\r
mRestoreAfterFocusLost( false ),\r
mIdleCallbackConnected( false )\r
{\r
+\r
+ actor.OnStageSignal().Connect( this, &InputMethodContextWin::OnStaged );\r
}\r
\r
InputMethodContextWin::~InputMethodContextWin()\r
return eventHandled;\r
}\r
\r
+void InputMethodContextWin::OnStaged( Dali::Actor actor )\r
+{\r
+ WinWindowHandle winWindow( AnyCast< WinWindowHandle >( Dali::Integration::SceneHolder::Get( actor ).GetNativeHandle() ) );\r
+\r
+ if( mWin32Window != winWindow )\r
+ {\r
+ mWin32Window = winWindow;\r
+\r
+ // Reset\r
+ Finalize();\r
+ Initialize();\r
+ }\r
+}\r
+\r
} // Adaptor\r
\r
} // Internal\r
namespace Adaptor\r
{\r
\r
-class InputMethodContextWin : public Dali::Internal::Adaptor::InputMethodContext\r
+class InputMethodContextWin : public Dali::Internal::Adaptor::InputMethodContext, public Dali::ConnectionTracker\r
{\r
public:\r
/**\r
* @brief Creates a new InputMethodContext handle\r
*\r
+ * @param[in] actor The actor that uses the new InputMethodContext instance.\r
* @return InputMethodContext pointer\r
*/\r
- static InputMethodContextPtr New();\r
+ static InputMethodContextPtr New( Dali::Actor actor );\r
\r
/**\r
* Constructor\r
* @param[in] win32Window, The window is created by application.\r
*/\r
- explicit InputMethodContextWin( WinWindowHandle win32Window );\r
+ explicit InputMethodContextWin( Dali::Actor actor );\r
\r
public:\r
\r
*/\r
bool ProcessEventKeyUp( const KeyEvent& keyEvent );\r
\r
+ /**\r
+ * Called when the binded actor is added to a window.\r
+ */\r
+ void OnStaged( Dali::Actor actor );\r
+\r
public:\r
\r
/**\r
return Dali::Window( windowImpl );
}
-
void Window::SetParent( Dali::Window& parent )
{
if ( DALI_UNLIKELY( parent ) )