Kaydet (Commit) 59c38539 authored tarafından Matthew J. Francis's avatar Matthew J. Francis Kaydeden (comit) Matthew Francis

Allow injection of keyboard and mouse events through UNO

Change-Id: I3d139c6378f5274be1e7bfd88f72d1576c13243d
Reviewed-on: https://gerrit.libreoffice.org/19321Reviewed-by: 's avatarMatthew Francis <mjay.francis@gmail.com>
Tested-by: 's avatarMatthew Francis <mjay.francis@gmail.com>
üst fa2a7665
...@@ -145,11 +145,15 @@ public: ...@@ -145,11 +145,15 @@ public:
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext
); );
static ::MouseEvent createVCLMouseEvent( const ::com::sun::star::awt::MouseEvent& _rAwtEvent );
static ::com::sun::star::awt::KeyEvent static ::com::sun::star::awt::KeyEvent
createKeyEvent( createKeyEvent(
const ::KeyEvent& _rVclEvent, const ::KeyEvent& _rVclEvent,
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext
); );
static ::KeyEvent createVCLKeyEvent( const ::com::sun::star::awt::KeyEvent& _rAwtEvent );
}; };
......
...@@ -1889,6 +1889,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/awt,\ ...@@ -1889,6 +1889,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/awt,\
XToolkit \ XToolkit \
XToolkit2 \ XToolkit2 \
XToolkitExperimental \ XToolkitExperimental \
XToolkitRobot \
XTopWindow \ XTopWindow \
XTopWindow2 \ XTopWindow2 \
XTopWindowListener \ XTopWindowListener \
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef __com_sun_star_awt_XToolkitRobot_idl__
#define __com_sun_star_awt_XToolkitRobot_idl__
#include <com/sun/star/awt/KeyEvent.idl>
#include <com/sun/star/awt/XTopWindow.idl>
module com { module sun { module star { module awt {
/** Allows injection of keyboard and mouse events
*/
interface XToolkitRobot
{
void keyPress( [in] com::sun::star::awt::KeyEvent aKeyEvent );
void keyRelease( [in] com::sun::star::awt::KeyEvent aKeyEvent );
void mousePress( [in] com::sun::star::awt::MouseEvent aMouseEvent );
void mouseRelease( [in] com::sun::star::awt::MouseEvent aMouseEvent );
void mouseMove( [in] com::sun::star::awt::MouseEvent aMouseEvent );
};
}; }; }; };
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp> #include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/awt/XToolkitExperimental.hpp> #include <com/sun/star/awt/XToolkitExperimental.hpp>
#include <com/sun/star/awt/XToolkitRobot.hpp>
#include <com/sun/star/awt/XMessageBoxFactory.hpp> #include <com/sun/star/awt/XMessageBoxFactory.hpp>
#include <cppuhelper/bootstrap.hxx> #include <cppuhelper/bootstrap.hxx>
...@@ -149,6 +150,7 @@ protected: ...@@ -149,6 +150,7 @@ protected:
class VCLXToolkit : public VCLXToolkitMutexHelper, class VCLXToolkit : public VCLXToolkitMutexHelper,
public cppu::WeakComponentImplHelper< public cppu::WeakComponentImplHelper<
css::awt::XToolkitExperimental, css::awt::XToolkitExperimental,
css::awt::XToolkitRobot,
css::lang::XServiceInfo > css::lang::XServiceInfo >
{ {
css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxClipboard; css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxClipboard;
...@@ -277,6 +279,23 @@ public: ...@@ -277,6 +279,23 @@ public:
// css::awt::XReschedule: // css::awt::XReschedule:
virtual void SAL_CALL reschedule() virtual void SAL_CALL reschedule()
throw (css::uno::RuntimeException, std::exception) override; 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 ) WinBits ImplGetWinBits( sal_uInt32 nComponentAttribs, sal_uInt16 nCompType )
...@@ -650,6 +669,7 @@ static void SAL_CALL ToolkitWorkerFunction( void* pArgs ) ...@@ -650,6 +669,7 @@ static void SAL_CALL ToolkitWorkerFunction( void* pArgs )
VCLXToolkit::VCLXToolkit(): VCLXToolkit::VCLXToolkit():
cppu::WeakComponentImplHelper< cppu::WeakComponentImplHelper<
::com::sun::star::awt::XToolkitExperimental, ::com::sun::star::awt::XToolkitExperimental,
::com::sun::star::awt::XToolkitRobot,
::com::sun::star::lang::XServiceInfo>( GetMutex() ), ::com::sun::star::lang::XServiceInfo>( GetMutex() ),
m_aTopWindowListeners(rBHelper.rMutex), m_aTopWindowListeners(rBHelper.rMutex),
m_aKeyHandlers(rBHelper.rMutex), m_aKeyHandlers(rBHelper.rMutex),
...@@ -1896,6 +1916,85 @@ void SAL_CALL VCLXToolkit::processEventsToIdle() ...@@ -1896,6 +1916,85 @@ void SAL_CALL VCLXToolkit::processEventsToIdle()
Scheduler::ProcessTaskScheduling(false); 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 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
......
...@@ -736,6 +736,14 @@ awt::MouseEvent VCLUnoHelper::createMouseEvent( const ::MouseEvent& _rVclEvent, ...@@ -736,6 +736,14 @@ awt::MouseEvent VCLUnoHelper::createMouseEvent( const ::MouseEvent& _rVclEvent,
return aMouseEvent; 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 VCLUnoHelper::createKeyEvent( const ::KeyEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext )
{ {
awt::KeyEvent aKeyEvent; awt::KeyEvent aKeyEvent;
...@@ -758,4 +766,16 @@ awt::KeyEvent VCLUnoHelper::createKeyEvent( const ::KeyEvent& _rVclEvent, const ...@@ -758,4 +766,16 @@ awt::KeyEvent VCLUnoHelper::createKeyEvent( const ::KeyEvent& _rVclEvent, const
return aKeyEvent; 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment