Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / sw / source / core / doc / docchart.cxx
blob901b8f088d4bbba8a1c343b0cc43970381100e29
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 <com/sun/star/frame/XModel.hpp>
22 #include <com/sun/star/chart2/XChartDocument.hpp>
24 #include <float.h>
25 #include <hintids.hxx>
26 #include <vcl/window.hxx>
27 #include <doc.hxx>
28 #include <docary.hxx>
29 #include <ndindex.hxx>
30 #include <swtable.hxx>
31 #include <ndtxt.hxx>
32 #include <calc.hxx>
33 #include <frmfmt.hxx>
34 #include <cellfml.hxx>
35 #include <viewsh.hxx>
36 #include <ndole.hxx>
37 #include <calbck.hxx>
38 #include <cntfrm.hxx>
39 #include <swtblfmt.hxx>
40 #include <tblsel.hxx>
41 #include <cellatr.hxx>
42 #include <osl/mutex.hxx>
43 #include <vcl/svapp.hxx>
45 #include <unochart.hxx>
47 using namespace com::sun::star;
48 using namespace com::sun::star::uno;
51 void SwTable::UpdateCharts() const
53 GetFrmFmt()->GetDoc()->UpdateCharts( GetFrmFmt()->GetName() );
56 bool SwTable::IsTblComplexForChart( const String& rSelection ) const
58 const SwTableBox* pSttBox, *pEndBox;
59 if( 2 < rSelection.Len() )
61 // Remove brackets at the beginning and from the end
62 String sBox( rSelection );
63 if( '<' == sBox.GetChar( 0 ) ) sBox.Erase( 0, 1 );
64 if( '>' == sBox.GetChar( sBox.Len()-1 ) ) sBox.Erase( sBox.Len()-1 );
66 xub_StrLen nSeperator = sBox.Search( ':' );
67 OSL_ENSURE( STRING_NOTFOUND != nSeperator, "no valid selection" );
69 pSttBox = GetTblBox( sBox.Copy( 0, nSeperator ));
70 pEndBox = GetTblBox( sBox.Copy( nSeperator+1 ));
72 else
74 const SwTableLines* pLns = &GetTabLines();
75 pSttBox = (*pLns)[ 0 ]->GetTabBoxes().front();
76 while( !pSttBox->GetSttNd() )
77 // Until the Content Box!
78 pSttBox = pSttBox->GetTabLines().front()->GetTabBoxes().front();
80 const SwTableBoxes* pBoxes = &pLns->back()->GetTabBoxes();
81 pEndBox = pBoxes->back();
82 while( !pEndBox->GetSttNd() )
84 // Until the Content Box!
85 pLns = &pEndBox->GetTabLines();
86 pBoxes = &pLns->back()->GetTabBoxes();
87 pEndBox = pBoxes->back();
91 return !pSttBox || !pEndBox || !::ChkChartSel( *pSttBox->GetSttNd(),
92 *pEndBox->GetSttNd() );
95 void SwDoc::DoUpdateAllCharts()
97 ViewShell* pVSh;
98 GetEditShell( &pVSh );
99 if( pVSh )
101 const SwFrmFmts& rTblFmts = *GetTblFrmFmts();
102 for( sal_uInt16 n = 0; n < rTblFmts.size(); ++n )
104 SwTable* pTmpTbl;
105 const SwTableNode* pTblNd;
106 SwFrmFmt* pFmt = rTblFmts[ n ];
108 if( 0 != ( pTmpTbl = SwTable::FindTable( pFmt ) ) &&
109 0 != ( pTblNd = pTmpTbl->GetTableNode() ) &&
110 pTblNd->GetNodes().IsDocNodes() )
112 _UpdateCharts( *pTmpTbl, *pVSh );
118 void SwDoc::_UpdateCharts( const SwTable& rTbl, ViewShell& rVSh ) const
120 String aName( rTbl.GetFrmFmt()->GetName() );
121 SwOLENode *pONd;
122 SwStartNode *pStNd;
123 SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
124 while( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
126 ++aIdx;
127 if( 0 != ( pONd = aIdx.GetNode().GetOLENode() ) &&
128 aName.Equals( pONd->GetChartTblName() ) &&
129 pONd->getLayoutFrm( rVSh.GetLayout() ) )
131 SwChartDataProvider *pPCD = GetChartDataProvider();
132 if (pPCD)
133 pPCD->InvalidateTable( &rTbl );
134 // following this the framework will now take care of repainting
135 // the chart or it's replacement image...
137 aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
141 void SwDoc::UpdateCharts( const String &rName ) const
143 SwTable* pTmpTbl = SwTable::FindTable( FindTblFmtByName( rName ) );
144 if( pTmpTbl )
146 ViewShell* pVSh;
147 GetEditShell( &pVSh );
149 if( pVSh )
150 _UpdateCharts( *pTmpTbl, *pVSh );
154 void SwDoc::SetTableName( SwFrmFmt& rTblFmt, const String &rNewName )
156 const String aOldName( rTblFmt.GetName() );
158 bool bNameFound = 0 == rNewName.Len();
159 if( !bNameFound )
161 SwFrmFmt* pFmt;
162 const SwFrmFmts& rTbl = *GetTblFrmFmts();
163 for( sal_uInt16 i = rTbl.size(); i; )
164 if( !( pFmt = rTbl[ --i ] )->IsDefault() &&
165 pFmt->GetName() == rNewName && IsUsed( *pFmt ) )
167 bNameFound = true;
168 break;
172 if( !bNameFound )
173 rTblFmt.SetName( rNewName, sal_True );
174 else
175 rTblFmt.SetName( GetUniqueTblName(), sal_True );
177 SwStartNode *pStNd;
178 SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
179 while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
181 ++aIdx;
182 SwOLENode *pNd = aIdx.GetNode().GetOLENode();
183 if( pNd && aOldName == pNd->GetChartTblName() )
185 pNd->SetChartTblName( rNewName );
187 ViewShell* pVSh;
188 GetEditShell( &pVSh );
190 SwTable* pTable = SwTable::FindTable( &rTblFmt );
191 SwChartDataProvider *pPCD = GetChartDataProvider();
192 if (pPCD)
193 pPCD->InvalidateTable( pTable );
194 // following this the framework will now take care of repainting
195 // the chart or it's replacement image...
197 aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
199 SetModified();
203 SwChartDataProvider * SwDoc::GetChartDataProvider( bool bCreate ) const
205 // since there must be only one instance of this object per document
206 // we need a mutex here
207 SolarMutexGuard aGuard;
209 if (bCreate && !aChartDataProviderImplRef.get())
211 aChartDataProviderImplRef = comphelper::ImplementationReference< SwChartDataProvider
212 , chart2::data::XDataProvider >( new SwChartDataProvider( this ) );
214 return aChartDataProviderImplRef.get();
218 void SwDoc::CreateChartInternalDataProviders( const SwTable *pTable )
220 if (pTable)
222 String aName( pTable->GetFrmFmt()->GetName() );
223 SwOLENode *pONd;
224 SwStartNode *pStNd;
225 SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
226 while (0 != (pStNd = aIdx.GetNode().GetStartNode()))
228 ++aIdx;
229 if( 0 != ( pONd = aIdx.GetNode().GetOLENode() ) &&
230 aName.Equals( pONd->GetChartTblName() ) /* OLE node is chart? */ &&
231 0 != (pONd->getLayoutFrm( GetCurrentLayout() )) /* chart frame is not hidden */ )
233 uno::Reference < embed::XEmbeddedObject > xIP = pONd->GetOLEObj().GetOleRef();
234 if ( svt::EmbeddedObjectRef::TryRunningState( xIP ) )
236 uno::Reference< chart2::XChartDocument > xChart( xIP->getComponent(), UNO_QUERY );
237 if (xChart.is())
238 xChart->createInternalDataProvider( sal_True );
240 // there may be more than one chart for each table thus we need to continue the loop...
243 aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
249 SwChartLockController_Helper & SwDoc::GetChartControllerHelper()
251 if (!pChartControllerHelper)
253 pChartControllerHelper = new SwChartLockController_Helper( this );
255 return *pChartControllerHelper;
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */