| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
*/ |
| 9 |
|
| 10 |
#pragma once |
| 11 |
|
| 12 |
#include <test/testdllapi.hxx> |
| 13 |
|
| 14 |
#include <com/sun/star/accessibility/XAccessible.hpp> |
| 15 |
#include <com/sun/star/uno/Reference.hxx> |
| 16 |
|
| 17 |
#include <LibreOfficeKit/LibreOfficeKitEnums.h> |
| 18 |
#include <rtl/ustring.hxx> |
| 19 |
#include <vcl/window.hxx> |
| 20 |
|
| 21 |
namespace test |
| 22 |
{ |
| 23 |
/** |
| 24 |
* @brief Base helper class to send events to a window. |
| 25 |
* |
| 26 |
* Implementations of this helper will usually just wrap an implementation of post*Event*() calls. |
| 27 |
* This class is mostly useful to encapsulate the calls when getting the target window is not |
| 28 |
* trivial or is only relevant to sending events, and to have a generic event poster interface. |
| 29 |
* |
| 30 |
* Additionally, this class provides simplified helpers to send event pairs, like key down/up, or |
| 31 |
* text+commit, to make it easier on the common case for callers. |
| 32 |
*/ |
| 33 |
class OOO_DLLPUBLIC_TEST EventPosterHelperBase |
| 34 |
{ |
| 35 |
public: |
| 36 |
virtual ~EventPosterHelperBase(){}; |
| 37 |
|
| 38 |
/** @see SfxLokHelper::postKeyEventAsync */ |
| 39 |
virtual void postKeyEventAsync(int nType, int nCharCode, int nKeyCode) const = 0; |
| 40 |
|
| 41 |
/** Posts a full key down/up cycle */ |
| 42 |
void postKeyEventAsync(int nCharCode, int nKeyCode) const |
| 43 |
{ |
| 44 |
postKeyEventAsync(LOK_KEYEVENT_KEYINPUT, nCharCode, nKeyCode); |
| 45 |
postKeyEventAsync(LOK_KEYEVENT_KEYUP, nCharCode, nKeyCode); |
| 46 |
} |
| 47 |
|
| 48 |
/** @see SfxLokHelper::postExtTextEventAsync */ |
| 49 |
virtual void postExtTextEventAsync(int nType, const OUString& rText) const = 0; |
| 50 |
|
| 51 |
/** Posts a full text input + commit sequence */ |
| 52 |
void postExtTextEventAsync(const OUString& rText) const |
| 53 |
{ |
| 54 |
postExtTextEventAsync(LOK_EXT_TEXTINPUT, rText); |
| 55 |
postExtTextEventAsync(LOK_EXT_TEXTINPUT_END, rText); |
| 56 |
} |
| 57 |
}; |
| 58 |
|
| 59 |
/** |
| 60 |
* @brief Helper to send events to a window. |
| 61 |
* |
| 62 |
* This helper basically just wraps SfxLokHelper::post*EventAsync() calls to hold the target window |
| 63 |
* reference in the class. |
| 64 |
*/ |
| 65 |
class OOO_DLLPUBLIC_TEST EventPosterHelper : public EventPosterHelperBase |
| 66 |
{ |
| 67 |
protected: |
| 68 |
VclPtr<vcl::Window> mxWindow; |
| 69 |
|
| 70 |
public: |
| 71 |
EventPosterHelper(void) |
| 72 |
: mxWindow(nullptr) |
| 73 |
{ |
| 74 |
} |
| 75 |
EventPosterHelper(VclPtr<vcl::Window> xWindow) |
| 76 |
: mxWindow(xWindow) |
| 77 |
{ |
| 78 |
} |
| 79 |
EventPosterHelper(vcl::Window* pWindow) |
| 80 |
: mxWindow(pWindow) |
| 81 |
{ |
| 82 |
} |
| 83 |
|
| 84 |
vcl::Window* getWindow() const { return mxWindow; } |
| 85 |
|
| 86 |
void setWindow(VclPtr<vcl::Window> xWindow) { mxWindow = xWindow; } |
| 87 |
void setWindow(vcl::Window* pWindow) { mxWindow = pWindow; } |
| 88 |
|
| 89 |
explicit operator bool() const { return mxWindow && !mxWindow->isDisposed(); } |
| 90 |
bool operator!() const { return !bool(*this); } |
| 91 |
|
| 92 |
using EventPosterHelperBase::postKeyEventAsync; |
| 93 |
using EventPosterHelperBase::postExtTextEventAsync; |
| 94 |
|
| 95 |
/** @see SfxLokHelper::postKeyEventAsync */ |
| 96 |
virtual void postKeyEventAsync(int nType, int nCharCode, int nKeyCode) const override; |
| 97 |
/** @see SfxLokHelper::postExtTextEventAsync */ |
| 98 |
virtual void postExtTextEventAsync(int nType, const OUString& rText) const override; |
| 99 |
}; |
| 100 |
|
| 101 |
/** |
| 102 |
* @brief Accessibility-specialized helper to send events to a window. |
| 103 |
* |
| 104 |
* This augments @c test::EventPosterHelper to simplify usage in accessibility tests. |
| 105 |
*/ |
| 106 |
class OOO_DLLPUBLIC_TEST AccessibleEventPosterHelper : public EventPosterHelper |
| 107 |
{ |
| 108 |
public: |
| 109 |
AccessibleEventPosterHelper(void) |
| 110 |
: EventPosterHelper() |
| 111 |
{ |
| 112 |
} |
| 113 |
AccessibleEventPosterHelper(const css::uno::Reference<css::accessibility::XAccessible>& xAcc) |
| 114 |
{ |
| 115 |
setWindow(xAcc); |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* @brief Sets the window on which post events based on an accessible object inside it. |
| 120 |
* @param xAcc An accessible object inside a toplevel. |
| 121 |
* |
| 122 |
* This method tries and find the top level window containing @p xAcc to use it to post events. |
| 123 |
* |
| 124 |
* This currently relies on a toplevel accessible being a @c VCLXWindow, and requires that |
| 125 |
* window's output device to be set (@see VCLXWindow::GetWindow()). |
| 126 |
*/ |
| 127 |
void setWindow(css::uno::Reference<css::accessibility::XAccessible> xAcc); |
| 128 |
}; |
| 129 |
} |
| 130 |
|
| 131 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |