Line data Source code
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 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <DocumentChartDataProviderManager.hxx>
21 :
22 : #include <doc.hxx>
23 : #include <IDocumentLayoutAccess.hxx>
24 : #include <vcl/svapp.hxx>
25 : #include <swtable.hxx>
26 : #include <unochart.hxx>
27 : #include <frmfmt.hxx>
28 : #include <ndole.hxx>
29 : #include <com/sun/star/chart2/XChartDocument.hpp>
30 :
31 :
32 : using namespace com::sun::star;
33 : using namespace com::sun::star::uno;
34 :
35 : namespace sw {
36 :
37 5052 : DocumentChartDataProviderManager::DocumentChartDataProviderManager( SwDoc& i_rSwdoc ) : m_rSwdoc( i_rSwdoc ),
38 : maChartDataProviderImplRef(),
39 5052 : mpChartControllerHelper( 0 )
40 : {
41 :
42 5052 : }
43 :
44 5063 : SwChartDataProvider * DocumentChartDataProviderManager::GetChartDataProvider( bool bCreate ) const
45 : {
46 : // since there must be only one instance of this object per document
47 : // we need a mutex here
48 5063 : SolarMutexGuard aGuard;
49 :
50 5063 : if (bCreate && !maChartDataProviderImplRef.is())
51 : {
52 6 : maChartDataProviderImplRef = new SwChartDataProvider( & m_rSwdoc );
53 : }
54 5063 : return maChartDataProviderImplRef.get();
55 : }
56 :
57 2 : void DocumentChartDataProviderManager::CreateChartInternalDataProviders( const SwTable *pTable )
58 : {
59 2 : if (pTable)
60 : {
61 2 : OUString aName( pTable->GetFrmFmt()->GetName() );
62 : SwOLENode *pONd;
63 : SwStartNode *pStNd;
64 4 : SwNodeIndex aIdx( *m_rSwdoc.GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
65 4 : while (0 != (pStNd = aIdx.GetNode().GetStartNode()))
66 : {
67 0 : ++aIdx;
68 0 : if( 0 != ( pONd = aIdx.GetNode().GetOLENode() ) &&
69 0 : aName == pONd->GetChartTblName() /* OLE node is chart? */ &&
70 0 : 0 != (pONd->getLayoutFrm( m_rSwdoc.getIDocumentLayoutAccess().GetCurrentLayout() )) /* chart frame is not hidden */ )
71 : {
72 0 : uno::Reference < embed::XEmbeddedObject > xIP = pONd->GetOLEObj().GetOleRef();
73 0 : if ( svt::EmbeddedObjectRef::TryRunningState( xIP ) )
74 : {
75 0 : uno::Reference< chart2::XChartDocument > xChart( xIP->getComponent(), UNO_QUERY );
76 0 : if (xChart.is())
77 0 : xChart->createInternalDataProvider( sal_True );
78 :
79 : // there may be more than one chart for each table thus we need to continue the loop...
80 0 : }
81 : }
82 0 : aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
83 2 : }
84 : }
85 2 : }
86 :
87 5041 : SwChartLockController_Helper & DocumentChartDataProviderManager::GetChartControllerHelper()
88 : {
89 5041 : if (!mpChartControllerHelper)
90 : {
91 5041 : mpChartControllerHelper = new SwChartLockController_Helper( & m_rSwdoc );
92 : }
93 5041 : return *mpChartControllerHelper;
94 : }
95 :
96 15135 : DocumentChartDataProviderManager::~DocumentChartDataProviderManager()
97 : {
98 : // clean up chart related structures...
99 : // Note: the chart data provider gets already disposed in ~SwDocShell
100 : // since all UNO API related functionality requires an existing SwDocShell
101 : // this assures that dipose gets called if there is need for it.
102 5045 : maChartDataProviderImplRef.clear();
103 5045 : delete mpChartControllerHelper;
104 10090 : }
105 :
106 270 : }
107 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|