Virtualize wxUIActionSimulator implementation

Extract platform-specific code in a wxUIActionSimulatorImpl-derived class
instead of keeping it in wxUIActionSimulator itself.

This will allow determining which implementation to use dynamically (i.e. at
run-time and not compile-time) to use later and already allows to get rid of
an __WXOSX__ #ifdef in common code.
This commit is contained in:
Vadim Zeitlin
2016-05-21 18:34:45 +02:00
parent e82c619402
commit cfc1681b4c
7 changed files with 280 additions and 50 deletions

View File

@@ -2,11 +2,10 @@
// Name: src/unix/uiactionx11.cpp
// Purpose: wxUIActionSimulator implementation
// Author: Kevin Ollivier, Steven Lamerton, Vadim Zeitlin
// Modified by:
// Created: 2010-03-06
// Copyright: (c) Kevin Ollivier
// Copyright: (c) 2010 Kevin Ollivier
// (c) 2010 Steven Lamerton
// (c) 2010 Vadim Zeitlin
// (c) 2010-2016 Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
@@ -18,6 +17,8 @@
#include "wx/event.h"
#include "wx/evtloop.h"
#include "wx/private/uiaction.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#if wxUSE_XTEST
@@ -29,6 +30,31 @@
namespace
{
class wxUIActionSimulatorX11Impl : public wxUIActionSimulatorImpl
{
public:
// Returns a pointer to the global simulator object: as it's stateless, we
// can reuse the same one without having to allocate it on the heap all the
// time.
static wxUIActionSimulatorX11Impl* Get()
{
static wxUIActionSimulatorX11Impl s_impl;
return &s_impl;
}
virtual bool MouseMove(long x, long y) wxOVERRIDE;
virtual bool MouseDown(int button = wxMOUSE_BTN_LEFT) wxOVERRIDE;
virtual bool MouseUp(int button = wxMOUSE_BTN_LEFT) wxOVERRIDE;
virtual bool DoKey(int keycode, int modifiers, bool isDown) wxOVERRIDE;
private:
// This class has no public ctors, use Get() instead.
wxUIActionSimulatorX11Impl() { }
wxDECLARE_NO_COPY_CLASS(wxUIActionSimulatorX11Impl);
};
void SendButtonEvent(int button, bool isDown)
{
int xbutton;
@@ -83,13 +109,13 @@ void SendButtonEvent(int button, bool isDown)
} // anonymous namespace
bool wxUIActionSimulator::MouseDown(int button)
bool wxUIActionSimulatorX11Impl::MouseDown(int button)
{
SendButtonEvent(button, true);
return true;
}
bool wxUIActionSimulator::MouseMove(long x, long y)
bool wxUIActionSimulatorX11Impl::MouseMove(long x, long y)
{
wxX11Display display;
wxASSERT_MSG(display, "No display available!");
@@ -114,13 +140,13 @@ bool wxUIActionSimulator::MouseMove(long x, long y)
return true;
}
bool wxUIActionSimulator::MouseUp(int button)
bool wxUIActionSimulatorX11Impl::MouseUp(int button)
{
SendButtonEvent(button, false);
return true;
}
bool wxUIActionSimulator::DoKey(int keycode, int modifiers, bool isDown)
bool wxUIActionSimulatorX11Impl::DoKey(int keycode, int modifiers, bool isDown)
{
wxX11Display display;
wxCHECK_MSG(display, false, "No display available!");
@@ -188,4 +214,15 @@ bool wxUIActionSimulator::DoKey(int keycode, int modifiers, bool isDown)
#endif // !wxUSE_XTEST
}
wxUIActionSimulator::wxUIActionSimulator()
: m_impl(wxUIActionSimulatorX11Impl::Get())
{
}
wxUIActionSimulator::~wxUIActionSimulator()
{
// We can use a static wxUIActionSimulatorX11Impl object because it's
// stateless, so no need to delete it.
}
#endif // wxUSE_UIACTIONSIMULATOR