1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #ifndef INCLUDED_VCL_UITEST_UIOBJECT_HXX
11 #define INCLUDED_VCL_UITEST_UIOBJECT_HXX
13 #include <rtl/ustring.hxx>
17 #include <vcl/vclevent.hxx>
18 #include <vcl/vclptr.hxx>
19 #include <vcl/dllapi.h>
20 #include <vcl/window.hxx>
35 class SvTreeListEntry
;
38 class VerticalTabControl
;
41 class VclMultiLineEdit
;
44 namespace vcl
{ class Window
; }
45 namespace weld
{ class CustomWidgetController
; }
47 typedef std::map
<OUString
, OUString
> StringMap
;
50 * This class wraps a UI object like vcl::Window and provides
51 * an interface for the UI testing.
53 * This class should only have virtual methods.
55 class UITEST_DLLPUBLIC UIObject
57 UIObject(UIObject
const &) = delete;
58 UIObject
& operator =(UIObject
const &) = delete;
66 * Returns the state of the wrapped UI object as a
67 * string key value map.
69 virtual StringMap
get_state();
72 * Executes an action on the wrapped UI object,
73 * possibly with some additional parameters
75 virtual void execute(const OUString
& rAction
,
76 const StringMap
& rParameters
);
79 * Returns the type of the UIObject. Additional information might
80 * be available through UIObject::get_state().
82 virtual OUString
get_type() const;
85 * Returns the child of the current UIObject with the corresponding id.
86 * If no object with that id is being found returns a nullptr.
89 virtual std::unique_ptr
<UIObject
> get_child(const OUString
& rID
);
92 * Returns a set containing all descendants of the object.
94 virtual std::set
<OUString
> get_children() const;
97 * Currently an internal method to dump the state of the current UIObject as represented by get_state().
99 * This method should not be exposed to the outside world.
102 virtual OUString
dumpState() const;
105 * Currently an internal method to dump the parent-child relationship starting from the current top focus window.
107 * This method should not be exposed to the outside world.
110 virtual OUString
dumpHierarchy() const;
113 * Gets the corresponding Action string for the event.
115 virtual OUString
get_action(VclEventId nEvent
) const;
118 class UITEST_DLLPUBLIC WindowUIObject
: public UIObject
120 VclPtr
<vcl::Window
> mxWindow
;
124 WindowUIObject(const VclPtr
<vcl::Window
>& xWindow
);
126 virtual StringMap
get_state() override
;
128 virtual void execute(const OUString
& rAction
,
129 const StringMap
& rParameters
) override
;
131 virtual OUString
get_type() const override
;
133 virtual std::unique_ptr
<UIObject
> get_child(const OUString
& rID
) override
;
135 std::unique_ptr
<UIObject
> get_visible_child(const OUString
& rID
);
137 virtual std::set
<OUString
> get_children() const override
;
139 virtual OUString
dumpState() const override
;
141 virtual OUString
dumpHierarchy() const override
;
143 virtual OUString
get_action(VclEventId nEvent
) const override
;
145 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
149 virtual OUString
get_name() const;
153 // TODO: moggi: what about push buttons?
154 class ButtonUIObject final
: public WindowUIObject
156 VclPtr
<Button
> mxButton
;
159 ButtonUIObject(const VclPtr
<Button
>& xButton
);
160 virtual ~ButtonUIObject() override
;
162 virtual StringMap
get_state() override
;
164 virtual void execute(const OUString
& rAction
,
165 const StringMap
& rParameters
) override
;
167 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
169 virtual OUString
get_action(VclEventId nEvent
) const override
;
173 virtual OUString
get_name() const override
;
176 class DialogUIObject final
: public WindowUIObject
178 VclPtr
<Dialog
> mxDialog
;
182 DialogUIObject(const VclPtr
<Dialog
>& xDialog
);
183 virtual ~DialogUIObject() override
;
185 virtual StringMap
get_state() override
;
187 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
191 virtual OUString
get_name() const override
;
194 class EditUIObject
: public WindowUIObject
200 EditUIObject(const VclPtr
<Edit
>& xEdit
);
201 virtual ~EditUIObject() override
;
203 virtual void execute(const OUString
& rAction
,
204 const StringMap
& rParameters
) override
;
206 virtual StringMap
get_state() override
;
208 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
210 virtual OUString
get_action(VclEventId nEvent
) const override
;
214 virtual OUString
get_name() const override
;
217 class MultiLineEditUIObject final
: public WindowUIObject
219 VclPtr
<VclMultiLineEdit
> mxEdit
;
223 MultiLineEditUIObject(const VclPtr
<VclMultiLineEdit
>& xEdit
);
224 virtual ~MultiLineEditUIObject() override
;
226 virtual void execute(const OUString
& rAction
,
227 const StringMap
& rParameters
) override
;
229 virtual StringMap
get_state() override
;
231 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
235 virtual OUString
get_name() const override
;
238 class ExpanderUIObject final
: public WindowUIObject
240 VclPtr
<VclExpander
> mxExpander
;
244 ExpanderUIObject(const VclPtr
<VclExpander
>& xExpander
);
245 virtual ~ExpanderUIObject() override
;
247 virtual void execute(const OUString
& rAction
,
248 const StringMap
& rParameters
) override
;
250 virtual StringMap
get_state() override
;
252 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
255 virtual OUString
get_name() const override
;
259 // TODO: moggi: maybe let it inherit from the button case
260 class CheckBoxUIObject final
: public WindowUIObject
263 VclPtr
<CheckBox
> mxCheckBox
;
266 CheckBoxUIObject(const VclPtr
<CheckBox
>& xCheckbox
);
267 virtual ~CheckBoxUIObject() override
;
269 virtual void execute(const OUString
& rAction
,
270 const StringMap
& rParameters
) override
;
272 virtual StringMap
get_state() override
;
274 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
276 virtual OUString
get_action(VclEventId nEvent
) const override
;
280 virtual OUString
get_name() const override
;
283 class RadioButtonUIObject final
: public WindowUIObject
286 VclPtr
<RadioButton
> mxRadioButton
;
289 RadioButtonUIObject(const VclPtr
<RadioButton
>& xCheckbox
);
290 virtual ~RadioButtonUIObject() override
;
292 virtual void execute(const OUString
& rAction
,
293 const StringMap
& rParameters
) override
;
295 virtual StringMap
get_state() override
;
297 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
299 virtual OUString
get_action(VclEventId nEvent
) const override
;
303 virtual OUString
get_name() const override
;
306 class TabPageUIObject final
: public WindowUIObject
309 VclPtr
<TabPage
> mxTabPage
;
311 TabPageUIObject(const VclPtr
<TabPage
>& xTabPage
);
312 virtual ~TabPageUIObject() override
;
314 virtual void execute(const OUString
& rAction
,
315 const StringMap
& rParameters
) override
;
317 virtual StringMap
get_state() override
;
319 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
323 virtual OUString
get_name() const override
;
326 class ListBoxUIObject final
: public WindowUIObject
329 VclPtr
<ListBox
> mxListBox
;
333 ListBoxUIObject(const VclPtr
<ListBox
>& xListBox
);
334 virtual ~ListBoxUIObject() override
;
336 virtual void execute(const OUString
& rAction
,
337 const StringMap
& rParameters
) override
;
339 virtual StringMap
get_state() override
;
341 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
343 virtual OUString
get_action(VclEventId nEvent
) const override
;
347 virtual OUString
get_name() const override
;
350 // TODO: moggi: should it inherit from EditUIObject?
351 class ComboBoxUIObject final
: public WindowUIObject
354 VclPtr
<ComboBox
> mxComboBox
;
358 ComboBoxUIObject(const VclPtr
<ComboBox
>& xListBox
);
359 virtual ~ComboBoxUIObject() override
;
361 virtual void execute(const OUString
& rAction
,
362 const StringMap
& rParameters
) override
;
364 virtual StringMap
get_state() override
;
366 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
368 virtual OUString
get_action(VclEventId nEvent
) const override
;
372 virtual OUString
get_name() const override
;
375 class SpinUIObject final
: public WindowUIObject
378 VclPtr
<SpinButton
> mxSpinButton
;
382 SpinUIObject(const VclPtr
<SpinButton
>& xSpinButton
);
383 virtual ~SpinUIObject() override
;
385 virtual void execute(const OUString
& rAction
,
386 const StringMap
& rParameters
) override
;
388 virtual StringMap
get_state() override
;
390 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
392 virtual OUString
get_action(VclEventId nEvent
) const override
;
396 virtual OUString
get_name() const override
;
399 class SpinFieldUIObject
: public EditUIObject
401 VclPtr
<SpinField
> mxSpinField
;
405 SpinFieldUIObject(const VclPtr
<SpinField
>& xEdit
);
406 virtual ~SpinFieldUIObject() override
;
408 virtual void execute(const OUString
& rAction
,
409 const StringMap
& rParameters
) override
;
411 virtual StringMap
get_state() override
;
413 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
415 virtual OUString
get_action(VclEventId nEvent
) const override
;
419 virtual OUString
get_name() const override
;
422 class TabControlUIObject final
: public WindowUIObject
425 VclPtr
<TabControl
> mxTabControl
;
429 TabControlUIObject(const VclPtr
<TabControl
>& mxTabControl
);
430 virtual ~TabControlUIObject() override
;
432 virtual void execute(const OUString
& rAction
,
433 const StringMap
& rParameters
) override
;
435 virtual StringMap
get_state() override
;
437 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
439 virtual OUString
get_action(VclEventId nEvent
) const override
;
443 virtual OUString
get_name() const override
;
446 class VerticalTabControlUIObject final
: public WindowUIObject
449 VclPtr
<VerticalTabControl
> mxTabControl
;
453 VerticalTabControlUIObject(const VclPtr
<VerticalTabControl
>& mxTabControl
);
454 virtual ~VerticalTabControlUIObject() override
;
456 virtual void execute(const OUString
& rAction
,
457 const StringMap
& rParameters
) override
;
459 virtual StringMap
get_state() override
;
461 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
465 virtual OUString
get_name() const override
;
468 class TreeListUIObject
: public WindowUIObject
471 TreeListUIObject(const VclPtr
<SvTreeListBox
>& xTreeList
);
473 virtual StringMap
get_state() override
;
475 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
477 virtual void execute(const OUString
& rAction
,
478 const StringMap
& rParameters
) override
;
480 virtual std::unique_ptr
<UIObject
> get_child(const OUString
& rID
) override
;
482 virtual std::set
<OUString
> get_children() const override
;
486 virtual OUString
get_name() const override
;
488 VclPtr
<SvTreeListBox
> mxTreeList
;
491 class TreeListEntryUIObject final
: public UIObject
495 TreeListEntryUIObject(const VclPtr
<SvTreeListBox
>& xTreeList
, std::vector
<sal_Int32
> nTreePath
);
497 virtual StringMap
get_state() override
;
499 virtual void execute(const OUString
& rAction
,
500 const StringMap
& rParameters
) override
;
502 virtual std::unique_ptr
<UIObject
> get_child(const OUString
& rID
) override
;
504 virtual std::set
<OUString
> get_children() const override
;
506 virtual OUString
get_type() const override
;
510 SvTreeListEntry
* getEntry() const;
512 VclPtr
<SvTreeListBox
> mxTreeList
;
514 std::vector
<sal_Int32
> maTreePath
;
517 class IconViewUIObject final
: public TreeListUIObject
520 IconViewUIObject(const VclPtr
<SvTreeListBox
>& xIconView
);
522 virtual StringMap
get_state() override
;
524 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
528 virtual OUString
get_name() const override
;
531 class ToolBoxUIObject final
: public WindowUIObject
534 VclPtr
<ToolBox
> mxToolBox
;
538 ToolBoxUIObject(const VclPtr
<ToolBox
>& mxToolBox
);
539 virtual ~ToolBoxUIObject() override
;
541 virtual void execute(const OUString
& rAction
,
542 const StringMap
& rParameters
) override
;
544 virtual StringMap
get_state() override
;
546 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
548 virtual OUString
get_action(VclEventId nEvent
) const override
;
552 virtual OUString
get_name() const override
;
555 class MenuButtonUIObject final
: public WindowUIObject
557 VclPtr
<MenuButton
> mxMenuButton
;
561 MenuButtonUIObject(const VclPtr
<MenuButton
>& xMenuButton
);
562 virtual ~MenuButtonUIObject() override
;
564 virtual StringMap
get_state() override
;
566 virtual void execute(const OUString
& rAction
,
567 const StringMap
& rParameters
) override
;
569 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
573 virtual OUString
get_name() const override
;
576 class UITEST_DLLPUBLIC DrawingAreaUIObject
: public WindowUIObject
579 VclPtr
<VclDrawingArea
> mxDrawingArea
;
581 weld::CustomWidgetController
* mpController
;
583 DrawingAreaUIObject(const VclPtr
<vcl::Window
>& rDrawingArea
);
584 virtual ~DrawingAreaUIObject() override
;
585 virtual void execute(const OUString
& rAction
, const StringMap
& rParameters
) override
;
586 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
591 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */