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().Contains(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( std::u16string_view 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 
167 void ScDocument::GetChartRanges( std::u16string_view rChartName, ::std::vector< ScRangeList >& rRangesVector, const ScDocument& rSheetNameDoc )
168 {
169  rRangesVector.clear();
170  uno::Reference< chart2::XChartDocument > xChartDoc( GetChartByName( rChartName ) );
171  if ( xChartDoc.is() )
172  {
173  std::vector< OUString > aRangeStrings;
174  ScChartHelper::GetChartRanges( xChartDoc, aRangeStrings );
175  for(const OUString & aRangeString : aRangeStrings)
176  {
177  ScRangeList aRanges;
178  aRanges.Parse( aRangeString, rSheetNameDoc, rSheetNameDoc.GetAddressConvention() );
179  rRangesVector.push_back(aRanges);
180  }
181  }
182 }
183 
184 void ScDocument::SetChartRanges( std::u16string_view rChartName, const ::std::vector< ScRangeList >& rRangesVector )
185 {
186  uno::Reference< chart2::XChartDocument > xChartDoc( GetChartByName( rChartName ) );
187  if ( !xChartDoc.is() )
188  return;
189 
190  sal_Int32 nCount = static_cast<sal_Int32>( rRangesVector.size() );
191  uno::Sequence< OUString > aRangeStrings(nCount);
192  for( sal_Int32 nN=0; nN<nCount; nN++ )
193  {
194  ScRangeList aScRangeList( rRangesVector[nN] );
195  OUString sRangeStr;
196  aScRangeList.Format( sRangeStr, ScRefFlags::RANGE_ABS_3D, *this, GetAddressConvention() );
197  aRangeStrings[nN]=sRangeStr;
198  }
199  ScChartHelper::SetChartRanges( xChartDoc, aRangeStrings );
200 }
201 
202 void ScDocument::GetOldChartParameters( std::u16string_view rName,
203  ScRangeList& rRanges, bool& rColHeaders, bool& rRowHeaders )
204 {
205  // used for undo of changing chart source area
206 
207  if (!mpDrawLayer)
208  return;
209 
210  sal_uInt16 nCount = mpDrawLayer->GetPageCount();
211  for (sal_uInt16 nTab=0; nTab<nCount && nTab < static_cast<SCTAB>(maTabs.size()); nTab++)
212  {
213  SdrPage* pPage = mpDrawLayer->GetPage(nTab);
214  OSL_ENSURE(pPage,"Page ?");
215 
216  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
217  SdrObject* pObject = aIter.Next();
218  while (pObject)
219  {
220  if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
221  static_cast<SdrOle2Obj*>(pObject)->GetPersistName() == rName )
222  {
223  uno::Reference< chart2::XChartDocument > xChartDoc( ScChartHelper::GetChartFromSdrObject( pObject ) );
224  if ( xChartDoc.is() )
225  {
226  chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
227  bool bHasCategories = false;
228  bool bFirstCellAsLabel = false;
229  OUString aRangesStr;
230  lcl_GetChartParameters( xChartDoc, aRangesStr, eDataRowSource, bHasCategories, bFirstCellAsLabel );
231 
232  rRanges.Parse( aRangesStr, *this, GetAddressConvention());
233  if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS )
234  {
235  rRowHeaders = bHasCategories;
236  rColHeaders = bFirstCellAsLabel;
237  }
238  else
239  {
240  rColHeaders = bHasCategories;
241  rRowHeaders = bFirstCellAsLabel;
242  }
243  }
244  return;
245  }
246  pObject = aIter.Next();
247  }
248  }
249 }
250 
251 void ScDocument::UpdateChartArea( const OUString& rChartName,
252  const ScRangeListRef& rNewList, bool bColHeaders, bool bRowHeaders,
253  bool bAdd )
254 {
255  if (!mpDrawLayer)
256  return;
257 
258  for (SCTAB nTab=0; nTab< static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]; nTab++)
259  {
260  SdrPage* pPage = mpDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
261  OSL_ENSURE(pPage,"Page ?");
262 
263  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
264  SdrObject* pObject = aIter.Next();
265  while (pObject)
266  {
267  if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
268  static_cast<SdrOle2Obj*>(pObject)->GetPersistName() == rChartName )
269  {
270  uno::Reference< chart2::XChartDocument > xChartDoc( ScChartHelper::GetChartFromSdrObject( pObject ) );
271  uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
272  if ( xChartDoc.is() && xReceiver.is() )
273  {
274  ScRangeListRef aNewRanges;
275  chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
276  bool bHasCategories = false;
277  bool bFirstCellAsLabel = false;
278  OUString aRangesStr;
279  lcl_GetChartParameters( xChartDoc, aRangesStr, eDataRowSource, bHasCategories, bFirstCellAsLabel );
280 
281  bool bInternalData = xChartDoc->hasInternalDataProvider();
282 
283  if ( bAdd && !bInternalData )
284  {
285  // append to old ranges, keep other settings
286 
287  aNewRanges = new ScRangeList;
288  aNewRanges->Parse( aRangesStr, *this, GetAddressConvention());
289  aNewRanges->insert( aNewRanges->begin(), rNewList->begin(), rNewList->end() );
290  }
291  else
292  {
293  // directly use new ranges (only eDataRowSource is used from old settings)
294 
295  if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS )
296  {
297  bHasCategories = bRowHeaders;
298  bFirstCellAsLabel = bColHeaders;
299  }
300  else
301  {
302  bHasCategories = bColHeaders;
303  bFirstCellAsLabel = bRowHeaders;
304  }
305  aNewRanges = rNewList;
306  }
307 
308  if ( bInternalData && mpShell )
309  {
310  // Calc -> DataProvider
311  uno::Reference< chart2::data::XDataProvider > xDataProvider = new ScChart2DataProvider( this );
312  xReceiver->attachDataProvider( xDataProvider );
313  uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier(
314  mpShell->GetModel(), uno::UNO_QUERY );
315  xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
316  }
317 
318  OUString sRangeStr;
319  aNewRanges->Format( sRangeStr, ScRefFlags::RANGE_ABS_3D, *this, GetAddressConvention() );
320 
321  lcl_SetChartParameters( xReceiver, sRangeStr, eDataRowSource, bHasCategories, bFirstCellAsLabel );
322 
323  pChartListenerCollection->ChangeListening( rChartName, aNewRanges );
324 
325  return; // do not search anymore
326  }
327  }
328  pObject = aIter.Next();
329  }
330  }
331 }
332 
333 void ScDocument::UpdateChart( const OUString& rChartName )
334 {
335  if (!mpDrawLayer || bInDtorClear)
336  return;
337  uno::Reference< chart2::XChartDocument > xChartDoc( GetChartByName( rChartName ) );
338  if (xChartDoc && (!mpShell || mpShell->IsEnableSetModified()))
339  {
340  try
341  {
342  uno::Reference< util::XModifiable > xModif( xChartDoc, uno::UNO_QUERY_THROW );
344  apTemporaryChartLock->AlsoLockThisChart( uno::Reference< frame::XModel >( xModif, uno::UNO_QUERY ) );
345  xModif->setModified( true );
346  }
347  catch ( uno::Exception& )
348  {
349  }
350  }
351 
352  // After the update, chart keeps track of its own data source ranges,
353  // the listener doesn't need to listen anymore, except the chart has
354  // an internal data provider.
355  if ( !( xChartDoc.is() && xChartDoc->hasInternalDataProvider() ) && pChartListenerCollection )
356  {
357  pChartListenerCollection->ChangeListening( rChartName, new ScRangeList );
358  }
359 }
360 
361 void ScDocument::RestoreChartListener( const OUString& rName )
362 {
363  // Read the data ranges from the chart object, and start listening to those ranges again
364  // (called when a chart is saved, because then it might be swapped out and stop listening itself).
365 
366  uno::Reference< embed::XEmbeddedObject > xObject = FindOleObjectByName( rName );
367  if ( !xObject.is() )
368  return;
369 
370  uno::Reference< util::XCloseable > xComponent = xObject->getComponent();
371  uno::Reference< chart2::XChartDocument > xChartDoc( xComponent, uno::UNO_QUERY );
372  uno::Reference< chart2::data::XDataReceiver > xReceiver( xComponent, uno::UNO_QUERY );
373  if ( !xChartDoc.is() || !xReceiver.is() || xChartDoc->hasInternalDataProvider() )
374  return;
375 
376  const uno::Sequence<OUString> aRepresentations( xReceiver->getUsedRangeRepresentations() );
377  ScRangeListRef aRanges = new ScRangeList;
378  for ( const auto& rRepresentation : aRepresentations )
379  {
380  ScRange aRange;
381  ScAddress::Details aDetails(GetAddressConvention(), 0, 0);
382  if ( aRange.ParseAny( rRepresentation, *this, aDetails ) & ScRefFlags::VALID )
383  aRanges->push_back( aRange );
384  }
385 
386  pChartListenerCollection->ChangeListening( rName, aRanges );
387 }
388 
390  SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
391  SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
392  SCCOL nDx, SCROW nDy, SCTAB nDz )
393 {
394  if (!mpDrawLayer)
395  return;
396 
398  for (auto const& it : rListeners)
399  {
400  ScChartListener *const pChartListener = it.second.get();
401  ScRangeListRef aRLR( pChartListener->GetRangeList() );
402  ScRangeListRef aNewRLR( new ScRangeList );
403  bool bChanged = false;
404  bool bDataChanged = false;
405  for ( size_t i = 0, nListSize = aRLR->size(); i < nListSize; ++i )
406  {
407  ScRange& rRange = (*aRLR)[i];
408  SCCOL theCol1 = rRange.aStart.Col();
409  SCROW theRow1 = rRange.aStart.Row();
410  SCTAB theTab1 = rRange.aStart.Tab();
411  SCCOL theCol2 = rRange.aEnd.Col();
412  SCROW theRow2 = rRange.aEnd.Row();
413  SCTAB theTab2 = rRange.aEnd.Tab();
415  this, eUpdateRefMode,
416  nCol1,nRow1,nTab1, nCol2,nRow2,nTab2,
417  nDx,nDy,nDz,
418  theCol1,theRow1,theTab1,
419  theCol2,theRow2,theTab2 );
420  if ( eRes != UR_NOTHING )
421  {
422  bChanged = true;
423  aNewRLR->push_back( ScRange(
424  theCol1, theRow1, theTab1,
425  theCol2, theRow2, theTab2 ));
426  if ( eUpdateRefMode == URM_INSDEL
427  && !bDataChanged
428  && (eRes == UR_INVALID ||
429  ((rRange.aEnd.Col() - rRange.aStart.Col()
430  != theCol2 - theCol1)
431  || (rRange.aEnd.Row() - rRange.aStart.Row()
432  != theRow2 - theRow1)
433  || (rRange.aEnd.Tab() - rRange.aStart.Tab()
434  != theTab2 - theTab1))) )
435  {
436  bDataChanged = true;
437  }
438  }
439  else
440  aNewRLR->push_back( rRange );
441  }
442  if ( bChanged )
443  {
444  // Force the chart to be loaded now, so it registers itself for UNO events.
445  // UNO broadcasts are done after UpdateChartRef, so the chart will get this
446  // reference change.
447 
448  uno::Reference<embed::XEmbeddedObject> xIPObj =
449  FindOleObjectByName(pChartListener->GetName());
450 
452 
453  // After the change, chart keeps track of its own data source ranges,
454  // the listener doesn't need to listen anymore, except the chart has
455  // an internal data provider.
456  bool bInternalDataProvider = false;
457  if ( xIPObj.is() )
458  {
459  try
460  {
461  uno::Reference< chart2::XChartDocument > xChartDoc( xIPObj->getComponent(), uno::UNO_QUERY_THROW );
462  bInternalDataProvider = xChartDoc->hasInternalDataProvider();
463  }
464  catch ( uno::Exception& )
465  {
466  }
467  }
468  if ( bInternalDataProvider )
469  {
470  pChartListener->ChangeListening( aNewRLR, bDataChanged );
471  }
472  else
473  {
474  pChartListener->ChangeListening( new ScRangeList, bDataChanged );
475  }
476  }
477  }
478 }
479 
480 void ScDocument::SetChartRangeList( std::u16string_view rChartName,
481  const ScRangeListRef& rNewRangeListRef )
482 {
483  // called from ChartListener
484 
485  if (!mpDrawLayer)
486  return;
487 
488  for (SCTAB nTab=0; nTab< static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]; nTab++)
489  {
490  SdrPage* pPage = mpDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
491  OSL_ENSURE(pPage,"Page ?");
492 
493  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
494  SdrObject* pObject = aIter.Next();
495  while (pObject)
496  {
497  if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
498  static_cast<SdrOle2Obj*>(pObject)->GetPersistName() == rChartName )
499  {
500  uno::Reference< chart2::XChartDocument > xChartDoc( ScChartHelper::GetChartFromSdrObject( pObject ) );
501  uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
502  if ( xChartDoc.is() && xReceiver.is() )
503  {
504  chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
505  bool bHasCategories = false;
506  bool bFirstCellAsLabel = false;
507  OUString aRangesStr;
508  lcl_GetChartParameters( xChartDoc, aRangesStr, eDataRowSource, bHasCategories, bFirstCellAsLabel );
509 
510  OUString sRangeStr;
511  rNewRangeListRef->Format( sRangeStr, ScRefFlags::RANGE_ABS_3D, *this, GetAddressConvention() );
512 
513  lcl_SetChartParameters( xReceiver, sRangeStr, eDataRowSource, bHasCategories, bFirstCellAsLabel );
514 
515  // don't modify pChartListenerCollection here, called from there
516  return;
517  }
518  }
519  pObject = aIter.Next();
520  }
521  }
522 }
523 
524 bool ScDocument::HasData( SCCOL nCol, SCROW nRow, SCTAB nTab )
525 {
526  if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]
527  && nCol < maTabs[nTab]->GetAllocatedColumnsCount())
528  return maTabs[nTab]->HasData( nCol, nRow );
529  else
530  return false;
531 }
532 
533 uno::Reference< embed::XEmbeddedObject >
534  ScDocument::FindOleObjectByName( std::u16string_view rName )
535 {
536  if (!mpDrawLayer)
537  return uno::Reference< embed::XEmbeddedObject >();
538 
539  // take the pages here from Draw-Layer, as they might not match with the tables
540  // (e.g. delete Redo of table; Draw-Redo happens before DeleteTab)
541 
542  sal_uInt16 nCount = mpDrawLayer->GetPageCount();
543  for (sal_uInt16 nTab=0; nTab<nCount; nTab++)
544  {
545  SdrPage* pPage = mpDrawLayer->GetPage(nTab);
546  OSL_ENSURE(pPage,"Page ?");
547 
548  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
549  SdrObject* pObject = aIter.Next();
550  while (pObject)
551  {
552  if ( pObject->GetObjIdentifier() == OBJ_OLE2 )
553  {
554  SdrOle2Obj * pOleObject ( dynamic_cast< SdrOle2Obj * >( pObject ));
555  if( pOleObject &&
556  pOleObject->GetPersistName() == rName )
557  {
558  return pOleObject->GetObjRef();
559  }
560  }
561  pObject = aIter.Next();
562  }
563  }
564 
565  return uno::Reference< embed::XEmbeddedObject >();
566 }
567 
569 {
570  assert(pChartListenerCollection);
571 
573  if (!mpDrawLayer)
574  return;
575 
576  for (SCTAB nTab=0; nTab< static_cast<SCTAB>(maTabs.size()); nTab++)
577  {
578  if (!maTabs[nTab])
579  continue;
580 
581  SdrPage* pPage = mpDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
582  OSL_ENSURE(pPage,"Page ?");
583 
584  if (!pPage)
585  continue;
586 
587  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
589  pChartListenerCollection->getNonOleObjectNames();
590 
591  for (SdrObject* pObject = aIter.Next(); pObject; pObject = aIter.Next())
592  {
593  if ( pObject->GetObjIdentifier() != OBJ_OLE2 )
594  continue;
595 
596  OUString aObjName = static_cast<SdrOle2Obj*>(pObject)->GetPersistName();
597  ScChartListener* pListener = pChartListenerCollection->findByName(aObjName);
598 
599  if (pListener)
600  pListener->SetUsed(true);
601  else if (rNonOleObjects.count(aObjName) > 0)
602  {
603  // non-chart OLE object -> don't touch
604  }
605  else
606  {
607  uno::Reference< embed::XEmbeddedObject > xIPObj = static_cast<SdrOle2Obj*>(pObject)->GetObjRef();
608  OSL_ENSURE( xIPObj.is(), "No embedded object is given!");
609  uno::Reference< css::chart2::data::XDataReceiver > xReceiver;
610  if( xIPObj.is())
611  xReceiver.set( xIPObj->getComponent(), uno::UNO_QUERY );
612 
613  // if the object is a chart2::XDataReceiver, we must attach as XDataProvider
614  if( xReceiver.is() &&
616  {
617  // NOTE: this currently does not work as we are
618  // unable to set the data. So a chart from the
619  // same document is treated like a chart with
620  // own data for the time being.
621 
622  // data provider
623  // number formats supplier
624 
625  // data ?
626  // how to set?? Defined in XML-file, which is already loaded!!!
627  // => we have to do this stuff here, BEFORE the chart is actually loaded
628  }
629 
630  // put into list of other ole objects, so the object doesn't have to
631  // be swapped in the next time UpdateChartListenerCollection is called
632  //TODO: remove names when objects are no longer there?
633  // (object names aren't used again before reloading the document)
634 
635  rNonOleObjects.insert(aObjName);
636  }
637  }
638  }
639  // delete all that are not set SetUsed
640  pChartListenerCollection->FreeUnused();
641 }
642 
643 void ScDocument::AddOLEObjectToCollection(const OUString& rName)
644 {
645  assert(pChartListenerCollection);
647  pChartListenerCollection->getNonOleObjectNames();
648 
649  rNonOleObjects.insert(rName);
650 }
651 
652 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScRefFlags ParseAny(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1)
Definition: address.cxx:1775
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:188
ScAddress aStart
Definition: address.hxx:499
static sal_Int32 GetEnumFromAny(const css::uno::Any &aAny)
Definition: miscuno.cxx:160
virtual const tools::Rectangle & GetCurrentBoundRect() const
css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef() const
bool bChartListenerCollectionNeedsUpdate
Definition: document.hxx:507
bool bInDtorClear
Definition: document.hxx:511
SCROW Row() const
Definition: address.hxx:261
static css::uno::Reference< css::chart2::XChartDocument > GetChartFromSdrObject(const SdrObject *pObject)
bool Contains(const Point &rPOINT) const
std::unordered_set< OUString > StringSetType
Definition: chartlis.hxx:126
SfxObjectShell * mpShell
Definition: document.hxx:368
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:144
static void lcl_GetChartParameters(const uno::Reference< chart2::XChartDocument > &xChartDoc, OUString &rRanges, chart::ChartDataRowSource &rDataRowSource, bool &rHasCategories, bool &rFirstCellAsLabel)
Definition: documen5.cxx:45
css::uno::Reference< css::frame::XModel3 > GetModel() const
ScRangeListRef GetRangeList() const
Definition: chartlis.cxx:184
ScAddress aEnd
Definition: address.hxx:500
virtual SdrObjKind GetObjIdentifier() const
css::uno::Reference< css::embed::XEmbeddedObject > FindOleObjectByName(std::u16string_view rName)
Definition: documen5.cxx:534
EmbeddedObjectRef * pObject
css::uno::Reference< css::chart2::XChartDocument > GetChartByName(std::u16string_view rChartName)
Definition: documen5.cxx:137
Some part of the reference became invalid.
Definition: refupdat.hxx:33
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:494
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:333
bool HasChartAtPoint(SCTAB nTab, const Point &rPos, OUString &rName)
Definition: documen5.cxx:99
TableContainer maTabs
Definition: document.hxx:375
int nCount
void GetOldChartParameters(std::u16string_view rName, ScRangeList &rRanges, bool &rColHeaders, bool &rRowHeaders)
Definition: documen5.cxx:202
SCTAB Tab() const
Definition: address.hxx:270
void RestoreChartListener(const OUString &rName)
Definition: documen5.cxx:361
std::unique_ptr< ScDrawLayer > mpDrawLayer
Definition: document.hxx:371
SC_DLLPUBLIC SCCOL GetAllocatedColumnsCount(SCTAB nTab) const
Definition: documen3.cxx:2153
void AddOLEObjectToCollection(const OUString &rName)
Definition: documen5.cxx:643
bool PastingDrawFromOtherDoc() const
Definition: document.hxx:2436
int i
static void GetChartRanges(const css::uno::Reference< css::chart2::XChartDocument > &xChartDoc, std::vector< OUString > &rRanges)
const OUString & GetName() const
Definition: chartlis.hxx:83
sal_Int16 SCCOL
Definition: types.hxx:21
void SetUsed(bool bFlg)
Definition: chartlis.hxx:101
::std::vector< ScRange >::const_iterator end() const
Definition: rangelst.hxx:98
ScRefFlags Parse(const OUString &, const ScDocument &, formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO, SCTAB nDefaultTab=0, sal_Unicode cDelimiter=0)
Definition: rangelst.cxx:104
OUString aPropName
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:389
std::map< OUString, std::unique_ptr< ScChartListener > > ListenersType
Definition: chartlis.hxx:125
Reference not affected, no change at all.
Definition: refupdat.hxx:31
SCCOL Col() const
Definition: address.hxx:266
UpdateRefMode
Definition: global.hxx:310
SdrObject * Next()
sal_Int32 SCROW
Definition: types.hxx:17
void ChangeListening(const ScRangeListRef &rRangeListRef, bool bDirty)
Definition: chartlis.cxx:280
const OUString & GetPersistName() const
SC_DLLPUBLIC bool HasData(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: documen5.cxx:524
SC_DLLPUBLIC void GetChartRanges(std::u16string_view rChartName, std::vector< ScRangeList > &rRanges, const ScDocument &rSheetNameDoc)
Definition: documen5.cxx:167
void SetChartRangeList(std::u16string_view rChartName, const ScRangeListRef &rNewRangeListRef)
only assigns the new RangeList, no ChartListener or the like
Definition: documen5.cxx:480
ScRefUpdateRes
Definition: refupdat.hxx:30
SC_DLLPUBLIC void UpdateChartListenerCollection()
Definition: documen5.cxx:568
static bool IsChart(const SdrObject *pObject)
Definition: documen9.cxx:203
bool IsEnableSetModified() const
::std::vector< ScRange >::const_iterator begin() const
Definition: rangelst.hxx:97
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
void insert(std::vector< ScRange >::iterator aPos, std::vector< ScRange >::const_iterator aSourceBegin, std::vector< ScRange >::const_iterator aSourceEnd)
Definition: rangelst.hxx:101
void SetChartRanges(std::u16string_view rChartName, const std::vector< ScRangeList > &rRanges)
Definition: documen5.cxx:184
OBJ_OLE2
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:388
bool ValidTab(SCTAB nTab)
Definition: address.hxx:104
std::unique_ptr< ScTemporaryChartLock > apTemporaryChartLock
Definition: document.hxx:381
sal_Int16 SCTAB
Definition: types.hxx:22