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