LibreOffice Module sc (master)  1
TablePivotChart.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
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>
16 
17 #include <miscuno.hxx>
18 #include <docsh.hxx>
19 
20 #include <TablePivotChart.hxx>
21 #include <ChartTools.hxx>
22 
23 using namespace css;
24 
25 namespace sc
26 {
27 
28 SC_SIMPLE_SERVICE_INFO(TablePivotChart, "TablePivotChart", "com.sun.star.table.TablePivotChart")
29 
30 TablePivotChart::TablePivotChart(ScDocShell* pDocShell, SCTAB nTab, const OUString& rName)
31  : m_pDocShell(pDocShell)
32  , m_nTab(nTab)
33  , m_aChartName(rName)
34 {
35  if (m_pDocShell)
36  m_pDocShell->GetDocument().AddUnoObject(*this);
37 }
38 
39 TablePivotChart::~TablePivotChart()
40 {
41  SolarMutexGuard aGuard;
42 
43  if (m_pDocShell)
44  m_pDocShell->GetDocument().RemoveUnoObject(*this);
45 }
46 
48 {
49  if (rHint.GetId() == SfxHintId::Dying)
50  m_pDocShell = nullptr;
51 }
52 
53 // XEmbeddedObjectSupplier
54 
55 uno::Reference<lang::XComponent> SAL_CALL TablePivotChart::getEmbeddedObject()
56 {
57  SolarMutexGuard aGuard;
59  if (pObject && svt::EmbeddedObjectRef::TryRunningState(pObject->GetObjRef()))
60  return uno::Reference<lang::XComponent>(pObject->GetObjRef()->getComponent(), uno::UNO_QUERY);
61  return nullptr;
62 }
63 
64 // XNamed
65 
66 OUString SAL_CALL TablePivotChart::getName()
67 {
68  return m_aChartName;
69 }
70 
71 void SAL_CALL TablePivotChart::setName(OUString const & /* aName */)
72 {
73  throw uno::RuntimeException(); // name cannot be changed
74 }
75 
76 // XTablePivotChart
77 
78 OUString SAL_CALL TablePivotChart::getPivotTableName()
79 {
80  SolarMutexGuard aGuard;
81 
83  if (!pObject)
84  return OUString();
85 
86  uno::Reference<embed::XEmbeddedObject> xObject = pObject->GetObjRef();
87  if (!xObject.is())
88  return OUString();
89 
90  uno::Reference<chart2::XChartDocument> xChartDoc(xObject->getComponent(), uno::UNO_QUERY);
91  if (!xChartDoc.is())
92  return OUString();
93 
94  uno::Reference<chart2::data::XPivotTableDataProvider> xPivotTableDataProvider(xChartDoc->getDataProvider(), uno::UNO_QUERY);
95  if (!xPivotTableDataProvider.is())
96  return OUString();
97 
98  return xPivotTableDataProvider->getPivotTableName();
99 }
100 
101 } // end sc namespace
102 
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef() const
EmbeddedObjectRef * pObject
SfxHintId GetId() const
void Notify(ScModelObj &rModelObj, const ScRangeList &rChangeRanges, const OUString &rType=OUString("cell-change"), const css::uno::Sequence< css::beans::PropertyValue > &rProperties=css::uno::Sequence< css::beans::PropertyValue >())
Definition: docsh.hxx:483
CAUTION! The following defines must be in the same namespace as the respective type.
#define SC_SIMPLE_SERVICE_INFO(ClassName, ClassNameAscii, ServiceAscii)
Definition: miscuno.hxx:63
SdrOle2Obj * findChartsByName(ScDocShell *pDocShell, SCTAB nTab, std::u16string_view rName, ChartSourceType eChartSourceType)
Definition: ChartTools.cxx:98
static bool TryRunningState(const css::uno::Reference< css::embed::XEmbeddedObject > &)
sal_Int16 SCTAB
Definition: types.hxx:22