Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/frame/XModel.hpp>
30 : :
31 : : #include <com/sun/star/chart2/XChartDocument.hpp>
32 : :
33 : : #include <float.h>
34 : : #include <hintids.hxx>
35 : : #include <vcl/window.hxx>
36 : : #include <doc.hxx>
37 : : #include <docary.hxx>
38 : : #include <ndindex.hxx>
39 : : #include <swtable.hxx>
40 : : #include <ndtxt.hxx>
41 : : #include <calc.hxx>
42 : : #include <frmfmt.hxx>
43 : : #include <cellfml.hxx>
44 : : #include <viewsh.hxx>
45 : : #include <ndole.hxx>
46 : : #include <calbck.hxx>
47 : : #include <cntfrm.hxx>
48 : : #include <swtblfmt.hxx>
49 : : #include <tblsel.hxx>
50 : : #include <cellatr.hxx>
51 : : #include <osl/mutex.hxx>
52 : : #include <vcl/svapp.hxx>
53 : :
54 : : #include <unochart.hxx>
55 : :
56 : : using namespace com::sun::star;
57 : : using namespace com::sun::star::uno;
58 : :
59 : :
60 : 0 : void SwTable::UpdateCharts() const
61 : : {
62 : 0 : GetFrmFmt()->GetDoc()->UpdateCharts( GetFrmFmt()->GetName() );
63 : 0 : }
64 : :
65 : 0 : sal_Bool SwTable::IsTblComplexForChart( const String& rSelection ) const
66 : : {
67 : : const SwTableBox* pSttBox, *pEndBox;
68 [ # # ]: 0 : if( 2 < rSelection.Len() )
69 : : {
70 : : // Remove brackets at the beginning and from the end
71 [ # # ]: 0 : String sBox( rSelection );
72 [ # # ][ # # ]: 0 : if( '<' == sBox.GetChar( 0 ) ) sBox.Erase( 0, 1 );
73 [ # # ][ # # ]: 0 : if( '>' == sBox.GetChar( sBox.Len()-1 ) ) sBox.Erase( sBox.Len()-1 );
74 : :
75 [ # # ]: 0 : xub_StrLen nSeperator = sBox.Search( ':' );
76 : : OSL_ENSURE( STRING_NOTFOUND != nSeperator, "no valid selection" );
77 : :
78 [ # # ][ # # ]: 0 : pSttBox = GetTblBox( sBox.Copy( 0, nSeperator ));
[ # # ]
79 [ # # ][ # # ]: 0 : pEndBox = GetTblBox( sBox.Copy( nSeperator+1 ));
[ # # ][ # # ]
80 : : }
81 : : else
82 : : {
83 : 0 : const SwTableLines* pLns = &GetTabLines();
84 : 0 : pSttBox = (*pLns)[ 0 ]->GetTabBoxes().front();
85 [ # # ]: 0 : while( !pSttBox->GetSttNd() )
86 : : // Until the Content Box!
87 : 0 : pSttBox = pSttBox->GetTabLines().front()->GetTabBoxes().front();
88 : :
89 : 0 : const SwTableBoxes* pBoxes = &pLns->back()->GetTabBoxes();
90 : 0 : pEndBox = pBoxes->back();
91 [ # # ]: 0 : while( !pEndBox->GetSttNd() )
92 : : {
93 : : // Until the Content Box!
94 : 0 : pLns = &pEndBox->GetTabLines();
95 : 0 : pBoxes = &pLns->back()->GetTabBoxes();
96 : 0 : pEndBox = pBoxes->back();
97 : : }
98 : : }
99 : :
100 : 0 : return !pSttBox || !pEndBox || !::ChkChartSel( *pSttBox->GetSttNd(),
101 [ # # ][ # # ]: 0 : *pEndBox->GetSttNd() );
[ # # ]
102 : : }
103 : :
104 : 0 : void SwDoc::DoUpdateAllCharts()
105 : : {
106 : : ViewShell* pVSh;
107 [ # # ]: 0 : GetEditShell( &pVSh );
108 [ # # ]: 0 : if( pVSh )
109 : : {
110 : 0 : const SwFrmFmts& rTblFmts = *GetTblFrmFmts();
111 [ # # ]: 0 : for( sal_uInt16 n = 0; n < rTblFmts.size(); ++n )
112 : : {
113 : : SwTable* pTmpTbl;
114 : : const SwTableNode* pTblNd;
115 : 0 : SwFrmFmt* pFmt = rTblFmts[ n ];
116 : :
117 [ # # ][ # # ]: 0 : if( 0 != ( pTmpTbl = SwTable::FindTable( pFmt ) ) &&
[ # # ][ # # ]
[ # # ][ # # ]
118 : : 0 != ( pTblNd = pTmpTbl->GetTableNode() ) &&
119 [ # # ]: 0 : pTblNd->GetNodes().IsDocNodes() )
120 : : {
121 [ # # ]: 0 : _UpdateCharts( *pTmpTbl, *pVSh );
122 : : }
123 : : }
124 : : }
125 : 0 : }
126 : :
127 : 16 : void SwDoc::_UpdateCharts( const SwTable& rTbl, ViewShell& rVSh ) const
128 : : {
129 [ + - ]: 16 : String aName( rTbl.GetFrmFmt()->GetName() );
130 : : SwOLENode *pONd;
131 : : SwStartNode *pStNd;
132 [ + - ][ + - ]: 16 : SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
133 [ - + ]: 16 : while( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
134 : : {
135 [ # # ]: 0 : aIdx++;
136 [ # # ][ # # ]: 0 : if( 0 != ( pONd = aIdx.GetNode().GetOLENode() ) &&
[ # # ][ # # ]
137 [ # # ]: 0 : aName.Equals( pONd->GetChartTblName() ) &&
138 [ # # ][ # # ]: 0 : pONd->getLayoutFrm( rVSh.GetLayout() ) )
139 : : {
140 [ # # ]: 0 : SwChartDataProvider *pPCD = GetChartDataProvider();
141 [ # # ]: 0 : if (pPCD)
142 [ # # ]: 0 : pPCD->InvalidateTable( &rTbl );
143 : : // following this the framework will now take care of repainting
144 : : // the chart or it's replacement image...
145 : : }
146 [ # # ]: 0 : aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
147 [ + - ][ + - ]: 16 : }
148 : 16 : }
149 : :
150 : 16 : void SwDoc::UpdateCharts( const String &rName ) const
151 : : {
152 : 16 : SwTable* pTmpTbl = SwTable::FindTable( FindTblFmtByName( rName ) );
153 [ + - ]: 16 : if( pTmpTbl )
154 : : {
155 : : ViewShell* pVSh;
156 [ + - ]: 16 : GetEditShell( &pVSh );
157 : :
158 [ + - ]: 16 : if( pVSh )
159 [ + - ]: 16 : _UpdateCharts( *pTmpTbl, *pVSh );
160 : : }
161 : 16 : }
162 : :
163 : 4 : void SwDoc::SetTableName( SwFrmFmt& rTblFmt, const String &rNewName )
164 : : {
165 : : // sal_Bool bStop = 1;
166 : :
167 [ + - ]: 4 : const String aOldName( rTblFmt.GetName() );
168 : :
169 : 4 : sal_Bool bNameFound = 0 == rNewName.Len();
170 [ + - ]: 4 : if( !bNameFound )
171 : : {
172 : : SwFrmFmt* pFmt;
173 : 4 : const SwFrmFmts& rTbl = *GetTblFrmFmts();
174 [ + + ]: 8 : for( sal_uInt16 i = rTbl.size(); i; )
175 [ + - ][ - + ]: 8 : if( !( pFmt = rTbl[ --i ] )->IsDefault() &&
[ # # ][ - + ]
176 [ + - ][ # # ]: 4 : pFmt->GetName() == rNewName && IsUsed( *pFmt ) )
177 : : {
178 : 0 : bNameFound = sal_True;
179 : 0 : break;
180 : : }
181 : : }
182 : :
183 [ + - ]: 4 : if( !bNameFound )
184 [ + - ]: 4 : rTblFmt.SetName( rNewName, sal_True );
185 : : else
186 [ # # ][ # # ]: 0 : rTblFmt.SetName( GetUniqueTblName(), sal_True );
[ # # ]
187 : :
188 : : SwStartNode *pStNd;
189 [ + - ][ + - ]: 4 : SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
190 [ - + ]: 4 : while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
191 : : {
192 [ # # ]: 0 : aIdx++;
193 : 0 : SwOLENode *pNd = aIdx.GetNode().GetOLENode();
194 [ # # ][ # # ]: 0 : if( pNd && aOldName == pNd->GetChartTblName() )
[ # # ][ # # ]
195 : : {
196 [ # # ]: 0 : pNd->SetChartTblName( rNewName );
197 : :
198 : : ViewShell* pVSh;
199 [ # # ]: 0 : GetEditShell( &pVSh );
200 : :
201 [ # # ]: 0 : SwTable* pTable = SwTable::FindTable( &rTblFmt );
202 [ # # ]: 0 : SwChartDataProvider *pPCD = GetChartDataProvider();
203 [ # # ]: 0 : if (pPCD)
204 [ # # ]: 0 : pPCD->InvalidateTable( pTable );
205 : : // following this the framework will now take care of repainting
206 : : // the chart or it's replacement image...
207 : : }
208 [ # # ]: 0 : aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
209 : : }
210 [ + - ][ + - ]: 4 : SetModified();
[ + - ]
211 : 4 : }
212 : :
213 : :
214 : 1440 : SwChartDataProvider * SwDoc::GetChartDataProvider( bool bCreate ) const
215 : : {
216 : : // since there must be only one instance of this object per document
217 : : // we need a mutex here
218 [ + - ]: 1440 : SolarMutexGuard aGuard;
219 : :
220 [ - + ][ # # ]: 1440 : if (bCreate && !aChartDataProviderImplRef.get())
[ - + ]
221 : : {
222 : : aChartDataProviderImplRef = comphelper::ImplementationReference< SwChartDataProvider
223 [ # # ][ # # ]: 0 : , chart2::data::XDataProvider >( new SwChartDataProvider( this ) );
[ # # ][ # # ]
224 : : }
225 [ + - ]: 1440 : return aChartDataProviderImplRef.get();
226 : : }
227 : :
228 : :
229 : 2 : void SwDoc::CreateChartInternalDataProviders( const SwTable *pTable )
230 : : {
231 [ + - ]: 2 : if (pTable)
232 : : {
233 [ + - ]: 2 : String aName( pTable->GetFrmFmt()->GetName() );
234 : : SwOLENode *pONd;
235 : : SwStartNode *pStNd;
236 [ + - ][ + - ]: 2 : SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
237 [ - + ]: 2 : while (0 != (pStNd = aIdx.GetNode().GetStartNode()))
238 : : {
239 [ # # ]: 0 : aIdx++;
240 [ # # ][ # # ]: 0 : if( 0 != ( pONd = aIdx.GetNode().GetOLENode() ) &&
[ # # ][ # # ]
241 [ # # ]: 0 : aName.Equals( pONd->GetChartTblName() ) /* OLE node is chart? */ &&
242 [ # # ][ # # ]: 0 : 0 != (pONd->getLayoutFrm( GetCurrentLayout() )) /* chart frame is not hidden */ )
243 : : {
244 [ # # ]: 0 : uno::Reference < embed::XEmbeddedObject > xIP = pONd->GetOLEObj().GetOleRef();
245 [ # # ][ # # ]: 0 : if ( svt::EmbeddedObjectRef::TryRunningState( xIP ) )
246 : : {
247 [ # # ][ # # ]: 0 : uno::Reference< chart2::XChartDocument > xChart( xIP->getComponent(), UNO_QUERY );
[ # # ]
248 [ # # ]: 0 : if (xChart.is())
249 [ # # ][ # # ]: 0 : xChart->createInternalDataProvider( sal_True );
250 : :
251 : : // there may be more than one chart for each table thus we need to continue the loop...
252 : 0 : }
253 : : }
254 [ # # ]: 0 : aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
255 [ + - ][ + - ]: 2 : }
256 : : }
257 : 2 : }
258 : :
259 : :
260 : 1432 : SwChartLockController_Helper & SwDoc::GetChartControllerHelper()
261 : : {
262 [ + - ]: 1432 : if (!pChartControllerHelper)
263 : : {
264 [ + - ]: 1432 : pChartControllerHelper = new SwChartLockController_Helper( this );
265 : : }
266 : 1432 : return *pChartControllerHelper;
267 : : }
268 : :
269 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|