tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / ChartDocumentWrapper.cxx
blobab6de48e0fe13eb60db428e3f6dbac4b4ba415bc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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/ExplicitValueProvider.hxx>
34 #include <chartview/DrawModelWrapper.hxx>
35 #include "Chart2ModelContact.hxx"
36 #include <BaseCoordinateSystem.hxx>
38 #include <ChartModel.hxx>
40 #include <DataSourceHelper.hxx>
41 #include <AxisHelper.hxx>
42 #include <ThreeDHelper.hxx>
44 #include "TitleWrapper.hxx"
45 #include "ChartDataWrapper.hxx"
46 #include "DiagramWrapper.hxx"
47 #include "LegendWrapper.hxx"
48 #include "AreaWrapper.hxx"
49 #include "WrappedAddInProperty.hxx"
50 #include <WrappedIgnoreProperty.hxx>
51 #include <cppuhelper/supportsservice.hxx>
52 #include <comphelper/processfactory.hxx>
53 #include <comphelper/sequence.hxx>
54 #include <utility>
55 #include <vcl/settings.hxx>
57 #include <com/sun/star/drawing/ShapeCollection.hpp>
58 #include <com/sun/star/beans/PropertyAttribute.hpp>
59 #include <com/sun/star/lang/DisposedException.hpp>
60 #include <com/sun/star/lang/XInitialization.hpp>
61 #include <com/sun/star/util/XRefreshable.hpp>
62 #include <comphelper/diagnose_ex.hxx>
64 #include <algorithm>
65 #include <map>
67 using namespace ::com::sun::star;
68 using namespace ::com::sun::star::chart;
70 using ::com::sun::star::uno::Any;
71 using ::com::sun::star::uno::UNO_QUERY_THROW;
72 using ::com::sun::star::uno::Reference;
73 using ::com::sun::star::uno::Sequence;
74 using ::com::sun::star::beans::Property;
76 namespace
78 enum eServiceType
80 SERVICE_NAME_AREA_DIAGRAM = 0,
81 SERVICE_NAME_BAR_DIAGRAM,
82 SERVICE_NAME_DONUT_DIAGRAM,
83 SERVICE_NAME_LINE_DIAGRAM,
84 SERVICE_NAME_NET_DIAGRAM,
85 SERVICE_NAME_FILLED_NET_DIAGRAM,
86 SERVICE_NAME_PIE_DIAGRAM,
87 SERVICE_NAME_STOCK_DIAGRAM,
88 SERVICE_NAME_XY_DIAGRAM,
89 SERVICE_NAME_BUBBLE_DIAGRAM,
91 SERVICE_NAME_DASH_TABLE,
92 SERVICE_NAME_GRADIENT_TABLE,
93 SERVICE_NAME_HATCH_TABLE,
94 SERVICE_NAME_BITMAP_TABLE,
95 SERVICE_NAME_TRANSP_GRADIENT_TABLE,
96 SERVICE_NAME_MARKER_TABLE,
98 SERVICE_NAME_NAMESPACE_MAP,
99 SERVICE_NAME_EXPORT_GRAPHIC_STORAGE_RESOLVER,
100 SERVICE_NAME_IMPORT_GRAPHIC_STORAGE_RESOLVER
103 typedef std::map< OUString, enum eServiceType > tServiceNameMap;
105 tServiceNameMap & lcl_getStaticServiceNameMap()
107 static tServiceNameMap aServiceNameMap {
108 {"com.sun.star.chart.AreaDiagram", SERVICE_NAME_AREA_DIAGRAM},
109 {"com.sun.star.chart.BarDiagram", SERVICE_NAME_BAR_DIAGRAM},
110 {"com.sun.star.chart.DonutDiagram", SERVICE_NAME_DONUT_DIAGRAM},
111 {"com.sun.star.chart.LineDiagram", SERVICE_NAME_LINE_DIAGRAM},
112 {"com.sun.star.chart.NetDiagram", SERVICE_NAME_NET_DIAGRAM},
113 {"com.sun.star.chart.FilledNetDiagram", SERVICE_NAME_FILLED_NET_DIAGRAM},
114 {"com.sun.star.chart.PieDiagram", SERVICE_NAME_PIE_DIAGRAM},
115 {"com.sun.star.chart.StockDiagram", SERVICE_NAME_STOCK_DIAGRAM},
116 {"com.sun.star.chart.XYDiagram", SERVICE_NAME_XY_DIAGRAM},
117 {"com.sun.star.chart.BubbleDiagram", SERVICE_NAME_BUBBLE_DIAGRAM},
119 {"com.sun.star.drawing.DashTable", SERVICE_NAME_DASH_TABLE},
120 {"com.sun.star.drawing.GradientTable", SERVICE_NAME_GRADIENT_TABLE},
121 {"com.sun.star.drawing.HatchTable", SERVICE_NAME_HATCH_TABLE},
122 {"com.sun.star.drawing.BitmapTable", SERVICE_NAME_BITMAP_TABLE},
123 {"com.sun.star.drawing.TransparencyGradientTable", SERVICE_NAME_TRANSP_GRADIENT_TABLE},
124 {"com.sun.star.drawing.MarkerTable", SERVICE_NAME_MARKER_TABLE},
126 {"com.sun.star.xml.NamespaceMap", SERVICE_NAME_NAMESPACE_MAP},
127 {"com.sun.star.document.ExportGraphicStorageHandler", SERVICE_NAME_EXPORT_GRAPHIC_STORAGE_RESOLVER},
128 {"com.sun.star.document.ImportGraphicStorageHandler", SERVICE_NAME_IMPORT_GRAPHIC_STORAGE_RESOLVER}
131 return aServiceNameMap;
134 enum
136 PROP_DOCUMENT_HAS_MAIN_TITLE,
137 PROP_DOCUMENT_HAS_SUB_TITLE,
138 PROP_DOCUMENT_HAS_LEGEND,
139 PROP_DOCUMENT_LABELS_IN_FIRST_ROW,
140 PROP_DOCUMENT_LABELS_IN_FIRST_COLUMN,
141 PROP_DOCUMENT_ADDIN,
142 PROP_DOCUMENT_BASEDIAGRAM,
143 PROP_DOCUMENT_ADDITIONAL_SHAPES,
144 PROP_DOCUMENT_UPDATE_ADDIN,
145 PROP_DOCUMENT_NULL_DATE,
146 PROP_DOCUMENT_ENABLE_COMPLEX_CHARTTYPES,
147 PROP_DOCUMENT_ENABLE_DATATABLE_DIALOG
150 void lcl_AddPropertiesToVector(
151 std::vector< Property > & rOutProperties )
153 rOutProperties.emplace_back( "HasMainTitle",
154 PROP_DOCUMENT_HAS_MAIN_TITLE,
155 cppu::UnoType<bool>::get(),
156 //#i111967# no PropertyChangeEvent is fired on change so far
157 beans::PropertyAttribute::MAYBEDEFAULT );
158 rOutProperties.emplace_back( "HasSubTitle",
159 PROP_DOCUMENT_HAS_SUB_TITLE,
160 cppu::UnoType<bool>::get(),
161 //#i111967# no PropertyChangeEvent is fired on change so far
162 beans::PropertyAttribute::MAYBEDEFAULT );
163 rOutProperties.emplace_back( "HasLegend",
164 PROP_DOCUMENT_HAS_LEGEND,
165 cppu::UnoType<bool>::get(),
166 //#i111967# no PropertyChangeEvent is fired on change so far
167 beans::PropertyAttribute::MAYBEDEFAULT );
169 // really needed?
170 rOutProperties.emplace_back( "DataSourceLabelsInFirstRow",
171 PROP_DOCUMENT_LABELS_IN_FIRST_ROW,
172 cppu::UnoType<bool>::get(),
173 beans::PropertyAttribute::BOUND
174 | beans::PropertyAttribute::MAYBEDEFAULT );
175 rOutProperties.emplace_back( "DataSourceLabelsInFirstColumn",
176 PROP_DOCUMENT_LABELS_IN_FIRST_COLUMN,
177 cppu::UnoType<bool>::get(),
178 //#i111967# no PropertyChangeEvent is fired on change so far
179 beans::PropertyAttribute::MAYBEDEFAULT );
181 //add-in
182 rOutProperties.emplace_back( "AddIn",
183 PROP_DOCUMENT_ADDIN,
184 cppu::UnoType<util::XRefreshable>::get(),
185 beans::PropertyAttribute::BOUND
186 | beans::PropertyAttribute::MAYBEVOID );
187 rOutProperties.emplace_back( "BaseDiagram",
188 PROP_DOCUMENT_BASEDIAGRAM,
189 cppu::UnoType<OUString>::get(),
190 beans::PropertyAttribute::BOUND
191 | beans::PropertyAttribute::MAYBEVOID );
192 rOutProperties.emplace_back( "AdditionalShapes",
193 PROP_DOCUMENT_ADDITIONAL_SHAPES,
194 cppu::UnoType<drawing::XShapes>::get(),
195 beans::PropertyAttribute::BOUND
196 | beans::PropertyAttribute::MAYBEVOID
197 | beans::PropertyAttribute::READONLY );
198 rOutProperties.emplace_back( "RefreshAddInAllowed",
199 PROP_DOCUMENT_UPDATE_ADDIN,
200 cppu::UnoType<bool>::get(),
201 //#i111967# no PropertyChangeEvent is fired on change so far
202 beans::PropertyAttribute::TRANSIENT );
204 // table:null-date // i99104
205 rOutProperties.emplace_back( "NullDate",
206 PROP_DOCUMENT_NULL_DATE,
207 ::cppu::UnoType<css::util::DateTime>::get(),
208 beans::PropertyAttribute::MAYBEVOID );
210 rOutProperties.emplace_back( "EnableComplexChartTypes",
211 PROP_DOCUMENT_ENABLE_COMPLEX_CHARTTYPES,
212 cppu::UnoType<bool>::get(),
213 //#i112666# no PropertyChangeEvent is fired on change so far
214 beans::PropertyAttribute::MAYBEDEFAULT );
215 rOutProperties.emplace_back( "EnableDataTableDialog",
216 PROP_DOCUMENT_ENABLE_DATATABLE_DIALOG,
217 cppu::UnoType<bool>::get(),
218 //#i112666# no PropertyChangeEvent is fired on change so far
219 beans::PropertyAttribute::MAYBEDEFAULT );
222 const Sequence< Property > & StaticChartDocumentWrapperPropertyArray()
224 static Sequence< Property > aPropSeq = []()
226 std::vector< css::beans::Property > aProperties;
227 lcl_AddPropertiesToVector( aProperties );
229 std::sort( aProperties.begin(), aProperties.end(),
230 ::chart::PropertyNameLess() );
232 return comphelper::containerToSequence( aProperties );
233 }();
234 return aPropSeq;
237 } // anonymous namespace
239 namespace chart::wrapper
242 namespace {
244 //PROP_DOCUMENT_LABELS_IN_FIRST_ROW
245 class WrappedDataSourceLabelsInFirstRowProperty : public WrappedProperty
247 public:
248 explicit WrappedDataSourceLabelsInFirstRowProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact);
250 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
252 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
254 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
256 private: //member
257 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
258 mutable Any m_aOuterValue;
263 WrappedDataSourceLabelsInFirstRowProperty::WrappedDataSourceLabelsInFirstRowProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
264 : WrappedProperty(u"DataSourceLabelsInFirstRow"_ustr,OUString())
265 , m_spChart2ModelContact(std::move( spChart2ModelContact ))
267 m_aOuterValue = WrappedDataSourceLabelsInFirstRowProperty::getPropertyDefault( nullptr );
270 void WrappedDataSourceLabelsInFirstRowProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
272 bool bLabelsInFirstRow = true;
273 if( ! (rOuterValue >>= bLabelsInFirstRow) )
274 throw lang::IllegalArgumentException(u"Property DataSourceLabelsInFirstRow requires value of type boolean"_ustr, nullptr, 0 );
276 m_aOuterValue = rOuterValue;
277 bool bNewValue = bLabelsInFirstRow;
279 OUString aRangeString;
280 bool bUseColumns = true;
281 bool bFirstCellAsLabel = true;
282 bool bHasCategories = true;
283 uno::Sequence< sal_Int32 > aSequenceMapping;
285 if( !DataSourceHelper::detectRangeSegmentation(
286 m_spChart2ModelContact->getDocumentModel(), aRangeString, aSequenceMapping, bUseColumns
287 , bFirstCellAsLabel, bHasCategories ) )
288 return;
290 if( bUseColumns && bNewValue != bFirstCellAsLabel )
292 DataSourceHelper::setRangeSegmentation(
293 m_spChart2ModelContact->getDocumentModel(), aSequenceMapping, bUseColumns ,bNewValue, bHasCategories );
295 else if( !bUseColumns && bNewValue != bHasCategories )
297 DataSourceHelper::setRangeSegmentation(
298 m_spChart2ModelContact->getDocumentModel(), aSequenceMapping, bUseColumns , bFirstCellAsLabel, bNewValue );
302 Any WrappedDataSourceLabelsInFirstRowProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
304 OUString aRangeString;
305 bool bUseColumns = true;
306 bool bFirstCellAsLabel = true;
307 bool bHasCategories = true;
308 uno::Sequence< sal_Int32 > aSequenceMapping;
310 if( DataSourceHelper::detectRangeSegmentation(
311 m_spChart2ModelContact->getDocumentModel(), aRangeString, aSequenceMapping, bUseColumns
312 , bFirstCellAsLabel, bHasCategories ) )
314 bool bLabelsInFirstRow = true;
315 if( bUseColumns )
316 bLabelsInFirstRow = bFirstCellAsLabel;
317 else
318 bLabelsInFirstRow = bHasCategories;
320 m_aOuterValue <<= bLabelsInFirstRow;
322 return m_aOuterValue;
325 Any WrappedDataSourceLabelsInFirstRowProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
327 Any aRet;
328 aRet <<= true;
329 return aRet;
332 namespace {
334 //PROP_DOCUMENT_LABELS_IN_FIRST_COLUMN
335 class WrappedDataSourceLabelsInFirstColumnProperty : public WrappedProperty
337 public:
338 explicit WrappedDataSourceLabelsInFirstColumnProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact);
340 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
342 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
344 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
346 private: //member
347 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
348 mutable Any m_aOuterValue;
353 WrappedDataSourceLabelsInFirstColumnProperty::WrappedDataSourceLabelsInFirstColumnProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
354 : WrappedProperty(u"DataSourceLabelsInFirstColumn"_ustr,OUString())
355 , m_spChart2ModelContact(std::move( spChart2ModelContact ))
357 m_aOuterValue = WrappedDataSourceLabelsInFirstColumnProperty::getPropertyDefault( nullptr );
360 void WrappedDataSourceLabelsInFirstColumnProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
362 bool bLabelsInFirstRow = true;
363 if( ! (rOuterValue >>= bLabelsInFirstRow) )
364 throw lang::IllegalArgumentException(u"Property DataSourceLabelsInFirstRow requires value of type boolean"_ustr, nullptr, 0 );
366 m_aOuterValue = rOuterValue;
367 bool bNewValue = bLabelsInFirstRow;
369 OUString aRangeString;
370 bool bUseColumns = true;
371 bool bFirstCellAsLabel = true;
372 bool bHasCategories = true;
373 uno::Sequence< sal_Int32 > aSequenceMapping;
375 if( !DataSourceHelper::detectRangeSegmentation(
376 m_spChart2ModelContact->getDocumentModel(), aRangeString, aSequenceMapping, bUseColumns
377 , bFirstCellAsLabel, bHasCategories ) )
378 return;
380 if( bUseColumns && bNewValue != bHasCategories )
382 DataSourceHelper::setRangeSegmentation(
383 m_spChart2ModelContact->getDocumentModel(), aSequenceMapping, bUseColumns, bFirstCellAsLabel, bNewValue );
385 else if( !bUseColumns && bNewValue != bFirstCellAsLabel )
387 DataSourceHelper::setRangeSegmentation(
388 m_spChart2ModelContact->getDocumentModel(), aSequenceMapping, bUseColumns , bNewValue, bHasCategories );
392 Any WrappedDataSourceLabelsInFirstColumnProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
394 OUString aRangeString;
395 bool bUseColumns = true;
396 bool bFirstCellAsLabel = true;
397 bool bHasCategories = true;
398 uno::Sequence< sal_Int32 > aSequenceMapping;
400 if( DataSourceHelper::detectRangeSegmentation(
401 m_spChart2ModelContact->getDocumentModel(), aRangeString, aSequenceMapping, bUseColumns
402 , bFirstCellAsLabel, bHasCategories ) )
404 bool bLabelsInFirstColumn = true;
405 if( bUseColumns )
406 bLabelsInFirstColumn = bHasCategories;
407 else
408 bLabelsInFirstColumn = bFirstCellAsLabel;
410 m_aOuterValue <<= bLabelsInFirstColumn;
412 return m_aOuterValue;
415 Any WrappedDataSourceLabelsInFirstColumnProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
417 Any aRet;
418 aRet <<= true;
419 return aRet;
422 namespace {
424 //PROP_DOCUMENT_HAS_LEGEND
425 class WrappedHasLegendProperty : public WrappedProperty
427 public:
428 explicit WrappedHasLegendProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact);
430 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
432 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
434 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
436 private: //member
437 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
442 WrappedHasLegendProperty::WrappedHasLegendProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
443 : WrappedProperty(u"HasLegend"_ustr,OUString())
444 , m_spChart2ModelContact(std::move( spChart2ModelContact ))
448 void WrappedHasLegendProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
450 bool bNewValue = true;
451 if( ! (rOuterValue >>= bNewValue) )
452 throw lang::IllegalArgumentException(u"Property HasLegend requires value of type boolean"_ustr, nullptr, 0 );
456 rtl::Reference< Legend > xLegend = LegendHelper::getLegend( *m_spChart2ModelContact->getDocumentModel(), m_spChart2ModelContact->m_xContext,bNewValue );
457 if(xLegend.is())
459 bool bOldValue = true;
460 Any aAOld = xLegend->getPropertyValue(u"Show"_ustr);
461 aAOld >>= bOldValue;
462 if( bOldValue != bNewValue )
463 xLegend->setPropertyValue(u"Show"_ustr, uno::Any( bNewValue ));
466 catch (const uno::Exception&)
468 DBG_UNHANDLED_EXCEPTION("chart2");
472 Any WrappedHasLegendProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
474 Any aRet;
477 rtl::Reference< Legend > xLegend =
478 LegendHelper::getLegend( *m_spChart2ModelContact->getDocumentModel() );
479 if( xLegend.is())
480 aRet = xLegend->getPropertyValue(u"Show"_ustr);
481 else
482 aRet <<= false;
484 catch (const uno::Exception&)
486 DBG_UNHANDLED_EXCEPTION("chart2");
488 return aRet;
491 Any WrappedHasLegendProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
493 Any aRet;
494 aRet <<= false;
495 return aRet;
498 namespace {
500 //PROP_DOCUMENT_HAS_MAIN_TITLE
501 class WrappedHasMainTitleProperty : public WrappedProperty
503 public:
504 explicit WrappedHasMainTitleProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact);
506 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
508 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
510 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
512 private: //member
513 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
518 WrappedHasMainTitleProperty::WrappedHasMainTitleProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
519 : WrappedProperty(u"HasMainTitle"_ustr,OUString())
520 , m_spChart2ModelContact(std::move( spChart2ModelContact ))
524 void WrappedHasMainTitleProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
526 bool bNewValue = true;
527 if( ! (rOuterValue >>= bNewValue) )
528 throw lang::IllegalArgumentException(u"Property HasMainTitle requires value of type boolean"_ustr, nullptr, 0 );
532 if( bNewValue )
533 TitleHelper::createTitle( TitleHelper::MAIN_TITLE, u"main-title"_ustr, m_spChart2ModelContact->getDocumentModel(), m_spChart2ModelContact->m_xContext );
534 else
535 TitleHelper::removeTitle( TitleHelper::MAIN_TITLE, m_spChart2ModelContact->getDocumentModel() );
537 catch (const uno::Exception&)
539 DBG_UNHANDLED_EXCEPTION("chart2");
543 Any WrappedHasMainTitleProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
545 Any aRet;
548 aRet <<= TitleHelper::getTitle( TitleHelper::MAIN_TITLE, m_spChart2ModelContact->getDocumentModel() ).is();
550 catch (const uno::Exception&)
552 DBG_UNHANDLED_EXCEPTION("chart2");
554 return aRet;
557 Any WrappedHasMainTitleProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
559 Any aRet;
560 aRet <<= false;
561 return aRet;
564 namespace {
566 //PROP_DOCUMENT_HAS_SUB_TITLE
567 class WrappedHasSubTitleProperty : public WrappedProperty
569 public:
570 explicit WrappedHasSubTitleProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact);
572 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
574 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
576 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
578 private: //member
579 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
584 WrappedHasSubTitleProperty::WrappedHasSubTitleProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
585 : WrappedProperty(u"HasSubTitle"_ustr,OUString())
586 , m_spChart2ModelContact(std::move( spChart2ModelContact ))
590 void WrappedHasSubTitleProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
592 bool bNewValue = true;
593 if( ! (rOuterValue >>= bNewValue) )
594 throw lang::IllegalArgumentException(u"Property HasSubTitle requires value of type boolean"_ustr, nullptr, 0 );
598 if( bNewValue )
599 TitleHelper::createTitle( TitleHelper::SUB_TITLE, u""_ustr, m_spChart2ModelContact->getDocumentModel(), m_spChart2ModelContact->m_xContext );
600 else
601 TitleHelper::removeTitle( TitleHelper::SUB_TITLE, m_spChart2ModelContact->getDocumentModel() );
603 catch (const uno::Exception&)
605 DBG_UNHANDLED_EXCEPTION("chart2");
609 Any WrappedHasSubTitleProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
611 Any aRet;
614 aRet <<= TitleHelper::getTitle( TitleHelper::SUB_TITLE, m_spChart2ModelContact->getDocumentModel() ).is();
616 catch (const uno::Exception&)
618 DBG_UNHANDLED_EXCEPTION("chart2");
620 return aRet;
623 Any WrappedHasSubTitleProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
625 Any aRet;
626 aRet <<= false;
627 return aRet;
630 ChartDocumentWrapper::ChartDocumentWrapper(
631 const Reference< uno::XComponentContext > & xContext ) :
632 m_spChart2ModelContact( std::make_shared<Chart2ModelContact>( xContext ) ),
633 m_bUpdateAddIn( true ),
634 m_bIsDisposed( false )
638 ChartDocumentWrapper::~ChartDocumentWrapper()
640 stopAllComponentListening();
643 // ____ XInterface (for new interfaces) ____
644 // [-loplugin:unoaggregation]
645 uno::Any SAL_CALL ChartDocumentWrapper::queryInterface( const uno::Type& aType )
647 if( m_xDelegator.is())
648 // calls queryAggregation if the delegator doesn't know aType
649 return m_xDelegator->queryInterface( aType );
650 else
651 return queryAggregation( aType );
654 // ____ chart::XChartDocument (old API wrapper) ____
655 Reference< drawing::XShape > SAL_CALL ChartDocumentWrapper::getTitle()
657 if( !m_xTitle.is() )
659 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getDocumentModel() );
660 m_xTitle = new TitleWrapper( TitleHelper::MAIN_TITLE, m_spChart2ModelContact );
662 return m_xTitle;
665 Reference< drawing::XShape > SAL_CALL ChartDocumentWrapper::getSubTitle()
667 if( !m_xSubTitle.is() )
669 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getDocumentModel() );
670 m_xSubTitle = new TitleWrapper( TitleHelper::SUB_TITLE, m_spChart2ModelContact );
672 return m_xSubTitle;
675 Reference< drawing::XShape > SAL_CALL ChartDocumentWrapper::getLegend()
677 if( ! m_xLegend.is())
679 m_xLegend = new LegendWrapper( m_spChart2ModelContact );
682 return m_xLegend;
685 Reference< beans::XPropertySet > SAL_CALL ChartDocumentWrapper::getArea()
687 if( ! m_xArea.is())
689 m_xArea.set( new AreaWrapper( m_spChart2ModelContact ) );
692 return m_xArea;
695 Reference< XDiagram > SAL_CALL ChartDocumentWrapper::getDiagram()
697 if( !m_xDiagram.is() )
701 m_xDiagram = new DiagramWrapper( m_spChart2ModelContact );
703 catch (const uno::Exception&)
705 DBG_UNHANDLED_EXCEPTION("chart2");
709 return m_xDiagram;
712 void SAL_CALL ChartDocumentWrapper::setDiagram( const Reference< XDiagram >& _xDiagram )
714 if (!_xDiagram.is())
715 return;
716 auto xDiagram = dynamic_cast<DiagramWrapper*>(_xDiagram.get());
717 assert(xDiagram);
718 if( xDiagram != m_xDiagram )
720 // set new wrapped diagram at new chart. This requires the old
721 // diagram given as parameter to implement the new interface. If
722 // this is not possible throw an exception
723 rtl::Reference< ::chart::Diagram > xNewDia( xDiagram->getUnderlyingDiagram());
727 rtl::Reference< ChartModel > xChartDoc( m_spChart2ModelContact->getDocumentModel() );
728 if( xChartDoc.is() )
730 // set the new diagram
731 xChartDoc->setFirstDiagram( xNewDia );
732 m_xDiagram = xDiagram;
735 catch (const uno::Exception&)
737 DBG_UNHANDLED_EXCEPTION("chart2");
742 Reference< XChartData > SAL_CALL ChartDocumentWrapper::getData()
744 if( !m_xChartData.is() )
746 m_xChartData.set( new ChartDataWrapper( m_spChart2ModelContact ) );
748 //@todo: check hasInternalDataProvider also in else?
750 return m_xChartData;
753 void SAL_CALL ChartDocumentWrapper::attachData( const Reference< XChartData >& xNewData )
755 if( !xNewData.is() )
756 return;
758 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getDocumentModel() );
759 m_xChartData.set( new ChartDataWrapper( m_spChart2ModelContact, xNewData ) );
762 // ____ XModel ____
763 sal_Bool SAL_CALL ChartDocumentWrapper::attachResource(
764 const OUString& URL,
765 const Sequence< beans::PropertyValue >& Arguments )
767 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
768 if( xModel.is() )
769 return xModel->attachResource( URL, Arguments );
770 return false;
773 OUString SAL_CALL ChartDocumentWrapper::getURL()
775 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
776 if( xModel.is() )
777 return xModel->getURL();
778 return OUString();
781 Sequence< beans::PropertyValue > SAL_CALL ChartDocumentWrapper::getArgs()
783 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
784 if( xModel.is() )
785 return xModel->getArgs();
786 return Sequence< beans::PropertyValue >();
789 void SAL_CALL ChartDocumentWrapper::connectController( const Reference< frame::XController >& Controller )
791 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
792 if( xModel.is() )
793 xModel->connectController( Controller );
796 void SAL_CALL ChartDocumentWrapper::disconnectController(
797 const Reference< frame::XController >& Controller )
799 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
800 if( xModel.is() )
801 xModel->disconnectController( Controller );
804 void SAL_CALL ChartDocumentWrapper::lockControllers()
806 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
807 if( xModel.is() )
808 xModel->lockControllers();
811 void SAL_CALL ChartDocumentWrapper::unlockControllers()
813 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
814 if( xModel.is() )
815 xModel->unlockControllers();
818 sal_Bool SAL_CALL ChartDocumentWrapper::hasControllersLocked()
820 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
821 if( xModel.is() )
822 return xModel->hasControllersLocked();
823 return false;
826 Reference< frame::XController > SAL_CALL ChartDocumentWrapper::getCurrentController()
828 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
829 if( xModel.is() )
830 return xModel->getCurrentController();
831 return nullptr;
834 void SAL_CALL ChartDocumentWrapper::setCurrentController(
835 const Reference< frame::XController >& Controller )
837 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
838 if( xModel.is() )
839 xModel->setCurrentController( Controller );
842 Reference< uno::XInterface > SAL_CALL ChartDocumentWrapper::getCurrentSelection()
844 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
845 if( xModel.is() )
846 return xModel->getCurrentSelection();
847 return nullptr;
850 // ____ XComponent ____
851 void SAL_CALL ChartDocumentWrapper::dispose()
853 if( m_bIsDisposed )
854 return;
856 m_bIsDisposed = true;
860 Reference< lang::XComponent > xFormerDelegator( m_xDelegator, uno::UNO_QUERY );
861 if (m_xTitle)
863 m_xTitle->dispose();
864 m_xTitle.clear();
866 DisposeHelper::DisposeAndClear( m_xSubTitle );
867 DisposeHelper::DisposeAndClear( m_xLegend );
868 DisposeHelper::DisposeAndClear( m_xChartData );
869 DisposeHelper::DisposeAndClear( m_xDiagram );
870 DisposeHelper::DisposeAndClear( m_xArea );
871 m_xChartView.clear();
872 m_xShapeFactory.clear();
873 m_xDelegator.clear();
875 clearWrappedPropertySet();
876 m_spChart2ModelContact->clear();
877 impl_resetAddIn();
879 stopAllComponentListening();
883 if( xFormerDelegator.is())
884 xFormerDelegator->dispose();
886 catch (const lang::DisposedException&)
888 // this is ok, don't panic
891 catch (const uno::Exception &)
893 DBG_UNHANDLED_EXCEPTION("chart2");
897 void ChartDocumentWrapper::impl_resetAddIn()
899 Reference< util::XRefreshable > xAddIn( m_xAddIn );
900 m_xAddIn.clear();
902 if( !xAddIn.is() )
903 return;
907 //make sure that the add-in does not hold a references to us anymore:
908 Reference< lang::XComponent > xComp( xAddIn, uno::UNO_QUERY );
909 if( xComp.is())
910 xComp->dispose();
911 else
913 uno::Reference< lang::XInitialization > xInit( xAddIn, uno::UNO_QUERY );
914 if( xInit.is() )
916 uno::Any aParam;
917 uno::Reference< css::chart::XChartDocument > xDoc;
918 aParam <<= xDoc;
919 uno::Sequence< uno::Any > aSeq( &aParam, 1 );
920 xInit->initialize( aSeq );
924 catch (const uno::RuntimeException&)
926 DBG_UNHANDLED_EXCEPTION("chart2");
928 catch (const uno::Exception&)
930 DBG_UNHANDLED_EXCEPTION("chart2");
934 void ChartDocumentWrapper::setBaseDiagram( const OUString& rBaseDiagram )
936 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getDocumentModel() );
937 m_aBaseDiagram = rBaseDiagram;
939 uno::Reference< XDiagram > xDiagram( ChartDocumentWrapper::createInstance( rBaseDiagram ), uno::UNO_QUERY );
940 if( xDiagram.is() )
941 setDiagram( xDiagram );
944 void ChartDocumentWrapper::setAddIn( const Reference< util::XRefreshable >& xAddIn )
946 if( m_xAddIn == xAddIn )
947 return;
949 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getDocumentModel() );
950 impl_resetAddIn();
951 m_xAddIn = xAddIn;
952 // initialize AddIn with this as chart document
953 uno::Reference< lang::XInitialization > xInit( m_xAddIn, uno::UNO_QUERY );
954 if( xInit.is() )
956 uno::Any aParam;
957 uno::Reference< XChartDocument > xDoc(this);
958 aParam <<= xDoc;
959 uno::Sequence< uno::Any > aSeq( &aParam, 1 );
960 xInit->initialize( aSeq );
964 void ChartDocumentWrapper::setUpdateAddIn( bool bUpdateAddIn )
966 m_bUpdateAddIn = bUpdateAddIn;
969 Reference< drawing::XShapes > ChartDocumentWrapper::getAdditionalShapes() const
971 // get additional non-chart shapes for XML export
972 uno::Reference< drawing::XShapes > xFoundShapes;
973 rtl::Reference<SvxDrawPage> xDrawPage( impl_getDrawPage() );
975 if( !xDrawPage.is() )
976 return xFoundShapes;
978 uno::Reference<drawing::XShapes> xChartRoot( DrawModelWrapper::getChartRootShape( xDrawPage ) );
980 // iterate 'flat' over all top-level objects
981 // and determine all that are no chart objects
982 std::vector< uno::Reference< drawing::XShape > > aShapeVector;
983 sal_Int32 nSubCount = xDrawPage->getCount();
984 uno::Reference< drawing::XShape > xShape;
985 for( sal_Int32 nS = 0; nS < nSubCount; nS++ )
987 if( xDrawPage->getByIndex( nS ) >>= xShape )
989 if( xShape.is() && xChartRoot!=xShape )
990 aShapeVector.push_back( xShape );
994 if( !aShapeVector.empty() )
996 // create a shape collection
997 xFoundShapes = drawing::ShapeCollection::create(
998 comphelper::getProcessComponentContext());
1000 OSL_ENSURE( xFoundShapes.is(), "Couldn't create a shape collection!" );
1001 if( xFoundShapes.is())
1003 for (auto const& shape : aShapeVector)
1004 xFoundShapes->add(shape);
1008 return xFoundShapes;
1011 void SAL_CALL ChartDocumentWrapper::addEventListener( const Reference< lang::XEventListener >& xListener )
1013 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
1014 if( xModel.is() )
1015 xModel->addEventListener( xListener );
1018 void SAL_CALL ChartDocumentWrapper::removeEventListener( const Reference< lang::XEventListener >& aListener )
1020 rtl::Reference< ChartModel > xModel( m_spChart2ModelContact->getDocumentModel() );
1021 if( xModel.is() )
1022 xModel->removeEventListener( aListener );
1025 // ____ XDrawPageSupplier ____
1026 uno::Reference< drawing::XDrawPage > SAL_CALL ChartDocumentWrapper::getDrawPage()
1028 return impl_getDrawPage();
1031 rtl::Reference<SvxDrawPage> ChartDocumentWrapper::impl_getDrawPage() const
1033 return m_spChart2ModelContact->getDrawPage();
1036 namespace {
1038 uno::Reference< lang::XMultiServiceFactory > getShapeFactory(const rtl::Reference<ChartView>& xChartView)
1040 if( xChartView )
1041 return xChartView->getDrawModelWrapper()->getShapeFactory();
1043 return uno::Reference< lang::XMultiServiceFactory >();
1048 // ____ XMultiServiceFactory ____
1049 uno::Reference< uno::XInterface > SAL_CALL ChartDocumentWrapper::createInstance(
1050 const OUString& aServiceSpecifier )
1052 uno::Reference< uno::XInterface > xResult;
1054 rtl::Reference< ChartModel > xChartDoc( m_spChart2ModelContact->getDocumentModel() );
1055 if( !xChartDoc.is() )
1056 return xResult;
1058 bool bServiceFound = false;
1059 tServiceNameMap & rMap = lcl_getStaticServiceNameMap();
1061 tServiceNameMap::const_iterator aIt( rMap.find( aServiceSpecifier ));
1062 if( aIt != rMap.end())
1064 bool bCreateDiagram = false;
1065 rtl::Reference< ::chart::ChartTypeManager > xChartTypeManager =
1066 xChartDoc->getTypeManager();
1067 rtl::Reference< ::chart::ChartTypeTemplate > xTemplate;
1069 switch( (*aIt).second )
1071 case SERVICE_NAME_AREA_DIAGRAM:
1072 if( xChartTypeManager.is())
1074 xTemplate =
1075 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.Area"_ustr);
1076 bCreateDiagram = true;
1078 break;
1079 case SERVICE_NAME_BAR_DIAGRAM:
1080 if( xChartTypeManager.is())
1082 // this is for bar and column (the latter is the default if
1083 // no "Vertical=false" property was set)
1084 xTemplate =
1085 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.Column"_ustr);
1086 bCreateDiagram = true;
1088 break;
1089 case SERVICE_NAME_DONUT_DIAGRAM:
1090 if( xChartTypeManager.is())
1092 xTemplate =
1093 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.Donut"_ustr);
1094 bCreateDiagram = true;
1096 break;
1097 case SERVICE_NAME_LINE_DIAGRAM:
1098 if( xChartTypeManager.is())
1100 xTemplate =
1101 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.Line"_ustr);
1102 bCreateDiagram = true;
1104 break;
1105 case SERVICE_NAME_NET_DIAGRAM:
1106 if( xChartTypeManager.is())
1108 xTemplate =
1109 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.Net"_ustr);
1110 bCreateDiagram = true;
1112 break;
1113 case SERVICE_NAME_FILLED_NET_DIAGRAM:
1114 if( xChartTypeManager.is())
1116 xTemplate =
1117 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.FilledNet"_ustr);
1118 bCreateDiagram = true;
1120 break;
1121 case SERVICE_NAME_PIE_DIAGRAM:
1122 if( xChartTypeManager.is())
1124 xTemplate =
1125 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.Pie"_ustr);
1126 bCreateDiagram = true;
1128 break;
1129 case SERVICE_NAME_STOCK_DIAGRAM:
1130 if( xChartTypeManager.is())
1132 xTemplate =
1133 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.StockLowHighClose"_ustr);
1134 bCreateDiagram = true;
1136 break;
1137 case SERVICE_NAME_XY_DIAGRAM:
1138 if( xChartTypeManager.is())
1140 xTemplate =
1141 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.ScatterLineSymbol"_ustr);
1142 bCreateDiagram = true;
1144 break;
1146 case SERVICE_NAME_BUBBLE_DIAGRAM:
1147 if( xChartTypeManager.is())
1149 xTemplate =
1150 xChartTypeManager->createTemplate(u"com.sun.star.chart2.template.Bubble"_ustr);
1151 bCreateDiagram = true;
1153 break;
1155 case SERVICE_NAME_DASH_TABLE:
1156 case SERVICE_NAME_GRADIENT_TABLE:
1157 case SERVICE_NAME_HATCH_TABLE:
1158 case SERVICE_NAME_BITMAP_TABLE:
1159 case SERVICE_NAME_TRANSP_GRADIENT_TABLE:
1160 case SERVICE_NAME_MARKER_TABLE:
1161 xResult.set( xChartDoc->createInstance( aIt->first ), uno::UNO_QUERY );
1162 break;
1164 case SERVICE_NAME_NAMESPACE_MAP:
1165 break;
1166 case SERVICE_NAME_EXPORT_GRAPHIC_STORAGE_RESOLVER:
1167 break;
1168 case SERVICE_NAME_IMPORT_GRAPHIC_STORAGE_RESOLVER:
1169 break;
1172 if( bCreateDiagram && xTemplate.is() )
1176 uno::Reference< chart2::XDiagram > xDia( xChartDoc->getFirstDiagram());
1177 if( xDia.is())
1179 // locked controllers
1180 ControllerLockGuardUNO aCtrlLockGuard( xChartDoc );
1181 rtl::Reference< Diagram > xDiagram = xChartDoc->getFirstChartDiagram();
1182 ThreeDLookScheme e3DScheme = xDiagram->detectScheme();
1183 rtl::Reference< ::chart::ChartTypeManager > xTemplateManager = xChartDoc->getTypeManager();
1184 Diagram::tTemplateWithServiceName aTemplateWithService(
1185 xDiagram->getTemplate( xTemplateManager ));
1186 if( aTemplateWithService.xChartTypeTemplate.is())
1187 aTemplateWithService.xChartTypeTemplate->resetStyles2( xDiagram );//#i109371#
1188 xTemplate->changeDiagram( xDiagram );
1189 if( AllSettings::GetMathLayoutRTL() )
1190 AxisHelper::setRTLAxisLayout( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 ) );
1191 xDiagram->setScheme( e3DScheme );
1193 else
1195 // locked controllers
1196 ControllerLockGuardUNO aCtrlLockGuard( xChartDoc );
1197 xDia.set( xTemplate->createDiagramByDataSource(
1198 uno::Reference< chart2::data::XDataSource >(),
1199 uno::Sequence< beans::PropertyValue >()));
1200 xChartDoc->setFirstDiagram( xDia );
1203 xResult = static_cast< ::cppu::OWeakObject* >( new DiagramWrapper( m_spChart2ModelContact ));
1205 catch (const uno::Exception&)
1207 DBG_UNHANDLED_EXCEPTION("chart2");
1211 bServiceFound = true;
1213 else if( aServiceSpecifier == "com.sun.star.comp.chart2.DataSeriesWrapper" )
1215 Reference< beans::XPropertySet > xDataSeries( new DataSeriesPointWrapper( m_spChart2ModelContact ) );
1216 xResult.set( xDataSeries );
1217 bServiceFound = true;
1219 else if( aServiceSpecifier == CHART_VIEW_SERVICE_NAME )
1221 if( !m_xChartView.is() )
1223 rtl::Reference<::chart::ChartModel> pChartModel = new ::chart::ChartModel(m_spChart2ModelContact->m_xContext);
1224 rtl::Reference<ChartView> xChartView = new ::chart::ChartView(m_spChart2ModelContact->m_xContext, *pChartModel);
1228 m_xChartView = xChartView;
1230 Sequence< Any > aArguments{ Any(Reference<frame::XModel>(this)),
1231 Any(true) }; // bRefreshAddIn
1232 xChartView->initialize(aArguments);
1234 catch (const uno::Exception&)
1236 DBG_UNHANDLED_EXCEPTION("chart2");
1239 xResult.set( static_cast<cppu::OWeakObject*>(m_xChartView.get()) );
1240 bServiceFound = true;
1242 else
1244 // try to create a shape
1247 if( !m_xShapeFactory.is() && m_xChartView.is() )
1249 m_xShapeFactory = getShapeFactory( m_xChartView );
1251 else
1253 rtl::Reference<ChartModel> pModel = m_spChart2ModelContact->getDocumentModel();
1254 if(pModel)
1256 m_xChartView = pModel->getChartView();
1257 m_xShapeFactory = getShapeFactory( m_xChartView );
1261 if( m_xShapeFactory.is() )
1263 xResult = m_xShapeFactory->createInstance( aServiceSpecifier );
1264 bServiceFound = true;
1267 catch (const uno::Exception&)
1269 // couldn't create shape
1273 // finally, try to create an addin
1274 if( !bServiceFound )
1278 Reference< lang::XMultiServiceFactory > xFact(
1279 m_spChart2ModelContact->m_xContext->getServiceManager(), uno::UNO_QUERY_THROW );
1280 uno::Reference< util::XRefreshable > xAddIn(
1281 xFact->createInstance( aServiceSpecifier ), uno::UNO_QUERY );
1282 if( xAddIn.is() )
1284 xResult = xAddIn;
1287 catch (const uno::Exception&)
1289 // couldn't create service
1293 return xResult;
1296 uno::Reference< uno::XInterface > SAL_CALL ChartDocumentWrapper::createInstanceWithArguments(
1297 const OUString& ServiceSpecifier,
1298 const uno::Sequence< uno::Any >& Arguments )
1300 OSL_ENSURE( Arguments.hasElements(), "createInstanceWithArguments: Warning: Arguments are ignored" );
1302 return createInstance( ServiceSpecifier );
1305 uno::Sequence< OUString > SAL_CALL ChartDocumentWrapper::getAvailableServiceNames()
1307 return comphelper::mapKeysToSequence( lcl_getStaticServiceNameMap() );
1310 // ____ XAggregation ____
1311 void SAL_CALL ChartDocumentWrapper::setDelegator(
1312 const uno::Reference< uno::XInterface >& rDelegator )
1314 if( m_bIsDisposed )
1316 if( rDelegator.is() )
1317 throw lang::DisposedException(u"ChartDocumentWrapper is disposed"_ustr,
1318 static_cast< ::cppu::OWeakObject* >( this ));
1319 return;
1322 if( rDelegator.is())
1324 m_xDelegator = rDelegator;
1325 ChartModel* pChartModel = dynamic_cast<ChartModel*>(rDelegator.get());
1326 assert(pChartModel);
1327 m_spChart2ModelContact->setDocumentModel( pChartModel );
1329 else
1331 // this is a sort of dispose() from the new model,so release resources here
1334 dispose();
1336 catch (const uno::Exception&)
1338 DBG_UNHANDLED_EXCEPTION("chart2");
1343 uno::Any SAL_CALL ChartDocumentWrapper::queryAggregation( const uno::Type& rType )
1345 return ChartDocumentWrapper_Base::queryInterface( rType );
1348 // ____ ::utl::OEventListenerAdapter ____
1349 void ChartDocumentWrapper::_disposing( const lang::EventObject& rSource )
1351 if( rSource.Source == cppu::getXWeak(m_xTitle.get()) )
1352 m_xTitle.clear();
1353 else if( rSource.Source == cppu::getXWeak(m_xSubTitle.get()) )
1354 m_xSubTitle.clear();
1355 else if( rSource.Source == cppu::getXWeak(m_xLegend.get()) )
1356 m_xLegend.clear();
1357 else if( rSource.Source == m_xChartData )
1358 m_xChartData.clear();
1359 else if( rSource.Source == cppu::getXWeak(m_xDiagram.get()) )
1360 m_xDiagram.clear();
1361 else if( rSource.Source == m_xArea )
1362 m_xArea.clear();
1363 else if( rSource.Source == m_xAddIn )
1364 m_xAddIn.clear();
1365 else if( rSource.Source == static_cast<cppu::OWeakObject*>(m_xChartView.get()) )
1366 m_xChartView.clear();
1369 // ____ XPropertySet ____
1370 void SAL_CALL ChartDocumentWrapper::setPropertyValue(const OUString& rPropertyName, const css::uno::Any& rValue)
1372 if (rPropertyName == u"ODFImport_UpdateView")
1374 // A hack used at load time to notify the view that it needs an update
1375 // See SchXMLImport::~SchXMLImport
1376 if (auto xChartModel = rValue.query<css::chart2::XChartDocument>())
1377 ChartViewHelper::setViewToDirtyState_UNO(xChartModel);
1378 return;
1380 ChartDocumentWrapper_Base::setPropertyValue(rPropertyName, rValue);
1383 // WrappedPropertySet
1384 Reference< beans::XPropertySet > ChartDocumentWrapper::getInnerPropertySet()
1386 return nullptr;
1388 const Sequence< beans::Property >& ChartDocumentWrapper::getPropertySequence()
1390 return StaticChartDocumentWrapperPropertyArray();
1393 std::vector< std::unique_ptr<WrappedProperty> > ChartDocumentWrapper::createWrappedProperties()
1395 std::vector< std::unique_ptr<WrappedProperty> > aWrappedProperties;
1396 aWrappedProperties.emplace_back( new WrappedDataSourceLabelsInFirstRowProperty( m_spChart2ModelContact ) );
1397 aWrappedProperties.emplace_back( new WrappedDataSourceLabelsInFirstColumnProperty( m_spChart2ModelContact ) );
1398 aWrappedProperties.emplace_back( new WrappedHasLegendProperty( m_spChart2ModelContact ) );
1399 aWrappedProperties.emplace_back( new WrappedHasMainTitleProperty( m_spChart2ModelContact ) );
1400 aWrappedProperties.emplace_back( new WrappedHasSubTitleProperty( m_spChart2ModelContact ) );
1401 aWrappedProperties.emplace_back( new WrappedAddInProperty( *this ) );
1402 aWrappedProperties.emplace_back( new WrappedBaseDiagramProperty( *this ) );
1403 aWrappedProperties.emplace_back( new WrappedAdditionalShapesProperty( *this ) );
1404 aWrappedProperties.emplace_back( new WrappedRefreshAddInAllowedProperty( *this ) );
1405 aWrappedProperties.emplace_back( new WrappedIgnoreProperty(u"NullDate"_ustr,Any() ) ); // i99104
1406 aWrappedProperties.emplace_back( new WrappedIgnoreProperty(u"EnableComplexChartTypes"_ustr, uno::Any(true) ) );
1407 aWrappedProperties.emplace_back( new WrappedIgnoreProperty(u"EnableDataTableDialog"_ustr, uno::Any(true) ) );
1409 return aWrappedProperties;
1412 OUString SAL_CALL ChartDocumentWrapper::getImplementationName()
1414 return CHART_CHARTAPIWRAPPER_IMPLEMENTATION_NAME;
1417 sal_Bool SAL_CALL ChartDocumentWrapper::supportsService( const OUString& rServiceName )
1419 return cppu::supportsService(this, rServiceName);
1422 css::uno::Sequence< OUString > SAL_CALL ChartDocumentWrapper::getSupportedServiceNames()
1424 return {
1425 u"com.sun.star.chart.ChartDocument"_ustr,
1426 CHART_CHARTAPIWRAPPER_SERVICE_NAME,
1427 u"com.sun.star.xml.UserDefinedAttributesSupplier"_ustr,
1428 u"com.sun.star.beans.PropertySet"_ustr
1432 } // namespace chart::wrapper
1434 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1435 com_sun_star_comp_chart2_ChartDocumentWrapper_get_implementation(css::uno::XComponentContext *context,
1436 css::uno::Sequence<css::uno::Any> const &)
1438 return cppu::acquire(new ::chart::wrapper::ChartDocumentWrapper(context));
1441 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */