Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / ChartDocumentWrapper.cxx
blob406df92db13a2407fb8e40748df6f5cd2d66042c
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 <servicenames.hxx>
22 #include <PropertyHelper.hxx>
23 #include <TitleHelper.hxx>
24 #include <LegendHelper.hxx>
25 #include <ControllerLockGuard.hxx>
26 #include <DisposeHelper.hxx>
27 #include "DataSeriesPointWrapper.hxx"
28 #include <chartview/ExplicitValueProvider.hxx>
29 #include <chartview/DrawModelWrapper.hxx>
30 #include "Chart2ModelContact.hxx"
32 #include <ChartModel.hxx>
34 #include <DiagramHelper.hxx>
35 #include <DataSourceHelper.hxx>
36 #include <ChartModelHelper.hxx>
37 #include <AxisHelper.hxx>
38 #include <ThreeDHelper.hxx>
40 #include "TitleWrapper.hxx"
41 #include "ChartDataWrapper.hxx"
42 #include "DiagramWrapper.hxx"
43 #include "LegendWrapper.hxx"
44 #include "AreaWrapper.hxx"
45 #include "WrappedAddInProperty.hxx"
46 #include <WrappedIgnoreProperty.hxx>
47 #include <cppuhelper/supportsservice.hxx>
48 #include <comphelper/processfactory.hxx>
49 #include <comphelper/sequence.hxx>
50 #include <comphelper/servicehelper.hxx>
51 #include <vcl/settings.hxx>
53 #include <com/sun/star/drawing/ShapeCollection.hpp>
54 #include <com/sun/star/beans/PropertyAttribute.hpp>
55 #include <com/sun/star/lang/DisposedException.hpp>
56 #include <com/sun/star/lang/XInitialization.hpp>
57 #include <com/sun/star/util/XRefreshable.hpp>
58 #include <tools/diagnose_ex.h>
60 #include <vector>
61 #include <algorithm>
62 #include <map>
64 using namespace ::com::sun::star;
65 using namespace ::com::sun::star::chart;
67 using ::com::sun::star::uno::Any;
68 using ::com::sun::star::uno::UNO_QUERY_THROW;
69 using ::com::sun::star::uno::Reference;
70 using ::com::sun::star::uno::Sequence;
71 using ::com::sun::star::beans::Property;
73 namespace
75 enum eServiceType
77 SERVICE_NAME_AREA_DIAGRAM = 0,
78 SERVICE_NAME_BAR_DIAGRAM,
79 SERVICE_NAME_DONUT_DIAGRAM,
80 SERVICE_NAME_LINE_DIAGRAM,
81 SERVICE_NAME_NET_DIAGRAM,
82 SERVICE_NAME_FILLED_NET_DIAGRAM,
83 SERVICE_NAME_PIE_DIAGRAM,
84 SERVICE_NAME_STOCK_DIAGRAM,
85 SERVICE_NAME_XY_DIAGRAM,
86 SERVICE_NAME_BUBBLE_DIAGRAM,
88 SERVICE_NAME_DASH_TABLE,
89 SERVICE_NAME_GARDIENT_TABLE,
90 SERVICE_NAME_HATCH_TABLE,
91 SERVICE_NAME_BITMAP_TABLE,
92 SERVICE_NAME_TRANSP_GRADIENT_TABLE,
93 SERVICE_NAME_MARKER_TABLE,
95 SERVICE_NAME_NAMESPACE_MAP,
96 SERVICE_NAME_EXPORT_GRAPHIC_STORAGE_RESOLVER,
97 SERVICE_NAME_IMPORT_GRAPHIC_STORAGE_RESOLVER
100 typedef std::map< OUString, enum eServiceType > tServiceNameMap;
102 tServiceNameMap & lcl_getStaticServiceNameMap()
104 static tServiceNameMap aServiceNameMap {
105 {"com.sun.star.chart.AreaDiagram", SERVICE_NAME_AREA_DIAGRAM},
106 {"com.sun.star.chart.BarDiagram", SERVICE_NAME_BAR_DIAGRAM},
107 {"com.sun.star.chart.DonutDiagram", SERVICE_NAME_DONUT_DIAGRAM},
108 {"com.sun.star.chart.LineDiagram", SERVICE_NAME_LINE_DIAGRAM},
109 {"com.sun.star.chart.NetDiagram", SERVICE_NAME_NET_DIAGRAM},
110 {"com.sun.star.chart.FilledNetDiagram", SERVICE_NAME_FILLED_NET_DIAGRAM},
111 {"com.sun.star.chart.PieDiagram", SERVICE_NAME_PIE_DIAGRAM},
112 {"com.sun.star.chart.StockDiagram", SERVICE_NAME_STOCK_DIAGRAM},
113 {"com.sun.star.chart.XYDiagram", SERVICE_NAME_XY_DIAGRAM},
114 {"com.sun.star.chart.BubbleDiagram", SERVICE_NAME_BUBBLE_DIAGRAM},
116 {"com.sun.star.drawing.DashTable", SERVICE_NAME_DASH_TABLE},
117 {"com.sun.star.drawing.GradientTable", SERVICE_NAME_GARDIENT_TABLE},
118 {"com.sun.star.drawing.HatchTable", SERVICE_NAME_HATCH_TABLE},
119 {"com.sun.star.drawing.BitmapTable", SERVICE_NAME_BITMAP_TABLE},
120 {"com.sun.star.drawing.TransparencyGradientTable", SERVICE_NAME_TRANSP_GRADIENT_TABLE},
121 {"com.sun.star.drawing.MarkerTable", SERVICE_NAME_MARKER_TABLE},
123 {"com.sun.star.xml.NamespaceMap", SERVICE_NAME_NAMESPACE_MAP},
124 {"com.sun.star.document.ExportGraphicStoreageHandler", SERVICE_NAME_EXPORT_GRAPHIC_STORAGE_RESOLVER},
125 {"com.sun.star.document.ImportGraphicStoreageHandler", SERVICE_NAME_IMPORT_GRAPHIC_STORAGE_RESOLVER}
128 return aServiceNameMap;
131 enum
133 PROP_DOCUMENT_HAS_MAIN_TITLE,
134 PROP_DOCUMENT_HAS_SUB_TITLE,
135 PROP_DOCUMENT_HAS_LEGEND,
136 PROP_DOCUMENT_LABELS_IN_FIRST_ROW,
137 PROP_DOCUMENT_LABELS_IN_FIRST_COLUMN,
138 PROP_DOCUMENT_ADDIN,
139 PROP_DOCUMENT_BASEDIAGRAM,
140 PROP_DOCUMENT_ADDITIONAL_SHAPES,
141 PROP_DOCUMENT_UPDATE_ADDIN,
142 PROP_DOCUMENT_NULL_DATE,
143 PROP_DOCUMENT_ENABLE_COMPLEX_CHARTTYPES,
144 PROP_DOCUMENT_ENABLE_DATATABLE_DIALOG
147 void lcl_AddPropertiesToVector(
148 std::vector< Property > & rOutProperties )
150 rOutProperties.emplace_back( "HasMainTitle",
151 PROP_DOCUMENT_HAS_MAIN_TITLE,
152 cppu::UnoType<bool>::get(),
153 //#i111967# no PropertyChangeEvent is fired on change so far
154 beans::PropertyAttribute::MAYBEDEFAULT );
155 rOutProperties.emplace_back( "HasSubTitle",
156 PROP_DOCUMENT_HAS_SUB_TITLE,
157 cppu::UnoType<bool>::get(),
158 //#i111967# no PropertyChangeEvent is fired on change so far
159 beans::PropertyAttribute::MAYBEDEFAULT );
160 rOutProperties.emplace_back( "HasLegend",
161 PROP_DOCUMENT_HAS_LEGEND,
162 cppu::UnoType<bool>::get(),
163 //#i111967# no PropertyChangeEvent is fired on change so far
164 beans::PropertyAttribute::MAYBEDEFAULT );
166 // really needed?
167 rOutProperties.emplace_back( "DataSourceLabelsInFirstRow",
168 PROP_DOCUMENT_LABELS_IN_FIRST_ROW,
169 cppu::UnoType<bool>::get(),
170 beans::PropertyAttribute::BOUND
171 | beans::PropertyAttribute::MAYBEDEFAULT );
172 rOutProperties.emplace_back( "DataSourceLabelsInFirstColumn",
173 PROP_DOCUMENT_LABELS_IN_FIRST_COLUMN,
174 cppu::UnoType<bool>::get(),
175 //#i111967# no PropertyChangeEvent is fired on change so far
176 beans::PropertyAttribute::MAYBEDEFAULT );
178 //add-in
179 rOutProperties.emplace_back( "AddIn",
180 PROP_DOCUMENT_ADDIN,
181 cppu::UnoType<util::XRefreshable>::get(),
182 beans::PropertyAttribute::BOUND
183 | beans::PropertyAttribute::MAYBEVOID );
184 rOutProperties.emplace_back( "BaseDiagram",
185 PROP_DOCUMENT_BASEDIAGRAM,
186 cppu::UnoType<OUString>::get(),
187 beans::PropertyAttribute::BOUND
188 | beans::PropertyAttribute::MAYBEVOID );
189 rOutProperties.emplace_back( "AdditionalShapes",
190 PROP_DOCUMENT_ADDITIONAL_SHAPES,
191 cppu::UnoType<drawing::XShapes>::get(),
192 beans::PropertyAttribute::BOUND
193 | beans::PropertyAttribute::MAYBEVOID
194 | beans::PropertyAttribute::READONLY );
195 rOutProperties.emplace_back( "RefreshAddInAllowed",
196 PROP_DOCUMENT_UPDATE_ADDIN,
197 cppu::UnoType<bool>::get(),
198 //#i111967# no PropertyChangeEvent is fired on change so far
199 beans::PropertyAttribute::TRANSIENT );
201 // table:null-date // i99104
202 rOutProperties.emplace_back( "NullDate",
203 PROP_DOCUMENT_NULL_DATE,
204 ::cppu::UnoType<css::util::DateTime>::get(),
205 beans::PropertyAttribute::MAYBEVOID );
207 rOutProperties.emplace_back( "EnableComplexChartTypes",
208 PROP_DOCUMENT_ENABLE_COMPLEX_CHARTTYPES,
209 cppu::UnoType<bool>::get(),
210 //#i112666# no PropertyChangeEvent is fired on change so far
211 beans::PropertyAttribute::MAYBEDEFAULT );
212 rOutProperties.emplace_back( "EnableDataTableDialog",
213 PROP_DOCUMENT_ENABLE_DATATABLE_DIALOG,
214 cppu::UnoType<bool>::get(),
215 //#i112666# no PropertyChangeEvent is fired on change so far
216 beans::PropertyAttribute::MAYBEDEFAULT );
219 struct StaticChartDocumentWrapperPropertyArray_Initializer
221 Sequence< Property >* operator()()
223 static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
224 return &aPropSeq;
227 private:
228 static uno::Sequence< Property > lcl_GetPropertySequence()
230 std::vector< css::beans::Property > aProperties;
231 lcl_AddPropertiesToVector( aProperties );
233 std::sort( aProperties.begin(), aProperties.end(),
234 ::chart::PropertyNameLess() );
236 return comphelper::containerToSequence( aProperties );
240 struct StaticChartDocumentWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticChartDocumentWrapperPropertyArray_Initializer >
244 } // anonymous namespace
246 namespace chart
248 namespace wrapper
251 //PROP_DOCUMENT_LABELS_IN_FIRST_ROW
252 class WrappedDataSourceLabelsInFirstRowProperty : public WrappedProperty
254 public:
255 explicit WrappedDataSourceLabelsInFirstRowProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact);
257 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
259 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
261 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
263 private: //member
264 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
265 mutable Any m_aOuterValue;
268 WrappedDataSourceLabelsInFirstRowProperty::WrappedDataSourceLabelsInFirstRowProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact)
269 : WrappedProperty("DataSourceLabelsInFirstRow",OUString())
270 , m_spChart2ModelContact( spChart2ModelContact )
271 , m_aOuterValue()
273 m_aOuterValue = WrappedDataSourceLabelsInFirstRowProperty::getPropertyDefault( nullptr );
276 void WrappedDataSourceLabelsInFirstRowProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
278 bool bLabelsInFirstRow = true;
279 if( ! (rOuterValue >>= bLabelsInFirstRow) )
280 throw lang::IllegalArgumentException("Property DataSourceLabelsInFirstRow requires value of type boolean", nullptr, 0 );
282 m_aOuterValue = rOuterValue;
283 bool bNewValue = bLabelsInFirstRow;
285 OUString aRangeString;
286 bool bUseColumns = true;
287 bool bFirstCellAsLabel = true;
288 bool bHasCategories = true;
289 uno::Sequence< sal_Int32 > aSequenceMapping;
291 if( DataSourceHelper::detectRangeSegmentation(
292 m_spChart2ModelContact->getChartModel(), aRangeString, aSequenceMapping, bUseColumns
293 , bFirstCellAsLabel, bHasCategories ) )
295 if( bUseColumns && bNewValue != bFirstCellAsLabel )
297 DataSourceHelper::setRangeSegmentation(
298 m_spChart2ModelContact->getChartModel(), aSequenceMapping, bUseColumns ,bNewValue, bHasCategories );
300 else if( !bUseColumns && bNewValue != bHasCategories )
302 DataSourceHelper::setRangeSegmentation(
303 m_spChart2ModelContact->getChartModel(), aSequenceMapping, bUseColumns , bFirstCellAsLabel, bNewValue );
308 Any WrappedDataSourceLabelsInFirstRowProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
310 OUString aRangeString;
311 bool bUseColumns = true;
312 bool bFirstCellAsLabel = true;
313 bool bHasCategories = true;
314 uno::Sequence< sal_Int32 > aSequenceMapping;
316 if( DataSourceHelper::detectRangeSegmentation(
317 m_spChart2ModelContact->getChartModel(), aRangeString, aSequenceMapping, bUseColumns
318 , bFirstCellAsLabel, bHasCategories ) )
320 bool bLabelsInFirstRow = true;
321 if( bUseColumns )
322 bLabelsInFirstRow = bFirstCellAsLabel;
323 else
324 bLabelsInFirstRow = bHasCategories;
326 m_aOuterValue <<= bLabelsInFirstRow;
328 return m_aOuterValue;
331 Any WrappedDataSourceLabelsInFirstRowProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
333 Any aRet;
334 aRet <<= true;
335 return aRet;
338 //PROP_DOCUMENT_LABELS_IN_FIRST_COLUMN
339 class WrappedDataSourceLabelsInFirstColumnProperty : public WrappedProperty
341 public:
342 explicit WrappedDataSourceLabelsInFirstColumnProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact);
344 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
346 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
348 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
350 private: //member
351 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
352 mutable Any m_aOuterValue;
355 WrappedDataSourceLabelsInFirstColumnProperty::WrappedDataSourceLabelsInFirstColumnProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact)
356 : WrappedProperty("DataSourceLabelsInFirstColumn",OUString())
357 , m_spChart2ModelContact( spChart2ModelContact )
358 , m_aOuterValue()
360 m_aOuterValue = WrappedDataSourceLabelsInFirstColumnProperty::getPropertyDefault( nullptr );
363 void WrappedDataSourceLabelsInFirstColumnProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
365 bool bLabelsInFirstRow = true;
366 if( ! (rOuterValue >>= bLabelsInFirstRow) )
367 throw lang::IllegalArgumentException("Property DataSourceLabelsInFirstRow requires value of type boolean", nullptr, 0 );
369 m_aOuterValue = rOuterValue;
370 bool bNewValue = bLabelsInFirstRow;
372 OUString aRangeString;
373 bool bUseColumns = true;
374 bool bFirstCellAsLabel = true;
375 bool bHasCategories = true;
376 uno::Sequence< sal_Int32 > aSequenceMapping;
378 if( DataSourceHelper::detectRangeSegmentation(
379 m_spChart2ModelContact->getChartModel(), aRangeString, aSequenceMapping, bUseColumns
380 , bFirstCellAsLabel, bHasCategories ) )
382 if( bUseColumns && bNewValue != bHasCategories )
384 DataSourceHelper::setRangeSegmentation(
385 m_spChart2ModelContact->getChartModel(), aSequenceMapping, bUseColumns, bFirstCellAsLabel, bNewValue );
387 else if( !bUseColumns && bNewValue != bFirstCellAsLabel )
389 DataSourceHelper::setRangeSegmentation(
390 m_spChart2ModelContact->getChartModel(), aSequenceMapping, bUseColumns , bNewValue, bHasCategories );
395 Any WrappedDataSourceLabelsInFirstColumnProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
397 OUString aRangeString;
398 bool bUseColumns = true;
399 bool bFirstCellAsLabel = true;
400 bool bHasCategories = true;
401 uno::Sequence< sal_Int32 > aSequenceMapping;
403 if( DataSourceHelper::detectRangeSegmentation(
404 m_spChart2ModelContact->getChartModel(), aRangeString, aSequenceMapping, bUseColumns
405 , bFirstCellAsLabel, bHasCategories ) )
407 bool bLabelsInFirstColumn = true;
408 if( bUseColumns )
409 bLabelsInFirstColumn = bHasCategories;
410 else
411 bLabelsInFirstColumn = bFirstCellAsLabel;
413 m_aOuterValue <<= bLabelsInFirstColumn;
415 return m_aOuterValue;
418 Any WrappedDataSourceLabelsInFirstColumnProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
420 Any aRet;
421 aRet <<= true;
422 return aRet;
425 //PROP_DOCUMENT_HAS_LEGEND
426 class WrappedHasLegendProperty : public WrappedProperty
428 public:
429 explicit WrappedHasLegendProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact);
431 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
433 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
435 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
437 private: //member
438 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
441 WrappedHasLegendProperty::WrappedHasLegendProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact)
442 : WrappedProperty("HasLegend",OUString())
443 , m_spChart2ModelContact( spChart2ModelContact )
447 void WrappedHasLegendProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
449 bool bNewValue = true;
450 if( ! (rOuterValue >>= bNewValue) )
451 throw lang::IllegalArgumentException("Property HasLegend requires value of type boolean", nullptr, 0 );
455 Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( *m_spChart2ModelContact->getModel(), m_spChart2ModelContact->m_xContext,bNewValue ));
456 if(xLegend.is())
458 Reference< beans::XPropertySet > xLegendProp( xLegend, uno::UNO_QUERY_THROW );
459 bool bOldValue = true;
460 Any aAOld = xLegendProp->getPropertyValue("Show");
461 aAOld >>= bOldValue;
462 if( bOldValue != bNewValue )
463 xLegendProp->setPropertyValue("Show", 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 Reference< beans::XPropertySet > xLegendProp(
478 LegendHelper::getLegend( *m_spChart2ModelContact->getModel() ), uno::UNO_QUERY );
479 if( xLegendProp.is())
480 aRet = xLegendProp->getPropertyValue("Show");
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 //PROP_DOCUMENT_HAS_MAIN_TITLE
499 class WrappedHasMainTitleProperty : public WrappedProperty
501 public:
502 explicit WrappedHasMainTitleProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact);
504 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
506 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
508 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
510 private: //member
511 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
514 WrappedHasMainTitleProperty::WrappedHasMainTitleProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact)
515 : WrappedProperty("HasMainTitle",OUString())
516 , m_spChart2ModelContact( spChart2ModelContact )
520 void WrappedHasMainTitleProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
522 bool bNewValue = true;
523 if( ! (rOuterValue >>= bNewValue) )
524 throw lang::IllegalArgumentException("Property HasMainTitle requires value of type boolean", nullptr, 0 );
528 if( bNewValue )
529 TitleHelper::createTitle( TitleHelper::MAIN_TITLE, "main-title", m_spChart2ModelContact->getChartModel(), m_spChart2ModelContact->m_xContext );
530 else
531 TitleHelper::removeTitle( TitleHelper::MAIN_TITLE, m_spChart2ModelContact->getChartModel() );
533 catch (const uno::Exception&)
535 DBG_UNHANDLED_EXCEPTION("chart2");
539 Any WrappedHasMainTitleProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
541 Any aRet;
544 aRet <<= TitleHelper::getTitle( TitleHelper::MAIN_TITLE, m_spChart2ModelContact->getChartModel() ).is();
546 catch (const uno::Exception&)
548 DBG_UNHANDLED_EXCEPTION("chart2");
550 return aRet;
553 Any WrappedHasMainTitleProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
555 Any aRet;
556 aRet <<= false;
557 return aRet;
560 //PROP_DOCUMENT_HAS_SUB_TITLE
561 class WrappedHasSubTitleProperty : public WrappedProperty
563 public:
564 explicit WrappedHasSubTitleProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact);
566 virtual void setPropertyValue( const css::uno::Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
568 virtual css::uno::Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
570 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
572 private: //member
573 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
576 WrappedHasSubTitleProperty::WrappedHasSubTitleProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact)
577 : WrappedProperty("HasSubTitle",OUString())
578 , m_spChart2ModelContact( spChart2ModelContact )
582 void WrappedHasSubTitleProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
584 bool bNewValue = true;
585 if( ! (rOuterValue >>= bNewValue) )
586 throw lang::IllegalArgumentException("Property HasSubTitle requires value of type boolean", nullptr, 0 );
590 if( bNewValue )
591 TitleHelper::createTitle( TitleHelper::SUB_TITLE, "", m_spChart2ModelContact->getChartModel(), m_spChart2ModelContact->m_xContext );
592 else
593 TitleHelper::removeTitle( TitleHelper::SUB_TITLE, m_spChart2ModelContact->getChartModel() );
595 catch (const uno::Exception&)
597 DBG_UNHANDLED_EXCEPTION("chart2");
601 Any WrappedHasSubTitleProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
603 Any aRet;
606 aRet <<= TitleHelper::getTitle( TitleHelper::SUB_TITLE, m_spChart2ModelContact->getChartModel() ).is();
608 catch (const uno::Exception&)
610 DBG_UNHANDLED_EXCEPTION("chart2");
612 return aRet;
615 Any WrappedHasSubTitleProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
617 Any aRet;
618 aRet <<= false;
619 return aRet;
622 ChartDocumentWrapper::ChartDocumentWrapper(
623 const Reference< uno::XComponentContext > & xContext ) :
624 m_spChart2ModelContact( new Chart2ModelContact( xContext ) ),
625 m_bUpdateAddIn( true ),
626 m_bIsDisposed( false )
630 ChartDocumentWrapper::~ChartDocumentWrapper()
632 stopAllComponentListening();
635 // ____ XInterface (for new interfaces) ____
636 uno::Any SAL_CALL ChartDocumentWrapper::queryInterface( const uno::Type& aType )
638 if( m_xDelegator.is())
639 // calls queryAggregation if the delegator doesn't know aType
640 return m_xDelegator->queryInterface( aType );
641 else
642 return queryAggregation( aType );
645 // ____ chart::XChartDocument (old API wrapper) ____
646 Reference< drawing::XShape > SAL_CALL ChartDocumentWrapper::getTitle()
648 if( !m_xTitle.is() )
650 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getChart2Document() );
651 m_xTitle = new TitleWrapper( TitleHelper::MAIN_TITLE, m_spChart2ModelContact );
653 return m_xTitle;
656 Reference< drawing::XShape > SAL_CALL ChartDocumentWrapper::getSubTitle()
658 if( !m_xSubTitle.is() )
660 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getChart2Document() );
661 m_xSubTitle = new TitleWrapper( TitleHelper::SUB_TITLE, m_spChart2ModelContact );
663 return m_xSubTitle;
666 Reference< drawing::XShape > SAL_CALL ChartDocumentWrapper::getLegend()
668 if( ! m_xLegend.is())
670 m_xLegend = new LegendWrapper( m_spChart2ModelContact );
673 return m_xLegend;
676 Reference< beans::XPropertySet > SAL_CALL ChartDocumentWrapper::getArea()
678 if( ! m_xArea.is())
680 m_xArea.set( new AreaWrapper( m_spChart2ModelContact ) );
683 return m_xArea;
686 Reference< XDiagram > SAL_CALL ChartDocumentWrapper::getDiagram()
688 if( !m_xDiagram.is() )
692 m_xDiagram = new DiagramWrapper( m_spChart2ModelContact );
694 catch (const uno::Exception&)
696 DBG_UNHANDLED_EXCEPTION("chart2");
700 return m_xDiagram;
703 void SAL_CALL ChartDocumentWrapper::setDiagram( const Reference< XDiagram >& xDiagram )
705 uno::Reference< util::XRefreshable > xAddIn( xDiagram, uno::UNO_QUERY );
706 if( xAddIn.is() )
708 setAddIn( xAddIn );
710 else if( xDiagram.is() && xDiagram != m_xDiagram )
712 // set new wrapped diagram at new chart. This requires the old
713 // diagram given as parameter to implement the new interface. If
714 // this is not possible throw an exception
715 Reference< chart2::XDiagramProvider > xNewDiaProvider( xDiagram, uno::UNO_QUERY_THROW );
716 Reference< chart2::XDiagram > xNewDia( xNewDiaProvider->getDiagram());
720 Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
721 if( xChartDoc.is() )
723 // set the new diagram
724 xChartDoc->setFirstDiagram( xNewDia );
725 m_xDiagram = xDiagram;
728 catch (const uno::Exception&)
730 DBG_UNHANDLED_EXCEPTION("chart2");
735 Reference< XChartData > SAL_CALL ChartDocumentWrapper::getData()
737 if( !m_xChartData.is() )
739 m_xChartData.set( new ChartDataWrapper( m_spChart2ModelContact ) );
741 //@todo: check hasInternalDataProvider also in else?
743 return m_xChartData;
746 void SAL_CALL ChartDocumentWrapper::attachData( const Reference< XChartData >& xNewData )
748 if( !xNewData.is() )
749 return;
751 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getChart2Document() );
752 m_xChartData.set( new ChartDataWrapper( m_spChart2ModelContact, xNewData ) );
755 // ____ XModel ____
756 sal_Bool SAL_CALL ChartDocumentWrapper::attachResource(
757 const OUString& URL,
758 const Sequence< beans::PropertyValue >& Arguments )
760 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
761 if( xModel.is() )
762 return xModel->attachResource( URL, Arguments );
763 return false;
766 OUString SAL_CALL ChartDocumentWrapper::getURL()
768 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
769 if( xModel.is() )
770 return xModel->getURL();
771 return OUString();
774 Sequence< beans::PropertyValue > SAL_CALL ChartDocumentWrapper::getArgs()
776 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
777 if( xModel.is() )
778 return xModel->getArgs();
779 return Sequence< beans::PropertyValue >();
782 void SAL_CALL ChartDocumentWrapper::connectController( const Reference< frame::XController >& Controller )
784 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
785 if( xModel.is() )
786 xModel->connectController( Controller );
789 void SAL_CALL ChartDocumentWrapper::disconnectController(
790 const Reference< frame::XController >& Controller )
792 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
793 if( xModel.is() )
794 xModel->disconnectController( Controller );
797 void SAL_CALL ChartDocumentWrapper::lockControllers()
799 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
800 if( xModel.is() )
801 xModel->lockControllers();
804 void SAL_CALL ChartDocumentWrapper::unlockControllers()
806 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
807 if( xModel.is() )
808 xModel->unlockControllers();
811 sal_Bool SAL_CALL ChartDocumentWrapper::hasControllersLocked()
813 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
814 if( xModel.is() )
815 return xModel->hasControllersLocked();
816 return false;
819 Reference< frame::XController > SAL_CALL ChartDocumentWrapper::getCurrentController()
821 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
822 if( xModel.is() )
823 return xModel->getCurrentController();
824 return nullptr;
827 void SAL_CALL ChartDocumentWrapper::setCurrentController(
828 const Reference< frame::XController >& Controller )
830 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
831 if( xModel.is() )
832 xModel->setCurrentController( Controller );
835 Reference< uno::XInterface > SAL_CALL ChartDocumentWrapper::getCurrentSelection()
837 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
838 if( xModel.is() )
839 return xModel->getCurrentSelection();
840 return nullptr;
843 // ____ XComponent ____
844 void SAL_CALL ChartDocumentWrapper::dispose()
846 if( m_bIsDisposed )
847 throw lang::DisposedException("ChartDocumentWrapper is disposed",
848 static_cast< ::cppu::OWeakObject* >( this ));
850 m_bIsDisposed = true;
854 Reference< lang::XComponent > xFormerDelegator( m_xDelegator, uno::UNO_QUERY );
855 DisposeHelper::DisposeAndClear( m_xTitle );
856 DisposeHelper::DisposeAndClear( m_xSubTitle );
857 DisposeHelper::DisposeAndClear( m_xLegend );
858 DisposeHelper::DisposeAndClear( m_xChartData );
859 DisposeHelper::DisposeAndClear( m_xDiagram );
860 DisposeHelper::DisposeAndClear( m_xArea );
861 m_xChartView.set( nullptr );
862 m_xShapeFactory.set( nullptr );
863 m_xDelegator.set( nullptr );
865 clearWrappedPropertySet();
866 m_spChart2ModelContact->clear();
867 impl_resetAddIn();
869 stopAllComponentListening();
873 if( xFormerDelegator.is())
874 xFormerDelegator->dispose();
876 catch (const lang::DisposedException&)
878 // this is ok, don't panic
881 catch (const uno::Exception &)
883 DBG_UNHANDLED_EXCEPTION("chart2");
887 void ChartDocumentWrapper::impl_resetAddIn()
889 Reference< util::XRefreshable > xAddIn( m_xAddIn );
890 m_xAddIn.set( nullptr );
892 if( xAddIn.is() )
896 //make sure that the add-in does not hold a references to us anymore:
897 Reference< lang::XComponent > xComp( xAddIn, uno::UNO_QUERY );
898 if( xComp.is())
899 xComp->dispose();
900 else
902 uno::Reference< lang::XInitialization > xInit( xAddIn, uno::UNO_QUERY );
903 if( xInit.is() )
905 uno::Any aParam;
906 uno::Reference< css::chart::XChartDocument > xDoc;
907 aParam <<= xDoc;
908 uno::Sequence< uno::Any > aSeq( &aParam, 1 );
909 xInit->initialize( aSeq );
913 catch (const uno::RuntimeException&)
915 DBG_UNHANDLED_EXCEPTION("chart2");
917 catch (const uno::Exception&)
919 DBG_UNHANDLED_EXCEPTION("chart2");
924 void ChartDocumentWrapper::setBaseDiagram( const OUString& rBaseDiagram )
926 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getChartModel() );
927 m_aBaseDiagram = rBaseDiagram;
929 uno::Reference< XDiagram > xDiagram( ChartDocumentWrapper::createInstance( rBaseDiagram ), uno::UNO_QUERY );
930 if( xDiagram.is() )
931 setDiagram( xDiagram );
934 void ChartDocumentWrapper::setAddIn( const Reference< util::XRefreshable >& xAddIn )
936 if( m_xAddIn == xAddIn )
937 return;
939 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getChartModel() );
940 impl_resetAddIn();
941 m_xAddIn = xAddIn;
942 // initialize AddIn with this as chart document
943 uno::Reference< lang::XInitialization > xInit( m_xAddIn, uno::UNO_QUERY );
944 if( xInit.is() )
946 uno::Any aParam;
947 uno::Reference< XChartDocument > xDoc( static_cast<XChartDocument*>(this), uno::UNO_QUERY );
948 aParam <<= xDoc;
949 uno::Sequence< uno::Any > aSeq( &aParam, 1 );
950 xInit->initialize( aSeq );
954 void ChartDocumentWrapper::setUpdateAddIn( bool bUpdateAddIn )
956 m_bUpdateAddIn = bUpdateAddIn;
959 Reference< drawing::XShapes > ChartDocumentWrapper::getAdditionalShapes() const
961 // get additional non-chart shapes for XML export
962 uno::Reference< drawing::XShapes > xFoundShapes;
963 uno::Reference< drawing::XDrawPage > xDrawPage( impl_getDrawPage() );
965 if( !xDrawPage.is() )
966 return xFoundShapes;
968 uno::Reference<drawing::XShapes> xChartRoot( DrawModelWrapper::getChartRootShape( xDrawPage ) );
970 // iterate 'flat' over all top-level objects
971 // and determine all that are no chart objects
972 std::vector< uno::Reference< drawing::XShape > > aShapeVector;
973 sal_Int32 nSubCount = xDrawPage->getCount();
974 uno::Reference< drawing::XShape > xShape;
975 for( sal_Int32 nS = 0; nS < nSubCount; nS++ )
977 if( xDrawPage->getByIndex( nS ) >>= xShape )
979 if( xShape.is() && xChartRoot!=xShape )
980 aShapeVector.push_back( xShape );
984 if( !aShapeVector.empty() )
986 // create a shape collection
987 xFoundShapes = drawing::ShapeCollection::create(
988 comphelper::getProcessComponentContext());
990 OSL_ENSURE( xFoundShapes.is(), "Couldn't create a shape collection!" );
991 if( xFoundShapes.is())
993 for (auto const& shape : aShapeVector)
994 xFoundShapes->add(shape);
998 return xFoundShapes;
1001 void SAL_CALL ChartDocumentWrapper::addEventListener( const Reference< lang::XEventListener >& xListener )
1003 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
1004 if( xModel.is() )
1005 xModel->addEventListener( xListener );
1008 void SAL_CALL ChartDocumentWrapper::removeEventListener( const Reference< lang::XEventListener >& aListener )
1010 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
1011 if( xModel.is() )
1012 xModel->removeEventListener( aListener );
1015 // ____ XDrawPageSupplier ____
1016 uno::Reference< drawing::XDrawPage > SAL_CALL ChartDocumentWrapper::getDrawPage()
1018 return impl_getDrawPage();
1021 uno::Reference< drawing::XDrawPage > ChartDocumentWrapper::impl_getDrawPage() const
1023 return m_spChart2ModelContact->getDrawPage();
1026 namespace {
1028 uno::Reference< lang::XMultiServiceFactory > getShapeFactory(const uno::Reference<uno::XInterface>& xChartView)
1030 auto pProvider = comphelper::getUnoTunnelImplementation<ExplicitValueProvider>(xChartView);
1031 if( pProvider )
1032 return pProvider->getDrawModelWrapper()->getShapeFactory();
1034 return uno::Reference< lang::XMultiServiceFactory >();
1039 // ____ XMultiServiceFactory ____
1040 uno::Reference< uno::XInterface > SAL_CALL ChartDocumentWrapper::createInstance(
1041 const OUString& aServiceSpecifier )
1043 uno::Reference< uno::XInterface > xResult;
1045 Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
1046 if( !xChartDoc.is() )
1047 return xResult;
1049 bool bServiceFound = false;
1050 tServiceNameMap & rMap = lcl_getStaticServiceNameMap();
1052 tServiceNameMap::const_iterator aIt( rMap.find( aServiceSpecifier ));
1053 if( aIt != rMap.end())
1055 bool bCreateDiagram = false;
1056 uno::Reference< lang::XMultiServiceFactory > xManagerFact(
1057 xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
1058 uno::Reference< chart2::XChartTypeTemplate > xTemplate;
1060 switch( (*aIt).second )
1062 case SERVICE_NAME_AREA_DIAGRAM:
1063 if( xManagerFact.is())
1065 xTemplate.set(
1066 xManagerFact->createInstance("com.sun.star.chart2.template.Area"),
1067 uno::UNO_QUERY );
1068 bCreateDiagram = true;
1070 break;
1071 case SERVICE_NAME_BAR_DIAGRAM:
1072 if( xManagerFact.is())
1074 // this is for bar and column (the latter is the default if
1075 // no "Vertical=false" property was set)
1076 xTemplate.set(
1077 xManagerFact->createInstance("com.sun.star.chart2.template.Column"),
1078 uno::UNO_QUERY );
1079 bCreateDiagram = true;
1081 break;
1082 case SERVICE_NAME_DONUT_DIAGRAM:
1083 if( xManagerFact.is())
1085 xTemplate.set(
1086 xManagerFact->createInstance("com.sun.star.chart2.template.Donut"),
1087 uno::UNO_QUERY );
1088 bCreateDiagram = true;
1090 break;
1091 case SERVICE_NAME_LINE_DIAGRAM:
1092 if( xManagerFact.is())
1094 xTemplate.set(
1095 xManagerFact->createInstance("com.sun.star.chart2.template.Line"),
1096 uno::UNO_QUERY );
1097 bCreateDiagram = true;
1099 break;
1100 case SERVICE_NAME_NET_DIAGRAM:
1101 if( xManagerFact.is())
1103 xTemplate.set(
1104 xManagerFact->createInstance("com.sun.star.chart2.template.Net"),
1105 uno::UNO_QUERY );
1106 bCreateDiagram = true;
1108 break;
1109 case SERVICE_NAME_FILLED_NET_DIAGRAM:
1110 if( xManagerFact.is())
1112 xTemplate.set(
1113 xManagerFact->createInstance("com.sun.star.chart2.template.FilledNet"),
1114 uno::UNO_QUERY );
1115 bCreateDiagram = true;
1117 break;
1118 case SERVICE_NAME_PIE_DIAGRAM:
1119 if( xManagerFact.is())
1121 xTemplate.set(
1122 xManagerFact->createInstance("com.sun.star.chart2.template.Pie"),
1123 uno::UNO_QUERY );
1124 bCreateDiagram = true;
1126 break;
1127 case SERVICE_NAME_STOCK_DIAGRAM:
1128 if( xManagerFact.is())
1130 xTemplate.set(
1131 xManagerFact->createInstance("com.sun.star.chart2.template.StockLowHighClose"),
1132 uno::UNO_QUERY );
1133 bCreateDiagram = true;
1135 break;
1136 case SERVICE_NAME_XY_DIAGRAM:
1137 if( xManagerFact.is())
1139 xTemplate.set(
1140 xManagerFact->createInstance("com.sun.star.chart2.template.ScatterLineSymbol"),
1141 uno::UNO_QUERY );
1142 bCreateDiagram = true;
1144 break;
1146 case SERVICE_NAME_BUBBLE_DIAGRAM:
1147 if( xManagerFact.is())
1149 xTemplate.set(
1150 xManagerFact->createInstance("com.sun.star.chart2.template.Bubble"),
1151 uno::UNO_QUERY );
1152 bCreateDiagram = true;
1154 break;
1156 case SERVICE_NAME_DASH_TABLE:
1157 case SERVICE_NAME_GARDIENT_TABLE:
1158 case SERVICE_NAME_HATCH_TABLE:
1159 case SERVICE_NAME_BITMAP_TABLE:
1160 case SERVICE_NAME_TRANSP_GRADIENT_TABLE:
1161 case SERVICE_NAME_MARKER_TABLE:
1163 uno::Reference< lang::XMultiServiceFactory > xTableFactory( xChartDoc, uno::UNO_QUERY );
1164 OSL_ENSURE( xTableFactory.get() != this, "new model is expected to implement service factory for gradient table etc" );
1165 if( xTableFactory.is() && xTableFactory.get() != this )
1166 xResult.set( xTableFactory->createInstance( aIt->first ), uno::UNO_QUERY );
1168 break;
1170 case SERVICE_NAME_NAMESPACE_MAP:
1171 break;
1172 case SERVICE_NAME_EXPORT_GRAPHIC_STORAGE_RESOLVER:
1173 break;
1174 case SERVICE_NAME_IMPORT_GRAPHIC_STORAGE_RESOLVER:
1175 break;
1178 if( bCreateDiagram && xTemplate.is() )
1182 uno::Reference< chart2::XDiagram > xDia( xChartDoc->getFirstDiagram());
1183 if( xDia.is())
1185 // locked controllers
1186 ControllerLockGuardUNO aCtrlLockGuard( xChartDoc );
1187 Reference< chart2::XDiagram > xDiagram = ChartModelHelper::findDiagram( xChartDoc );
1188 ThreeDLookScheme e3DScheme = ThreeDHelper::detectScheme( xDiagram );
1189 Reference< lang::XMultiServiceFactory > xTemplateManager( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
1190 DiagramHelper::tTemplateWithServiceName aTemplateWithService(
1191 DiagramHelper::getTemplateForDiagram( xDiagram, xTemplateManager ));
1192 if( aTemplateWithService.first.is())
1193 aTemplateWithService.first->resetStyles( xDiagram );//#i109371#
1194 xTemplate->changeDiagram( xDiagram );
1195 if( AllSettings::GetMathLayoutRTL() )
1196 AxisHelper::setRTLAxisLayout( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 ) );
1197 ThreeDHelper::setScheme( xDiagram, e3DScheme );
1199 else
1201 // locked controllers
1202 ControllerLockGuardUNO aCtrlLockGuard( xChartDoc );
1203 xDia.set( xTemplate->createDiagramByDataSource(
1204 uno::Reference< chart2::data::XDataSource >(),
1205 uno::Sequence< beans::PropertyValue >()));
1206 xChartDoc->setFirstDiagram( xDia );
1209 xResult = static_cast< ::cppu::OWeakObject* >( new DiagramWrapper( m_spChart2ModelContact ));
1211 catch (const uno::Exception&)
1213 DBG_UNHANDLED_EXCEPTION("chart2");
1217 bServiceFound = true;
1219 else if( aServiceSpecifier == "com.sun.star.comp.chart2.DataSeriesWrapper" )
1221 Reference< beans::XPropertySet > xDataSeries( new DataSeriesPointWrapper( m_spChart2ModelContact ) );
1222 xResult.set( xDataSeries );
1223 bServiceFound = true;
1225 else if( aServiceSpecifier == CHART_VIEW_SERVICE_NAME )
1227 if( !m_xChartView.is() )
1229 Reference< lang::XMultiServiceFactory > xFact(
1230 m_spChart2ModelContact->m_xContext->getServiceManager(), uno::UNO_QUERY_THROW );
1231 Reference< lang::XInitialization > xViewInit( xFact->createInstance(
1232 CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
1233 if(xViewInit.is())
1237 m_xChartView = xViewInit;
1239 Sequence< Any > aArguments(2);
1240 aArguments[0] <<= Reference<frame::XModel>(this);
1241 aArguments[1] <<= true; // bRefreshAddIn
1242 xViewInit->initialize(aArguments);
1244 catch (const uno::Exception&)
1246 DBG_UNHANDLED_EXCEPTION("chart2");
1250 xResult.set( m_xChartView );
1251 bServiceFound = true;
1253 else
1255 // try to create a shape
1258 if( !m_xShapeFactory.is() && m_xChartView.is() )
1260 m_xShapeFactory = getShapeFactory( m_xChartView );
1262 else
1264 ChartModel* pModel = m_spChart2ModelContact->getModel();
1265 if(pModel)
1267 m_xChartView = pModel->getChartView();
1268 m_xShapeFactory = getShapeFactory( m_xChartView );
1272 if( m_xShapeFactory.is() )
1274 xResult = m_xShapeFactory->createInstance( aServiceSpecifier );
1275 bServiceFound = true;
1278 catch (const uno::Exception&)
1280 // couldn't create shape
1284 // finally, try to create an addin
1285 if( !bServiceFound )
1289 Reference< lang::XMultiServiceFactory > xFact(
1290 m_spChart2ModelContact->m_xContext->getServiceManager(), uno::UNO_QUERY_THROW );
1291 uno::Reference< util::XRefreshable > xAddIn(
1292 xFact->createInstance( aServiceSpecifier ), uno::UNO_QUERY );
1293 if( xAddIn.is() )
1295 xResult = xAddIn;
1298 catch (const uno::Exception&)
1300 // couldn't create service
1304 return xResult;
1307 uno::Reference< uno::XInterface > SAL_CALL ChartDocumentWrapper::createInstanceWithArguments(
1308 const OUString& ServiceSpecifier,
1309 const uno::Sequence< uno::Any >& Arguments )
1311 OSL_ENSURE( Arguments.hasElements(), "createInstanceWithArguments: Warning: Arguments are ignored" );
1313 return createInstance( ServiceSpecifier );
1316 uno::Sequence< OUString > SAL_CALL ChartDocumentWrapper::getAvailableServiceNames()
1318 return comphelper::mapKeysToSequence( lcl_getStaticServiceNameMap() );
1321 // ____ XAggregation ____
1322 void SAL_CALL ChartDocumentWrapper::setDelegator(
1323 const uno::Reference< uno::XInterface >& rDelegator )
1325 if( m_bIsDisposed )
1327 if( rDelegator.is() )
1328 throw lang::DisposedException("ChartDocumentWrapper is disposed",
1329 static_cast< ::cppu::OWeakObject* >( this ));
1330 return;
1333 if( rDelegator.is())
1335 m_xDelegator = rDelegator;
1336 m_spChart2ModelContact->setModel( uno::Reference< frame::XModel >(m_xDelegator, uno::UNO_QUERY) );
1338 else
1340 // this is a sort of dispose() from the new model,so release resources here
1343 dispose();
1345 catch (const uno::Exception&)
1347 DBG_UNHANDLED_EXCEPTION("chart2");
1352 uno::Any SAL_CALL ChartDocumentWrapper::queryAggregation( const uno::Type& rType )
1354 return ChartDocumentWrapper_Base::queryInterface( rType );
1357 // ____ ::utl::OEventListenerAdapter ____
1358 void ChartDocumentWrapper::_disposing( const lang::EventObject& rSource )
1360 if( rSource.Source == m_xTitle )
1361 m_xTitle.set( nullptr );
1362 else if( rSource.Source == m_xSubTitle )
1363 m_xSubTitle.set( nullptr );
1364 else if( rSource.Source == m_xLegend )
1365 m_xLegend.set( nullptr );
1366 else if( rSource.Source == m_xChartData )
1367 m_xChartData.set( nullptr );
1368 else if( rSource.Source == m_xDiagram )
1369 m_xDiagram.set( nullptr );
1370 else if( rSource.Source == m_xArea )
1371 m_xArea.set( nullptr );
1372 else if( rSource.Source == m_xAddIn )
1373 m_xAddIn.set( nullptr );
1374 else if( rSource.Source == m_xChartView )
1375 m_xChartView.set( nullptr );
1378 // WrappedPropertySet
1379 Reference< beans::XPropertySet > ChartDocumentWrapper::getInnerPropertySet()
1381 return nullptr;
1383 const Sequence< beans::Property >& ChartDocumentWrapper::getPropertySequence()
1385 return *StaticChartDocumentWrapperPropertyArray::get();
1388 std::vector< std::unique_ptr<WrappedProperty> > ChartDocumentWrapper::createWrappedProperties()
1390 std::vector< std::unique_ptr<WrappedProperty> > aWrappedProperties;
1391 aWrappedProperties.emplace_back( new WrappedDataSourceLabelsInFirstRowProperty( m_spChart2ModelContact ) );
1392 aWrappedProperties.emplace_back( new WrappedDataSourceLabelsInFirstColumnProperty( m_spChart2ModelContact ) );
1393 aWrappedProperties.emplace_back( new WrappedHasLegendProperty( m_spChart2ModelContact ) );
1394 aWrappedProperties.emplace_back( new WrappedHasMainTitleProperty( m_spChart2ModelContact ) );
1395 aWrappedProperties.emplace_back( new WrappedHasSubTitleProperty( m_spChart2ModelContact ) );
1396 aWrappedProperties.emplace_back( new WrappedAddInProperty( *this ) );
1397 aWrappedProperties.emplace_back( new WrappedBaseDiagramProperty( *this ) );
1398 aWrappedProperties.emplace_back( new WrappedAdditionalShapesProperty( *this ) );
1399 aWrappedProperties.emplace_back( new WrappedRefreshAddInAllowedProperty( *this ) );
1400 aWrappedProperties.emplace_back( new WrappedIgnoreProperty("NullDate",Any() ) ); // i99104
1401 aWrappedProperties.emplace_back( new WrappedIgnoreProperty("EnableComplexChartTypes", uno::Any(true) ) );
1402 aWrappedProperties.emplace_back( new WrappedIgnoreProperty("EnableDataTableDialog", uno::Any(true) ) );
1404 return aWrappedProperties;
1407 OUString SAL_CALL ChartDocumentWrapper::getImplementationName()
1409 return CHART_CHARTAPIWRAPPER_IMPLEMENTATION_NAME;
1412 sal_Bool SAL_CALL ChartDocumentWrapper::supportsService( const OUString& rServiceName )
1414 return cppu::supportsService(this, rServiceName);
1417 css::uno::Sequence< OUString > SAL_CALL ChartDocumentWrapper::getSupportedServiceNames()
1419 return {
1420 "com.sun.star.chart.ChartDocument",
1421 CHART_CHARTAPIWRAPPER_SERVICE_NAME,
1422 "com.sun.star.xml.UserDefinedAttributesSupplier",
1423 "com.sun.star.beans.PropertySet"
1427 } // namespace wrapper
1428 } // namespace chart
1430 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1431 com_sun_star_comp_chart2_ChartDocumentWrapper_get_implementation(css::uno::XComponentContext *context,
1432 css::uno::Sequence<css::uno::Any> const &)
1434 return cppu::acquire(new ::chart::wrapper::ChartDocumentWrapper(context));
1437 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */