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/.
11 #include <uiobject.hxx>
13 #include <ChartWindow.hxx>
14 #include <ChartView.hxx>
15 #include <ChartController.hxx>
16 #include <ChartModel.hxx>
17 #include <ObjectHierarchy.hxx>
18 #include <chartview/ExplicitValueProvider.hxx>
20 #include <comphelper/servicehelper.hxx>
23 #include <vcl/svapp.hxx>
28 ChartUIObject::ChartUIObject(const VclPtr
<chart::ChartWindow
>& xChartWindow
,
30 maCID(std::move(aCID
)),
31 mxChartWindow(xChartWindow
)
35 StringMap
ChartUIObject::get_state()
43 void ChartUIObject::execute(const OUString
& rAction
,
44 const StringMap
& rParameters
)
46 if (rAction
== "SELECT")
48 std::unique_ptr
<UIObject
> pWindow
= mxChartWindow
->GetUITestFactory()(mxChartWindow
.get());
51 aParams
["NAME"] = maCID
;
52 pWindow
->execute(rAction
, aParams
);
54 else if (rAction
== "COMMAND")
56 // first select object
57 std::unique_ptr
<UIObject
> pWindow
= mxChartWindow
->GetUITestFactory()(mxChartWindow
.get());
60 aParams
["NAME"] = maCID
;
61 pWindow
->execute("SELECT", aParams
);
63 auto itr
= rParameters
.find("COMMAND");
64 if (itr
== rParameters
.end())
65 throw css::uno::RuntimeException("missing COMMAND parameter");
67 maCommands
.emplace_back(new OUString(itr
->second
));
68 OUString
* pCommand
= maCommands
.rbegin()->get();
70 Application::PostUserEvent(LINK(this, ChartUIObject
, PostCommand
), pCommand
);
74 IMPL_LINK(ChartUIObject
, PostCommand
, void*, pCommand
, void)
77 aURL
.Path
= *static_cast<OUString
*>(pCommand
);
78 mxChartWindow
->GetController()->dispatch(aURL
, css::uno::Sequence
<css::beans::PropertyValue
>());
81 std::unique_ptr
<UIObject
> ChartUIObject::get_child(const OUString
& rID
)
83 std::unique_ptr
<UIObject
> pWindow
= mxChartWindow
->GetUITestFactory()(mxChartWindow
.get());
85 return pWindow
->get_child(rID
);
88 std::set
<OUString
> ChartUIObject::get_children() const
90 std::unique_ptr
<UIObject
> pWindow
= mxChartWindow
->GetUITestFactory()(mxChartWindow
.get());
92 return pWindow
->get_children();
95 OUString
ChartUIObject::get_type() const
97 return "ChartUIObject for type: ";
100 ChartWindowUIObject::ChartWindowUIObject(const VclPtr
<chart::ChartWindow
>& xChartWindow
):
101 WindowUIObject(xChartWindow
),
102 mxChartWindow(xChartWindow
)
106 StringMap
ChartWindowUIObject::get_state()
108 StringMap aMap
= WindowUIObject::get_state();
110 chart::ChartController
* pController
= mxChartWindow
->GetController();
113 css::uno::Any aAny
= pController
->getSelection();
114 OUString aSelectedObject
;
115 aAny
>>= aSelectedObject
;
116 aMap
["SelectedObject"] = aSelectedObject
;
122 void ChartWindowUIObject::execute(const OUString
& rAction
,
123 const StringMap
& rParameters
)
125 if (rAction
== "SELECT")
127 auto itr
= rParameters
.find("NAME");
128 if (itr
== rParameters
.end())
129 throw css::uno::RuntimeException("Missing Parameter 'NAME' for action 'SELECT'");
132 const OUString
& rName
= itr
->second
;
136 chart::ChartController
* pController
= mxChartWindow
->GetController();
137 pController
->select(aAny
);
140 WindowUIObject::execute(rAction
, rParameters
);
143 std::unique_ptr
<UIObject
> ChartWindowUIObject::get_child(const OUString
& rID
)
145 if (chart::ObjectIdentifier::isCID(rID
))
146 return std::unique_ptr
<UIObject
>(new ChartUIObject(mxChartWindow
, rID
));
148 throw css::uno::RuntimeException("unknown child");
153 void recursiveAdd(chart::ObjectIdentifier
const & rID
, std::set
<OUString
>& rChildren
, const chart::ObjectHierarchy
& rHierarchy
)
155 std::vector
<chart::ObjectIdentifier
> aChildIdentifiers
= rHierarchy
.getChildren(rID
);
156 std::transform(aChildIdentifiers
.begin(), aChildIdentifiers
.end(), std::inserter(rChildren
, rChildren
.begin()),
157 [](const chart::ObjectIdentifier
& rObject
)
159 return rObject
.getObjectCID();
163 for (const chart::ObjectIdentifier
& ID
: aChildIdentifiers
)
164 recursiveAdd(ID
, rChildren
, rHierarchy
);
169 std::set
<OUString
> ChartWindowUIObject::get_children() const
171 std::set
<OUString
> aChildren
;
173 chart::ChartController
* pController
= mxChartWindow
->GetController();
177 rtl::Reference
<::chart::ChartModel
> xChartDoc
= pController
->getChartModel();
178 rtl::Reference
<::chart::ChartView
> xChartView
= pController
->getChartView();
179 chart::ExplicitValueProvider
* pValueProvider
= xChartView
.get();
180 chart::ObjectHierarchy
aHierarchy(xChartDoc
, pValueProvider
);
181 chart::ObjectIdentifier aIdentifier
= chart::ObjectHierarchy::getRootNodeOID();
182 aChildren
.insert(aIdentifier
.getObjectCID());
184 recursiveAdd(aIdentifier
, aChildren
, aHierarchy
);
189 std::unique_ptr
<UIObject
> ChartWindowUIObject::create(vcl::Window
* pWindow
)
191 chart::ChartWindow
* pChartWindow
= dynamic_cast<chart::ChartWindow
*>(pWindow
);
192 assert(pChartWindow
);
194 return std::unique_ptr
<UIObject
>(new ChartWindowUIObject(pChartWindow
));
197 OUString
ChartWindowUIObject::get_name() const
199 return "ChartWindowUIObject";
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */