From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- chart2/source/controller/uitest/uiobject.cxx | 201 +++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 chart2/source/controller/uitest/uiobject.cxx (limited to 'chart2/source/controller/uitest/uiobject.cxx') diff --git a/chart2/source/controller/uitest/uiobject.cxx b/chart2/source/controller/uitest/uiobject.cxx new file mode 100644 index 000000000..5081f00c7 --- /dev/null +++ b/chart2/source/controller/uitest/uiobject.cxx @@ -0,0 +1,201 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include + +ChartUIObject::ChartUIObject(const VclPtr& xChartWindow, + const OUString& rCID): + maCID(rCID), + mxChartWindow(xChartWindow) +{ +} + +StringMap ChartUIObject::get_state() +{ + StringMap aMap; + aMap["CID"] = maCID; + + return aMap; +} + +void ChartUIObject::execute(const OUString& rAction, + const StringMap& rParameters) +{ + if (rAction == "SELECT") + { + std::unique_ptr pWindow = mxChartWindow->GetUITestFactory()(mxChartWindow.get()); + + StringMap aParams; + aParams["NAME"] = maCID; + pWindow->execute(rAction, aParams); + } + else if (rAction == "COMMAND") + { + // first select object + std::unique_ptr pWindow = mxChartWindow->GetUITestFactory()(mxChartWindow.get()); + + StringMap aParams; + aParams["NAME"] = maCID; + pWindow->execute("SELECT", aParams); + + auto itr = rParameters.find("COMMAND"); + if (itr == rParameters.end()) + throw css::uno::RuntimeException("missing COMMAND parameter"); + + maCommands.emplace_back(new OUString(itr->second)); + OUString* pCommand = maCommands.rbegin()->get(); + + Application::PostUserEvent(LINK(this, ChartUIObject, PostCommand), pCommand); + } +} + +IMPL_LINK(ChartUIObject, PostCommand, void*, pCommand, void) +{ + css::util::URL aURL; + aURL.Path = *static_cast(pCommand); + mxChartWindow->GetController()->dispatch(aURL, css::uno::Sequence()); +} + +std::unique_ptr ChartUIObject::get_child(const OUString& rID) +{ + std::unique_ptr pWindow = mxChartWindow->GetUITestFactory()(mxChartWindow.get()); + + return pWindow->get_child(rID); +} + +std::set ChartUIObject::get_children() const +{ + std::unique_ptr pWindow = mxChartWindow->GetUITestFactory()(mxChartWindow.get()); + + return pWindow->get_children(); +} + +OUString ChartUIObject::get_type() const +{ + return "ChartUIObject for type: "; +} + +ChartWindowUIObject::ChartWindowUIObject(const VclPtr& xChartWindow): + WindowUIObject(xChartWindow), + mxChartWindow(xChartWindow) +{ +} + +StringMap ChartWindowUIObject::get_state() +{ + StringMap aMap = WindowUIObject::get_state(); + + chart::ChartController* pController = mxChartWindow->GetController(); + if (pController) + { + css::uno::Any aAny = pController->getSelection(); + OUString aSelectedObject; + aAny >>= aSelectedObject; + aMap["SelectedObject"] = aSelectedObject; + } + + return aMap; +} + +void ChartWindowUIObject::execute(const OUString& rAction, + const StringMap& rParameters) +{ + if (rAction == "SELECT") + { + auto itr = rParameters.find("NAME"); + if (itr == rParameters.end()) + throw css::uno::RuntimeException("Missing Parameter 'NAME' for action 'SELECT'"); + + + const OUString& rName = itr->second; + css::uno::Any aAny; + aAny <<= rName; + + chart::ChartController* pController = mxChartWindow->GetController(); + pController->select(aAny); + } + else + WindowUIObject::execute(rAction, rParameters); +} + +std::unique_ptr ChartWindowUIObject::get_child(const OUString& rID) +{ + if (chart::ObjectIdentifier::isCID(rID)) + return std::unique_ptr(new ChartUIObject(mxChartWindow, rID)); + + throw css::uno::RuntimeException("unknown child"); +} + +namespace { + +void recursiveAdd(chart::ObjectIdentifier const & rID, std::set& rChildren, const chart::ObjectHierarchy& rHierarchy) +{ + std::vector aChildIdentifiers = rHierarchy.getChildren(rID); + std::transform(aChildIdentifiers.begin(), aChildIdentifiers.end(), std::inserter(rChildren, rChildren.begin()), + [](const chart::ObjectIdentifier& rObject) + { + return rObject.getObjectCID(); + } + ); + + for (const chart::ObjectIdentifier& ID: aChildIdentifiers) + recursiveAdd(ID, rChildren, rHierarchy); +} + +} + +std::set ChartWindowUIObject::get_children() const +{ + std::set aChildren; + + chart::ChartController* pController = mxChartWindow->GetController(); + if (!pController) + return aChildren; + + rtl::Reference<::chart::ChartModel> xChartDoc( pController->getChartModel() ); + + css::uno::Reference xChartView = pController->getChartView(); + chart::ExplicitValueProvider* pValueProvider = comphelper::getFromUnoTunnel( xChartView ); + chart::ObjectHierarchy aHierarchy(xChartDoc, pValueProvider); + chart::ObjectIdentifier aIdentifier = chart::ObjectHierarchy::getRootNodeOID(); + aChildren.insert(aIdentifier.getObjectCID()); + + recursiveAdd(aIdentifier, aChildren, aHierarchy); + + return aChildren; +} + +std::unique_ptr ChartWindowUIObject::create(vcl::Window* pWindow) +{ + chart::ChartWindow* pChartWindow = dynamic_cast(pWindow); + assert(pChartWindow); + + return std::unique_ptr(new ChartWindowUIObject(pChartWindow)); +} + +OUString ChartWindowUIObject::get_name() const +{ + return "ChartWindowUIObject"; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3