1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
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"
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"
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>
65 #include <svx/ActionDescriptionProvider.hxx>
66 // for TransferableDataHelper/TransferableHelper
67 #include <svtools/transfer.hxx>
68 // for SotStorageStreamRef
69 #include <sot/storage.hxx>
71 #include <vcl/graph.hxx>
72 // for SvxDrawingLayerImport/SvxUnoDrawingModel
73 #include <svx/unomodel.hxx>
75 #include <svx/svdmodel.hxx>
76 // for OInputStreamWrapper
77 #include <unotools/streamwrap.hxx>
79 #include <vcl/svapp.hxx>
80 #include <vos/mutex.hxx>
81 #include <svx/dialmgr.hxx>
82 #include <svx/dialogs.hrc>
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>
91 #include <boost/scoped_ptr.hpp>
93 using namespace ::com::sun::star
;
95 using ::com::sun::star::uno::Reference
;
96 using ::com::sun::star::uno::Sequence
;
97 using ::rtl::OUString
;
102 bool lcl_deleteDataSeries(
103 const OUString
& rCID
,
104 const Reference
< frame::XModel
> & xModel
,
105 const Reference
< chart2::XUndoManager
> & xUndoManager
)
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())
112 uno::Reference
< chart2::XChartType
> xChartType(
113 ::chart::DataSeriesHelper::getChartTypeOfSeries( xSeries
, xChartDoc
->getFirstDiagram()));
116 ::chart::UndoGuard
aUndoGuard(
117 ActionDescriptionProvider::createDescription(
118 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String( ::chart::SchResId( STR_OBJECT_DATASERIES
)))),
119 xUndoManager
, xModel
);
121 Reference
< chart2::XDiagram
> xDiagram( ::chart::ChartModelHelper::findDiagram( xModel
) );
122 uno::Reference
< chart2::XAxis
> xAxis( ::chart::DiagramHelper::getAttachedAxis( xSeries
, xDiagram
) );
124 ::chart::DataSeriesHelper::deleteSeries( xSeries
, xChartType
);
126 ::chart::AxisHelper::hideAxisIfNoDataIsAttached( xAxis
, xDiagram
);
129 aUndoGuard
.commitAction();
135 bool lcl_deleteDataCurve(
136 const OUString
& rCID
,
137 const Reference
< frame::XModel
> & xModel
,
138 const Reference
< chart2::XUndoManager
> & xUndoManager
)
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())
146 ::chart::UndoGuard
aUndoGuard(
147 ActionDescriptionProvider::createDescription(
148 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String( ::chart::SchResId( STR_OBJECT_CURVE
)))),
149 xUndoManager
, xModel
);
150 ::chart::RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt
);
152 aUndoGuard
.commitAction();
157 // void lcl_CopyPageContentToPage(
158 // const Reference< drawing::XDrawPage > & xSourcePage,
159 // const Reference< drawing::XDrawPage > & xDestPage )
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 )
167 // Reference< drawing::XShape > xShape;
168 // if( xSourceIA->getByIndex( i ) >>= xShape )
169 // xDestPage->add( xShape );
172 // catch( const uno::Exception & ex )
174 // ASSERT_EXCEPTION( ex );
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 )
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());
189 // sal_Int32 nCount( xSourcePages->getCount());
190 // for( sal_Int32 i=0; i<nCount; ++i )
192 // Reference< drawing::XDrawPage > xSourcePage( xSourcePages->getByIndex( i ), uno::UNO_QUERY_THROW );
193 // lcl_CopyPageContentToPage( xSourcePage, xDestPage );
196 // catch( const uno::Exception & ex )
198 // ASSERT_EXCEPTION( ex );
202 } // anonymous namespace
208 ::std::auto_ptr
< ReferenceSizeProvider
> ChartController::impl_createReferenceSizeProvider()
210 awt::Size
aPageSize( ChartModelHelper::getPageSize( getModel() ) );
212 return ::std::auto_ptr
< ReferenceSizeProvider
>(
213 new ReferenceSizeProvider( aPageSize
,
214 Reference
< chart2::XChartDocument
>( getModel(), uno::UNO_QUERY
)));
217 void ChartController::impl_adaptDataSeriesAutoResize()
219 ::std::auto_ptr
< ReferenceSizeProvider
> apRefSizeProvider(
220 impl_createReferenceSizeProvider());
221 if( apRefSizeProvider
.get())
222 apRefSizeProvider
->setValuesAtAllDataSeries();
225 void ChartController::executeDispatch_NewArrangement()
227 // remove manual positions at titles, legend and the diagram, remove manual
228 // size at the diagram
232 Reference
< frame::XModel
> xModel( getModel() );
233 Reference
< chart2::XDiagram
> xDiagram( ChartModelHelper::findDiagram( xModel
));
236 // using assignment for broken gcc 3.3
237 UndoGuard aUndoGuard
= UndoGuard(
238 ::rtl::OUString( String( SchResId( STR_ACTION_REARRANGE_CHART
))),
239 m_xUndoManager
, xModel
);
240 ControllerLockGuard
aCtlLockGuard( xModel
);
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"));
249 ThreeDHelper::set3DSettingsToDefault( uno::Reference
< beans::XPropertySet
>( xDiagram
, uno::UNO_QUERY
) );
252 Reference
< beans::XPropertyState
> xLegendState( xDiagram
->getLegend(), uno::UNO_QUERY
);
253 if( xLegendState
.is())
254 xLegendState
->setPropertyToDefault( C2U("RelativePosition"));
257 for( sal_Int32 eType
= TitleHelper::TITLE_BEGIN
;
258 eType
< TitleHelper::NORMAL_TITLE_END
;
261 Reference
< beans::XPropertyState
> xTitleState(
262 TitleHelper::getTitle(
263 static_cast< TitleHelper::eTitleType
>( eType
), xModel
), uno::UNO_QUERY
);
264 if( xTitleState
.is())
265 xTitleState
->setPropertyToDefault( C2U("RelativePosition"));
268 // regression curve equations
269 ::std::vector
< Reference
< chart2::XRegressionCurve
> > aRegressionCurves(
270 RegressionCurveHelper::getAllRegressionCurvesNotMeanValueLine( xDiagram
));
271 ::std::for_each( aRegressionCurves
.begin(), aRegressionCurves
.end(),
272 RegressionCurveHelper::resetEquationPosition
);
274 aUndoGuard
.commitAction();
277 catch( uno::RuntimeException
& ex
)
279 ASSERT_EXCEPTION( ex
);
283 void ChartController::executeDispatch_ScaleText()
285 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex());
286 // using assignment for broken gcc 3.3
287 UndoGuard aUndoGuard
= UndoGuard(
288 ::rtl::OUString( String( SchResId( STR_ACTION_SCALE_TEXT
))),
289 m_xUndoManager
, getModel() );
290 ControllerLockGuard
aCtlLockGuard( getModel() );
291 ::std::auto_ptr
< ReferenceSizeProvider
> apRefSizeProv( impl_createReferenceSizeProvider());
292 OSL_ASSERT( apRefSizeProv
.get());
293 if( apRefSizeProv
.get())
294 apRefSizeProv
->toggleAutoResizeState();
295 aUndoGuard
.commitAction();
298 void ChartController::executeDispatch_Paste()
303 // paste location: center of window
305 aPos
= m_pChartWindow
->PixelToLogic( Rectangle( aPos
, m_pChartWindow
->GetSizePixel()).Center());
307 // handle different formats
308 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( m_pChartWindow
));
309 if( aDataHelper
.GetTransferable().is())
311 if ( aDataHelper
.HasFormat( SOT_FORMATSTR_ID_DRAWING
) )
313 SotStorageStreamRef xStm
;
314 if ( aDataHelper
.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING
, xStm
) )
317 Reference
< io::XInputStream
> xInputStream( new utl::OInputStreamWrapper( *xStm
) );
318 ::boost::scoped_ptr
< SdrModel
> spModel( new SdrModel() );
319 if ( SvxDrawingLayerImport( spModel
.get(), xInputStream
) )
321 impl_PasteShapes( spModel
.get() );
325 else if ( aDataHelper
.HasFormat( SOT_FORMATSTR_ID_SVXB
) )
327 // graphic exchange format (graphic manager bitmap format?)
328 SotStorageStreamRef xStm
;
329 if( aDataHelper
.GetSotStorageStream( SOT_FORMATSTR_ID_SVXB
, xStm
))
332 else if( aDataHelper
.HasFormat( FORMAT_GDIMETAFILE
))
335 GDIMetaFile aMetafile
;
336 if( aDataHelper
.GetGDIMetaFile( FORMAT_GDIMETAFILE
, aMetafile
))
337 aGraphic
= Graphic( aMetafile
);
339 else if( aDataHelper
.HasFormat( FORMAT_BITMAP
))
341 // bitmap (non-graphic-manager)
343 if( aDataHelper
.GetBitmap( FORMAT_BITMAP
, aBmp
))
344 aGraphic
= Graphic( aBmp
);
346 else if( aDataHelper
.HasFormat( FORMAT_STRING
))
349 if( aDataHelper
.GetString( FORMAT_STRING
, aString
) && m_pDrawModelWrapper
)
351 if( m_pDrawViewWrapper
)
353 OutlinerView
* pOutlinerView
= m_pDrawViewWrapper
->GetTextEditOutlinerView();
354 if( pOutlinerView
)//in case of edit mode insert into edited string
355 pOutlinerView
->InsertText( aString
);
358 impl_PasteStringAsTextShape( aString
, awt::Point( 0, 0 ) );
365 if( aGraphic
.GetType() != GRAPHIC_NONE
)
367 Reference
< graphic::XGraphic
> xGraphic( aGraphic
.GetXGraphic());
369 impl_PasteGraphic( xGraphic
, aPos
);
374 // note: aPosition is ignored for now. The object is always pasted centered to
376 void ChartController::impl_PasteGraphic(
377 uno::Reference
< graphic::XGraphic
> & xGraphic
,
378 const ::Point
& /* aPosition */ )
380 // note: the XPropertySet of the model is the old API. Also the property
381 // "AdditionalShapes" that is used there.
382 uno::Reference
< beans::XPropertySet
> xModelProp( getModel(), uno::UNO_QUERY
);
383 DrawModelWrapper
* pDrawModelWrapper( this->GetDrawModelWrapper());
384 if( ! (xGraphic
.is() && xModelProp
.is()))
386 uno::Reference
< lang::XMultiServiceFactory
> xFact( pDrawModelWrapper
->getShapeFactory());
387 uno::Reference
< drawing::XShape
> xGraphicShape(
388 xFact
->createInstance( C2U( "com.sun.star.drawing.GraphicObjectShape" )), uno::UNO_QUERY
);
389 uno::Reference
< beans::XPropertySet
> xGraphicShapeProp( xGraphicShape
, uno::UNO_QUERY
);
390 if( xGraphicShapeProp
.is() && xGraphicShape
.is())
392 uno::Reference
< drawing::XShapes
> xPage( pDrawModelWrapper
->getMainDrawPage(), uno::UNO_QUERY
);
395 xPage
->add( xGraphicShape
);
396 //need to change the model state manually
398 uno::Reference
< util::XModifiable
> xModifiable( getModel(), uno::UNO_QUERY
);
399 if( xModifiable
.is() )
400 xModifiable
->setModified( true );
403 m_aSelection
.setSelection( xGraphicShape
);
404 m_aSelection
.applySelection( m_pDrawViewWrapper
);
406 xGraphicShapeProp
->setPropertyValue( C2U("Graphic"), uno::makeAny( xGraphic
));
407 uno::Reference
< beans::XPropertySet
> xGraphicProp( xGraphic
, uno::UNO_QUERY
);
409 awt::Size
aGraphicSize( 1000, 1000 );
410 // first try size in 100th mm, then pixel size
411 if( ! ( xGraphicProp
->getPropertyValue( C2U("Size100thMM")) >>= aGraphicSize
) &&
412 ( ( xGraphicProp
->getPropertyValue( C2U("SizePixel")) >>= aGraphicSize
) && m_pChartWindow
))
414 ::Size
aVCLSize( m_pChartWindow
->PixelToLogic( Size( aGraphicSize
.Width
, aGraphicSize
.Height
)));
415 aGraphicSize
.Width
= aVCLSize
.getWidth();
416 aGraphicSize
.Height
= aVCLSize
.getHeight();
418 xGraphicShape
->setSize( aGraphicSize
);
419 xGraphicShape
->setPosition( awt::Point( 0, 0 ) );
423 void ChartController::impl_PasteShapes( SdrModel
* pModel
)
425 DrawModelWrapper
* pDrawModelWrapper( this->GetDrawModelWrapper() );
426 if ( pDrawModelWrapper
&& m_pDrawViewWrapper
)
428 Reference
< drawing::XDrawPage
> xDestPage( pDrawModelWrapper
->getMainDrawPage() );
429 SdrPage
* pDestPage
= GetSdrPageFromXDrawPage( xDestPage
);
432 Reference
< drawing::XShape
> xSelShape
;
433 m_pDrawViewWrapper
->BegUndo( SVX_RESSTR( RID_SVX_3D_UNDO_EXCHANGE_PASTE
) );
434 sal_uInt16 nCount
= pModel
->GetPageCount();
435 for ( sal_uInt16 i
= 0; i
< nCount
; ++i
)
437 const SdrPage
* pPage
= pModel
->GetPage( i
);
438 SdrObjListIter
aIter( *pPage
, IM_DEEPNOGROUPS
);
439 while ( aIter
.IsMore() )
441 SdrObject
* pObj
= aIter
.Next();
442 SdrObject
* pNewObj
= ( pObj
? pObj
->Clone() : NULL
);
445 pNewObj
->SetModel( &pDrawModelWrapper
->getSdrModel() );
446 pNewObj
->SetPage( pDestPage
);
449 Reference
< drawing::XShape
> xShape( pNewObj
->getUnoShape(), uno::UNO_QUERY
);
452 xShape
->setPosition( awt::Point( 0, 0 ) );
455 pDestPage
->InsertObject( pNewObj
);
456 m_pDrawViewWrapper
->AddUndo( new SdrUndoInsertObj( *pNewObj
) );
462 Reference
< util::XModifiable
> xModifiable( getModel(), uno::UNO_QUERY
);
463 if ( xModifiable
.is() )
465 xModifiable
->setModified( true );
468 // select last inserted shape
469 m_aSelection
.setSelection( xSelShape
);
470 m_aSelection
.applySelection( m_pDrawViewWrapper
);
472 m_pDrawViewWrapper
->EndUndo();
474 impl_switchDiagramPositioningToExcludingPositioning();
479 void ChartController::impl_PasteStringAsTextShape( const OUString
& rString
, const awt::Point
& rPosition
)
481 DrawModelWrapper
* pDrawModelWrapper( this->GetDrawModelWrapper() );
482 if ( pDrawModelWrapper
&& m_pDrawViewWrapper
)
484 const Reference
< lang::XMultiServiceFactory
>& xShapeFactory( pDrawModelWrapper
->getShapeFactory() );
485 const Reference
< drawing::XDrawPage
>& xDrawPage( pDrawModelWrapper
->getMainDrawPage() );
486 OSL_ASSERT( xShapeFactory
.is() && xDrawPage
.is() );
488 if ( xShapeFactory
.is() && xDrawPage
.is() )
492 Reference
< drawing::XShape
> xTextShape(
493 xShapeFactory
->createInstance( C2U( "com.sun.star.drawing.TextShape" ) ), uno::UNO_QUERY_THROW
);
494 xDrawPage
->add( xTextShape
);
496 Reference
< text::XTextRange
> xRange( xTextShape
, uno::UNO_QUERY_THROW
);
497 xRange
->setString( rString
);
499 float fCharHeight
= 10.0;
500 Reference
< beans::XPropertySet
> xProperties( xTextShape
, uno::UNO_QUERY_THROW
);
501 xProperties
->setPropertyValue( C2U( "TextAutoGrowHeight" ), uno::makeAny( true ) );
502 xProperties
->setPropertyValue( C2U( "TextAutoGrowWidth" ), uno::makeAny( true ) );
503 xProperties
->setPropertyValue( C2U( "CharHeight" ), uno::makeAny( fCharHeight
) );
504 xProperties
->setPropertyValue( C2U( "CharHeightAsian" ), uno::makeAny( fCharHeight
) );
505 xProperties
->setPropertyValue( C2U( "CharHeightComplex" ), uno::makeAny( fCharHeight
) );
506 xProperties
->setPropertyValue( C2U( "TextVerticalAdjust" ), uno::makeAny( drawing::TextVerticalAdjust_CENTER
) );
507 xProperties
->setPropertyValue( C2U( "TextHorizontalAdjust" ), uno::makeAny( drawing::TextHorizontalAdjust_CENTER
) );
508 xProperties
->setPropertyValue( C2U( "CharFontName" ), uno::makeAny( C2U( "Albany" ) ) );
510 xTextShape
->setPosition( rPosition
);
512 m_aSelection
.setSelection( xTextShape
);
513 m_aSelection
.applySelection( m_pDrawViewWrapper
);
515 SdrObject
* pObj
= DrawViewWrapper::getSdrObject( xTextShape
);
518 m_pDrawViewWrapper
->BegUndo( SVX_RESSTR( RID_SVX_3D_UNDO_EXCHANGE_PASTE
) );
519 m_pDrawViewWrapper
->AddUndo( new SdrUndoInsertObj( *pObj
) );
520 m_pDrawViewWrapper
->EndUndo();
522 impl_switchDiagramPositioningToExcludingPositioning();
525 catch ( const uno::Exception
& ex
)
527 ASSERT_EXCEPTION( ex
);
533 void ChartController::executeDispatch_Copy()
535 if ( m_pDrawViewWrapper
)
537 OutlinerView
* pOutlinerView
= m_pDrawViewWrapper
->GetTextEditOutlinerView();
540 pOutlinerView
->Copy();
544 Reference
< datatransfer::XTransferable
> xTransferable
;
546 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
547 SdrObject
* pSelectedObj
= 0;
548 if ( m_pDrawModelWrapper
)
550 ObjectIdentifier
aSelOID( m_aSelection
.getSelectedOID() );
551 if ( aSelOID
.isAutoGeneratedObject() )
553 pSelectedObj
= m_pDrawModelWrapper
->getNamedSdrObject( aSelOID
.getObjectCID() );
555 else if ( aSelOID
.isAdditionalShape() )
557 pSelectedObj
= DrawViewWrapper::getSdrObject( aSelOID
.getAdditionalShape() );
561 xTransferable
= Reference
< datatransfer::XTransferable
>( new ChartTransferable(
562 &m_pDrawModelWrapper
->getSdrModel(), pSelectedObj
, aSelOID
.isAdditionalShape() ) );
566 if ( xTransferable
.is() )
568 Reference
< datatransfer::clipboard::XClipboard
> xClipboard( TransferableHelper::GetSystemClipboard() );
569 if ( xClipboard
.is() )
571 xClipboard
->setContents( xTransferable
, Reference
< datatransfer::clipboard::XClipboardOwner
>() );
578 void ChartController::executeDispatch_Cut()
580 executeDispatch_Copy();
581 executeDispatch_Delete();
585 bool ChartController::isObjectDeleteable( const uno::Any
& rSelection
)
587 ObjectIdentifier
aSelOID( rSelection
);
588 if ( aSelOID
.isAutoGeneratedObject() )
590 OUString
aSelObjCID( aSelOID
.getObjectCID() );
591 ObjectType
aObjectType(ObjectIdentifier::getObjectType( aSelObjCID
));
592 if( (OBJECTTYPE_TITLE
== aObjectType
) || (OBJECTTYPE_LEGEND
== aObjectType
) )
594 if( (OBJECTTYPE_DATA_SERIES
== aObjectType
) || (OBJECTTYPE_LEGEND_ENTRY
== aObjectType
) )
596 if( (OBJECTTYPE_DATA_CURVE_EQUATION
== aObjectType
) || (OBJECTTYPE_DATA_CURVE
== aObjectType
) ||
597 (OBJECTTYPE_DATA_AVERAGE_LINE
== aObjectType
) || (OBJECTTYPE_DATA_ERRORS
== aObjectType
))
599 if( (OBJECTTYPE_DATA_LABELS
== aObjectType
) || (OBJECTTYPE_DATA_LABEL
== aObjectType
) )
601 if( (OBJECTTYPE_AXIS
== aObjectType
) || (OBJECTTYPE_GRID
== aObjectType
) || (OBJECTTYPE_SUBGRID
== aObjectType
) )
604 else if ( aSelOID
.isAdditionalShape() )
612 bool ChartController::isShapeContext() const
614 if ( m_aSelection
.isAdditionalShapeSelected() ||
615 ( m_pDrawViewWrapper
&& m_pDrawViewWrapper
->AreObjectsMarked() &&
616 ( m_pDrawViewWrapper
->GetCurrentObjIdentifier() == OBJ_TEXT
) ) )
624 void ChartController::impl_ClearSelection()
626 if( m_aSelection
.hasSelection())
628 m_aSelection
.clearSelection();
629 impl_notifySelectionChangeListeners();
633 bool ChartController::executeDispatch_Delete()
635 bool bReturn
= false;
637 // remove the selected object
639 rtl::OUString
aCID( m_aSelection
.getSelectedCID() );
640 if( aCID
.getLength() )
642 if( !isObjectDeleteable( uno::Any( aCID
) ) )
645 //remove chart object
646 uno::Reference
< chart2::XChartDocument
> xChartDoc( getModel(), uno::UNO_QUERY
);
647 if( !xChartDoc
.is() )
650 ObjectType
aObjectType( ObjectIdentifier::getObjectType( aCID
));
651 switch( aObjectType
)
653 case OBJECTTYPE_TITLE
:
655 // using assignment for broken gcc 3.3
656 UndoGuard aUndoGuard
= UndoGuard(
657 ActionDescriptionProvider::createDescription(
658 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String( SchResId( STR_OBJECT_TITLE
)))),
659 m_xUndoManager
, getModel());
660 TitleHelper::removeTitle(
661 ObjectIdentifier::getTitleTypeForCID( aCID
), getModel() );
663 aUndoGuard
.commitAction();
666 case OBJECTTYPE_LEGEND
:
668 uno::Reference
< chart2::XDiagram
> xDiagram( xChartDoc
->getFirstDiagram());
671 uno::Reference
< beans::XPropertySet
> xLegendProp( xDiagram
->getLegend(), uno::UNO_QUERY
);
672 if( xLegendProp
.is())
674 // using assignment for broken gcc 3.3
675 UndoGuard aUndoGuard
= UndoGuard(
676 ActionDescriptionProvider::createDescription(
677 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String( SchResId( STR_OBJECT_LEGEND
)))),
678 m_xUndoManager
, getModel() );
679 xLegendProp
->setPropertyValue( C2U("Show"), uno::makeAny( false ));
681 aUndoGuard
.commitAction();
687 case OBJECTTYPE_DATA_SERIES
:
688 bReturn
= lcl_deleteDataSeries( aCID
, getModel(), m_xUndoManager
);
691 case OBJECTTYPE_LEGEND_ENTRY
:
693 ObjectType eParentObjectType
= ObjectIdentifier::getObjectType(
694 ObjectIdentifier::getFullParentParticle( aCID
));
695 if( eParentObjectType
== OBJECTTYPE_DATA_SERIES
)
696 bReturn
= lcl_deleteDataSeries( aCID
, getModel(), m_xUndoManager
);
697 else if( eParentObjectType
== OBJECTTYPE_DATA_CURVE
)
698 bReturn
= lcl_deleteDataCurve( aCID
, getModel(), m_xUndoManager
);
702 case OBJECTTYPE_DATA_AVERAGE_LINE
:
704 uno::Reference
< chart2::XRegressionCurveContainer
> xRegCurveCnt(
705 ObjectIdentifier::getObjectPropertySet(
706 ObjectIdentifier::getFullParentParticle( aCID
), getModel()), uno::UNO_QUERY
);
707 if( xRegCurveCnt
.is())
709 // using assignment for broken gcc 3.3
710 UndoGuard aUndoGuard
= UndoGuard(
711 ActionDescriptionProvider::createDescription(
712 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String( SchResId( STR_OBJECT_AVERAGE_LINE
)))),
713 m_xUndoManager
, getModel() );
714 RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt
);
716 aUndoGuard
.commitAction();
721 case OBJECTTYPE_DATA_CURVE
:
722 bReturn
= lcl_deleteDataCurve( aCID
, getModel(), m_xUndoManager
);
725 case OBJECTTYPE_DATA_CURVE_EQUATION
:
727 uno::Reference
< beans::XPropertySet
> xEqProp(
728 ObjectIdentifier::getObjectPropertySet( aCID
, getModel()));
731 uno::Reference
< frame::XModel
> xModel( getModel() );
732 // using assignment for broken gcc 3.3
733 UndoGuard aUndoGuard
= UndoGuard(
734 ActionDescriptionProvider::createDescription(
735 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE_EQUATION
)))),
736 m_xUndoManager
, xModel
);
738 ControllerLockGuard
aCtlLockGuard( xModel
);
739 xEqProp
->setPropertyValue( C2U("ShowEquation"), uno::makeAny( false ));
740 xEqProp
->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( false ));
743 aUndoGuard
.commitAction();
748 case OBJECTTYPE_DATA_ERRORS
:
750 uno::Reference
< beans::XPropertySet
> xErrorBarProp(
751 ObjectIdentifier::getObjectPropertySet( aCID
, getModel() ));
752 if( xErrorBarProp
.is())
754 uno::Reference
< frame::XModel
> xModel( getModel() );
755 // using assignment for broken gcc 3.3
756 UndoGuard aUndoGuard
= UndoGuard(
757 ActionDescriptionProvider::createDescription(
758 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String( SchResId( STR_OBJECT_ERROR_BARS
)))),
759 m_xUndoManager
, xModel
);
761 ControllerLockGuard
aCtlLockGuard( xModel
);
762 xErrorBarProp
->setPropertyValue(
763 C2U("ErrorBarStyle"),
764 uno::makeAny( ::com::sun::star::chart::ErrorBarStyle::NONE
));
767 aUndoGuard
.commitAction();
772 case OBJECTTYPE_DATA_LABELS
:
773 case OBJECTTYPE_DATA_LABEL
:
775 uno::Reference
< beans::XPropertySet
> xObjectProperties
=
776 ObjectIdentifier::getObjectPropertySet( aCID
, getModel() );
777 if( xObjectProperties
.is() )
779 UndoGuard aUndoGuard
= UndoGuard(
780 ActionDescriptionProvider::createDescription(
781 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String(
782 SchResId( aObjectType
== OBJECTTYPE_DATA_LABEL
? STR_OBJECT_LABEL
: STR_OBJECT_DATALABELS
)))),
783 m_xUndoManager
, getModel() );
784 chart2::DataPointLabel aLabel
;
785 xObjectProperties
->getPropertyValue( C2U( "Label" ) ) >>= aLabel
;
786 aLabel
.ShowNumber
= false;
787 aLabel
.ShowNumberInPercent
= false;
788 aLabel
.ShowCategoryName
= false;
789 aLabel
.ShowLegendSymbol
= false;
790 if( aObjectType
== OBJECTTYPE_DATA_LABELS
)
792 uno::Reference
< chart2::XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( aCID
, getModel() ));
793 ::chart::DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries
, C2U( "Label" ), uno::makeAny(aLabel
) );
796 xObjectProperties
->setPropertyValue( C2U( "Label" ), uno::makeAny(aLabel
) );
798 aUndoGuard
.commitAction();
802 case OBJECTTYPE_AXIS
:
804 executeDispatch_DeleteAxis();
808 case OBJECTTYPE_GRID
:
810 executeDispatch_DeleteMajorGrid();
814 case OBJECTTYPE_SUBGRID
:
816 executeDispatch_DeleteMinorGrid();
829 //remove additional shape
830 impl_ClearSelection();
832 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
833 if ( m_pDrawViewWrapper
)
835 m_pDrawViewWrapper
->DeleteMarked();
843 void ChartController::executeDispatch_ToggleLegend()
845 Reference
< frame::XModel
> xModel( getModel() );
846 UndoGuard aUndoGuard
= UndoGuard(
847 ::rtl::OUString( String( SchResId( STR_ACTION_TOGGLE_LEGEND
))), m_xUndoManager
, xModel
);
848 Reference
< beans::XPropertySet
> xLegendProp( LegendHelper::getLegend( xModel
), uno::UNO_QUERY
);
849 bool bChanged
= false;
850 if( xLegendProp
.is())
855 if( xLegendProp
->getPropertyValue( C2U("Show")) >>= bShow
)
857 xLegendProp
->setPropertyValue( C2U("Show"), uno::makeAny( ! bShow
));
861 catch( const uno::Exception
& ex
)
863 ASSERT_EXCEPTION( ex
);
868 xLegendProp
.set( LegendHelper::getLegend( xModel
, m_xCC
, true ), uno::UNO_QUERY
);
869 if( xLegendProp
.is())
874 aUndoGuard
.commitAction();
877 void ChartController::executeDispatch_ToggleGridHorizontal()
879 Reference
< frame::XModel
> xModel( getModel() );
880 UndoGuard aUndoGuard
= UndoGuard(
881 ::rtl::OUString( String( SchResId( STR_ACTION_TOGGLE_GRID_HORZ
))), m_xUndoManager
, xModel
);
882 Reference
< chart2::XDiagram
> xDiagram( ChartModelHelper::findDiagram( getModel() ));
885 sal_Int32 nDimensionIndex
= 1;
886 sal_Int32 nCooSysIndex
= 0;
887 bool bIsMainGrid
= true;
889 bool bHasMainYGrid
= AxisHelper::isGridShown( nDimensionIndex
, nCooSysIndex
, bIsMainGrid
, xDiagram
);
892 AxisHelper::hideGrid( nDimensionIndex
, nCooSysIndex
, bIsMainGrid
, xDiagram
);
894 AxisHelper::showGrid( nDimensionIndex
, nCooSysIndex
, bIsMainGrid
, xDiagram
, m_xCC
);
896 aUndoGuard
.commitAction();
900 void ChartController::impl_ShapeControllerDispatch( const util::URL
& rURL
, const Sequence
< beans::PropertyValue
>& rArgs
)
902 Reference
< frame::XDispatch
> xDispatch( m_aDispatchContainer
.getShapeController() );
903 if ( xDispatch
.is() )
905 xDispatch
->dispatch( rURL
, rArgs
);
909 void ChartController::impl_switchDiagramPositioningToExcludingPositioning()
911 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription(
912 ActionDescriptionProvider::POS_SIZE
,
913 ObjectNameProvider::getName( OBJECTTYPE_DIAGRAM
)),
914 m_xUndoManager
, m_aModel
->getModel() );
915 if( DiagramHelper::switchDiagramPositioningToExcludingPositioning( m_aModel
->getModel(), true, true ) )
916 aUndoGuard
.commitAction();