fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / ChartDocumentWrapper.cxx
blob33c06dcf5b773102d5096351c3e7f7af4ce2c2b3
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 "macros.hxx"
22 #include "servicenames.hxx"
23 #include "PropertyHelper.hxx"
24 #include "TitleHelper.hxx"
25 #include "LegendHelper.hxx"
26 #include "ControllerLockGuard.hxx"
27 #include "ModifyListenerHelper.hxx"
28 #include "DisposeHelper.hxx"
29 #include "DataSeriesPointWrapper.hxx"
30 #include "chartview/ExplicitValueProvider.hxx"
31 #include "chartview/DrawModelWrapper.hxx"
32 #include "Chart2ModelContact.hxx"
34 #include "ChartModel.hxx"
36 #include "DiagramHelper.hxx"
37 #include "DataSourceHelper.hxx"
38 #include "ChartModelHelper.hxx"
39 #include "ContainerHelper.hxx"
40 #include "AxisHelper.hxx"
41 #include "ThreeDHelper.hxx"
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 <com/sun/star/chart2/XTitled.hpp>
52 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
53 #include <com/sun/star/chart/ChartDataRowSource.hpp>
54 #include <comphelper/InlineContainer.hxx>
55 #include <comphelper/processfactory.hxx>
56 #include <vcl/svapp.hxx>
57 #include <vcl/settings.hxx>
59 #include <com/sun/star/drawing/ShapeCollection.hpp>
60 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
61 #include <com/sun/star/beans/PropertyAttribute.hpp>
62 #include <com/sun/star/lang/DisposedException.hpp>
63 #include <com/sun/star/lang/XInitialization.hpp>
64 #include <com/sun/star/util/DateTime.hpp>
66 #include <vector>
67 #include <algorithm>
68 #include <functional>
69 #include <o3tl/compat_functional.hxx>
71 using namespace ::com::sun::star;
72 using namespace ::com::sun::star::chart;
74 using ::com::sun::star::uno::Any;
75 using ::com::sun::star::uno::UNO_QUERY_THROW;
76 using ::com::sun::star::uno::Reference;
77 using ::com::sun::star::uno::Sequence;
78 using ::com::sun::star::beans::Property;
79 using ::osl::MutexGuard;
81 namespace
83 enum eServiceType
85 SERVICE_NAME_AREA_DIAGRAM = 0,
86 SERVICE_NAME_BAR_DIAGRAM,
87 SERVICE_NAME_DONUT_DIAGRAM,
88 SERVICE_NAME_LINE_DIAGRAM,
89 SERVICE_NAME_NET_DIAGRAM,
90 SERVICE_NAME_FILLED_NET_DIAGRAM,
91 SERVICE_NAME_PIE_DIAGRAM,
92 SERVICE_NAME_STOCK_DIAGRAM,
93 SERVICE_NAME_XY_DIAGRAM,
94 SERVICE_NAME_BUBBLE_DIAGRAM,
95 SERVICE_NAME_GL3DBAR_DIAGRAM,
97 SERVICE_NAME_DASH_TABLE,
98 SERVICE_NAME_GARDIENT_TABLE,
99 SERVICE_NAME_HATCH_TABLE,
100 SERVICE_NAME_BITMAP_TABLE,
101 SERVICE_NAME_TRANSP_GRADIENT_TABLE,
102 SERVICE_NAME_MARKER_TABLE,
104 SERVICE_NAME_NAMESPACE_MAP,
105 SERVICE_NAME_EXPORT_GRAPHIC_RESOLVER,
106 SERVICE_NAME_IMPORT_GRAPHIC_RESOLVER
109 typedef ::std::map< OUString, enum eServiceType > tServiceNameMap;
110 typedef ::comphelper::MakeMap< OUString, enum eServiceType > tMakeServiceNameMap;
112 tServiceNameMap & lcl_getStaticServiceNameMap()
114 static tServiceNameMap aServiceNameMap(
115 tMakeServiceNameMap
116 ( "com.sun.star.chart.AreaDiagram", SERVICE_NAME_AREA_DIAGRAM )
117 ( "com.sun.star.chart.BarDiagram", SERVICE_NAME_BAR_DIAGRAM )
118 ( "com.sun.star.chart.DonutDiagram", SERVICE_NAME_DONUT_DIAGRAM )
119 ( "com.sun.star.chart.LineDiagram", SERVICE_NAME_LINE_DIAGRAM )
120 ( "com.sun.star.chart.NetDiagram", SERVICE_NAME_NET_DIAGRAM )
121 ( "com.sun.star.chart.FilledNetDiagram", SERVICE_NAME_FILLED_NET_DIAGRAM )
122 ( "com.sun.star.chart.PieDiagram", SERVICE_NAME_PIE_DIAGRAM )
123 ( "com.sun.star.chart.StockDiagram", SERVICE_NAME_STOCK_DIAGRAM )
124 ( "com.sun.star.chart.XYDiagram", SERVICE_NAME_XY_DIAGRAM )
125 ( "com.sun.star.chart.BubbleDiagram", SERVICE_NAME_BUBBLE_DIAGRAM )
126 ( "com.sun.star.chart.GL3DBarDiagram", SERVICE_NAME_GL3DBAR_DIAGRAM )
128 ( "com.sun.star.drawing.DashTable", SERVICE_NAME_DASH_TABLE )
129 ( "com.sun.star.drawing.GradientTable", SERVICE_NAME_GARDIENT_TABLE )
130 ( "com.sun.star.drawing.HatchTable", SERVICE_NAME_HATCH_TABLE )
131 ( "com.sun.star.drawing.BitmapTable", SERVICE_NAME_BITMAP_TABLE )
132 ( "com.sun.star.drawing.TransparencyGradientTable", SERVICE_NAME_TRANSP_GRADIENT_TABLE )
133 ( "com.sun.star.drawing.MarkerTable", SERVICE_NAME_MARKER_TABLE )
135 ( "com.sun.star.xml.NamespaceMap", SERVICE_NAME_NAMESPACE_MAP )
136 ( "com.sun.star.document.ExportGraphicObjectResolver", SERVICE_NAME_EXPORT_GRAPHIC_RESOLVER )
137 ( "com.sun.star.document.ImportGraphicObjectResolver", SERVICE_NAME_IMPORT_GRAPHIC_RESOLVER )
140 return aServiceNameMap;
143 enum
145 PROP_DOCUMENT_HAS_MAIN_TITLE,
146 PROP_DOCUMENT_HAS_SUB_TITLE,
147 PROP_DOCUMENT_HAS_LEGEND,
148 PROP_DOCUMENT_LABELS_IN_FIRST_ROW,
149 PROP_DOCUMENT_LABELS_IN_FIRST_COLUMN,
150 PROP_DOCUMENT_ADDIN,
151 PROP_DOCUMENT_BASEDIAGRAM,
152 PROP_DOCUMENT_ADDITIONAL_SHAPES,
153 PROP_DOCUMENT_UPDATE_ADDIN,
154 PROP_DOCUMENT_NULL_DATE,
155 PROP_DOCUMENT_ENABLE_COMPLEX_CHARTTYPES,
156 PROP_DOCUMENT_ENABLE_DATATABLE_DIALOG
159 void lcl_AddPropertiesToVector(
160 ::std::vector< Property > & rOutProperties )
162 rOutProperties.push_back(
163 Property( "HasMainTitle",
164 PROP_DOCUMENT_HAS_MAIN_TITLE,
165 cppu::UnoType<bool>::get(),
166 //#i111967# no PropertyChangeEvent is fired on change so far
167 beans::PropertyAttribute::MAYBEDEFAULT ));
168 rOutProperties.push_back(
169 Property( "HasSubTitle",
170 PROP_DOCUMENT_HAS_SUB_TITLE,
171 cppu::UnoType<bool>::get(),
172 //#i111967# no PropertyChangeEvent is fired on change so far
173 beans::PropertyAttribute::MAYBEDEFAULT ));
174 rOutProperties.push_back(
175 Property( "HasLegend",
176 PROP_DOCUMENT_HAS_LEGEND,
177 cppu::UnoType<bool>::get(),
178 //#i111967# no PropertyChangeEvent is fired on change so far
179 beans::PropertyAttribute::MAYBEDEFAULT ));
181 // really needed?
182 rOutProperties.push_back(
183 Property( "DataSourceLabelsInFirstRow",
184 PROP_DOCUMENT_LABELS_IN_FIRST_ROW,
185 cppu::UnoType<bool>::get(),
186 beans::PropertyAttribute::BOUND
187 | beans::PropertyAttribute::MAYBEDEFAULT ));
188 rOutProperties.push_back(
189 Property( "DataSourceLabelsInFirstColumn",
190 PROP_DOCUMENT_LABELS_IN_FIRST_COLUMN,
191 cppu::UnoType<bool>::get(),
192 //#i111967# no PropertyChangeEvent is fired on change so far
193 beans::PropertyAttribute::MAYBEDEFAULT ));
195 //add-in
196 rOutProperties.push_back(
197 Property( "AddIn",
198 PROP_DOCUMENT_ADDIN,
199 cppu::UnoType<util::XRefreshable>::get(),
200 beans::PropertyAttribute::BOUND
201 | beans::PropertyAttribute::MAYBEVOID ));
202 rOutProperties.push_back(
203 Property( "BaseDiagram",
204 PROP_DOCUMENT_BASEDIAGRAM,
205 cppu::UnoType<OUString>::get(),
206 beans::PropertyAttribute::BOUND
207 | beans::PropertyAttribute::MAYBEVOID ));
208 rOutProperties.push_back(
209 Property( "AdditionalShapes",
210 PROP_DOCUMENT_ADDITIONAL_SHAPES,
211 cppu::UnoType<drawing::XShapes>::get(),
212 beans::PropertyAttribute::BOUND
213 | beans::PropertyAttribute::MAYBEVOID
214 | beans::PropertyAttribute::READONLY ));
215 rOutProperties.push_back(
216 Property( "RefreshAddInAllowed",
217 PROP_DOCUMENT_UPDATE_ADDIN,
218 cppu::UnoType<bool>::get(),
219 //#i111967# no PropertyChangeEvent is fired on change so far
220 beans::PropertyAttribute::TRANSIENT ));
222 // table:null-date // i99104
223 rOutProperties.push_back(
224 Property( "NullDate",
225 PROP_DOCUMENT_NULL_DATE,
226 ::cppu::UnoType<com::sun::star::util::DateTime>::get(),
227 beans::PropertyAttribute::MAYBEVOID ));
229 rOutProperties.push_back(
230 Property( "EnableComplexChartTypes",
231 PROP_DOCUMENT_ENABLE_COMPLEX_CHARTTYPES,
232 cppu::UnoType<bool>::get(),
233 //#i112666# no PropertyChangeEvent is fired on change so far
234 beans::PropertyAttribute::MAYBEDEFAULT ) );
235 rOutProperties.push_back(
236 Property( "EnableDataTableDialog",
237 PROP_DOCUMENT_ENABLE_DATATABLE_DIALOG,
238 cppu::UnoType<bool>::get(),
239 //#i112666# no PropertyChangeEvent is fired on change so far
240 beans::PropertyAttribute::MAYBEDEFAULT ) );
243 struct StaticChartDocumentWrapperPropertyArray_Initializer
245 Sequence< Property >* operator()()
247 static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
248 return &aPropSeq;
251 private:
252 static uno::Sequence< Property > lcl_GetPropertySequence()
254 ::std::vector< ::com::sun::star::beans::Property > aProperties;
255 lcl_AddPropertiesToVector( aProperties );
257 ::std::sort( aProperties.begin(), aProperties.end(),
258 ::chart::PropertyNameLess() );
260 return ::chart::ContainerHelper::ContainerToSequence( aProperties );
264 struct StaticChartDocumentWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticChartDocumentWrapperPropertyArray_Initializer >
268 } // anonymous namespace
270 namespace chart
272 namespace wrapper
275 //PROP_DOCUMENT_LABELS_IN_FIRST_ROW
276 class WrappedDataSourceLabelsInFirstRowProperty : public WrappedProperty
278 public:
279 WrappedDataSourceLabelsInFirstRowProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
280 virtual ~WrappedDataSourceLabelsInFirstRowProperty();
282 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
283 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
285 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
286 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
288 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
289 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
291 private: //member
292 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
293 mutable Any m_aOuterValue;
296 WrappedDataSourceLabelsInFirstRowProperty::WrappedDataSourceLabelsInFirstRowProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
297 : WrappedProperty("DataSourceLabelsInFirstRow",OUString())
298 , m_spChart2ModelContact( spChart2ModelContact )
299 , m_aOuterValue()
301 m_aOuterValue = WrappedDataSourceLabelsInFirstRowProperty::getPropertyDefault( 0 );
304 WrappedDataSourceLabelsInFirstRowProperty::~WrappedDataSourceLabelsInFirstRowProperty()
308 void WrappedDataSourceLabelsInFirstRowProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
309 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
311 bool bLabelsInFirstRow = true;
312 if( ! (rOuterValue >>= bLabelsInFirstRow) )
313 throw lang::IllegalArgumentException("Property DataSourceLabelsInFirstRow requires value of type boolean", 0, 0 );
315 m_aOuterValue = rOuterValue;
316 bool bNewValue = bLabelsInFirstRow;
318 OUString aRangeString;
319 bool bUseColumns = true;
320 bool bFirstCellAsLabel = true;
321 bool bHasCategories = true;
322 uno::Sequence< sal_Int32 > aSequenceMapping;
324 if( DataSourceHelper::detectRangeSegmentation(
325 m_spChart2ModelContact->getChartModel(), aRangeString, aSequenceMapping, bUseColumns
326 , bFirstCellAsLabel, bHasCategories ) )
328 if( bUseColumns && bNewValue != bFirstCellAsLabel )
330 DataSourceHelper::setRangeSegmentation(
331 m_spChart2ModelContact->getChartModel(), aSequenceMapping, bUseColumns ,bNewValue, bHasCategories );
333 else if( !bUseColumns && bNewValue != bHasCategories )
335 DataSourceHelper::setRangeSegmentation(
336 m_spChart2ModelContact->getChartModel(), aSequenceMapping, bUseColumns , bFirstCellAsLabel, bNewValue );
341 Any WrappedDataSourceLabelsInFirstRowProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
342 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
344 OUString aRangeString;
345 bool bUseColumns = true;
346 bool bFirstCellAsLabel = true;
347 bool bHasCategories = true;
348 uno::Sequence< sal_Int32 > aSequenceMapping;
350 if( DataSourceHelper::detectRangeSegmentation(
351 m_spChart2ModelContact->getChartModel(), aRangeString, aSequenceMapping, bUseColumns
352 , bFirstCellAsLabel, bHasCategories ) )
354 bool bLabelsInFirstRow = true;
355 if( bUseColumns )
356 bLabelsInFirstRow = bFirstCellAsLabel;
357 else
358 bLabelsInFirstRow = bHasCategories;
360 m_aOuterValue <<= bLabelsInFirstRow;
362 return m_aOuterValue;
365 Any WrappedDataSourceLabelsInFirstRowProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
366 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
368 Any aRet;
369 aRet <<= sal_True;
370 return aRet;
373 //PROP_DOCUMENT_LABELS_IN_FIRST_COLUMN
374 class WrappedDataSourceLabelsInFirstColumnProperty : public WrappedProperty
376 public:
377 WrappedDataSourceLabelsInFirstColumnProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
378 virtual ~WrappedDataSourceLabelsInFirstColumnProperty();
380 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
381 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
383 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
384 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
386 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
387 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
389 private: //member
390 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
391 mutable Any m_aOuterValue;
394 WrappedDataSourceLabelsInFirstColumnProperty::WrappedDataSourceLabelsInFirstColumnProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
395 : WrappedProperty("DataSourceLabelsInFirstColumn",OUString())
396 , m_spChart2ModelContact( spChart2ModelContact )
397 , m_aOuterValue()
399 m_aOuterValue = WrappedDataSourceLabelsInFirstColumnProperty::getPropertyDefault( 0 );
402 WrappedDataSourceLabelsInFirstColumnProperty::~WrappedDataSourceLabelsInFirstColumnProperty()
406 void WrappedDataSourceLabelsInFirstColumnProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
407 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
409 bool bLabelsInFirstRow = true;
410 if( ! (rOuterValue >>= bLabelsInFirstRow) )
411 throw lang::IllegalArgumentException("Property DataSourceLabelsInFirstRow requires value of type boolean", 0, 0 );
413 m_aOuterValue = rOuterValue;
414 bool bNewValue = bLabelsInFirstRow;
416 OUString aRangeString;
417 bool bUseColumns = true;
418 bool bFirstCellAsLabel = true;
419 bool bHasCategories = true;
420 uno::Sequence< sal_Int32 > aSequenceMapping;
422 if( DataSourceHelper::detectRangeSegmentation(
423 m_spChart2ModelContact->getChartModel(), aRangeString, aSequenceMapping, bUseColumns
424 , bFirstCellAsLabel, bHasCategories ) )
426 if( bUseColumns && bNewValue != bHasCategories )
428 DataSourceHelper::setRangeSegmentation(
429 m_spChart2ModelContact->getChartModel(), aSequenceMapping, bUseColumns, bFirstCellAsLabel, bNewValue );
431 else if( !bUseColumns && bNewValue != bFirstCellAsLabel )
433 DataSourceHelper::setRangeSegmentation(
434 m_spChart2ModelContact->getChartModel(), aSequenceMapping, bUseColumns , bNewValue, bHasCategories );
439 Any WrappedDataSourceLabelsInFirstColumnProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
440 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
442 OUString aRangeString;
443 bool bUseColumns = true;
444 bool bFirstCellAsLabel = true;
445 bool bHasCategories = true;
446 uno::Sequence< sal_Int32 > aSequenceMapping;
448 if( DataSourceHelper::detectRangeSegmentation(
449 m_spChart2ModelContact->getChartModel(), aRangeString, aSequenceMapping, bUseColumns
450 , bFirstCellAsLabel, bHasCategories ) )
452 bool bLabelsInFirstColumn = true;
453 if( bUseColumns )
454 bLabelsInFirstColumn = bHasCategories;
455 else
456 bLabelsInFirstColumn = bFirstCellAsLabel;
458 m_aOuterValue <<= bLabelsInFirstColumn;
460 return m_aOuterValue;
463 Any WrappedDataSourceLabelsInFirstColumnProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
464 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
466 Any aRet;
467 aRet <<= sal_True;
468 return aRet;
471 //PROP_DOCUMENT_HAS_LEGEND
472 class WrappedHasLegendProperty : public WrappedProperty
474 public:
475 WrappedHasLegendProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
476 virtual ~WrappedHasLegendProperty();
478 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
479 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
481 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
482 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
484 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
485 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
487 private: //member
488 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
491 WrappedHasLegendProperty::WrappedHasLegendProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
492 : WrappedProperty("HasLegend",OUString())
493 , m_spChart2ModelContact( spChart2ModelContact )
497 WrappedHasLegendProperty::~WrappedHasLegendProperty()
501 void WrappedHasLegendProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
502 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
504 bool bNewValue = true;
505 if( ! (rOuterValue >>= bNewValue) )
506 throw lang::IllegalArgumentException("Property HasLegend requires value of type boolean", 0, 0 );
510 Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( *m_spChart2ModelContact->getModel(), m_spChart2ModelContact->m_xContext,bNewValue ));
511 if(xLegend.is())
513 Reference< beans::XPropertySet > xLegendProp( xLegend, uno::UNO_QUERY_THROW );
514 bool bOldValue = true;
515 Any aAOld = xLegendProp->getPropertyValue("Show");
516 aAOld >>= bOldValue;
517 if( bOldValue != bNewValue )
518 xLegendProp->setPropertyValue("Show", uno::makeAny( bNewValue ));
521 catch (const uno::Exception& ex)
523 ASSERT_EXCEPTION( ex );
527 Any WrappedHasLegendProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
528 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
530 Any aRet;
533 Reference< beans::XPropertySet > xLegendProp(
534 LegendHelper::getLegend( *m_spChart2ModelContact->getModel() ), uno::UNO_QUERY );
535 if( xLegendProp.is())
536 aRet = xLegendProp->getPropertyValue("Show");
537 else
538 aRet <<= sal_False;
540 catch (const uno::Exception& ex)
542 ASSERT_EXCEPTION( ex );
544 return aRet;
547 Any WrappedHasLegendProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
548 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
550 Any aRet;
551 aRet <<= sal_False;
552 return aRet;
555 //PROP_DOCUMENT_HAS_MAIN_TITLE
556 class WrappedHasMainTitleProperty : public WrappedProperty
558 public:
559 WrappedHasMainTitleProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
560 virtual ~WrappedHasMainTitleProperty();
562 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
563 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
565 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
566 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
568 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
569 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
571 private: //member
572 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
575 WrappedHasMainTitleProperty::WrappedHasMainTitleProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
576 : WrappedProperty("HasMainTitle",OUString())
577 , m_spChart2ModelContact( spChart2ModelContact )
581 WrappedHasMainTitleProperty::~WrappedHasMainTitleProperty()
585 void WrappedHasMainTitleProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
586 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
588 bool bNewValue = true;
589 if( ! (rOuterValue >>= bNewValue) )
590 throw lang::IllegalArgumentException("Property HasMainTitle requires value of type boolean", 0, 0 );
594 if( bNewValue )
595 TitleHelper::createTitle( TitleHelper::MAIN_TITLE, "main-title", m_spChart2ModelContact->getChartModel(), m_spChart2ModelContact->m_xContext );
596 else
597 TitleHelper::removeTitle( TitleHelper::MAIN_TITLE, m_spChart2ModelContact->getChartModel() );
599 catch (const uno::Exception& ex)
601 ASSERT_EXCEPTION( ex );
605 Any WrappedHasMainTitleProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
606 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
608 Any aRet;
611 aRet <<= TitleHelper::getTitle( TitleHelper::MAIN_TITLE, m_spChart2ModelContact->getChartModel() ).is();
613 catch (const uno::Exception& ex)
615 ASSERT_EXCEPTION( ex );
617 return aRet;
620 Any WrappedHasMainTitleProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
621 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
623 Any aRet;
624 aRet <<= sal_False;
625 return aRet;
628 //PROP_DOCUMENT_HAS_SUB_TITLE
629 class WrappedHasSubTitleProperty : public WrappedProperty
631 public:
632 WrappedHasSubTitleProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
633 virtual ~WrappedHasSubTitleProperty();
635 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
636 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
638 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
639 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
641 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
642 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
644 private: //member
645 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
648 WrappedHasSubTitleProperty::WrappedHasSubTitleProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
649 : WrappedProperty("HasSubTitle",OUString())
650 , m_spChart2ModelContact( spChart2ModelContact )
654 WrappedHasSubTitleProperty::~WrappedHasSubTitleProperty()
658 void WrappedHasSubTitleProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
659 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
661 bool bNewValue = true;
662 if( ! (rOuterValue >>= bNewValue) )
663 throw lang::IllegalArgumentException("Property HasSubTitle requires value of type boolean", 0, 0 );
667 if( bNewValue )
668 TitleHelper::createTitle( TitleHelper::SUB_TITLE, "sub-title", m_spChart2ModelContact->getChartModel(), m_spChart2ModelContact->m_xContext );
669 else
670 TitleHelper::removeTitle( TitleHelper::SUB_TITLE, m_spChart2ModelContact->getChartModel() );
672 catch (const uno::Exception& ex)
674 ASSERT_EXCEPTION( ex );
678 Any WrappedHasSubTitleProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const
679 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
681 Any aRet;
684 aRet <<= TitleHelper::getTitle( TitleHelper::SUB_TITLE, m_spChart2ModelContact->getChartModel() ).is();
686 catch (const uno::Exception& ex)
688 ASSERT_EXCEPTION( ex );
690 return aRet;
693 Any WrappedHasSubTitleProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
694 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
696 Any aRet;
697 aRet <<= sal_False;
698 return aRet;
701 ChartDocumentWrapper::ChartDocumentWrapper(
702 const Reference< uno::XComponentContext > & xContext ) :
703 m_spChart2ModelContact( new Chart2ModelContact( xContext ) ),
704 m_bUpdateAddIn( true ),
705 m_bIsDisposed( false )
709 ChartDocumentWrapper::~ChartDocumentWrapper()
711 stopAllComponentListening();
714 // ____ XInterface (for new interfaces) ____
715 uno::Any SAL_CALL ChartDocumentWrapper::queryInterface( const uno::Type& aType )
716 throw (uno::RuntimeException, std::exception)
718 if( m_xDelegator.is())
719 // calls queryAggregation if the delegator doesn't know aType
720 return m_xDelegator->queryInterface( aType );
721 else
722 return queryAggregation( aType );
725 // ____ chart::XChartDocument (old API wrapper) ____
726 Reference< drawing::XShape > SAL_CALL ChartDocumentWrapper::getTitle()
727 throw (uno::RuntimeException, std::exception)
729 if( !m_xTitle.is() )
731 ControllerLockGuardUNO aCtrlLockGuard( Reference< frame::XModel >( m_spChart2ModelContact->getChart2Document(), uno::UNO_QUERY ));
732 m_xTitle = new TitleWrapper( TitleHelper::MAIN_TITLE, m_spChart2ModelContact );
734 return m_xTitle;
737 Reference< drawing::XShape > SAL_CALL ChartDocumentWrapper::getSubTitle()
738 throw (uno::RuntimeException, std::exception)
740 if( !m_xSubTitle.is() )
742 ControllerLockGuardUNO aCtrlLockGuard( Reference< frame::XModel >( m_spChart2ModelContact->getChart2Document(), uno::UNO_QUERY ));
743 m_xSubTitle = new TitleWrapper( TitleHelper::SUB_TITLE, m_spChart2ModelContact );
745 return m_xSubTitle;
748 Reference< drawing::XShape > SAL_CALL ChartDocumentWrapper::getLegend()
749 throw (uno::RuntimeException, std::exception)
751 if( ! m_xLegend.is())
753 m_xLegend = new LegendWrapper( m_spChart2ModelContact );
754 Reference< lang::XComponent > xComp( m_xLegend, uno::UNO_QUERY );
757 return m_xLegend;
760 Reference< beans::XPropertySet > SAL_CALL ChartDocumentWrapper::getArea()
761 throw (uno::RuntimeException, std::exception)
763 if( ! m_xArea.is())
765 m_xArea.set( new AreaWrapper( m_spChart2ModelContact ) );
766 Reference< lang::XComponent > xComp( m_xArea, uno::UNO_QUERY );
769 return m_xArea;
772 Reference< XDiagram > SAL_CALL ChartDocumentWrapper::getDiagram()
773 throw (uno::RuntimeException, std::exception)
775 if( !m_xDiagram.is() )
779 m_xDiagram = new DiagramWrapper( m_spChart2ModelContact );
781 catch (const uno::Exception& ex)
783 ASSERT_EXCEPTION( ex );
787 return m_xDiagram;
790 void SAL_CALL ChartDocumentWrapper::setDiagram( const Reference< XDiagram >& xDiagram )
791 throw (uno::RuntimeException, std::exception)
793 uno::Reference< util::XRefreshable > xAddIn( xDiagram, uno::UNO_QUERY );
794 if( xAddIn.is() )
796 setAddIn( xAddIn );
798 else if( xDiagram.is() && xDiagram != m_xDiagram )
800 // set new wrapped diagram at new chart. This requires the old
801 // diagram given as parameter to implement the new interface. If
802 // this is not possible throw an exception
803 Reference< chart2::XDiagramProvider > xNewDiaProvider( xDiagram, uno::UNO_QUERY_THROW );
804 Reference< chart2::XDiagram > xNewDia( xNewDiaProvider->getDiagram());
808 Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
809 if( xChartDoc.is() )
811 // set the new diagram
812 xChartDoc->setFirstDiagram( xNewDia );
813 m_xDiagram = xDiagram;
816 catch (const uno::Exception& ex)
818 ASSERT_EXCEPTION( ex );
823 Reference< XChartData > SAL_CALL ChartDocumentWrapper::getData()
824 throw (uno::RuntimeException, std::exception)
826 if( !m_xChartData.is() )
828 m_xChartData.set( new ChartDataWrapper( m_spChart2ModelContact ) );
830 //@todo: check hasInternalDataProvider also in else?
832 return m_xChartData;
835 void SAL_CALL ChartDocumentWrapper::attachData( const Reference< XChartData >& xNewData )
836 throw (uno::RuntimeException, std::exception)
838 if( !xNewData.is() )
839 return;
841 // /-- locked controllers
842 ControllerLockGuardUNO aCtrlLockGuard( Reference< frame::XModel >( m_spChart2ModelContact->getChart2Document(), uno::UNO_QUERY ));
843 m_xChartData.set( new ChartDataWrapper( m_spChart2ModelContact, xNewData ) );
844 // \-- locked controllers
847 // ____ XModel ____
848 sal_Bool SAL_CALL ChartDocumentWrapper::attachResource(
849 const OUString& URL,
850 const Sequence< beans::PropertyValue >& Arguments )
851 throw (uno::RuntimeException, std::exception)
853 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
854 if( xModel.is() )
855 return xModel->attachResource( URL, Arguments );
856 return sal_False;
859 OUString SAL_CALL ChartDocumentWrapper::getURL()
860 throw (uno::RuntimeException, std::exception)
862 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
863 if( xModel.is() )
864 return xModel->getURL();
865 return OUString();
868 Sequence< beans::PropertyValue > SAL_CALL ChartDocumentWrapper::getArgs()
869 throw (uno::RuntimeException, std::exception)
871 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
872 if( xModel.is() )
873 return xModel->getArgs();
874 return Sequence< beans::PropertyValue >();
877 void SAL_CALL ChartDocumentWrapper::connectController( const Reference< frame::XController >& Controller )
878 throw (uno::RuntimeException, std::exception)
880 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
881 if( xModel.is() )
882 xModel->connectController( Controller );
885 void SAL_CALL ChartDocumentWrapper::disconnectController(
886 const Reference< frame::XController >& Controller )
887 throw (uno::RuntimeException, std::exception)
889 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
890 if( xModel.is() )
891 xModel->disconnectController( Controller );
894 void SAL_CALL ChartDocumentWrapper::lockControllers()
895 throw (uno::RuntimeException, std::exception)
897 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
898 if( xModel.is() )
899 xModel->lockControllers();
902 void SAL_CALL ChartDocumentWrapper::unlockControllers()
903 throw (uno::RuntimeException, std::exception)
905 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
906 if( xModel.is() )
907 xModel->unlockControllers();
910 sal_Bool SAL_CALL ChartDocumentWrapper::hasControllersLocked()
911 throw (uno::RuntimeException, std::exception)
913 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
914 if( xModel.is() )
915 return xModel->hasControllersLocked();
916 return sal_False;
919 Reference< frame::XController > SAL_CALL ChartDocumentWrapper::getCurrentController()
920 throw (uno::RuntimeException, std::exception)
922 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
923 if( xModel.is() )
924 return xModel->getCurrentController();
925 return 0;
928 void SAL_CALL ChartDocumentWrapper::setCurrentController(
929 const Reference< frame::XController >& Controller )
930 throw (container::NoSuchElementException,
931 uno::RuntimeException, std::exception)
933 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
934 if( xModel.is() )
935 xModel->setCurrentController( Controller );
938 Reference< uno::XInterface > SAL_CALL ChartDocumentWrapper::getCurrentSelection()
939 throw (uno::RuntimeException, std::exception)
941 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
942 if( xModel.is() )
943 return xModel->getCurrentSelection();
944 return 0;
947 // ____ XComponent ____
948 void SAL_CALL ChartDocumentWrapper::dispose()
949 throw (uno::RuntimeException, std::exception)
951 if( m_bIsDisposed )
952 throw lang::DisposedException("ChartDocumentWrapper is disposed",
953 static_cast< ::cppu::OWeakObject* >( this ));
955 m_bIsDisposed = true;
959 Reference< lang::XComponent > xFormerDelegator( m_xDelegator, uno::UNO_QUERY );
960 DisposeHelper::DisposeAndClear( m_xTitle );
961 DisposeHelper::DisposeAndClear( m_xSubTitle );
962 DisposeHelper::DisposeAndClear( m_xLegend );
963 DisposeHelper::DisposeAndClear( m_xChartData );
964 DisposeHelper::DisposeAndClear( m_xDiagram );
965 DisposeHelper::DisposeAndClear( m_xArea );
966 m_xChartView.set( 0 );
967 m_xShapeFactory.set( 0 );
968 m_xDelegator.set( 0 );
970 clearWrappedPropertySet();
971 m_spChart2ModelContact->clear();
972 impl_resetAddIn();
974 stopAllComponentListening();
978 if( xFormerDelegator.is())
979 xFormerDelegator->dispose();
981 catch (const lang::DisposedException&)
983 // this is ok, don't panic
986 catch (const uno::Exception &ex)
988 ASSERT_EXCEPTION( ex );
992 void ChartDocumentWrapper::impl_resetAddIn()
994 Reference< util::XRefreshable > xAddIn( m_xAddIn );
995 m_xAddIn.set( 0 );
997 if( xAddIn.is() )
1001 //make sure that the add-in does not hold a references to us anymore:
1002 Reference< lang::XComponent > xComp( xAddIn, uno::UNO_QUERY );
1003 if( xComp.is())
1004 xComp->dispose();
1005 else
1007 uno::Reference< lang::XInitialization > xInit( xAddIn, uno::UNO_QUERY );
1008 if( xInit.is() )
1010 uno::Any aParam;
1011 uno::Reference< com::sun::star::chart::XChartDocument > xDoc( 0 );
1012 aParam <<= xDoc;
1013 uno::Sequence< uno::Any > aSeq( &aParam, 1 );
1014 xInit->initialize( aSeq );
1018 catch (const uno::RuntimeException& ex)
1020 ASSERT_EXCEPTION( ex );
1022 catch (const uno::Exception& ex)
1024 ASSERT_EXCEPTION( ex );
1029 void ChartDocumentWrapper::setBaseDiagram( const OUString& rBaseDiagram )
1031 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getChartModel() );
1032 m_aBaseDiagram = rBaseDiagram;
1034 uno::Reference< XDiagram > xDiagram( ChartDocumentWrapper::createInstance( rBaseDiagram ), uno::UNO_QUERY );
1035 if( xDiagram.is() )
1036 this->setDiagram( xDiagram );
1039 void ChartDocumentWrapper::setAddIn( const Reference< util::XRefreshable >& xAddIn )
1041 if( m_xAddIn == xAddIn )
1042 return;
1044 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getChartModel() );
1045 impl_resetAddIn();
1046 m_xAddIn = xAddIn;
1047 // initialize AddIn with this as chart document
1048 uno::Reference< lang::XInitialization > xInit( m_xAddIn, uno::UNO_QUERY );
1049 if( xInit.is() )
1051 uno::Any aParam;
1052 uno::Reference< XChartDocument > xDoc( (XChartDocument*)this, uno::UNO_QUERY );
1053 aParam <<= xDoc;
1054 uno::Sequence< uno::Any > aSeq( &aParam, 1 );
1055 xInit->initialize( aSeq );
1059 void ChartDocumentWrapper::setUpdateAddIn( bool bUpdateAddIn )
1061 m_bUpdateAddIn = bUpdateAddIn;
1064 Reference< drawing::XShapes > ChartDocumentWrapper::getAdditionalShapes() const
1066 // get additional non-chart shapes for XML export
1067 uno::Reference< drawing::XShapes > xFoundShapes;
1068 uno::Reference< drawing::XDrawPage > xDrawPage( this->impl_getDrawPage() );
1070 uno::Reference< drawing::XShapes > xDrawPageShapes( xDrawPage, uno::UNO_QUERY );
1071 if( !xDrawPageShapes.is() )
1072 return xFoundShapes;
1074 uno::Reference<drawing::XShapes> xChartRoot( DrawModelWrapper::getChartRootShape( xDrawPage ) );
1076 // iterate 'flat' over all top-level objects
1077 // and determine all that are no chart objects
1078 ::std::vector< uno::Reference< drawing::XShape > > aShapeVector;
1079 sal_Int32 nSubCount = xDrawPageShapes->getCount();
1080 uno::Reference< drawing::XShape > xShape;
1081 for( sal_Int32 nS = 0; nS < nSubCount; nS++ )
1083 if( xDrawPageShapes->getByIndex( nS ) >>= xShape )
1085 if( xShape.is() && xChartRoot!=xShape )
1086 aShapeVector.push_back( xShape );
1090 if( !aShapeVector.empty() )
1092 // create a shape collection
1093 xFoundShapes = uno::Reference< drawing::XShapes >( drawing::ShapeCollection::create(
1094 comphelper::getProcessComponentContext()), uno::UNO_QUERY );
1096 OSL_ENSURE( xFoundShapes.is(), "Couldn't create a shape collection!" );
1097 if( xFoundShapes.is())
1099 ::std::vector< uno::Reference< drawing::XShape > >::iterator aIter;
1100 for( aIter = aShapeVector.begin(); aIter != aShapeVector.end(); ++aIter )
1101 xFoundShapes->add( *aIter );
1105 return xFoundShapes;
1108 void SAL_CALL ChartDocumentWrapper::addEventListener( const Reference< lang::XEventListener >& xListener )
1109 throw (uno::RuntimeException, std::exception)
1111 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
1112 if( xModel.is() )
1113 xModel->addEventListener( xListener );
1116 void SAL_CALL ChartDocumentWrapper::removeEventListener( const Reference< lang::XEventListener >& aListener )
1117 throw (uno::RuntimeException, std::exception)
1119 Reference< frame::XModel > xModel( m_spChart2ModelContact->getChartModel() );
1120 if( xModel.is() )
1121 xModel->removeEventListener( aListener );
1124 // ____ XDrawPageSupplier ____
1125 uno::Reference< drawing::XDrawPage > SAL_CALL ChartDocumentWrapper::getDrawPage()
1126 throw (uno::RuntimeException, std::exception)
1128 return this->impl_getDrawPage();
1131 uno::Reference< drawing::XDrawPage > ChartDocumentWrapper::impl_getDrawPage() const
1132 throw (uno::RuntimeException)
1134 return m_spChart2ModelContact->getDrawPage();
1137 namespace {
1139 uno::Reference< lang::XMultiServiceFactory > getShapeFactory(uno::Reference<uno::XInterface> xChartView)
1141 Reference< lang::XUnoTunnel> xUnoTunnel(xChartView,uno::UNO_QUERY);
1142 if(xUnoTunnel.is())
1144 ExplicitValueProvider* pProvider = reinterpret_cast<ExplicitValueProvider*>(xUnoTunnel->getSomething(
1145 ExplicitValueProvider::getUnoTunnelId() ));
1146 if( pProvider )
1147 return pProvider->getDrawModelWrapper()->getShapeFactory();
1150 return uno::Reference< lang::XMultiServiceFactory >();
1155 // ____ XMultiServiceFactory ____
1156 uno::Reference< uno::XInterface > SAL_CALL ChartDocumentWrapper::createInstance(
1157 const OUString& aServiceSpecifier )
1158 throw (uno::Exception,
1159 uno::RuntimeException, std::exception)
1161 uno::Reference< uno::XInterface > xResult;
1163 Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
1164 if( !xChartDoc.is() )
1165 return xResult;
1167 bool bServiceFound = false;
1168 tServiceNameMap & rMap = lcl_getStaticServiceNameMap();
1170 tServiceNameMap::const_iterator aIt( rMap.find( aServiceSpecifier ));
1171 if( aIt != rMap.end())
1173 bool bCreateDiagram = false;
1174 uno::Reference< lang::XMultiServiceFactory > xManagerFact(
1175 xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
1176 uno::Reference< chart2::XChartTypeTemplate > xTemplate;
1178 switch( (*aIt).second )
1180 case SERVICE_NAME_AREA_DIAGRAM:
1181 if( xManagerFact.is())
1183 xTemplate.set(
1184 xManagerFact->createInstance("com.sun.star.chart2.template.Area"),
1185 uno::UNO_QUERY );
1186 bCreateDiagram = true;
1188 break;
1189 case SERVICE_NAME_BAR_DIAGRAM:
1190 if( xManagerFact.is())
1192 // this is for bar and column (the latter is the default if
1193 // no "Vertical=false" property was set)
1194 xTemplate.set(
1195 xManagerFact->createInstance("com.sun.star.chart2.template.Column"),
1196 uno::UNO_QUERY );
1197 bCreateDiagram = true;
1199 break;
1200 case SERVICE_NAME_DONUT_DIAGRAM:
1201 if( xManagerFact.is())
1203 xTemplate.set(
1204 xManagerFact->createInstance("com.sun.star.chart2.template.Donut"),
1205 uno::UNO_QUERY );
1206 bCreateDiagram = true;
1208 break;
1209 case SERVICE_NAME_LINE_DIAGRAM:
1210 if( xManagerFact.is())
1212 xTemplate.set(
1213 xManagerFact->createInstance("com.sun.star.chart2.template.Line"),
1214 uno::UNO_QUERY );
1215 bCreateDiagram = true;
1217 break;
1218 case SERVICE_NAME_NET_DIAGRAM:
1219 if( xManagerFact.is())
1221 xTemplate.set(
1222 xManagerFact->createInstance("com.sun.star.chart2.template.Net"),
1223 uno::UNO_QUERY );
1224 bCreateDiagram = true;
1226 break;
1227 case SERVICE_NAME_FILLED_NET_DIAGRAM:
1228 if( xManagerFact.is())
1230 xTemplate.set(
1231 xManagerFact->createInstance("com.sun.star.chart2.template.FilledNet"),
1232 uno::UNO_QUERY );
1233 bCreateDiagram = true;
1235 break;
1236 case SERVICE_NAME_PIE_DIAGRAM:
1237 if( xManagerFact.is())
1239 xTemplate.set(
1240 xManagerFact->createInstance("com.sun.star.chart2.template.Pie"),
1241 uno::UNO_QUERY );
1242 bCreateDiagram = true;
1244 break;
1245 case SERVICE_NAME_STOCK_DIAGRAM:
1246 if( xManagerFact.is())
1248 xTemplate.set(
1249 xManagerFact->createInstance("com.sun.star.chart2.template.StockLowHighClose"),
1250 uno::UNO_QUERY );
1251 bCreateDiagram = true;
1253 break;
1254 case SERVICE_NAME_XY_DIAGRAM:
1255 if( xManagerFact.is())
1257 xTemplate.set(
1258 xManagerFact->createInstance("com.sun.star.chart2.template.ScatterLineSymbol"),
1259 uno::UNO_QUERY );
1260 bCreateDiagram = true;
1262 break;
1264 case SERVICE_NAME_BUBBLE_DIAGRAM:
1265 if( xManagerFact.is())
1267 xTemplate.set(
1268 xManagerFact->createInstance("com.sun.star.chart2.template.Bubble"),
1269 uno::UNO_QUERY );
1270 bCreateDiagram = true;
1272 break;
1273 case SERVICE_NAME_GL3DBAR_DIAGRAM:
1274 if( xManagerFact.is())
1276 xTemplate.set(
1277 xManagerFact->createInstance("com.sun.star.chart2.template.GL3DBar"),
1278 uno::UNO_QUERY );
1279 bCreateDiagram = true;
1281 break;
1283 case SERVICE_NAME_DASH_TABLE:
1284 case SERVICE_NAME_GARDIENT_TABLE:
1285 case SERVICE_NAME_HATCH_TABLE:
1286 case SERVICE_NAME_BITMAP_TABLE:
1287 case SERVICE_NAME_TRANSP_GRADIENT_TABLE:
1288 case SERVICE_NAME_MARKER_TABLE:
1290 uno::Reference< lang::XMultiServiceFactory > xTableFactory( xChartDoc, uno::UNO_QUERY );
1291 OSL_ENSURE( xTableFactory.get() != this, "new model is expected to implement service factory for gradient table etc" );
1292 if( xTableFactory.is() && xTableFactory.get() != this )
1293 xResult.set( xTableFactory->createInstance( aIt->first ), uno::UNO_QUERY );
1295 break;
1297 case SERVICE_NAME_NAMESPACE_MAP:
1298 break;
1299 case SERVICE_NAME_EXPORT_GRAPHIC_RESOLVER:
1300 break;
1301 case SERVICE_NAME_IMPORT_GRAPHIC_RESOLVER:
1302 break;
1305 if( bCreateDiagram && xTemplate.is() )
1309 uno::Reference< chart2::XDiagram > xDia( xChartDoc->getFirstDiagram());
1310 if( xDia.is())
1312 // locked controllers
1313 Reference< frame::XModel > xModel( xChartDoc, uno::UNO_QUERY );
1314 ControllerLockGuardUNO aCtrlLockGuard( xModel );
1315 Reference< chart2::XDiagram > xDiagram = ChartModelHelper::findDiagram( xModel );
1316 ThreeDLookScheme e3DScheme = ThreeDHelper::detectScheme( xDiagram );
1317 Reference< lang::XMultiServiceFactory > xTemplateManager( xChartDoc->getChartTypeManager(), uno::UNO_QUERY );
1318 DiagramHelper::tTemplateWithServiceName aTemplateWithService(
1319 DiagramHelper::getTemplateForDiagram( xDiagram, xTemplateManager ));
1320 if( aTemplateWithService.first.is())
1321 aTemplateWithService.first->resetStyles( xDiagram );//#i109371#
1322 xTemplate->changeDiagram( xDiagram );
1323 if( AllSettings::GetMathLayoutRTL() )
1324 AxisHelper::setRTLAxisLayout( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 ) );
1325 ThreeDHelper::setScheme( xDiagram, e3DScheme );
1327 else
1329 // locked controllers
1330 ControllerLockGuardUNO aCtrlLockGuard( Reference< frame::XModel >( xChartDoc, uno::UNO_QUERY ));
1331 xDia.set( xTemplate->createDiagramByDataSource(
1332 uno::Reference< chart2::data::XDataSource >(),
1333 uno::Sequence< beans::PropertyValue >()));
1334 xChartDoc->setFirstDiagram( xDia );
1337 xResult = static_cast< ::cppu::OWeakObject* >( new DiagramWrapper( m_spChart2ModelContact ));
1339 catch (const uno::Exception& ex)
1341 ASSERT_EXCEPTION( ex );
1345 bServiceFound = true;
1347 else if( aServiceSpecifier == "com.sun.star.comp.chart2.DataSeriesWrapper" )
1349 Reference< beans::XPropertySet > xDataSeries( new DataSeriesPointWrapper( m_spChart2ModelContact ) );
1350 xResult.set( xDataSeries );
1351 bServiceFound = true;
1353 else if( aServiceSpecifier == CHART_VIEW_SERVICE_NAME )
1355 if( !m_xChartView.is() )
1357 Reference< lang::XMultiServiceFactory > xFact(
1358 m_spChart2ModelContact->m_xContext->getServiceManager(), uno::UNO_QUERY_THROW );
1359 if( xFact.is() )
1361 Reference< lang::XInitialization > xViewInit( xFact->createInstance(
1362 CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
1363 if(xViewInit.is())
1367 m_xChartView = xViewInit;
1369 Sequence< Any > aArguments(2);
1370 Reference<frame::XModel> xModel(this);
1371 aArguments[0]=uno::makeAny(xModel);
1372 bool bRefreshAddIn = true;
1373 aArguments[1]=uno::makeAny(bRefreshAddIn);
1374 xViewInit->initialize(aArguments);
1376 catch (const uno::Exception& ex)
1378 ASSERT_EXCEPTION( ex );
1383 xResult.set( m_xChartView );
1384 bServiceFound = true;
1386 else
1388 // try to create a shape
1391 if( !m_xShapeFactory.is() && m_xChartView.is() )
1393 m_xShapeFactory = getShapeFactory( m_xChartView );
1395 else
1397 ChartModel* pModel = m_spChart2ModelContact->getModel();
1398 if(pModel)
1400 m_xChartView = pModel->getChartView();
1401 m_xShapeFactory = getShapeFactory( m_xChartView );
1405 if( m_xShapeFactory.is() )
1407 xResult = m_xShapeFactory->createInstance( aServiceSpecifier );
1408 bServiceFound = true;
1411 catch (const uno::Exception&)
1413 // couldn't create shape
1417 // finally, try to create an addin
1418 if( !bServiceFound )
1422 Reference< lang::XMultiServiceFactory > xFact(
1423 m_spChart2ModelContact->m_xContext->getServiceManager(), uno::UNO_QUERY_THROW );
1424 if( xFact.is() )
1426 uno::Reference< util::XRefreshable > xAddIn(
1427 xFact->createInstance( aServiceSpecifier ), uno::UNO_QUERY );
1428 if( xAddIn.is() )
1430 xResult = xAddIn;
1431 bServiceFound = true;
1435 catch (const uno::Exception&)
1437 // couldn't create service
1441 return xResult;
1444 uno::Reference< uno::XInterface > SAL_CALL ChartDocumentWrapper::createInstanceWithArguments(
1445 const OUString& ServiceSpecifier,
1446 const uno::Sequence< uno::Any >& Arguments )
1447 throw (uno::Exception,
1448 uno::RuntimeException, std::exception)
1450 OSL_ENSURE( Arguments.getLength(), "createInstanceWithArguments: Warning: Arguments are ignored" );
1451 (void)(Arguments);
1453 return createInstance( ServiceSpecifier );
1456 uno::Sequence< OUString > SAL_CALL ChartDocumentWrapper::getAvailableServiceNames()
1457 throw (uno::RuntimeException, std::exception)
1459 tServiceNameMap & rMap = lcl_getStaticServiceNameMap();
1460 uno::Sequence< OUString > aResult( rMap.size());
1462 ::std::transform( rMap.begin(), rMap.end(),
1463 aResult.getArray(),
1464 ::o3tl::select1st< tServiceNameMap::value_type >() );
1466 return aResult;
1470 // ____ XAggregation ____
1471 void SAL_CALL ChartDocumentWrapper::setDelegator(
1472 const uno::Reference< uno::XInterface >& rDelegator )
1473 throw (uno::RuntimeException, std::exception)
1475 if( m_bIsDisposed )
1477 if( rDelegator.is() )
1478 throw lang::DisposedException("ChartDocumentWrapper is disposed",
1479 static_cast< ::cppu::OWeakObject* >( this ));
1480 else
1481 return;
1484 if( rDelegator.is())
1486 m_xDelegator = rDelegator;
1487 m_spChart2ModelContact->setModel( uno::Reference< frame::XModel >(m_xDelegator, uno::UNO_QUERY) );
1489 else
1491 // this is a sort of dispose() from the new model,so release resources here
1494 this->dispose();
1496 catch (const uno::Exception& ex)
1498 ASSERT_EXCEPTION( ex );
1503 uno::Any SAL_CALL ChartDocumentWrapper::queryAggregation( const uno::Type& rType )
1504 throw (uno::RuntimeException, std::exception)
1506 return ChartDocumentWrapper_Base::queryInterface( rType );
1509 // ____ ::utl::OEventListenerAdapter ____
1510 void ChartDocumentWrapper::_disposing( const lang::EventObject& rSource )
1512 if( rSource.Source == m_xTitle )
1513 m_xTitle.set( 0 );
1514 else if( rSource.Source == m_xSubTitle )
1515 m_xSubTitle.set( 0 );
1516 else if( rSource.Source == m_xLegend )
1517 m_xLegend.set( 0 );
1518 else if( rSource.Source == m_xChartData )
1519 m_xChartData.set( 0 );
1520 else if( rSource.Source == m_xDiagram )
1521 m_xDiagram.set( 0 );
1522 else if( rSource.Source == m_xArea )
1523 m_xArea.set( 0 );
1524 else if( rSource.Source == m_xAddIn )
1525 m_xAddIn.set( 0 );
1526 else if( rSource.Source == m_xChartView )
1527 m_xChartView.set( 0 );
1530 // WrappedPropertySet
1531 Reference< beans::XPropertySet > ChartDocumentWrapper::getInnerPropertySet()
1533 return 0;
1535 const Sequence< beans::Property >& ChartDocumentWrapper::getPropertySequence()
1537 return *StaticChartDocumentWrapperPropertyArray::get();
1540 const std::vector< WrappedProperty* > ChartDocumentWrapper::createWrappedProperties()
1542 ::std::vector< ::chart::WrappedProperty* > aWrappedProperties;
1543 aWrappedProperties.push_back( new WrappedDataSourceLabelsInFirstRowProperty( m_spChart2ModelContact ) );
1544 aWrappedProperties.push_back( new WrappedDataSourceLabelsInFirstColumnProperty( m_spChart2ModelContact ) );
1545 aWrappedProperties.push_back( new WrappedHasLegendProperty( m_spChart2ModelContact ) );
1546 aWrappedProperties.push_back( new WrappedHasMainTitleProperty( m_spChart2ModelContact ) );
1547 aWrappedProperties.push_back( new WrappedHasSubTitleProperty( m_spChart2ModelContact ) );
1548 aWrappedProperties.push_back( new WrappedAddInProperty( *this ) );
1549 aWrappedProperties.push_back( new WrappedBaseDiagramProperty( *this ) );
1550 aWrappedProperties.push_back( new WrappedAdditionalShapesProperty( *this ) );
1551 aWrappedProperties.push_back( new WrappedRefreshAddInAllowedProperty( *this ) );
1552 aWrappedProperties.push_back( new WrappedIgnoreProperty("NullDate",Any() ) ); // i99104
1553 aWrappedProperties.push_back( new WrappedIgnoreProperty("EnableComplexChartTypes", uno::makeAny(sal_True) ) );
1554 aWrappedProperties.push_back( new WrappedIgnoreProperty("EnableDataTableDialog", uno::makeAny(sal_True) ) );
1556 return aWrappedProperties;
1559 uno::Sequence< OUString > ChartDocumentWrapper::getSupportedServiceNames_Static()
1561 uno::Sequence< OUString > aServices( 4 );
1562 aServices[ 0 ] = "com.sun.star.chart.ChartDocument";
1563 aServices[ 1 ] = CHART_CHARTAPIWRAPPER_SERVICE_NAME;
1564 aServices[ 2 ] = "com.sun.star.xml.UserDefinedAttributesSupplier";
1565 aServices[ 3 ] = "com.sun.star.beans.PropertySet";
1566 return aServices;
1569 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
1570 OUString SAL_CALL ChartDocumentWrapper::getImplementationName()
1571 throw( css::uno::RuntimeException, std::exception )
1573 return getImplementationName_Static();
1576 OUString ChartDocumentWrapper::getImplementationName_Static()
1578 return OUString(CHART_CHARTAPIWRAPPER_IMPLEMENTATION_NAME);
1581 sal_Bool SAL_CALL ChartDocumentWrapper::supportsService( const OUString& rServiceName )
1582 throw( css::uno::RuntimeException, std::exception )
1584 return cppu::supportsService(this, rServiceName);
1587 css::uno::Sequence< OUString > SAL_CALL ChartDocumentWrapper::getSupportedServiceNames()
1588 throw( css::uno::RuntimeException, std::exception )
1590 return getSupportedServiceNames_Static();
1593 } // namespace wrapper
1594 } // namespace chart
1596 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
1597 com_sun_star_comp_chart2_ChartDocumentWrapper_get_implementation(css::uno::XComponentContext *context,
1598 css::uno::Sequence<css::uno::Any> const &)
1600 return cppu::acquire(new ::chart::wrapper::ChartDocumentWrapper(context));
1603 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */