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  : TablePivotChart_Base(m_aMutex)
32  , m_pDocShell(pDocShell)
33  , m_nTab(nTab)
34  , m_aChartName(rName)
35 {
36  if (m_pDocShell)
37  m_pDocShell->GetDocument().AddUnoObject(*this);
38 }
39 
40 TablePivotChart::~TablePivotChart()
41 {
42  SolarMutexGuard aGuard;
43 
44  if (m_pDocShell)
45  m_pDocShell->GetDocument().RemoveUnoObject(*this);
46 }
47 
49 {
50  if (rHint.GetId() == SfxHintId::Dying)
51  m_pDocShell = nullptr;
52 }
53 
54 // XEmbeddedObjectSupplier
55 
56 uno::Reference<lang::XComponent> SAL_CALL TablePivotChart::getEmbeddedObject()
57 {
58  SolarMutexGuard aGuard;
60  if (pObject && svt::EmbeddedObjectRef::TryRunningState(pObject->GetObjRef()))
61  return uno::Reference<lang::XComponent>(pObject->GetObjRef()->getComponent(), uno::UNO_QUERY);
62  return nullptr;
63 }
64 
65 // XNamed
66 
67 OUString SAL_CALL TablePivotChart::getName()
68 {
69  SolarMutexGuard aGuard;
70  return m_aChartName;
71 }
72 
73 void SAL_CALL TablePivotChart::setName(OUString const & /* aName */)
74 {
75  SolarMutexGuard aGuard;
76  throw uno::RuntimeException(); // name cannot be changed
77 }
78 
79 // XTablePivotChart
80 
81 OUString SAL_CALL TablePivotChart::getPivotTableName()
82 {
83  SolarMutexGuard aGuard;
84 
86  if (!pObject)
87  return OUString();
88 
89  uno::Reference<embed::XEmbeddedObject> xObject = pObject->GetObjRef();
90  if (!xObject.is())
91  return OUString();
92 
93  uno::Reference<chart2::XChartDocument> xChartDoc(xObject->getComponent(), uno::UNO_QUERY);
94  if (!xChartDoc.is())
95  return OUString();
96 
97  uno::Reference<chart2::data::XPivotTableDataProvider> xPivotTableDataProvider(xChartDoc->getDataProvider(), uno::UNO_QUERY);
98  if (!xPivotTableDataProvider.is())
99  return OUString();
100 
101  return xPivotTableDataProvider->getPivotTableName();
102 }
103 
104 } // end sc namespace
105 
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef() const
EmbeddedObjectRef * pObject
SfxHintId GetId() const
cppu::WeakComponentImplHelper< css::table::XTablePivotChart, css::document::XEmbeddedObjectSupplier, css::container::XNamed, css::lang::XServiceInfo > TablePivotChart_Base
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:477
#define SC_SIMPLE_SERVICE_INFO(ClassName, ClassNameAscii, ServiceAscii)
Definition: miscuno.hxx:64
SdrOle2Obj * findChartsByName(ScDocShell *pDocShell, SCTAB nTab, OUString const &rName, ChartSourceType eChartSourceType)
Definition: ChartTools.cxx:98
static bool TryRunningState(const css::uno::Reference< css::embed::XEmbeddedObject > &)
sal_Int16 SCTAB
Definition: types.hxx:23