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 * Does this represent the same underlying UI widget as rOther?
120 virtual bool equals(const UIObject
& rOther
) const = 0;
123 class UITEST_DLLPUBLIC WindowUIObject
: public UIObject
125 VclPtr
<vcl::Window
> mxWindow
;
129 WindowUIObject(const VclPtr
<vcl::Window
>& xWindow
);
131 virtual StringMap
get_state() override
;
133 virtual void execute(const OUString
& rAction
,
134 const StringMap
& rParameters
) override
;
136 virtual OUString
get_type() const override
;
138 virtual std::unique_ptr
<UIObject
> get_child(const OUString
& rID
) override
;
140 std::unique_ptr
<UIObject
> get_visible_child(const OUString
& rID
);
142 virtual std::set
<OUString
> get_children() const override
;
144 virtual OUString
dumpState() const override
;
146 virtual OUString
dumpHierarchy() const override
;
148 virtual OUString
get_action(VclEventId nEvent
) const override
;
150 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
152 virtual bool equals(const UIObject
& rOther
) const override
;
156 virtual OUString
get_name() const;
160 // TODO: moggi: what about push buttons?
161 class ButtonUIObject final
: public WindowUIObject
163 VclPtr
<Button
> mxButton
;
166 ButtonUIObject(const VclPtr
<Button
>& xButton
);
167 virtual ~ButtonUIObject() override
;
169 virtual StringMap
get_state() override
;
171 virtual void execute(const OUString
& rAction
,
172 const StringMap
& rParameters
) override
;
174 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
176 virtual OUString
get_action(VclEventId nEvent
) const override
;
180 virtual OUString
get_name() const override
;
183 class DialogUIObject final
: public WindowUIObject
185 VclPtr
<Dialog
> mxDialog
;
189 DialogUIObject(const VclPtr
<Dialog
>& xDialog
);
190 virtual ~DialogUIObject() override
;
192 virtual StringMap
get_state() override
;
194 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
198 virtual OUString
get_name() const override
;
201 class EditUIObject
: public WindowUIObject
207 EditUIObject(const VclPtr
<Edit
>& xEdit
);
208 virtual ~EditUIObject() override
;
210 virtual void execute(const OUString
& rAction
,
211 const StringMap
& rParameters
) override
;
213 virtual StringMap
get_state() override
;
215 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
217 virtual OUString
get_action(VclEventId nEvent
) const override
;
221 virtual OUString
get_name() const override
;
224 class MultiLineEditUIObject final
: public WindowUIObject
226 VclPtr
<VclMultiLineEdit
> mxEdit
;
230 MultiLineEditUIObject(const VclPtr
<VclMultiLineEdit
>& xEdit
);
231 virtual ~MultiLineEditUIObject() override
;
233 virtual void execute(const OUString
& rAction
,
234 const StringMap
& rParameters
) override
;
236 virtual StringMap
get_state() override
;
238 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
242 virtual OUString
get_name() const override
;
245 class ExpanderUIObject final
: public WindowUIObject
247 VclPtr
<VclExpander
> mxExpander
;
251 ExpanderUIObject(const VclPtr
<VclExpander
>& xExpander
);
252 virtual ~ExpanderUIObject() override
;
254 virtual void execute(const OUString
& rAction
,
255 const StringMap
& rParameters
) override
;
257 virtual StringMap
get_state() override
;
259 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
262 virtual OUString
get_name() const override
;
266 // TODO: moggi: maybe let it inherit from the button case
267 class CheckBoxUIObject final
: public WindowUIObject
270 VclPtr
<CheckBox
> mxCheckBox
;
273 CheckBoxUIObject(const VclPtr
<CheckBox
>& xCheckbox
);
274 virtual ~CheckBoxUIObject() override
;
276 virtual void execute(const OUString
& rAction
,
277 const StringMap
& rParameters
) override
;
279 virtual StringMap
get_state() override
;
281 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
283 virtual OUString
get_action(VclEventId nEvent
) const override
;
287 virtual OUString
get_name() const override
;
290 class RadioButtonUIObject final
: public WindowUIObject
293 VclPtr
<RadioButton
> mxRadioButton
;
296 RadioButtonUIObject(const VclPtr
<RadioButton
>& xCheckbox
);
297 virtual ~RadioButtonUIObject() override
;
299 virtual void execute(const OUString
& rAction
,
300 const StringMap
& rParameters
) override
;
302 virtual StringMap
get_state() override
;
304 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
306 virtual OUString
get_action(VclEventId nEvent
) const override
;
310 virtual OUString
get_name() const override
;
313 class TabPageUIObject final
: public WindowUIObject
316 VclPtr
<TabPage
> mxTabPage
;
318 TabPageUIObject(const VclPtr
<TabPage
>& xTabPage
);
319 virtual ~TabPageUIObject() override
;
321 virtual void execute(const OUString
& rAction
,
322 const StringMap
& rParameters
) override
;
324 virtual StringMap
get_state() override
;
326 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
330 virtual OUString
get_name() const override
;
333 class ListBoxUIObject final
: public WindowUIObject
336 VclPtr
<ListBox
> mxListBox
;
340 ListBoxUIObject(const VclPtr
<ListBox
>& xListBox
);
341 virtual ~ListBoxUIObject() override
;
343 virtual void execute(const OUString
& rAction
,
344 const StringMap
& rParameters
) override
;
346 virtual StringMap
get_state() override
;
348 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
350 virtual OUString
get_action(VclEventId nEvent
) const override
;
354 virtual OUString
get_name() const override
;
357 // TODO: moggi: should it inherit from EditUIObject?
358 class ComboBoxUIObject final
: public WindowUIObject
361 VclPtr
<ComboBox
> mxComboBox
;
365 ComboBoxUIObject(const VclPtr
<ComboBox
>& xListBox
);
366 virtual ~ComboBoxUIObject() override
;
368 virtual void execute(const OUString
& rAction
,
369 const StringMap
& rParameters
) override
;
371 virtual StringMap
get_state() override
;
373 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
375 virtual OUString
get_action(VclEventId nEvent
) const override
;
379 virtual OUString
get_name() const override
;
382 class SpinUIObject final
: public WindowUIObject
385 VclPtr
<SpinButton
> mxSpinButton
;
389 SpinUIObject(const VclPtr
<SpinButton
>& xSpinButton
);
390 virtual ~SpinUIObject() override
;
392 virtual void execute(const OUString
& rAction
,
393 const StringMap
& rParameters
) override
;
395 virtual StringMap
get_state() override
;
397 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
399 virtual OUString
get_action(VclEventId nEvent
) const override
;
403 virtual OUString
get_name() const override
;
406 class SpinFieldUIObject
: public EditUIObject
408 VclPtr
<SpinField
> mxSpinField
;
412 SpinFieldUIObject(const VclPtr
<SpinField
>& xEdit
);
413 virtual ~SpinFieldUIObject() override
;
415 virtual void execute(const OUString
& rAction
,
416 const StringMap
& rParameters
) override
;
418 virtual StringMap
get_state() override
;
420 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
422 virtual OUString
get_action(VclEventId nEvent
) const override
;
426 virtual OUString
get_name() const override
;
429 class TabControlUIObject final
: public WindowUIObject
432 VclPtr
<TabControl
> mxTabControl
;
436 TabControlUIObject(const VclPtr
<TabControl
>& mxTabControl
);
437 virtual ~TabControlUIObject() override
;
439 virtual void execute(const OUString
& rAction
,
440 const StringMap
& rParameters
) override
;
442 virtual StringMap
get_state() override
;
444 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
446 virtual OUString
get_action(VclEventId nEvent
) const override
;
450 virtual OUString
get_name() const override
;
453 class VerticalTabControlUIObject final
: public WindowUIObject
456 VclPtr
<VerticalTabControl
> mxTabControl
;
460 VerticalTabControlUIObject(const VclPtr
<VerticalTabControl
>& mxTabControl
);
461 virtual ~VerticalTabControlUIObject() override
;
463 virtual void execute(const OUString
& rAction
,
464 const StringMap
& rParameters
) override
;
466 virtual StringMap
get_state() override
;
468 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
472 virtual OUString
get_name() const override
;
475 class TreeListUIObject
: public WindowUIObject
478 TreeListUIObject(const VclPtr
<SvTreeListBox
>& xTreeList
);
480 virtual StringMap
get_state() override
;
482 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
484 virtual void execute(const OUString
& rAction
,
485 const StringMap
& rParameters
) override
;
487 virtual std::unique_ptr
<UIObject
> get_child(const OUString
& rID
) override
;
489 virtual std::set
<OUString
> get_children() const override
;
493 virtual OUString
get_name() const override
;
495 VclPtr
<SvTreeListBox
> mxTreeList
;
498 class TreeListEntryUIObject final
: public UIObject
502 TreeListEntryUIObject(const VclPtr
<SvTreeListBox
>& xTreeList
, std::vector
<sal_Int32
> nTreePath
);
504 virtual StringMap
get_state() override
;
506 virtual void execute(const OUString
& rAction
,
507 const StringMap
& rParameters
) override
;
509 virtual std::unique_ptr
<UIObject
> get_child(const OUString
& rID
) override
;
511 virtual std::set
<OUString
> get_children() const override
;
513 virtual OUString
get_type() const override
;
515 virtual bool equals(const UIObject
& rOther
) const override
;
519 SvTreeListEntry
* getEntry() const;
521 VclPtr
<SvTreeListBox
> mxTreeList
;
523 std::vector
<sal_Int32
> maTreePath
;
526 class IconViewUIObject final
: public TreeListUIObject
529 IconViewUIObject(const VclPtr
<SvTreeListBox
>& xIconView
);
531 virtual StringMap
get_state() override
;
533 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
537 virtual OUString
get_name() const override
;
540 class ToolBoxUIObject final
: public WindowUIObject
543 VclPtr
<ToolBox
> mxToolBox
;
547 ToolBoxUIObject(const VclPtr
<ToolBox
>& mxToolBox
);
548 virtual ~ToolBoxUIObject() override
;
550 virtual void execute(const OUString
& rAction
,
551 const StringMap
& rParameters
) override
;
553 virtual StringMap
get_state() override
;
555 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
557 virtual OUString
get_action(VclEventId nEvent
) const override
;
561 virtual OUString
get_name() const override
;
564 class MenuButtonUIObject final
: public WindowUIObject
566 VclPtr
<MenuButton
> mxMenuButton
;
570 MenuButtonUIObject(const VclPtr
<MenuButton
>& xMenuButton
);
571 virtual ~MenuButtonUIObject() override
;
573 virtual StringMap
get_state() override
;
575 virtual void execute(const OUString
& rAction
,
576 const StringMap
& rParameters
) override
;
578 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
582 virtual OUString
get_name() const override
;
585 class UITEST_DLLPUBLIC DrawingAreaUIObject
: public WindowUIObject
588 VclPtr
<VclDrawingArea
> mxDrawingArea
;
590 weld::CustomWidgetController
* mpController
;
592 DrawingAreaUIObject(const VclPtr
<vcl::Window
>& rDrawingArea
);
593 virtual ~DrawingAreaUIObject() override
;
594 virtual void execute(const OUString
& rAction
, const StringMap
& rParameters
) override
;
595 static std::unique_ptr
<UIObject
> create(vcl::Window
* pWindow
);
600 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */