diff options
author | Matthew J. Francis <mjay.francis@gmail.com> | 2015-10-03 04:31:48 +0800 |
---|---|---|
committer | Matthew Francis <mjay.francis@gmail.com> | 2015-10-16 12:03:30 +0000 |
commit | 59c38539bcabf3a5c949745ff8f501ed7c98a528 (patch) | |
tree | f53668f6e0f0554171718b3491b8ff0183598a21 /toolkit | |
parent | fa2a7665194c7fff311d14932ee7930f80e6c7e2 (diff) |
Allow injection of keyboard and mouse events through UNO
Change-Id: I3d139c6378f5274be1e7bfd88f72d1576c13243d
Reviewed-on: https://gerrit.libreoffice.org/19321
Reviewed-by: Matthew Francis <mjay.francis@gmail.com>
Tested-by: Matthew Francis <mjay.francis@gmail.com>
Diffstat (limited to 'toolkit')
-rw-r--r-- | toolkit/source/awt/vclxtoolkit.cxx | 99 | ||||
-rw-r--r-- | toolkit/source/helper/vclunohelper.cxx | 20 |
2 files changed, 119 insertions, 0 deletions
diff --git a/toolkit/source/awt/vclxtoolkit.cxx b/toolkit/source/awt/vclxtoolkit.cxx index 31ed8c409efd..f97be03731bc 100644 --- a/toolkit/source/awt/vclxtoolkit.cxx +++ b/toolkit/source/awt/vclxtoolkit.cxx @@ -42,6 +42,7 @@ #include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/awt/XToolkitExperimental.hpp> +#include <com/sun/star/awt/XToolkitRobot.hpp> #include <com/sun/star/awt/XMessageBoxFactory.hpp> #include <cppuhelper/bootstrap.hxx> @@ -149,6 +150,7 @@ protected: class VCLXToolkit : public VCLXToolkitMutexHelper, public cppu::WeakComponentImplHelper< css::awt::XToolkitExperimental, + css::awt::XToolkitRobot, css::lang::XServiceInfo > { css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxClipboard; @@ -277,6 +279,23 @@ public: // css::awt::XReschedule: virtual void SAL_CALL reschedule() throw (css::uno::RuntimeException, std::exception) override; + + // css:awt:XToolkitRobot + virtual void SAL_CALL keyPress( const css::awt::KeyEvent & aKeyEvent ) + throw (css::uno::RuntimeException, std::exception) override; + + virtual void SAL_CALL keyRelease( const css::awt::KeyEvent & aKeyEvent ) + throw (css::uno::RuntimeException, std::exception) override; + + virtual void SAL_CALL mousePress( const css::awt::MouseEvent & aMouseEvent ) + throw (css::uno::RuntimeException, std::exception) override; + + virtual void SAL_CALL mouseRelease( const css::awt::MouseEvent & aMouseEvent ) + throw (css::uno::RuntimeException, std::exception) override; + + virtual void SAL_CALL mouseMove( const css::awt::MouseEvent & aMouseEvent ) + throw (css::uno::RuntimeException, std::exception) override; + }; WinBits ImplGetWinBits( sal_uInt32 nComponentAttribs, sal_uInt16 nCompType ) @@ -650,6 +669,7 @@ static void SAL_CALL ToolkitWorkerFunction( void* pArgs ) VCLXToolkit::VCLXToolkit(): cppu::WeakComponentImplHelper< ::com::sun::star::awt::XToolkitExperimental, + ::com::sun::star::awt::XToolkitRobot, ::com::sun::star::lang::XServiceInfo>( GetMutex() ), m_aTopWindowListeners(rBHelper.rMutex), m_aKeyHandlers(rBHelper.rMutex), @@ -1896,6 +1916,85 @@ void SAL_CALL VCLXToolkit::processEventsToIdle() Scheduler::ProcessTaskScheduling(false); } +// css:awt:XToolkitRobot + +void SAL_CALL VCLXToolkit::keyPress( const css::awt::KeyEvent & aKeyEvent ) + throw (css::uno::RuntimeException, std::exception) +{ + css::uno::Reference<css::awt::XWindow> xWindow ( aKeyEvent.Source, css::uno::UNO_QUERY ); + if( !xWindow.is() ) + throw css::uno::RuntimeException( "invalid event source" ); + + vcl::Window * pWindow = VCLUnoHelper::GetWindow( xWindow ); + if( !pWindow ) + throw css::uno::RuntimeException( "invalid event source" ); + + ::KeyEvent aVCLKeyEvent = VCLUnoHelper::createVCLKeyEvent( aKeyEvent ); + ::Application::PostKeyEvent( VCLEVENT_WINDOW_KEYINPUT, pWindow, &aVCLKeyEvent ); +} + +void SAL_CALL VCLXToolkit::keyRelease( const css::awt::KeyEvent & aKeyEvent ) + throw (css::uno::RuntimeException, std::exception) +{ + css::uno::Reference<css::awt::XWindow> xWindow ( aKeyEvent.Source, css::uno::UNO_QUERY ); + if( !xWindow.is() ) + throw css::uno::RuntimeException( "invalid event source" ); + + vcl::Window * pWindow = VCLUnoHelper::GetWindow( xWindow ); + if( !pWindow ) + throw css::uno::RuntimeException( "invalid event source" ); + + ::KeyEvent aVCLKeyEvent = VCLUnoHelper::createVCLKeyEvent( aKeyEvent ); + ::Application::PostKeyEvent( VCLEVENT_WINDOW_KEYUP, pWindow, &aVCLKeyEvent ); +} + + +void SAL_CALL VCLXToolkit::mousePress( const css::awt::MouseEvent & aMouseEvent ) + throw (css::uno::RuntimeException, std::exception) +{ + css::uno::Reference<css::awt::XWindow> xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY ); + if( !xWindow.is() ) + throw css::uno::RuntimeException( "invalid event source" ); + + vcl::Window * pWindow = VCLUnoHelper::GetWindow( xWindow ); + if( !pWindow ) + throw css::uno::RuntimeException( "invalid event source" ); + + ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent ); + ::Application::PostMouseEvent( VCLEVENT_WINDOW_MOUSEBUTTONDOWN, pWindow, &aVCLMouseEvent ); +} + +void SAL_CALL VCLXToolkit::mouseRelease( const css::awt::MouseEvent & aMouseEvent ) + throw (css::uno::RuntimeException, std::exception) +{ + css::uno::Reference<css::awt::XWindow> xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY ); + if( !xWindow.is() ) + throw css::uno::RuntimeException( "invalid event source" ); + + vcl::Window * pWindow = VCLUnoHelper::GetWindow( xWindow ); + if( !pWindow ) + throw css::uno::RuntimeException( "invalid event source" ); + + ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent ); + ::Application::PostMouseEvent( VCLEVENT_WINDOW_MOUSEBUTTONUP, pWindow, &aVCLMouseEvent ); +} + +void SAL_CALL VCLXToolkit::mouseMove( const css::awt::MouseEvent & aMouseEvent ) + throw (css::uno::RuntimeException, std::exception) +{ + css::uno::Reference<css::awt::XWindow> xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY ); + if( !xWindow.is() ) + throw css::uno::RuntimeException( "invalid event source" ); + + vcl::Window * pWindow = VCLUnoHelper::GetWindow( xWindow ); + if( !pWindow ) + throw css::uno::RuntimeException( "invalid event source" ); + + ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent ); + ::Application::PostMouseEvent( VCLEVENT_WINDOW_MOUSEMOVE, pWindow, &aVCLMouseEvent ); +} + + } extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL diff --git a/toolkit/source/helper/vclunohelper.cxx b/toolkit/source/helper/vclunohelper.cxx index 1cc223a59e66..57d398158858 100644 --- a/toolkit/source/helper/vclunohelper.cxx +++ b/toolkit/source/helper/vclunohelper.cxx @@ -736,6 +736,14 @@ awt::MouseEvent VCLUnoHelper::createMouseEvent( const ::MouseEvent& _rVclEvent, return aMouseEvent; } +::MouseEvent VCLUnoHelper::createVCLMouseEvent( const awt::MouseEvent& _rAwtEvent ) +{ + ::MouseEvent aMouseEvent( Point( _rAwtEvent.X, _rAwtEvent.Y ), _rAwtEvent.ClickCount, + ::MouseEventModifiers::NONE, _rAwtEvent.Buttons, _rAwtEvent.Modifiers ); + + return aMouseEvent; +} + awt::KeyEvent VCLUnoHelper::createKeyEvent( const ::KeyEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext ) { awt::KeyEvent aKeyEvent; @@ -758,4 +766,16 @@ awt::KeyEvent VCLUnoHelper::createKeyEvent( const ::KeyEvent& _rVclEvent, const return aKeyEvent; } +::KeyEvent VCLUnoHelper::createVCLKeyEvent( const awt::KeyEvent& _rAwtEvent ) +{ + sal_Unicode nChar = _rAwtEvent.KeyChar; + vcl::KeyCode aKeyCode( _rAwtEvent.KeyCode, _rAwtEvent.Modifiers & awt::KeyModifier::SHIFT, + _rAwtEvent.Modifiers & awt::KeyModifier::MOD1, + _rAwtEvent.Modifiers & awt::KeyModifier::MOD2, + _rAwtEvent.Modifiers & awt::KeyModifier::MOD3 ); + + return ::KeyEvent (nChar, aKeyCode); + +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |