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 <ChartController.hxx>
15 #include <ObjectHierarchy.hxx>
16 #include <chartview/ExplicitValueProvider.hxx>
18 #include <vcl/svapp.hxx>
23 ChartUIObject::ChartUIObject(const VclPtr
<chart::ChartWindow
>& xChartWindow
,
24 const OUString
& rCID
):
26 mxChartWindow(xChartWindow
)
30 StringMap
ChartUIObject::get_state()
38 void ChartUIObject::execute(const OUString
& rAction
,
39 const StringMap
& rParameters
)
41 if (rAction
== "SELECT")
43 std::unique_ptr
<UIObject
> pWindow
= mxChartWindow
->GetUITestFactory()(mxChartWindow
.get());
46 aParams
["NAME"] = maCID
;
47 pWindow
->execute(rAction
, aParams
);
49 else if (rAction
== "COMMAND")
51 // first select object
52 std::unique_ptr
<UIObject
> pWindow
= mxChartWindow
->GetUITestFactory()(mxChartWindow
.get());
55 aParams
["NAME"] = maCID
;
56 pWindow
->execute("SELECT", aParams
);
58 auto itr
= rParameters
.find("COMMAND");
59 if (itr
== rParameters
.end())
60 throw css::uno::RuntimeException("missing COMMAND parameter");
62 maCommands
.emplace_back(new OUString(itr
->second
));
63 OUString
* pCommand
= maCommands
.rbegin()->get();
65 Application::PostUserEvent(LINK(this, ChartUIObject
, PostCommand
), pCommand
);
69 IMPL_LINK(ChartUIObject
, PostCommand
, void*, pCommand
, void)
72 aURL
.Path
= *static_cast<OUString
*>(pCommand
);
73 mxChartWindow
->GetController()->dispatch(aURL
, css::uno::Sequence
<css::beans::PropertyValue
>());
76 std::unique_ptr
<UIObject
> ChartUIObject::get_child(const OUString
& rID
)
78 std::unique_ptr
<UIObject
> pWindow
= mxChartWindow
->GetUITestFactory()(mxChartWindow
.get());
80 return pWindow
->get_child(rID
);
83 std::set
<OUString
> ChartUIObject::get_children() const
85 std::unique_ptr
<UIObject
> pWindow
= mxChartWindow
->GetUITestFactory()(mxChartWindow
.get());
87 return pWindow
->get_children();
90 OUString
ChartUIObject::get_type() const
92 return OUString("ChartUIObject for type: ");
95 ChartWindowUIObject::ChartWindowUIObject(const VclPtr
<chart::ChartWindow
>& xChartWindow
):
96 WindowUIObject(xChartWindow
),
97 mxChartWindow(xChartWindow
)
101 StringMap
ChartWindowUIObject::get_state()
103 StringMap aMap
= WindowUIObject::get_state();
105 chart::ChartController
* pController
= mxChartWindow
->GetController();
108 css::uno::Any aAny
= pController
->getSelection();
109 OUString aSelectedObject
;
110 aAny
>>= aSelectedObject
;
111 aMap
["SelectedObject"] = aSelectedObject
;
117 void ChartWindowUIObject::execute(const OUString
& rAction
,
118 const StringMap
& rParameters
)
120 if (rAction
== "SELECT")
122 auto itr
= rParameters
.find("NAME");
123 if (itr
== rParameters
.end())
124 throw css::uno::RuntimeException("Missing Parameter 'NAME' for action 'SELECT'");
127 const OUString
& rName
= itr
->second
;
131 chart::ChartController
* pController
= mxChartWindow
->GetController();
132 pController
->select(aAny
);
135 WindowUIObject::execute(rAction
, rParameters
);
138 std::unique_ptr
<UIObject
> ChartWindowUIObject::get_child(const OUString
& rID
)
140 if (chart::ObjectIdentifier::isCID(rID
))
141 return std::unique_ptr
<UIObject
>(new ChartUIObject(mxChartWindow
, rID
));
143 throw css::uno::RuntimeException("unknown child");
148 void recursiveAdd(chart::ObjectIdentifier
const & rID
, std::set
<OUString
>& rChildren
, const chart::ObjectHierarchy
& rHierarchy
)
150 std::vector
<chart::ObjectIdentifier
> aChildIndentifiers
= rHierarchy
.getChildren(rID
);
151 std::transform(aChildIndentifiers
.begin(), aChildIndentifiers
.end(), std::inserter(rChildren
, rChildren
.begin()),
152 [](const chart::ObjectIdentifier
& rObject
)
154 return rObject
.getObjectCID();
158 for (chart::ObjectIdentifier
& ID
: aChildIndentifiers
)
159 recursiveAdd(ID
, rChildren
, rHierarchy
);
164 std::set
<OUString
> ChartWindowUIObject::get_children() const
166 std::set
<OUString
> aChildren
;
168 chart::ChartController
* pController
= mxChartWindow
->GetController();
172 css::uno::Reference
< css::chart2::XChartDocument
> xChartDoc( pController
->getModel(), css::uno::UNO_QUERY
);
174 css::uno::Reference
<css::uno::XInterface
> xChartView
= pController
->getChartView();
175 chart::ExplicitValueProvider
* pValueProvider
= chart::ExplicitValueProvider::getExplicitValueProvider( xChartView
);
176 chart::ObjectHierarchy
aHierarchy(xChartDoc
, pValueProvider
, true);
177 chart::ObjectIdentifier aIdentifier
= chart::ObjectHierarchy::getRootNodeOID();
178 aChildren
.insert(aIdentifier
.getObjectCID());
180 recursiveAdd(aIdentifier
, aChildren
, aHierarchy
);
185 std::unique_ptr
<UIObject
> ChartWindowUIObject::create(vcl::Window
* pWindow
)
187 chart::ChartWindow
* pChartWindow
= dynamic_cast<chart::ChartWindow
*>(pWindow
);
188 assert(pChartWindow
);
190 return std::unique_ptr
<UIObject
>(new ChartWindowUIObject(pChartWindow
));
193 OUString
ChartWindowUIObject::get_name() const
195 return OUString("ChartWindowUIObject");
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */