LibreOffice Module chart2 (master) 1
uiobject.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <memory>
11#include <uiobject.hxx>
12
13#include <ChartWindow.hxx>
14#include <ChartView.hxx>
15#include <ChartController.hxx>
16#include <ChartModel.hxx>
17#include <ObjectHierarchy.hxx>
19
21
22#include <utility>
23#include <vcl/svapp.hxx>
24
25#include <algorithm>
26#include <iterator>
27
29 OUString aCID):
30 maCID(std::move(aCID)),
31 mxChartWindow(xChartWindow)
32{
33}
34
36{
38 aMap["CID"] = maCID;
39
40 return aMap;
41}
42
43void ChartUIObject::execute(const OUString& rAction,
44 const StringMap& rParameters)
45{
46 if (rAction == "SELECT")
47 {
48 std::unique_ptr<UIObject> pWindow = mxChartWindow->GetUITestFactory()(mxChartWindow.get());
49
50 StringMap aParams;
51 aParams["NAME"] = maCID;
52 pWindow->execute(rAction, aParams);
53 }
54 else if (rAction == "COMMAND")
55 {
56 // first select object
57 std::unique_ptr<UIObject> pWindow = mxChartWindow->GetUITestFactory()(mxChartWindow.get());
58
59 StringMap aParams;
60 aParams["NAME"] = maCID;
61 pWindow->execute("SELECT", aParams);
62
63 auto itr = rParameters.find("COMMAND");
64 if (itr == rParameters.end())
65 throw css::uno::RuntimeException("missing COMMAND parameter");
66
67 maCommands.emplace_back(new OUString(itr->second));
68 OUString* pCommand = maCommands.rbegin()->get();
69
70 Application::PostUserEvent(LINK(this, ChartUIObject, PostCommand), pCommand);
71 }
72}
73
74IMPL_LINK(ChartUIObject, PostCommand, void*, pCommand, void)
75{
76 css::util::URL aURL;
77 aURL.Path = *static_cast<OUString*>(pCommand);
78 mxChartWindow->GetController()->dispatch(aURL, css::uno::Sequence<css::beans::PropertyValue>());
79}
80
81std::unique_ptr<UIObject> ChartUIObject::get_child(const OUString& rID)
82{
83 std::unique_ptr<UIObject> pWindow = mxChartWindow->GetUITestFactory()(mxChartWindow.get());
84
85 return pWindow->get_child(rID);
86}
87
88std::set<OUString> ChartUIObject::get_children() const
89{
90 std::unique_ptr<UIObject> pWindow = mxChartWindow->GetUITestFactory()(mxChartWindow.get());
91
92 return pWindow->get_children();
93}
94
96{
97 return "ChartUIObject for type: ";
98}
99
101 WindowUIObject(xChartWindow),
102 mxChartWindow(xChartWindow)
103{
104}
105
107{
109
110 chart::ChartController* pController = mxChartWindow->GetController();
111 if (pController)
112 {
113 css::uno::Any aAny = pController->getSelection();
114 OUString aSelectedObject;
115 aAny >>= aSelectedObject;
116 aMap["SelectedObject"] = aSelectedObject;
117 }
118
119 return aMap;
120}
121
122void ChartWindowUIObject::execute(const OUString& rAction,
123 const StringMap& rParameters)
124{
125 if (rAction == "SELECT")
126 {
127 auto itr = rParameters.find("NAME");
128 if (itr == rParameters.end())
129 throw css::uno::RuntimeException("Missing Parameter 'NAME' for action 'SELECT'");
130
131
132 const OUString& rName = itr->second;
133 css::uno::Any aAny;
134 aAny <<= rName;
135
136 chart::ChartController* pController = mxChartWindow->GetController();
137 pController->select(aAny);
138 }
139 else
140 WindowUIObject::execute(rAction, rParameters);
141}
142
143std::unique_ptr<UIObject> ChartWindowUIObject::get_child(const OUString& rID)
144{
146 return std::unique_ptr<UIObject>(new ChartUIObject(mxChartWindow, rID));
147
148 throw css::uno::RuntimeException("unknown child");
149}
150
151namespace {
152
153void recursiveAdd(chart::ObjectIdentifier const & rID, std::set<OUString>& rChildren, const chart::ObjectHierarchy& rHierarchy)
154{
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)
158 {
159 return rObject.getObjectCID();
160 }
161 );
162
163 for (const chart::ObjectIdentifier& ID: aChildIdentifiers)
164 recursiveAdd(ID, rChildren, rHierarchy);
165}
166
167}
168
169std::set<OUString> ChartWindowUIObject::get_children() const
170{
171 std::set<OUString> aChildren;
172
173 chart::ChartController* pController = mxChartWindow->GetController();
174 if (!pController)
175 return aChildren;
176
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);
182 aChildren.insert(aIdentifier.getObjectCID());
183
184 recursiveAdd(aIdentifier, aChildren, aHierarchy);
185
186 return aChildren;
187}
188
189std::unique_ptr<UIObject> ChartWindowUIObject::create(vcl::Window* pWindow)
190{
191 chart::ChartWindow* pChartWindow = dynamic_cast<chart::ChartWindow*>(pWindow);
192 assert(pChartWindow);
193
194 return std::unique_ptr<UIObject>(new ChartWindowUIObject(pChartWindow));
195}
196
198{
199 return "ChartWindowUIObject";
200}
201
202/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
ChartUIObject(const VclPtr< chart::ChartWindow > &xChartWindow, OUString aCID)
Definition: uiobject.cxx:28
virtual OUString get_type() const override
Definition: uiobject.cxx:95
virtual std::unique_ptr< UIObject > get_child(const OUString &rID) override
Definition: uiobject.cxx:81
virtual std::set< OUString > get_children() const override
Definition: uiobject.cxx:88
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:43
OUString maCID
Definition: uiobject.hxx:37
VclPtr< chart::ChartWindow > mxChartWindow
Definition: uiobject.hxx:38
std::vector< std::unique_ptr< OUString > > maCommands
Definition: uiobject.hxx:39
StringMap get_state() override
Definition: uiobject.cxx:35
VclPtr< chart::ChartWindow > mxChartWindow
Definition: uiobject.hxx:46
virtual std::set< OUString > get_children() const override
Definition: uiobject.cxx:169
ChartWindowUIObject(const VclPtr< chart::ChartWindow > &xChartWindow)
Definition: uiobject.cxx:100
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:122
virtual StringMap get_state() override
Definition: uiobject.cxx:106
virtual std::unique_ptr< UIObject > get_child(const OUString &rID) override
Definition: uiobject.cxx:143
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:189
virtual OUString get_name() const override
Definition: uiobject.cxx:197
reference_type * get() const
virtual StringMap get_state() override
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
rtl::Reference<::chart::ChartModel > getChartModel()
rtl::Reference<::chart::ChartView > const & getChartView() const
virtual css::uno::Any SAL_CALL getSelection() override
virtual sal_Bool SAL_CALL select(const css::uno::Any &rSelection) override
The ChartWindow collects events from the window and forwards them the to the controller thus the cont...
Definition: ChartWindow.hxx:33
static ObjectIdentifier getRootNodeOID()
const tChildContainer & getChildren(const ObjectIdentifier &rParent) const
static bool isCID(std::u16string_view rName)
const OUString & getObjectCID() const
URL aURL
HashMap_OWString_Interface aMap
IMPL_LINK(ChartUIObject, PostCommand, void *, pCommand, void)
Definition: uiobject.cxx:74
std::map< OUString, OUString > StringMap