workaround segfault in compiler on macos-clang-intel
[LibreOffice.git] / include / vcl / uitest / uiobject.hxx
blob8f1624dc7f7ac851cbcb80e568c09435f632db61
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #ifndef INCLUDED_VCL_UITEST_UIOBJECT_HXX
11 #define INCLUDED_VCL_UITEST_UIOBJECT_HXX
13 #include <rtl/ustring.hxx>
14 #include <map>
15 #include <memory>
17 #include <vcl/vclevent.hxx>
18 #include <vcl/vclptr.hxx>
19 #include <vcl/dllapi.h>
20 #include <vcl/window.hxx>
22 #include <set>
24 class Button;
25 class CheckBox;
26 class ComboBox;
27 class Dialog;
28 class Edit;
29 class IconView;
30 class ListBox;
31 class RadioButton;
32 class TabControl;
33 class TabPage;
34 class SvTreeListBox;
35 class SvTreeListEntry;
36 class SpinButton;
37 class SpinField;
38 class VerticalTabControl;
39 class VclExpander;
40 class VclDrawingArea;
41 class VclMultiLineEdit;
42 class MenuButton;
43 class ToolBox;
44 namespace vcl { class Window; }
45 namespace weld { class CustomWidgetController; }
47 typedef std::map<OUString, OUString> StringMap;
49 /**
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;
60 public:
61 UIObject() = default;
63 virtual ~UIObject();
65 /**
66 * Returns the state of the wrapped UI object as a
67 * string key value map.
69 virtual StringMap get_state();
71 /**
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);
78 /**
79 * Returns the type of the UIObject. Additional information might
80 * be available through UIObject::get_state().
82 virtual OUString get_type() const;
84 /**
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);
91 /**
92 * Returns a set containing all descendants of the object.
94 virtual std::set<OUString> get_children() const;
96 /**
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;
127 public:
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;
154 protected:
156 virtual OUString get_name() const;
160 // TODO: moggi: what about push buttons?
161 class ButtonUIObject final : public WindowUIObject
163 VclPtr<Button> mxButton;
164 public:
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;
178 private:
180 virtual OUString get_name() const override;
183 class DialogUIObject final : public WindowUIObject
185 VclPtr<Dialog> mxDialog;
187 public:
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);
196 private:
198 virtual OUString get_name() const override;
201 class EditUIObject : public WindowUIObject
203 VclPtr<Edit> mxEdit;
205 public:
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;
219 protected:
221 virtual OUString get_name() const override;
224 class MultiLineEditUIObject final : public WindowUIObject
226 VclPtr<VclMultiLineEdit> mxEdit;
228 public:
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);
240 private:
242 virtual OUString get_name() const override;
245 class ExpanderUIObject final : public WindowUIObject
247 VclPtr<VclExpander> mxExpander;
249 public:
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);
260 private:
262 virtual OUString get_name() const override;
266 // TODO: moggi: maybe let it inherit from the button case
267 class CheckBoxUIObject final : public WindowUIObject
269 private:
270 VclPtr<CheckBox> mxCheckBox;
272 public:
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;
285 private:
287 virtual OUString get_name() const override;
290 class RadioButtonUIObject final : public WindowUIObject
292 private:
293 VclPtr<RadioButton> mxRadioButton;
295 public:
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;
308 private:
310 virtual OUString get_name() const override;
313 class TabPageUIObject final : public WindowUIObject
315 private:
316 VclPtr<TabPage> mxTabPage;
317 public:
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);
328 private:
330 virtual OUString get_name() const override;
333 class ListBoxUIObject final : public WindowUIObject
335 private:
336 VclPtr<ListBox> mxListBox;
338 public:
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;
352 private:
354 virtual OUString get_name() const override;
357 // TODO: moggi: should it inherit from EditUIObject?
358 class ComboBoxUIObject final : public WindowUIObject
360 private:
361 VclPtr<ComboBox> mxComboBox;
363 public:
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;
377 private:
379 virtual OUString get_name() const override;
382 class SpinUIObject final : public WindowUIObject
384 private:
385 VclPtr<SpinButton> mxSpinButton;
387 public:
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;
401 private:
403 virtual OUString get_name() const override;
406 class SpinFieldUIObject : public EditUIObject
408 VclPtr<SpinField> mxSpinField;
410 public:
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;
424 private:
426 virtual OUString get_name() const override;
429 class TabControlUIObject final : public WindowUIObject
431 private:
432 VclPtr<TabControl> mxTabControl;
434 public:
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;
448 private:
450 virtual OUString get_name() const override;
453 class VerticalTabControlUIObject final : public WindowUIObject
455 private:
456 VclPtr<VerticalTabControl> mxTabControl;
458 public:
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);
470 private:
472 virtual OUString get_name() const override;
475 class TreeListUIObject : public WindowUIObject
477 public:
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;
491 protected:
493 virtual OUString get_name() const override;
495 VclPtr<SvTreeListBox> mxTreeList;
498 class TreeListEntryUIObject final : public UIObject
500 public:
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;
517 private:
519 SvTreeListEntry* getEntry() const;
521 VclPtr<SvTreeListBox> mxTreeList;
523 std::vector<sal_Int32> maTreePath;
526 class IconViewUIObject final : public TreeListUIObject
528 public:
529 IconViewUIObject(const VclPtr<SvTreeListBox>& xIconView);
531 virtual StringMap get_state() override;
533 static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
535 private:
537 virtual OUString get_name() const override;
540 class ToolBoxUIObject final : public WindowUIObject
542 private:
543 VclPtr<ToolBox> mxToolBox;
545 public:
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;
559 private:
561 virtual OUString get_name() const override;
564 class MenuButtonUIObject final : public WindowUIObject
566 VclPtr<MenuButton> mxMenuButton;
568 public:
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);
580 private:
582 virtual OUString get_name() const override;
585 class UITEST_DLLPUBLIC DrawingAreaUIObject : public WindowUIObject
587 private:
588 VclPtr<VclDrawingArea> mxDrawingArea;
589 protected:
590 weld::CustomWidgetController* mpController;
591 public:
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);
598 #endif
600 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */