LibreOffice Module sc (master)  1
documen5.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  * 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 <com/sun/star/util/XModifiable.hpp>
21 #include <com/sun/star/chart/ChartDataRowSource.hpp>
22 #include <com/sun/star/chart2/XChartDocument.hpp>
23 #include <com/sun/star/chart2/data/XDataProvider.hpp>
24 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
25 #include <com/sun/star/embed/XEmbeddedObject.hpp>
26 
27 #include <sfx2/objsh.hxx>
28 #include <svx/svditer.hxx>
29 #include <svx/svdoole2.hxx>
30 #include <svtools/embedhlp.hxx>
31 
32 #include <document.hxx>
33 #include <table.hxx>
34 #include <drwlayer.hxx>
35 #include <chartlis.hxx>
36 #include <chartlock.hxx>
37 #include <refupdat.hxx>
38 
39 #include <miscuno.hxx>
40 #include <chart2uno.hxx>
41 #include <charthelper.hxx>
42 
43 using namespace ::com::sun::star;
44 
45 static void lcl_GetChartParameters( const uno::Reference< chart2::XChartDocument >& xChartDoc,
46  OUString& rRanges, chart::ChartDataRowSource& rDataRowSource,
47  bool& rHasCategories, bool& rFirstCellAsLabel )
48 {
49  rHasCategories = rFirstCellAsLabel = false; // default if not in sequence
50 
51  uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
52 
53  uno::Reference< chart2::data::XDataSource > xDataSource = xReceiver->getUsedData();
54  uno::Reference< chart2::data::XDataProvider > xProvider = xChartDoc->getDataProvider();
55 
56  if ( !xProvider.is() )
57  return;
58 
59  const uno::Sequence< beans::PropertyValue > aArgs( xProvider->detectArguments( xDataSource ) );
60 
61  for (const beans::PropertyValue& rProp : aArgs)
62  {
63  OUString aPropName(rProp.Name);
64 
65  if ( aPropName == "CellRangeRepresentation" )
66  rProp.Value >>= rRanges;
67  else if ( aPropName == "DataRowSource" )
68  rDataRowSource = static_cast<chart::ChartDataRowSource>(ScUnoHelpFunctions::GetEnumFromAny( rProp.Value ));
69  else if ( aPropName == "HasCategories" )
70  rHasCategories = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
71  else if ( aPropName == "FirstCellAsLabel" )
72  rFirstCellAsLabel = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
73  }
74 }
75 
76 static void lcl_SetChartParameters( const uno::Reference< chart2::data::XDataReceiver >& xReceiver,
77  const OUString& rRanges, chart::ChartDataRowSource eDataRowSource,
78  bool bHasCategories, bool bFirstCellAsLabel )
79 {
80  if ( !xReceiver.is() )
81  return;
82 
83  uno::Sequence< beans::PropertyValue > aArgs( 4 );
84  aArgs[0] = beans::PropertyValue(
85  "CellRangeRepresentation", -1,
86  uno::makeAny( rRanges ), beans::PropertyState_DIRECT_VALUE );
87  aArgs[1] = beans::PropertyValue(
88  "HasCategories", -1,
89  uno::makeAny( bHasCategories ), beans::PropertyState_DIRECT_VALUE );
90  aArgs[2] = beans::PropertyValue(
91  "FirstCellAsLabel", -1,
92  uno::makeAny( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE );
93  aArgs[3] = beans::PropertyValue(
94  "DataRowSource", -1,
95  uno::makeAny( eDataRowSource ), beans::PropertyState_DIRECT_VALUE );
96  xReceiver->setArguments( aArgs );
97 }
98 
99 bool ScDocument::HasChartAtPoint( SCTAB nTab, const Point& rPos, OUString& rName )
100 {
101  if (mpDrawLayer && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
102  {
103  SdrPage* pPage = mpDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
104  OSL_ENSURE(pPage,"Page ?");
105 
106  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
107  SdrObject* pObject = aIter.Next();
108  while (pObject)
109  {
110  if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
111  pObject->GetCurrentBoundRect().IsInside(rPos) )
112  {
113  // also Chart-Objects that are not in the Collection
114 
115  if (IsChart(pObject))
116  {
117  rName = static_cast<SdrOle2Obj*>(pObject)->GetPersistName();
118  return true;
119  }
120  }
121  pObject = aIter.Next();
122  }
123  }
124 
125  rName.clear();
126  return false; // nothing found
127 }
128 
129 void ScDocument::UpdateChartArea( const OUString& rChartName,
130  const ScRange& rNewArea, bool bColHeaders, bool bRowHeaders,
131  bool bAdd )
132 {
133  ScRangeListRef aRLR( new ScRangeList(rNewArea) );
134  UpdateChartArea( rChartName, aRLR, bColHeaders, bRowHeaders, bAdd );
135 }
136 
137 uno::Reference< chart2::XChartDocument > ScDocument::GetChartByName( const OUString& rChartName )
138 {
139  uno::Reference< chart2::XChartDocument > xReturn;
140 
141  if (mpDrawLayer)
142  {
143  sal_uInt16 nCount = mpDrawLayer->GetPageCount();
144  SCTAB nSize = static_cast<SCTAB>(maTabs.size());
145  for (sal_uInt16 nTab=0; nTab<nCount && nTab < nSize; nTab++)
146  {
147  SdrPage* pPage = mpDrawLayer->GetPage(nTab);
148  OSL_ENSURE(pPage,"Page ?");
149 
150  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
151  SdrObject* pObject = aIter.Next();
152  while (pObject)
153  {
154  if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
155  static_cast<SdrOle2Obj*>(pObject)->GetPersistName() == rChartName )
156  {
157  xReturn.set( ScChartHelper::GetChartFromSdrObject( pObject ) );
158  return xReturn;
159  }
160  pObject = aIter.Next();
161  }
162  }
163  }
164  return xReturn;
165 }
166 void ScDocument::GetChartRanges( const OUString& rChartName, ::std::vector< ScRangeList >& rRangesVector, const ScDocument* pSheetNameDoc )
167 {
168  rRangesVector.clear();
169  uno::Reference< chart2::XChartDocument > xChartDoc( GetChartByName( rChartName ) );
170  if ( xChartDoc.is() )
171  {
172  std::vector< OUString > aRangeStrings;
173  ScChartHelper::GetChartRanges( xChartDoc, aRangeStrings );
174  for(const OUString & aRangeString : aRangeStrings)
175  {
176  ScRangeList aRanges;
177  aRanges.Parse( aRangeString, pSheetNameDoc, pSheetNameDoc->GetAddressConvention() );
178  rRangesVector.push_back(aRanges);
179  }
180  }
181 }
182 
183 void ScDocument::SetChartRanges( const OUString& rChartName, const ::std::vector< ScRangeList >& rRangesVector )
184 {
185  uno::Reference< chart2::XChartDocument > xChartDoc( GetChartByName( rChartName ) );
186  if ( !xChartDoc.is() )
187  return;
188 
189  sal_Int32 nCount = static_cast<sal_Int32>( rRangesVector.size() );
190  uno::Sequence< OUString > aRangeStrings(nCount);
191  for( sal_Int32 nN=0; nN<nCount; nN++ )
192  {
193  ScRangeList aScRangeList( rRangesVector[nN] );
194  OUString sRangeStr;
195  aScRangeList.Format( sRangeStr, ScRefFlags::RANGE_ABS_3D, *this, GetAddressConvention() );
196  aRangeStrings[nN]=sRangeStr;
197  }
198  ScChartHelper::SetChartRanges( xChartDoc, aRangeStrings );
199 }
200 
201 void ScDocument::GetOldChartParameters( const OUString& rName,
202  ScRangeList& rRanges, bool& rColHeaders, bool& rRowHeaders )
203 {
204  // used for undo of changing chart source area
205 
206  if (!mpDrawLayer)
207  return;
208 
209  sal_uInt16 nCount = mpDrawLayer->GetPageCount();
210  for (sal_uInt16 nTab=0; nTab<nCount && nTab < static_cast<SCTAB>(maTabs.size()); nTab++)
211  {
212  SdrPage* pPage = mpDrawLayer->GetPage(nTab);
213  OSL_ENSURE(pPage,"Page ?");
214 
215  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
216  SdrObject* pObject = aIter.Next();
217  while (pObject)
218  {
219  if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
220  static_cast<SdrOle2Obj*>(pObject)->GetPersistName() == rName )
221  {
222  uno::Reference< chart2::XChartDocument > xChartDoc( ScChartHelper::GetChartFromSdrObject( pObject ) );
223  if ( xChartDoc.is() )
224  {
225  chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
226  bool bHasCategories = false;
227  bool bFirstCellAsLabel = false;
228  OUString aRangesStr;
229  lcl_GetChartParameters( xChartDoc, aRangesStr, eDataRowSource, bHasCategories, bFirstCellAsLabel );
230 
231  rRanges.Parse( aRangesStr, this );
232  if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS )
233  {
234  rRowHeaders = bHasCategories;
235  rColHeaders = bFirstCellAsLabel;
236  }
237  else
238  {
239  rColHeaders = bHasCategories;
240  rRowHeaders = bFirstCellAsLabel;
241  }
242  }
243  return;
244  }
245  pObject = aIter.Next();
246  }
247  }
248 }
249 
250 void ScDocument::UpdateChartArea( const OUString& rChartName,
251  const ScRangeListRef& rNewList, bool bColHeaders, bool bRowHeaders,
252  bool bAdd )
253 {
254  if (!mpDrawLayer)
255  return;
256 
257  for (SCTAB nTab=0; nTab< static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]; nTab++)
258  {
259  SdrPage* pPage = mpDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
260  OSL_ENSURE(pPage,"Page ?");
261 
262  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
263  SdrObject* pObject = aIter.Next();
264  while (pObject)
265  {
266  if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
267  static_cast<SdrOle2Obj*>(pObject)->GetPersistName() == rChartName )
268  {
269  uno::Reference< chart2::XChartDocument > xChartDoc( ScChartHelper::GetChartFromSdrObject( pObject ) );
270  uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
271  if ( xChartDoc.is() && xReceiver.is() )
272  {
273  ScRangeListRef aNewRanges;
274  chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
275  bool bHasCategories = false;
276  bool bFirstCellAsLabel = false;
277  OUString aRangesStr;
278  lcl_GetChartParameters( xChartDoc, aRangesStr, eDataRowSource, bHasCategories, bFirstCellAsLabel );
279 
280  bool bInternalData = xChartDoc->hasInternalDataProvider();
281 
282  if ( bAdd && !bInternalData )
283  {
284  // append to old ranges, keep other settings
285 
286  aNewRanges = new ScRangeList;
287  aNewRanges->Parse( aRangesStr, this );
288 
289  for ( size_t nAdd = 0, nAddCount = rNewList->size(); nAdd < nAddCount; ++nAdd )
290  aNewRanges->push_back( (*rNewList)[nAdd] );
291  }
292  else
293  {
294  // directly use new ranges (only eDataRowSource is used from old settings)
295 
296  if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS )
297  {
298  bHasCategories = bRowHeaders;
299  bFirstCellAsLabel = bColHeaders;
300  }
301  else
302  {
303  bHasCategories = bColHeaders;
304  bFirstCellAsLabel = bRowHeaders;
305  }
306  aNewRanges = rNewList;
307  }
308 
309  if ( bInternalData && mpShell )
310  {
311  // Calc -> DataProvider
312  uno::Reference< chart2::data::XDataProvider > xDataProvider = new ScChart2DataProvider( this );
313  xReceiver->attachDataProvider( xDataProvider );
314  uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier(
315  mpShell->GetModel(), uno::UNO_QUERY );
316  xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
317  }
318 
319  OUString sRangeStr;
320  aNewRanges->Format( sRangeStr, ScRefFlags::RANGE_ABS_3D, *this, GetAddressConvention() );
321 
322  lcl_SetChartParameters( xReceiver, sRangeStr, eDataRowSource, bHasCategories, bFirstCellAsLabel );
323 
324  pChartListenerCollection->ChangeListening( rChartName, aNewRanges );
325 
326  return; // do not search anymore
327  }
328  }
329  pObject = aIter.Next();
330  }
331  }
332 }
333 
334 void ScDocument::UpdateChart( const OUString& rChartName )
335 {
336  if (!mpDrawLayer || bInDtorClear)
337  return;
338  uno::Reference< chart2::XChartDocument > xChartDoc( GetChartByName( rChartName ) );
339  if (xChartDoc && (!mpShell || mpShell->IsEnableSetModified()))
340  {
341  try
342  {
343  uno::Reference< util::XModifiable > xModif( xChartDoc, uno::UNO_QUERY_THROW );
345  apTemporaryChartLock->AlsoLockThisChart( uno::Reference< frame::XModel >( xModif, uno::UNO_QUERY ) );
346  xModif->setModified( true );
347  }
348  catch ( uno::Exception& )
349  {
350  }
351  }
352 
353  // After the update, chart keeps track of its own data source ranges,
354  // the listener doesn't need to listen anymore, except the chart has
355  // an internal data provider.
356  if ( !( xChartDoc.is() && xChartDoc->hasInternalDataProvider() ) && pChartListenerCollection )
357  {
358  pChartListenerCollection->ChangeListening( rChartName, new ScRangeList );
359  }
360 }
361 
362 void ScDocument::RestoreChartListener( const OUString& rName )
363 {
364  // Read the data ranges from the chart object, and start listening to those ranges again
365  // (called when a chart is saved, because then it might be swapped out and stop listening itself).
366 
367  uno::Reference< embed::XEmbeddedObject > xObject = FindOleObjectByName( rName );
368  if ( !xObject.is() )
369  return;
370 
371  uno::Reference< util::XCloseable > xComponent = xObject->getComponent();
372  uno::Reference< chart2::XChartDocument > xChartDoc( xComponent, uno::UNO_QUERY );
373  uno::Reference< chart2::data::XDataReceiver > xReceiver( xComponent, uno::UNO_QUERY );
374  if ( !(xChartDoc.is() && xReceiver.is() && !xChartDoc->hasInternalDataProvider()))
375  return;
376 
377  const uno::Sequence<OUString> aRepresentations( xReceiver->getUsedRangeRepresentations() );
378  ScRangeListRef aRanges = new ScRangeList;
379  for ( const auto& rRepresentation : aRepresentations )
380  {
381  ScRange aRange;
382  ScAddress::Details aDetails(GetAddressConvention(), 0, 0);
383  if ( aRange.ParseAny( rRepresentation, this, aDetails ) & ScRefFlags::VALID )
384  aRanges->push_back( aRange );
385  }
386 
387  pChartListenerCollection->ChangeListening( rName, aRanges );
388 }
389 
391  SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
392  SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
393  SCCOL nDx, SCROW nDy, SCTAB nDz )
394 {
395  if (!mpDrawLayer)
396  return;
397 
399  for (auto const& it : rListeners)
400  {
401  ScChartListener *const pChartListener = it.second.get();
402  ScRangeListRef aRLR( pChartListener->GetRangeList() );
403  ScRangeListRef aNewRLR( new ScRangeList );
404  bool bChanged = false;
405  bool bDataChanged = false;
406  for ( size_t i = 0, nListSize = aRLR->size(); i < nListSize; ++i )
407  {
408  ScRange& rRange = (*aRLR)[i];
409  SCCOL theCol1 = rRange.aStart.Col();
410  SCROW theRow1 = rRange.aStart.Row();
411  SCTAB theTab1 = rRange.aStart.Tab();
412  SCCOL theCol2 = rRange.aEnd.Col();
413  SCROW theRow2 = rRange.aEnd.Row();
414  SCTAB theTab2 = rRange.aEnd.Tab();
416  this, eUpdateRefMode,
417  nCol1,nRow1,nTab1, nCol2,nRow2,nTab2,
418  nDx,nDy,nDz,
419  theCol1,theRow1,theTab1,
420  theCol2,theRow2,theTab2 );
421  if ( eRes != UR_NOTHING )
422  {
423  bChanged = true;
424  aNewRLR->push_back( ScRange(
425  theCol1, theRow1, theTab1,
426  theCol2, theRow2, theTab2 ));
427  if ( eUpdateRefMode == URM_INSDEL
428  && !bDataChanged
429  && (eRes == UR_INVALID ||
430  ((rRange.aEnd.Col() - rRange.aStart.Col()
431  != theCol2 - theCol1)
432  || (rRange.aEnd.Row() - rRange.aStart.Row()
433  != theRow2 - theRow1)
434  || (rRange.aEnd.Tab() - rRange.aStart.Tab()
435  != theTab2 - theTab1))) )
436  {
437  bDataChanged = true;
438  }
439  }
440  else
441  aNewRLR->push_back( rRange );
442  }
443  if ( bChanged )
444  {
445  // Force the chart to be loaded now, so it registers itself for UNO events.
446  // UNO broadcasts are done after UpdateChartRef, so the chart will get this
447  // reference change.
448 
449  uno::Reference<embed::XEmbeddedObject> xIPObj =
450  FindOleObjectByName(pChartListener->GetName());
451 
453 
454  // After the change, chart keeps track of its own data source ranges,
455  // the listener doesn't need to listen anymore, except the chart has
456  // an internal data provider.
457  bool bInternalDataProvider = false;
458  if ( xIPObj.is() )
459  {
460  try
461  {
462  uno::Reference< chart2::XChartDocument > xChartDoc( xIPObj->getComponent(), uno::UNO_QUERY_THROW );
463  bInternalDataProvider = xChartDoc->hasInternalDataProvider();
464  }
465  catch ( uno::Exception& )
466  {
467  }
468  }
469  if ( bInternalDataProvider )
470  {
471  pChartListener->ChangeListening( aNewRLR, bDataChanged );
472  }
473  else
474  {
475  pChartListener->ChangeListening( new ScRangeList, bDataChanged );
476  }
477  }
478  }
479 }
480 
481 void ScDocument::SetChartRangeList( const OUString& rChartName,
482  const ScRangeListRef& rNewRangeListRef )
483 {
484  // called from ChartListener
485 
486  if (!mpDrawLayer)
487  return;
488 
489  for (SCTAB nTab=0; nTab< static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]; nTab++)
490  {
491  SdrPage* pPage = mpDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
492  OSL_ENSURE(pPage,"Page ?");
493 
494  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
495  SdrObject* pObject = aIter.Next();
496  while (pObject)
497  {
498  if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
499  static_cast<SdrOle2Obj*>(pObject)->GetPersistName() == rChartName )
500  {
501  uno::Reference< chart2::XChartDocument > xChartDoc( ScChartHelper::GetChartFromSdrObject( pObject ) );
502  uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
503  if ( xChartDoc.is() && xReceiver.is() )
504  {
505  chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
506  bool bHasCategories = false;
507  bool bFirstCellAsLabel = false;
508  OUString aRangesStr;
509  lcl_GetChartParameters( xChartDoc, aRangesStr, eDataRowSource, bHasCategories, bFirstCellAsLabel );
510 
511  OUString sRangeStr;
512  rNewRangeListRef->Format( sRangeStr, ScRefFlags::RANGE_ABS_3D, *this, GetAddressConvention() );
513 
514  lcl_SetChartParameters( xReceiver, sRangeStr, eDataRowSource, bHasCategories, bFirstCellAsLabel );
515 
516  // don't modify pChartListenerCollection here, called from there
517  return;
518  }
519  }
520  pObject = aIter.Next();
521  }
522  }
523 }
524 
525 bool ScDocument::HasData( SCCOL nCol, SCROW nRow, SCTAB nTab )
526 {
527  if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]
528  && nCol < maTabs[nTab]->GetAllocatedColumnsCount())
529  return maTabs[nTab]->HasData( nCol, nRow );
530  else
531  return false;
532 }
533 
534 uno::Reference< embed::XEmbeddedObject >
535  ScDocument::FindOleObjectByName( const OUString& rName )
536 {
537  if (!mpDrawLayer)
538  return uno::Reference< embed::XEmbeddedObject >();
539 
540  // take the pages here from Draw-Layer, as they might not match with the tables
541  // (e.g. delete Redo of table; Draw-Redo happens before DeleteTab)
542 
543  sal_uInt16 nCount = mpDrawLayer->GetPageCount();
544  for (sal_uInt16 nTab=0; nTab<nCount; nTab++)
545  {
546  SdrPage* pPage = mpDrawLayer->GetPage(nTab);
547  OSL_ENSURE(pPage,"Page ?");
548 
549  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
550  SdrObject* pObject = aIter.Next();
551  while (pObject)
552  {
553  if ( pObject->GetObjIdentifier() == OBJ_OLE2 )
554  {
555  SdrOle2Obj * pOleObject ( dynamic_cast< SdrOle2Obj * >( pObject ));
556  if( pOleObject &&
557  pOleObject->GetPersistName() == rName )
558  {
559  return pOleObject->GetObjRef();
560  }
561  }
562  pObject = aIter.Next();
563  }
564  }
565 
566  return uno::Reference< embed::XEmbeddedObject >();
567 }
568 
570 {
572 
574  if (!mpDrawLayer)
575  return;
576 
577  for (SCTAB nTab=0; nTab< static_cast<SCTAB>(maTabs.size()); nTab++)
578  {
579  if (!maTabs[nTab])
580  continue;
581 
582  SdrPage* pPage = mpDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
583  OSL_ENSURE(pPage,"Page ?");
584 
585  if (!pPage)
586  continue;
587 
588  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
590  pChartListenerCollection->getNonOleObjectNames();
591 
592  for (SdrObject* pObject = aIter.Next(); pObject; pObject = aIter.Next())
593  {
594  if ( pObject->GetObjIdentifier() != OBJ_OLE2 )
595  continue;
596 
597  OUString aObjName = static_cast<SdrOle2Obj*>(pObject)->GetPersistName();
598  ScChartListener* pListener = pChartListenerCollection->findByName(aObjName);
599 
600  if (pListener)
601  pListener->SetUsed(true);
602  else if (rNonOleObjects.count(aObjName) > 0)
603  {
604  // non-chart OLE object -> don't touch
605  }
606  else
607  {
608  uno::Reference< embed::XEmbeddedObject > xIPObj = static_cast<SdrOle2Obj*>(pObject)->GetObjRef();
609  OSL_ENSURE( xIPObj.is(), "No embedded object is given!");
610  uno::Reference< css::chart2::data::XDataReceiver > xReceiver;
611  if( xIPObj.is())
612  xReceiver.set( xIPObj->getComponent(), uno::UNO_QUERY );
613 
614  // if the object is a chart2::XDataReceiver, we must attach as XDataProvider
615  if( xReceiver.is() &&
617  {
618  // NOTE: this currently does not work as we are
619  // unable to set the data. So a chart from the
620  // same document is treated like a chart with
621  // own data for the time being.
622 
623  // data provider
624  // number formats supplier
625 
626  // data ?
627  // how to set?? Defined in XML-file, which is already loaded!!!
628  // => we have to do this stuff here, BEFORE the chart is actually loaded
629  }
630 
631  // put into list of other ole objects, so the object doesn't have to
632  // be swapped in the next time UpdateChartListenerCollection is called
633  //TODO: remove names when objects are no longer there?
634  // (object names aren't used again before reloading the document)
635 
636  rNonOleObjects.insert(aObjName);
637  }
638  }
639  }
640  // delete all that are not set SetUsed
641  pChartListenerCollection->FreeUnused();
642 }
643 
644 void ScDocument::AddOLEObjectToCollection(const OUString& rName)
645 {
648  pChartListenerCollection->getNonOleObjectNames();
649 
650  rNonOleObjects.insert(rName);
651 }
652 
653 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC ScRefFlags ParseAny(const OUString &, const ScDocument *, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1)
Definition: address.cxx:1770
static ScRefUpdateRes Update(const ScDocument *pDoc, UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, SCCOL nDx, SCROW nDy, SCTAB nDz, SCCOL &theCol1, SCROW &theRow1, SCTAB &theTab1, SCCOL &theCol2, SCROW &theRow2, SCTAB &theTab2)
Definition: refupdat.cxx:189
ScAddress aStart
Definition: address.hxx:500
static sal_Int32 GetEnumFromAny(const css::uno::Any &aAny)
Definition: miscuno.cxx:160
virtual const tools::Rectangle & GetCurrentBoundRect() const
OBJ_OLE2
css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef() const
bool bChartListenerCollectionNeedsUpdate
Definition: document.hxx:515
bool bInDtorClear
Definition: document.hxx:519
SCROW Row() const
Definition: address.hxx:262
static css::uno::Reference< css::chart2::XChartDocument > GetChartFromSdrObject(const SdrObject *pObject)
std::unordered_set< OUString > StringSetType
Definition: chartlis.hxx:126
SfxObjectShell * mpShell
Definition: document.hxx:376
void Format(OUString &, ScRefFlags nFlags, const ScDocument &, formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO, sal_Unicode cDelimiter=0, bool bFullAddressNotation=false) const
Definition: rangelst.cxx:146
static void lcl_GetChartParameters(const uno::Reference< chart2::XChartDocument > &xChartDoc, OUString &rRanges, chart::ChartDataRowSource &rDataRowSource, bool &rHasCategories, bool &rFirstCellAsLabel)
Definition: documen5.cxx:45
ScRangeListRef GetRangeList() const
Definition: chartlis.cxx:186
ScAddress aEnd
Definition: address.hxx:501
ScRefFlags Parse(const OUString &, const ScDocument *, formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO, SCTAB nDefaultTab=0, sal_Unicode cDelimiter=0)
Definition: rangelst.cxx:106
css::uno::Reference< css::frame::XModel > GetModel() const
EmbeddedObjectRef * pObject
Some part of the reference became invalid.
Definition: refupdat.hxx:34
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:475
void UpdateChartArea(const OUString &rChartName, const ScRange &rNewArea, bool bColHeaders, bool bRowHeaders, bool bAdd)
Definition: documen5.cxx:129
void UpdateChart(const OUString &rName)
Definition: documen5.cxx:334
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
bool HasChartAtPoint(SCTAB nTab, const Point &rPos, OUString &rName)
Definition: documen5.cxx:99
TableContainer maTabs
Definition: document.hxx:383
int nCount
void push_back(const ScRange &rRange)
Definition: rangelst.cxx:1144
SCTAB Tab() const
Definition: address.hxx:271
void RestoreChartListener(const OUString &rName)
Definition: documen5.cxx:362
std::unique_ptr< ScDrawLayer > mpDrawLayer
Definition: document.hxx:379
SC_DLLPUBLIC SCCOL GetAllocatedColumnsCount(SCTAB nTab) const
Definition: documen3.cxx:2110
void AddOLEObjectToCollection(const OUString &rName)
Definition: documen5.cxx:644
bool PastingDrawFromOtherDoc() const
Definition: document.hxx:2423
int i
static void GetChartRanges(const css::uno::Reference< css::chart2::XChartDocument > &xChartDoc, std::vector< OUString > &rRanges)
void GetOldChartParameters(const OUString &rName, ScRangeList &rRanges, bool &rColHeaders, bool &rRowHeaders)
Definition: documen5.cxx:201
virtual sal_uInt16 GetObjIdentifier() const
const OUString & GetName() const
Definition: chartlis.hxx:83
sal_Int16 SCCOL
Definition: types.hxx:22
void SetUsed(bool bFlg)
Definition: chartlis.hxx:101
size_t size() const
Definition: rangelst.hxx:90
bool IsInside(const Point &rPOINT) const
css::uno::Reference< css::chart2::XChartDocument > GetChartByName(const OUString &rChartName)
Definition: documen5.cxx:137
void UpdateChartRef(UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, SCCOL nDx, SCROW nDy, SCTAB nDz)
Definition: documen5.cxx:390
std::map< OUString, std::unique_ptr< ScChartListener > > ListenersType
Definition: chartlis.hxx:125
Reference not affected, no change at all.
Definition: refupdat.hxx:32
SCCOL Col() const
Definition: address.hxx:267
void SetChartRangeList(const OUString &rChartName, const ScRangeListRef &rNewRangeListRef)
only assigns the new RangeList, no ChartListener or the like
Definition: documen5.cxx:481
UpdateRefMode
Definition: global.hxx:310
SdrObject * Next()
sal_Int32 SCROW
Definition: types.hxx:18
void ChangeListening(const ScRangeListRef &rRangeListRef, bool bDirty)
Definition: chartlis.cxx:282
const OUString & GetPersistName() const
SC_DLLPUBLIC bool HasData(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: documen5.cxx:525
ScRefUpdateRes
Definition: refupdat.hxx:31
SC_DLLPUBLIC void UpdateChartListenerCollection()
Definition: documen5.cxx:569
static bool IsChart(const SdrObject *pObject)
Definition: documen9.cxx:201
bool IsEnableSetModified() const
static void lcl_SetChartParameters(const uno::Reference< chart2::data::XDataReceiver > &xReceiver, const OUString &rRanges, chart::ChartDataRowSource eDataRowSource, bool bHasCategories, bool bFirstCellAsLabel)
Definition: documen5.cxx:76
static bool TryRunningState(const css::uno::Reference< css::embed::XEmbeddedObject > &)
static bool GetBoolFromAny(const css::uno::Any &aAny)
Definition: miscuno.cxx:138
SC_DLLPUBLIC void GetChartRanges(const OUString &rChartName, std::vector< ScRangeList > &rRanges, const ScDocument *pSheetNameDoc)
Definition: documen5.cxx:166
void SetChartRanges(const OUString &rChartName, const std::vector< ScRangeList > &rRanges)
Definition: documen5.cxx:183
static void SetChartRanges(const css::uno::Reference< css::chart2::XChartDocument > &xChartDoc, const css::uno::Sequence< OUString > &rRanges)
std::unique_ptr< ScChartListenerCollection > pChartListenerCollection
Definition: document.hxx:396
bool ValidTab(SCTAB nTab)
Definition: address.hxx:105
std::unique_ptr< ScTemporaryChartLock > apTemporaryChartLock
Definition: document.hxx:389
sal_Int16 SCTAB
Definition: types.hxx:23
css::uno::Reference< css::embed::XEmbeddedObject > FindOleObjectByName(const OUString &rName)
Definition: documen5.cxx:535