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/uno/Reference.hxx>
17 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
18 #include <rtl/ustring.hxx>
19 #include <vcl/window.hxx>
24 * @brief Base helper class to send events to a window.
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.
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.
33 class OOO_DLLPUBLIC_TEST EventPosterHelperBase
36 virtual ~EventPosterHelperBase(){};
38 /** @see SfxLokHelper::postKeyEventAsync */
39 virtual void postKeyEventAsync(int nType
, int nCharCode
, int nKeyCode
) const = 0;
41 /** Posts a full key down/up cycle */
42 void postKeyEventAsync(int nCharCode
, int nKeyCode
) const
44 postKeyEventAsync(LOK_KEYEVENT_KEYINPUT
, nCharCode
, nKeyCode
);
45 postKeyEventAsync(LOK_KEYEVENT_KEYUP
, nCharCode
, nKeyCode
);
48 /** @see SfxLokHelper::postExtTextEventAsync */
49 virtual void postExtTextEventAsync(int nType
, const OUString
& rText
) const = 0;
51 /** Posts a full text input + commit sequence */
52 void postExtTextEventAsync(const OUString
& rText
) const
54 postExtTextEventAsync(LOK_EXT_TEXTINPUT
, rText
);
55 postExtTextEventAsync(LOK_EXT_TEXTINPUT_END
, rText
);
60 * @brief Helper to send events to a window.
62 * This helper basically just wraps SfxLokHelper::post*EventAsync() calls to hold the target window
63 * reference in the class.
65 class OOO_DLLPUBLIC_TEST EventPosterHelper
: public EventPosterHelperBase
68 VclPtr
<vcl::Window
> mxWindow
;
71 EventPosterHelper(void)
75 EventPosterHelper(VclPtr
<vcl::Window
> xWindow
)
79 EventPosterHelper(vcl::Window
* pWindow
)
84 vcl::Window
* getWindow() const { return mxWindow
; }
86 void setWindow(VclPtr
<vcl::Window
> xWindow
) { mxWindow
= xWindow
; }
87 void setWindow(vcl::Window
* pWindow
) { mxWindow
= pWindow
; }
89 explicit operator bool() const { return mxWindow
&& !mxWindow
->isDisposed(); }
90 bool operator!() const { return !bool(*this); }
92 using EventPosterHelperBase::postKeyEventAsync
;
93 using EventPosterHelperBase::postExtTextEventAsync
;
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
;
102 * @brief Accessibility-specialized helper to send events to a window.
104 * This augments @c test::EventPosterHelper to simplify usage in accessibility tests.
106 class OOO_DLLPUBLIC_TEST AccessibleEventPosterHelper
: public EventPosterHelper
109 AccessibleEventPosterHelper(void)
110 : EventPosterHelper()
113 AccessibleEventPosterHelper(const css::uno::Reference
<css::accessibility::XAccessible
>& xAcc
)
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.
122 * This method tries and find the top level window containing @p xAcc to use it to post events.
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()).
127 void setWindow(css::uno::Reference
<css::accessibility::XAccessible
> xAcc
);
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */