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 #include <vcl/uitest/uiobject.hxx>
11 #include <vcl/uitest/metricfielduiobject.hxx>
12 #include <vcl/uitest/formattedfielduiobject.hxx>
14 #include <vcl/svapp.hxx>
15 #include <vcl/toolkit/combobox.hxx>
16 #include <vcl/event.hxx>
17 #include <vcl/toolkit/floatwin.hxx>
18 #include <vcl/menu.hxx>
19 #include <vcl/tabpage.hxx>
20 #include <vcl/tabctrl.hxx>
21 #include <vcl/toolkit/lstbox.hxx>
22 #include <vcl/toolkit/spin.hxx>
23 #include <vcl/toolkit/fmtfield.hxx>
24 #include <vcl/toolkit/spinfld.hxx>
25 #include <vcl/toolkit/ivctrl.hxx>
26 #include <vcl/toolkit/button.hxx>
27 #include <vcl/toolkit/dialog.hxx>
28 #include <vcl/toolkit/edit.hxx>
29 #include <vcl/toolkit/field.hxx>
30 #include <vcl/toolkit/treelistbox.hxx>
31 #include <vcl/toolkit/treelistentry.hxx>
32 #include <vcl/toolkit/svlbitm.hxx>
33 #include <vcl/toolkit/menubtn.hxx>
34 #include <vcl/toolkit/vclmedit.hxx>
35 #include <vcl/uitest/logger.hxx>
36 #include <uiobject-internal.hxx>
37 #include <verticaltabctrl.hxx>
38 #include <vcl/toolbox.hxx>
40 #include <comphelper/string.hxx>
41 #include <comphelper/lok.hxx>
43 #include <rtl/ustrbuf.hxx>
44 #include <sal/log.hxx>
54 StringMap
UIObject::get_state()
57 aMap
["NotImplemented"] = "NotImplemented";
61 void UIObject::execute(const OUString
& /*rAction*/,
62 const StringMap
& /*rParameters*/)
64 // should never be called
65 throw std::exception();
68 OUString
UIObject::get_type() const
70 return "Generic UIObject";
73 std::unique_ptr
<UIObject
> UIObject::get_child(const OUString
&)
75 return std::unique_ptr
<UIObject
>();
78 std::set
<OUString
> UIObject::get_children() const
80 return std::set
<OUString
>();
83 OUString
UIObject::dumpState() const
88 OUString
UIObject::dumpHierarchy() const
93 OUString
UIObject::get_action(VclEventId
/*nEvent*/) const
100 bool isDialogWindow(vcl::Window
const * pWindow
)
102 WindowType nType
= pWindow
->GetType();
103 if (nType
== WindowType::DIALOG
|| nType
== WindowType::MODELESSDIALOG
)
106 // MESSBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX
107 if (nType
>= WindowType::MESSBOX
&& nType
<= WindowType::QUERYBOX
)
110 if (nType
== WindowType::TABDIALOG
)
116 bool isTopWindow(vcl::Window
const * pWindow
)
118 WindowType eType
= pWindow
->GetType();
119 if (eType
== WindowType::FLOATINGWINDOW
)
121 return pWindow
->GetStyle() & WB_SYSTEMFLOATWIN
;
126 vcl::Window
* get_top_parent(vcl::Window
* pWindow
)
128 if (isDialogWindow(pWindow
) || isTopWindow(pWindow
))
131 vcl::Window
* pParent
= pWindow
->GetParent();
135 return get_top_parent(pParent
);
138 std::vector
<KeyEvent
> generate_key_events_from_text(std::u16string_view rStr
)
140 std::vector
<KeyEvent
> aEvents
;
142 for (size_t i
= 0, n
= rStr
.size(); i
!= n
; ++i
)
144 aEvents
.emplace_back(rStr
[i
], aCode
);
149 sal_uInt16
get_key(sal_Unicode cChar
, bool& bShift
)
152 if (cChar
>= 'a' && cChar
<= 'z')
153 return KEY_A
+ (cChar
- 'a');
154 else if (cChar
>= 'A' && cChar
<= 'Z')
157 return KEY_A
+ (cChar
- 'A');
159 else if (cChar
>= '0' && cChar
<= '9')
160 return KEY_0
+ (cChar
- 'A');
165 bool isFunctionKey(const OUString
& rStr
, sal_uInt16
& rKeyCode
)
167 std::map
<OUString
, sal_uInt16
> aFunctionKeyMap
= {
183 auto itr
= aFunctionKeyMap
.find(rStr
);
184 if (itr
== aFunctionKeyMap
.end())
187 rKeyCode
= itr
->second
;
191 std::vector
<KeyEvent
> generate_key_events_from_keycode(std::u16string_view rStr
)
193 std::vector
<KeyEvent
> aEvents
;
195 std::map
<OUString
, sal_uInt16
> aKeyMap
= {
201 {"RIGHT", KEY_RIGHT
},
202 {"DELETE", KEY_DELETE
},
203 {"INSERT", KEY_INSERT
},
204 {"SPACE", KEY_SPACE
},
205 {"BACKSPACE", KEY_BACKSPACE
},
206 {"RETURN", KEY_RETURN
},
209 {"PAGEUP", KEY_PAGEUP
},
210 {"PAGEDOWN", KEY_PAGEDOWN
}
213 // split string along '+'
214 // then translate to keycodes
218 OUString aRemainingText
;
220 std::vector
<OUString
> aTokens
= comphelper::string::split(rStr
, '+');
221 for (auto const& token
: aTokens
)
223 OUString aToken
= token
.trim();
224 if (aToken
== "CTRL")
228 else if (aToken
== "SHIFT")
232 else if (aToken
== "ALT")
237 aRemainingText
= aToken
;
240 sal_uInt16 nFunctionKey
= 0;
241 if (isFunctionKey(aRemainingText
, nFunctionKey
))
243 vcl::KeyCode
aCode(nFunctionKey
, bShift
, bMod1
, bMod2
, false);
244 aEvents
.emplace_back(0, aCode
);
246 else if (aKeyMap
.find(aRemainingText
) != aKeyMap
.end())
248 sal_uInt16 nKey
= aKeyMap
[aRemainingText
];
249 vcl::KeyCode
aCode(nKey
, bShift
, bMod1
, bMod2
, false);
250 aEvents
.emplace_back( 'a', aCode
);
254 for (sal_Int32 i
= 0; i
< aRemainingText
.getLength(); ++i
)
256 bool bShiftThroughKey
= false;
257 sal_uInt16 nKey
= get_key(aRemainingText
[i
], bShiftThroughKey
);
258 vcl::KeyCode
aCode(nKey
, bShift
|| bShiftThroughKey
, bMod1
, bMod2
, false);
259 aEvents
.emplace_back(aRemainingText
[i
], aCode
);
266 OUString
to_string(const Point
& rPos
)
268 OUString sStr
= OUString::number(rPos
.X())
270 + OUString::number(rPos
.Y());
275 OUString
to_string(const Size
& rSize
)
277 OUString sStr
= OUString::number(rSize
.Width())
279 + OUString::number(rSize
.Height());
286 WindowUIObject::WindowUIObject(const VclPtr
<vcl::Window
>& xWindow
):
291 StringMap
WindowUIObject::get_state()
293 // Double-buffering is not interesting for uitesting, but can result in direct paint for a
294 // double-buffered widget, which is incorrect.
295 if (mxWindow
->SupportsDoubleBuffering())
296 mxWindow
->RequestDoubleBuffering(false);
299 aMap
["Visible"] = OUString::boolean(mxWindow
->IsVisible());
300 aMap
["ReallyVisible"] = OUString::boolean(mxWindow
->IsReallyVisible());
301 aMap
["Enabled"] = OUString::boolean(mxWindow
->IsEnabled());
302 aMap
["HasFocus"] = OUString::boolean(mxWindow
->HasChildPathFocus());
303 aMap
["WindowType"] = OUString::number(static_cast<sal_uInt16
>(mxWindow
->GetType()), 16);
305 Point aPos
= mxWindow
->GetPosPixel();
306 aMap
["RelPosition"] = to_string(aPos
);
307 aMap
["Size"] = to_string(mxWindow
->GetSizePixel());
308 aMap
["ID"] = mxWindow
->get_id();
309 vcl::Window
* pParent
= mxWindow
->GetParent();
311 aMap
["Parent"] = mxWindow
->GetParent()->get_id();
313 bool bIgnoreAllExceptTop
= isDialogWindow(mxWindow
.get());
316 Point aParentPos
= pParent
->GetPosPixel();
317 if (!bIgnoreAllExceptTop
)
320 if (isDialogWindow(pParent
))
322 bIgnoreAllExceptTop
= true;
325 pParent
= pParent
->GetParent();
327 if (!pParent
&& bIgnoreAllExceptTop
)
330 aMap
["AbsPosition"] = to_string(aPos
);
331 aMap
["Text"] = mxWindow
->GetText();
332 aMap
["DisplayText"] = mxWindow
->GetDisplayText();
337 void WindowUIObject::execute(const OUString
& rAction
,
338 const StringMap
& rParameters
)
340 if (rAction
== "SET")
342 for (auto const& parameter
: rParameters
)
344 std::cout
<< parameter
.first
;
347 else if (rAction
== "TYPE")
349 auto it
= rParameters
.find("TEXT");
350 if (it
!= rParameters
.end())
352 const OUString
& rText
= it
->second
;
353 auto aKeyEvents
= generate_key_events_from_text(rText
);
354 for (auto const& keyEvent
: aKeyEvents
)
356 mxWindow
->KeyInput(keyEvent
);
359 else if (rParameters
.find("KEYCODE") != rParameters
.end())
361 auto itr
= rParameters
.find("KEYCODE");
362 const OUString rText
= itr
->second
;
363 auto aKeyEvents
= generate_key_events_from_keycode(rText
);
364 for (auto const& keyEvent
: aKeyEvents
)
366 mxWindow
->KeyInput(keyEvent
);
372 for (auto const & rPair
: rParameters
)
373 buf
.append("," + rPair
.first
.toUtf8() + "=" + rPair
.second
.toUtf8());
374 SAL_WARN("vcl.uitest", "missing parameter TEXT to action TYPE "
375 << buf
.makeStringAndClear());
376 throw std::logic_error("missing parameter TEXT to action TYPE");
379 else if (rAction
== "FOCUS")
381 mxWindow
->GrabFocus();
386 for (auto const & rPair
: rParameters
)
387 buf
.append("," + rPair
.first
.toUtf8() + "=" + rPair
.second
.toUtf8());
388 SAL_WARN("vcl.uitest", "unknown action for " << get_name()
389 << ". Action: " << rAction
<< buf
.makeStringAndClear());
390 throw std::logic_error("unknown action");
394 OUString
WindowUIObject::get_type() const
401 vcl::Window
* findChild(vcl::Window
* pParent
, const OUString
& rID
, bool bRequireVisible
= false, OUStringBuffer
* debug
= nullptr)
403 if (!pParent
|| pParent
->isDisposed())
406 if (pParent
->get_id() == rID
)
409 size_t nCount
= pParent
->GetChildCount();
410 for (size_t i
= 0; i
< nCount
; ++i
)
412 vcl::Window
* pChild
= pParent
->GetChild(i
);
413 bool bCandidate
= !bRequireVisible
|| pChild
->IsVisible();
417 if (pChild
->get_id() == rID
)
421 debug
->append(pChild
->get_id() + " ");
423 vcl::Window
* pResult
= findChild(pChild
, rID
, bRequireVisible
, debug
);
431 void addChildren(vcl::Window
const * pParent
, std::set
<OUString
>& rChildren
)
436 size_t nCount
= pParent
->GetChildCount();
437 for (size_t i
= 0; i
< nCount
; ++i
)
439 vcl::Window
* pChild
= pParent
->GetChild(i
);
442 OUString aId
= pChild
->get_id();
445 auto ret
= rChildren
.insert(aId
);
446 SAL_WARN_IF(!ret
.second
, "vcl.uitest", "duplicate ids '" << aId
<< "' for ui elements. violates locally unique requirement");
449 addChildren(pChild
, rChildren
);
456 std::unique_ptr
<UIObject
> WindowUIObject::get_child(const OUString
& rID
)
458 // in a first step try the real children before moving to the top level parent
459 // This makes it easier to handle cases with the same ID as there is a way
460 // to resolve conflicts
461 OUStringBuffer debug
;
462 vcl::Window
* pWindow
= findChild(mxWindow
.get(), rID
, false, &debug
);
465 vcl::Window
* pDialogParent
= get_top_parent(mxWindow
.get());
466 pWindow
= findChild(pDialogParent
, rID
, false, &debug
);
470 throw css::uno::RuntimeException("Could not find child with id: " + rID
+ " children were " + std::u16string_view(debug
));
472 FactoryFunction aFunction
= pWindow
->GetUITestFactory();
473 return aFunction(pWindow
);
476 std::unique_ptr
<UIObject
> WindowUIObject::get_visible_child(const OUString
& rID
)
478 // in a first step try the real children before moving to the top level parent
479 // This makes it easier to handle cases with the same ID as there is a way
480 // to resolve conflicts
481 vcl::Window
* pWindow
= findChild(mxWindow
.get(), rID
, true);
484 vcl::Window
* pDialogParent
= get_top_parent(mxWindow
.get());
485 pWindow
= findChild(pDialogParent
, rID
, true);
489 throw css::uno::RuntimeException("Could not find child with id: " + rID
);
491 FactoryFunction aFunction
= pWindow
->GetUITestFactory();
492 return aFunction(pWindow
);
495 std::set
<OUString
> WindowUIObject::get_children() const
497 std::set
<OUString
> aChildren
;
498 vcl::Window
* pDialogParent
= get_top_parent(mxWindow
.get());
499 if (!pDialogParent
->isDisposed())
501 aChildren
.insert(pDialogParent
->get_id());
502 addChildren(pDialogParent
, aChildren
);
507 OUString
WindowUIObject::get_name() const
509 return "WindowUIObject";
514 OUString
escape(const OUString
& rStr
)
516 return rStr
.replaceAll("\"", "\\\"");
521 OUString
WindowUIObject::dumpState() const
523 OUStringBuffer aStateString
= "{\"name\":\"" + mxWindow
->get_id() + "\"";
524 aStateString
.append(", \"ImplementationName\":\"").appendAscii(typeid(*mxWindow
).name()).append("\"");
525 StringMap aState
= const_cast<WindowUIObject
*>(this)->get_state();
526 for (auto const& elem
: aState
)
528 OUString property
= ",\"" + elem
.first
+ "\":\"" + escape(elem
.second
) + "\"";
529 aStateString
.append(property
);
532 size_t nCount
= mxWindow
->GetChildCount();
535 aStateString
.append(",\"children\":[");
537 for (size_t i
= 0; i
< nCount
; ++i
)
541 aStateString
.append(",");
543 vcl::Window
* pChild
= mxWindow
->GetChild(i
);
544 std::unique_ptr
<UIObject
> pChildWrapper
=
545 pChild
->GetUITestFactory()(pChild
);
546 OUString children
= pChildWrapper
->dumpState();
547 aStateString
.append(children
);
551 aStateString
.append("]");
553 aStateString
.append("}");
555 OUString aString
= aStateString
.makeStringAndClear();
556 return aString
.replaceAll("\n", "\\n");
559 OUString
WindowUIObject::dumpHierarchy() const
561 vcl::Window
* pDialogParent
= get_top_parent(mxWindow
.get());
562 std::unique_ptr
<UIObject
> pParentWrapper
=
563 pDialogParent
->GetUITestFactory()(pDialogParent
);
564 return pParentWrapper
->dumpState();
567 OUString
WindowUIObject::get_action(VclEventId nEvent
) const
570 OUString aActionName
;
573 case VclEventId::ControlGetFocus
:
574 case VclEventId::ControlLoseFocus
:
577 case VclEventId::ButtonClick
:
578 case VclEventId::CheckboxToggle
:
579 aActionName
= "CLICK";
582 case VclEventId::EditModify
:
583 aActionName
= "TYPE";
586 aActionName
= OUString::number(static_cast<int>(nEvent
));
588 return "Action on element: " + mxWindow
->get_id() + " with action : " + aActionName
;
591 std::unique_ptr
<UIObject
> WindowUIObject::create(vcl::Window
* pWindow
)
593 return std::unique_ptr
<UIObject
>(new WindowUIObject(pWindow
));
596 ButtonUIObject::ButtonUIObject(const VclPtr
<Button
>& xButton
):
597 WindowUIObject(xButton
),
602 ButtonUIObject::~ButtonUIObject()
606 StringMap
ButtonUIObject::get_state()
608 StringMap aMap
= WindowUIObject::get_state();
609 // Move that to a Control base class
610 aMap
["Label"] = mxButton
->GetDisplayText();
615 void ButtonUIObject::execute(const OUString
& rAction
,
616 const StringMap
& rParameters
)
618 if (rAction
== "CLICK")
620 //Click doesn't call toggle when it's a pushbutton tweaked to be a toggle-button
621 if (PushButton
*pPushButton
= (mxButton
->GetStyle() & WB_TOGGLE
) ? dynamic_cast<PushButton
*>(mxButton
.get()) : nullptr)
623 pPushButton
->Check(!pPushButton
->IsChecked());
624 pPushButton
->Toggle();
630 WindowUIObject::execute(rAction
, rParameters
);
633 OUString
ButtonUIObject::get_name() const
635 return "ButtonUIObject";
638 OUString
ButtonUIObject::get_action(VclEventId nEvent
) const
640 if (nEvent
== VclEventId::ButtonClick
)
642 if(mxButton
->get_id()=="writer_all")
644 UITestLogger::getInstance().setAppName("writer");
645 return "Start writer" ;
647 else if(mxButton
->get_id()=="calc_all")
649 UITestLogger::getInstance().setAppName("calc");
650 return "Start calc" ;
652 else if(mxButton
->get_id()=="impress_all")
654 UITestLogger::getInstance().setAppName("impress");
655 return "Start impress" ;
657 else if(mxButton
->get_id()=="draw_all")
659 UITestLogger::getInstance().setAppName("draw");
660 return "Start draw" ;
662 else if(mxButton
->get_id()=="math_all")
664 UITestLogger::getInstance().setAppName("math");
665 return "Start math" ;
667 else if(mxButton
->get_id()=="database_all")
669 UITestLogger::getInstance().setAppName("database");
670 return "Start database" ;
673 if (get_top_parent(mxButton
)->get_id().isEmpty()){
674 //This part because if we don't have parent
675 return "Click on '" + mxButton
->get_id() ;
677 return "Click on '" + mxButton
->get_id() + "' from "+
678 get_top_parent(mxButton
)->get_id();
682 return WindowUIObject::get_action(nEvent
);
685 std::unique_ptr
<UIObject
> ButtonUIObject::create(vcl::Window
* pWindow
)
687 Button
* pButton
= dynamic_cast<Button
*>(pWindow
);
689 return std::unique_ptr
<UIObject
>(new ButtonUIObject(pButton
));
692 DialogUIObject::DialogUIObject(const VclPtr
<Dialog
>& xDialog
):
693 WindowUIObject(xDialog
),
698 DialogUIObject::~DialogUIObject()
702 StringMap
DialogUIObject::get_state()
704 StringMap aMap
= WindowUIObject::get_state();
705 aMap
["Modal"] = OUString::boolean(mxDialog
->IsModalInputMode());
710 OUString
DialogUIObject::get_name() const
712 return "DialogUIObject";
715 std::unique_ptr
<UIObject
> DialogUIObject::create(vcl::Window
* pWindow
)
717 Dialog
* pDialog
= dynamic_cast<Dialog
*>(pWindow
);
719 return std::unique_ptr
<UIObject
>(new DialogUIObject(pDialog
));
722 EditUIObject::EditUIObject(const VclPtr
<Edit
>& xEdit
):
723 WindowUIObject(xEdit
),
728 EditUIObject::~EditUIObject()
732 void EditUIObject::execute(const OUString
& rAction
,
733 const StringMap
& rParameters
)
735 bool bHandled
= true;
736 if (rAction
== "TYPE")
738 auto it
= rParameters
.find("TEXT");
739 if (it
!= rParameters
.end())
741 const OUString
& rText
= it
->second
;
742 auto aKeyEvents
= generate_key_events_from_text(rText
);
743 for (auto const& keyEvent
: aKeyEvents
)
745 mxEdit
->KeyInput(keyEvent
);
753 else if (rAction
== "SET")
755 auto it
= rParameters
.find("TEXT");
756 if (it
!= rParameters
.end())
758 mxEdit
->SetText(it
->second
);
764 else if (rAction
== "SELECT")
766 if (rParameters
.find("FROM") != rParameters
.end() &&
767 rParameters
.find("TO") != rParameters
.end())
769 tools::Long nMin
= rParameters
.find("FROM")->second
.toInt32();
770 tools::Long nMax
= rParameters
.find("TO")->second
.toInt32();
771 Selection
aSelection(nMin
, nMax
);
772 mxEdit
->SetSelection(aSelection
);
775 else if (rAction
== "CLEAR")
787 WindowUIObject::execute(rAction
, rParameters
);
790 StringMap
EditUIObject::get_state()
792 StringMap aMap
= WindowUIObject::get_state();
793 aMap
["MaxTextLength"] = OUString::number(mxEdit
->GetMaxTextLen());
794 aMap
["QuickHelpText"] = mxEdit
->GetQuickHelpText();
795 aMap
["SelectedText"] = mxEdit
->GetSelected();
796 aMap
["Text"] = mxEdit
->GetText();
801 OUString
EditUIObject::get_action(VclEventId nEvent
) const
803 if (nEvent
== VclEventId::EditSelectionChanged
)
805 const Selection
& rSelection
= mxEdit
->GetSelection();
806 tools::Long nMin
= rSelection
.Min();
807 tools::Long nMax
= rSelection
.Max();
808 if(get_top_parent(mxEdit
)->get_id().isEmpty()){
809 //This part because if we don't have parent
810 return "Select in '" +
812 "' {\"FROM\": \"" + OUString::number(nMin
) + "\", \"TO\": \"" +
813 OUString::number(nMax
) + "\"}"
816 return "Select in '" +
818 "' {\"FROM\": \"" + OUString::number(nMin
) + "\", \"TO\": \"" +
819 OUString::number(nMax
) + "\"} from "
820 + get_top_parent(mxEdit
)->get_id()
824 return WindowUIObject::get_action(nEvent
);
827 OUString
EditUIObject::get_name() const
829 return "EditUIObject";
832 std::unique_ptr
<UIObject
> EditUIObject::create(vcl::Window
* pWindow
)
834 Edit
* pEdit
= dynamic_cast<Edit
*>(pWindow
);
836 return std::unique_ptr
<UIObject
>(new EditUIObject(pEdit
));
839 MultiLineEditUIObject::MultiLineEditUIObject(const VclPtr
<VclMultiLineEdit
>& xEdit
):
840 WindowUIObject(xEdit
),
845 MultiLineEditUIObject::~MultiLineEditUIObject()
849 void MultiLineEditUIObject::execute(const OUString
& rAction
,
850 const StringMap
& rParameters
)
852 bool bHandled
= true;
853 if (rAction
== "TYPE")
855 WindowUIObject
aChildObj(mxEdit
->GetTextWindow());
856 aChildObj
.execute(rAction
, rParameters
);
858 else if (rAction
== "SELECT")
860 if (rParameters
.find("FROM") != rParameters
.end() &&
861 rParameters
.find("TO") != rParameters
.end())
863 tools::Long nMin
= rParameters
.find("FROM")->second
.toInt32();
864 tools::Long nMax
= rParameters
.find("TO")->second
.toInt32();
865 Selection
aSelection(nMin
, nMax
);
866 mxEdit
->SetSelection(aSelection
);
875 WindowUIObject::execute(rAction
, rParameters
);
878 StringMap
MultiLineEditUIObject::get_state()
880 StringMap aMap
= WindowUIObject::get_state();
881 aMap
["MaxTextLength"] = OUString::number(mxEdit
->GetMaxTextLen());
882 aMap
["SelectedText"] = mxEdit
->GetSelected();
883 aMap
["Text"] = mxEdit
->GetText();
888 OUString
MultiLineEditUIObject::get_name() const
890 return "MultiLineEditUIObject";
893 std::unique_ptr
<UIObject
> MultiLineEditUIObject::create(vcl::Window
* pWindow
)
895 VclMultiLineEdit
* pEdit
= dynamic_cast<VclMultiLineEdit
*>(pWindow
);
897 return std::unique_ptr
<UIObject
>(new MultiLineEditUIObject(pEdit
));
900 ExpanderUIObject::ExpanderUIObject(const VclPtr
<VclExpander
>& xExpander
)
901 : WindowUIObject(xExpander
)
902 , mxExpander(xExpander
)
906 ExpanderUIObject::~ExpanderUIObject()
910 void ExpanderUIObject::execute(const OUString
& rAction
, const StringMap
& rParameters
)
912 if (rAction
== "EXPAND")
914 mxExpander
->set_expanded(true);
916 else if (rAction
== "COLLAPSE")
918 mxExpander
->set_expanded(false);
921 WindowUIObject::execute(rAction
, rParameters
);
924 StringMap
ExpanderUIObject::get_state()
926 StringMap aMap
= WindowUIObject::get_state();
927 aMap
["Expanded"] = OUString::boolean(mxExpander
->get_expanded());
931 OUString
ExpanderUIObject::get_name() const
933 return "ExpanderUIObject";
936 std::unique_ptr
<UIObject
> ExpanderUIObject::create(vcl::Window
* pWindow
)
938 VclExpander
* pVclExpander
= dynamic_cast<VclExpander
*>(pWindow
);
939 assert(pVclExpander
);
940 return std::unique_ptr
<UIObject
>(new ExpanderUIObject(pVclExpander
));
943 CheckBoxUIObject::CheckBoxUIObject(const VclPtr
<CheckBox
>& xCheckbox
):
944 WindowUIObject(xCheckbox
),
945 mxCheckBox(xCheckbox
)
949 CheckBoxUIObject::~CheckBoxUIObject()
953 void CheckBoxUIObject::execute(const OUString
& rAction
,
954 const StringMap
& rParameters
)
956 if (rAction
== "CLICK")
958 // don't use toggle directly, it does not set the value
959 mxCheckBox
->ImplCheck();
962 WindowUIObject::execute(rAction
, rParameters
);
965 StringMap
CheckBoxUIObject::get_state()
967 StringMap aMap
= WindowUIObject::get_state();
968 aMap
["Selected"] = OUString::boolean(mxCheckBox
->IsChecked());
969 aMap
["TriStateEnabled"] = OUString::boolean(mxCheckBox
->IsTriStateEnabled());
973 OUString
CheckBoxUIObject::get_name() const
975 return "CheckBoxUIObject";
978 OUString
CheckBoxUIObject::get_action(VclEventId nEvent
) const
980 if (nEvent
== VclEventId::CheckboxToggle
)
982 if(get_top_parent(mxCheckBox
)->get_id().isEmpty()){
983 //This part because if we don't have parent
984 return "Toggle '" + mxCheckBox
->get_id() + "' CheckBox";
986 return "Toggle '" + mxCheckBox
->get_id() + "' CheckBox from " +
987 get_top_parent(mxCheckBox
)->get_id();
990 return WindowUIObject::get_action(nEvent
);
993 std::unique_ptr
<UIObject
> CheckBoxUIObject::create(vcl::Window
* pWindow
)
995 CheckBox
* pCheckBox
= dynamic_cast<CheckBox
*>(pWindow
);
997 return std::unique_ptr
<UIObject
>(new CheckBoxUIObject(pCheckBox
));
1000 RadioButtonUIObject::RadioButtonUIObject(const VclPtr
<RadioButton
>& xRadioButton
):
1001 WindowUIObject(xRadioButton
),
1002 mxRadioButton(xRadioButton
)
1006 RadioButtonUIObject::~RadioButtonUIObject()
1010 void RadioButtonUIObject::execute(const OUString
& rAction
,
1011 const StringMap
& rParameters
)
1013 if (rAction
== "CLICK")
1015 mxRadioButton
->ImplCallClick();
1018 WindowUIObject::execute(rAction
, rParameters
);
1021 StringMap
RadioButtonUIObject::get_state()
1023 StringMap aMap
= WindowUIObject::get_state();
1024 aMap
["Checked"] = OUString::boolean(mxRadioButton
->IsChecked());
1025 aMap
["Enabled"] = OUString::boolean(mxRadioButton
->IsEnabled());
1030 OUString
RadioButtonUIObject::get_name() const
1032 return "RadioButtonUIObject";
1035 OUString
RadioButtonUIObject::get_action(VclEventId nEvent
) const
1037 if (nEvent
== VclEventId::RadiobuttonToggle
)
1039 if(get_top_parent(mxRadioButton
)->get_id().isEmpty()){
1040 //This part because if we don't have parent
1041 return "Select '" + mxRadioButton
->get_id() + "' RadioButton";
1043 return "Select '" + mxRadioButton
->get_id() + "' RadioButton from " +
1044 get_top_parent(mxRadioButton
)->get_id();
1047 return WindowUIObject::get_action(nEvent
);
1050 std::unique_ptr
<UIObject
> RadioButtonUIObject::create(vcl::Window
* pWindow
)
1052 RadioButton
* pRadioButton
= dynamic_cast<RadioButton
*>(pWindow
);
1053 assert(pRadioButton
);
1054 return std::unique_ptr
<UIObject
>(new RadioButtonUIObject(pRadioButton
));
1057 TabPageUIObject::TabPageUIObject(const VclPtr
<TabPage
>& xTabPage
):
1058 WindowUIObject(xTabPage
),
1063 TabPageUIObject::~TabPageUIObject()
1067 void TabPageUIObject::execute(const OUString
& rAction
,
1068 const StringMap
& rParameters
)
1070 WindowUIObject::execute(rAction
, rParameters
);
1073 StringMap
TabPageUIObject::get_state()
1075 StringMap aMap
= WindowUIObject::get_state();
1080 OUString
TabPageUIObject::get_name() const
1082 return "TabPageUIObject";
1085 ListBoxUIObject::ListBoxUIObject(const VclPtr
<ListBox
>& xListBox
):
1086 WindowUIObject(xListBox
),
1091 ListBoxUIObject::~ListBoxUIObject()
1095 void ListBoxUIObject::execute(const OUString
& rAction
,
1096 const StringMap
& rParameters
)
1098 if (!mxListBox
->IsEnabled())
1101 bool isTiledRendering
= comphelper::LibreOfficeKit::isActive();
1102 if (!isTiledRendering
&& !mxListBox
->IsReallyVisible())
1105 if (rAction
== "SELECT")
1107 bool bSelect
= true;
1108 if (rParameters
.find("POS") != rParameters
.end())
1110 auto itr
= rParameters
.find("POS");
1111 OUString aVal
= itr
->second
;
1112 sal_Int32 nPos
= aVal
.toInt32();
1113 mxListBox
->SelectEntryPos(nPos
, bSelect
);
1115 else if (rParameters
.find("TEXT") != rParameters
.end())
1117 auto itr
= rParameters
.find("TEXT");
1118 OUString aText
= itr
->second
;
1119 mxListBox
->SelectEntry(aText
, bSelect
);
1121 mxListBox
->Select();
1124 WindowUIObject::execute(rAction
, rParameters
);
1127 StringMap
ListBoxUIObject::get_state()
1129 StringMap aMap
= WindowUIObject::get_state();
1130 aMap
["ReadOnly"] = OUString::boolean(mxListBox
->IsReadOnly());
1131 aMap
["MultiSelect"] = OUString::boolean(mxListBox
->IsMultiSelectionEnabled());
1132 aMap
["EntryCount"] = OUString::number(mxListBox
->GetEntryCount());
1133 aMap
["SelectEntryCount"] = OUString::number(mxListBox
->GetSelectedEntryCount());
1134 aMap
["SelectEntryPos"] = OUString::number(mxListBox
->GetSelectedEntryPos());
1135 aMap
["SelectEntryText"] = mxListBox
->GetSelectedEntry();
1140 OUString
ListBoxUIObject::get_name() const
1142 return "ListBoxUIObject";
1145 OUString
ListBoxUIObject::get_action(VclEventId nEvent
) const
1147 if (nEvent
== VclEventId::ListboxSelect
)
1149 sal_Int32 nPos
= mxListBox
->GetSelectedEntryPos();
1150 if(get_top_parent(mxListBox
)->get_id().isEmpty()){
1151 //This part because if we don't have parent
1152 return "Select element with position " + OUString::number(nPos
) +
1153 " in '" + mxListBox
->get_id();
1155 return "Select element with position " + OUString::number(nPos
) +
1156 " in '" + mxListBox
->get_id() +"' from" + get_top_parent(mxListBox
)->get_id() ;
1158 else if (nEvent
== VclEventId::ListboxFocus
)
1160 if(get_top_parent(mxListBox
)->get_id().isEmpty())
1162 //This part because if we don't have parent
1163 return this->get_type() + " Action:FOCUS Id:" + mxListBox
->get_id();
1165 return this->get_type() + " Action:FOCUS Id:" + mxListBox
->get_id() +
1166 " Parent:" + get_top_parent(mxListBox
)->get_id();
1169 return WindowUIObject::get_action(nEvent
);
1172 std::unique_ptr
<UIObject
> ListBoxUIObject::create(vcl::Window
* pWindow
)
1174 ListBox
* pListBox
= dynamic_cast<ListBox
*>(pWindow
);
1176 return std::unique_ptr
<UIObject
>(new ListBoxUIObject(pListBox
));
1179 ComboBoxUIObject::ComboBoxUIObject(const VclPtr
<ComboBox
>& xComboBox
):
1180 WindowUIObject(xComboBox
),
1181 mxComboBox(xComboBox
)
1185 ComboBoxUIObject::~ComboBoxUIObject()
1189 void ComboBoxUIObject::execute(const OUString
& rAction
,
1190 const StringMap
& rParameters
)
1192 if (rAction
== "SELECT")
1194 if (rParameters
.find("POS") != rParameters
.end())
1196 auto itr
= rParameters
.find("POS");
1197 OUString aVal
= itr
->second
;
1198 sal_Int32 nPos
= aVal
.toInt32();
1199 mxComboBox
->SelectEntryPos(nPos
);
1201 else if(rParameters
.find("TEXT") != rParameters
.end()){
1202 auto itr
= rParameters
.find("TEXT");
1203 OUString aVal
= itr
->second
;
1204 sal_Int32 nPos
= mxComboBox
->GetEntryPos(aVal
);
1205 mxComboBox
->SelectEntryPos(nPos
);
1207 mxComboBox
->Select();
1209 else if ( rAction
== "TYPE" || rAction
== "SET" || rAction
== "CLEAR" ){
1210 if (mxComboBox
->GetSubEdit())
1212 Edit
* pEdit
= mxComboBox
->GetSubEdit();
1213 std::unique_ptr
<UIObject
> pObj
= EditUIObject::create(pEdit
);
1214 pObj
->execute(rAction
, rParameters
);
1217 WindowUIObject::execute(rAction
, rParameters
);
1220 WindowUIObject::execute(rAction
, rParameters
);
1223 StringMap
ComboBoxUIObject::get_state()
1225 StringMap aMap
= WindowUIObject::get_state();
1226 aMap
["SelectedText"] = mxComboBox
->GetSelected();
1227 aMap
["EntryCount"] = OUString::number(mxComboBox
->GetEntryCount());
1231 OUString
ComboBoxUIObject::get_name() const
1233 return "ComboBoxUIObject";
1236 OUString
ComboBoxUIObject::get_action(VclEventId nEvent
) const
1238 if (nEvent
== VclEventId::ComboboxSelect
)
1240 sal_Int32 nPos
= mxComboBox
->GetSelectedEntryPos();
1241 if (get_top_parent(mxComboBox
)->get_id().isEmpty()){
1242 //This part because if we don't have parent
1243 return "Select in '" + mxComboBox
->get_id() +
1244 "' ComboBox item number " + OUString::number(nPos
);
1246 return "Select in '" + mxComboBox
->get_id() +
1247 "' ComboBox item number " + OUString::number(nPos
) +
1248 " from " + get_top_parent(mxComboBox
)->get_id();
1251 return WindowUIObject::get_action(nEvent
);
1254 std::unique_ptr
<UIObject
> ComboBoxUIObject::create(vcl::Window
* pWindow
)
1256 ComboBox
* pComboBox
= dynamic_cast<ComboBox
*>(pWindow
);
1258 return std::unique_ptr
<UIObject
>(new ComboBoxUIObject(pComboBox
));
1261 SpinUIObject::SpinUIObject(const VclPtr
<SpinButton
>& xSpinButton
):
1262 WindowUIObject(xSpinButton
),
1263 mxSpinButton(xSpinButton
)
1267 SpinUIObject::~SpinUIObject()
1271 void SpinUIObject::execute(const OUString
& rAction
,
1272 const StringMap
& rParameters
)
1274 if (rAction
== "UP")
1278 else if (rAction
== "DOWN")
1280 mxSpinButton
->Down();
1283 WindowUIObject::execute(rAction
, rParameters
);
1286 StringMap
SpinUIObject::get_state()
1288 StringMap aMap
= WindowUIObject::get_state();
1289 aMap
["Min"] = OUString::number(mxSpinButton
->GetRangeMin());
1290 aMap
["Max"] = OUString::number(mxSpinButton
->GetRangeMax());
1291 aMap
["Step"] = OUString::number(mxSpinButton
->GetValueStep());
1292 aMap
["Value"] = OUString::number(mxSpinButton
->GetValue());
1297 OUString
SpinUIObject::get_action(VclEventId nEvent
) const
1299 if (nEvent
== VclEventId::SpinbuttonUp
)
1301 return this->get_type() + " Action:UP Id:" + mxSpinButton
->get_id() +
1302 " Parent:" + get_top_parent(mxSpinButton
)->get_id();
1304 else if (nEvent
== VclEventId::SpinbuttonDown
)
1306 return this->get_type() + " Action:DOWN Id:" + mxSpinButton
->get_id() +
1307 " Parent:" + get_top_parent(mxSpinButton
)->get_id();
1310 return WindowUIObject::get_action(nEvent
);
1313 OUString
SpinUIObject::get_name() const
1315 return "SpinUIObject";
1318 SpinFieldUIObject::SpinFieldUIObject(const VclPtr
<SpinField
>& xSpinField
):
1319 EditUIObject(xSpinField
),
1320 mxSpinField(xSpinField
)
1324 SpinFieldUIObject::~SpinFieldUIObject()
1328 void SpinFieldUIObject::execute(const OUString
& rAction
,
1329 const StringMap
& rParameters
)
1331 if (rAction
== "UP")
1335 else if (rAction
== "DOWN")
1337 mxSpinField
->Down();
1339 else if (rAction
== "TYPE")
1341 if (mxSpinField
->GetSubEdit())
1343 Edit
* pSubEdit
= mxSpinField
->GetSubEdit();
1344 EditUIObject
aSubObject(pSubEdit
);
1345 aSubObject
.execute(rAction
, rParameters
);
1349 EditUIObject::execute(rAction
, rParameters
);
1352 StringMap
SpinFieldUIObject::get_state()
1354 StringMap aMap
= EditUIObject::get_state();
1359 OUString
SpinFieldUIObject::get_action(VclEventId nEvent
) const
1361 if (nEvent
== VclEventId::SpinfieldUp
)
1363 if(get_top_parent(mxSpinField
)->get_id().isEmpty())
1365 //This part because if we don't have parent
1366 return "Increase '" + mxSpinField
->get_id();
1368 return "Increase '" + mxSpinField
->get_id() +
1369 "' from " + get_top_parent(mxSpinField
)->get_id();
1371 else if (nEvent
== VclEventId::SpinfieldDown
)
1373 if(get_top_parent(mxSpinField
)->get_id().isEmpty())
1375 //This part because if we don't have parent
1376 return "Decrease '" + mxSpinField
->get_id();
1378 return "Decrease '" + mxSpinField
->get_id() +
1379 "' from " + get_top_parent(mxSpinField
)->get_id();
1382 return WindowUIObject::get_action(nEvent
);
1385 OUString
SpinFieldUIObject::get_name() const
1387 return "SpinFieldUIObject";
1390 std::unique_ptr
<UIObject
> SpinFieldUIObject::create(vcl::Window
* pWindow
)
1392 SpinField
* pSpinField
= dynamic_cast<SpinField
*>(pWindow
);
1394 return std::unique_ptr
<UIObject
>(new SpinFieldUIObject(pSpinField
));
1398 MetricFieldUIObject::MetricFieldUIObject(const VclPtr
<MetricField
>& xMetricField
):
1399 SpinFieldUIObject(xMetricField
),
1400 mxMetricField(xMetricField
)
1404 MetricFieldUIObject::~MetricFieldUIObject()
1408 void MetricFieldUIObject::execute(const OUString
& rAction
,
1409 const StringMap
& rParameters
)
1411 if (rAction
== "VALUE")
1413 auto itPos
= rParameters
.find("VALUE");
1414 if (itPos
!= rParameters
.end())
1416 mxMetricField
->SetValueFromString(itPos
->second
);
1420 SpinFieldUIObject::execute(rAction
, rParameters
);
1423 StringMap
MetricFieldUIObject::get_state()
1425 StringMap aMap
= EditUIObject::get_state();
1426 aMap
["Value"] = mxMetricField
->GetValueString();
1431 OUString
MetricFieldUIObject::get_name() const
1433 return "MetricFieldUIObject";
1436 std::unique_ptr
<UIObject
> MetricFieldUIObject::create(vcl::Window
* pWindow
)
1438 MetricField
* pMetricField
= dynamic_cast<MetricField
*>(pWindow
);
1439 assert(pMetricField
);
1440 return std::unique_ptr
<UIObject
>(new MetricFieldUIObject(pMetricField
));
1443 FormattedFieldUIObject::FormattedFieldUIObject(const VclPtr
<FormattedField
>& xFormattedField
):
1444 SpinFieldUIObject(xFormattedField
),
1445 mxFormattedField(xFormattedField
)
1449 FormattedFieldUIObject::~FormattedFieldUIObject()
1453 void FormattedFieldUIObject::execute(const OUString
& rAction
,
1454 const StringMap
& rParameters
)
1456 if (rAction
== "VALUE")
1458 auto itPos
= rParameters
.find("VALUE");
1459 if (itPos
!= rParameters
.end())
1461 mxFormattedField
->SetValueFromString(itPos
->second
);
1465 SpinFieldUIObject::execute(rAction
, rParameters
);
1468 StringMap
FormattedFieldUIObject::get_state()
1470 StringMap aMap
= EditUIObject::get_state();
1471 aMap
["Value"] = OUString::number(mxFormattedField
->GetFormatter().GetValue());
1476 OUString
FormattedFieldUIObject::get_name() const
1478 return "FormattedFieldUIObject";
1481 std::unique_ptr
<UIObject
> FormattedFieldUIObject::create(vcl::Window
* pWindow
)
1483 FormattedField
* pFormattedField
= dynamic_cast<FormattedField
*>(pWindow
);
1484 assert(pFormattedField
);
1485 return std::unique_ptr
<UIObject
>(new FormattedFieldUIObject(pFormattedField
));
1488 TabControlUIObject::TabControlUIObject(const VclPtr
<TabControl
>& xTabControl
):
1489 WindowUIObject(xTabControl
),
1490 mxTabControl(xTabControl
)
1494 TabControlUIObject::~TabControlUIObject()
1498 void TabControlUIObject::execute(const OUString
& rAction
,
1499 const StringMap
& rParameters
)
1501 if (rAction
== "SELECT")
1503 if (rParameters
.find("POS") != rParameters
.end())
1505 auto itr
= rParameters
.find("POS");
1506 sal_uInt32 nPos
= itr
->second
.toUInt32();
1507 std::vector
<sal_uInt16
> aIds
= mxTabControl
->GetPageIDs();
1508 mxTabControl
->SelectTabPage(aIds
[nPos
]);
1512 WindowUIObject::execute(rAction
, rParameters
);
1515 StringMap
TabControlUIObject::get_state()
1517 StringMap aMap
= WindowUIObject::get_state();
1518 aMap
["PageCount"] = OUString::number(mxTabControl
->GetPageCount());
1520 sal_uInt16 nPageId
= mxTabControl
->GetCurPageId();
1521 aMap
["CurrPageId"] = OUString::number(nPageId
);
1522 aMap
["CurrPagePos"] = OUString::number(mxTabControl
->GetPagePos(nPageId
));
1527 OUString
TabControlUIObject::get_action(VclEventId nEvent
) const
1529 if (nEvent
== VclEventId::TabpageActivate
)
1531 sal_Int32 nPageId
= mxTabControl
->GetCurPageId();
1533 if(get_top_parent(mxTabControl
)->get_id().isEmpty()){
1534 //This part because if we don't have parent
1535 return "Choose Tab number " + OUString::number(mxTabControl
->GetPagePos(nPageId
)) +
1536 " in '" + mxTabControl
->get_id();
1538 return "Choose Tab number " + OUString::number(mxTabControl
->GetPagePos(nPageId
)) +
1539 " in '" + mxTabControl
->get_id()+
1540 "' from " + get_top_parent(mxTabControl
)->get_id() ;
1543 return WindowUIObject::get_action(nEvent
);
1546 OUString
TabControlUIObject::get_name() const
1548 return "TabControlUIObject";
1551 std::unique_ptr
<UIObject
> TabControlUIObject::create(vcl::Window
* pWindow
)
1553 TabControl
* pTabControl
= dynamic_cast<TabControl
*>(pWindow
);
1554 assert(pTabControl
);
1555 return std::unique_ptr
<UIObject
>(new TabControlUIObject(pTabControl
));
1558 RoadmapWizardUIObject::RoadmapWizardUIObject(const VclPtr
<vcl::RoadmapWizard
>& xRoadmapWizard
):
1559 WindowUIObject(xRoadmapWizard
),
1560 mxRoadmapWizard(xRoadmapWizard
)
1564 RoadmapWizardUIObject::~RoadmapWizardUIObject()
1568 void RoadmapWizardUIObject::execute(const OUString
& rAction
,
1569 const StringMap
& rParameters
)
1571 if (rAction
== "SELECT")
1573 if (rParameters
.find("POS") != rParameters
.end())
1575 auto itr
= rParameters
.find("POS");
1576 sal_uInt32 nPos
= itr
->second
.toUInt32();
1577 mxRoadmapWizard
->SelectRoadmapItemByID(nPos
);
1581 WindowUIObject::execute(rAction
, rParameters
);
1584 StringMap
RoadmapWizardUIObject::get_state()
1586 StringMap aMap
= WindowUIObject::get_state();
1588 aMap
["CurrentStep"] = OUString::number(mxRoadmapWizard
->GetCurrentRoadmapItemID());
1593 OUString
RoadmapWizardUIObject::get_name() const
1595 return "RoadmapWizardUIObject";
1598 std::unique_ptr
<UIObject
> RoadmapWizardUIObject::create(vcl::Window
* pWindow
)
1600 vcl::RoadmapWizard
* pRoadmapWizard
= dynamic_cast<vcl::RoadmapWizard
*>(pWindow
);
1601 assert(pRoadmapWizard
);
1602 return std::unique_ptr
<UIObject
>(new RoadmapWizardUIObject(pRoadmapWizard
));
1605 VerticalTabControlUIObject::VerticalTabControlUIObject(const VclPtr
<VerticalTabControl
>& xTabControl
):
1606 WindowUIObject(xTabControl
),
1607 mxTabControl(xTabControl
)
1611 VerticalTabControlUIObject::~VerticalTabControlUIObject()
1615 void VerticalTabControlUIObject::execute(const OUString
& rAction
,
1616 const StringMap
& rParameters
)
1618 if (rAction
== "SELECT")
1620 if (rParameters
.find("POS") != rParameters
.end())
1622 auto itr
= rParameters
.find("POS");
1623 sal_uInt32 nPos
= itr
->second
.toUInt32();
1624 OUString xid
= mxTabControl
->GetPageId(nPos
);
1625 mxTabControl
->SetCurPageId(xid
);
1629 WindowUIObject::execute(rAction
, rParameters
);
1632 StringMap
VerticalTabControlUIObject::get_state()
1634 StringMap aMap
= WindowUIObject::get_state();
1635 aMap
["PageCount"] = OUString::number(mxTabControl
->GetPageCount());
1637 OUString nPageId
= mxTabControl
->GetCurPageId();
1638 aMap
["CurrPageTitel"] = mxTabControl
->GetPageText(nPageId
);
1639 aMap
["CurrPagePos"] = OUString::number(mxTabControl
->GetPagePos(nPageId
));
1644 OUString
VerticalTabControlUIObject::get_name() const
1646 return "VerticalTabControlUIObject";
1649 std::unique_ptr
<UIObject
> VerticalTabControlUIObject::create(vcl::Window
* pWindow
)
1651 VerticalTabControl
* pTabControl
= dynamic_cast<VerticalTabControl
*>(pWindow
);
1652 assert(pTabControl
);
1653 return std::unique_ptr
<UIObject
>(new VerticalTabControlUIObject(pTabControl
));
1657 ToolBoxUIObject::ToolBoxUIObject(const VclPtr
<ToolBox
>& xToolBox
):
1658 WindowUIObject(xToolBox
),
1663 ToolBoxUIObject::~ToolBoxUIObject()
1667 void ToolBoxUIObject::execute(const OUString
& rAction
,
1668 const StringMap
& rParameters
)
1670 if (rAction
== "CLICK")
1672 if (rParameters
.find("POS") != rParameters
.end())
1674 auto itr
= rParameters
.find("POS");
1675 sal_uInt16 nPos
= itr
->second
.toUInt32();
1676 mxToolBox
->SetCurItemId(mxToolBox
->GetItemId(nPos
));
1678 mxToolBox
->Select();
1682 WindowUIObject::execute(rAction
, rParameters
);
1685 OUString
ToolBoxUIObject::get_action(VclEventId nEvent
) const
1687 if (nEvent
== VclEventId::ToolboxClick
)
1689 return "Click on item number " + OUString::number(sal_uInt16(mxToolBox
->GetCurItemId())) +
1690 " in " + mxToolBox
->get_id();
1693 return WindowUIObject::get_action(nEvent
);
1696 StringMap
ToolBoxUIObject::get_state()
1698 StringMap aMap
= WindowUIObject::get_state();
1699 aMap
["CurrSelectedItemID"] = OUString::number(sal_uInt16(mxToolBox
->GetCurItemId()));
1700 aMap
["CurrSelectedItemText"] = mxToolBox
->GetItemText(mxToolBox
->GetCurItemId());
1701 aMap
["CurrSelectedItemCommand"] = mxToolBox
->GetItemCommand(mxToolBox
->GetCurItemId());
1702 aMap
["ItemCount"] = OUString::number(mxToolBox
->GetItemCount());
1706 OUString
ToolBoxUIObject::get_name() const
1708 return "ToolBoxUIObject";
1711 std::unique_ptr
<UIObject
> ToolBoxUIObject::create(vcl::Window
* pWindow
)
1713 ToolBox
* pToolBox
= dynamic_cast<ToolBox
*>(pWindow
);
1715 return std::unique_ptr
<UIObject
>(new ToolBoxUIObject(pToolBox
));
1718 MenuButtonUIObject::MenuButtonUIObject(const VclPtr
<MenuButton
>& xMenuButton
):
1719 WindowUIObject(xMenuButton
),
1720 mxMenuButton(xMenuButton
)
1724 MenuButtonUIObject::~MenuButtonUIObject()
1728 StringMap
MenuButtonUIObject::get_state()
1730 StringMap aMap
= WindowUIObject::get_state();
1731 aMap
["Label"] = mxMenuButton
->GetDisplayText();
1732 aMap
["CurrentItem"] = mxMenuButton
->GetCurItemIdent();
1736 void MenuButtonUIObject::execute(const OUString
& rAction
,
1737 const StringMap
& rParameters
)
1739 if (rAction
== "CLICK")
1741 mxMenuButton
->Check(!mxMenuButton
->IsChecked());
1742 mxMenuButton
->Toggle();
1744 else if (rAction
== "OPENLIST")
1746 mxMenuButton
->ExecuteMenu();
1748 else if (rAction
== "OPENFROMLIST")
1750 auto itr
= rParameters
.find("POS");
1751 sal_uInt32 nPos
= itr
->second
.toUInt32();
1753 sal_uInt32 nId
= mxMenuButton
->GetPopupMenu()->GetItemId(nPos
);
1754 mxMenuButton
->GetPopupMenu()->SetSelectedEntry(nId
);
1755 mxMenuButton
->SetCurItemId();
1756 mxMenuButton
->Select();
1758 else if (rAction
== "CLOSELIST")
1760 mxMenuButton
->GetPopupMenu()->EndExecute();
1763 WindowUIObject::execute(rAction
, rParameters
);
1766 OUString
MenuButtonUIObject::get_name() const
1768 return "MenuButtonUIObject";
1771 std::unique_ptr
<UIObject
> MenuButtonUIObject::create(vcl::Window
* pWindow
)
1773 MenuButton
* pMenuButton
= dynamic_cast<MenuButton
*>(pWindow
);
1774 assert(pMenuButton
);
1775 return std::unique_ptr
<UIObject
>(new MenuButtonUIObject(pMenuButton
));
1778 DrawingAreaUIObject::DrawingAreaUIObject(const VclPtr
<vcl::Window
>& rDrawingArea
)
1779 : WindowUIObject(rDrawingArea
)
1780 , mxDrawingArea(dynamic_cast<VclDrawingArea
*>(rDrawingArea
.get()))
1782 assert(mxDrawingArea
);
1783 mpController
= static_cast<weld::CustomWidgetController
*>(mxDrawingArea
->GetUserData());
1786 DrawingAreaUIObject::~DrawingAreaUIObject()
1790 void DrawingAreaUIObject::execute(const OUString
& rAction
, const StringMap
& rParameters
)
1792 if (rAction
== "CLICK")
1794 // POSX and POSY are percentage of width/height dimensions
1795 if (rParameters
.find("POSX") != rParameters
.end() &&
1796 rParameters
.find("POSY") != rParameters
.end())
1798 auto aPosX
= rParameters
.find("POSX");
1799 auto aPosY
= rParameters
.find("POSY");
1801 OString sPosX2
= OUStringToOString(aPosX
->second
, RTL_TEXTENCODING_ASCII_US
);
1802 OString sPoxY2
= OUStringToOString(aPosY
->second
, RTL_TEXTENCODING_ASCII_US
);
1804 if (!sPosX2
.isEmpty() && !sPoxY2
.isEmpty())
1806 double fPosX
= std::atof(sPosX2
.getStr());
1807 double fPosY
= std::atof(sPoxY2
.getStr());
1809 fPosX
= fPosX
* mxDrawingArea
->GetOutputSizePixel().Width();
1810 fPosY
= fPosY
* mxDrawingArea
->GetOutputSizePixel().Height();
1812 MouseEvent
aEvent(Point(fPosX
, fPosY
), 1, MouseEventModifiers::NONE
, MOUSE_LEFT
, 0);
1813 mxDrawingArea
->MouseButtonDown(aEvent
);
1814 mxDrawingArea
->MouseButtonUp(aEvent
);
1819 WindowUIObject::execute(rAction
, rParameters
);
1822 std::unique_ptr
<UIObject
> DrawingAreaUIObject::create(vcl::Window
* pWindow
)
1824 VclDrawingArea
* pVclDrawingArea
= dynamic_cast<VclDrawingArea
*>(pWindow
);
1825 assert(pVclDrawingArea
);
1826 return std::unique_ptr
<UIObject
>(new DrawingAreaUIObject(pVclDrawingArea
));
1829 IconViewUIObject::IconViewUIObject(const VclPtr
<SvTreeListBox
>& xIconView
):
1830 TreeListUIObject(xIconView
)
1834 StringMap
IconViewUIObject::get_state()
1836 StringMap aMap
= TreeListUIObject::get_state();
1838 SvTreeListEntry
* pEntry
= mxTreeList
->FirstSelected();
1840 OUString
* pId
= static_cast<OUString
*>(pEntry
->GetUserData());
1842 aMap
["SelectedItemId"] = *pId
;
1844 SvTreeList
* pModel
= mxTreeList
->GetModel();
1846 aMap
["SelectedItemPos"] = OUString::number(pModel
->GetAbsPos(pEntry
));
1851 OUString
IconViewUIObject::get_name() const
1853 return "IconViewUIObject";
1856 std::unique_ptr
<UIObject
> IconViewUIObject::create(vcl::Window
* pWindow
)
1858 SvTreeListBox
* pTreeList
= dynamic_cast<SvTreeListBox
*>(pWindow
);
1860 return std::unique_ptr
<UIObject
>(new IconViewUIObject(pTreeList
));
1863 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */