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 31 #include "ChartController.hxx" 32 #include "ChartWindow.hxx" 33 #include "ChartModelHelper.hxx" 34 #include "TitleHelper.hxx" 35 #include "ThreeDHelper.hxx" 36 #include "DataSeriesHelper.hxx" 37 #include "UndoGuard.hxx" 38 #include "ControllerLockGuard.hxx" 39 #include "macros.hxx" 40 #include "ResId.hxx" 41 #include "Strings.hrc" 42 #include "ObjectIdentifier.hxx" 43 #include "ReferenceSizeProvider.hxx" 44 #include "chartview/ExplicitValueProvider.hxx" 45 #include "chartview/DrawModelWrapper.hxx" 46 #include "ChartTransferable.hxx" 47 #include "DrawViewWrapper.hxx" 48 #include "LegendHelper.hxx" 49 #include "AxisHelper.hxx" 50 #include "RegressionCurveHelper.hxx" 51 #include "ShapeController.hxx" 52 #include "DiagramHelper.hxx" 53 #include "ObjectNameProvider.hxx" 54 55 #include <com/sun/star/chart2/DataPointLabel.hpp> 56 #include <com/sun/star/beans/XPropertyState.hpp> 57 #include <com/sun/star/drawing/CameraGeometry.hpp> 58 #include <com/sun/star/graphic/XGraphic.hpp> 59 #include <com/sun/star/io/XInputStream.hpp> 60 #include <com/sun/star/text/XTextRange.hpp> 61 #include <com/sun/star/drawing/TextVerticalAdjust.hpp> 62 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp> 63 #include <com/sun/star/chart/ErrorBarStyle.hpp> 64 65 #include <svx/ActionDescriptionProvider.hxx> 66 // for TransferableDataHelper/TransferableHelper 67 #include <svtools/transfer.hxx> 68 // for SotStorageStreamRef 69 #include <sot/storage.hxx> 70 // for Graphic 71 #include <vcl/graph.hxx> 72 // for SvxDrawingLayerImport/SvxUnoDrawingModel 73 #include <svx/unomodel.hxx> 74 // for SdrModel 75 #include <svx/svdmodel.hxx> 76 // for OInputStreamWrapper 77 #include <unotools/streamwrap.hxx> 78 // for SolarMutex 79 #include <vcl/svapp.hxx> 80 #include <vos/mutex.hxx> 81 #include <svx/dialmgr.hxx> 82 #include <svx/dialogs.hrc> 83 // for OutlinerView 84 #include <editeng/outliner.hxx> 85 #include <svx/svditer.hxx> 86 #include <svx/svdpage.hxx> 87 #include <svx/svdundo.hxx> 88 #include <svx/unoapi.hxx> 89 #include <svx/unopage.hxx> 90 91 #include <boost/scoped_ptr.hpp> 92 93 using namespace ::com::sun::star; 94 95 using ::com::sun::star::uno::Reference; 96 using ::com::sun::star::uno::Sequence; 97 using ::rtl::OUString; 98 99 namespace 100 { 101 102 bool lcl_deleteDataSeries( 103 const OUString & rCID, 104 const Reference< frame::XModel > & xModel, 105 const Reference< document::XUndoManager > & xUndoManager ) 106 { 107 bool bResult = false; 108 uno::Reference< chart2::XDataSeries > xSeries( ::chart::ObjectIdentifier::getDataSeriesForCID( rCID, xModel )); 109 uno::Reference< chart2::XChartDocument > xChartDoc( xModel, uno::UNO_QUERY ); 110 if( xSeries.is() && xChartDoc.is()) 111 { 112 uno::Reference< chart2::XChartType > xChartType( 113 ::chart::DataSeriesHelper::getChartTypeOfSeries( xSeries, xChartDoc->getFirstDiagram())); 114 if( xChartType.is()) 115 { 116 ::chart::UndoGuard aUndoGuard( 117 ActionDescriptionProvider::createDescription( 118 ActionDescriptionProvider::DELETE, String( ::chart::SchResId( STR_OBJECT_DATASERIES ))), 119 xUndoManager ); 120 121 Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( xModel ) ); 122 uno::Reference< chart2::XAxis > xAxis( ::chart::DiagramHelper::getAttachedAxis( xSeries, xDiagram ) ); 123 124 ::chart::DataSeriesHelper::deleteSeries( xSeries, xChartType ); 125 126 ::chart::AxisHelper::hideAxisIfNoDataIsAttached( xAxis, xDiagram ); 127 128 bResult = true; 129 aUndoGuard.commit(); 130 } 131 } 132 return bResult; 133 } 134 135 bool lcl_deleteDataCurve( 136 const OUString & rCID, 137 const Reference< frame::XModel > & xModel, 138 const Reference< document::XUndoManager > & xUndoManager ) 139 { 140 bool bResult = false; 141 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( 142 ::chart::ObjectIdentifier::getObjectPropertySet( 143 ::chart::ObjectIdentifier::getSeriesParticleFromCID( rCID ), xModel ), uno::UNO_QUERY ); 144 if( xRegCurveCnt.is()) 145 { 146 ::chart::UndoGuard aUndoGuard( 147 ActionDescriptionProvider::createDescription( 148 ActionDescriptionProvider::DELETE, String( ::chart::SchResId( STR_OBJECT_CURVE ))), 149 xUndoManager ); 150 ::chart::RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt ); 151 bResult = true; 152 aUndoGuard.commit(); 153 } 154 return bResult; 155 } 156 157 // void lcl_CopyPageContentToPage( 158 // const Reference< drawing::XDrawPage > & xSourcePage, 159 // const Reference< drawing::XDrawPage > & xDestPage ) 160 // { 161 // try 162 // { 163 // Reference< container::XIndexAccess > xSourceIA( xSourcePage, uno::UNO_QUERY_THROW ); 164 // sal_Int32 nCount( xSourceIA->getCount()); 165 // for( sal_Int32 i=0; i<nCount; ++i ) 166 // { 167 // Reference< drawing::XShape > xShape; 168 // if( xSourceIA->getByIndex( i ) >>= xShape ) 169 // xDestPage->add( xShape ); 170 // } 171 // } 172 // catch( const uno::Exception & ex ) 173 // { 174 // ASSERT_EXCEPTION( ex ); 175 // } 176 // } 177 178 // // copies all shapes on all pages of xSource to the only page of xDestination 179 // void lcl_CopyShapesToChart( 180 // const Reference< frame::XModel > & xSource, const Reference< frame::XModel > & xDestination ) 181 // { 182 // try 183 // { 184 // Reference< drawing::XDrawPageSupplier > xDestPGSupp( xDestination, uno::UNO_QUERY_THROW ); 185 // Reference< drawing::XDrawPage > xDestPage( xDestPGSupp->getDrawPage()); 186 // Reference< drawing::XDrawPagesSupplier > xSourcePGsSupp( xSource, uno::UNO_QUERY_THROW ); 187 // Reference< drawing::XDrawPages > xSourcePages( xSourcePGsSupp->getDrawPages()); 188 189 // sal_Int32 nCount( xSourcePages->getCount()); 190 // for( sal_Int32 i=0; i<nCount; ++i ) 191 // { 192 // Reference< drawing::XDrawPage > xSourcePage( xSourcePages->getByIndex( i ), uno::UNO_QUERY_THROW ); 193 // lcl_CopyPageContentToPage( xSourcePage, xDestPage ); 194 // } 195 // } 196 // catch( const uno::Exception & ex ) 197 // { 198 // ASSERT_EXCEPTION( ex ); 199 // } 200 // } 201 202 } // anonymous namespace 203 204 205 namespace chart 206 { 207 208 ::std::auto_ptr< ReferenceSizeProvider > ChartController::impl_createReferenceSizeProvider() 209 { 210 awt::Size aPageSize( ChartModelHelper::getPageSize( getModel() ) ); 211 212 return ::std::auto_ptr< ReferenceSizeProvider >( 213 new ReferenceSizeProvider( aPageSize, 214 Reference< chart2::XChartDocument >( getModel(), uno::UNO_QUERY ))); 215 } 216 217 void ChartController::impl_adaptDataSeriesAutoResize() 218 { 219 ::std::auto_ptr< ReferenceSizeProvider > apRefSizeProvider( 220 impl_createReferenceSizeProvider()); 221 if( apRefSizeProvider.get()) 222 apRefSizeProvider->setValuesAtAllDataSeries(); 223 } 224 225 void ChartController::executeDispatch_NewArrangement() 226 { 227 // remove manual positions at titles, legend and the diagram, remove manual 228 // size at the diagram 229 230 try 231 { 232 Reference< frame::XModel > xModel( getModel() ); 233 Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( xModel )); 234 if( xDiagram.is()) 235 { 236 // using assignment for broken gcc 3.3 237 UndoGuard aUndoGuard = UndoGuard( 238 String( SchResId( STR_ACTION_REARRANGE_CHART )), 239 m_xUndoManager ); 240 ControllerLockGuard aCtlLockGuard( xModel ); 241 242 // diagram 243 Reference< beans::XPropertyState > xState( xDiagram, uno::UNO_QUERY_THROW ); 244 xState->setPropertyToDefault( C2U("RelativeSize")); 245 xState->setPropertyToDefault( C2U("RelativePosition")); 246 xState->setPropertyToDefault( C2U("PosSizeExcludeAxes")); 247 248 // 3d rotation 249 ThreeDHelper::set3DSettingsToDefault( uno::Reference< beans::XPropertySet >( xDiagram, uno::UNO_QUERY ) ); 250 251 // legend 252 Reference< beans::XPropertyState > xLegendState( xDiagram->getLegend(), uno::UNO_QUERY ); 253 if( xLegendState.is()) 254 { 255 xLegendState->setPropertyToDefault( C2U("RelativePosition")); 256 xLegendState->setPropertyToDefault( C2U("RelativeSize")); 257 xLegendState->setPropertyToDefault( C2U("AnchorPosition")); 258 } 259 260 // titles 261 for( sal_Int32 eType = TitleHelper::TITLE_BEGIN; 262 eType < TitleHelper::NORMAL_TITLE_END; 263 ++eType ) 264 { 265 Reference< beans::XPropertyState > xTitleState( 266 TitleHelper::getTitle( 267 static_cast< TitleHelper::eTitleType >( eType ), xModel ), uno::UNO_QUERY ); 268 if( xTitleState.is()) 269 xTitleState->setPropertyToDefault( C2U("RelativePosition")); 270 } 271 272 // regression curve equations 273 ::std::vector< Reference< chart2::XRegressionCurve > > aRegressionCurves( 274 RegressionCurveHelper::getAllRegressionCurvesNotMeanValueLine( xDiagram )); 275 ::std::for_each( aRegressionCurves.begin(), aRegressionCurves.end(), 276 RegressionCurveHelper::resetEquationPosition ); 277 278 aUndoGuard.commit(); 279 } 280 } 281 catch( uno::RuntimeException & ex ) 282 { 283 ASSERT_EXCEPTION( ex ); 284 } 285 } 286 287 void ChartController::executeDispatch_ScaleText() 288 { 289 ::vos::OGuard aSolarGuard( Application::GetSolarMutex()); 290 // using assignment for broken gcc 3.3 291 UndoGuard aUndoGuard = UndoGuard( 292 String( SchResId( STR_ACTION_SCALE_TEXT )), 293 m_xUndoManager ); 294 ControllerLockGuard aCtlLockGuard( getModel() ); 295 ::std::auto_ptr< ReferenceSizeProvider > apRefSizeProv( impl_createReferenceSizeProvider()); 296 OSL_ASSERT( apRefSizeProv.get()); 297 if( apRefSizeProv.get()) 298 apRefSizeProv->toggleAutoResizeState(); 299 aUndoGuard.commit(); 300 } 301 302 void ChartController::executeDispatch_Paste() 303 { 304 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 305 if( m_pChartWindow ) 306 { 307 Graphic aGraphic; 308 // paste location: center of window 309 Point aPos; 310 aPos = m_pChartWindow->PixelToLogic( Rectangle( aPos, m_pChartWindow->GetSizePixel()).Center()); 311 312 // handle different formats 313 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( m_pChartWindow )); 314 if( aDataHelper.GetTransferable().is()) 315 { 316 if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) ) 317 { 318 SotStorageStreamRef xStm; 319 if ( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xStm ) ) 320 { 321 xStm->Seek( 0 ); 322 Reference< io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ) ); 323 ::boost::scoped_ptr< SdrModel > spModel( new SdrModel() ); 324 if ( SvxDrawingLayerImport( spModel.get(), xInputStream ) ) 325 { 326 impl_PasteShapes( spModel.get() ); 327 } 328 } 329 } 330 else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ) ) 331 { 332 // graphic exchange format (graphic manager bitmap format?) 333 SotStorageStreamRef xStm; 334 if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_SVXB, xStm )) 335 (*xStm) >> aGraphic; 336 } 337 else if( aDataHelper.HasFormat( FORMAT_GDIMETAFILE )) 338 { 339 // meta file 340 GDIMetaFile aMetafile; 341 if( aDataHelper.GetGDIMetaFile( FORMAT_GDIMETAFILE, aMetafile )) 342 aGraphic = Graphic( aMetafile ); 343 } 344 else if( aDataHelper.HasFormat( FORMAT_BITMAP )) 345 { 346 // bitmap (non-graphic-manager) 347 Bitmap aBmp; 348 if( aDataHelper.GetBitmap( FORMAT_BITMAP, aBmp )) 349 aGraphic = Graphic( aBmp ); 350 } 351 else if( aDataHelper.HasFormat( FORMAT_STRING )) 352 { 353 OUString aString; 354 if( aDataHelper.GetString( FORMAT_STRING, aString ) && m_pDrawModelWrapper ) 355 { 356 if( m_pDrawViewWrapper ) 357 { 358 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView(); 359 if( pOutlinerView )//in case of edit mode insert into edited string 360 pOutlinerView->InsertText( aString ); 361 else 362 { 363 impl_PasteStringAsTextShape( aString, awt::Point( 0, 0 ) ); 364 } 365 } 366 } 367 } 368 } 369 370 if( aGraphic.GetType() != GRAPHIC_NONE ) 371 { 372 Reference< graphic::XGraphic > xGraphic( aGraphic.GetXGraphic()); 373 if( xGraphic.is()) 374 impl_PasteGraphic( xGraphic, aPos ); 375 } 376 } 377 } 378 379 // note: aPosition is ignored for now. The object is always pasted centered to 380 // the page 381 void ChartController::impl_PasteGraphic( 382 uno::Reference< graphic::XGraphic > & xGraphic, 383 const ::Point & /* aPosition */ ) 384 { 385 // note: the XPropertySet of the model is the old API. Also the property 386 // "AdditionalShapes" that is used there. 387 uno::Reference< beans::XPropertySet > xModelProp( getModel(), uno::UNO_QUERY ); 388 DrawModelWrapper * pDrawModelWrapper( this->GetDrawModelWrapper()); 389 if( ! (xGraphic.is() && xModelProp.is())) 390 return; 391 uno::Reference< lang::XMultiServiceFactory > xFact( pDrawModelWrapper->getShapeFactory()); 392 uno::Reference< drawing::XShape > xGraphicShape( 393 xFact->createInstance( C2U( "com.sun.star.drawing.GraphicObjectShape" )), uno::UNO_QUERY ); 394 uno::Reference< beans::XPropertySet > xGraphicShapeProp( xGraphicShape, uno::UNO_QUERY ); 395 if( xGraphicShapeProp.is() && xGraphicShape.is()) 396 { 397 uno::Reference< drawing::XShapes > xPage( pDrawModelWrapper->getMainDrawPage(), uno::UNO_QUERY ); 398 if( xPage.is()) 399 { 400 xPage->add( xGraphicShape ); 401 //need to change the model state manually 402 { 403 uno::Reference< util::XModifiable > xModifiable( getModel(), uno::UNO_QUERY ); 404 if( xModifiable.is() ) 405 xModifiable->setModified( true ); 406 } 407 //select new shape 408 m_aSelection.setSelection( xGraphicShape ); 409 m_aSelection.applySelection( m_pDrawViewWrapper ); 410 } 411 xGraphicShapeProp->setPropertyValue( C2U("Graphic"), uno::makeAny( xGraphic )); 412 uno::Reference< beans::XPropertySet > xGraphicProp( xGraphic, uno::UNO_QUERY ); 413 414 awt::Size aGraphicSize( 1000, 1000 ); 415 // first try size in 100th mm, then pixel size 416 if( ! ( xGraphicProp->getPropertyValue( C2U("Size100thMM")) >>= aGraphicSize ) && 417 ( ( xGraphicProp->getPropertyValue( C2U("SizePixel")) >>= aGraphicSize ) && m_pChartWindow )) 418 { 419 ::Size aVCLSize( m_pChartWindow->PixelToLogic( Size( aGraphicSize.Width, aGraphicSize.Height ))); 420 aGraphicSize.Width = aVCLSize.getWidth(); 421 aGraphicSize.Height = aVCLSize.getHeight(); 422 } 423 xGraphicShape->setSize( aGraphicSize ); 424 xGraphicShape->setPosition( awt::Point( 0, 0 ) ); 425 } 426 } 427 428 void ChartController::impl_PasteShapes( SdrModel* pModel ) 429 { 430 DrawModelWrapper* pDrawModelWrapper( this->GetDrawModelWrapper() ); 431 if ( pDrawModelWrapper && m_pDrawViewWrapper ) 432 { 433 Reference< drawing::XDrawPage > xDestPage( pDrawModelWrapper->getMainDrawPage() ); 434 SdrPage* pDestPage = GetSdrPageFromXDrawPage( xDestPage ); 435 if ( pDestPage ) 436 { 437 Reference< drawing::XShape > xSelShape; 438 m_pDrawViewWrapper->BegUndo( SVX_RESSTR( RID_SVX_3D_UNDO_EXCHANGE_PASTE ) ); 439 sal_uInt16 nCount = pModel->GetPageCount(); 440 for ( sal_uInt16 i = 0; i < nCount; ++i ) 441 { 442 const SdrPage* pPage = pModel->GetPage( i ); 443 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS ); 444 while ( aIter.IsMore() ) 445 { 446 SdrObject* pObj = aIter.Next(); 447 SdrObject* pNewObj = ( pObj ? pObj->Clone() : NULL ); 448 if ( pNewObj ) 449 { 450 pNewObj->SetModel( &pDrawModelWrapper->getSdrModel() ); 451 pNewObj->SetPage( pDestPage ); 452 453 // set position 454 Reference< drawing::XShape > xShape( pNewObj->getUnoShape(), uno::UNO_QUERY ); 455 if ( xShape.is() ) 456 { 457 xShape->setPosition( awt::Point( 0, 0 ) ); 458 } 459 460 pDestPage->InsertObject( pNewObj ); 461 m_pDrawViewWrapper->AddUndo( new SdrUndoInsertObj( *pNewObj ) ); 462 xSelShape = xShape; 463 } 464 } 465 } 466 467 Reference< util::XModifiable > xModifiable( getModel(), uno::UNO_QUERY ); 468 if ( xModifiable.is() ) 469 { 470 xModifiable->setModified( true ); 471 } 472 473 // select last inserted shape 474 m_aSelection.setSelection( xSelShape ); 475 m_aSelection.applySelection( m_pDrawViewWrapper ); 476 477 m_pDrawViewWrapper->EndUndo(); 478 479 impl_switchDiagramPositioningToExcludingPositioning(); 480 } 481 } 482 } 483 484 void ChartController::impl_PasteStringAsTextShape( const OUString& rString, const awt::Point& rPosition ) 485 { 486 DrawModelWrapper* pDrawModelWrapper( this->GetDrawModelWrapper() ); 487 if ( pDrawModelWrapper && m_pDrawViewWrapper ) 488 { 489 const Reference< lang::XMultiServiceFactory >& xShapeFactory( pDrawModelWrapper->getShapeFactory() ); 490 const Reference< drawing::XDrawPage >& xDrawPage( pDrawModelWrapper->getMainDrawPage() ); 491 OSL_ASSERT( xShapeFactory.is() && xDrawPage.is() ); 492 493 if ( xShapeFactory.is() && xDrawPage.is() ) 494 { 495 try 496 { 497 Reference< drawing::XShape > xTextShape( 498 xShapeFactory->createInstance( C2U( "com.sun.star.drawing.TextShape" ) ), uno::UNO_QUERY_THROW ); 499 xDrawPage->add( xTextShape ); 500 501 Reference< text::XTextRange > xRange( xTextShape, uno::UNO_QUERY_THROW ); 502 xRange->setString( rString ); 503 504 float fCharHeight = 10.0; 505 Reference< beans::XPropertySet > xProperties( xTextShape, uno::UNO_QUERY_THROW ); 506 xProperties->setPropertyValue( C2U( "TextAutoGrowHeight" ), uno::makeAny( true ) ); 507 xProperties->setPropertyValue( C2U( "TextAutoGrowWidth" ), uno::makeAny( true ) ); 508 xProperties->setPropertyValue( C2U( "CharHeight" ), uno::makeAny( fCharHeight ) ); 509 xProperties->setPropertyValue( C2U( "CharHeightAsian" ), uno::makeAny( fCharHeight ) ); 510 xProperties->setPropertyValue( C2U( "CharHeightComplex" ), uno::makeAny( fCharHeight ) ); 511 xProperties->setPropertyValue( C2U( "TextVerticalAdjust" ), uno::makeAny( drawing::TextVerticalAdjust_CENTER ) ); 512 xProperties->setPropertyValue( C2U( "TextHorizontalAdjust" ), uno::makeAny( drawing::TextHorizontalAdjust_CENTER ) ); 513 xProperties->setPropertyValue( C2U( "CharFontName" ), uno::makeAny( C2U( "Albany" ) ) ); 514 515 xTextShape->setPosition( rPosition ); 516 517 m_aSelection.setSelection( xTextShape ); 518 m_aSelection.applySelection( m_pDrawViewWrapper ); 519 520 SdrObject* pObj = DrawViewWrapper::getSdrObject( xTextShape ); 521 if ( pObj ) 522 { 523 m_pDrawViewWrapper->BegUndo( SVX_RESSTR( RID_SVX_3D_UNDO_EXCHANGE_PASTE ) ); 524 m_pDrawViewWrapper->AddUndo( new SdrUndoInsertObj( *pObj ) ); 525 m_pDrawViewWrapper->EndUndo(); 526 527 impl_switchDiagramPositioningToExcludingPositioning(); 528 } 529 } 530 catch ( const uno::Exception& ex ) 531 { 532 ASSERT_EXCEPTION( ex ); 533 } 534 } 535 } 536 } 537 538 void ChartController::executeDispatch_Copy() 539 { 540 if ( m_pDrawViewWrapper ) 541 { 542 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView(); 543 if ( pOutlinerView ) 544 { 545 pOutlinerView->Copy(); 546 } 547 else 548 { 549 Reference< datatransfer::XTransferable > xTransferable; 550 { 551 ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 552 SdrObject* pSelectedObj = 0; 553 if ( m_pDrawModelWrapper ) 554 { 555 ObjectIdentifier aSelOID( m_aSelection.getSelectedOID() ); 556 if ( aSelOID.isAutoGeneratedObject() ) 557 { 558 pSelectedObj = m_pDrawModelWrapper->getNamedSdrObject( aSelOID.getObjectCID() ); 559 } 560 else if ( aSelOID.isAdditionalShape() ) 561 { 562 pSelectedObj = DrawViewWrapper::getSdrObject( aSelOID.getAdditionalShape() ); 563 } 564 if ( pSelectedObj ) 565 { 566 xTransferable = Reference< datatransfer::XTransferable >( new ChartTransferable( 567 &m_pDrawModelWrapper->getSdrModel(), pSelectedObj, aSelOID.isAdditionalShape() ) ); 568 } 569 } 570 } 571 if ( xTransferable.is() ) 572 { 573 Reference< datatransfer::clipboard::XClipboard > xClipboard( TransferableHelper::GetSystemClipboard() ); 574 if ( xClipboard.is() ) 575 { 576 xClipboard->setContents( xTransferable, Reference< datatransfer::clipboard::XClipboardOwner >() ); 577 } 578 } 579 } 580 } 581 } 582 583 void ChartController::executeDispatch_Cut() 584 { 585 executeDispatch_Copy(); 586 executeDispatch_Delete(); 587 } 588 589 bool ChartController::isObjectDeleteable( const uno::Any& rSelection ) 590 { 591 ObjectIdentifier aSelOID( rSelection ); 592 if ( aSelOID.isAutoGeneratedObject() ) 593 { 594 OUString aSelObjCID( aSelOID.getObjectCID() ); 595 ObjectType aObjectType(ObjectIdentifier::getObjectType( aSelObjCID )); 596 if( (OBJECTTYPE_TITLE == aObjectType) || (OBJECTTYPE_LEGEND == aObjectType) ) 597 return true; 598 if( (OBJECTTYPE_DATA_SERIES == aObjectType) || (OBJECTTYPE_LEGEND_ENTRY == aObjectType) ) 599 return true; 600 if( (OBJECTTYPE_DATA_CURVE_EQUATION == aObjectType) || (OBJECTTYPE_DATA_CURVE == aObjectType) || 601 (OBJECTTYPE_DATA_AVERAGE_LINE == aObjectType) || (OBJECTTYPE_DATA_ERRORS == aObjectType)) 602 return true; 603 if( (OBJECTTYPE_DATA_LABELS == aObjectType) || (OBJECTTYPE_DATA_LABEL == aObjectType) ) 604 return true; 605 if( (OBJECTTYPE_AXIS == aObjectType) || (OBJECTTYPE_GRID == aObjectType) || (OBJECTTYPE_SUBGRID == aObjectType) ) 606 return true; 607 } 608 else if ( aSelOID.isAdditionalShape() ) 609 { 610 return true; 611 } 612 613 return false; 614 } 615 616 bool ChartController::isShapeContext() const 617 { 618 if ( m_aSelection.isAdditionalShapeSelected() || 619 ( m_pDrawViewWrapper && m_pDrawViewWrapper->AreObjectsMarked() && 620 ( m_pDrawViewWrapper->GetCurrentObjIdentifier() == OBJ_TEXT ) ) ) 621 { 622 return true; 623 } 624 625 return false; 626 } 627 628 void ChartController::impl_ClearSelection() 629 { 630 if( m_aSelection.hasSelection()) 631 { 632 m_aSelection.clearSelection(); 633 impl_notifySelectionChangeListeners(); 634 } 635 } 636 637 bool ChartController::executeDispatch_Delete() 638 { 639 bool bReturn = false; 640 641 // remove the selected object 642 // 643 rtl::OUString aCID( m_aSelection.getSelectedCID() ); 644 if( aCID.getLength() ) 645 { 646 if( !isObjectDeleteable( uno::Any( aCID ) ) ) 647 return false; 648 649 //remove chart object 650 uno::Reference< chart2::XChartDocument > xChartDoc( getModel(), uno::UNO_QUERY ); 651 if( !xChartDoc.is() ) 652 return false; 653 654 ObjectType aObjectType( ObjectIdentifier::getObjectType( aCID )); 655 switch( aObjectType ) 656 { 657 case OBJECTTYPE_TITLE: 658 { 659 // using assignment for broken gcc 3.3 660 UndoGuard aUndoGuard = UndoGuard( 661 ActionDescriptionProvider::createDescription( 662 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_TITLE ))), 663 m_xUndoManager ); 664 TitleHelper::removeTitle( 665 ObjectIdentifier::getTitleTypeForCID( aCID ), getModel() ); 666 bReturn = true; 667 aUndoGuard.commit(); 668 break; 669 } 670 case OBJECTTYPE_LEGEND: 671 { 672 uno::Reference< chart2::XDiagram > xDiagram( xChartDoc->getFirstDiagram()); 673 if( xDiagram.is()) 674 { 675 uno::Reference< beans::XPropertySet > xLegendProp( xDiagram->getLegend(), uno::UNO_QUERY ); 676 if( xLegendProp.is()) 677 { 678 // using assignment for broken gcc 3.3 679 UndoGuard aUndoGuard = UndoGuard( 680 ActionDescriptionProvider::createDescription( 681 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_LEGEND ))), 682 m_xUndoManager ); 683 xLegendProp->setPropertyValue( C2U("Show"), uno::makeAny( false )); 684 bReturn = true; 685 aUndoGuard.commit(); 686 } 687 } 688 break; 689 } 690 691 case OBJECTTYPE_DATA_SERIES: 692 bReturn = lcl_deleteDataSeries( aCID, getModel(), m_xUndoManager ); 693 break; 694 695 case OBJECTTYPE_LEGEND_ENTRY: 696 { 697 ObjectType eParentObjectType = ObjectIdentifier::getObjectType( 698 ObjectIdentifier::getFullParentParticle( aCID )); 699 if( eParentObjectType == OBJECTTYPE_DATA_SERIES ) 700 bReturn = lcl_deleteDataSeries( aCID, getModel(), m_xUndoManager ); 701 else if( eParentObjectType == OBJECTTYPE_DATA_CURVE ) 702 bReturn = lcl_deleteDataCurve( aCID, getModel(), m_xUndoManager ); 703 else if( eParentObjectType == OBJECTTYPE_DATA_AVERAGE_LINE ) 704 { 705 executeDispatch_DeleteMeanValue(); 706 bReturn = true; 707 } 708 break; 709 } 710 711 case OBJECTTYPE_DATA_AVERAGE_LINE: 712 { 713 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( 714 ObjectIdentifier::getObjectPropertySet( 715 ObjectIdentifier::getFullParentParticle( aCID ), getModel()), uno::UNO_QUERY ); 716 if( xRegCurveCnt.is()) 717 { 718 // using assignment for broken gcc 3.3 719 UndoGuard aUndoGuard = UndoGuard( 720 ActionDescriptionProvider::createDescription( 721 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_AVERAGE_LINE ))), 722 m_xUndoManager ); 723 RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt ); 724 bReturn = true; 725 aUndoGuard.commit(); 726 } 727 break; 728 } 729 730 case OBJECTTYPE_DATA_CURVE: 731 bReturn = lcl_deleteDataCurve( aCID, getModel(), m_xUndoManager ); 732 break; 733 734 case OBJECTTYPE_DATA_CURVE_EQUATION: 735 { 736 uno::Reference< beans::XPropertySet > xEqProp( 737 ObjectIdentifier::getObjectPropertySet( aCID, getModel())); 738 if( xEqProp.is()) 739 { 740 uno::Reference< frame::XModel > xModel( getModel() ); 741 // using assignment for broken gcc 3.3 742 UndoGuard aUndoGuard = UndoGuard( 743 ActionDescriptionProvider::createDescription( 744 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE_EQUATION ))), 745 m_xUndoManager ); 746 { 747 ControllerLockGuard aCtlLockGuard( xModel ); 748 xEqProp->setPropertyValue( C2U("ShowEquation"), uno::makeAny( false )); 749 xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( false )); 750 } 751 bReturn = true; 752 aUndoGuard.commit(); 753 } 754 break; 755 } 756 757 case OBJECTTYPE_DATA_ERRORS: 758 { 759 uno::Reference< beans::XPropertySet > xErrorBarProp( 760 ObjectIdentifier::getObjectPropertySet( aCID, getModel() )); 761 if( xErrorBarProp.is()) 762 { 763 uno::Reference< frame::XModel > xModel( getModel() ); 764 // using assignment for broken gcc 3.3 765 UndoGuard aUndoGuard = UndoGuard( 766 ActionDescriptionProvider::createDescription( 767 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_ERROR_BARS ))), 768 m_xUndoManager ); 769 { 770 ControllerLockGuard aCtlLockGuard( xModel ); 771 xErrorBarProp->setPropertyValue( 772 C2U("ErrorBarStyle"), 773 uno::makeAny( ::com::sun::star::chart::ErrorBarStyle::NONE )); 774 } 775 bReturn = true; 776 aUndoGuard.commit(); 777 } 778 break; 779 } 780 781 case OBJECTTYPE_DATA_LABELS: 782 case OBJECTTYPE_DATA_LABEL: 783 { 784 uno::Reference< beans::XPropertySet > xObjectProperties = 785 ObjectIdentifier::getObjectPropertySet( aCID, getModel() ); 786 if( xObjectProperties.is() ) 787 { 788 UndoGuard aUndoGuard = UndoGuard( 789 ActionDescriptionProvider::createDescription( 790 ActionDescriptionProvider::DELETE, ::rtl::OUString( String( 791 SchResId( aObjectType == OBJECTTYPE_DATA_LABEL ? STR_OBJECT_LABEL : STR_OBJECT_DATALABELS )))), 792 m_xUndoManager ); 793 chart2::DataPointLabel aLabel; 794 xObjectProperties->getPropertyValue( C2U( "Label" ) ) >>= aLabel; 795 aLabel.ShowNumber = false; 796 aLabel.ShowNumberInPercent = false; 797 aLabel.ShowCategoryName = false; 798 aLabel.ShowLegendSymbol = false; 799 if( aObjectType == OBJECTTYPE_DATA_LABELS ) 800 { 801 uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( aCID, getModel() )); 802 ::chart::DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "Label" ), uno::makeAny(aLabel) ); 803 } 804 else 805 xObjectProperties->setPropertyValue( C2U( "Label" ), uno::makeAny(aLabel) ); 806 bReturn = true; 807 aUndoGuard.commit(); 808 } 809 break; 810 } 811 case OBJECTTYPE_AXIS: 812 { 813 executeDispatch_DeleteAxis(); 814 bReturn = true; 815 break; 816 } 817 case OBJECTTYPE_GRID: 818 { 819 executeDispatch_DeleteMajorGrid(); 820 bReturn = true; 821 break; 822 } 823 case OBJECTTYPE_SUBGRID: 824 { 825 executeDispatch_DeleteMinorGrid(); 826 bReturn = true; 827 break; 828 } 829 830 default: 831 { 832 break; 833 } 834 } 835 } 836 else 837 { 838 //remove additional shape 839 impl_ClearSelection(); 840 { 841 ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 842 if ( m_pDrawViewWrapper ) 843 { 844 m_pDrawViewWrapper->DeleteMarked(); 845 bReturn = true; 846 } 847 } 848 } 849 return bReturn; 850 } 851 852 void ChartController::executeDispatch_ToggleLegend() 853 { 854 Reference< frame::XModel > xModel( getModel() ); 855 UndoGuard aUndoGuard = UndoGuard( 856 String( SchResId( STR_ACTION_TOGGLE_LEGEND )), m_xUndoManager ); 857 Reference< beans::XPropertySet > xLegendProp( LegendHelper::getLegend( xModel ), uno::UNO_QUERY ); 858 bool bChanged = false; 859 if( xLegendProp.is()) 860 { 861 try 862 { 863 bool bShow = false; 864 if( xLegendProp->getPropertyValue( C2U("Show")) >>= bShow ) 865 { 866 xLegendProp->setPropertyValue( C2U("Show"), uno::makeAny( ! bShow )); 867 bChanged = true; 868 } 869 } 870 catch( const uno::Exception & ex ) 871 { 872 ASSERT_EXCEPTION( ex ); 873 } 874 } 875 else 876 { 877 xLegendProp.set( LegendHelper::getLegend( xModel, m_xCC, true ), uno::UNO_QUERY ); 878 if( xLegendProp.is()) 879 bChanged = true; 880 } 881 882 if( bChanged ) 883 aUndoGuard.commit(); 884 } 885 886 void ChartController::executeDispatch_ToggleGridHorizontal() 887 { 888 Reference< frame::XModel > xModel( getModel() ); 889 UndoGuard aUndoGuard = UndoGuard( 890 String( SchResId( STR_ACTION_TOGGLE_GRID_HORZ )), m_xUndoManager ); 891 Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( getModel() )); 892 if( xDiagram.is()) 893 { 894 sal_Int32 nDimensionIndex = 1; 895 sal_Int32 nCooSysIndex = 0; 896 bool bIsMainGrid = true; 897 898 bool bHasMainYGrid = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, bIsMainGrid, xDiagram ); 899 900 if( bHasMainYGrid ) 901 AxisHelper::hideGrid( nDimensionIndex, nCooSysIndex, bIsMainGrid, xDiagram ); 902 else 903 AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, bIsMainGrid, xDiagram, m_xCC ); 904 905 aUndoGuard.commit(); 906 } 907 } 908 909 void ChartController::impl_ShapeControllerDispatch( const util::URL& rURL, const Sequence< beans::PropertyValue >& rArgs ) 910 { 911 Reference< frame::XDispatch > xDispatch( m_aDispatchContainer.getShapeController() ); 912 if ( xDispatch.is() ) 913 { 914 xDispatch->dispatch( rURL, rArgs ); 915 } 916 } 917 918 void ChartController::impl_switchDiagramPositioningToExcludingPositioning() 919 { 920 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( 921 ActionDescriptionProvider::POS_SIZE, 922 ObjectNameProvider::getName( OBJECTTYPE_DIAGRAM)), 923 m_xUndoManager ); 924 if( DiagramHelper::switchDiagramPositioningToExcludingPositioning( m_aModel->getModel(), true, true ) ) 925 aUndoGuard.commit(); 926 } 927 928 } // namespace chart 929