1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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"
51 #include "Strings.hrc"
52 #include "ReferenceSizeProvider.hxx"
53 #include "RegressionCurveHelper.hxx"
54 #include <com/sun/star/chart2/XChartDocument.hpp>
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>
66 using namespace ::com::sun::star
;
67 using namespace ::com::sun::star::chart2
;
68 using ::com::sun::star::uno::Reference
;
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");
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())
96 //create itemconverter for a single object
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
);
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
),
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
),
129 case OBJECTTYPE_LEGEND_ENTRY
:
131 case OBJECTTYPE_DIAGRAM
:
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
);
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(),
163 uno::Reference
< chart2::XChartDocument
>( xChartModel
, uno::UNO_QUERY
),
164 &aExplicitScale
, &aExplicitIncrement
,
168 case OBJECTTYPE_AXIS_UNITLABEL
:
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*/
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
);
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*/
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
) &&
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
);
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
);
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
));
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
));
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
),
289 case OBJECTTYPE_DATA_STOCK_RANGE
:
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
);
298 default: //OBJECTTYPE_UNKNOWN
304 //create itemconverter for a all objects of given type
307 case OBJECTTYPE_TITLE
:
308 pItemConverter
= new wrapper::AllTitleItemConverter( xChartModel
, rDrawModel
.GetItemPool(),
309 rDrawModel
, uno::Reference
< lang::XMultiServiceFactory
>( xChartModel
, uno::UNO_QUERY
));
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());
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
));
327 default: //for this type it is not supported to change all elements at once
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;
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;
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
) );
436 OUString
lcl_getErrorCIDForCommand( const ObjectType eDispatchType
, const ObjectType
&eSelectedType
, const OUString
&rSelectedCID
)
438 if( eSelectedType
== eDispatchType
)
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
);
455 if( rDispatchCommand
.equals("Legend") || rDispatchCommand
.equals("FormatLegend") )
457 eObjectType
= OBJECTTYPE_LEGEND
;
458 //@todo set particular aParticleID if we have more than one legend
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
;
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
);
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
);
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
);
513 else if( rDispatchCommand
.equals("FormatDataSeries") )
515 if( eSelectedType
== OBJECTTYPE_DATA_SERIES
)
518 return ObjectIdentifier::createClassifiedIdentifier(
519 OBJECTTYPE_DATA_SERIES
, ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID
) );
522 else if( rDispatchCommand
.equals("FormatDataPoint") )
527 else if( rDispatchCommand
.equals("FormatDataLabels") )
529 if( eSelectedType
== OBJECTTYPE_DATA_LABELS
)
532 return ObjectIdentifier::createClassifiedIdentifierWithParent(
533 OBJECTTYPE_DATA_LABELS
, OUString(), rSelectedCID
);
536 else if( rDispatchCommand
.equals("FormatDataLabel") )
538 if( eSelectedType
== OBJECTTYPE_DATA_LABEL
)
542 sal_Int32 nPointIndex
= ObjectIdentifier::getParticleID( rSelectedCID
).toInt32();
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
);
556 else if( rDispatchCommand
.equals("FormatMeanValue") )
558 if( eSelectedType
== OBJECTTYPE_DATA_AVERAGE_LINE
)
561 return ObjectIdentifier::createDataCurveCID(
562 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID
),
563 RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt
,
564 RegressionCurveHelper::getMeanValueLine( xRegCurveCnt
) ), true );
567 else if( rDispatchCommand
.equals("FormatTrendline") )
569 if( eSelectedType
== OBJECTTYPE_DATA_CURVE
)
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
)
583 return ObjectIdentifier::createDataCurveEquationCID(
584 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID
),
585 RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt
,
586 RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt
) ) );
589 else if( rDispatchCommand
.equals("FormatXErrorBars") )
591 return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_X
, eSelectedType
, rSelectedCID
);
594 else if( rDispatchCommand
.equals("FormatYErrorBars") )
596 return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_Y
, eSelectedType
, rSelectedCID
);
599 else if( rDispatchCommand
.equals("FormatAxis") )
601 if( eSelectedType
== OBJECTTYPE_AXIS
)
605 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( rSelectedCID
, xChartModel
);
606 return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis
, xChartModel
);
610 else if( rDispatchCommand
.equals("FormatMajorGrid") )
612 if( eSelectedType
== OBJECTTYPE_GRID
)
616 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( rSelectedCID
, xChartModel
);
617 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis
, xChartModel
);
622 else if( rDispatchCommand
.equals("FormatMinorGrid") )
624 if( eSelectedType
== OBJECTTYPE_SUBGRID
)
628 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( rSelectedCID
, xChartModel
);
629 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis
, xChartModel
, 0 /*sub grid index*/ );
633 else if( rDispatchCommand
.equals("FormatTitle") )
635 if( eSelectedType
== OBJECTTYPE_TITLE
)
639 else if( rDispatchCommand
.equals("FormatStockLoss") )
641 if( eSelectedType
== OBJECTTYPE_DATA_STOCK_LOSS
)
644 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_LOSS
, OUString());
647 else if( rDispatchCommand
.equals("FormatStockGain") )
649 if( eSelectedType
== OBJECTTYPE_DATA_STOCK_GAIN
)
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() );
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() );
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
))),
710 bool bSuccess
= ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID
, false );
715 bool ChartController::executeDlg_ObjectProperties_withoutUndoGuard(
716 const OUString
& rObjectCID
, bool bSuccessOnUnchanged
)
718 //return true if the properties were changed successfully
720 if( rObjectCID
.isEmpty() )
727 ObjectType eObjectType
= ObjectIdentifier::getObjectType( rObjectCID
);
728 if( OBJECTTYPE_UNKNOWN
==eObjectType
)
732 if( OBJECTTYPE_DIAGRAM_WALL
==eObjectType
|| OBJECTTYPE_DIAGRAM_FLOOR
==eObjectType
)
734 if( !DiagramHelper::isSupportingFloorAndWall( ChartModelHelper::findDiagram( getModel() ) ) )
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()));
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
);
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
) );
797 if (aDlg
->Execute() == RET_OK
|| (bSuccessOnUnchanged
&& aDlg
->DialogWasClosedWithOK()))
799 const SfxItemSet
* pOutItemSet
= aDlg
->GetOutputItemSet();
802 ControllerLockGuardUNO
aCLGuard( getModel());
803 (void)pItemConverter
->ApplyItemSet(*pOutItemSet
); //model should be changed now
808 catch( const util::CloseVetoException
& )
811 catch( const uno::RuntimeException
& )
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
),
827 SolarMutexGuard aSolarGuard
;
828 ScopedVclPtrInstance
< View3DDialog
> aDlg( m_pChartWindow
, getModel(), m_pDrawModelWrapper
->GetColorList() );
829 if( aDlg
->Execute() == RET_OK
)
832 catch(const uno::RuntimeException
& e
)
834 ASSERT_EXCEPTION( e
);
840 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */