Debian Codegraph @

chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx

raw
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 <ChartDocumentWrapper.hxx>
21 #include <ChartView.hxx>
22 #include <ChartViewHelper.hxx>
23 #include <ChartTypeManager.hxx>
24 #include <ChartTypeTemplate.hxx>
25 #include <servicenames.hxx>
26 #include <PropertyHelper.hxx>
27 #include <TitleHelper.hxx>
28 #include <Legend.hxx>
29 #include <LegendHelper.hxx>
30 #include <ControllerLockGuard.hxx>
31 #include <DisposeHelper.hxx>
32 #include "DataSeriesPointWrapper.hxx"
33 #include <chartview/DrawModelWrapper.hxx>
34 #include "Chart2ModelContact.hxx"
35 #include <BaseCoordinateSystem.hxx>
36
37 #include <ChartModel.hxx>
38
39 #include <DataSourceHelper.hxx>
40 #include <AxisHelper.hxx>
41 #include <ThreeDHelper.hxx>
42
43 #include "TitleWrapper.hxx"
44 #include "ChartDataWrapper.hxx"
45 #include "DiagramWrapper.hxx"
46 #include "LegendWrapper.hxx"
47 #include "AreaWrapper.hxx"
48 #include "WrappedAddInProperty.hxx"
49 #include <WrappedIgnoreProperty.hxx>
50 #include <cppuhelper/supportsservice.hxx>
51 #include <comphelper/processfactory.hxx>
52 #include <comphelper/sequence.hxx>
53 #include <utility>
54 #include <vcl/settings.hxx>
55
56 #include <com/sun/star/drawing/ShapeCollection.hpp>
57 #include <com/sun/star/beans/PropertyAttribute.hpp>
58 #include <com/sun/star/lang/DisposedException.hpp>
59 #include <com/sun/star/lang/XInitialization.hpp>
60 #include <com/sun/star/util/XRefreshable.hpp>
61 #include <comphelper/diagnose_ex.hxx>
62
63 #include <algorithm>
64 #include <map>
65
66 using namespace ::com::sun::star;
67 using namespace ::com::sun::star::chart;
68
69 using ::com::sun::star::uno::Any;
70 using ::com::sun::star::uno::UNO_QUERY_THROW;
71 using ::com::sun::star::uno::Reference;
72 using ::com::sun::star::uno::Sequence;
73 using ::com::sun::star::beans::Property;
74
75 namespace
76 {
77 enum eServiceType
78 {
79 SERVICE_NAME_AREA_DIAGRAM = 0,
80 SERVICE_NAME_BAR_DIAGRAM,
81 SERVICE_NAME_DONUT_DIAGRAM,
82 SERVICE_NAME_LINE_DIAGRAM,
83 SERVICE_NAME_NET_DIAGRAM,
84 SERVICE_NAME_FILLED_NET_DIAGRAM,
85 SERVICE_NAME_PIE_DIAGRAM,
86 SERVICE_NAME_STOCK_DIAGRAM,
87 SERVICE_NAME_XY_DIAGRAM,
88 SERVICE_NAME_BUBBLE_DIAGRAM,
89
90 SERVICE_NAME_DASH_TABLE,
91 SERVICE_NAME_GRADIENT_TABLE,
92 SERVICE_NAME_HATCH_TABLE,
93 SERVICE_NAME_BITMAP_TABLE,
94 SERVICE_NAME_TRANSP_GRADIENT_TABLE,
95 SERVICE_NAME_MARKER_TABLE,
96
97 SERVICE_NAME_NAMESPACE_MAP,
98 SERVICE_NAME_EXPORT_GRAPHIC_STORAGE_RESOLVER,
99 SERVICE_NAME_IMPORT_GRAPHIC_STORAGE_RESOLVER
100 };
101
102 typedef std::map< OUString, enum eServiceType > tServiceNameMap;
103
104 tServiceNameMap & lcl_getStaticServiceNameMap()
105 {
106 static tServiceNameMap aServiceNameMap {
107 {"com.sun.star.chart.AreaDiagram", SERVICE_NAME_AREA_DIAGRAM},
108 {"com.sun.star.chart.BarDiagram", SERVICE_NAME_BAR_DIAGRAM},
109 {"com.sun.star.chart.DonutDiagram", SERVICE_NAME_DONUT_DIAGRAM},
110 {"com.sun.star.chart.LineDiagram", SERVICE_NAME_LINE_DIAGRAM},
111 {"com.sun.star.chart.NetDiagram", SERVICE_NAME_NET_DIAGRAM},
112 {"com.sun.star.chart.FilledNetDiagram", SERVICE_NAME_FILLED_NET_DIAGRAM},
113 {"com.sun.star.chart.PieDiagram", SERVICE_NAME_PIE_DIAGRAM},
114 {"com.sun.star.chart.StockDiagram", SERVICE_NAME_STOCK_DIAGRAM},
115 {"com.sun.star.chart.XYDiagram", SERVICE_NAME_XY_DIAGRAM},
116 {"com.sun.star.chart.BubbleDiagram", SERVICE_NAME_BUBBLE_DIAGRAM},
117
118 {"com.sun.star.drawing.DashTable", SERVICE_NAME_DASH_TABLE},
119 {"com.sun.star.drawing.GradientTable", SERVICE_NAME_GRADIENT_TABLE},
120 {"com.sun.star.drawing.HatchTable", SERVICE_NAME_HATCH_TABLE},
121 {"com.sun.star.drawing.BitmapTable", SERVICE_NAME_BITMAP_TABLE},
122 {"com.sun.star.drawing.TransparencyGradientTable", SERVICE_NAME_TRANSP_GRADIENT_TABLE},
123 {"com.sun.star.drawing.MarkerTable", SERVICE_NAME_MARKER_TABLE},
124
125 {"com.sun.star.xml.NamespaceMap", SERVICE_NAME_NAMESPACE_MAP},
126 {"com.sun.star.document.ExportGraphicStorageHandler", SERVICE_NAME_EXPORT_GRAPHIC_STORAGE_RESOLVER},
127 {"com.sun.star.document.ImportGraphicStorageHandler", SERVICE_NAME_IMPORT_GRAPHIC_STORAGE_RESOLVER}
128 };
129
130 return aServiceNameMap;
131 }
132
133 enum
134 {
135 PROP_DOCUMENT_HAS_MAIN_TITLE,
136 PROP_DOCUMENT_HAS_SUB_TITLE,
137 PROP_DOCUMENT_HAS_LEGEND,
138 PROP_DOCUMENT_LABELS_IN_FIRST_ROW,
139 PROP_DOCUMENT_LABELS_IN_FIRST_COLUMN,
140 PROP_DOCUMENT_ADDIN,
141 PROP_DOCUMENT_BASEDIAGRAM,
142 PROP_DOCUMENT_ADDITIONAL_SHAPES,
143 PROP_DOCUMENT_UPDATE_ADDIN,
144 PROP_DOCUMENT_NULL_DATE,
145 PROP_DOCUMENT_ENABLE_COMPLEX_CHARTTYPES,
146 PROP_DOCUMENT_ENABLE_DATATABLE_DIALOG
147 };
148
149 void lcl_AddPropertiesToVector(
150 std::vector< Property > & rOutProperties )
151 {
152 rOutProperties.emplace_back( "HasMainTitle",
153 PROP_DOCUMENT_HAS_MAIN_TITLE,
154 cppu::UnoType<bool>::get(),
155 //#i111967# no PropertyChangeEvent is fired on change so far
156 beans::PropertyAttribute::MAYBEDEFAULT );
157 rOutProperties.emplace_back( "HasSubTitle",
158 PROP_DOCUMENT_HAS_SUB_TITLE,
159 cppu::UnoType<bool>::get(),
160 //#i111967# no PropertyChangeEvent is fired on change so far
161 beans::PropertyAttribute::MAYBEDEFAULT );
162 rOutProperties.emplace_back( "HasLegend",
163 PROP_DOCUMENT_HAS_LEGEND,
164 cppu::UnoType<bool>::get(),
165 //#i111967# no PropertyChangeEvent is fired on change so far
166 beans::PropertyAttribute::MAYBEDEFAULT );
167
168 // really needed?
169 rOutProperties.emplace_back( "DataSourceLabelsInFirstRow",
170 PROP_DOCUMENT_LABELS_IN_FIRST_ROW,
171 cppu::UnoType<bool>::get(),
172 beans::PropertyAttribute::BOUND
173 | beans::PropertyAttribute::MAYBEDEFAULT );
174 rOutProperties.emplace_back( "DataSourceLabelsInFirstColumn",
175 PROP_DOCUMENT_LABELS_IN_FIRST_COLUMN,
176 cppu::UnoType<bool>::get(),
177 //#i111967# no PropertyChangeEvent is fired on change so far
178 beans::PropertyAttribute::MAYBEDEFAULT );
179
180 //add-in
181 rOutProperties.emplace_back( "AddIn",
182 PROP_DOCUMENT_ADDIN,
183 cppu::UnoType<util::XRefreshable>::get(),
184 beans::PropertyAttribute::BOUND
185 | beans::PropertyAttribute::MAYBEVOID );
186 rOutProperties.emplace_back( "BaseDiagram",
187 PROP_DOCUMENT_BASEDIAGRAM,
188 cppu::UnoType<OUString>::get(),
189 beans::PropertyAttribute::BOUND
190 | beans::PropertyAttribute::MAYBEVOID );
191 rOutProperties.emplace_back( "AdditionalShapes",
192 PROP_DOCUMENT_ADDITIONAL_SHAPES,
193 cppu::UnoType<drawing::XShapes>::get(),
194 beans::PropertyAttribute::BOUND
195 | beans::PropertyAttribute::MAYBEVOID
196 | beans::PropertyAttribute::READONLY );
197 rOutProperties.emplace_back( "RefreshAddInAllowed",
198 PROP_DOCUMENT_UPDATE_ADDIN,
199 cppu::UnoType<bool>::get(),
200 //#i111967# no PropertyChangeEvent is fired on change so far
201 beans::PropertyAttribute::TRANSIENT );
202
203 // table:null-date // i99104
204 rOutProperties.emplace_back( "NullDate",
205 PROP_DOCUMENT_NULL_DATE,
206 ::cppu::UnoType<css::util::DateTime>::get(),
207 beans::PropertyAttribute::MAYBEVOID );
208
209 rOutProperties.emplace_back( "EnableComplexChartTypes",
210 PROP_DOCUMENT_ENABLE_COMPLEX_CHARTTYPES,
211 cppu::UnoType<bool>::get(),
212 //#i112666# no PropertyChangeEvent is fired on change so far
213 beans::PropertyAttribute::MAYBEDEFAULT );
214 rOutProperties.emplace_back( "EnableDataTableDialog",
215 PROP_DOCUMENT_ENABLE_DATATABLE_DIALOG,
216 cppu::UnoType<bool>::get(),
217 //#i112666# no PropertyChangeEvent is fired on change so far
218 beans::PropertyAttribute::MAYBEDEFAULT );
219 }
220
221 const Sequence< Property > & StaticChartDocumentWrapperPropertyArray()
222 {
223 static Sequence< Property > aPropSeq = []()
224 {
225 std::vector< css::beans::Property > aProperties;
226 lcl_AddPropertiesToVector( aProperties );
227
228 std::sort( aProperties.begin(), aProperties.end(),
229 ::chart::PropertyNameLess() );
230
231 return comphelper::containerToSequence( aProperties );
232 }();
233 return aPropSeq;
234 }
235
236 } // anonymous namespace
237
238 namespace chart::wrapper
239 {
240
241 namespace {
242
243 //PROP_DOCUMENT_LABELS_IN_FIRST_ROW
244 class WrappedDataSourceLabelsInFirstRowProperty : public WrappedProperty
245 {
246 public:
247 explicit WrappedDataSourceLabelsInFirstRowProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact);
248
249 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
250
251 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
252
253 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
254
255 private: //member
256 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
257 mutable Any m_aOuterValue;
258 };
259
260 }
261
262 WrappedDataSourceLabelsInFirstRowProperty::WrappedDataSourceLabelsInFirstRowProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
263 : WrappedProperty(u"DataSourceLabelsInFirstRow"_ustr,OUString())
264 , m_spChart2ModelContact(std::move( spChart2ModelContact ))
265 {
266 m_aOuterValue = WrappedDataSourceLabelsInFirstRowProperty::getPropertyDefault( nullptr );
267 }
268
269 void WrappedDataSourceLabelsInFirstRowProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
270 {
271 bool bLabelsInFirstRow = true;
272 if( ! (rOuterValue >>= bLabelsInFirstRow) )
273 throw lang::IllegalArgumentException(u"Property DataSourceLabelsInFirstRow requires value of type boolean"_ustr, nullptr, 0 );
274
275 m_aOuterValue = rOuterValue;
276 bool bNewValue = bLabelsInFirstRow;
277
278 OUString aRangeString;
279 bool bUseColumns = true;
280 bool bFirstCellAsLabel = true;
281 bool bHasCategories = true;
282 uno::Sequence< sal_Int32 > aSequenceMapping;
283
284 if( !DataSourceHelper::detectRangeSegmentation(
285 m_spChart2ModelContact->getDocumentModel(), aRangeString, aSequenceMapping, bUseColumns
286 , bFirstCellAsLabel, bHasCategories ) )
287 return;
288
289 if( bUseColumns && bNewValue != bFirstCellAsLabel )
290 {
291 DataSourceHelper::setRangeSegmentation(
292 m_spChart2ModelContact->getDocumentModel(), aSequenceMapping, bUseColumns ,bNewValue, bHasCategories );
293 }
294 else if( !bUseColumns && bNewValue != bHasCategories )
295 {
296 DataSourceHelper::setRangeSegmentation(
297 m_spChart2ModelContact->getDocumentModel(), aSequenceMapping, bUseColumns , bFirstCellAsLabel, bNewValue );
298 }
299 }
300
301 Any WrappedDataSourceLabelsInFirstRowProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
302 {
303 OUString aRangeString;
304 bool bUseColumns = true;
305 bool bFirstCellAsLabel = true;
306 bool bHasCategories = true;
307 uno::Sequence< sal_Int32 > aSequenceMapping;
308
309 if( DataSourceHelper::detectRangeSegmentation(
310 m_spChart2ModelContact->getDocumentModel(), aRangeString, aSequenceMapping, bUseColumns
311 , bFirstCellAsLabel, bHasCategories ) )
312 {
313 bool bLabelsInFirstRow = true;
314 if( bUseColumns )
315 bLabelsInFirstRow = bFirstCellAsLabel;
316 else
317 bLabelsInFirstRow = bHasCategories;
318
319 m_aOuterValue <<= bLabelsInFirstRow;
320 }
321 return m_aOuterValue;
322 }
323
324 Any WrappedDataSourceLabelsInFirstRowProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
325 {
326 Any aRet;
327 aRet <<= true;
328 return aRet;
329 }
330
331 namespace {
332
333 //PROP_DOCUMENT_LABELS_IN_FIRST_COLUMN
334 class WrappedDataSourceLabelsInFirstColumnProperty : public WrappedProperty
335 {
336 public:
337 explicit WrappedDataSourceLabelsInFirstColumnProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact);
338
339 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
340
341 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
342
343 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
344
345 private: //member
346 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
347 mutable Any m_aOuterValue;
348 };
349
350 }
351
352 WrappedDataSourceLabelsInFirstColumnProperty::WrappedDataSourceLabelsInFirstColumnProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
353 : WrappedProperty(u"DataSourceLabelsInFirstColumn"_ustr,OUString())
354 , m_spChart2ModelContact(std::move( spChart2ModelContact ))
355 {
356 m_aOuterValue = WrappedDataSourceLabelsInFirstColumnProperty::getPropertyDefault( nullptr );
357 }
358
359 void WrappedDataSourceLabelsInFirstColumnProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
360 {
361 bool bLabelsInFirstRow = true;
362 if( ! (rOuterValue >>= bLabelsInFirstRow) )
363 throw lang::IllegalArgumentException(u"Property DataSourceLabelsInFirstRow requires value of type boolean"_ustr, nullptr, 0 );
364
365 m_aOuterValue = rOuterValue;
366 bool bNewValue = bLabelsInFirstRow;
367
368 OUString aRangeString;
369 bool bUseColumns = true;
370 bool bFirstCellAsLabel = true;
371 bool bHasCategories = true;
372 uno::Sequence< sal_Int32 > aSequenceMapping;
373
374 if( !DataSourceHelper::detectRangeSegmentation(
375 m_spChart2ModelContact->getDocumentModel(), aRangeString, aSequenceMapping, bUseColumns
376 , bFirstCellAsLabel, bHasCategories ) )
377 return;
378
379 if( bUseColumns && bNewValue != bHasCategories )
380 {
381 DataSourceHelper::setRangeSegmentation(
382 m_spChart2ModelContact->getDocumentModel(), aSequenceMapping, bUseColumns, bFirstCellAsLabel, bNewValue );
383 }
384 else if( !bUseColumns && bNewValue != bFirstCellAsLabel )
385 {
386 DataSourceHelper::setRangeSegmentation(
387 m_spChart2ModelContact->getDocumentModel(), aSequenceMapping, bUseColumns , bNewValue, bHasCategories );
388 }
389 }
390
391 Any WrappedDataSourceLabelsInFirstColumnProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
392 {
393 OUString aRangeString;
394 bool bUseColumns = true;
395 bool bFirstCellAsLabel = true;
396 bool bHasCategories = true;
397 uno::Sequence< sal_Int32 > aSequenceMapping;
398
399 if( DataSourceHelper::detectRangeSegmentation(
400 m_spChart2ModelContact->getDocumentModel(), aRangeString, aSequenceMapping, bUseColumns
401 , bFirstCellAsLabel, bHasCategories ) )
402 {
403 bool bLabelsInFirstColumn = true;
404 if( bUseColumns )
405 bLabelsInFirstColumn = bHasCategories;
406 else
407 bLabelsInFirstColumn = bFirstCellAsLabel;
408
409 m_aOuterValue <<= bLabelsInFirstColumn;
410 }
411 return m_aOuterValue;
412 }
413
414 Any WrappedDataSourceLabelsInFirstColumnProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
415 {
416 Any aRet;
417 aRet <<= true;
418 return aRet;
419 }
420
421 namespace {
422
423 //PROP_DOCUMENT_HAS_LEGEND
424 class WrappedHasLegendProperty : public WrappedProperty
425 {
426 public:
427 explicit WrappedHasLegendProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact);
428
429 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
430
431 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
432
433 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
434
435 private: //member
436 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
437 };
438
439 }
440
441 WrappedHasLegendProperty::WrappedHasLegendProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
442 : WrappedProperty(u"HasLegend"_ustr,OUString())
443 , m_spChart2ModelContact(std::move( spChart2ModelContact ))
444 {
445 }
446
447 void WrappedHasLegendProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
448 {
449 bool bNewValue = true;
450 if( ! (rOuterValue >>= bNewValue) )
451 throw lang::IllegalArgumentException(u"Property HasLegend requires value of type boolean"_ustr, nullptr, 0 );
452
453 try
454 {
455 rtl::Reference< Legend > xLegend = LegendHelper::getLegend( *m_spChart2ModelContact->getDocumentModel(), m_spChart2ModelContact->m_xContext,bNewValue );
456 if(xLegend.is())
457 {
458 bool bOldValue = true;
459 Any aAOld = xLegend->getPropertyValue(u"Show"_ustr);
460 aAOld >>= bOldValue;
461 if( bOldValue != bNewValue )
462 xLegend->setPropertyValue(u"Show"_ustr, uno::Any( bNewValue ));
463 }
464 }
465 catch (const uno::Exception&)
466 {
467 DBG_UNHANDLED_EXCEPTION("chart2");
468 }
469 }
470
471 Any WrappedHasLegendProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
472 {
473 Any aRet;
474 try
475 {
476 rtl::Reference< Legend > xLegend =
477 LegendHelper::getLegend( *m_spChart2ModelContact->getDocumentModel() );
478 if( xLegend.is())
479 aRet = xLegend->getPropertyValue(u"Show"_ustr);
480 else
481 aRet <<= false;
482 }
483 catch (const uno::Exception&)
484 {
485 DBG_UNHANDLED_EXCEPTION("chart2");
486 }
487 return aRet;
488 }
489
490 Any WrappedHasLegendProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
491 {
492 Any aRet;
493 aRet <<= false;
494 return aRet;
495 }
496
497 namespace {
498
499 //PROP_DOCUMENT_HAS_MAIN_TITLE
500 class WrappedHasMainTitleProperty : public WrappedProperty
501 {
502 public:
503 explicit WrappedHasMainTitleProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact);
504
505 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
506
507 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
508
509 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
510
511 private: //member
512 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
513 };
514
515 }
516
517 WrappedHasMainTitleProperty::WrappedHasMainTitleProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
518 : WrappedProperty(u"HasMainTitle"_ustr,OUString())
519 , m_spChart2ModelContact(std::move( spChart2ModelContact ))
520 {
521 }
522
523 void WrappedHasMainTitleProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
524 {
525 bool bNewValue = true;
526 if( ! (rOuterValue >>= bNewValue) )
527 throw lang::IllegalArgumentException(u"Property HasMainTitle requires value of type boolean"_ustr, nullptr, 0 );
528
529 try
530 {
531 if( bNewValue )
532 TitleHelper::createTitle( TitleHelper::MAIN_TITLE, u"main-title"_ustr, m_spChart2ModelContact->getDocumentModel(), m_spChart2ModelContact->m_xContext );
533 else
534 TitleHelper::removeTitle( TitleHelper::MAIN_TITLE, m_spChart2ModelContact->getDocumentModel() );
535 }
536 catch (const uno::Exception&)
537 {
538 DBG_UNHANDLED_EXCEPTION("chart2");
539 }
540 }
541
542 Any WrappedHasMainTitleProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
543 {
544 Any aRet;
545 try
546 {
547 aRet <<= TitleHelper::getTitle( TitleHelper::MAIN_TITLE, m_spChart2ModelContact->getDocumentModel() ).is();
548 }
549 catch (const uno::Exception&)
550 {
551 DBG_UNHANDLED_EXCEPTION("chart2");
552 }
553 return aRet;
554 }
555
556 Any WrappedHasMainTitleProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
557 {
558 Any aRet;
559 aRet <<= false;
560 return aRet;
561 }
562
563 namespace {
564
565 //PROP_DOCUMENT_HAS_SUB_TITLE
566 class WrappedHasSubTitleProperty : public WrappedProperty
567 {
568 public:
569 explicit WrappedHasSubTitleProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact);
570
571 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
572
573 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
574
575 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
576
577 private: //member
578 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
579 };
580
581 }
582
583 WrappedHasSubTitleProperty::WrappedHasSubTitleProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
584 : WrappedProperty(u"HasSubTitle"_ustr,OUString())
585 , m_spChart2ModelContact(std::move( spChart2ModelContact ))
586 {
587 }
588
589 void WrappedHasSubTitleProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
590 {
591 bool bNewValue = true;
592 if( ! (rOuterValue >>= bNewValue) )
593 throw lang::IllegalArgumentException(u"Property HasSubTitle requires value of type boolean"_ustr, nullptr, 0 );
594
595 try
596 {
597 if( bNewValue )
598 TitleHelper::createTitle( TitleHelper::SUB_TITLE, u""_ustr, m_spChart2ModelContact->getDocumentModel(), m_spChart2ModelContact->m_xContext );
599 else
600 TitleHelper::removeTitle( TitleHelper::SUB_TITLE, m_spChart2ModelContact->getDocumentModel() );
601 }
602 catch (const uno::Exception&)
603 {
604 DBG_UNHANDLED_EXCEPTION("chart2");
605 }
606 }
607
608 Any WrappedHasSubTitleProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
609 {
610 Any aRet;
611 try
612 {
613 aRet <<= TitleHelper::getTitle( TitleHelper::SUB_TITLE, m_spChart2ModelContact->getDocumentModel() ).is();
614 }
615 catch (const uno::Exception&)
616 {
617 DBG_UNHANDLED_EXCEPTION("chart2");
618 }
619 return aRet;
620 }
621
622 Any WrappedHasSubTitleProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
623 {
624 Any aRet;
625 aRet <<= false;
626 return aRet;
627 }
628
629 namespace {
630
631 //PROP_DOCUMENT_NULL_DATE
632 class WrappedNullDateProperty : public WrappedProperty
633 {
634 public:
635 explicit WrappedNullDateProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact);
636
637 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
638
639 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
640
641 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
642
643 private: //member
644 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
645 };
646
647 }
648
649 WrappedNullDateProperty::WrappedNullDateProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
650 : WrappedProperty(u"NullDate"_ustr, OUString())
651 , m_spChart2ModelContact(std::move( spChart2ModelContact ))
652 {
653 }
654
655 void WrappedNullDateProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
656 {
657 util::DateTime aDateTime;
658 if( ! (rOuterValue >>= aDateTime) )
659 throw lang::IllegalArgumentException(u"Property NullDate requires value of type util::DateTime"_ustr, nullptr, 0 );
660
661 try
662 {
663 m_spChart2ModelContact->getDocumentModel()->changeNullDate(aDateTime);
664 }
665 catch (const uno::Exception&)
666 {
667 DBG_UNHANDLED_EXCEPTION("chart2");
668 }
669 }
670
671 Any WrappedNullDateProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
672 {
673 Any aRet;
674 try
675 {
676 std::optional<css::util::DateTime> moDateTime = m_spChart2ModelContact->getDocumentModel()->getNullDate();
677 if (moDateTime)
678 {
679 aRet <<= *moDateTime;
680 }
681 }
682 catch (const uno::Exception&)
683 {
684 DBG_UNHANDLED_EXCEPTION("chart2");
685 }
686 return aRet;
687 }
688
689 Any WrappedNullDateProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
690 {
691 Any aRet;
692 return aRet;
693 }
694
695 ChartDocumentWrapper::ChartDocumentWrapper(
696 const Reference< uno::XComponentContext > & xContext ) :
697 m_spChart2ModelContact( std::make_shared<Chart2ModelContact>( xContext ) ),
698 m_bUpdateAddIn( true ),
699 m_bIsDisposed( false )
700 {
701 }
702
703 ChartDocumentWrapper::~ChartDocumentWrapper()
704 {
705 stopAllComponentListening();
706 }
707
708 // ____ XInterface (for new interfaces) ____
709 // [-loplugin:unoaggregation]
710 uno::Any SAL_CALL ChartDocumentWrapper::queryInterface( const uno::Type& aType )
711 {
712 if( m_xDelegator.is())
713 // calls queryAggregation if the delegator doesn't know aType
714 return m_xDelegator->queryInterface( aType );
715 else
716 return queryAggregation( aType );
717 }
718
719 // ____ chart::XChartDocument (old API wrapper) ____
720 Reference< drawing::XShape > SAL_CALL ChartDocumentWrapper::getTitle()
721 {
722 if( !m_xTitle.is() )
723 {
724 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getDocumentModel() );
725 m_xTitle = new TitleWrapper( TitleHelper::MAIN_TITLE, m_spChart2ModelContact );
726 }
727 return m_xTitle;
728 }
729
730 Reference< drawing::XShape > SAL_CALL ChartDocumentWrapper::getSubTitle()
731 {
732 if( !m_xSubTitle.is() )
733 {
734 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getDocumentModel() );
735 m_xSubTitle = new TitleWrapper( TitleHelper::SUB_TITLE, m_spChart2ModelContact );
736 }
737 return m_xSubTitle;
738 }
739
740 Reference< drawing::XShape > SAL_CALL ChartDocumentWrapper::getLegend()
741 {
742 if( ! m_xLegend.is())
743 {
744 m_xLegend = new LegendWrapper( m_spChart2ModelContact );
745 }
746
747 return m_xLegend;
748 }
749
750 Reference< beans::XPropertySet > SAL_CALL ChartDocumentWrapper::getArea()
751 {
752 if( ! m_xArea.is())
753 {
754 m_xArea.set( new AreaWrapper( m_spChart2ModelContact ) );
755 }
756
757 return m_xArea;
758 }
759
760 Reference< XDiagram > SAL_CALL ChartDocumentWrapper::getDiagram()
761 {
762 if( !m_xDiagram.is() )
763 {
764 try
765 {
766 m_xDiagram = new DiagramWrapper( m_spChart2ModelContact );
767 }
768 catch (const uno::Exception&)
769 {
770 DBG_UNHANDLED_EXCEPTION("chart2");
771 }
772 }
773
774 return m_xDiagram;
775 }
776
777 void SAL_CALL ChartDocumentWrapper::setDiagram( const Reference< XDiagram >& _xDiagram )
778 {
779 if (!_xDiagram.is())
780 return;
781 auto xDiagram = dynamic_cast<DiagramWrapper*>(_xDiagram.get());
782 assert(xDiagram);
783 if( xDiagram != m_xDiagram )
784 {
785 // set new wrapped diagram at new chart. This requires the old
786 // diagram given as parameter to implement the new interface. If
787 // this is not possible throw an exception
788 rtl::Reference< ::chart::Diagram > xNewDia( xDiagram->getUnderlyingDiagram());
789
790 try
791 {
792 rtl::Reference< ChartModel > xChartDoc( m_spChart2ModelContact->getDocumentModel() );
793 if( xChartDoc.is() )
794 {
795 // set the new diagram
796 xChartDoc->setFirstDiagram( xNewDia );
797 m_xDiagram = xDiagram;
798 }
799 }
800 catch (const uno::Exception&)
801 {
802 DBG_UNHANDLED_EXCEPTION("chart2");
803 }
804 }
805 }
806
807 Reference< XChartData > SAL_CALL ChartDocumentWrapper::getData()
808 {
809 if( !m_xChartData.is() )
810 {
811 m_xChartData.set( new ChartDataWrapper( m_spChart2ModelContact ) );
812 }
813 //@todo: check hasInternalDataProvider also in else?
814
815 return m_xChartData;
816 }
817
818 void SAL_CALL ChartDocumentWrapper::attachData( const Reference< XChartData >& xNewData )
819 {
820 if( !xNewData.is() )
821 return;
822
823 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getDocumentModel() );
824 m_xChartData.set( new ChartDataWrapper( m_spChart2ModelContact, xNewData ) );
825 }
826
827 // ____ XModel ____
828 sal_Bool SAL_CALL ChartDocumentWrapper::attachResource(
829 const OUString& URL,
830 const Sequence< beans::PropertyValue >& Arguments )
831 {
832 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
833 if( xModel.is() )
834 return xModel->attachResource( URL, Arguments );
835 return false;
836 }
837
838 OUString SAL_CALL ChartDocumentWrapper::getURL()
839 {
840 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
841 if( xModel.is() )
842 return xModel->getURL();
843 return OUString();
844 }
845
846 Sequence< beans::PropertyValue > SAL_CALL ChartDocumentWrapper::getArgs()
847 {
848 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
849 if( xModel.is() )
850 return xModel->getArgs();
851 return Sequence< beans::PropertyValue >();
852 }
853
854 void SAL_CALL ChartDocumentWrapper::connectController( const Reference< frame::XController >& Controller )
855 {
856 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
857 if( xModel.is() )
858 xModel->connectController( Controller );
859 }
860
861 void SAL_CALL ChartDocumentWrapper::disconnectController(
862 const Reference< frame::XController >& Controller )
863 {
864 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
865 if( xModel.is() )
866 xModel->disconnectController( Controller );
867 }
868
869 void SAL_CALL ChartDocumentWrapper::lockControllers()
870 {
871 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
872 if( xModel.is() )
873 xModel->lockControllers();
874 }
875
876 void SAL_CALL ChartDocumentWrapper::unlockControllers()
877 {
878 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
879 if( xModel.is() )
880 xModel->unlockControllers();
881 }
882
883 sal_Bool SAL_CALL ChartDocumentWrapper::hasControllersLocked()
884 {
885 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
886 if( xModel.is() )
887 return xModel->hasControllersLocked();
888 return false;
889 }
890
891 Reference< frame::XController > SAL_CALL ChartDocumentWrapper::getCurrentController()
892 {
893 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
894 if( xModel.is() )
895 return xModel->getCurrentController();
896 return nullptr;
897 }
898
899 void SAL_CALL ChartDocumentWrapper::setCurrentController(
900 const Reference< frame::XController >& Controller )
901 {
902 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
903 if( xModel.is() )
904 xModel->setCurrentController( Controller );
905 }
906
907 Reference< uno::XInterface > SAL_CALL ChartDocumentWrapper::getCurrentSelection()
908 {
909 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
910 if( xModel.is() )
911 return xModel->getCurrentSelection();
912 return nullptr;
913 }
914
915 // ____ XComponent ____
916 void SAL_CALL ChartDocumentWrapper::dispose()
917 {
918 if( m_bIsDisposed )
919 return;
920
921 m_bIsDisposed = true;
922
923 try
924 {
925 Reference< lang::XComponent > xFormerDelegator( m_xDelegator, uno::UNO_QUERY );
926 if (m_xTitle)
927 {
928 m_xTitle->dispose();
929 m_xTitle.clear();
930 }
931 DisposeHelper::DisposeAndClear( m_xSubTitle );
932 DisposeHelper::DisposeAndClear( m_xLegend );
933 DisposeHelper::DisposeAndClear( m_xChartData );
934 DisposeHelper::DisposeAndClear( m_xDiagram );
935 DisposeHelper::DisposeAndClear( m_xArea );
936 m_xChartView.clear();
937 m_xShapeFactory.clear();
938 m_xDelegator.clear();
939
940 clearWrappedPropertySet();
941 m_spChart2ModelContact->clear();
942 impl_resetAddIn();
943
944 stopAllComponentListening();
945
946 try
947 {
948 if( xFormerDelegator.is())
949 xFormerDelegator->dispose();
950 }
951 catch (const lang::DisposedException&)
952 {
953 // this is ok, don't panic
954 }
955 }
956 catch (const uno::Exception &)
957 {
958 DBG_UNHANDLED_EXCEPTION("chart2");
959 }
960 }
961
962 void ChartDocumentWrapper::impl_resetAddIn()
963 {
964 Reference< util::XRefreshable > xAddIn( m_xAddIn );
965 m_xAddIn.clear();
966
967 if( !xAddIn.is() )
968 return;
969
970 try
971 {
972 //make sure that the add-in does not hold a references to us anymore:
973 Reference< lang::XComponent > xComp( xAddIn, uno::UNO_QUERY );
974 if( xComp.is())
975 xComp->dispose();
976 else
977 {
978 uno::Reference< lang::XInitialization > xInit( xAddIn, uno::UNO_QUERY );
979 if( xInit.is() )
980 {
981 uno::Any aParam;
982 uno::Reference< css::chart::XChartDocument > xDoc;
983 aParam <<= xDoc;
984 uno::Sequence< uno::Any > aSeq( &aParam, 1 );
985 xInit->initialize( aSeq );
986 }
987 }
988 }
989 catch (const uno::RuntimeException&)
990 {
991 DBG_UNHANDLED_EXCEPTION("chart2");
992 }
993 catch (const uno::Exception&)
994 {
995 DBG_UNHANDLED_EXCEPTION("chart2");
996 }
997 }
998
999 void ChartDocumentWrapper::setBaseDiagram( const OUString& rBaseDiagram )
1000 {
1001 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getDocumentModel() );
1002 m_aBaseDiagram = rBaseDiagram;
1003
1004 uno::Reference< XDiagram > xDiagram( ChartDocumentWrapper::createInstance( rBaseDiagram ), uno::UNO_QUERY );
1005 if( xDiagram.is() )
1006 setDiagram( xDiagram );
1007 }
1008
1009 void ChartDocumentWrapper::setAddIn( const Reference< util::XRefreshable >& xAddIn )
1010 {
1011 if( m_xAddIn == xAddIn )
1012 return;
1013
1014 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getDocumentModel() );
1015 impl_resetAddIn();
1016 m_xAddIn = xAddIn;
1017 // initialize AddIn with this as chart document
1018 uno::Reference< lang::XInitialization > xInit( m_xAddIn, uno::UNO_QUERY );
1019 if( xInit.is() )
1020 {
1021 uno::Any aParam;
1022 uno::Reference< XChartDocument > xDoc(this);
1023 aParam <<= xDoc;
1024 uno::Sequence< uno::Any > aSeq( &aParam, 1 );
1025 xInit->initialize( aSeq );
1026 }
1027 }
1028
1029 void ChartDocumentWrapper::setUpdateAddIn( bool bUpdateAddIn )
1030 {
1031 m_bUpdateAddIn = bUpdateAddIn;
1032 }
1033
1034 Reference< drawing::XShapes > ChartDocumentWrapper::getAdditionalShapes() const
1035 {
1036 // get additional non-chart shapes for XML export
1037 uno::Reference< drawing::XShapes > xFoundShapes;
1038 rtl::Reference<SvxDrawPage> xDrawPage( impl_getDrawPage() );
1039
1040 if( !xDrawPage.is() )
1041 return xFoundShapes;
1042
1043 uno::Reference<drawing::XShapes> xChartRoot( DrawModelWrapper::getChartRootShape( xDrawPage ) );
1044
1045 // iterate 'flat' over all top-level objects
1046 // and determine all that are no chart objects
1047 std::vector< uno::Reference< drawing::XShape > > aShapeVector;
1048 sal_Int32 nSubCount = xDrawPage->getCount();
1049 uno::Reference< drawing::XShape > xShape;
1050 for( sal_Int32 nS = 0; nS < nSubCount; nS++ )
1051 {
1052 if( xDrawPage->getByIndex( nS ) >>= xShape )
1053 {
1054 if( xShape.is() && xChartRoot!=xShape )
1055 aShapeVector.push_back( xShape );
1056 }
1057 }
1058
1059 if( !aShapeVector.empty() )
1060 {
1061 // create a shape collection
1062 xFoundShapes = drawing::ShapeCollection::create(
1063 comphelper::getProcessComponentContext());
1064
1065 OSL_ENSURE( xFoundShapes.is(), "Couldn't create a shape collection!" );
1066 if( xFoundShapes.is())
1067 {
1068 for (auto const& shape : aShapeVector)
1069 xFoundShapes->add(shape);
1070 }
1071 }
1072
1073 return xFoundShapes;
1074 }
1075
1076 void SAL_CALL ChartDocumentWrapper::addEventListener( const Reference< lang::XEventListener >& xListener )
1077 {
1078 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
1079 if( xModel.is() )
1080 xModel->addEventListener( xListener );
1081 }
1082
1083 void SAL_CALL ChartDocumentWrapper::removeEventListener( const Reference< lang::XEventListener >& aListener )
1084 {
1085 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
1086 if( xModel.is() )
1087 xModel->removeEventListener( aListener );
1088 }
1089
1090 // ____ XDrawPageSupplier ____
1091 uno::Reference< drawing::XDrawPage > SAL_CALL ChartDocumentWrapper::getDrawPage()
1092 {
1093 return impl_getDrawPage();
1094 }
1095
1096 rtl::Reference<SvxDrawPage> ChartDocumentWrapper::impl_getDrawPage() const
1097 {
1098 return m_spChart2ModelContact->getDrawPage();
1099 }
1100
1101 namespace {
1102
1103 uno::Reference< lang::XMultiServiceFactory > getShapeFactory(const rtl::Reference<ChartView>& xChartView)
1104 {
1105 if( xChartView )
1106 return xChartView->getDrawModelWrapper()->getShapeFactory();
1107
1108 return uno::Reference< lang::XMultiServiceFactory >();
1109 }
1110
1111 }
1112
1113 // ____ XMultiServiceFactory ____
1114 uno::Reference< uno::XInterface > SAL_CALL ChartDocumentWrapper::createInstance(
1115 const OUString& aServiceSpecifier )
1116 {
1117 uno::Reference< uno::XInterface > xResult;
1118
1119 rtl::Reference< ChartModel > xChartDoc( m_spChart2ModelContact->getDocumentModel() );
1120 if( !xChartDoc.is() )
1121 return xResult;
1122
1123 bool bServiceFound = false;
1124 tServiceNameMap & rMap = lcl_getStaticServiceNameMap();
1125
1126 tServiceNameMap::const_iterator aIt( rMap.find( aServiceSpecifier ));
1127 if( aIt != rMap.end())
1128 {
1129 bool bCreateDiagram = false;
1130 rtl::Reference< ::chart::ChartTypeManager > xChartTypeManager =
1131 xChartDoc->getTypeManager();
1132 rtl::Reference< ::chart::ChartTypeTemplate > xTemplate;
1133
1134 switch( (*aIt).second )
1135 {
1136 case SERVICE_NAME_AREA_DIAGRAM:
1137 if( xChartTypeManager.is())
1138 {
1139 xTemplate =
1140 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.Area"_ustr);
1141 bCreateDiagram = true;
1142 }
1143 break;
1144 case SERVICE_NAME_BAR_DIAGRAM:
1145 if( xChartTypeManager.is())
1146 {
1147 // this is for bar and column (the latter is the default if
1148 // no "Vertical=false" property was set)
1149 xTemplate =
1150 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.Column"_ustr);
1151 bCreateDiagram = true;
1152 }
1153 break;
1154 case SERVICE_NAME_DONUT_DIAGRAM:
1155 if( xChartTypeManager.is())
1156 {
1157 xTemplate =
1158 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.Donut"_ustr);
1159 bCreateDiagram = true;
1160 }
1161 break;
1162 case SERVICE_NAME_LINE_DIAGRAM:
1163 if( xChartTypeManager.is())
1164 {
1165 xTemplate =
1166 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.Line"_ustr);
1167 bCreateDiagram = true;
1168 }
1169 break;
1170 case SERVICE_NAME_NET_DIAGRAM:
1171 if( xChartTypeManager.is())
1172 {
1173 xTemplate =
1174 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.Net"_ustr);
1175 bCreateDiagram = true;
1176 }
1177 break;
1178 case SERVICE_NAME_FILLED_NET_DIAGRAM:
1179 if( xChartTypeManager.is())
1180 {
1181 xTemplate =
1182 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.FilledNet"_ustr);
1183 bCreateDiagram = true;
1184 }
1185 break;
1186 case SERVICE_NAME_PIE_DIAGRAM:
1187 if( xChartTypeManager.is())
1188 {
1189 xTemplate =
1190 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.Pie"_ustr);
1191 bCreateDiagram = true;
1192 }
1193 break;
1194 case SERVICE_NAME_STOCK_DIAGRAM:
1195 if( xChartTypeManager.is())
1196 {
1197 xTemplate =
1198 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.StockLowHighClose"_ustr);
1199 bCreateDiagram = true;
1200 }
1201 break;
1202 case SERVICE_NAME_XY_DIAGRAM:
1203 if( xChartTypeManager.is())
1204 {
1205 xTemplate =
1206 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.ScatterLineSymbol"_ustr);
1207 bCreateDiagram = true;
1208 }
1209 break;
1210
1211 case SERVICE_NAME_BUBBLE_DIAGRAM:
1212 if( xChartTypeManager.is())
1213 {
1214 xTemplate =
1215 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.Bubble"_ustr);
1216 bCreateDiagram = true;
1217 }
1218 break;
1219
1220 case SERVICE_NAME_DASH_TABLE:
1221 case SERVICE_NAME_GRADIENT_TABLE:
1222 case SERVICE_NAME_HATCH_TABLE:
1223 case SERVICE_NAME_BITMAP_TABLE:
1224 case SERVICE_NAME_TRANSP_GRADIENT_TABLE:
1225 case SERVICE_NAME_MARKER_TABLE:
1226 xResult.set( xChartDoc->createInstance( aIt->first ), uno::UNO_QUERY );
1227 break;
1228
1229 case SERVICE_NAME_NAMESPACE_MAP:
1230 break;
1231 case SERVICE_NAME_EXPORT_GRAPHIC_STORAGE_RESOLVER:
1232 break;
1233 case SERVICE_NAME_IMPORT_GRAPHIC_STORAGE_RESOLVER:
1234 break;
1235 }
1236
1237 if( bCreateDiagram && xTemplate.is() )
1238 {
1239 try
1240 {
1241 uno::Reference< chart2::XDiagram > xDia( xChartDoc->getFirstDiagram());
1242 if( xDia.is())
1243 {
1244 // locked controllers
1245 ControllerLockGuardUNO aCtrlLockGuard( xChartDoc );
1246 rtl::Reference< Diagram > xDiagram = xChartDoc->getFirstChartDiagram();
1247 ThreeDLookScheme e3DScheme = xDiagram->detectScheme();
1248 rtl::Reference< ::chart::ChartTypeManager > xTemplateManager = xChartDoc->getTypeManager();
1249 Diagram::tTemplateWithServiceName aTemplateWithService(
1250 xDiagram->getTemplate( xTemplateManager ));
1251 if( aTemplateWithService.xChartTypeTemplate.is())
1252 aTemplateWithService.xChartTypeTemplate->resetStyles2( xDiagram );//#i109371#
1253 xTemplate->changeDiagram( xDiagram );
1254 if( AllSettings::GetMathLayoutRTL() )
1255 AxisHelper::setRTLAxisLayout( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 ) );
1256 xDiagram->setScheme( e3DScheme );
1257 }
1258 else
1259 {
1260 // locked controllers
1261 ControllerLockGuardUNO aCtrlLockGuard( xChartDoc );
1262 xDia.set( xTemplate->createDiagramByDataSource(
1263 uno::Reference< chart2::data::XDataSource >(),
1264 uno::Sequence< beans::PropertyValue >()));
1265 xChartDoc->setFirstDiagram( xDia );
1266 }
1267
1268 xResult = static_cast< ::cppu::OWeakObject* >( new DiagramWrapper( m_spChart2ModelContact ));
1269 }
1270 catch (const uno::Exception&)
1271 {
1272 DBG_UNHANDLED_EXCEPTION("chart2");
1273 }
1274 }
1275
1276 bServiceFound = true;
1277 }
1278 else if( aServiceSpecifier == "com.sun.star.comp.chart2.DataSeriesWrapper" )
1279 {
1280 Reference< beans::XPropertySet > xDataSeries( new DataSeriesPointWrapper( m_spChart2ModelContact ) );
1281 xResult.set( xDataSeries );
1282 bServiceFound = true;
1283 }
1284 else if( aServiceSpecifier == CHART_VIEW_SERVICE_NAME )
1285 {
1286 if( !m_xChartView.is() )
1287 {
1288 rtl::Reference<::chart::ChartModel> pChartModel = new ::chart::ChartModel(m_spChart2ModelContact->m_xContext);
1289 rtl::Reference<ChartView> xChartView = new ::chart::ChartView(m_spChart2ModelContact->m_xContext, *pChartModel);
1290
1291 try
1292 {
1293 m_xChartView = xChartView;
1294
1295 Sequence< Any > aArguments{ Any(Reference<frame::XModel>(this)),
1296 Any(true) }; // bRefreshAddIn
1297 xChartView->initialize(aArguments);
1298 }
1299 catch (const uno::Exception&)
1300 {
1301 DBG_UNHANDLED_EXCEPTION("chart2");
1302 }
1303 }
1304 xResult.set( static_cast<cppu::OWeakObject*>(m_xChartView.get()) );
1305 bServiceFound = true;
1306 }
1307 else
1308 {
1309 // try to create a shape
1310 try
1311 {
1312 if( !m_xShapeFactory.is() && m_xChartView.is() )
1313 {
1314 m_xShapeFactory = getShapeFactory( m_xChartView );
1315 }
1316 else
1317 {
1318 rtl::Reference<ChartModel> pModel = m_spChart2ModelContact->getDocumentModel();
1319 if(pModel)
1320 {
1321 m_xChartView = pModel->getChartView();
1322 m_xShapeFactory = getShapeFactory( m_xChartView );
1323 }
1324 }
1325
1326 if( m_xShapeFactory.is() )
1327 {
1328 xResult = m_xShapeFactory->createInstance( aServiceSpecifier );
1329 bServiceFound = true;
1330 }
1331 }
1332 catch (const uno::Exception&)
1333 {
1334 // couldn't create shape
1335 }
1336 }
1337
1338 // finally, try to create an addin
1339 if( !bServiceFound )
1340 {
1341 try
1342 {
1343 Reference< lang::XMultiServiceFactory > xFact(
1344 m_spChart2ModelContact->m_xContext->getServiceManager(), uno::UNO_QUERY_THROW );
1345 uno::Reference< util::XRefreshable > xAddIn(
1346 xFact->createInstance( aServiceSpecifier ), uno::UNO_QUERY );
1347 if( xAddIn.is() )
1348 {
1349 xResult = xAddIn;
1350 }
1351 }
1352 catch (const uno::Exception&)
1353 {
1354 // couldn't create service
1355 }
1356 }
1357
1358 return xResult;
1359 }
1360
1361 uno::Reference< uno::XInterface > SAL_CALL ChartDocumentWrapper::createInstanceWithArguments(
1362 const OUString& ServiceSpecifier,
1363 const uno::Sequence< uno::Any >& Arguments )
1364 {
1365 OSL_ENSURE( Arguments.hasElements(), "createInstanceWithArguments: Warning: Arguments are ignored" );
1366
1367 return createInstance( ServiceSpecifier );
1368 }
1369
1370 uno::Sequence< OUString > SAL_CALL ChartDocumentWrapper::getAvailableServiceNames()
1371 {
1372 return comphelper::mapKeysToSequence( lcl_getStaticServiceNameMap() );
1373 }
1374
1375 // ____ XAggregation ____
1376 void SAL_CALL ChartDocumentWrapper::setDelegator(
1377 const uno::Reference< uno::XInterface >& rDelegator )
1378 {
1379 if( m_bIsDisposed )
1380 {
1381 if( rDelegator.is() )
1382 throw lang::DisposedException(u"ChartDocumentWrapper is disposed"_ustr,
1383 static_cast< ::cppu::OWeakObject* >( this ));
1384 return;
1385 }
1386
1387 if( rDelegator.is())
1388 {
1389 m_xDelegator = rDelegator;
1390 ChartModel* pChartModel = dynamic_cast<ChartModel*>(rDelegator.get());
1391 assert(pChartModel);
1392 m_spChart2ModelContact->setDocumentModel( pChartModel );
1393 }
1394 else
1395 {
1396 // this is a sort of dispose() from the new model,so release resources here
1397 try
1398 {
1399 dispose();
1400 }
1401 catch (const uno::Exception&)
1402 {
1403 DBG_UNHANDLED_EXCEPTION("chart2");
1404 }
1405 }
1406 }
1407
1408 uno::Any SAL_CALL ChartDocumentWrapper::queryAggregation( const uno::Type& rType )
1409 {
1410 return ChartDocumentWrapper_Base::queryInterface( rType );
1411 }
1412
1413 // ____ ::utl::OEventListenerAdapter ____
1414 void ChartDocumentWrapper::_disposing( const lang::EventObject& rSource )
1415 {
1416 if( rSource.Source == cppu::getXWeak(m_xTitle.get()) )
1417 m_xTitle.clear();
1418 else if( rSource.Source == cppu::getXWeak(m_xSubTitle.get()) )
1419 m_xSubTitle.clear();
1420 else if( rSource.Source == cppu::getXWeak(m_xLegend.get()) )
1421 m_xLegend.clear();
1422 else if( rSource.Source == m_xChartData )
1423 m_xChartData.clear();
1424 else if( rSource.Source == cppu::getXWeak(m_xDiagram.get()) )
1425 m_xDiagram.clear();
1426 else if( rSource.Source == m_xArea )
1427 m_xArea.clear();
1428 else if( rSource.Source == m_xAddIn )
1429 m_xAddIn.clear();
1430 else if( rSource.Source == static_cast<cppu::OWeakObject*>(m_xChartView.get()) )
1431 m_xChartView.clear();
1432 }
1433
1434 // ____ XPropertySet ____
1435 void SAL_CALL ChartDocumentWrapper::setPropertyValue(const OUString& rPropertyName, const css::uno::Any& rValue)
1436 {
1437 if (rPropertyName == u"ODFImport_UpdateView")
1438 {
1439 // A hack used at load time to notify the view that it needs an update
1440 // See SchXMLImport::~SchXMLImport
1441 if (auto xChartModel = rValue.query<css::chart2::XChartDocument>())
1442 ChartViewHelper::setViewToDirtyState_UNO(xChartModel);
1443 return;
1444 }
1445 ChartDocumentWrapper_Base::setPropertyValue(rPropertyName, rValue);
1446 }
1447
1448 // WrappedPropertySet
1449 Reference< beans::XPropertySet > ChartDocumentWrapper::getInnerPropertySet()
1450 {
1451 return nullptr;
1452 }
1453 const Sequence< beans::Property >& ChartDocumentWrapper::getPropertySequence()
1454 {
1455 return StaticChartDocumentWrapperPropertyArray();
1456 }
1457
1458 std::vector< std::unique_ptr<WrappedProperty> > ChartDocumentWrapper::createWrappedProperties()
1459 {
1460 std::vector< std::unique_ptr<WrappedProperty> > aWrappedProperties;
1461 aWrappedProperties.emplace_back( new WrappedDataSourceLabelsInFirstRowProperty( m_spChart2ModelContact ) );
1462 aWrappedProperties.emplace_back( new WrappedDataSourceLabelsInFirstColumnProperty( m_spChart2ModelContact ) );
1463 aWrappedProperties.emplace_back( new WrappedHasLegendProperty( m_spChart2ModelContact ) );
1464 aWrappedProperties.emplace_back( new WrappedHasMainTitleProperty( m_spChart2ModelContact ) );
1465 aWrappedProperties.emplace_back( new WrappedHasSubTitleProperty( m_spChart2ModelContact ) );
1466 aWrappedProperties.emplace_back( new WrappedAddInProperty( *this ) );
1467 aWrappedProperties.emplace_back( new WrappedBaseDiagramProperty( *this ) );
1468 aWrappedProperties.emplace_back( new WrappedAdditionalShapesProperty( *this ) );
1469 aWrappedProperties.emplace_back( new WrappedRefreshAddInAllowedProperty( *this ) );
1470 aWrappedProperties.emplace_back( new WrappedNullDateProperty( m_spChart2ModelContact ) );
1471 aWrappedProperties.emplace_back( new WrappedIgnoreProperty(u"EnableComplexChartTypes"_ustr, uno::Any(true) ) );
1472 aWrappedProperties.emplace_back( new WrappedIgnoreProperty(u"EnableDataTableDialog"_ustr, uno::Any(true) ) );
1473
1474 return aWrappedProperties;
1475 }
1476
1477 OUString SAL_CALL ChartDocumentWrapper::getImplementationName()
1478 {
1479 return u"com.sun.star.comp.chart2.ChartDocumentWrapper"_ustr;
1480 }
1481
1482 sal_Bool SAL_CALL ChartDocumentWrapper::supportsService( const OUString& rServiceName )
1483 {
1484 return cppu::supportsService(this, rServiceName);
1485 }
1486
1487 css::uno::Sequence< OUString > SAL_CALL ChartDocumentWrapper::getSupportedServiceNames()
1488 {
1489 return {
1490 u"com.sun.star.chart.ChartDocument"_ustr,
1491 u"com.sun.star.chart2.ChartDocumentWrapper"_ustr,
1492 u"com.sun.star.xml.UserDefinedAttributesSupplier"_ustr,
1493 u"com.sun.star.beans.PropertySet"_ustr
1494 };
1495 }
1496
1497 } // namespace chart::wrapper
1498
1499 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1500 com_sun_star_comp_chart2_ChartDocumentWrapper_get_implementation(css::uno::XComponentContext *context,
1501 css::uno::Sequence<css::uno::Any> const &)
1502 {
1503 return cppu::acquire(new ::chart::wrapper::ChartDocumentWrapper(context));
1504 }
1505
1506 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */