1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
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/.
12 #include <test/testdllapi.hxx>
14 #include <com/sun/star/accessibility/XAccessible.hpp>
15 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
16 #include <com/sun/star/uno/Reference.hxx>
18 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
19 #include <rtl/ustring.hxx>
20 #include <vcl/window.hxx>
25 * @brief Base helper class to send events to a window.
27 * Implementations of this helper will usually just wrap an implementation of post*Event*() calls.
28 * This class is mostly useful to encapsulate the calls when getting the target window is not
29 * trivial or is only relevant to sending events, and to have a generic event poster interface.
31 * Additionally, this class provides simplified helpers to send event pairs, like key down/up, or
32 * text+commit, to make it easier on the common case for callers.
34 class OOO_DLLPUBLIC_TEST EventPosterHelperBase
37 virtual ~EventPosterHelperBase(){};
39 /** @see SfxLokHelper::postKeyEventAsync */
40 virtual void postKeyEventAsync(int nType
, int nCharCode
, int nKeyCode
) const = 0;
42 /** Posts a full key down/up cycle */
43 void postKeyEventAsync(int nCharCode
, int nKeyCode
) const
45 postKeyEventAsync(LOK_KEYEVENT_KEYINPUT
, nCharCode
, nKeyCode
);
46 postKeyEventAsync(LOK_KEYEVENT_KEYUP
, nCharCode
, nKeyCode
);
49 /** @see SfxLokHelper::postExtTextEventAsync */
50 virtual void postExtTextEventAsync(int nType
, const OUString
& rText
) const = 0;
52 /** Posts a full text input + commit sequence */
53 void postExtTextEventAsync(const OUString
& rText
) const
55 postExtTextEventAsync(LOK_EXT_TEXTINPUT
, rText
);
56 postExtTextEventAsync(LOK_EXT_TEXTINPUT_END
, rText
);
61 * @brief Helper to send events to a window.
63 * This helper basically just wraps SfxLokHelper::post*EventAsync() calls to hold the target window
64 * reference in the class.
66 class OOO_DLLPUBLIC_TEST EventPosterHelper
: public EventPosterHelperBase
69 VclPtr
<vcl::Window
> mxWindow
;
72 EventPosterHelper(void)
76 EventPosterHelper(VclPtr
<vcl::Window
> xWindow
)
80 EventPosterHelper(vcl::Window
* pWindow
)
85 vcl::Window
* getWindow() const { return mxWindow
; }
87 void setWindow(VclPtr
<vcl::Window
> xWindow
) { mxWindow
= xWindow
; }
88 void setWindow(vcl::Window
* pWindow
) { mxWindow
= pWindow
; }
90 explicit operator bool() const { return mxWindow
&& !mxWindow
->isDisposed(); }
91 bool operator!() const { return !bool(*this); }
93 using EventPosterHelperBase::postKeyEventAsync
;
94 using EventPosterHelperBase::postExtTextEventAsync
;
96 /** @see SfxLokHelper::postKeyEventAsync */
97 virtual void postKeyEventAsync(int nType
, int nCharCode
, int nKeyCode
) const override
;
98 /** @see SfxLokHelper::postExtTextEventAsync */
99 virtual void postExtTextEventAsync(int nType
, const OUString
& rText
) const override
;
103 * @brief Accessibility-specialized helper to send events to a window.
105 * This augments @c test::EventPosterHelper to simplify usage in accessibility tests.
107 class OOO_DLLPUBLIC_TEST AccessibleEventPosterHelper
: public EventPosterHelper
110 AccessibleEventPosterHelper(void)
111 : EventPosterHelper()
114 AccessibleEventPosterHelper(const css::uno::Reference
<css::accessibility::XAccessible
> xAcc
)
120 * @brief Sets the window on which post events based on an accessible object inside it.
121 * @param xAcc An accessible object inside a toplevel.
123 * This method tries and find the top level window containing @p xAcc to use it to post events.
125 * This currently relies on a toplevel accessible being a @c VCLXWindow, and requires that
126 * window's output device to be set (@see VCLXWindow::GetWindow()).
128 void setWindow(css::uno::Reference
<css::accessibility::XAccessible
> xAcc
);
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */