tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / unoobj / TablePivotChart.cxx
blob9b17b355de9a5ca5b94b64d2a59c9d2f14a09de5
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 <utility>
16 #include <vcl/svapp.hxx>
18 #include <miscuno.hxx>
19 #include <docsh.hxx>
21 #include <TablePivotChart.hxx>
22 #include <ChartTools.hxx>
24 using namespace css;
26 namespace sc
29 SC_SIMPLE_SERVICE_INFO(TablePivotChart, u"TablePivotChart"_ustr, u"com.sun.star.table.TablePivotChart"_ustr)
31 TablePivotChart::TablePivotChart(ScDocShell* pDocShell, SCTAB nTab, OUString aName)
32 : m_pDocShell(pDocShell)
33 , m_nTab(nTab)
34 , m_aChartName(std::move(aName))
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 return m_aChartName;
72 void SAL_CALL TablePivotChart::setName(OUString const & /* aName */)
74 throw uno::RuntimeException(); // name cannot be changed
77 // XTablePivotChart
79 OUString SAL_CALL TablePivotChart::getPivotTableName()
81 SolarMutexGuard aGuard;
83 SdrOle2Obj* pObject = sc::tools::findChartsByName(m_pDocShell, m_nTab, m_aChartName, sc::tools::ChartSourceType::PIVOT_TABLE);
84 if (!pObject)
85 return OUString();
87 uno::Reference<embed::XEmbeddedObject> xObject = pObject->GetObjRef();
88 if (!xObject.is())
89 return OUString();
91 uno::Reference<chart2::XChartDocument> xChartDoc(xObject->getComponent(), uno::UNO_QUERY);
92 if (!xChartDoc.is())
93 return OUString();
95 uno::Reference<chart2::data::XPivotTableDataProvider> xPivotTableDataProvider(xChartDoc->getDataProvider(), uno::UNO_QUERY);
96 if (!xPivotTableDataProvider.is())
97 return OUString();
99 return xPivotTableDataProvider->getPivotTableName();
102 } // end sc namespace
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */