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 --- sc/source/ui/unoobj/TablePivotChart.cxx | 103 ++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 sc/source/ui/unoobj/TablePivotChart.cxx (limited to 'sc/source/ui/unoobj/TablePivotChart.cxx') diff --git a/sc/source/ui/unoobj/TablePivotChart.cxx b/sc/source/ui/unoobj/TablePivotChart.cxx new file mode 100644 index 000000000..ecc158002 --- /dev/null +++ b/sc/source/ui/unoobj/TablePivotChart.cxx @@ -0,0 +1,103 @@ +/* -*- 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 + +using namespace css; + +namespace sc +{ + +SC_SIMPLE_SERVICE_INFO(TablePivotChart, "TablePivotChart", "com.sun.star.table.TablePivotChart") + +TablePivotChart::TablePivotChart(ScDocShell* pDocShell, SCTAB nTab, const OUString& rName) + : m_pDocShell(pDocShell) + , m_nTab(nTab) + , m_aChartName(rName) +{ + if (m_pDocShell) + m_pDocShell->GetDocument().AddUnoObject(*this); +} + +TablePivotChart::~TablePivotChart() +{ + SolarMutexGuard aGuard; + + if (m_pDocShell) + m_pDocShell->GetDocument().RemoveUnoObject(*this); +} + +void TablePivotChart::Notify(SfxBroadcaster&, const SfxHint& rHint) +{ + if (rHint.GetId() == SfxHintId::Dying) + m_pDocShell = nullptr; +} + +// XEmbeddedObjectSupplier + +uno::Reference SAL_CALL TablePivotChart::getEmbeddedObject() +{ + SolarMutexGuard aGuard; + SdrOle2Obj* pObject = sc::tools::findChartsByName(m_pDocShell, m_nTab, m_aChartName, sc::tools::ChartSourceType::PIVOT_TABLE); + if (pObject && svt::EmbeddedObjectRef::TryRunningState(pObject->GetObjRef())) + return uno::Reference(pObject->GetObjRef()->getComponent(), uno::UNO_QUERY); + return nullptr; +} + +// XNamed + +OUString SAL_CALL TablePivotChart::getName() +{ + return m_aChartName; +} + +void SAL_CALL TablePivotChart::setName(OUString const & /* aName */) +{ + throw uno::RuntimeException(); // name cannot be changed +} + +// XTablePivotChart + +OUString SAL_CALL TablePivotChart::getPivotTableName() +{ + SolarMutexGuard aGuard; + + SdrOle2Obj* pObject = sc::tools::findChartsByName(m_pDocShell, m_nTab, m_aChartName, sc::tools::ChartSourceType::PIVOT_TABLE); + if (!pObject) + return OUString(); + + uno::Reference xObject = pObject->GetObjRef(); + if (!xObject.is()) + return OUString(); + + uno::Reference xChartDoc(xObject->getComponent(), uno::UNO_QUERY); + if (!xChartDoc.is()) + return OUString(); + + uno::Reference xPivotTableDataProvider(xChartDoc->getDataProvider(), uno::UNO_QUERY); + if (!xPivotTableDataProvider.is()) + return OUString(); + + return xPivotTableDataProvider->getPivotTableName(); +} + +} // end sc namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3