tdf#42949 Fix IWYU warnings in sc/source/ui/unoobj/*
[LibreOffice.git] / sc / source / ui / unoobj / TablePivotChart.cxx
blob4ede28086fc5142a845688a1741b130a46229dcd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <com/sun/star/chart2/data/XPivotTableDataProvider.hpp>
11 #include <com/sun/star/chart2/XChartDocument.hpp>
12 #include <com/sun/star/embed/XEmbeddedObject.hpp>
13 #include <svx/svdoole2.hxx>
14 #include <svtools/embedhlp.hxx>
15 #include <vcl/svapp.hxx>
17 #include <miscuno.hxx>
18 #include <docsh.hxx>
20 #include <TablePivotChart.hxx>
21 #include <ChartTools.hxx>
23 using namespace css;
25 namespace sc
28 SC_SIMPLE_SERVICE_INFO(TablePivotChart, "TablePivotChart", "com.sun.star.table.TablePivotChart")
30 TablePivotChart::TablePivotChart(ScDocShell* pDocShell, SCTAB nTab, const OUString& rName)
31 : TablePivotChart_Base(m_aMutex)
32 , m_pDocShell(pDocShell)
33 , m_nTab(nTab)
34 , m_aChartName(rName)
36 if (m_pDocShell)
37 m_pDocShell->GetDocument().AddUnoObject(*this);
40 TablePivotChart::~TablePivotChart()
42 SolarMutexGuard aGuard;
44 if (m_pDocShell)
45 m_pDocShell->GetDocument().RemoveUnoObject(*this);
48 void TablePivotChart::Notify(SfxBroadcaster&, const SfxHint& rHint)
50 if (rHint.GetId() == SfxHintId::Dying)
51 m_pDocShell = nullptr;
54 // XEmbeddedObjectSupplier
56 uno::Reference<lang::XComponent> SAL_CALL TablePivotChart::getEmbeddedObject()
58 SolarMutexGuard aGuard;
59 SdrOle2Obj* pObject = sc::tools::findChartsByName(m_pDocShell, m_nTab, m_aChartName, sc::tools::ChartSourceType::PIVOT_TABLE);
60 if (pObject && svt::EmbeddedObjectRef::TryRunningState(pObject->GetObjRef()))
61 return uno::Reference<lang::XComponent>(pObject->GetObjRef()->getComponent(), uno::UNO_QUERY);
62 return nullptr;
65 // XNamed
67 OUString SAL_CALL TablePivotChart::getName()
69 SolarMutexGuard aGuard;
70 return m_aChartName;
73 void SAL_CALL TablePivotChart::setName(OUString const & /* aName */)
75 SolarMutexGuard aGuard;
76 throw uno::RuntimeException(); // name cannot be changed
79 // XTablePivotChart
81 OUString SAL_CALL TablePivotChart::getPivotTableName()
83 SolarMutexGuard aGuard;
85 SdrOle2Obj* pObject = sc::tools::findChartsByName(m_pDocShell, m_nTab, m_aChartName, sc::tools::ChartSourceType::PIVOT_TABLE);
86 if (!pObject)
87 return OUString();
89 uno::Reference<embed::XEmbeddedObject> xObject = pObject->GetObjRef();
90 if (!xObject.is())
91 return OUString();
93 uno::Reference<chart2::XChartDocument> xChartDoc(xObject->getComponent(), uno::UNO_QUERY);
94 if (!xChartDoc.is())
95 return OUString();
97 uno::Reference<chart2::data::XPivotTableDataProvider> xPivotTableDataProvider(xChartDoc->getDataProvider(), uno::UNO_QUERY);
98 if (!xPivotTableDataProvider.is())
99 return OUString();
101 return xPivotTableDataProvider->getPivotTableName();
104 } // end sc namespace
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */