fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / main / ChartController_Properties.cxx
blob4cc7a171d03162e7941080de97a3dc67be815d92
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 "ChartController.hxx"
21 #include "ChartWindow.hxx"
22 #include "chartview/DrawModelWrapper.hxx"
23 #include "ObjectIdentifier.hxx"
24 #include "chartview/ExplicitValueProvider.hxx"
25 #include "macros.hxx"
26 #include "dlg_ObjectProperties.hxx"
27 #include "dlg_View3D.hxx"
28 #include "dlg_InsertErrorBars.hxx"
29 #include "ViewElementListProvider.hxx"
30 #include "DataPointItemConverter.hxx"
31 #include "TextLabelItemConverter.hxx"
32 #include "AxisItemConverter.hxx"
33 #include "MultipleChartConverters.hxx"
34 #include "TitleItemConverter.hxx"
35 #include "LegendItemConverter.hxx"
36 #include "RegressionCurveItemConverter.hxx"
37 #include "RegressionEquationItemConverter.hxx"
38 #include "ErrorBarItemConverter.hxx"
39 #include "ChartModelHelper.hxx"
40 #include "AxisHelper.hxx"
41 #include "TitleHelper.hxx"
42 #include "LegendHelper.hxx"
43 #include "ChartTypeHelper.hxx"
44 #include "ColorPerPointHelper.hxx"
45 #include "DiagramHelper.hxx"
46 #include "servicenames_charttypes.hxx"
47 #include "ControllerLockGuard.hxx"
48 #include "UndoGuard.hxx"
49 #include "ObjectNameProvider.hxx"
50 #include "ResId.hxx"
51 #include "Strings.hrc"
52 #include "ReferenceSizeProvider.hxx"
53 #include "RegressionCurveHelper.hxx"
54 #include <com/sun/star/chart2/XChartDocument.hpp>
56 #include <memory>
57 #include <boost/scoped_ptr.hpp>
59 #include <vcl/msgbox.hxx>
60 #include <vcl/svapp.hxx>
61 #include <osl/mutex.hxx>
62 #include <svx/ActionDescriptionProvider.hxx>
64 namespace chart
66 using namespace ::com::sun::star;
67 using namespace ::com::sun::star::chart2;
68 using ::com::sun::star::uno::Reference;
70 namespace
73 wrapper::ItemConverter* createItemConverter(
74 const OUString & aObjectCID, const uno::Reference<frame::XModel>& xChartModel,
75 const uno::Reference<uno::XComponentContext>& xContext, SdrModel& rDrawModel,
76 ExplicitValueProvider* pExplicitValueProvider, ReferenceSizeProvider* pRefSizeProvider )
78 wrapper::ItemConverter* pItemConverter=NULL;
80 //get type of selected object
81 ObjectType eObjectType = ObjectIdentifier::getObjectType( aObjectCID );
82 if( OBJECTTYPE_UNKNOWN==eObjectType )
84 OSL_FAIL("unknown ObjectType");
85 return NULL;
88 OUString aParticleID = ObjectIdentifier::getParticleID( aObjectCID );
89 bool bAffectsMultipleObjects = aParticleID == "ALLELEMENTS";
90 if( !bAffectsMultipleObjects )
92 uno::Reference< beans::XPropertySet > xObjectProperties =
93 ObjectIdentifier::getObjectPropertySet( aObjectCID, xChartModel );
94 if(!xObjectProperties.is())
95 return NULL;
96 //create itemconverter for a single object
97 switch(eObjectType)
99 case OBJECTTYPE_PAGE:
100 pItemConverter = new wrapper::GraphicPropertyItemConverter(
101 xObjectProperties, rDrawModel.GetItemPool(),
102 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
103 wrapper::GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES );
104 break;
105 case OBJECTTYPE_TITLE:
107 boost::scoped_ptr<awt::Size> pRefSize;
108 if (pRefSizeProvider)
109 pRefSize.reset(new awt::Size(pRefSizeProvider->getPageSize()));
111 pItemConverter = new wrapper::TitleItemConverter(
112 xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
113 uno::Reference<lang::XMultiServiceFactory>(xChartModel, uno::UNO_QUERY),
114 pRefSize.get());
116 break;
117 case OBJECTTYPE_LEGEND:
119 boost::scoped_ptr<awt::Size> pRefSize;
120 if (pRefSizeProvider)
121 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
123 pItemConverter = new wrapper::LegendItemConverter(
124 xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
125 uno::Reference<lang::XMultiServiceFactory>(xChartModel, uno::UNO_QUERY),
126 pRefSize.get());
128 break;
129 case OBJECTTYPE_LEGEND_ENTRY:
130 break;
131 case OBJECTTYPE_DIAGRAM:
132 break;
133 case OBJECTTYPE_DIAGRAM_WALL:
134 case OBJECTTYPE_DIAGRAM_FLOOR:
135 pItemConverter = new wrapper::GraphicPropertyItemConverter(
136 xObjectProperties, rDrawModel.GetItemPool(),
137 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
138 wrapper::GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES );
139 break;
140 case OBJECTTYPE_AXIS:
142 boost::scoped_ptr<awt::Size> pRefSize;
143 if (pRefSizeProvider)
144 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
146 uno::Reference< beans::XPropertySet > xDiaProp;
147 xDiaProp.set( ChartModelHelper::findDiagram( xChartModel ), uno::UNO_QUERY );
149 // the second property set contains the property CoordinateOrigin
150 // nOriginIndex is the index of the corresponding index of the
151 // origin (x=0, y=1, z=2)
153 ExplicitScaleData aExplicitScale;
154 ExplicitIncrementData aExplicitIncrement;
155 if( pExplicitValueProvider )
156 pExplicitValueProvider->getExplicitValuesForAxis(
157 uno::Reference< XAxis >( xObjectProperties, uno::UNO_QUERY ),
158 aExplicitScale, aExplicitIncrement );
160 pItemConverter = new wrapper::AxisItemConverter(
161 xObjectProperties, rDrawModel.GetItemPool(),
162 rDrawModel,
163 uno::Reference< chart2::XChartDocument >( xChartModel, uno::UNO_QUERY ),
164 &aExplicitScale, &aExplicitIncrement,
165 pRefSize.get() );
167 break;
168 case OBJECTTYPE_AXIS_UNITLABEL:
169 break;
170 case OBJECTTYPE_DATA_LABELS:
171 case OBJECTTYPE_DATA_LABEL:
173 boost::scoped_ptr<awt::Size> pRefSize;
174 if (pRefSizeProvider)
175 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
177 uno::Reference<XDataSeries> xSeries = ObjectIdentifier::getDataSeriesForCID(aObjectCID, xChartModel);
178 uno::Reference<XChartType> xChartType = ChartModelHelper::getChartTypeOfSeries(xChartModel, xSeries);
180 uno::Reference<XDiagram> xDiagram = ChartModelHelper::findDiagram(xChartModel);
182 bool bDataSeries = eObjectType == OBJECTTYPE_DATA_LABELS;
184 sal_Int32 nPointIndex = -1; /*-1 for whole series*/
185 if (!bDataSeries)
186 nPointIndex = aParticleID.toInt32();
188 sal_Int32 nNumberFormat = ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel(
189 xObjectProperties, xSeries, nPointIndex, xDiagram);
190 sal_Int32 nPercentNumberFormat = ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabel(
191 xObjectProperties,uno::Reference<util::XNumberFormatsSupplier>(xChartModel, uno::UNO_QUERY));
193 pItemConverter = new wrapper::TextLabelItemConverter(
194 xChartModel, xObjectProperties, xSeries,
195 rDrawModel.GetItemPool(), pRefSize.get(), bDataSeries,
196 nNumberFormat, nPercentNumberFormat);
198 break;
199 case OBJECTTYPE_DATA_SERIES:
200 case OBJECTTYPE_DATA_POINT:
202 boost::scoped_ptr<awt::Size> pRefSize;
203 if (pRefSizeProvider)
204 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
206 wrapper::GraphicPropertyItemConverter::eGraphicObjectType eMapTo =
207 wrapper::GraphicPropertyItemConverter::FILLED_DATA_POINT;
209 uno::Reference< XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel );
210 uno::Reference< XChartType > xChartType = ChartModelHelper::getChartTypeOfSeries( xChartModel, xSeries );
212 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
213 sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
214 if( !ChartTypeHelper::isSupportingAreaProperties( xChartType, nDimensionCount ) )
215 eMapTo = wrapper::GraphicPropertyItemConverter::LINE_DATA_POINT;
217 bool bDataSeries = eObjectType == OBJECTTYPE_DATA_SERIES;
219 //special color for pie chart:
220 bool bUseSpecialFillColor = false;
221 sal_Int32 nSpecialFillColor =0;
222 sal_Int32 nPointIndex = -1; /*-1 for whole series*/
223 if(!bDataSeries)
225 nPointIndex = aParticleID.toInt32();
226 uno::Reference< beans::XPropertySet > xSeriesProp( xSeries, uno::UNO_QUERY );
227 bool bVaryColorsByPoint = false;
228 if( xSeriesProp.is() &&
229 (xSeriesProp->getPropertyValue("VaryColorsByPoint") >>= bVaryColorsByPoint) &&
230 bVaryColorsByPoint )
232 if( !ColorPerPointHelper::hasPointOwnColor( xSeriesProp, nPointIndex, xObjectProperties ) )
234 bUseSpecialFillColor = true;
235 OSL_ASSERT( xDiagram.is());
236 uno::Reference< XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme() );
237 if( xColorScheme.is())
238 nSpecialFillColor = xColorScheme->getColorByIndex( nPointIndex );
242 sal_Int32 nNumberFormat=ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel( xObjectProperties, xSeries, nPointIndex, xDiagram );
243 sal_Int32 nPercentNumberFormat=ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabel(
244 xObjectProperties,uno::Reference< util::XNumberFormatsSupplier >(xChartModel, uno::UNO_QUERY));
246 pItemConverter = new wrapper::DataPointItemConverter( xChartModel, xContext,
247 xObjectProperties, xSeries, rDrawModel.GetItemPool(), rDrawModel,
248 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
249 eMapTo, pRefSize.get(), bDataSeries, bUseSpecialFillColor, nSpecialFillColor, true,
250 nNumberFormat, nPercentNumberFormat );
251 break;
253 case OBJECTTYPE_GRID:
254 case OBJECTTYPE_SUBGRID:
255 case OBJECTTYPE_DATA_AVERAGE_LINE:
256 pItemConverter = new wrapper::GraphicPropertyItemConverter(
257 xObjectProperties, rDrawModel.GetItemPool(),
258 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
259 wrapper::GraphicPropertyItemConverter::LINE_PROPERTIES );
260 break;
262 case OBJECTTYPE_DATA_ERRORS_X:
263 case OBJECTTYPE_DATA_ERRORS_Y:
264 case OBJECTTYPE_DATA_ERRORS_Z:
265 pItemConverter = new wrapper::ErrorBarItemConverter(
266 xChartModel, xObjectProperties, rDrawModel.GetItemPool(),
267 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
268 break;
270 case OBJECTTYPE_DATA_CURVE:
271 pItemConverter = new wrapper::RegressionCurveItemConverter(
272 xObjectProperties, uno::Reference< chart2::XRegressionCurveContainer >(
273 ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel ), uno::UNO_QUERY ),
274 rDrawModel.GetItemPool(), rDrawModel,
275 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
276 break;
277 case OBJECTTYPE_DATA_CURVE_EQUATION:
279 boost::scoped_ptr<awt::Size> pRefSize;
280 if (pRefSizeProvider)
281 pRefSize.reset(new awt::Size(pRefSizeProvider->getPageSize()));
283 pItemConverter = new wrapper::RegressionEquationItemConverter(
284 xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
285 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
286 pRefSize.get());
287 break;
289 case OBJECTTYPE_DATA_STOCK_RANGE:
290 break;
291 case OBJECTTYPE_DATA_STOCK_LOSS:
292 case OBJECTTYPE_DATA_STOCK_GAIN:
293 pItemConverter = new wrapper::GraphicPropertyItemConverter(
294 xObjectProperties, rDrawModel.GetItemPool(),
295 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
296 wrapper::GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES );
297 break;
298 default: //OBJECTTYPE_UNKNOWN
299 break;
302 else
304 //create itemconverter for a all objects of given type
305 switch(eObjectType)
307 case OBJECTTYPE_TITLE:
308 pItemConverter = new wrapper::AllTitleItemConverter( xChartModel, rDrawModel.GetItemPool(),
309 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
310 break;
311 case OBJECTTYPE_AXIS:
313 boost::scoped_ptr<awt::Size> pRefSize;
314 if (pRefSizeProvider)
315 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
317 pItemConverter = new wrapper::AllAxisItemConverter(
318 xChartModel, rDrawModel.GetItemPool(),
319 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ), pRefSize.get());
321 break;
322 case OBJECTTYPE_GRID:
323 case OBJECTTYPE_SUBGRID:
324 pItemConverter = new wrapper::AllGridItemConverter( xChartModel, rDrawModel.GetItemPool(),
325 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
326 break;
327 default: //for this type it is not supported to change all elements at once
328 break;
332 return pItemConverter;
335 OUString lcl_getTitleCIDForCommand( const OString& rDispatchCommand, const uno::Reference< frame::XModel > & xChartModel )
337 if( rDispatchCommand.equals("AllTitles"))
338 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_TITLE, "ALLELEMENTS" );
340 TitleHelper::eTitleType nTitleType( TitleHelper::MAIN_TITLE );
341 if( rDispatchCommand.equals("SubTitle") )
342 nTitleType = TitleHelper::SUB_TITLE;
343 else if( rDispatchCommand.equals("XTitle") )
344 nTitleType = TitleHelper::X_AXIS_TITLE;
345 else if( rDispatchCommand.equals("YTitle") )
346 nTitleType = TitleHelper::Y_AXIS_TITLE;
347 else if( rDispatchCommand.equals("ZTitle") )
348 nTitleType = TitleHelper::Z_AXIS_TITLE;
349 else if( rDispatchCommand.equals("SecondaryXTitle") )
350 nTitleType = TitleHelper::SECONDARY_X_AXIS_TITLE;
351 else if( rDispatchCommand.equals("SecondaryYTitle") )
352 nTitleType = TitleHelper::SECONDARY_Y_AXIS_TITLE;
354 uno::Reference< XTitle > xTitle( TitleHelper::getTitle( nTitleType, xChartModel ) );
355 return ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, xChartModel );
358 OUString lcl_getAxisCIDForCommand( const OString& rDispatchCommand, const uno::Reference< frame::XModel >& xChartModel )
360 if( rDispatchCommand.equals("DiagramAxisAll"))
361 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_AXIS, "ALLELEMENTS" );
363 sal_Int32 nDimensionIndex=0;
364 bool bMainAxis=true;
365 if( rDispatchCommand.equals("DiagramAxisX"))
367 nDimensionIndex=0; bMainAxis=true;
369 else if( rDispatchCommand.equals("DiagramAxisY"))
371 nDimensionIndex=1; bMainAxis=true;
373 else if( rDispatchCommand.equals("DiagramAxisZ"))
375 nDimensionIndex=2; bMainAxis=true;
377 else if( rDispatchCommand.equals("DiagramAxisA"))
379 nDimensionIndex=0; bMainAxis=false;
381 else if( rDispatchCommand.equals("DiagramAxisB"))
383 nDimensionIndex=1; bMainAxis=false;
386 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
387 uno::Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
388 return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, xChartModel );
391 OUString lcl_getGridCIDForCommand( const OString& rDispatchCommand, const uno::Reference< frame::XModel >& xChartModel )
393 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
395 if( rDispatchCommand.equals("DiagramGridAll"))
396 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_GRID, "ALLELEMENTS" );
398 sal_Int32 nDimensionIndex=0;
399 bool bMainGrid=true;
401 //x and y is swapped in the commands
403 if( rDispatchCommand.equals("DiagramGridYMain"))
405 nDimensionIndex=0; bMainGrid=true;
407 else if( rDispatchCommand.equals("DiagramGridXMain"))
409 nDimensionIndex=1; bMainGrid=true;
411 else if( rDispatchCommand.equals("DiagramGridZMain"))
413 nDimensionIndex=2; bMainGrid=true;
415 else if( rDispatchCommand.equals("DiagramGridYHelp"))
417 nDimensionIndex=0; bMainGrid=false;
419 else if( rDispatchCommand.equals("DiagramGridXHelp"))
421 nDimensionIndex=1; bMainGrid=false;
423 else if( rDispatchCommand.equals("DiagramGridZHelp"))
425 nDimensionIndex=2; bMainGrid=false;
428 bool bMainAxis = true;
429 uno::Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
431 sal_Int32 nSubGridIndex= bMainGrid ? (-1) : 0;
432 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel, nSubGridIndex ) );
433 return aCID;
436 OUString lcl_getErrorCIDForCommand( const ObjectType eDispatchType, const ObjectType &eSelectedType, const OUString &rSelectedCID)
438 if( eSelectedType == eDispatchType )
439 return rSelectedCID;
441 return ObjectIdentifier::createClassifiedIdentifierWithParent( eDispatchType, OUString(), rSelectedCID );
444 OUString lcl_getObjectCIDForCommand( const OString& rDispatchCommand, const uno::Reference< XChartDocument > & xChartDocument, const OUString& rSelectedCID )
446 ObjectType eObjectType = OBJECTTYPE_UNKNOWN;
447 OUString aParticleID;
449 uno::Reference< frame::XModel > xChartModel( xChartDocument, uno::UNO_QUERY );
450 const ObjectType eSelectedType = ObjectIdentifier::getObjectType( rSelectedCID );
451 uno::Reference< XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rSelectedCID, xChartModel );
452 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( xSeries, uno::UNO_QUERY );
454 //legend
455 if( rDispatchCommand.equals("Legend") || rDispatchCommand.equals("FormatLegend") )
457 eObjectType = OBJECTTYPE_LEGEND;
458 //@todo set particular aParticleID if we have more than one legend
460 //wall floor area
461 else if( rDispatchCommand.equals("DiagramWall") || rDispatchCommand.equals("FormatWall") )
463 //OBJECTTYPE_DIAGRAM;
464 eObjectType = OBJECTTYPE_DIAGRAM_WALL;
465 //@todo set particular aParticleID if we have more than one diagram
467 else if( rDispatchCommand.equals("DiagramFloor") || rDispatchCommand.equals("FormatFloor") )
469 eObjectType = OBJECTTYPE_DIAGRAM_FLOOR;
470 //@todo set particular aParticleID if we have more than one diagram
472 else if( rDispatchCommand.equals("DiagramArea") || rDispatchCommand.equals("FormatChartArea") )
474 eObjectType = OBJECTTYPE_PAGE;
476 //title
477 else if( rDispatchCommand.equals("MainTitle")
478 || rDispatchCommand.equals("SubTitle")
479 || rDispatchCommand.equals("XTitle")
480 || rDispatchCommand.equals("YTitle")
481 || rDispatchCommand.equals("ZTitle")
482 || rDispatchCommand.equals("SecondaryXTitle")
483 || rDispatchCommand.equals("SecondaryYTitle")
484 || rDispatchCommand.equals("AllTitles")
487 return lcl_getTitleCIDForCommand( rDispatchCommand, xChartModel );
489 //axis
490 else if( rDispatchCommand.equals("DiagramAxisX")
491 || rDispatchCommand.equals("DiagramAxisY")
492 || rDispatchCommand.equals("DiagramAxisZ")
493 || rDispatchCommand.equals("DiagramAxisA")
494 || rDispatchCommand.equals("DiagramAxisB")
495 || rDispatchCommand.equals("DiagramAxisAll")
498 return lcl_getAxisCIDForCommand( rDispatchCommand, xChartModel );
500 //grid
501 else if( rDispatchCommand.equals("DiagramGridYMain")
502 || rDispatchCommand.equals("DiagramGridXMain")
503 || rDispatchCommand.equals("DiagramGridZMain")
504 || rDispatchCommand.equals("DiagramGridYHelp")
505 || rDispatchCommand.equals("DiagramGridXHelp")
506 || rDispatchCommand.equals("DiagramGridZHelp")
507 || rDispatchCommand.equals("DiagramGridAll")
510 return lcl_getGridCIDForCommand( rDispatchCommand, xChartModel );
512 //data series
513 else if( rDispatchCommand.equals("FormatDataSeries") )
515 if( eSelectedType == OBJECTTYPE_DATA_SERIES )
516 return rSelectedCID;
517 else
518 return ObjectIdentifier::createClassifiedIdentifier(
519 OBJECTTYPE_DATA_SERIES, ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ) );
521 //data point
522 else if( rDispatchCommand.equals("FormatDataPoint") )
524 return rSelectedCID;
526 //data labels
527 else if( rDispatchCommand.equals("FormatDataLabels") )
529 if( eSelectedType == OBJECTTYPE_DATA_LABELS )
530 return rSelectedCID;
531 else
532 return ObjectIdentifier::createClassifiedIdentifierWithParent(
533 OBJECTTYPE_DATA_LABELS, OUString(), rSelectedCID );
535 //data labels
536 else if( rDispatchCommand.equals("FormatDataLabel") )
538 if( eSelectedType == OBJECTTYPE_DATA_LABEL )
539 return rSelectedCID;
540 else
542 sal_Int32 nPointIndex = ObjectIdentifier::getParticleID( rSelectedCID ).toInt32();
543 if( nPointIndex>=0 )
545 OUString aSeriesParticle = ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID );
546 OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) + "=" );
547 OUString aLabelsCID = ObjectIdentifier::createClassifiedIdentifierForParticles( aSeriesParticle, aChildParticle );
548 OUString aLabelCID_Stub = ObjectIdentifier::createClassifiedIdentifierWithParent(
549 OBJECTTYPE_DATA_LABEL, OUString(), aLabelsCID );
551 return ObjectIdentifier::createPointCID( aLabelCID_Stub, nPointIndex );
555 //mean value line
556 else if( rDispatchCommand.equals("FormatMeanValue") )
558 if( eSelectedType == OBJECTTYPE_DATA_AVERAGE_LINE )
559 return rSelectedCID;
560 else
561 return ObjectIdentifier::createDataCurveCID(
562 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ),
563 RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt,
564 RegressionCurveHelper::getMeanValueLine( xRegCurveCnt ) ), true );
566 //trend line
567 else if( rDispatchCommand.equals("FormatTrendline") )
569 if( eSelectedType == OBJECTTYPE_DATA_CURVE )
570 return rSelectedCID;
571 else
572 return ObjectIdentifier::createDataCurveCID(
573 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ),
574 RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt,
575 RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) ), false );
577 //trend line equation
578 else if( rDispatchCommand.equals("FormatTrendlineEquation") )
580 if( eSelectedType == OBJECTTYPE_DATA_CURVE_EQUATION )
581 return rSelectedCID;
582 else
583 return ObjectIdentifier::createDataCurveEquationCID(
584 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ),
585 RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt,
586 RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) ) );
588 // y error bars
589 else if( rDispatchCommand.equals("FormatXErrorBars") )
591 return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_X, eSelectedType, rSelectedCID );
593 // y error bars
594 else if( rDispatchCommand.equals("FormatYErrorBars") )
596 return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_Y, eSelectedType, rSelectedCID );
598 // axis
599 else if( rDispatchCommand.equals("FormatAxis") )
601 if( eSelectedType == OBJECTTYPE_AXIS )
602 return rSelectedCID;
603 else
605 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartModel );
606 return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis , xChartModel );
609 // major grid
610 else if( rDispatchCommand.equals("FormatMajorGrid") )
612 if( eSelectedType == OBJECTTYPE_GRID )
613 return rSelectedCID;
614 else
616 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartModel );
617 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel );
621 // minor grid
622 else if( rDispatchCommand.equals("FormatMinorGrid") )
624 if( eSelectedType == OBJECTTYPE_SUBGRID )
625 return rSelectedCID;
626 else
628 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartModel );
629 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel, 0 /*sub grid index*/ );
632 // title
633 else if( rDispatchCommand.equals("FormatTitle") )
635 if( eSelectedType == OBJECTTYPE_TITLE )
636 return rSelectedCID;
638 // stock loss
639 else if( rDispatchCommand.equals("FormatStockLoss") )
641 if( eSelectedType == OBJECTTYPE_DATA_STOCK_LOSS )
642 return rSelectedCID;
643 else
644 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_LOSS, OUString());
646 // stock gain
647 else if( rDispatchCommand.equals("FormatStockGain") )
649 if( eSelectedType == OBJECTTYPE_DATA_STOCK_GAIN )
650 return rSelectedCID;
651 else
652 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_GAIN, OUString() );
655 return ObjectIdentifier::createClassifiedIdentifier(
656 eObjectType, aParticleID );
660 // anonymous namespace
662 void ChartController::executeDispatch_FormatObject(const OUString& rDispatchCommand)
664 uno::Reference< XChartDocument > xChartDocument( getModel(), uno::UNO_QUERY );
665 OString aCommand( OUStringToOString( rDispatchCommand, RTL_TEXTENCODING_ASCII_US ) );
666 OUString rObjectCID = lcl_getObjectCIDForCommand( aCommand, xChartDocument, m_aSelection.getSelectedCID() );
667 executeDlg_ObjectProperties( rObjectCID );
670 void ChartController::executeDispatch_ObjectProperties()
672 executeDlg_ObjectProperties( m_aSelection.getSelectedCID() );
675 namespace
678 OUString lcl_getFormatCIDforSelectedCID( const OUString& rSelectedCID )
680 OUString aFormatCID(rSelectedCID);
682 //get type of selected object
683 ObjectType eObjectType = ObjectIdentifier::getObjectType( aFormatCID );
685 // some legend entries are handled as if they were data series
686 if( OBJECTTYPE_LEGEND_ENTRY==eObjectType )
688 OUString aParentParticle( ObjectIdentifier::getFullParentParticle( rSelectedCID ) );
689 aFormatCID = ObjectIdentifier::createClassifiedIdentifierForParticle( aParentParticle );
692 // treat diagram as wall
693 if( OBJECTTYPE_DIAGRAM==eObjectType )
694 aFormatCID = ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, OUString() );
696 return aFormatCID;
699 }//end anonymous namespace
701 void ChartController::executeDlg_ObjectProperties( const OUString& rSelectedObjectCID )
703 OUString aObjectCID = lcl_getFormatCIDforSelectedCID( rSelectedObjectCID );
705 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription(
706 ActionDescriptionProvider::FORMAT,
707 ObjectNameProvider::getName( ObjectIdentifier::getObjectType( aObjectCID ))),
708 m_xUndoManager );
710 bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, false );
711 if( bSuccess )
712 aUndoGuard.commit();
715 bool ChartController::executeDlg_ObjectProperties_withoutUndoGuard(
716 const OUString& rObjectCID, bool bSuccessOnUnchanged )
718 //return true if the properties were changed successfully
719 bool bRet = false;
720 if( rObjectCID.isEmpty() )
722 return bRet;
726 //get type of object
727 ObjectType eObjectType = ObjectIdentifier::getObjectType( rObjectCID );
728 if( OBJECTTYPE_UNKNOWN==eObjectType )
730 return bRet;
732 if( OBJECTTYPE_DIAGRAM_WALL==eObjectType || OBJECTTYPE_DIAGRAM_FLOOR==eObjectType )
734 if( !DiagramHelper::isSupportingFloorAndWall( ChartModelHelper::findDiagram( getModel() ) ) )
735 return bRet;
738 //convert properties to ItemSet
740 boost::scoped_ptr<ReferenceSizeProvider> pRefSizeProv(impl_createReferenceSizeProvider());
742 boost::scoped_ptr<wrapper::ItemConverter> pItemConverter(
743 createItemConverter( rObjectCID, getModel(), m_xCC,
744 m_pDrawModelWrapper->getSdrModel(),
745 ExplicitValueProvider::getExplicitValueProvider(m_xChartView),
746 pRefSizeProv.get()));
748 if (!pItemConverter)
749 return bRet;
751 SfxItemSet aItemSet = pItemConverter->CreateEmptyItemSet();
753 if ( eObjectType == OBJECTTYPE_DATA_ERRORS_X || eObjectType == OBJECTTYPE_DATA_ERRORS_Y )
754 aItemSet.Put(SfxBoolItem(SCHATTR_STAT_ERRORBAR_TYPE, eObjectType == OBJECTTYPE_DATA_ERRORS_Y ));
756 pItemConverter->FillItemSet(aItemSet);
758 //prepare dialog
759 ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter( rObjectCID );
760 aDialogParameter.init( getModel() );
761 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get() );
763 SolarMutexGuard aGuard;
764 ScopedVclPtrInstance<SchAttribTabDlg> aDlg(
765 m_pChartWindow, &aItemSet, &aDialogParameter,
766 &aViewElementListProvider,
767 uno::Reference< util::XNumberFormatsSupplier >(
768 getModel(), uno::UNO_QUERY ) );
770 if(aDialogParameter.HasSymbolProperties())
772 SfxItemSet* pSymbolShapeProperties=NULL;
773 uno::Reference< beans::XPropertySet > xObjectProperties =
774 ObjectIdentifier::getObjectPropertySet( rObjectCID, getModel() );
775 wrapper::DataPointItemConverter aSymbolItemConverter( getModel(), m_xCC
776 , xObjectProperties, ObjectIdentifier::getDataSeriesForCID( rObjectCID, getModel() )
777 , m_pDrawModelWrapper->getSdrModel().GetItemPool()
778 , m_pDrawModelWrapper->getSdrModel()
779 , uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY )
780 , wrapper::GraphicPropertyItemConverter::FILLED_DATA_POINT );
782 pSymbolShapeProperties = new SfxItemSet( aSymbolItemConverter.CreateEmptyItemSet() );
783 aSymbolItemConverter.FillItemSet( *pSymbolShapeProperties );
785 sal_Int32 nStandardSymbol=0;//@todo get from somewhere
786 Graphic* pAutoSymbolGraphic = new Graphic( aViewElementListProvider.GetSymbolGraphic( nStandardSymbol, pSymbolShapeProperties ) );
787 // note: the dialog takes the ownership of pSymbolShapeProperties and pAutoSymbolGraphic
788 aDlg->setSymbolInformation( pSymbolShapeProperties, pAutoSymbolGraphic );
790 if( aDialogParameter.HasStatisticProperties() )
792 aDlg->SetAxisMinorStepWidthForErrorBarDecimals(
793 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), m_xChartView, rObjectCID ) );
796 //open the dialog
797 if (aDlg->Execute() == RET_OK || (bSuccessOnUnchanged && aDlg->DialogWasClosedWithOK()))
799 const SfxItemSet* pOutItemSet = aDlg->GetOutputItemSet();
800 if(pOutItemSet)
802 ControllerLockGuardUNO aCLGuard( getModel());
803 (void)pItemConverter->ApplyItemSet(*pOutItemSet); //model should be changed now
804 bRet = true;
808 catch( const util::CloseVetoException& )
811 catch( const uno::RuntimeException& )
814 return bRet;
817 void ChartController::executeDispatch_View3D()
821 // using assignment for broken gcc 3.3
822 UndoLiveUpdateGuard aUndoGuard = UndoLiveUpdateGuard(
823 SCH_RESSTR( STR_ACTION_EDIT_3D_VIEW ),
824 m_xUndoManager );
826 //open dialog
827 SolarMutexGuard aSolarGuard;
828 ScopedVclPtrInstance< View3DDialog > aDlg( m_pChartWindow, getModel(), m_pDrawModelWrapper->GetColorList() );
829 if( aDlg->Execute() == RET_OK )
830 aUndoGuard.commit();
832 catch(const uno::RuntimeException& e)
834 ASSERT_EXCEPTION( e );
838 } //namespace chart
840 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */