android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / doc / DocumentChartDataProviderManager.cxx
blobe559892abf9dc6807936f33c1f537e351c73d494
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <DocumentChartDataProviderManager.hxx>
22 #include <doc.hxx>
23 #include <IDocumentLayoutAccess.hxx>
24 #include <vcl/svapp.hxx>
25 #include <swtable.hxx>
26 #include <unochart.hxx>
27 #include <ndole.hxx>
28 #include <com/sun/star/chart2/XChartDocument.hpp>
29 #include <com/sun/star/embed/XEmbeddedObject.hpp>
32 using namespace com::sun::star;
33 using namespace com::sun::star::uno;
35 namespace sw {
37 DocumentChartDataProviderManager::DocumentChartDataProviderManager( SwDoc& i_rSwdoc ) : m_rDoc( i_rSwdoc )
42 SwChartDataProvider * DocumentChartDataProviderManager::GetChartDataProvider( bool bCreate ) const
44 // since there must be only one instance of this object per document
45 // we need a mutex here
46 SolarMutexGuard aGuard;
48 if (bCreate && !maChartDataProviderImplRef.is())
50 maChartDataProviderImplRef = new SwChartDataProvider(m_rDoc);
52 return maChartDataProviderImplRef.get();
55 void DocumentChartDataProviderManager::CreateChartInternalDataProviders( const SwTable *pTable )
57 if (!pTable)
58 return;
60 OUString aName( pTable->GetFrameFormat()->GetName() );
61 SwOLENode *pONd;
62 SwStartNode *pStNd;
63 SwNodeIndex aIdx( *m_rDoc.GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
64 while (nullptr != (pStNd = aIdx.GetNode().GetStartNode()))
66 ++aIdx;
67 pONd = aIdx.GetNode().GetOLENode();
68 if( pONd &&
69 aName == pONd->GetChartTableName() /* OLE node is chart? */ &&
70 nullptr != (pONd->getLayoutFrame( m_rDoc.getIDocumentLayoutAccess().GetCurrentLayout() )) /* chart frame is not hidden */ )
72 uno::Reference < embed::XEmbeddedObject > xIP = pONd->GetOLEObj().GetOleRef();
73 if ( svt::EmbeddedObjectRef::TryRunningState( xIP ) )
75 uno::Reference< chart2::XChartDocument > xChart( xIP->getComponent(), UNO_QUERY );
76 if (xChart.is())
77 xChart->createInternalDataProvider( true );
79 // there may be more than one chart for each table thus we need to continue the loop...
82 aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
86 SwChartLockController_Helper & DocumentChartDataProviderManager::GetChartControllerHelper()
88 if (!mpChartControllerHelper)
90 mpChartControllerHelper.reset(new SwChartLockController_Helper( & m_rDoc ));
92 return *mpChartControllerHelper;
95 DocumentChartDataProviderManager::~DocumentChartDataProviderManager()
97 // clean up chart related structures...
98 // Note: the chart data provider gets already disposed in ~SwDocShell
99 // since all UNO API related functionality requires an existing SwDocShell
100 // this assures that dispose gets called if there is need for it.
101 maChartDataProviderImplRef.clear();
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */