1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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>
16 #include <vcl/svapp.hxx>
18 #include <miscuno.hxx>
21 #include <TablePivotChart.hxx>
22 #include <ChartTools.hxx>
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
)
34 , m_aChartName(std::move(aName
))
37 m_pDocShell
->GetDocument().AddUnoObject(*this);
40 TablePivotChart::~TablePivotChart()
42 SolarMutexGuard aGuard
;
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
);
67 OUString SAL_CALL
TablePivotChart::getName()
72 void SAL_CALL
TablePivotChart::setName(OUString
const & /* aName */)
74 throw uno::RuntimeException(); // name cannot be changed
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
);
87 uno::Reference
<embed::XEmbeddedObject
> xObject
= pObject
->GetObjRef();
91 uno::Reference
<chart2::XChartDocument
> xChartDoc(xObject
->getComponent(), uno::UNO_QUERY
);
95 uno::Reference
<chart2::data::XPivotTableDataProvider
> xPivotTableDataProvider(xChartDoc
->getDataProvider(), uno::UNO_QUERY
);
96 if (!xPivotTableDataProvider
.is())
99 return xPivotTableDataProvider
->getPivotTableName();
102 } // end sc namespace
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */