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>
17 #include <com/sun/star/chart2/XChartDocument.hpp>
19 #include <comphelper/servicehelper.hxx>
21 #include <vcl/svapp.hxx>
26 ChartUIObject::ChartUIObject(const VclPtr
<chart::ChartWindow
>& xChartWindow
,
27 const OUString
& rCID
):
29 mxChartWindow(xChartWindow
)
33 StringMap
ChartUIObject::get_state()
41 void ChartUIObject::execute(const OUString
& rAction
,
42 const StringMap
& rParameters
)
44 if (rAction
== "SELECT")
46 std::unique_ptr
<UIObject
> pWindow
= mxChartWindow
->GetUITestFactory()(mxChartWindow
.get());
49 aParams
["NAME"] = maCID
;
50 pWindow
->execute(rAction
, aParams
);
52 else if (rAction
== "COMMAND")
54 // first select object
55 std::unique_ptr
<UIObject
> pWindow
= mxChartWindow
->GetUITestFactory()(mxChartWindow
.get());
58 aParams
["NAME"] = maCID
;
59 pWindow
->execute("SELECT", aParams
);
61 auto itr
= rParameters
.find("COMMAND");
62 if (itr
== rParameters
.end())
63 throw css::uno::RuntimeException("missing COMMAND parameter");
65 maCommands
.emplace_back(new OUString(itr
->second
));
66 OUString
* pCommand
= maCommands
.rbegin()->get();
68 Application::PostUserEvent(LINK(this, ChartUIObject
, PostCommand
), pCommand
);
72 IMPL_LINK(ChartUIObject
, PostCommand
, void*, pCommand
, void)
75 aURL
.Path
= *static_cast<OUString
*>(pCommand
);
76 mxChartWindow
->GetController()->dispatch(aURL
, css::uno::Sequence
<css::beans::PropertyValue
>());
79 std::unique_ptr
<UIObject
> ChartUIObject::get_child(const OUString
& rID
)
81 std::unique_ptr
<UIObject
> pWindow
= mxChartWindow
->GetUITestFactory()(mxChartWindow
.get());
83 return pWindow
->get_child(rID
);
86 std::set
<OUString
> ChartUIObject::get_children() const
88 std::unique_ptr
<UIObject
> pWindow
= mxChartWindow
->GetUITestFactory()(mxChartWindow
.get());
90 return pWindow
->get_children();
93 OUString
ChartUIObject::get_type() const
95 return "ChartUIObject for type: ";
98 ChartWindowUIObject::ChartWindowUIObject(const VclPtr
<chart::ChartWindow
>& xChartWindow
):
99 WindowUIObject(xChartWindow
),
100 mxChartWindow(xChartWindow
)
104 StringMap
ChartWindowUIObject::get_state()
106 StringMap aMap
= WindowUIObject::get_state();
108 chart::ChartController
* pController
= mxChartWindow
->GetController();
111 css::uno::Any aAny
= pController
->getSelection();
112 OUString aSelectedObject
;
113 aAny
>>= aSelectedObject
;
114 aMap
["SelectedObject"] = aSelectedObject
;
120 void ChartWindowUIObject::execute(const OUString
& rAction
,
121 const StringMap
& rParameters
)
123 if (rAction
== "SELECT")
125 auto itr
= rParameters
.find("NAME");
126 if (itr
== rParameters
.end())
127 throw css::uno::RuntimeException("Missing Parameter 'NAME' for action 'SELECT'");
130 const OUString
& rName
= itr
->second
;
134 chart::ChartController
* pController
= mxChartWindow
->GetController();
135 pController
->select(aAny
);
138 WindowUIObject::execute(rAction
, rParameters
);
141 std::unique_ptr
<UIObject
> ChartWindowUIObject::get_child(const OUString
& rID
)
143 if (chart::ObjectIdentifier::isCID(rID
))
144 return std::unique_ptr
<UIObject
>(new ChartUIObject(mxChartWindow
, rID
));
146 throw css::uno::RuntimeException("unknown child");
151 void recursiveAdd(chart::ObjectIdentifier
const & rID
, std::set
<OUString
>& rChildren
, const chart::ObjectHierarchy
& rHierarchy
)
153 std::vector
<chart::ObjectIdentifier
> aChildIndentifiers
= rHierarchy
.getChildren(rID
);
154 std::transform(aChildIndentifiers
.begin(), aChildIndentifiers
.end(), std::inserter(rChildren
, rChildren
.begin()),
155 [](const chart::ObjectIdentifier
& rObject
)
157 return rObject
.getObjectCID();
161 for (const chart::ObjectIdentifier
& ID
: aChildIndentifiers
)
162 recursiveAdd(ID
, rChildren
, rHierarchy
);
167 std::set
<OUString
> ChartWindowUIObject::get_children() const
169 std::set
<OUString
> aChildren
;
171 chart::ChartController
* pController
= mxChartWindow
->GetController();
175 css::uno::Reference
< css::chart2::XChartDocument
> xChartDoc( pController
->getModel(), css::uno::UNO_QUERY
);
177 css::uno::Reference
<css::uno::XInterface
> xChartView
= pController
->getChartView();
178 chart::ExplicitValueProvider
* pValueProvider
= comphelper::getUnoTunnelImplementation
<chart::ExplicitValueProvider
>( xChartView
);
179 chart::ObjectHierarchy
aHierarchy(xChartDoc
, pValueProvider
, true);
180 chart::ObjectIdentifier aIdentifier
= chart::ObjectHierarchy::getRootNodeOID();
181 aChildren
.insert(aIdentifier
.getObjectCID());
183 recursiveAdd(aIdentifier
, aChildren
, aHierarchy
);
188 std::unique_ptr
<UIObject
> ChartWindowUIObject::create(vcl::Window
* pWindow
)
190 chart::ChartWindow
* pChartWindow
= dynamic_cast<chart::ChartWindow
*>(pWindow
);
191 assert(pChartWindow
);
193 return std::unique_ptr
<UIObject
>(new ChartWindowUIObject(pChartWindow
));
196 OUString
ChartWindowUIObject::get_name() const
198 return "ChartWindowUIObject";
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */