1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_chart2.hxx" 30 #include "ChartController.hxx" 31 #include "ChartWindow.hxx" 32 #include "chartview/DrawModelWrapper.hxx" 33 #include "ObjectIdentifier.hxx" 34 #include "chartview/ExplicitValueProvider.hxx" 35 #include "macros.hxx" 36 #include "dlg_ObjectProperties.hxx" 37 #include "dlg_View3D.hxx" 38 #include "dlg_InsertErrorBars.hxx" 39 #include "ViewElementListProvider.hxx" 40 #include "DataPointItemConverter.hxx" 41 #include "AxisItemConverter.hxx" 42 #include "MultipleChartConverters.hxx" 43 #include "TitleItemConverter.hxx" 44 #include "LegendItemConverter.hxx" 45 #include "RegressionCurveItemConverter.hxx" 46 #include "RegressionEquationItemConverter.hxx" 47 #include "ErrorBarItemConverter.hxx" 48 #include "ChartModelHelper.hxx" 49 #include "AxisHelper.hxx" 50 #include "TitleHelper.hxx" 51 #include "LegendHelper.hxx" 52 #include "ChartTypeHelper.hxx" 53 #include "ColorPerPointHelper.hxx" 54 #include "DiagramHelper.hxx" 55 #include "servicenames_charttypes.hxx" 56 #include "ControllerLockGuard.hxx" 57 #include "UndoGuard.hxx" 58 #include "ObjectNameProvider.hxx" 59 #include "ResId.hxx" 60 #include "Strings.hrc" 61 #include "ReferenceSizeProvider.hxx" 62 #include "RegressionCurveHelper.hxx" 63 #include <com/sun/star/chart2/XChartDocument.hpp> 64 65 //for auto_ptr 66 #include <memory> 67 68 // header for define RET_OK 69 #include <vcl/msgbox.hxx> 70 // for SolarMutex 71 #include <vcl/svapp.hxx> 72 #include <vos/mutex.hxx> 73 #include <svx/ActionDescriptionProvider.hxx> 74 75 //............................................................................. 76 namespace chart 77 { 78 //............................................................................. 79 using namespace ::com::sun::star; 80 using namespace ::com::sun::star::chart2; 81 using ::com::sun::star::uno::Reference; 82 using ::rtl::OUString; 83 84 namespace 85 { 86 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 >() 96 ) 97 { 98 ::comphelper::ItemConverter* pItemConverter=NULL; 99 100 //------------------------------------------------------------- 101 //get type of selected object 102 ObjectType eObjectType = ObjectIdentifier::getObjectType( aObjectCID ); 103 if( OBJECTTYPE_UNKNOWN==eObjectType ) 104 { 105 DBG_ERROR("unknown ObjectType"); 106 return NULL; 107 } 108 //-- 109 rtl::OUString aParticleID = ObjectIdentifier::getParticleID( aObjectCID ); 110 bool bAffectsMultipleObjects = aParticleID.equals(C2U("ALLELEMENTS")); 111 //------------------------------------------------------------- 112 if( !bAffectsMultipleObjects ) 113 { 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) 120 { 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: 128 { 129 ::std::auto_ptr< awt::Size > pRefSize; 130 if( pRefSizeProvider.get() ) 131 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize())); 132 133 pItemConverter = new wrapper::TitleItemConverter( xObjectProperties, 134 rDrawModel.GetItemPool(), rDrawModel, 135 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ), 136 pRefSize ); 137 } 138 break; 139 case OBJECTTYPE_LEGEND: 140 { 141 ::std::auto_ptr< awt::Size > pRefSize; 142 if( pRefSizeProvider.get() ) 143 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize())); 144 145 pItemConverter = new wrapper::LegendItemConverter( xObjectProperties, 146 rDrawModel.GetItemPool(), rDrawModel, 147 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ), 148 pRefSize ); 149 } 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: 163 { 164 ::std::auto_ptr< awt::Size > pRefSize; 165 if( pRefSizeProvider.get() ) 166 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize())); 167 168 uno::Reference< beans::XPropertySet > xDiaProp; 169 xDiaProp.set( ChartModelHelper::findDiagram( xChartModel ), uno::UNO_QUERY ); 170 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) 174 175 ExplicitScaleData aExplicitScale; 176 ExplicitIncrementData aExplicitIncrement; 177 if( pExplicitValueProvider ) 178 pExplicitValueProvider->getExplicitValuesForAxis( 179 uno::Reference< XAxis >( xObjectProperties, uno::UNO_QUERY ), 180 aExplicitScale, aExplicitIncrement ); 181 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 ); 188 } 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: 196 { 197 ::std::auto_ptr< awt::Size > pRefSize; 198 if( pRefSizeProvider.get() ) 199 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize())); 200 201 wrapper::GraphicPropertyItemConverter::eGraphicObjectType eMapTo = 202 wrapper::GraphicPropertyItemConverter::FILLED_DATA_POINT; 203 204 uno::Reference< XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel ); 205 uno::Reference< XChartType > xChartType = ChartModelHelper::getChartTypeOfSeries( xChartModel, xSeries ); 206 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; 211 /* 212 FILLED_DATA_POINT, 213 LINE_DATA_POINT, 214 LINE_PROPERTIES, 215 FILL_PROPERTIES, 216 LINE_AND_FILL_PROPERTIES 217 */ 218 bool bDataSeries = ( eObjectType == OBJECTTYPE_DATA_SERIES || eObjectType == OBJECTTYPE_DATA_LABELS ); 219 220 //special color for pie chart: 221 bool bUseSpecialFillColor = false; 222 sal_Int32 nSpecialFillColor =0; 223 sal_Int32 nPointIndex = -1; /*-1 for whole series*/ 224 if(!bDataSeries) 225 { 226 nPointIndex = aParticleID.toInt32(); 227 uno::Reference< beans::XPropertySet > xSeriesProp( xSeries, uno::UNO_QUERY ); 228 bool bVaryColorsByPoint = false; 229 if( xSeriesProp.is() && 230 (xSeriesProp->getPropertyValue(C2U("VaryColorsByPoint")) >>= bVaryColorsByPoint) && 231 bVaryColorsByPoint ) 232 { 233 if( !ColorPerPointHelper::hasPointOwnColor( xSeriesProp, nPointIndex, xObjectProperties ) ) 234 { 235 bUseSpecialFillColor = true; 236 OSL_ASSERT( xDiagram.is()); 237 uno::Reference< XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme() ); 238 if( xColorScheme.is()) 239 nSpecialFillColor = xColorScheme->getColorByIndex( nPointIndex ); 240 } 241 } 242 } 243 sal_Int32 nNumberFormat=ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel( xObjectProperties, xSeries, nPointIndex, xDiagram ); 244 sal_Int32 nPercentNumberFormat=ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabel( 245 xObjectProperties,uno::Reference< util::XNumberFormatsSupplier >(xChartModel, uno::UNO_QUERY)); 246 247 pItemConverter = new wrapper::DataPointItemConverter( xChartModel, xContext, 248 xObjectProperties, xSeries, rDrawModel.GetItemPool(), rDrawModel, 249 pNumberFormatterWrapper, 250 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ), 251 eMapTo, pRefSize, bDataSeries, bUseSpecialFillColor, nSpecialFillColor, false, 252 nNumberFormat, nPercentNumberFormat ); 253 break; 254 } 255 case OBJECTTYPE_GRID: 256 case OBJECTTYPE_SUBGRID: 257 case OBJECTTYPE_DATA_AVERAGE_LINE: 258 pItemConverter = new wrapper::GraphicPropertyItemConverter( 259 xObjectProperties, rDrawModel.GetItemPool(), 260 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ), 261 wrapper::GraphicPropertyItemConverter::LINE_PROPERTIES ); 262 break; 263 264 case OBJECTTYPE_DATA_ERRORS: 265 pItemConverter = new wrapper::ErrorBarItemConverter( 266 xChartModel, xObjectProperties, rDrawModel.GetItemPool(), 267 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY )); 268 break; 269 270 case OBJECTTYPE_DATA_CURVE: 271 pItemConverter = new wrapper::RegressionCurveItemConverter( 272 xObjectProperties, uno::Reference< chart2::XRegressionCurveContainer >( 273 ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel ), uno::UNO_QUERY ), 274 rDrawModel.GetItemPool(), rDrawModel, 275 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY )); 276 break; 277 case OBJECTTYPE_DATA_CURVE_EQUATION: 278 { 279 ::std::auto_ptr< awt::Size > pRefSize; 280 if( pRefSizeProvider.get() ) 281 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize())); 282 283 pItemConverter = new wrapper::RegressionEquationItemConverter( 284 xObjectProperties, rDrawModel.GetItemPool(), rDrawModel, 285 uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ), 286 pRefSize ); 287 break; 288 } 289 case OBJECTTYPE_DATA_ERRORS_X: 290 break; 291 case OBJECTTYPE_DATA_ERRORS_Y: 292 break; 293 case OBJECTTYPE_DATA_ERRORS_Z: 294 break; 295 case OBJECTTYPE_DATA_STOCK_RANGE: 296 break; 297 case OBJECTTYPE_DATA_STOCK_LOSS: 298 case OBJECTTYPE_DATA_STOCK_GAIN: 299 pItemConverter = new wrapper::GraphicPropertyItemConverter( 300 xObjectProperties, rDrawModel.GetItemPool(), 301 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ), 302 wrapper::GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES ); 303 break; 304 default: //OBJECTTYPE_UNKNOWN 305 break; 306 } 307 } 308 else 309 { 310 //create itemconverter for a all objects of given type 311 switch(eObjectType) 312 { 313 case OBJECTTYPE_TITLE: 314 pItemConverter = new wrapper::AllTitleItemConverter( xChartModel, rDrawModel.GetItemPool(), 315 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY )); 316 break; 317 case OBJECTTYPE_AXIS: 318 { 319 ::std::auto_ptr< awt::Size > pRefSize; 320 if( pRefSizeProvider.get() ) 321 pRefSize.reset( new awt::Size( pRefSizeProvider->getPageSize())); 322 323 pItemConverter = new wrapper::AllAxisItemConverter( xChartModel, rDrawModel.GetItemPool(), 324 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ), pRefSize ); 325 } 326 break; 327 case OBJECTTYPE_GRID: 328 case OBJECTTYPE_SUBGRID: 329 pItemConverter = new wrapper::AllGridItemConverter( xChartModel, rDrawModel.GetItemPool(), 330 rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY )); 331 break; 332 default: //for this type it is not supported to change all elements at once 333 break; 334 } 335 336 } 337 return pItemConverter; 338 } 339 340 rtl::OUString lcl_getTitleCIDForCommand( const ::rtl::OString& rDispatchCommand, const uno::Reference< frame::XModel > & xChartModel ) 341 { 342 if( rDispatchCommand.equals("AllTitles")) 343 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_TITLE, C2U("ALLELEMENTS") ); 344 345 TitleHelper::eTitleType nTitleType( TitleHelper::MAIN_TITLE ); 346 if( rDispatchCommand.equals("SubTitle") ) 347 nTitleType = TitleHelper::SUB_TITLE; 348 else if( rDispatchCommand.equals("XTitle") ) 349 nTitleType = TitleHelper::X_AXIS_TITLE; 350 else if( rDispatchCommand.equals("YTitle") ) 351 nTitleType = TitleHelper::Y_AXIS_TITLE; 352 else if( rDispatchCommand.equals("ZTitle") ) 353 nTitleType = TitleHelper::Z_AXIS_TITLE; 354 else if( rDispatchCommand.equals("SecondaryXTitle") ) 355 nTitleType = TitleHelper::SECONDARY_X_AXIS_TITLE; 356 else if( rDispatchCommand.equals("SecondaryYTitle") ) 357 nTitleType = TitleHelper::SECONDARY_Y_AXIS_TITLE; 358 359 uno::Reference< XTitle > xTitle( TitleHelper::getTitle( nTitleType, xChartModel ) ); 360 return ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, xChartModel ); 361 } 362 363 rtl::OUString lcl_getAxisCIDForCommand( const ::rtl::OString& rDispatchCommand, const uno::Reference< frame::XModel >& xChartModel ) 364 { 365 if( rDispatchCommand.equals("DiagramAxisAll")) 366 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_AXIS, C2U("ALLELEMENTS") ); 367 368 sal_Int32 nDimensionIndex=0; 369 bool bMainAxis=true; 370 if( rDispatchCommand.equals("DiagramAxisX")) 371 { 372 nDimensionIndex=0; bMainAxis=true; 373 } 374 else if( rDispatchCommand.equals("DiagramAxisY")) 375 { 376 nDimensionIndex=1; bMainAxis=true; 377 } 378 else if( rDispatchCommand.equals("DiagramAxisZ")) 379 { 380 nDimensionIndex=2; bMainAxis=true; 381 } 382 else if( rDispatchCommand.equals("DiagramAxisA")) 383 { 384 nDimensionIndex=0; bMainAxis=false; 385 } 386 else if( rDispatchCommand.equals("DiagramAxisB")) 387 { 388 nDimensionIndex=1; bMainAxis=false; 389 } 390 391 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) ); 392 uno::Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) ); 393 return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, xChartModel ); 394 } 395 396 rtl::OUString lcl_getGridCIDForCommand( const ::rtl::OString& rDispatchCommand, const uno::Reference< frame::XModel >& xChartModel ) 397 { 398 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) ); 399 400 if( rDispatchCommand.equals("DiagramGridAll")) 401 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_GRID, C2U("ALLELEMENTS") ); 402 403 sal_Int32 nDimensionIndex=0; 404 bool bMainGrid=true; 405 406 //x and y is swapped in the commands 407 408 if( rDispatchCommand.equals("DiagramGridYMain")) 409 { 410 nDimensionIndex=0; bMainGrid=true; 411 } 412 else if( rDispatchCommand.equals("DiagramGridXMain")) 413 { 414 nDimensionIndex=1; bMainGrid=true; 415 } 416 else if( rDispatchCommand.equals("DiagramGridZMain")) 417 { 418 nDimensionIndex=2; bMainGrid=true; 419 } 420 else if( rDispatchCommand.equals("DiagramGridYHelp")) 421 { 422 nDimensionIndex=0; bMainGrid=false; 423 } 424 else if( rDispatchCommand.equals("DiagramGridXHelp")) 425 { 426 nDimensionIndex=1; bMainGrid=false; 427 } 428 else if( rDispatchCommand.equals("DiagramGridZHelp")) 429 { 430 nDimensionIndex=2; bMainGrid=false; 431 } 432 433 bool bMainAxis = true; 434 uno::Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) ); 435 436 sal_Int32 nSubGridIndex= bMainGrid ? (-1) : 0; 437 rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel, nSubGridIndex ) ); 438 return aCID; 439 } 440 rtl::OUString lcl_getObjectCIDForCommand( const ::rtl::OString& rDispatchCommand, const uno::Reference< XChartDocument > & xChartDocument, const rtl::OUString& rSelectedCID ) 441 { 442 ObjectType eObjectType = OBJECTTYPE_UNKNOWN; 443 rtl::OUString aParticleID; 444 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 ); 449 450 //------------------------------------------------------------------------- 451 //legend 452 if( rDispatchCommand.equals("Legend") || rDispatchCommand.equals("FormatLegend") ) 453 { 454 eObjectType = OBJECTTYPE_LEGEND; 455 //@todo set particular aParticleID if we have more than one legend 456 } 457 //------------------------------------------------------------------------- 458 //wall floor area 459 else if( rDispatchCommand.equals("DiagramWall") || rDispatchCommand.equals("FormatWall") ) 460 { 461 //OBJECTTYPE_DIAGRAM; 462 eObjectType = OBJECTTYPE_DIAGRAM_WALL; 463 //@todo set particular aParticleID if we have more than one diagram 464 } 465 else if( rDispatchCommand.equals("DiagramFloor") || rDispatchCommand.equals("FormatFloor") ) 466 { 467 eObjectType = OBJECTTYPE_DIAGRAM_FLOOR; 468 //@todo set particular aParticleID if we have more than one diagram 469 } 470 else if( rDispatchCommand.equals("DiagramArea") || rDispatchCommand.equals("FormatChartArea") ) 471 { 472 eObjectType = OBJECTTYPE_PAGE; 473 } 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") 484 ) 485 { 486 return lcl_getTitleCIDForCommand( rDispatchCommand, xChartModel ); 487 } 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") 496 ) 497 { 498 return lcl_getAxisCIDForCommand( rDispatchCommand, xChartModel ); 499 } 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") 509 ) 510 { 511 return lcl_getGridCIDForCommand( rDispatchCommand, xChartModel ); 512 } 513 //------------------------------------------------------------------------- 514 //data series 515 else if( rDispatchCommand.equals("FormatDataSeries") ) 516 { 517 if( eSelectedType == OBJECTTYPE_DATA_SERIES ) 518 return rSelectedCID; 519 else 520 return ObjectIdentifier::createClassifiedIdentifier( 521 OBJECTTYPE_DATA_SERIES, ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ) ); 522 } 523 //------------------------------------------------------------------------- 524 //data point 525 else if( rDispatchCommand.equals("FormatDataPoint") ) 526 { 527 return rSelectedCID; 528 } 529 //------------------------------------------------------------------------- 530 //data labels 531 else if( rDispatchCommand.equals("FormatDataLabels") ) 532 { 533 if( eSelectedType == OBJECTTYPE_DATA_LABELS ) 534 return rSelectedCID; 535 else 536 return ObjectIdentifier::createClassifiedIdentifierWithParent( 537 OBJECTTYPE_DATA_LABELS, ::rtl::OUString(), rSelectedCID ); 538 } 539 //------------------------------------------------------------------------- 540 //data labels 541 else if( rDispatchCommand.equals("FormatDataLabel") ) 542 { 543 if( eSelectedType == OBJECTTYPE_DATA_LABEL ) 544 return rSelectedCID; 545 else 546 { 547 sal_Int32 nPointIndex = ObjectIdentifier::getParticleID( rSelectedCID ).toInt32(); 548 if( nPointIndex>=0 ) 549 { 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 ); 556 557 return ObjectIdentifier::createPointCID( aLabelCID_Stub, nPointIndex ); 558 } 559 } 560 } 561 //------------------------------------------------------------------------- 562 //mean value line 563 else if( rDispatchCommand.equals("FormatMeanValue") ) 564 { 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 ); 572 } 573 //------------------------------------------------------------------------- 574 //trend line 575 else if( rDispatchCommand.equals("FormatTrendline") ) 576 { 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 ); 584 } 585 //------------------------------------------------------------------------- 586 //trend line equation 587 else if( rDispatchCommand.equals("FormatTrendlineEquation") ) 588 { 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 ) ) ); 596 } 597 //------------------------------------------------------------------------- 598 // y error bars 599 else if( rDispatchCommand.equals("FormatYErrorBars") ) 600 { 601 if( eSelectedType == OBJECTTYPE_DATA_ERRORS ) 602 return rSelectedCID; 603 else 604 return ObjectIdentifier::createClassifiedIdentifierWithParent( 605 OBJECTTYPE_DATA_ERRORS, ::rtl::OUString(), rSelectedCID ); 606 } 607 //------------------------------------------------------------------------- 608 // axis 609 else if( rDispatchCommand.equals("FormatAxis") ) 610 { 611 if( eSelectedType == OBJECTTYPE_AXIS ) 612 return rSelectedCID; 613 else 614 { 615 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartModel ); 616 return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis , xChartModel ); 617 } 618 } 619 //------------------------------------------------------------------------- 620 // major grid 621 else if( rDispatchCommand.equals("FormatMajorGrid") ) 622 { 623 if( eSelectedType == OBJECTTYPE_GRID ) 624 return rSelectedCID; 625 else 626 { 627 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartModel ); 628 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel ); 629 } 630 631 } 632 //------------------------------------------------------------------------- 633 // minor grid 634 else if( rDispatchCommand.equals("FormatMinorGrid") ) 635 { 636 if( eSelectedType == OBJECTTYPE_SUBGRID ) 637 return rSelectedCID; 638 else 639 { 640 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartModel ); 641 return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel, 0 /*sub grid index*/ ); 642 } 643 } 644 //------------------------------------------------------------------------- 645 // title 646 else if( rDispatchCommand.equals("FormatTitle") ) 647 { 648 if( eSelectedType == OBJECTTYPE_TITLE ) 649 return rSelectedCID; 650 } 651 //------------------------------------------------------------------------- 652 // stock loss 653 else if( rDispatchCommand.equals("FormatStockLoss") ) 654 { 655 if( eSelectedType == OBJECTTYPE_DATA_STOCK_LOSS ) 656 return rSelectedCID; 657 else 658 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_LOSS, rtl::OUString()); 659 } 660 //------------------------------------------------------------------------- 661 // stock gain 662 else if( rDispatchCommand.equals("FormatStockGain") ) 663 { 664 if( eSelectedType == OBJECTTYPE_DATA_STOCK_GAIN ) 665 return rSelectedCID; 666 else 667 return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_GAIN, rtl::OUString() ); 668 } 669 670 return ObjectIdentifier::createClassifiedIdentifier( 671 eObjectType, aParticleID ); 672 } 673 674 } 675 // anonymous namespace 676 677 void SAL_CALL ChartController::executeDispatch_FormatObject(const ::rtl::OUString& rDispatchCommand) 678 { 679 uno::Reference< XChartDocument > xChartDocument( getModel(), uno::UNO_QUERY ); 680 rtl::OString aCommand( rtl::OUStringToOString( rDispatchCommand, RTL_TEXTENCODING_ASCII_US ) ); 681 rtl::OUString rObjectCID = lcl_getObjectCIDForCommand( aCommand, xChartDocument, m_aSelection.getSelectedCID() ); 682 executeDlg_ObjectProperties( rObjectCID ); 683 } 684 685 void SAL_CALL ChartController::executeDispatch_ObjectProperties() 686 { 687 executeDlg_ObjectProperties( m_aSelection.getSelectedCID() ); 688 } 689 690 namespace 691 { 692 693 rtl::OUString lcl_getFormatCIDforSelectedCID( const ::rtl::OUString& rSelectedCID ) 694 { 695 ::rtl::OUString aFormatCID(rSelectedCID); 696 697 //get type of selected object 698 ObjectType eObjectType = ObjectIdentifier::getObjectType( aFormatCID ); 699 700 // some legend entries are handled as if they were data series 701 if( OBJECTTYPE_LEGEND_ENTRY==eObjectType ) 702 { 703 rtl::OUString aParentParticle( ObjectIdentifier::getFullParentParticle( rSelectedCID ) ); 704 aFormatCID = ObjectIdentifier::createClassifiedIdentifierForParticle( aParentParticle ); 705 } 706 707 // treat diagram as wall 708 if( OBJECTTYPE_DIAGRAM==eObjectType ) 709 aFormatCID = ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, rtl::OUString() ); 710 711 return aFormatCID; 712 } 713 714 }//end anonymous namespace 715 716 void SAL_CALL ChartController::executeDlg_ObjectProperties( const ::rtl::OUString& rSelectedObjectCID ) 717 { 718 rtl::OUString aObjectCID = lcl_getFormatCIDforSelectedCID( rSelectedObjectCID ); 719 720 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( 721 ActionDescriptionProvider::FORMAT, 722 ObjectNameProvider::getName( ObjectIdentifier::getObjectType( aObjectCID ))), 723 m_xUndoManager ); 724 725 bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, false ); 726 if( bSuccess ) 727 aUndoGuard.commit(); 728 } 729 730 bool ChartController::executeDlg_ObjectProperties_withoutUndoGuard( const ::rtl::OUString& rObjectCID, bool bOkClickOnUnchangedDialogSouldBeRatedAsSuccessAlso ) 731 { 732 //return true if the properties were changed successfully 733 bool bRet = false; 734 if( !rObjectCID.getLength() ) 735 { 736 //DBG_ERROR("empty ObjectID"); 737 return bRet; 738 } 739 try 740 { 741 NumberFormatterWrapper aNumberFormatterWrapper( uno::Reference< util::XNumberFormatsSupplier >(getModel(), uno::UNO_QUERY) ); 742 743 //------------------------------------------------------------- 744 //get type of object 745 ObjectType eObjectType = ObjectIdentifier::getObjectType( rObjectCID ); 746 if( OBJECTTYPE_UNKNOWN==eObjectType ) 747 { 748 //DBG_ERROR("unknown ObjectType"); 749 return bRet; 750 } 751 if( OBJECTTYPE_DIAGRAM_WALL==eObjectType || OBJECTTYPE_DIAGRAM_FLOOR==eObjectType ) 752 { 753 if( !DiagramHelper::isSupportingFloorAndWall( ChartModelHelper::findDiagram( getModel() ) ) ) 754 return bRet; 755 } 756 757 //------------------------------------------------------------- 758 //convert properties to ItemSet 759 760 awt::Size aPageSize( ChartModelHelper::getPageSize(getModel()) ); 761 762 ::std::auto_ptr< ReferenceSizeProvider > pRefSizeProv( 763 impl_createReferenceSizeProvider()); 764 ::std::auto_ptr< ::comphelper::ItemConverter > apItemConverter( 765 createItemConverter( rObjectCID, getModel(), m_xCC, 766 m_pDrawModelWrapper->getSdrModel(), 767 &aNumberFormatterWrapper, 768 ExplicitValueProvider::getExplicitValueProvider(m_xChartView), 769 pRefSizeProv )); 770 if(!apItemConverter.get()) 771 return bRet; 772 773 SfxItemSet aItemSet = apItemConverter->CreateEmptyItemSet(); 774 apItemConverter->FillItemSet( aItemSet ); 775 776 //------------------------------------------------------------- 777 //prepare dialog 778 ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter( rObjectCID ); 779 aDialogParameter.init( getModel() ); 780 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get() ); 781 782 ::vos::OGuard aGuard( Application::GetSolarMutex()); 783 SchAttribTabDlg aDlg( m_pChartWindow, &aItemSet, &aDialogParameter, &aViewElementListProvider 784 , uno::Reference< util::XNumberFormatsSupplier >( getModel(), uno::UNO_QUERY ) ); 785 786 if(aDialogParameter.HasSymbolProperties()) 787 { 788 SfxItemSet* pSymbolShapeProperties=NULL; 789 uno::Reference< beans::XPropertySet > xObjectProperties = 790 ObjectIdentifier::getObjectPropertySet( rObjectCID, getModel() ); 791 wrapper::DataPointItemConverter aSymbolItemConverter( getModel(), m_xCC 792 , xObjectProperties, ObjectIdentifier::getDataSeriesForCID( rObjectCID, getModel() ) 793 , m_pDrawModelWrapper->getSdrModel().GetItemPool() 794 , m_pDrawModelWrapper->getSdrModel() 795 , &aNumberFormatterWrapper 796 , uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ) 797 , wrapper::GraphicPropertyItemConverter::FILLED_DATA_POINT ); 798 799 pSymbolShapeProperties = new SfxItemSet( aSymbolItemConverter.CreateEmptyItemSet() ); 800 aSymbolItemConverter.FillItemSet( *pSymbolShapeProperties ); 801 802 sal_Int32 nStandardSymbol=0;//@todo get from somewhere 803 Graphic* pAutoSymbolGraphic = new Graphic( aViewElementListProvider.GetSymbolGraphic( nStandardSymbol, pSymbolShapeProperties ) ); 804 // note: the dialog takes the ownership of pSymbolShapeProperties and pAutoSymbolGraphic 805 aDlg.setSymbolInformation( pSymbolShapeProperties, pAutoSymbolGraphic ); 806 } 807 if( aDialogParameter.HasStatisticProperties() ) 808 { 809 aDlg.SetAxisMinorStepWidthForErrorBarDecimals( 810 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), m_xChartView, rObjectCID ) ); 811 } 812 813 //------------------------------------------------------------- 814 //open the dialog 815 if( aDlg.Execute() == RET_OK || (bOkClickOnUnchangedDialogSouldBeRatedAsSuccessAlso && aDlg.DialogWasClosedWithOK()) ) 816 { 817 const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet(); 818 if(pOutItemSet) 819 { 820 ControllerLockGuard aCLGuard( getModel()); 821 apItemConverter->ApplyItemSet( *pOutItemSet );//model should be changed now 822 bRet = true; 823 } 824 } 825 } 826 catch( util::CloseVetoException& ) 827 { 828 } 829 catch( uno::RuntimeException& ) 830 { 831 } 832 return bRet; 833 } 834 835 void SAL_CALL ChartController::executeDispatch_View3D() 836 { 837 try 838 { 839 // using assignment for broken gcc 3.3 840 UndoLiveUpdateGuard aUndoGuard = UndoLiveUpdateGuard( 841 String( SchResId( STR_ACTION_EDIT_3D_VIEW )), 842 m_xUndoManager ); 843 844 // /-- 845 //open dialog 846 ::vos::OGuard aSolarGuard( Application::GetSolarMutex()); 847 View3DDialog aDlg( m_pChartWindow, getModel(), m_pDrawModelWrapper->GetColorTable() ); 848 if( aDlg.Execute() == RET_OK ) 849 aUndoGuard.commit(); 850 // \-- 851 } 852 catch( uno::RuntimeException& e) 853 { 854 ASSERT_EXCEPTION( e ); 855 } 856 } 857 858 //............................................................................. 859 } //namespace chart 860 //............................................................................. 861