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