Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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 "AxisItemConverter.hxx"
32 : #include "MultipleChartConverters.hxx"
33 : #include "TitleItemConverter.hxx"
34 : #include "LegendItemConverter.hxx"
35 : #include "RegressionCurveItemConverter.hxx"
36 : #include "RegressionEquationItemConverter.hxx"
37 : #include "ErrorBarItemConverter.hxx"
38 : #include "ChartModelHelper.hxx"
39 : #include "AxisHelper.hxx"
40 : #include "TitleHelper.hxx"
41 : #include "LegendHelper.hxx"
42 : #include "ChartTypeHelper.hxx"
43 : #include "ColorPerPointHelper.hxx"
44 : #include "DiagramHelper.hxx"
45 : #include "servicenames_charttypes.hxx"
46 : #include "ControllerLockGuard.hxx"
47 : #include "UndoGuard.hxx"
48 : #include "ObjectNameProvider.hxx"
49 : #include "ResId.hxx"
50 : #include "Strings.hrc"
51 : #include "ReferenceSizeProvider.hxx"
52 : #include "RegressionCurveHelper.hxx"
53 : #include <com/sun/star/chart2/XChartDocument.hpp>
54 :
55 : //for auto_ptr
56 : #include <memory>
57 :
58 : // header for define RET_OK
59 : #include <vcl/msgbox.hxx>
60 : // for SolarMutex
61 : #include <vcl/svapp.hxx>
62 : #include <osl/mutex.hxx>
63 : #include <svx/ActionDescriptionProvider.hxx>
64 :
65 : //.............................................................................
66 : namespace chart
67 : {
68 : //.............................................................................
69 : using namespace ::com::sun::star;
70 : using namespace ::com::sun::star::chart2;
71 : using ::com::sun::star::uno::Reference;
72 :
73 : namespace
74 : {
75 :
76 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
77 0 : ::comphelper::ItemConverter* createItemConverter(
78 : const OUString & aObjectCID
79 : , const uno::Reference< frame::XModel > & xChartModel
80 : , const uno::Reference< uno::XComponentContext > & xContext
81 : , SdrModel & rDrawModel
82 : , ExplicitValueProvider * pExplicitValueProvider = NULL
83 : , ::std::auto_ptr< ReferenceSizeProvider > pRefSizeProvider =
84 : ::std::auto_ptr< ReferenceSizeProvider >()
85 : )
86 : {
87 0 : ::comphelper::ItemConverter* pItemConverter=NULL;
88 :
89 : //-------------------------------------------------------------
90 : //get type of selected object
91 0 : ObjectType eObjectType = ObjectIdentifier::getObjectType( aObjectCID );
92 0 : if( OBJECTTYPE_UNKNOWN==eObjectType )
93 : {
94 : OSL_FAIL("unknown ObjectType");
95 0 : return NULL;
96 : }
97 :
98 0 : OUString aParticleID = ObjectIdentifier::getParticleID( aObjectCID );
99 0 : bool bAffectsMultipleObjects = aParticleID == "ALLELEMENTS";
100 : //-------------------------------------------------------------
101 0 : if( !bAffectsMultipleObjects )
102 : {
103 : uno::Reference< beans::XPropertySet > xObjectProperties =
104 0 : ObjectIdentifier::getObjectPropertySet( aObjectCID, xChartModel );
105 0 : if(!xObjectProperties.is())
106 0 : return NULL;
107 : //create itemconverter for a single object
108 0 : switch(eObjectType)
109 : {
110 : case OBJECTTYPE_PAGE:
111 : pItemConverter = new wrapper::GraphicPropertyItemConverter(
112 : xObjectProperties, rDrawModel.GetItemPool(),
113 : rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
114 0 : wrapper::GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES );
115 0 : break;
116 : case OBJECTTYPE_TITLE:
117 : {
118 0 : ::std::auto_ptr< awt::Size > pRefSize;
119 0 : if( pRefSizeProvider.get() )
120 0 : pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
121 :
122 : pItemConverter = new wrapper::TitleItemConverter( xObjectProperties,
123 : rDrawModel.GetItemPool(), rDrawModel,
124 : uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
125 0 : pRefSize );
126 : }
127 0 : break;
128 : case OBJECTTYPE_LEGEND:
129 : {
130 0 : ::std::auto_ptr< awt::Size > pRefSize;
131 0 : if( pRefSizeProvider.get() )
132 0 : pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
133 :
134 : pItemConverter = new wrapper::LegendItemConverter( xObjectProperties,
135 : rDrawModel.GetItemPool(), rDrawModel,
136 : uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
137 0 : pRefSize );
138 : }
139 0 : break;
140 : case OBJECTTYPE_LEGEND_ENTRY:
141 0 : break;
142 : case OBJECTTYPE_DIAGRAM:
143 0 : break;
144 : case OBJECTTYPE_DIAGRAM_WALL:
145 : case OBJECTTYPE_DIAGRAM_FLOOR:
146 : pItemConverter = new wrapper::GraphicPropertyItemConverter(
147 : xObjectProperties, rDrawModel.GetItemPool(),
148 : rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
149 0 : wrapper::GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES );
150 0 : break;
151 : case OBJECTTYPE_AXIS:
152 : {
153 0 : ::std::auto_ptr< awt::Size > pRefSize;
154 0 : if( pRefSizeProvider.get() )
155 0 : pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
156 :
157 0 : uno::Reference< beans::XPropertySet > xDiaProp;
158 0 : xDiaProp.set( ChartModelHelper::findDiagram( xChartModel ), uno::UNO_QUERY );
159 :
160 : // the second property set contains the property CoordinateOrigin
161 : // nOriginIndex is the index of the corresponding index of the
162 : // origin (x=0, y=1, z=2)
163 :
164 0 : ExplicitScaleData aExplicitScale;
165 0 : ExplicitIncrementData aExplicitIncrement;
166 0 : if( pExplicitValueProvider )
167 : pExplicitValueProvider->getExplicitValuesForAxis(
168 : uno::Reference< XAxis >( xObjectProperties, uno::UNO_QUERY ),
169 0 : aExplicitScale, aExplicitIncrement );
170 :
171 : pItemConverter = new wrapper::AxisItemConverter(
172 : xObjectProperties, rDrawModel.GetItemPool(),
173 : rDrawModel,
174 : uno::Reference< chart2::XChartDocument >( xChartModel, uno::UNO_QUERY ),
175 : &aExplicitScale, &aExplicitIncrement,
176 0 : pRefSize );
177 : }
178 0 : break;
179 : case OBJECTTYPE_AXIS_UNITLABEL:
180 0 : break;
181 : case OBJECTTYPE_DATA_LABELS:
182 : case OBJECTTYPE_DATA_SERIES:
183 : case OBJECTTYPE_DATA_LABEL:
184 : case OBJECTTYPE_DATA_POINT:
185 : {
186 0 : ::std::auto_ptr< awt::Size > pRefSize;
187 0 : if( pRefSizeProvider.get() )
188 0 : pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
189 :
190 : wrapper::GraphicPropertyItemConverter::eGraphicObjectType eMapTo =
191 0 : wrapper::GraphicPropertyItemConverter::FILLED_DATA_POINT;
192 :
193 0 : uno::Reference< XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel );
194 0 : uno::Reference< XChartType > xChartType = ChartModelHelper::getChartTypeOfSeries( xChartModel, xSeries );
195 :
196 0 : uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
197 0 : sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
198 0 : if( !ChartTypeHelper::isSupportingAreaProperties( xChartType, nDimensionCount ) )
199 0 : eMapTo = wrapper::GraphicPropertyItemConverter::LINE_DATA_POINT;
200 :
201 0 : bool bDataSeries = ( eObjectType == OBJECTTYPE_DATA_SERIES || eObjectType == OBJECTTYPE_DATA_LABELS );
202 :
203 : //special color for pie chart:
204 0 : bool bUseSpecialFillColor = false;
205 0 : sal_Int32 nSpecialFillColor =0;
206 0 : sal_Int32 nPointIndex = -1; /*-1 for whole series*/
207 0 : if(!bDataSeries)
208 : {
209 0 : nPointIndex = aParticleID.toInt32();
210 0 : uno::Reference< beans::XPropertySet > xSeriesProp( xSeries, uno::UNO_QUERY );
211 0 : bool bVaryColorsByPoint = false;
212 0 : if( xSeriesProp.is() &&
213 0 : (xSeriesProp->getPropertyValue("VaryColorsByPoint") >>= bVaryColorsByPoint) &&
214 : bVaryColorsByPoint )
215 : {
216 0 : if( !ColorPerPointHelper::hasPointOwnColor( xSeriesProp, nPointIndex, xObjectProperties ) )
217 : {
218 0 : bUseSpecialFillColor = true;
219 : OSL_ASSERT( xDiagram.is());
220 0 : uno::Reference< XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme() );
221 0 : if( xColorScheme.is())
222 0 : nSpecialFillColor = xColorScheme->getColorByIndex( nPointIndex );
223 : }
224 0 : }
225 : }
226 0 : sal_Int32 nNumberFormat=ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel( xObjectProperties, xSeries, nPointIndex, xDiagram );
227 : sal_Int32 nPercentNumberFormat=ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabel(
228 0 : xObjectProperties,uno::Reference< util::XNumberFormatsSupplier >(xChartModel, uno::UNO_QUERY));
229 :
230 : pItemConverter = new wrapper::DataPointItemConverter( xChartModel, xContext,
231 : xObjectProperties, xSeries, rDrawModel.GetItemPool(), rDrawModel,
232 : uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
233 : eMapTo, pRefSize, bDataSeries, bUseSpecialFillColor, nSpecialFillColor, true,
234 0 : nNumberFormat, nPercentNumberFormat );
235 0 : break;
236 : }
237 : case OBJECTTYPE_GRID:
238 : case OBJECTTYPE_SUBGRID:
239 : case OBJECTTYPE_DATA_AVERAGE_LINE:
240 : pItemConverter = new wrapper::GraphicPropertyItemConverter(
241 : xObjectProperties, rDrawModel.GetItemPool(),
242 : rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
243 0 : wrapper::GraphicPropertyItemConverter::LINE_PROPERTIES );
244 0 : break;
245 :
246 : case OBJECTTYPE_DATA_ERRORS_X:
247 : case OBJECTTYPE_DATA_ERRORS_Y:
248 : case OBJECTTYPE_DATA_ERRORS_Z:
249 : pItemConverter = new wrapper::ErrorBarItemConverter(
250 : xChartModel, xObjectProperties, rDrawModel.GetItemPool(),
251 0 : rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
252 0 : break;
253 :
254 : case OBJECTTYPE_DATA_CURVE:
255 : pItemConverter = new wrapper::RegressionCurveItemConverter(
256 : xObjectProperties, uno::Reference< chart2::XRegressionCurveContainer >(
257 : ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel ), uno::UNO_QUERY ),
258 : rDrawModel.GetItemPool(), rDrawModel,
259 0 : uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
260 0 : break;
261 : case OBJECTTYPE_DATA_CURVE_EQUATION:
262 : {
263 0 : ::std::auto_ptr< awt::Size > pRefSize;
264 0 : if( pRefSizeProvider.get() )
265 0 : pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
266 :
267 : pItemConverter = new wrapper::RegressionEquationItemConverter(
268 : xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
269 : uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
270 0 : pRefSize );
271 0 : break;
272 : }
273 : case OBJECTTYPE_DATA_STOCK_RANGE:
274 0 : break;
275 : case OBJECTTYPE_DATA_STOCK_LOSS:
276 : case OBJECTTYPE_DATA_STOCK_GAIN:
277 : pItemConverter = new wrapper::GraphicPropertyItemConverter(
278 : xObjectProperties, rDrawModel.GetItemPool(),
279 : rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
280 0 : wrapper::GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES );
281 0 : break;
282 : default: //OBJECTTYPE_UNKNOWN
283 0 : break;
284 0 : }
285 : }
286 : else
287 : {
288 : //create itemconverter for a all objects of given type
289 0 : switch(eObjectType)
290 : {
291 : case OBJECTTYPE_TITLE:
292 : pItemConverter = new wrapper::AllTitleItemConverter( xChartModel, rDrawModel.GetItemPool(),
293 0 : rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
294 0 : break;
295 : case OBJECTTYPE_AXIS:
296 : {
297 0 : ::std::auto_ptr< awt::Size > pRefSize;
298 0 : if( pRefSizeProvider.get() )
299 0 : pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize()));
300 :
301 : pItemConverter = new wrapper::AllAxisItemConverter( xChartModel, rDrawModel.GetItemPool(),
302 0 : rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ), pRefSize );
303 : }
304 0 : break;
305 : case OBJECTTYPE_GRID:
306 : case OBJECTTYPE_SUBGRID:
307 : pItemConverter = new wrapper::AllGridItemConverter( xChartModel, rDrawModel.GetItemPool(),
308 0 : rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ));
309 0 : break;
310 : default: //for this type it is not supported to change all elements at once
311 0 : break;
312 : }
313 :
314 : }
315 0 : return pItemConverter;
316 : }
317 : SAL_WNODEPRECATED_DECLARATIONS_POP
318 :
319 0 : OUString lcl_getTitleCIDForCommand( const OString& rDispatchCommand, const uno::Reference< frame::XModel > & xChartModel )
320 : {
321 0 : if( rDispatchCommand.equals("AllTitles"))
322 0 : return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_TITLE, "ALLELEMENTS" );
323 :
324 0 : TitleHelper::eTitleType nTitleType( TitleHelper::MAIN_TITLE );
325 0 : if( rDispatchCommand.equals("SubTitle") )
326 0 : nTitleType = TitleHelper::SUB_TITLE;
327 0 : else if( rDispatchCommand.equals("XTitle") )
328 0 : nTitleType = TitleHelper::X_AXIS_TITLE;
329 0 : else if( rDispatchCommand.equals("YTitle") )
330 0 : nTitleType = TitleHelper::Y_AXIS_TITLE;
331 0 : else if( rDispatchCommand.equals("ZTitle") )
332 0 : nTitleType = TitleHelper::Z_AXIS_TITLE;
333 0 : else if( rDispatchCommand.equals("SecondaryXTitle") )
334 0 : nTitleType = TitleHelper::SECONDARY_X_AXIS_TITLE;
335 0 : else if( rDispatchCommand.equals("SecondaryYTitle") )
336 0 : nTitleType = TitleHelper::SECONDARY_Y_AXIS_TITLE;
337 :
338 0 : uno::Reference< XTitle > xTitle( TitleHelper::getTitle( nTitleType, xChartModel ) );
339 0 : return ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, xChartModel );
340 : }
341 :
342 0 : OUString lcl_getAxisCIDForCommand( const OString& rDispatchCommand, const uno::Reference< frame::XModel >& xChartModel )
343 : {
344 0 : if( rDispatchCommand.equals("DiagramAxisAll"))
345 0 : return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_AXIS, "ALLELEMENTS" );
346 :
347 0 : sal_Int32 nDimensionIndex=0;
348 0 : bool bMainAxis=true;
349 0 : if( rDispatchCommand.equals("DiagramAxisX"))
350 : {
351 0 : nDimensionIndex=0; bMainAxis=true;
352 : }
353 0 : else if( rDispatchCommand.equals("DiagramAxisY"))
354 : {
355 0 : nDimensionIndex=1; bMainAxis=true;
356 : }
357 0 : else if( rDispatchCommand.equals("DiagramAxisZ"))
358 : {
359 0 : nDimensionIndex=2; bMainAxis=true;
360 : }
361 0 : else if( rDispatchCommand.equals("DiagramAxisA"))
362 : {
363 0 : nDimensionIndex=0; bMainAxis=false;
364 : }
365 0 : else if( rDispatchCommand.equals("DiagramAxisB"))
366 : {
367 0 : nDimensionIndex=1; bMainAxis=false;
368 : }
369 :
370 0 : uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
371 0 : uno::Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
372 0 : return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, xChartModel );
373 : }
374 :
375 0 : OUString lcl_getGridCIDForCommand( const OString& rDispatchCommand, const uno::Reference< frame::XModel >& xChartModel )
376 : {
377 0 : uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
378 :
379 0 : if( rDispatchCommand.equals("DiagramGridAll"))
380 0 : return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_GRID, "ALLELEMENTS" );
381 :
382 0 : sal_Int32 nDimensionIndex=0;
383 0 : bool bMainGrid=true;
384 :
385 : //x and y is swapped in the commands
386 :
387 0 : if( rDispatchCommand.equals("DiagramGridYMain"))
388 : {
389 0 : nDimensionIndex=0; bMainGrid=true;
390 : }
391 0 : else if( rDispatchCommand.equals("DiagramGridXMain"))
392 : {
393 0 : nDimensionIndex=1; bMainGrid=true;
394 : }
395 0 : else if( rDispatchCommand.equals("DiagramGridZMain"))
396 : {
397 0 : nDimensionIndex=2; bMainGrid=true;
398 : }
399 0 : else if( rDispatchCommand.equals("DiagramGridYHelp"))
400 : {
401 0 : nDimensionIndex=0; bMainGrid=false;
402 : }
403 0 : else if( rDispatchCommand.equals("DiagramGridXHelp"))
404 : {
405 0 : nDimensionIndex=1; bMainGrid=false;
406 : }
407 0 : else if( rDispatchCommand.equals("DiagramGridZHelp"))
408 : {
409 0 : nDimensionIndex=2; bMainGrid=false;
410 : }
411 :
412 0 : bool bMainAxis = true;
413 0 : uno::Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
414 :
415 0 : sal_Int32 nSubGridIndex= bMainGrid ? (-1) : 0;
416 0 : OUString aCID( ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel, nSubGridIndex ) );
417 0 : return aCID;
418 : }
419 :
420 0 : OUString lcl_getErrorCIDForCommand( const ObjectType eDispatchType, const ObjectType &eSelectedType, const OUString &rSelectedCID)
421 : {
422 0 : if( eSelectedType == eDispatchType )
423 0 : return rSelectedCID;
424 :
425 0 : return ObjectIdentifier::createClassifiedIdentifierWithParent( eDispatchType, OUString(), rSelectedCID );
426 : }
427 :
428 0 : OUString lcl_getObjectCIDForCommand( const OString& rDispatchCommand, const uno::Reference< XChartDocument > & xChartDocument, const OUString& rSelectedCID )
429 : {
430 0 : ObjectType eObjectType = OBJECTTYPE_UNKNOWN;
431 0 : OUString aParticleID;
432 :
433 0 : uno::Reference< frame::XModel > xChartModel( xChartDocument, uno::UNO_QUERY );
434 0 : const ObjectType eSelectedType = ObjectIdentifier::getObjectType( rSelectedCID );
435 0 : uno::Reference< XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rSelectedCID, xChartModel );
436 0 : uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( xSeries, uno::UNO_QUERY );
437 :
438 : //-------------------------------------------------------------------------
439 : //legend
440 0 : if( rDispatchCommand.equals("Legend") || rDispatchCommand.equals("FormatLegend") )
441 : {
442 0 : eObjectType = OBJECTTYPE_LEGEND;
443 : //@todo set particular aParticleID if we have more than one legend
444 : }
445 : //-------------------------------------------------------------------------
446 : //wall floor area
447 0 : else if( rDispatchCommand.equals("DiagramWall") || rDispatchCommand.equals("FormatWall") )
448 : {
449 : //OBJECTTYPE_DIAGRAM;
450 0 : eObjectType = OBJECTTYPE_DIAGRAM_WALL;
451 : //@todo set particular aParticleID if we have more than one diagram
452 : }
453 0 : else if( rDispatchCommand.equals("DiagramFloor") || rDispatchCommand.equals("FormatFloor") )
454 : {
455 0 : eObjectType = OBJECTTYPE_DIAGRAM_FLOOR;
456 : //@todo set particular aParticleID if we have more than one diagram
457 : }
458 0 : else if( rDispatchCommand.equals("DiagramArea") || rDispatchCommand.equals("FormatChartArea") )
459 : {
460 0 : eObjectType = OBJECTTYPE_PAGE;
461 : }
462 : //-------------------------------------------------------------------------
463 : //title
464 0 : else if( rDispatchCommand.equals("MainTitle")
465 0 : || rDispatchCommand.equals("SubTitle")
466 0 : || rDispatchCommand.equals("XTitle")
467 0 : || rDispatchCommand.equals("YTitle")
468 0 : || rDispatchCommand.equals("ZTitle")
469 0 : || rDispatchCommand.equals("SecondaryXTitle")
470 0 : || rDispatchCommand.equals("SecondaryYTitle")
471 0 : || rDispatchCommand.equals("AllTitles")
472 : )
473 : {
474 0 : return lcl_getTitleCIDForCommand( rDispatchCommand, xChartModel );
475 : }
476 : //-------------------------------------------------------------------------
477 : //axis
478 0 : else if( rDispatchCommand.equals("DiagramAxisX")
479 0 : || rDispatchCommand.equals("DiagramAxisY")
480 0 : || rDispatchCommand.equals("DiagramAxisZ")
481 0 : || rDispatchCommand.equals("DiagramAxisA")
482 0 : || rDispatchCommand.equals("DiagramAxisB")
483 0 : || rDispatchCommand.equals("DiagramAxisAll")
484 : )
485 : {
486 0 : return lcl_getAxisCIDForCommand( rDispatchCommand, xChartModel );
487 : }
488 : //-------------------------------------------------------------------------
489 : //grid
490 0 : else if( rDispatchCommand.equals("DiagramGridYMain")
491 0 : || rDispatchCommand.equals("DiagramGridXMain")
492 0 : || rDispatchCommand.equals("DiagramGridZMain")
493 0 : || rDispatchCommand.equals("DiagramGridYHelp")
494 0 : || rDispatchCommand.equals("DiagramGridXHelp")
495 0 : || rDispatchCommand.equals("DiagramGridZHelp")
496 0 : || rDispatchCommand.equals("DiagramGridAll")
497 : )
498 : {
499 0 : return lcl_getGridCIDForCommand( rDispatchCommand, xChartModel );
500 : }
501 : //-------------------------------------------------------------------------
502 : //data series
503 0 : else if( rDispatchCommand.equals("FormatDataSeries") )
504 : {
505 0 : if( eSelectedType == OBJECTTYPE_DATA_SERIES )
506 0 : return rSelectedCID;
507 : else
508 : return ObjectIdentifier::createClassifiedIdentifier(
509 0 : OBJECTTYPE_DATA_SERIES, ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ) );
510 : }
511 : //-------------------------------------------------------------------------
512 : //data point
513 0 : else if( rDispatchCommand.equals("FormatDataPoint") )
514 : {
515 0 : return rSelectedCID;
516 : }
517 : //-------------------------------------------------------------------------
518 : //data labels
519 0 : else if( rDispatchCommand.equals("FormatDataLabels") )
520 : {
521 0 : if( eSelectedType == OBJECTTYPE_DATA_LABELS )
522 0 : return rSelectedCID;
523 : else
524 : return ObjectIdentifier::createClassifiedIdentifierWithParent(
525 0 : OBJECTTYPE_DATA_LABELS, OUString(), rSelectedCID );
526 : }
527 : //-------------------------------------------------------------------------
528 : //data labels
529 0 : else if( rDispatchCommand.equals("FormatDataLabel") )
530 : {
531 0 : if( eSelectedType == OBJECTTYPE_DATA_LABEL )
532 0 : return rSelectedCID;
533 : else
534 : {
535 0 : sal_Int32 nPointIndex = ObjectIdentifier::getParticleID( rSelectedCID ).toInt32();
536 0 : if( nPointIndex>=0 )
537 : {
538 0 : OUString aSeriesParticle = ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID );
539 0 : OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) + "=" );
540 0 : OUString aLabelsCID = ObjectIdentifier::createClassifiedIdentifierForParticles( aSeriesParticle, aChildParticle );
541 : OUString aLabelCID_Stub = ObjectIdentifier::createClassifiedIdentifierWithParent(
542 0 : OBJECTTYPE_DATA_LABEL, OUString(), aLabelsCID );
543 :
544 0 : return ObjectIdentifier::createPointCID( aLabelCID_Stub, nPointIndex );
545 : }
546 : }
547 : }
548 : //-------------------------------------------------------------------------
549 : //mean value line
550 0 : else if( rDispatchCommand.equals("FormatMeanValue") )
551 : {
552 0 : if( eSelectedType == OBJECTTYPE_DATA_AVERAGE_LINE )
553 0 : return rSelectedCID;
554 : else
555 : return ObjectIdentifier::createDataCurveCID(
556 : ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ),
557 : RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt,
558 0 : RegressionCurveHelper::getMeanValueLine( xRegCurveCnt ) ), true );
559 : }
560 : //-------------------------------------------------------------------------
561 : //trend line
562 0 : else if( rDispatchCommand.equals("FormatTrendline") )
563 : {
564 0 : if( eSelectedType == OBJECTTYPE_DATA_CURVE )
565 0 : return rSelectedCID;
566 : else
567 : return ObjectIdentifier::createDataCurveCID(
568 : ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ),
569 : RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt,
570 0 : RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) ), false );
571 : }
572 : //-------------------------------------------------------------------------
573 : //trend line equation
574 0 : else if( rDispatchCommand.equals("FormatTrendlineEquation") )
575 : {
576 0 : if( eSelectedType == OBJECTTYPE_DATA_CURVE_EQUATION )
577 0 : return rSelectedCID;
578 : else
579 : return ObjectIdentifier::createDataCurveEquationCID(
580 : ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ),
581 : RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt,
582 0 : RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) ) );
583 : }
584 : //-------------------------------------------------------------------------
585 : // y error bars
586 0 : else if( rDispatchCommand.equals("FormatXErrorBars") )
587 : {
588 0 : return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_X, eSelectedType, rSelectedCID );
589 : }
590 : //-------------------------------------------------------------------------
591 : // y error bars
592 0 : else if( rDispatchCommand.equals("FormatYErrorBars") )
593 : {
594 0 : return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_Y, eSelectedType, rSelectedCID );
595 : }
596 : //-------------------------------------------------------------------------
597 : // axis
598 0 : else if( rDispatchCommand.equals("FormatAxis") )
599 : {
600 0 : if( eSelectedType == OBJECTTYPE_AXIS )
601 0 : return rSelectedCID;
602 : else
603 : {
604 0 : Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartModel );
605 0 : return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis , xChartModel );
606 : }
607 : }
608 : //-------------------------------------------------------------------------
609 : // major grid
610 0 : else if( rDispatchCommand.equals("FormatMajorGrid") )
611 : {
612 0 : if( eSelectedType == OBJECTTYPE_GRID )
613 0 : return rSelectedCID;
614 : else
615 : {
616 0 : Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartModel );
617 0 : return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel );
618 : }
619 :
620 : }
621 : //-------------------------------------------------------------------------
622 : // minor grid
623 0 : else if( rDispatchCommand.equals("FormatMinorGrid") )
624 : {
625 0 : if( eSelectedType == OBJECTTYPE_SUBGRID )
626 0 : return rSelectedCID;
627 : else
628 : {
629 0 : Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartModel );
630 0 : return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel, 0 /*sub grid index*/ );
631 : }
632 : }
633 : //-------------------------------------------------------------------------
634 : // title
635 0 : else if( rDispatchCommand.equals("FormatTitle") )
636 : {
637 0 : if( eSelectedType == OBJECTTYPE_TITLE )
638 0 : return rSelectedCID;
639 : }
640 : //-------------------------------------------------------------------------
641 : // stock loss
642 0 : else if( rDispatchCommand.equals("FormatStockLoss") )
643 : {
644 0 : if( eSelectedType == OBJECTTYPE_DATA_STOCK_LOSS )
645 0 : return rSelectedCID;
646 : else
647 0 : return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_LOSS, OUString());
648 : }
649 : //-------------------------------------------------------------------------
650 : // stock gain
651 0 : else if( rDispatchCommand.equals("FormatStockGain") )
652 : {
653 0 : if( eSelectedType == OBJECTTYPE_DATA_STOCK_GAIN )
654 0 : return rSelectedCID;
655 : else
656 0 : return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_GAIN, OUString() );
657 : }
658 :
659 : return ObjectIdentifier::createClassifiedIdentifier(
660 0 : eObjectType, aParticleID );
661 : }
662 :
663 : }
664 : // anonymous namespace
665 :
666 0 : void SAL_CALL ChartController::executeDispatch_FormatObject(const OUString& rDispatchCommand)
667 : {
668 0 : uno::Reference< XChartDocument > xChartDocument( getModel(), uno::UNO_QUERY );
669 0 : OString aCommand( OUStringToOString( rDispatchCommand, RTL_TEXTENCODING_ASCII_US ) );
670 0 : OUString rObjectCID = lcl_getObjectCIDForCommand( aCommand, xChartDocument, m_aSelection.getSelectedCID() );
671 0 : executeDlg_ObjectProperties( rObjectCID );
672 0 : }
673 :
674 0 : void SAL_CALL ChartController::executeDispatch_ObjectProperties()
675 : {
676 0 : executeDlg_ObjectProperties( m_aSelection.getSelectedCID() );
677 0 : }
678 :
679 : namespace
680 : {
681 :
682 0 : OUString lcl_getFormatCIDforSelectedCID( const OUString& rSelectedCID )
683 : {
684 0 : OUString aFormatCID(rSelectedCID);
685 :
686 : //get type of selected object
687 0 : ObjectType eObjectType = ObjectIdentifier::getObjectType( aFormatCID );
688 :
689 : // some legend entries are handled as if they were data series
690 0 : if( OBJECTTYPE_LEGEND_ENTRY==eObjectType )
691 : {
692 0 : OUString aParentParticle( ObjectIdentifier::getFullParentParticle( rSelectedCID ) );
693 0 : aFormatCID = ObjectIdentifier::createClassifiedIdentifierForParticle( aParentParticle );
694 : }
695 :
696 : // treat diagram as wall
697 0 : if( OBJECTTYPE_DIAGRAM==eObjectType )
698 0 : aFormatCID = ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, OUString() );
699 :
700 0 : return aFormatCID;
701 : }
702 :
703 : }//end anonymous namespace
704 :
705 0 : void SAL_CALL ChartController::executeDlg_ObjectProperties( const OUString& rSelectedObjectCID )
706 : {
707 0 : OUString aObjectCID = lcl_getFormatCIDforSelectedCID( rSelectedObjectCID );
708 :
709 : UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription(
710 : ActionDescriptionProvider::FORMAT,
711 : ObjectNameProvider::getName( ObjectIdentifier::getObjectType( aObjectCID ))),
712 0 : m_xUndoManager );
713 :
714 0 : bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, false );
715 0 : if( bSuccess )
716 0 : aUndoGuard.commit();
717 0 : }
718 :
719 0 : bool ChartController::executeDlg_ObjectProperties_withoutUndoGuard( const OUString& rObjectCID, bool bOkClickOnUnchangedDialogSouldBeRatedAsSuccessAlso )
720 : {
721 : //return true if the properties were changed successfully
722 0 : bool bRet = false;
723 0 : if( rObjectCID.isEmpty() )
724 : {
725 0 : return bRet;
726 : }
727 : try
728 : {
729 : //-------------------------------------------------------------
730 : //get type of object
731 0 : ObjectType eObjectType = ObjectIdentifier::getObjectType( rObjectCID );
732 0 : if( OBJECTTYPE_UNKNOWN==eObjectType )
733 : {
734 0 : return bRet;
735 : }
736 0 : if( OBJECTTYPE_DIAGRAM_WALL==eObjectType || OBJECTTYPE_DIAGRAM_FLOOR==eObjectType )
737 : {
738 0 : if( !DiagramHelper::isSupportingFloorAndWall( ChartModelHelper::findDiagram( getModel() ) ) )
739 0 : return bRet;
740 : }
741 :
742 : //-------------------------------------------------------------
743 : //convert properties to ItemSet
744 :
745 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
746 : ::std::auto_ptr< ReferenceSizeProvider > pRefSizeProv(
747 0 : impl_createReferenceSizeProvider());
748 : ::std::auto_ptr< ::comphelper::ItemConverter > apItemConverter(
749 0 : createItemConverter( rObjectCID, getModel(), m_xCC,
750 0 : m_pDrawModelWrapper->getSdrModel(),
751 : ExplicitValueProvider::getExplicitValueProvider(m_xChartView),
752 0 : pRefSizeProv ));
753 : SAL_WNODEPRECATED_DECLARATIONS_POP
754 0 : if(!apItemConverter.get())
755 0 : return bRet;
756 :
757 0 : SfxItemSet aItemSet = apItemConverter->CreateEmptyItemSet();
758 :
759 0 : if ( eObjectType == OBJECTTYPE_DATA_ERRORS_X || eObjectType == OBJECTTYPE_DATA_ERRORS_Y )
760 0 : aItemSet.Put(SfxBoolItem(SCHATTR_STAT_ERRORBAR_TYPE, eObjectType == OBJECTTYPE_DATA_ERRORS_Y ));
761 :
762 0 : apItemConverter->FillItemSet( aItemSet );
763 :
764 : //-------------------------------------------------------------
765 : //prepare dialog
766 0 : ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter( rObjectCID );
767 0 : aDialogParameter.init( getModel() );
768 0 : ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get() );
769 :
770 0 : SolarMutexGuard aGuard;
771 : SchAttribTabDlg aDlg( m_pChartWindow, &aItemSet, &aDialogParameter, &aViewElementListProvider
772 0 : , uno::Reference< util::XNumberFormatsSupplier >( getModel(), uno::UNO_QUERY ) );
773 :
774 0 : if(aDialogParameter.HasSymbolProperties())
775 : {
776 0 : SfxItemSet* pSymbolShapeProperties=NULL;
777 : uno::Reference< beans::XPropertySet > xObjectProperties =
778 0 : ObjectIdentifier::getObjectPropertySet( rObjectCID, getModel() );
779 0 : wrapper::DataPointItemConverter aSymbolItemConverter( getModel(), m_xCC
780 0 : , xObjectProperties, ObjectIdentifier::getDataSeriesForCID( rObjectCID, getModel() )
781 0 : , m_pDrawModelWrapper->getSdrModel().GetItemPool()
782 0 : , m_pDrawModelWrapper->getSdrModel()
783 0 : , uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY )
784 0 : , wrapper::GraphicPropertyItemConverter::FILLED_DATA_POINT );
785 :
786 0 : pSymbolShapeProperties = new SfxItemSet( aSymbolItemConverter.CreateEmptyItemSet() );
787 0 : aSymbolItemConverter.FillItemSet( *pSymbolShapeProperties );
788 :
789 0 : sal_Int32 nStandardSymbol=0;//@todo get from somewhere
790 0 : Graphic* pAutoSymbolGraphic = new Graphic( aViewElementListProvider.GetSymbolGraphic( nStandardSymbol, pSymbolShapeProperties ) );
791 : // note: the dialog takes the ownership of pSymbolShapeProperties and pAutoSymbolGraphic
792 0 : aDlg.setSymbolInformation( pSymbolShapeProperties, pAutoSymbolGraphic );
793 : }
794 0 : if( aDialogParameter.HasStatisticProperties() )
795 : {
796 : aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
797 0 : InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), m_xChartView, rObjectCID ) );
798 : }
799 :
800 : //-------------------------------------------------------------
801 : //open the dialog
802 0 : if( aDlg.Execute() == RET_OK || (bOkClickOnUnchangedDialogSouldBeRatedAsSuccessAlso && aDlg.DialogWasClosedWithOK()) )
803 : {
804 0 : const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
805 0 : if(pOutItemSet)
806 : {
807 0 : ControllerLockGuard aCLGuard( getModel());
808 0 : apItemConverter->ApplyItemSet( *pOutItemSet );//model should be changed now
809 0 : bRet = true;
810 : }
811 0 : }
812 : }
813 0 : catch( const util::CloseVetoException& )
814 : {
815 : }
816 0 : catch( const uno::RuntimeException& )
817 : {
818 : }
819 0 : return bRet;
820 : }
821 :
822 0 : void SAL_CALL ChartController::executeDispatch_View3D()
823 : {
824 : try
825 : {
826 : // using assignment for broken gcc 3.3
827 : UndoLiveUpdateGuard aUndoGuard = UndoLiveUpdateGuard(
828 : String( SchResId( STR_ACTION_EDIT_3D_VIEW )),
829 0 : m_xUndoManager );
830 :
831 : //open dialog
832 0 : SolarMutexGuard aSolarGuard;
833 0 : View3DDialog aDlg( m_pChartWindow, getModel(), m_pDrawModelWrapper->GetColorList() );
834 0 : if( aDlg.Execute() == RET_OK )
835 0 : aUndoGuard.commit();
836 : }
837 0 : catch(const uno::RuntimeException& e)
838 : {
839 : ASSERT_EXCEPTION( e );
840 : }
841 0 : }
842 :
843 : //.............................................................................
844 33 : } //namespace chart
845 : //.............................................................................
846 :
847 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|