LibreOffice Module sc (master)  1
chartuno.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/embed/Aspects.hpp>
21 #include <com/sun/star/embed/XEmbeddedObject.hpp>
22 #include <com/sun/star/awt/Size.hpp>
23 #include <com/sun/star/beans/PropertyAttribute.hpp>
24 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
25 #include <com/sun/star/chart/ChartDataRowSource.hpp>
26 #include <com/sun/star/chart2/XChartDocument.hpp>
27 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
28 #include <com/sun/star/table/CellRangeAddress.hpp>
29 
30 #include <osl/diagnose.h>
31 #include <svx/svditer.hxx>
32 #include <svx/svdoole2.hxx>
33 #include <svx/svdpage.hxx>
34 #include <svx/svdundo.hxx>
36 #include <comphelper/classids.hxx>
38 #include <tools/globname.hxx>
39 #include <svtools/embedhlp.hxx>
40 #include <vcl/svapp.hxx>
41 
42 #include <ChartTools.hxx>
43 #include <chartuno.hxx>
44 #include <miscuno.hxx>
45 #include <docsh.hxx>
46 #include <drwlayer.hxx>
47 #include <undodat.hxx>
48 #include <chartlis.hxx>
49 #include <chart2uno.hxx>
50 #include <convuno.hxx>
51 
52 using namespace css;
53 
54 #define PROP_HANDLE_RELATED_CELLRANGES 1
55 
56 SC_SIMPLE_SERVICE_INFO( ScChartObj, "ScChartObj", "com.sun.star.table.TableChart" )
57 SC_SIMPLE_SERVICE_INFO( ScChartsObj, "ScChartsObj", "com.sun.star.table.TableCharts" )
58 
59 ScChartsObj::ScChartsObj(ScDocShell* pDocSh, SCTAB nT) :
60  pDocShell( pDocSh ),
61  nTab( nT )
62 {
63  pDocShell->GetDocument().AddUnoObject(*this);
64 }
65 
67 {
69 
70  if (pDocShell)
71  pDocShell->GetDocument().RemoveUnoObject(*this);
72 }
73 
75 {
77 
78  if ( rHint.GetId() == SfxHintId::Dying )
79  {
80  pDocShell = nullptr;
81  }
82 }
83 
85 {
86  OUString aName;
87  if ( pDocShell )
88  {
89  ScDocument& rDoc = pDocShell->GetDocument();
90  ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
91  if (pDrawLayer)
92  {
93  SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
94  OSL_ENSURE(pPage, "Page not found");
95  if (pPage)
96  {
97  tools::Long nPos = 0;
98  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
99  SdrObject* pObject = aIter.Next();
100  while (pObject)
101  {
102  if ( pObject->GetObjIdentifier() == OBJ_OLE2 && ScDocument::IsChart(pObject) )
103  {
104  if ( nPos == nIndex )
105  {
106  uno::Reference < embed::XEmbeddedObject > xObj = static_cast<SdrOle2Obj*>(pObject)->GetObjRef();
107  if ( xObj.is() )
108  aName = pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
109  break; // stop searching
110  }
111  ++nPos;
112  }
113  pObject = aIter.Next();
114  }
115  }
116  }
117  }
118 
119  if (!aName.isEmpty())
120  return new ScChartObj( pDocShell, nTab, aName );
121  return nullptr;
122 }
123 
125 {
127  return new ScChartObj( pDocShell, nTab, aName );
129  return new ScChartObj( pDocShell, nTab, aName );
130  return nullptr;
131 }
132 
133 // XTableCharts
134 
135 void SAL_CALL ScChartsObj::addNewByName( const OUString& rName,
136  const awt::Rectangle& aRect,
137  const uno::Sequence<table::CellRangeAddress>& aRanges,
138  sal_Bool bColumnHeaders, sal_Bool bRowHeaders )
139 {
140  SolarMutexGuard aGuard;
141  if (!pDocShell)
142  return;
143 
144  ScDocument& rDoc = pDocShell->GetDocument();
145  ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
146  SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nTab));
147  OSL_ENSURE(pPage,"addChart: no Page");
148  if (!pPage)
149  return;
150 
151  // chart can't be inserted if any ole object with that name exists on any table
152  // (empty string: generate valid name)
153 
154  OUString aName = rName;
155  SCTAB nDummy;
156  if ( !aName.isEmpty() && pModel->GetNamedObject( aName, OBJ_OLE2, nDummy ) )
157  {
158  // object exists - only RuntimeException is specified
159  throw uno::RuntimeException();
160  }
161 
162  ScRangeList* pList = new ScRangeList;
163  for (const table::CellRangeAddress& rRange : aRanges)
164  {
165  ScRange aRange( static_cast<SCCOL>(rRange.StartColumn), rRange.StartRow, rRange.Sheet,
166  static_cast<SCCOL>(rRange.EndColumn), rRange.EndRow, rRange.Sheet );
167  pList->push_back( aRange );
168  }
169  ScRangeListRef xNewRanges( pList );
170 
171  uno::Reference < embed::XEmbeddedObject > xObj;
172  if ( SvtModuleOptions().IsChart() )
173  xObj = pDocShell->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID ).GetByteSequence(), aName );
174  if ( !xObj.is() )
175  return;
176 
177  // adjust rectangle
179  Point aRectPos( aRect.X, aRect.Y );
180  bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
181  if ( ( aRectPos.X() < 0 && !bLayoutRTL ) || ( aRectPos.X() > 0 && bLayoutRTL ) )
182  aRectPos.setX( 0 );
183 
184  if (aRectPos.Y() < 0)
185  aRectPos.setY( 0 );
186 
187  Size aRectSize( aRect.Width, aRect.Height );
188  if (aRectSize.Width() <= 0)
189  aRectSize.setWidth( 5000 ); // default size
190 
191  if (aRectSize.Height() <= 0)
192  aRectSize.setHeight( 5000 );
193  tools::Rectangle aInsRect( aRectPos, aRectSize );
194 
195  sal_Int64 nAspect(embed::Aspects::MSOLE_CONTENT);
196  MapUnit aMapUnit(VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) ));
197  Size aSize(aInsRect.GetSize());
198  aSize = OutputDevice::LogicToLogic( aSize, MapMode( MapUnit::Map100thMM ), MapMode( aMapUnit ) );
199  awt::Size aSz;
200  aSz.Width = aSize.Width();
201  aSz.Height = aSize.Height();
202 
203  // Calc -> DataProvider
204  uno::Reference< chart2::data::XDataProvider > xDataProvider = new
205  ScChart2DataProvider( &rDoc );
206  // Chart -> DataReceiver
207  uno::Reference< chart2::data::XDataReceiver > xReceiver;
208  if( xObj.is())
209  xReceiver.set( xObj->getComponent(), uno::UNO_QUERY );
210  if( xReceiver.is())
211  {
212  OUString sRangeStr;
213  xNewRanges->Format(sRangeStr, ScRefFlags::RANGE_ABS_3D, rDoc);
214 
215  // connect
216  if( !sRangeStr.isEmpty() )
217  xReceiver->attachDataProvider( xDataProvider );
218  else
219  sRangeStr = "all";
220 
221  uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pDocShell->GetModel(), uno::UNO_QUERY );
222  xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
223 
224  // set arguments
225  uno::Sequence< beans::PropertyValue > aArgs( 4 );
226  aArgs[0] = beans::PropertyValue(
227  "CellRangeRepresentation", -1,
228  uno::makeAny( sRangeStr ), beans::PropertyState_DIRECT_VALUE );
229  aArgs[1] = beans::PropertyValue(
230  "HasCategories", -1,
231  uno::makeAny( bRowHeaders ), beans::PropertyState_DIRECT_VALUE );
232  aArgs[2] = beans::PropertyValue(
233  "FirstCellAsLabel", -1,
234  uno::makeAny( bColumnHeaders ), beans::PropertyState_DIRECT_VALUE );
235  aArgs[3] = beans::PropertyValue(
236  "DataRowSource", -1,
237  uno::makeAny( chart::ChartDataRowSource_COLUMNS ), beans::PropertyState_DIRECT_VALUE );
238  xReceiver->setArguments( aArgs );
239  }
240 
241  ScChartListener* pChartListener =
242  new ScChartListener( aName, rDoc, xNewRanges );
243  rDoc.GetChartListenerCollection()->insert( pChartListener );
244  pChartListener->StartListeningTo();
245 
246  SdrOle2Obj* pObj = new SdrOle2Obj(
247  *pModel,
248  ::svt::EmbeddedObjectRef(xObj, embed::Aspects::MSOLE_CONTENT),
249  aName,
250  aInsRect);
251 
252  // set VisArea
253  if( xObj.is())
254  xObj->setVisualAreaSize( nAspect, aSz );
255 
256  // #i121334# This call will change the chart's default background fill from white to transparent.
257  // Add here again if this is wanted (see task description for details)
258  // ChartHelper::AdaptDefaultsForChart( xObj );
259 
260  pPage->InsertObject( pObj );
261  pModel->AddUndo( std::make_unique<SdrUndoInsertObj>( *pObj ) );
262 }
263 
264 void SAL_CALL ScChartsObj::removeByName( const OUString& aName )
265 {
266  SolarMutexGuard aGuard;
268  if (pObj)
269  {
270  ScDocument& rDoc = pDocShell->GetDocument();
272  ScDrawLayer* pModel = rDoc.GetDrawLayer(); // is not zero
273  SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nTab)); // is not zero
274 
275  pModel->AddUndo( std::make_unique<SdrUndoDelObj>( *pObj ) );
276  pPage->RemoveObject( pObj->GetOrdNum() );
277 
279  }
280 }
281 
282 // XEnumerationAccess
283 
284 uno::Reference<container::XEnumeration> SAL_CALL ScChartsObj::createEnumeration()
285 {
286  SolarMutexGuard aGuard;
287  return new ScIndexEnumeration(this, "com.sun.star.table.TableChartsEnumeration");
288 }
289 
290 // XIndexAccess
291 
292 sal_Int32 SAL_CALL ScChartsObj::getCount()
293 {
294  SolarMutexGuard aGuard;
295  sal_Int32 nCount = 0;
296  if ( pDocShell )
297  {
298  ScDocument& rDoc = pDocShell->GetDocument();
299  ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
300  if (pDrawLayer)
301  {
302  SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
303  OSL_ENSURE(pPage, "Page not found");
304  if (pPage)
305  {
306  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
307  SdrObject* pObject = aIter.Next();
308  while (pObject)
309  {
310  if ( pObject->GetObjIdentifier() == OBJ_OLE2 && ScDocument::IsChart(pObject) )
311  ++nCount;
312  pObject = aIter.Next();
313  }
314  }
315  }
316  }
317  return nCount;
318 }
319 
320 uno::Any SAL_CALL ScChartsObj::getByIndex( sal_Int32 nIndex )
321 {
322  SolarMutexGuard aGuard;
323  uno::Reference<table::XTableChart> xChart(GetObjectByIndex_Impl(nIndex));
324  if (!xChart.is())
325  throw lang::IndexOutOfBoundsException();
326 
327  return uno::makeAny(xChart);
328 }
329 
331 {
332  SolarMutexGuard aGuard;
334 }
335 
337 {
338  SolarMutexGuard aGuard;
339  return getCount() != 0;
340 }
341 
342 uno::Any SAL_CALL ScChartsObj::getByName( const OUString& aName )
343 {
344  SolarMutexGuard aGuard;
345  uno::Reference<table::XTableChart> xChart(GetObjectByName_Impl(aName));
346  if (!xChart.is())
347  throw container::NoSuchElementException();
348 
349  return uno::makeAny(xChart);
350 }
351 
352 uno::Sequence<OUString> SAL_CALL ScChartsObj::getElementNames()
353 {
354  SolarMutexGuard aGuard;
355  if (pDocShell)
356  {
357  ScDocument& rDoc = pDocShell->GetDocument();
358 
359  tools::Long nCount = getCount();
360  uno::Sequence<OUString> aSeq(nCount);
361  OUString* pAry = aSeq.getArray();
362 
363  tools::Long nPos = 0;
364  ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
365  if (pDrawLayer)
366  {
367  SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
368  OSL_ENSURE(pPage, "Page not found");
369  if (pPage)
370  {
371  SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
372  SdrObject* pObject = aIter.Next();
373  while (pObject)
374  {
375  if ( pObject->GetObjIdentifier() == OBJ_OLE2 && ScDocument::IsChart(pObject) )
376  {
377  OUString aName;
378  uno::Reference < embed::XEmbeddedObject > xObj = static_cast<SdrOle2Obj*>(pObject)->GetObjRef();
379  if ( xObj.is() )
380  aName = pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
381 
382  OSL_ENSURE(nPos<nCount, "oops, miscounted?");
383  pAry[nPos++] = aName;
384  }
385  pObject = aIter.Next();
386  }
387  }
388  }
389  OSL_ENSURE(nPos==nCount, "hey, miscounted?");
390 
391  return aSeq;
392  }
393  return {};
394 }
395 
396 sal_Bool SAL_CALL ScChartsObj::hasByName( const OUString& aName )
397 {
398  SolarMutexGuard aGuard;
399  SdrOle2Obj* aOle2Obj = sc::tools::findChartsByName(pDocShell, nTab, aName,
401  return aOle2Obj != nullptr;
402 }
403 
404 ScChartObj::ScChartObj(ScDocShell* pDocSh, SCTAB nT, const OUString& rN)
406  ,ScChartObj_PBase( ScChartObj_Base::rBHelper )
407  ,pDocShell( pDocSh )
408  ,nTab( nT )
409  ,aChartName( rN )
410 {
412 
413  registerPropertyNoMember( "RelatedCellRanges",
414  PROP_HANDLE_RELATED_CELLRANGES, beans::PropertyAttribute::MAYBEVOID,
415  cppu::UnoType<uno::Sequence<table::CellRangeAddress>>::get(),
416  css::uno::Any(uno::Sequence<table::CellRangeAddress>()) );
417 }
418 
420 {
421  SolarMutexGuard g;
422 
423  if (pDocShell)
425 }
426 
428 {
430 
431  if ( rHint.GetId() == SfxHintId::Dying )
432  {
433  pDocShell = nullptr;
434  }
435 }
436 
437 void ScChartObj::GetData_Impl( ScRangeListRef& rRanges, bool& rColHeaders, bool& rRowHeaders ) const
438 {
439  bool bFound = false;
440 
441  if( pDocShell )
442  {
443  ScDocument& rDoc = pDocShell->GetDocument();
444  uno::Reference< chart2::XChartDocument > xChartDoc( rDoc.GetChartByName( aChartName ) );
445  if( xChartDoc.is() )
446  {
447  uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
448  uno::Reference< chart2::data::XDataProvider > xProvider = xChartDoc->getDataProvider();
449  if( xReceiver.is() && xProvider.is() )
450  {
451  const uno::Sequence< beans::PropertyValue > aArgs( xProvider->detectArguments( xReceiver->getUsedData() ) );
452 
453  OUString aRanges;
454  chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
455  bool bHasCategories=false;
456  bool bFirstCellAsLabel=false;
457  for (const beans::PropertyValue& rProp : aArgs)
458  {
459  OUString aPropName(rProp.Name);
460 
461  if (aPropName == "CellRangeRepresentation")
462  rProp.Value >>= aRanges;
463  else if (aPropName == "DataRowSource")
464  eDataRowSource = static_cast<chart::ChartDataRowSource>(ScUnoHelpFunctions::GetEnumFromAny( rProp.Value ));
465  else if (aPropName == "HasCategories")
466  bHasCategories = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
467  else if (aPropName == "FirstCellAsLabel")
468  bFirstCellAsLabel = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
469  }
470 
471  if( chart::ChartDataRowSource_COLUMNS == eDataRowSource )
472  {
473  rColHeaders=bFirstCellAsLabel;
474  rRowHeaders=bHasCategories;
475  }
476  else
477  {
478  rColHeaders=bHasCategories;
479  rRowHeaders=bFirstCellAsLabel;
480  }
481  rRanges->Parse( aRanges, rDoc);
482  }
483  bFound = true;
484  }
485  }
486  if( !bFound )
487  {
488  rRanges = nullptr;
489  rColHeaders = false;
490  rRowHeaders = false;
491  }
492 }
493 
494 void ScChartObj::Update_Impl( const ScRangeListRef& rRanges, bool bColHeaders, bool bRowHeaders )
495 {
496  if (pDocShell)
497  {
498  ScDocument& rDoc = pDocShell->GetDocument();
499  bool bUndo(rDoc.IsUndoEnabled());
500 
501  if (bUndo)
502  {
504  std::make_unique<ScUndoChartData>( pDocShell, aChartName, rRanges, bColHeaders, bRowHeaders, false ) );
505  }
506  rDoc.UpdateChartArea( aChartName, rRanges, bColHeaders, bRowHeaders, false );
507  }
508 }
509 
510 // ::comphelper::OPropertySetHelper
511 
513 {
515 }
516 
517 void ScChartObj::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const uno::Any& rValue )
518 {
519  switch ( nHandle )
520  {
522  {
523  uno::Sequence< table::CellRangeAddress > aCellRanges;
524  if ( rValue >>= aCellRanges )
525  {
526  ScRangeListRef rRangeList = new ScRangeList();
527  for ( table::CellRangeAddress const & aCellRange : std::as_const(aCellRanges) )
528  {
529  ScRange aRange;
530  ScUnoConversion::FillScRange( aRange, aCellRange );
531  rRangeList->push_back( aRange );
532  }
533  if ( pDocShell )
534  {
536  if ( pCollection )
537  {
538  pCollection->ChangeListening( aChartName, rRangeList );
539  }
540  }
541  }
542  }
543  break;
544  default:
545  break;
546  }
547 }
548 
549 void ScChartObj::getFastPropertyValue( uno::Any& rValue, sal_Int32 nHandle ) const
550 {
551  switch ( nHandle )
552  {
554  {
555  if (!pDocShell)
556  break;
557  ScDocument& rDoc = pDocShell->GetDocument();
558 
560  if (!pCollection)
561  break;
562 
563  ScChartListener* pListener = pCollection->findByName(aChartName);
564  if (!pListener)
565  break;
566 
567  const ScRangeListRef& rRangeList = pListener->GetRangeList();
568  if (!rRangeList.is())
569  break;
570 
571  size_t nCount = rRangeList->size();
572  uno::Sequence<table::CellRangeAddress> aCellRanges(nCount);
573  table::CellRangeAddress* pCellRanges = aCellRanges.getArray();
574  for (size_t i = 0; i < nCount; ++i)
575  {
576  ScRange const & rRange = (*rRangeList)[i];
577  table::CellRangeAddress aCellRange;
578  ScUnoConversion::FillApiRange(aCellRange, rRange);
579  pCellRanges[i] = aCellRange;
580  }
581  rValue <<= aCellRanges;
582  }
583  break;
584  default:
585  ;
586  }
587 }
588 
589 // ::comphelper::OPropertyArrayUsageHelper
590 
592 {
593  uno::Sequence< beans::Property > aProps;
594  describeProperties( aProps );
595  return new ::cppu::OPropertyArrayHelper( aProps );
596 }
597 
598 // XInterface
599 
601 
602 // XTypeProvider
603 
604 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ScChartObj, ScChartObj_Base, ScChartObj_PBase )
605 
606 // XTableChart
607 
608 sal_Bool SAL_CALL ScChartObj::getHasColumnHeaders()
609 {
610  SolarMutexGuard aGuard;
611  ScRangeListRef xRanges = new ScRangeList;
612  bool bColHeaders, bRowHeaders;
613  GetData_Impl( xRanges, bColHeaders, bRowHeaders );
614  return bColHeaders;
615 }
616 
617 void SAL_CALL ScChartObj::setHasColumnHeaders( sal_Bool bHasColumnHeaders )
618 {
619  SolarMutexGuard aGuard;
620  ScRangeListRef xRanges = new ScRangeList;
621  bool bOldColHeaders, bOldRowHeaders;
622  GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders );
623  if ( bOldColHeaders != bool(bHasColumnHeaders) )
624  Update_Impl( xRanges, bHasColumnHeaders, bOldRowHeaders );
625 }
626 
628 {
629  SolarMutexGuard aGuard;
630  ScRangeListRef xRanges = new ScRangeList;
631  bool bColHeaders, bRowHeaders;
632  GetData_Impl( xRanges, bColHeaders, bRowHeaders );
633  return bRowHeaders;
634 }
635 
636 void SAL_CALL ScChartObj::setHasRowHeaders( sal_Bool bHasRowHeaders )
637 {
638  SolarMutexGuard aGuard;
639  ScRangeListRef xRanges = new ScRangeList;
640  bool bOldColHeaders, bOldRowHeaders;
641  GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders );
642  if ( bOldRowHeaders != bool(bHasRowHeaders) )
643  Update_Impl( xRanges, bOldColHeaders, bHasRowHeaders );
644 }
645 
646 uno::Sequence<table::CellRangeAddress> SAL_CALL ScChartObj::getRanges()
647 {
648  SolarMutexGuard aGuard;
649  ScRangeListRef xRanges = new ScRangeList;
650  bool bColHeaders, bRowHeaders;
651  GetData_Impl( xRanges, bColHeaders, bRowHeaders );
652  if ( xRanges.is() )
653  {
654  size_t nCount = xRanges->size();
655 
656  table::CellRangeAddress aRangeAddress;
657  uno::Sequence<table::CellRangeAddress> aSeq(nCount);
658  table::CellRangeAddress* pAry = aSeq.getArray();
659  for (size_t i = 0; i < nCount; i++)
660  {
661  ScRange const & rRange = (*xRanges)[i];
662 
663  aRangeAddress.Sheet = rRange.aStart.Tab();
664  aRangeAddress.StartColumn = rRange.aStart.Col();
665  aRangeAddress.StartRow = rRange.aStart.Row();
666  aRangeAddress.EndColumn = rRange.aEnd.Col();
667  aRangeAddress.EndRow = rRange.aEnd.Row();
668 
669  pAry[i] = aRangeAddress;
670  }
671  return aSeq;
672  }
673 
674  OSL_FAIL("ScChartObj::getRanges: no Ranges");
675  return uno::Sequence<table::CellRangeAddress>();
676 }
677 
678 void SAL_CALL ScChartObj::setRanges( const uno::Sequence<table::CellRangeAddress>& aRanges )
679 {
680  SolarMutexGuard aGuard;
681  ScRangeListRef xOldRanges = new ScRangeList;
682  bool bColHeaders, bRowHeaders;
683  GetData_Impl( xOldRanges, bColHeaders, bRowHeaders );
684 
685  ScRangeList* pList = new ScRangeList;
686  for (const table::CellRangeAddress& rRange : aRanges)
687  {
688  ScRange aRange( static_cast<SCCOL>(rRange.StartColumn), rRange.StartRow, rRange.Sheet,
689  static_cast<SCCOL>(rRange.EndColumn), rRange.EndRow, rRange.Sheet );
690  pList->push_back( aRange );
691  }
692  ScRangeListRef xNewRanges( pList );
693 
694  if ( !xOldRanges.is() || *xOldRanges != *xNewRanges )
695  Update_Impl( xNewRanges, bColHeaders, bRowHeaders );
696 }
697 
698 // XEmbeddedObjectSupplier
699 
700 uno::Reference<lang::XComponent> SAL_CALL ScChartObj::getEmbeddedObject()
701 {
702  SolarMutexGuard aGuard;
705  if ( pObject && svt::EmbeddedObjectRef::TryRunningState( pObject->GetObjRef() ) )
706  {
707  //TODO/LATER: is it OK that something is returned for *all* objects, not only own objects?
708  return uno::Reference < lang::XComponent > ( pObject->GetObjRef()->getComponent(), uno::UNO_QUERY );
709  }
710 
711  return nullptr;
712 }
713 
714 // XNamed
715 
716 OUString SAL_CALL ScChartObj::getName()
717 {
718  SolarMutexGuard aGuard;
719  return aChartName;
720 }
721 
722 void SAL_CALL ScChartObj::setName( const OUString& /* aName */ )
723 {
724  SolarMutexGuard aGuard;
725  throw uno::RuntimeException(); // name cannot be changed
726 }
727 
728 // XPropertySet
729 
730 uno::Reference< beans::XPropertySetInfo > ScChartObj::getPropertySetInfo()
731 {
732  return createPropertySetInfo( getInfoHelper() ) ;
733 }
734 
735 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~ScChartObj() override
Definition: chartuno.cxx:419
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
Definition: chartuno.cxx:320
bool is() const
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
virtual void SAL_CALL setHasColumnHeaders(sal_Bool bHasColumnHeaders) override
Definition: chartuno.cxx:617
ScAddress aStart
Definition: address.hxx:499
static sal_Int32 GetEnumFromAny(const css::uno::Any &aAny)
Definition: miscuno.cxx:160
rtl::Reference< ScChartObj > GetObjectByIndex_Impl(tools::Long nIndex) const
Definition: chartuno.cxx:84
void ChangeListening(const OUString &rName, const ScRangeListRef &rRangeListRef)
Definition: chartlis.cxx:428
css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef() const
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: chartuno.cxx:730
SCROW Row() const
Definition: address.hxx:261
void setWidth(tools::Long nWidth)
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
void describeProperties(css::uno::Sequence< css::beans::Property > &_rProps) const
virtual OUString SAL_CALL getName() override
Definition: chartuno.cxx:716
rtl::Reference< ScChartObj > GetObjectByName_Impl(const OUString &aName) const
Definition: chartuno.cxx:124
bool insert(ScChartListener *pListener)
Definition: chartlis.cxx:385
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
virtual ~ScChartsObj() override
Definition: chartuno.cxx:66
long Long
virtual void SAL_CALL setHasRowHeaders(sal_Bool bHasRowHeaders) override
Definition: chartuno.cxx:636
ScRangeListRef GetRangeList() const
Definition: chartlis.cxx:184
ScAddress aEnd
Definition: address.hxx:500
virtual sal_Bool SAL_CALL hasElements() override
Definition: chartuno.cxx:336
virtual SdrObjKind GetObjIdentifier() const
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
EmbeddedObjectRef * pObject
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
Definition: chartuno.cxx:549
css::uno::Reference< css::chart2::XChartDocument > GetChartByName(std::u16string_view rChartName)
Definition: documen5.cxx:137
void UpdateChartArea(const OUString &rChartName, const ScRange &rNewArea, bool bColHeaders, bool bRowHeaders, bool bAdd)
Definition: documen5.cxx:129
SfxHintId GetId() const
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2926
constexpr tools::Long Width() const
virtual void SAL_CALL addNewByName(const OUString &aName, const css::awt::Rectangle &aRect, const css::uno::Sequence< css::table::CellRangeAddress > &aRanges, sal_Bool bColumnHeaders, sal_Bool bRowHeaders) override
Definition: chartuno.cxx:135
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
Definition: chartuno.cxx:517
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
int nCount
std::mutex m_aMutex
void push_back(const ScRange &rRange)
Definition: rangelst.cxx:1141
SCTAB Tab() const
Definition: address.hxx:270
virtual void SAL_CALL setName(const OUString &aName) override
Definition: chartuno.cxx:722
void StartListeningTo()
Definition: chartlis.cxx:262
virtual sal_Bool SAL_CALL getHasRowHeaders() override
Definition: chartuno.cxx:627
ScChartListener * findByName(const OUString &rName)
Definition: chartlis.cxx:400
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1057
ScChartObj(ScDocShell *pDocSh, SCTAB nT, const OUString &rN)
Definition: chartuno.cxx:404
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
::cppu::WeakComponentImplHelper< css::table::XTableChart, css::document::XEmbeddedObjectSupplier, css::container::XNamed, css::lang::XServiceInfo > ScChartObj_Base
Definition: chartuno.hxx:95
virtual css::uno::Sequence< css::table::CellRangeAddress > SAL_CALL getRanges() override
Definition: chartuno.cxx:646
void GetData_Impl(ScRangeListRef &rRanges, bool &rColHeaders, bool &rRowHeaders) const
Definition: chartuno.cxx:437
int i
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
Definition: chartuno.cxx:396
const SdrPage * GetPage(sal_uInt16 nPgNum) const
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
size_t size() const
Definition: rangelst.hxx:89
unsigned char sal_Bool
sal_uInt32 GetOrdNum() const
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: chartuno.cxx:352
void removeByName(const OUString &rName)
Definition: chartlis.cxx:393
css::uno::Type const & get()
#define SC_SIMPLE_SERVICE_INFO(ClassName, ClassNameAscii, ServiceAscii)
Definition: miscuno.hxx:63
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: chartuno.cxx:284
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
Definition: chartuno.cxx:591
virtual SdrObject * RemoveObject(size_t nObjNum)
#define PROP_HANDLE_RELATED_CELLRANGES
Definition: chartuno.cxx:54
SCCOL Col() const
Definition: address.hxx:266
void AddUnoObject(SfxListener &rObject)
Definition: documen3.cxx:898
SdrObject * GetNamedObject(std::u16string_view rName, sal_uInt16 nId, SCTAB &rFoundTab) const
Definition: drwlayer.cxx:2165
SdrObject * Next()
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
Definition: chartuno.cxx:342
constexpr Size GetSize() const
::cppu::IPropertyArrayHelper * getArrayHelper()
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: chartuno.cxx:74
static MapUnit UnoEmbed2VCLMapUnit(sal_Int32 nUnoEmbedMapUnit)
constexpr tools::Long Height() const
OUString aName
#define SO3_SCH_CLASSID
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:906
void Update_Impl(const ScRangeListRef &rRanges, bool bColHeaders, bool bRowHeaders)
Definition: chartuno.cxx:494
SC_DLLPUBLIC ScChartListenerCollection * GetChartListenerCollection() const
Definition: document.hxx:2155
ScDocShell * pDocShell
Definition: chartuno.hxx:107
SCTAB nTab
Definition: chartuno.hxx:108
Sequence< sal_Int8 > aSeq
SdrOle2Obj * findChartsByName(ScDocShell *pDocShell, SCTAB nTab, std::u16string_view rName, ChartSourceType eChartSourceType)
Definition: ChartTools.cxx:98
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
virtual void SAL_CALL setRanges(const css::uno::Sequence< css::table::CellRangeAddress > &aRanges) override
Definition: chartuno.cxx:678
void registerPropertyNoMember(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, const css::uno::Type &_rType, css::uno::Any const &_pInitialValue)
static bool IsChart(const SdrObject *pObject)
Definition: documen9.cxx:203
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
Definition: document.cxx:986
virtual css::uno::Type SAL_CALL getElementType() override
Definition: chartuno.cxx:330
void setHeight(tools::Long nHeight)
virtual void SAL_CALL removeByName(const OUString &aName) override
Definition: chartuno.cxx:264
static void FillApiRange(css::table::CellRangeAddress &rApiRange, const ScRange &rScRange)
Definition: convuno.hxx:87
MapUnit
bool IsUndoEnabled() const
Definition: document.hxx:1534
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: chartuno.cxx:427
static bool TryRunningState(const css::uno::Reference< css::embed::XEmbeddedObject > &)
virtual sal_Int32 SAL_CALL getCount() override
Definition: chartuno.cxx:292
static bool GetBoolFromAny(const css::uno::Any &aAny)
Definition: miscuno.cxx:138
OUString aChartName
Definition: chartuno.hxx:109
static void FillScRange(ScRange &rScRange, const css::table::CellRangeAddress &rApiRange)
Definition: convuno.hxx:79
OBJ_OLE2
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
Definition: chartuno.cxx:512
virtual css::uno::Reference< css::lang::XComponent > SAL_CALL getEmbeddedObject() override
Definition: chartuno.cxx:700
sal_uInt16 nPos
sal_Int16 SCTAB
Definition: types.hxx:22