/src/libreoffice/vcl/source/uitest/toolboxuiobject.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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 | | */ |
9 | | |
10 | | #include <uitest/toolboxitemuiobject.hxx> |
11 | | #include <uitest/toolboxuiobject.hxx> |
12 | | |
13 | | #include <o3tl/string_view.hxx> |
14 | | #include <vcl/toolbox.hxx> |
15 | | #include <vcl/vclevent.hxx> |
16 | | |
17 | | constexpr OUString TOOLBOX_ITEM_ID_PREFIX = u"toolboxitem-"_ustr; |
18 | | |
19 | | ToolBoxUIObject::ToolBoxUIObject(const VclPtr<ToolBox>& xToolBox) |
20 | 0 | : WindowUIObject(xToolBox) |
21 | 0 | , mxToolBox(xToolBox) |
22 | 0 | { |
23 | 0 | } |
24 | | |
25 | 0 | ToolBoxUIObject::~ToolBoxUIObject() {} |
26 | | |
27 | | void ToolBoxUIObject::execute(const OUString& rAction, const StringMap& rParameters) |
28 | 0 | { |
29 | 0 | if (rAction == "CLICK") |
30 | 0 | { |
31 | 0 | if (rParameters.find(u"POS"_ustr) != rParameters.end()) |
32 | 0 | { |
33 | 0 | auto itr = rParameters.find(u"POS"_ustr); |
34 | 0 | sal_uInt16 nPos = itr->second.toUInt32(); |
35 | 0 | mxToolBox->SetCurItemId(mxToolBox->GetItemId(nPos)); |
36 | 0 | mxToolBox->Click(); |
37 | 0 | mxToolBox->Select(); |
38 | 0 | } |
39 | 0 | } |
40 | 0 | else |
41 | 0 | WindowUIObject::execute(rAction, rParameters); |
42 | 0 | } |
43 | | |
44 | | OUString ToolBoxUIObject::get_action(VclEventId nEvent) const |
45 | 0 | { |
46 | 0 | if (nEvent == VclEventId::ToolboxClick) |
47 | 0 | { |
48 | 0 | return "Click on item number " + OUString::number(sal_uInt16(mxToolBox->GetCurItemId())) |
49 | 0 | + " in " + mxToolBox->get_id(); |
50 | 0 | } |
51 | 0 | else |
52 | 0 | return WindowUIObject::get_action(nEvent); |
53 | 0 | } |
54 | | |
55 | | StringMap ToolBoxUIObject::get_state() |
56 | 0 | { |
57 | 0 | StringMap aMap = WindowUIObject::get_state(); |
58 | 0 | ToolBoxItemId nCurItemId = mxToolBox->GetCurItemId(); |
59 | 0 | aMap[u"CurrSelectedItemID"_ustr] = OUString::number(sal_uInt16(nCurItemId)); |
60 | 0 | aMap[u"CurrSelectedItemText"_ustr] = nCurItemId ? mxToolBox->GetItemText(nCurItemId) : u""_ustr; |
61 | 0 | aMap[u"CurrSelectedItemCommand"_ustr] |
62 | 0 | = nCurItemId ? mxToolBox->GetItemCommand(nCurItemId) : u""_ustr; |
63 | 0 | aMap[u"ItemCount"_ustr] = OUString::number(mxToolBox->GetItemCount()); |
64 | 0 | return aMap; |
65 | 0 | } |
66 | | |
67 | | std::set<OUString> ToolBoxUIObject::get_children() const |
68 | 0 | { |
69 | 0 | std::set<OUString> aChildren = WindowUIObject::get_children(); |
70 | |
|
71 | 0 | const size_t nItemCount = mxToolBox->GetItemCount(); |
72 | 0 | for (size_t i = 0; i < nItemCount; ++i) |
73 | 0 | { |
74 | 0 | const OUString sId |
75 | 0 | = TOOLBOX_ITEM_ID_PREFIX + OUString::number(sal_uInt16(mxToolBox->GetItemId(i))); |
76 | 0 | aChildren.insert(sId); |
77 | 0 | } |
78 | |
|
79 | 0 | return aChildren; |
80 | 0 | } |
81 | | |
82 | | std::unique_ptr<UIObject> ToolBoxUIObject::get_child(const OUString& rID) |
83 | 0 | { |
84 | 0 | if (rID.startsWith(TOOLBOX_ITEM_ID_PREFIX)) |
85 | 0 | { |
86 | 0 | const sal_Int32 nPrefixLength = TOOLBOX_ITEM_ID_PREFIX.getLength(); |
87 | 0 | const ToolBoxItemId nItemId(o3tl::toInt32(rID.subView(nPrefixLength))); |
88 | 0 | return std::make_unique<ToolBoxItemUIObject>(mxToolBox, nItemId); |
89 | 0 | } |
90 | | |
91 | 0 | return WindowUIObject::get_child(rID); |
92 | 0 | } |
93 | | |
94 | 0 | OUString ToolBoxUIObject::get_name() const { return u"ToolBoxUIObject"_ustr; } |
95 | | |
96 | | std::unique_ptr<UIObject> ToolBoxUIObject::create(vcl::Window* pWindow) |
97 | 0 | { |
98 | 0 | ToolBox* pToolBox = dynamic_cast<ToolBox*>(pWindow); |
99 | | assert(pToolBox); |
100 | 0 | return std::unique_ptr<UIObject>(new ToolBoxUIObject(pToolBox)); |
101 | 0 | } |
102 | | |
103 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |