Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / vcl / uitest / uiobject.hxx
blobd27140b2c21b289c5d01801494b9819de72769dc
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 class UITEST_DLLPUBLIC WindowUIObject : public UIObject
120 VclPtr<vcl::Window> mxWindow;
122 public:
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);
147 protected:
149 virtual OUString get_name() const;
153 // TODO: moggi: what about push buttons?
154 class ButtonUIObject final : public WindowUIObject
156 VclPtr<Button> mxButton;
157 public:
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;
171 private:
173 virtual OUString get_name() const override;
176 class DialogUIObject final : public WindowUIObject
178 VclPtr<Dialog> mxDialog;
180 public:
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);
189 private:
191 virtual OUString get_name() const override;
194 class EditUIObject : public WindowUIObject
196 VclPtr<Edit> mxEdit;
198 public:
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;
212 protected:
214 virtual OUString get_name() const override;
217 class MultiLineEditUIObject final : public WindowUIObject
219 VclPtr<VclMultiLineEdit> mxEdit;
221 public:
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);
233 private:
235 virtual OUString get_name() const override;
238 class ExpanderUIObject final : public WindowUIObject
240 VclPtr<VclExpander> mxExpander;
242 public:
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);
253 private:
255 virtual OUString get_name() const override;
259 // TODO: moggi: maybe let it inherit from the button case
260 class CheckBoxUIObject final : public WindowUIObject
262 private:
263 VclPtr<CheckBox> mxCheckBox;
265 public:
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;
278 private:
280 virtual OUString get_name() const override;
283 class RadioButtonUIObject final : public WindowUIObject
285 private:
286 VclPtr<RadioButton> mxRadioButton;
288 public:
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;
301 private:
303 virtual OUString get_name() const override;
306 class TabPageUIObject final : public WindowUIObject
308 private:
309 VclPtr<TabPage> mxTabPage;
310 public:
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);
321 private:
323 virtual OUString get_name() const override;
326 class ListBoxUIObject final : public WindowUIObject
328 private:
329 VclPtr<ListBox> mxListBox;
331 public:
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;
345 private:
347 virtual OUString get_name() const override;
350 // TODO: moggi: should it inherit from EditUIObject?
351 class ComboBoxUIObject final : public WindowUIObject
353 private:
354 VclPtr<ComboBox> mxComboBox;
356 public:
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;
370 private:
372 virtual OUString get_name() const override;
375 class SpinUIObject final : public WindowUIObject
377 private:
378 VclPtr<SpinButton> mxSpinButton;
380 public:
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;
394 private:
396 virtual OUString get_name() const override;
399 class SpinFieldUIObject : public EditUIObject
401 VclPtr<SpinField> mxSpinField;
403 public:
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;
417 private:
419 virtual OUString get_name() const override;
422 class TabControlUIObject final : public WindowUIObject
424 private:
425 VclPtr<TabControl> mxTabControl;
427 public:
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;
441 private:
443 virtual OUString get_name() const override;
446 class VerticalTabControlUIObject final : public WindowUIObject
448 private:
449 VclPtr<VerticalTabControl> mxTabControl;
451 public:
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);
463 private:
465 virtual OUString get_name() const override;
468 class TreeListUIObject : public WindowUIObject
470 public:
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;
484 protected:
486 virtual OUString get_name() const override;
488 VclPtr<SvTreeListBox> mxTreeList;
491 class TreeListEntryUIObject final : public UIObject
493 public:
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;
508 private:
510 SvTreeListEntry* getEntry() const;
512 VclPtr<SvTreeListBox> mxTreeList;
514 std::vector<sal_Int32> maTreePath;
517 class IconViewUIObject final : public TreeListUIObject
519 public:
520 IconViewUIObject(const VclPtr<SvTreeListBox>& xIconView);
522 virtual StringMap get_state() override;
524 static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
526 private:
528 virtual OUString get_name() const override;
531 class ToolBoxUIObject final : public WindowUIObject
533 private:
534 VclPtr<ToolBox> mxToolBox;
536 public:
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;
550 private:
552 virtual OUString get_name() const override;
555 class MenuButtonUIObject final : public WindowUIObject
557 VclPtr<MenuButton> mxMenuButton;
559 public:
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);
571 private:
573 virtual OUString get_name() const override;
576 class UITEST_DLLPUBLIC DrawingAreaUIObject : public WindowUIObject
578 private:
579 VclPtr<VclDrawingArea> mxDrawingArea;
580 protected:
581 weld::CustomWidgetController* mpController;
582 public:
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);
589 #endif
591 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */