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