Bump for 3.6-28
[LibreOffice.git] / chart2 / source / controller / main / ChartController_Properties.cxx
blob005c076acf2d4247a6b27707454a60040283c24f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "ChartController.hxx"
30 #include "ChartWindow.hxx"
31 #include "chartview/DrawModelWrapper.hxx"
32 #include "ObjectIdentifier.hxx"
33 #include "chartview/ExplicitValueProvider.hxx"
34 #include "macros.hxx"
35 #include "dlg_ObjectProperties.hxx"
36 #include "dlg_View3D.hxx"
37 #include "dlg_InsertErrorBars.hxx"
38 #include "ViewElementListProvider.hxx"
39 #include "DataPointItemConverter.hxx"
40 #include "AxisItemConverter.hxx"
41 #include "MultipleChartConverters.hxx"
42 #include "TitleItemConverter.hxx"
43 #include "LegendItemConverter.hxx"
44 #include "RegressionCurveItemConverter.hxx"
45 #include "RegressionEquationItemConverter.hxx"
46 #include "ErrorBarItemConverter.hxx"
47 #include "ChartModelHelper.hxx"
48 #include "AxisHelper.hxx"
49 #include "TitleHelper.hxx"
50 #include "LegendHelper.hxx"
51 #include "ChartTypeHelper.hxx"
52 #include "ColorPerPointHelper.hxx"
53 #include "DiagramHelper.hxx"
54 #include "servicenames_charttypes.hxx"
55 #include "ControllerLockGuard.hxx"
56 #include "UndoGuard.hxx"
57 #include "ObjectNameProvider.hxx"
58 #include "ResId.hxx"
59 #include "Strings.hrc"
60 #include "ReferenceSizeProvider.hxx"
61 #include "RegressionCurveHelper.hxx"
62 #include <com/sun/star/chart2/XChartDocument.hpp>
64 //for auto_ptr
65 #include <memory>
67 // header for define RET_OK
68 #include <vcl/msgbox.hxx>
69 // for SolarMutex
70 #include <vcl/svapp.hxx>
71 #include <osl/mutex.hxx>
72 #include <svx/ActionDescriptionProvider.hxx>
74 //.............................................................................
75 namespace chart
77 //.............................................................................
78 using namespace ::com::sun::star;
79 using namespace ::com::sun::star::chart2;
80 using ::com::sun::star::uno::Reference;
81 using ::rtl::OUString;
83 namespace
86 SAL_WNODEPRECATED_DECLARATIONS_PUSH
87 ::comphelper::ItemConverter* createItemConverter(
88 const ::rtl::OUString & aObjectCID
89 , const uno::Reference< frame::XModel > & xChartModel
90 , const uno::Reference< uno::XComponentContext > & xContext
91 , SdrModel & rDrawModel
92 , NumberFormatterWrapper * pNumberFormatterWrapper = NULL
93 , ExplicitValueProvider * pExplicitValueProvider = NULL
94 , ::std::auto_ptr< ReferenceSizeProvider > pRefSizeProvider =
95 ::std::auto_ptr< ReferenceSizeProvider >()
98 ::comphelper::ItemConverter* pItemConverter=NULL;
100 //-------------------------------------------------------------
101 //get type of selected object
102 ObjectType eObjectType = ObjectIdentifier::getObjectType( aObjectCID );
103 if( OBJECTTYPE_UNKNOWN==eObjectType )
105 OSL_FAIL("unknown ObjectType");
106 return NULL;
109 rtl::OUString aParticleID = ObjectIdentifier::getParticleID( aObjectCID );
110 bool bAffectsMultipleObjects = aParticleID.equals(C2U("ALLELEMENTS"));
111 //-------------------------------------------------------------
112 if( !bAffectsMultipleObjects )
114 uno::Reference< beans::XPropertySet > xObjectProperties =
115 ObjectIdentifier::getObjectPropertySet( aObjectCID, xChartModel );
116 if(!xObjectProperties.is())
117 return NULL;
118 //create itemconverter for a single object
119 switch(eObjectType)
121 case OBJECTTYPE_PAGE:
122 pItemConverter = new wrapper::GraphicPropertyItemConverter(
123 xObjectProperties, rDrawModel.GetItemPool(),
124 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
125 wrapper::GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES );
126 break;
127 case OBJECTTYPE_TITLE:
129 ::std::auto_ptr< awt::Size > pRefSize;
130 if( pRefSizeProvider.get() )
131 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
133 pItemConverter = new wrapper::TitleItemConverter( xObjectProperties,
134 rDrawModel.GetItemPool(), rDrawModel,
135 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
136 pRefSize );
138 break;
139 case OBJECTTYPE_LEGEND:
141 ::std::auto_ptr< awt::Size > pRefSize;
142 if( pRefSizeProvider.get() )
143 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
145 pItemConverter = new wrapper::LegendItemConverter( xObjectProperties,
146 rDrawModel.GetItemPool(), rDrawModel,
147 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
148 pRefSize );
150 break;
151 case OBJECTTYPE_LEGEND_ENTRY:
152 break;
153 case OBJECTTYPE_DIAGRAM:
154 break;
155 case OBJECTTYPE_DIAGRAM_WALL:
156 case OBJECTTYPE_DIAGRAM_FLOOR:
157 pItemConverter = new wrapper::GraphicPropertyItemConverter(
158 xObjectProperties, rDrawModel.GetItemPool(),
159 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
160 wrapper::GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES );
161 break;
162 case OBJECTTYPE_AXIS:
164 ::std::auto_ptr< awt::Size > pRefSize;
165 if( pRefSizeProvider.get() )
166 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
168 uno::Reference< beans::XPropertySet > xDiaProp;
169 xDiaProp.set( ChartModelHelper::findDiagram( xChartModel ), uno::UNO_QUERY );
171 // the second property set contains the property CoordinateOrigin
172 // nOriginIndex is the index of the corresponding index of the
173 // origin (x=0, y=1, z=2)
175 ExplicitScaleData aExplicitScale;
176 ExplicitIncrementData aExplicitIncrement;
177 if( pExplicitValueProvider )
178 pExplicitValueProvider->getExplicitValuesForAxis(
179 uno::Reference< XAxis >( xObjectProperties, uno::UNO_QUERY ),
180 aExplicitScale, aExplicitIncrement );
182 pItemConverter = new wrapper::AxisItemConverter(
183 xObjectProperties, rDrawModel.GetItemPool(),
184 rDrawModel,
185 uno::Reference< chart2::XChartDocument >( xChartModel, uno::UNO_QUERY ),
186 &aExplicitScale, &aExplicitIncrement,
187 pRefSize );
189 break;
190 case OBJECTTYPE_AXIS_UNITLABEL:
191 break;
192 case OBJECTTYPE_DATA_LABELS:
193 case OBJECTTYPE_DATA_SERIES:
194 case OBJECTTYPE_DATA_LABEL:
195 case OBJECTTYPE_DATA_POINT:
197 ::std::auto_ptr< awt::Size > pRefSize;
198 if( pRefSizeProvider.get() )
199 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
201 wrapper::GraphicPropertyItemConverter::eGraphicObjectType eMapTo =
202 wrapper::GraphicPropertyItemConverter::FILLED_DATA_POINT;
204 uno::Reference< XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel );
205 uno::Reference< XChartType > xChartType = ChartModelHelper::getChartTypeOfSeries( xChartModel, xSeries );
207 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
208 sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
209 if( !ChartTypeHelper::isSupportingAreaProperties( xChartType, nDimensionCount ) )
210 eMapTo = wrapper::GraphicPropertyItemConverter::LINE_DATA_POINT;
212 bool bDataSeries = ( eObjectType == OBJECTTYPE_DATA_SERIES || eObjectType == OBJECTTYPE_DATA_LABELS );
214 //special color for pie chart:
215 bool bUseSpecialFillColor = false;
216 sal_Int32 nSpecialFillColor =0;
217 sal_Int32 nPointIndex = -1; /*-1 for whole series*/
218 if(!bDataSeries)
220 nPointIndex = aParticleID.toInt32();
221 uno::Reference< beans::XPropertySet > xSeriesProp( xSeries, uno::UNO_QUERY );
222 bool bVaryColorsByPoint = false;
223 if( xSeriesProp.is() &&
224 (xSeriesProp->getPropertyValue(C2U("VaryColorsByPoint")) >>= bVaryColorsByPoint) &&
225 bVaryColorsByPoint )
227 if( !ColorPerPointHelper::hasPointOwnColor( xSeriesProp, nPointIndex, xObjectProperties ) )
229 bUseSpecialFillColor = true;
230 OSL_ASSERT( xDiagram.is());
231 uno::Reference< XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme() );
232 if( xColorScheme.is())
233 nSpecialFillColor = xColorScheme->getColorByIndex( nPointIndex );
237 sal_Int32 nNumberFormat=ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel( xObjectProperties, xSeries, nPointIndex, xDiagram );
238 sal_Int32 nPercentNumberFormat=ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabel(
239 xObjectProperties,uno::Reference< util::XNumberFormatsSupplier >(xChartModel, uno::UNO_QUERY));
241 pItemConverter = new wrapper::DataPointItemConverter( xChartModel, xContext,
242 xObjectProperties, xSeries, rDrawModel.GetItemPool(), rDrawModel,
243 pNumberFormatterWrapper,
244 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
245 eMapTo, pRefSize, bDataSeries, bUseSpecialFillColor, nSpecialFillColor, true,
246 nNumberFormat, nPercentNumberFormat );
247 break;
249 case OBJECTTYPE_GRID:
250 case OBJECTTYPE_SUBGRID:
251 case OBJECTTYPE_DATA_AVERAGE_LINE:
252 pItemConverter = new wrapper::GraphicPropertyItemConverter(
253 xObjectProperties, rDrawModel.GetItemPool(),
254 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
255 wrapper::GraphicPropertyItemConverter::LINE_PROPERTIES );
256 break;
258 case OBJECTTYPE_DATA_ERRORS_X:
259 case OBJECTTYPE_DATA_ERRORS_Y:
260 case OBJECTTYPE_DATA_ERRORS_Z:
261 pItemConverter = new wrapper::ErrorBarItemConverter(
262 xChartModel, xObjectProperties, rDrawModel.GetItemPool(),
263 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
264 break;
266 case OBJECTTYPE_DATA_CURVE:
267 pItemConverter = new wrapper::RegressionCurveItemConverter(
268 xObjectProperties, uno::Reference< chart2::XRegressionCurveContainer >(
269 ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel ), uno::UNO_QUERY ),
270 rDrawModel.GetItemPool(), rDrawModel,
271 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
272 break;
273 case OBJECTTYPE_DATA_CURVE_EQUATION:
275 ::std::auto_ptr< awt::Size > pRefSize;
276 if( pRefSizeProvider.get() )
277 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
279 pItemConverter = new wrapper::RegressionEquationItemConverter(
280 xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
281 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
282 pRefSize );
283 break;
285 case OBJECTTYPE_DATA_STOCK_RANGE:
286 break;
287 case OBJECTTYPE_DATA_STOCK_LOSS:
288 case OBJECTTYPE_DATA_STOCK_GAIN:
289 pItemConverter = new wrapper::GraphicPropertyItemConverter(
290 xObjectProperties, rDrawModel.GetItemPool(),
291 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
292 wrapper::GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES );
293 break;
294 default: //OBJECTTYPE_UNKNOWN
295 break;
298 else
300 //create itemconverter for a all objects of given type
301 switch(eObjectType)
303 case OBJECTTYPE_TITLE:
304 pItemConverter = new wrapper::AllTitleItemConverter( xChartModel, rDrawModel.GetItemPool(),
305 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
306 break;
307 case OBJECTTYPE_AXIS:
309 ::std::auto_ptr< awt::Size > pRefSize;
310 if( pRefSizeProvider.get() )
311 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
313 pItemConverter = new wrapper::AllAxisItemConverter( xChartModel, rDrawModel.GetItemPool(),
314 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ), pRefSize );
316 break;
317 case OBJECTTYPE_GRID:
318 case OBJECTTYPE_SUBGRID:
319 pItemConverter = new wrapper::AllGridItemConverter( xChartModel, rDrawModel.GetItemPool(),
320 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
321 break;
322 default: //for this type it is not supported to change all elements at once
323 break;
327 return pItemConverter;
329 SAL_WNODEPRECATED_DECLARATIONS_POP
331 rtl::OUString lcl_getTitleCIDForCommand( const ::rtl::OString& rDispatchCommand, const uno::Reference< frame::XModel > & xChartModel )
333 if( rDispatchCommand.equals("AllTitles"))
334 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_TITLE, C2U("ALLELEMENTS") );
336 TitleHelper::eTitleType nTitleType( TitleHelper::MAIN_TITLE );
337 if( rDispatchCommand.equals("SubTitle") )
338 nTitleType = TitleHelper::SUB_TITLE;
339 else if( rDispatchCommand.equals("XTitle") )
340 nTitleType = TitleHelper::X_AXIS_TITLE;
341 else if( rDispatchCommand.equals("YTitle") )
342 nTitleType = TitleHelper::Y_AXIS_TITLE;
343 else if( rDispatchCommand.equals("ZTitle") )
344 nTitleType = TitleHelper::Z_AXIS_TITLE;
345 else if( rDispatchCommand.equals("SecondaryXTitle") )
346 nTitleType = TitleHelper::SECONDARY_X_AXIS_TITLE;
347 else if( rDispatchCommand.equals("SecondaryYTitle") )
348 nTitleType = TitleHelper::SECONDARY_Y_AXIS_TITLE;
350 uno::Reference< XTitle > xTitle( TitleHelper::getTitle( nTitleType, xChartModel ) );
351 return ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, xChartModel );
354 rtl::OUString lcl_getAxisCIDForCommand( const ::rtl::OString& rDispatchCommand, const uno::Reference< frame::XModel >& xChartModel )
356 if( rDispatchCommand.equals("DiagramAxisAll"))
357 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_AXIS, C2U("ALLELEMENTS") );
359 sal_Int32 nDimensionIndex=0;
360 bool bMainAxis=true;
361 if( rDispatchCommand.equals("DiagramAxisX"))
363 nDimensionIndex=0; bMainAxis=true;
365 else if( rDispatchCommand.equals("DiagramAxisY"))
367 nDimensionIndex=1; bMainAxis=true;
369 else if( rDispatchCommand.equals("DiagramAxisZ"))
371 nDimensionIndex=2; bMainAxis=true;
373 else if( rDispatchCommand.equals("DiagramAxisA"))
375 nDimensionIndex=0; bMainAxis=false;
377 else if( rDispatchCommand.equals("DiagramAxisB"))
379 nDimensionIndex=1; bMainAxis=false;
382 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
383 uno::Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
384 return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, xChartModel );
387 rtl::OUString lcl_getGridCIDForCommand( const ::rtl::OString& rDispatchCommand, const uno::Reference< frame::XModel >& xChartModel )
389 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
391 if( rDispatchCommand.equals("DiagramGridAll"))
392 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_GRID, C2U("ALLELEMENTS") );
394 sal_Int32 nDimensionIndex=0;
395 bool bMainGrid=true;
397 //x and y is swapped in the commands
399 if( rDispatchCommand.equals("DiagramGridYMain"))
401 nDimensionIndex=0; bMainGrid=true;
403 else if( rDispatchCommand.equals("DiagramGridXMain"))
405 nDimensionIndex=1; bMainGrid=true;
407 else if( rDispatchCommand.equals("DiagramGridZMain"))
409 nDimensionIndex=2; bMainGrid=true;
411 else if( rDispatchCommand.equals("DiagramGridYHelp"))
413 nDimensionIndex=0; bMainGrid=false;
415 else if( rDispatchCommand.equals("DiagramGridXHelp"))
417 nDimensionIndex=1; bMainGrid=false;
419 else if( rDispatchCommand.equals("DiagramGridZHelp"))
421 nDimensionIndex=2; bMainGrid=false;
424 bool bMainAxis = true;
425 uno::Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
427 sal_Int32 nSubGridIndex= bMainGrid ? (-1) : 0;
428 rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel, nSubGridIndex ) );
429 return aCID;
432 rtl::OUString lcl_getErrorCIDForCommand( const ObjectType eDispatchType, const ObjectType &eSelectedType, const ::rtl::OUString &rSelectedCID)
434 if( eSelectedType == eDispatchType )
435 return rSelectedCID;
437 return ObjectIdentifier::createClassifiedIdentifierWithParent( eDispatchType, ::rtl::OUString(), rSelectedCID );
440 rtl::OUString lcl_getObjectCIDForCommand( const ::rtl::OString& rDispatchCommand, const uno::Reference< XChartDocument > & xChartDocument, const rtl::OUString& rSelectedCID )
442 ObjectType eObjectType = OBJECTTYPE_UNKNOWN;
443 rtl::OUString aParticleID;
445 uno::Reference< frame::XModel > xChartModel( xChartDocument, uno::UNO_QUERY );
446 const ObjectType eSelectedType = ObjectIdentifier::getObjectType( rSelectedCID );
447 uno::Reference< XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rSelectedCID, xChartModel );
448 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( xSeries, uno::UNO_QUERY );
450 //-------------------------------------------------------------------------
451 //legend
452 if( rDispatchCommand.equals("Legend") || rDispatchCommand.equals("FormatLegend") )
454 eObjectType = OBJECTTYPE_LEGEND;
455 //@todo set particular aParticleID if we have more than one legend
457 //-------------------------------------------------------------------------
458 //wall floor area
459 else if( rDispatchCommand.equals("DiagramWall") || rDispatchCommand.equals("FormatWall") )
461 //OBJECTTYPE_DIAGRAM;
462 eObjectType = OBJECTTYPE_DIAGRAM_WALL;
463 //@todo set particular aParticleID if we have more than one diagram
465 else if( rDispatchCommand.equals("DiagramFloor") || rDispatchCommand.equals("FormatFloor") )
467 eObjectType = OBJECTTYPE_DIAGRAM_FLOOR;
468 //@todo set particular aParticleID if we have more than one diagram
470 else if( rDispatchCommand.equals("DiagramArea") || rDispatchCommand.equals("FormatChartArea") )
472 eObjectType = OBJECTTYPE_PAGE;
474 //-------------------------------------------------------------------------
475 //title
476 else if( rDispatchCommand.equals("MainTitle")
477 || rDispatchCommand.equals("SubTitle")
478 || rDispatchCommand.equals("XTitle")
479 || rDispatchCommand.equals("YTitle")
480 || rDispatchCommand.equals("ZTitle")
481 || rDispatchCommand.equals("SecondaryXTitle")
482 || rDispatchCommand.equals("SecondaryYTitle")
483 || rDispatchCommand.equals("AllTitles")
486 return lcl_getTitleCIDForCommand( rDispatchCommand, xChartModel );
488 //-------------------------------------------------------------------------
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 //-------------------------------------------------------------------------
501 //grid
502 else if( rDispatchCommand.equals("DiagramGridYMain")
503 || rDispatchCommand.equals("DiagramGridXMain")
504 || rDispatchCommand.equals("DiagramGridZMain")
505 || rDispatchCommand.equals("DiagramGridYHelp")
506 || rDispatchCommand.equals("DiagramGridXHelp")
507 || rDispatchCommand.equals("DiagramGridZHelp")
508 || rDispatchCommand.equals("DiagramGridAll")
511 return lcl_getGridCIDForCommand( rDispatchCommand, xChartModel );
513 //-------------------------------------------------------------------------
514 //data series
515 else if( rDispatchCommand.equals("FormatDataSeries") )
517 if( eSelectedType == OBJECTTYPE_DATA_SERIES )
518 return rSelectedCID;
519 else
520 return ObjectIdentifier::createClassifiedIdentifier(
521 OBJECTTYPE_DATA_SERIES, ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ) );
523 //-------------------------------------------------------------------------
524 //data point
525 else if( rDispatchCommand.equals("FormatDataPoint") )
527 return rSelectedCID;
529 //-------------------------------------------------------------------------
530 //data labels
531 else if( rDispatchCommand.equals("FormatDataLabels") )
533 if( eSelectedType == OBJECTTYPE_DATA_LABELS )
534 return rSelectedCID;
535 else
536 return ObjectIdentifier::createClassifiedIdentifierWithParent(
537 OBJECTTYPE_DATA_LABELS, ::rtl::OUString(), rSelectedCID );
539 //-------------------------------------------------------------------------
540 //data labels
541 else if( rDispatchCommand.equals("FormatDataLabel") )
543 if( eSelectedType == OBJECTTYPE_DATA_LABEL )
544 return rSelectedCID;
545 else
547 sal_Int32 nPointIndex = ObjectIdentifier::getParticleID( rSelectedCID ).toInt32();
548 if( nPointIndex>=0 )
550 OUString aSeriesParticle = ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID );
551 OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) );
552 aChildParticle+=(C2U("="));
553 OUString aLabelsCID = ObjectIdentifier::createClassifiedIdentifierForParticles( aSeriesParticle, aChildParticle );
554 OUString aLabelCID_Stub = ObjectIdentifier::createClassifiedIdentifierWithParent(
555 OBJECTTYPE_DATA_LABEL, ::rtl::OUString(), aLabelsCID );
557 return ObjectIdentifier::createPointCID( aLabelCID_Stub, nPointIndex );
561 //-------------------------------------------------------------------------
562 //mean value line
563 else if( rDispatchCommand.equals("FormatMeanValue") )
565 if( eSelectedType == OBJECTTYPE_DATA_AVERAGE_LINE )
566 return rSelectedCID;
567 else
568 return ObjectIdentifier::createDataCurveCID(
569 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ),
570 RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt,
571 RegressionCurveHelper::getMeanValueLine( xRegCurveCnt ) ), true );
573 //-------------------------------------------------------------------------
574 //trend line
575 else if( rDispatchCommand.equals("FormatTrendline") )
577 if( eSelectedType == OBJECTTYPE_DATA_CURVE )
578 return rSelectedCID;
579 else
580 return ObjectIdentifier::createDataCurveCID(
581 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ),
582 RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt,
583 RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) ), false );
585 //-------------------------------------------------------------------------
586 //trend line equation
587 else if( rDispatchCommand.equals("FormatTrendlineEquation") )
589 if( eSelectedType == OBJECTTYPE_DATA_CURVE_EQUATION )
590 return rSelectedCID;
591 else
592 return ObjectIdentifier::createDataCurveEquationCID(
593 ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ),
594 RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt,
595 RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) ) );
597 //-------------------------------------------------------------------------
598 // y error bars
599 else if( rDispatchCommand.equals("FormatXErrorBars") )
601 return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_X, eSelectedType, rSelectedCID );
603 //-------------------------------------------------------------------------
604 // y error bars
605 else if( rDispatchCommand.equals("FormatYErrorBars") )
607 return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_Y, eSelectedType, rSelectedCID );
609 //-------------------------------------------------------------------------
610 // axis
611 else if( rDispatchCommand.equals("FormatAxis") )
613 if( eSelectedType == OBJECTTYPE_AXIS )
614 return rSelectedCID;
615 else
617 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartModel );
618 return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis , xChartModel );
621 //-------------------------------------------------------------------------
622 // major grid
623 else if( rDispatchCommand.equals("FormatMajorGrid") )
625 if( eSelectedType == OBJECTTYPE_GRID )
626 return rSelectedCID;
627 else
629 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartModel );
630 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel );
634 //-------------------------------------------------------------------------
635 // minor grid
636 else if( rDispatchCommand.equals("FormatMinorGrid") )
638 if( eSelectedType == OBJECTTYPE_SUBGRID )
639 return rSelectedCID;
640 else
642 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartModel );
643 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel, 0 /*sub grid index*/ );
646 //-------------------------------------------------------------------------
647 // title
648 else if( rDispatchCommand.equals("FormatTitle") )
650 if( eSelectedType == OBJECTTYPE_TITLE )
651 return rSelectedCID;
653 //-------------------------------------------------------------------------
654 // stock loss
655 else if( rDispatchCommand.equals("FormatStockLoss") )
657 if( eSelectedType == OBJECTTYPE_DATA_STOCK_LOSS )
658 return rSelectedCID;
659 else
660 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_LOSS, rtl::OUString());
662 //-------------------------------------------------------------------------
663 // stock gain
664 else if( rDispatchCommand.equals("FormatStockGain") )
666 if( eSelectedType == OBJECTTYPE_DATA_STOCK_GAIN )
667 return rSelectedCID;
668 else
669 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_GAIN, rtl::OUString() );
672 return ObjectIdentifier::createClassifiedIdentifier(
673 eObjectType, aParticleID );
677 // anonymous namespace
679 void SAL_CALL ChartController::executeDispatch_FormatObject(const ::rtl::OUString& rDispatchCommand)
681 uno::Reference< XChartDocument > xChartDocument( getModel(), uno::UNO_QUERY );
682 rtl::OString aCommand( rtl::OUStringToOString( rDispatchCommand, RTL_TEXTENCODING_ASCII_US ) );
683 rtl::OUString rObjectCID = lcl_getObjectCIDForCommand( aCommand, xChartDocument, m_aSelection.getSelectedCID() );
684 executeDlg_ObjectProperties( rObjectCID );
687 void SAL_CALL ChartController::executeDispatch_ObjectProperties()
689 executeDlg_ObjectProperties( m_aSelection.getSelectedCID() );
692 namespace
695 rtl::OUString lcl_getFormatCIDforSelectedCID( const ::rtl::OUString& rSelectedCID )
697 ::rtl::OUString aFormatCID(rSelectedCID);
699 //get type of selected object
700 ObjectType eObjectType = ObjectIdentifier::getObjectType( aFormatCID );
702 // some legend entries are handled as if they were data series
703 if( OBJECTTYPE_LEGEND_ENTRY==eObjectType )
705 rtl::OUString aParentParticle( ObjectIdentifier::getFullParentParticle( rSelectedCID ) );
706 aFormatCID = ObjectIdentifier::createClassifiedIdentifierForParticle( aParentParticle );
709 // treat diagram as wall
710 if( OBJECTTYPE_DIAGRAM==eObjectType )
711 aFormatCID = ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, rtl::OUString() );
713 return aFormatCID;
716 }//end anonymous namespace
718 void SAL_CALL ChartController::executeDlg_ObjectProperties( const ::rtl::OUString& rSelectedObjectCID )
720 rtl::OUString aObjectCID = lcl_getFormatCIDforSelectedCID( rSelectedObjectCID );
722 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription(
723 ActionDescriptionProvider::FORMAT,
724 ObjectNameProvider::getName( ObjectIdentifier::getObjectType( aObjectCID ))),
725 m_xUndoManager );
727 bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, false );
728 if( bSuccess )
729 aUndoGuard.commit();
732 bool ChartController::executeDlg_ObjectProperties_withoutUndoGuard( const ::rtl::OUString& rObjectCID, bool bOkClickOnUnchangedDialogSouldBeRatedAsSuccessAlso )
734 //return true if the properties were changed successfully
735 bool bRet = false;
736 if( rObjectCID.isEmpty() )
738 return bRet;
742 NumberFormatterWrapper aNumberFormatterWrapper( uno::Reference< util::XNumberFormatsSupplier >(getModel(), uno::UNO_QUERY) );
744 //-------------------------------------------------------------
745 //get type of object
746 ObjectType eObjectType = ObjectIdentifier::getObjectType( rObjectCID );
747 if( OBJECTTYPE_UNKNOWN==eObjectType )
749 return bRet;
751 if( OBJECTTYPE_DIAGRAM_WALL==eObjectType || OBJECTTYPE_DIAGRAM_FLOOR==eObjectType )
753 if( !DiagramHelper::isSupportingFloorAndWall( ChartModelHelper::findDiagram( getModel() ) ) )
754 return bRet;
757 //-------------------------------------------------------------
758 //convert properties to ItemSet
760 awt::Size aPageSize( ChartModelHelper::getPageSize(getModel()) );
762 SAL_WNODEPRECATED_DECLARATIONS_PUSH
763 ::std::auto_ptr< ReferenceSizeProvider > pRefSizeProv(
764 impl_createReferenceSizeProvider());
765 ::std::auto_ptr< ::comphelper::ItemConverter > apItemConverter(
766 createItemConverter( rObjectCID, getModel(), m_xCC,
767 m_pDrawModelWrapper->getSdrModel(),
768 &aNumberFormatterWrapper,
769 ExplicitValueProvider::getExplicitValueProvider(m_xChartView),
770 pRefSizeProv ));
771 SAL_WNODEPRECATED_DECLARATIONS_POP
772 if(!apItemConverter.get())
773 return bRet;
775 SfxItemSet aItemSet = apItemConverter->CreateEmptyItemSet();
777 if ( eObjectType == OBJECTTYPE_DATA_ERRORS_X || eObjectType == OBJECTTYPE_DATA_ERRORS_Y )
778 aItemSet.Put(SfxBoolItem(SCHATTR_STAT_ERRORBAR_TYPE, eObjectType == OBJECTTYPE_DATA_ERRORS_Y ));
780 apItemConverter->FillItemSet( aItemSet );
782 //-------------------------------------------------------------
783 //prepare dialog
784 ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter( rObjectCID );
785 aDialogParameter.init( getModel() );
786 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get() );
788 SolarMutexGuard aGuard;
789 SchAttribTabDlg aDlg( m_pChartWindow, &aItemSet, &aDialogParameter, &aViewElementListProvider
790 , uno::Reference< util::XNumberFormatsSupplier >( getModel(), uno::UNO_QUERY ) );
792 if(aDialogParameter.HasSymbolProperties())
794 SfxItemSet* pSymbolShapeProperties=NULL;
795 uno::Reference< beans::XPropertySet > xObjectProperties =
796 ObjectIdentifier::getObjectPropertySet( rObjectCID, getModel() );
797 wrapper::DataPointItemConverter aSymbolItemConverter( getModel(), m_xCC
798 , xObjectProperties, ObjectIdentifier::getDataSeriesForCID( rObjectCID, getModel() )
799 , m_pDrawModelWrapper->getSdrModel().GetItemPool()
800 , m_pDrawModelWrapper->getSdrModel()
801 , &aNumberFormatterWrapper
802 , uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY )
803 , wrapper::GraphicPropertyItemConverter::FILLED_DATA_POINT );
805 pSymbolShapeProperties = new SfxItemSet( aSymbolItemConverter.CreateEmptyItemSet() );
806 aSymbolItemConverter.FillItemSet( *pSymbolShapeProperties );
808 sal_Int32 nStandardSymbol=0;//@todo get from somewhere
809 Graphic* pAutoSymbolGraphic = new Graphic( aViewElementListProvider.GetSymbolGraphic( nStandardSymbol, pSymbolShapeProperties ) );
810 // note: the dialog takes the ownership of pSymbolShapeProperties and pAutoSymbolGraphic
811 aDlg.setSymbolInformation( pSymbolShapeProperties, pAutoSymbolGraphic );
813 if( aDialogParameter.HasStatisticProperties() )
815 aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
816 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), m_xChartView, rObjectCID ) );
819 //-------------------------------------------------------------
820 //open the dialog
821 if( aDlg.Execute() == RET_OK || (bOkClickOnUnchangedDialogSouldBeRatedAsSuccessAlso && aDlg.DialogWasClosedWithOK()) )
823 const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
824 if(pOutItemSet)
826 ControllerLockGuard aCLGuard( getModel());
827 apItemConverter->ApplyItemSet( *pOutItemSet );//model should be changed now
828 bRet = true;
832 catch( const util::CloseVetoException& )
835 catch( const uno::RuntimeException& )
838 return bRet;
841 void SAL_CALL ChartController::executeDispatch_View3D()
845 // using assignment for broken gcc 3.3
846 UndoLiveUpdateGuard aUndoGuard = UndoLiveUpdateGuard(
847 String( SchResId( STR_ACTION_EDIT_3D_VIEW )),
848 m_xUndoManager );
850 //open dialog
851 SolarMutexGuard aSolarGuard;
852 View3DDialog aDlg( m_pChartWindow, getModel(), m_pDrawModelWrapper->GetColorList() );
853 if( aDlg.Execute() == RET_OK )
854 aUndoGuard.commit();
856 catch(const uno::RuntimeException& e)
858 ASSERT_EXCEPTION( e );
862 //.............................................................................
863 } //namespace chart
864 //.............................................................................
866 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */