1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ChartController.hxx"
21 #include "ChartWindow.hxx"
22 #include "ChartModelHelper.hxx"
23 #include "TitleHelper.hxx"
24 #include "ThreeDHelper.hxx"
25 #include "DataSeriesHelper.hxx"
26 #include "UndoGuard.hxx"
27 #include "ControllerLockGuard.hxx"
30 #include "Strings.hrc"
31 #include "ObjectIdentifier.hxx"
32 #include "ReferenceSizeProvider.hxx"
33 #include "chartview/ExplicitValueProvider.hxx"
34 #include "chartview/DrawModelWrapper.hxx"
35 #include "ChartTransferable.hxx"
36 #include "DrawViewWrapper.hxx"
37 #include "LegendHelper.hxx"
38 #include "AxisHelper.hxx"
39 #include "RegressionCurveHelper.hxx"
40 #include "ShapeController.hxx"
41 #include "DiagramHelper.hxx"
42 #include "ObjectNameProvider.hxx"
43 #include <unonames.hxx>
45 #include <com/sun/star/chart2/DataPointLabel.hpp>
46 #include <com/sun/star/beans/XPropertyState.hpp>
47 #include <com/sun/star/drawing/CameraGeometry.hpp>
48 #include <com/sun/star/graphic/XGraphic.hpp>
49 #include <com/sun/star/io/XInputStream.hpp>
50 #include <com/sun/star/text/XTextRange.hpp>
51 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
52 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
53 #include <com/sun/star/chart/ErrorBarStyle.hpp>
55 #include <svx/ActionDescriptionProvider.hxx>
56 #include <svtools/transfer.hxx>
57 #include <sot/storage.hxx>
58 #include <vcl/graph.hxx>
59 #include <svx/unomodel.hxx>
60 #include <svx/svdmodel.hxx>
61 #include <unotools/streamwrap.hxx>
62 #include <vcl/svapp.hxx>
63 #include <osl/mutex.hxx>
64 #include <svx/dialmgr.hxx>
65 #include <svx/dialogs.hrc>
66 #include <editeng/outliner.hxx>
67 #include <svx/svditer.hxx>
68 #include <svx/svdpage.hxx>
69 #include <svx/svdundo.hxx>
70 #include <svx/unoapi.hxx>
71 #include <svx/unopage.hxx>
73 #include <boost/scoped_ptr.hpp>
75 using namespace ::com::sun::star
;
77 using ::com::sun::star::uno::Reference
;
78 using ::com::sun::star::uno::Sequence
;
86 bool lcl_deleteDataSeries(
87 const OUString
& rCID
,
88 const Reference
< frame::XModel
> & xModel
,
89 const Reference
< document::XUndoManager
> & xUndoManager
)
92 uno::Reference
< chart2::XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rCID
, xModel
));
93 uno::Reference
< chart2::XChartDocument
> xChartDoc( xModel
, uno::UNO_QUERY
);
94 if( xSeries
.is() && xChartDoc
.is())
96 uno::Reference
< chart2::XChartType
> xChartType(
97 DataSeriesHelper::getChartTypeOfSeries( xSeries
, xChartDoc
->getFirstDiagram()));
100 UndoGuard
aUndoGuard(
101 ActionDescriptionProvider::createDescription(
102 ActionDescriptionProvider::DELETE
, SCH_RESSTR( STR_OBJECT_DATASERIES
)),
105 Reference
< chart2::XDiagram
> xDiagram( ChartModelHelper::findDiagram( xModel
) );
106 uno::Reference
< chart2::XAxis
> xAxis( DiagramHelper::getAttachedAxis( xSeries
, xDiagram
) );
108 DataSeriesHelper::deleteSeries( xSeries
, xChartType
);
110 AxisHelper::hideAxisIfNoDataIsAttached( xAxis
, xDiagram
);
119 bool lcl_deleteDataCurve(
120 const OUString
& rCID
,
121 const Reference
< frame::XModel
> & xModel
,
122 const Reference
< document::XUndoManager
> & xUndoManager
)
124 bool bResult
= false;
126 uno::Reference
< beans::XPropertySet
> xProperties(
127 ObjectIdentifier::getObjectPropertySet( rCID
, xModel
));
129 uno::Reference
< chart2::XRegressionCurve
> xRegressionCurve( xProperties
, uno::UNO_QUERY
);
131 if( xRegressionCurve
.is())
133 uno::Reference
< chart2::XRegressionCurveContainer
> xRegressionCurveContainer(
134 ObjectIdentifier::getObjectPropertySet(
135 ObjectIdentifier::getFullParentParticle( rCID
), xModel
), uno::UNO_QUERY
);
137 if( xRegressionCurveContainer
.is())
139 UndoGuard aUndoGuard
= UndoGuard(
140 ActionDescriptionProvider::createDescription(
141 ActionDescriptionProvider::DELETE
, SCH_RESSTR( STR_OBJECT_CURVE
)),
144 xRegressionCurveContainer
->removeRegressionCurve( xRegressionCurve
);
153 } // anonymous namespace
155 ReferenceSizeProvider
* ChartController::impl_createReferenceSizeProvider()
157 awt::Size
aPageSize( ChartModelHelper::getPageSize( getModel() ) );
159 return new ReferenceSizeProvider(
160 aPageSize
, Reference
<chart2::XChartDocument
>(getModel(), uno::UNO_QUERY
));
163 void ChartController::impl_adaptDataSeriesAutoResize()
165 boost::scoped_ptr
<ReferenceSizeProvider
> pRefSizeProvider(impl_createReferenceSizeProvider());
166 if (pRefSizeProvider
)
167 pRefSizeProvider
->setValuesAtAllDataSeries();
170 void ChartController::executeDispatch_NewArrangement()
172 // remove manual positions at titles, legend and the diagram, remove manual
173 // size at the diagram
177 Reference
< frame::XModel
> xModel( getModel() );
178 Reference
< chart2::XDiagram
> xDiagram( ChartModelHelper::findDiagram( xModel
));
181 // using assignment for broken gcc 3.3
182 UndoGuard aUndoGuard
= UndoGuard(
183 SCH_RESSTR( STR_ACTION_REARRANGE_CHART
),
185 ControllerLockGuardUNO
aCtlLockGuard( xModel
);
188 Reference
< beans::XPropertyState
> xState( xDiagram
, uno::UNO_QUERY_THROW
);
189 xState
->setPropertyToDefault( "RelativeSize");
190 xState
->setPropertyToDefault( "RelativePosition");
191 xState
->setPropertyToDefault( "PosSizeExcludeAxes");
194 ThreeDHelper::set3DSettingsToDefault( uno::Reference
< beans::XPropertySet
>( xDiagram
, uno::UNO_QUERY
) );
197 Reference
< beans::XPropertyState
> xLegendState( xDiagram
->getLegend(), uno::UNO_QUERY
);
198 if( xLegendState
.is())
200 xLegendState
->setPropertyToDefault( "RelativePosition");
201 xLegendState
->setPropertyToDefault( "RelativeSize");
202 xLegendState
->setPropertyToDefault( "AnchorPosition");
206 for( sal_Int32 eType
= TitleHelper::TITLE_BEGIN
;
207 eType
< TitleHelper::NORMAL_TITLE_END
;
210 Reference
< beans::XPropertyState
> xTitleState(
211 TitleHelper::getTitle(
212 static_cast< TitleHelper::eTitleType
>( eType
), xModel
), uno::UNO_QUERY
);
213 if( xTitleState
.is())
214 xTitleState
->setPropertyToDefault( "RelativePosition");
217 // regression curve equations
218 ::std::vector
< Reference
< chart2::XRegressionCurve
> > aRegressionCurves(
219 RegressionCurveHelper::getAllRegressionCurvesNotMeanValueLine( xDiagram
));
220 ::std::for_each( aRegressionCurves
.begin(), aRegressionCurves
.end(),
221 RegressionCurveHelper::resetEquationPosition
);
226 catch( const uno::RuntimeException
& ex
)
228 ASSERT_EXCEPTION( ex
);
232 void ChartController::executeDispatch_ScaleText()
234 SolarMutexGuard aSolarGuard
;
235 // using assignment for broken gcc 3.3
236 UndoGuard aUndoGuard
= UndoGuard(
237 SCH_RESSTR( STR_ACTION_SCALE_TEXT
),
239 ControllerLockGuardUNO
aCtlLockGuard( getModel() );
241 boost::scoped_ptr
<ReferenceSizeProvider
> pRefSizeProv(impl_createReferenceSizeProvider());
242 OSL_ASSERT( pRefSizeProv
.get());
244 pRefSizeProv
->toggleAutoResizeState();
249 void ChartController::executeDispatch_Paste()
251 SolarMutexGuard aGuard
;
255 // paste location: center of window
257 aPos
= m_pChartWindow
->PixelToLogic( Rectangle( aPos
, m_pChartWindow
->GetSizePixel()).Center());
259 // handle different formats
260 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( m_pChartWindow
));
261 if( aDataHelper
.GetTransferable().is())
263 if ( aDataHelper
.HasFormat( SotClipboardFormatId::DRAWING
) )
265 tools::SvRef
<SotStorageStream
> xStm
;
266 if ( aDataHelper
.GetSotStorageStream( SotClipboardFormatId::DRAWING
, xStm
) )
269 Reference
< io::XInputStream
> xInputStream( new utl::OInputStreamWrapper( *xStm
) );
270 ::boost::scoped_ptr
< SdrModel
> spModel( new SdrModel() );
271 if ( SvxDrawingLayerImport( spModel
.get(), xInputStream
) )
273 impl_PasteShapes( spModel
.get() );
277 else if ( aDataHelper
.HasFormat( SotClipboardFormatId::SVXB
) )
279 // graphic exchange format (graphic manager bitmap format?)
280 tools::SvRef
<SotStorageStream
> xStm
;
281 if( aDataHelper
.GetSotStorageStream( SotClipboardFormatId::SVXB
, xStm
))
282 ReadGraphic( *xStm
, aGraphic
);
284 else if( aDataHelper
.HasFormat( SotClipboardFormatId::GDIMETAFILE
))
287 GDIMetaFile aMetafile
;
288 if( aDataHelper
.GetGDIMetaFile( SotClipboardFormatId::GDIMETAFILE
, aMetafile
))
289 aGraphic
= Graphic( aMetafile
);
291 else if( aDataHelper
.HasFormat( SotClipboardFormatId::BITMAP
))
293 // bitmap (non-graphic-manager)
295 if( aDataHelper
.GetBitmapEx( SotClipboardFormatId::BITMAP
, aBmpEx
))
296 aGraphic
= Graphic( aBmpEx
);
298 else if( aDataHelper
.HasFormat( SotClipboardFormatId::STRING
))
301 if( aDataHelper
.GetString( SotClipboardFormatId::STRING
, aString
) && m_pDrawModelWrapper
)
303 if( m_pDrawViewWrapper
)
305 OutlinerView
* pOutlinerView
= m_pDrawViewWrapper
->GetTextEditOutlinerView();
306 if( pOutlinerView
)//in case of edit mode insert into edited string
307 pOutlinerView
->InsertText( aString
);
310 impl_PasteStringAsTextShape( aString
, awt::Point( 0, 0 ) );
317 if( aGraphic
.GetType() != GRAPHIC_NONE
)
319 Reference
< graphic::XGraphic
> xGraphic( aGraphic
.GetXGraphic());
321 impl_PasteGraphic( xGraphic
, aPos
);
326 // note: aPosition is ignored for now. The object is always pasted centered to
328 void ChartController::impl_PasteGraphic(
329 uno::Reference
< graphic::XGraphic
> & xGraphic
,
330 const ::Point
& /* aPosition */ )
332 // note: the XPropertySet of the model is the old API. Also the property
333 // "AdditionalShapes" that is used there.
334 uno::Reference
< beans::XPropertySet
> xModelProp( getModel(), uno::UNO_QUERY
);
335 DrawModelWrapper
* pDrawModelWrapper( this->GetDrawModelWrapper());
336 if( ! (xGraphic
.is() && xModelProp
.is()))
338 uno::Reference
< lang::XMultiServiceFactory
> xFact( pDrawModelWrapper
->getShapeFactory());
339 uno::Reference
< drawing::XShape
> xGraphicShape(
340 xFact
->createInstance( "com.sun.star.drawing.GraphicObjectShape" ), uno::UNO_QUERY
);
341 uno::Reference
< beans::XPropertySet
> xGraphicShapeProp( xGraphicShape
, uno::UNO_QUERY
);
342 if( xGraphicShapeProp
.is() && xGraphicShape
.is())
344 uno::Reference
< drawing::XShapes
> xPage( pDrawModelWrapper
->getMainDrawPage(), uno::UNO_QUERY
);
347 xPage
->add( xGraphicShape
);
348 //need to change the model state manually
350 uno::Reference
< util::XModifiable
> xModifiable( getModel(), uno::UNO_QUERY
);
351 if( xModifiable
.is() )
352 xModifiable
->setModified( true );
355 m_aSelection
.setSelection( xGraphicShape
);
356 m_aSelection
.applySelection( m_pDrawViewWrapper
);
358 xGraphicShapeProp
->setPropertyValue( "Graphic", uno::makeAny( xGraphic
));
359 uno::Reference
< beans::XPropertySet
> xGraphicProp( xGraphic
, uno::UNO_QUERY
);
361 awt::Size
aGraphicSize( 1000, 1000 );
362 // first try size in 100th mm, then pixel size
363 if( ! ( xGraphicProp
->getPropertyValue( "Size100thMM") >>= aGraphicSize
) &&
364 ( ( xGraphicProp
->getPropertyValue( "SizePixel") >>= aGraphicSize
) && m_pChartWindow
))
366 ::Size
aVCLSize( m_pChartWindow
->PixelToLogic( Size( aGraphicSize
.Width
, aGraphicSize
.Height
)));
367 aGraphicSize
.Width
= aVCLSize
.getWidth();
368 aGraphicSize
.Height
= aVCLSize
.getHeight();
370 xGraphicShape
->setSize( aGraphicSize
);
371 xGraphicShape
->setPosition( awt::Point( 0, 0 ) );
375 void ChartController::impl_PasteShapes( SdrModel
* pModel
)
377 DrawModelWrapper
* pDrawModelWrapper( this->GetDrawModelWrapper() );
378 if ( pDrawModelWrapper
&& m_pDrawViewWrapper
)
380 Reference
< drawing::XDrawPage
> xDestPage( pDrawModelWrapper
->getMainDrawPage() );
381 SdrPage
* pDestPage
= GetSdrPageFromXDrawPage( xDestPage
);
384 Reference
< drawing::XShape
> xSelShape
;
385 m_pDrawViewWrapper
->BegUndo( SVX_RESSTR( RID_SVX_3D_UNDO_EXCHANGE_PASTE
) );
386 sal_uInt16 nCount
= pModel
->GetPageCount();
387 for ( sal_uInt16 i
= 0; i
< nCount
; ++i
)
389 const SdrPage
* pPage
= pModel
->GetPage( i
);
390 SdrObjListIter
aIter( *pPage
, IM_DEEPNOGROUPS
);
391 while ( aIter
.IsMore() )
393 SdrObject
* pObj
= aIter
.Next();
394 SdrObject
* pNewObj
= ( pObj
? pObj
->Clone() : NULL
);
397 pNewObj
->SetModel( &pDrawModelWrapper
->getSdrModel() );
398 pNewObj
->SetPage( pDestPage
);
401 Reference
< drawing::XShape
> xShape( pNewObj
->getUnoShape(), uno::UNO_QUERY
);
404 xShape
->setPosition( awt::Point( 0, 0 ) );
407 pDestPage
->InsertObject( pNewObj
);
408 m_pDrawViewWrapper
->AddUndo( new SdrUndoInsertObj( *pNewObj
) );
414 Reference
< util::XModifiable
> xModifiable( getModel(), uno::UNO_QUERY
);
415 if ( xModifiable
.is() )
417 xModifiable
->setModified( true );
420 // select last inserted shape
421 m_aSelection
.setSelection( xSelShape
);
422 m_aSelection
.applySelection( m_pDrawViewWrapper
);
424 m_pDrawViewWrapper
->EndUndo();
426 impl_switchDiagramPositioningToExcludingPositioning();
431 void ChartController::impl_PasteStringAsTextShape( const OUString
& rString
, const awt::Point
& rPosition
)
433 DrawModelWrapper
* pDrawModelWrapper( this->GetDrawModelWrapper() );
434 if ( pDrawModelWrapper
&& m_pDrawViewWrapper
)
436 const Reference
< lang::XMultiServiceFactory
>& xShapeFactory( pDrawModelWrapper
->getShapeFactory() );
437 const Reference
< drawing::XDrawPage
>& xDrawPage( pDrawModelWrapper
->getMainDrawPage() );
438 OSL_ASSERT( xShapeFactory
.is() && xDrawPage
.is() );
440 if ( xShapeFactory
.is() && xDrawPage
.is() )
444 Reference
< drawing::XShape
> xTextShape(
445 xShapeFactory
->createInstance( "com.sun.star.drawing.TextShape" ), uno::UNO_QUERY_THROW
);
446 xDrawPage
->add( xTextShape
);
448 Reference
< text::XTextRange
> xRange( xTextShape
, uno::UNO_QUERY_THROW
);
449 xRange
->setString( rString
);
451 float fCharHeight
= 10.0;
452 Reference
< beans::XPropertySet
> xProperties( xTextShape
, uno::UNO_QUERY_THROW
);
453 xProperties
->setPropertyValue( "TextAutoGrowHeight", uno::makeAny( true ) );
454 xProperties
->setPropertyValue( "TextAutoGrowWidth", uno::makeAny( true ) );
455 xProperties
->setPropertyValue( "CharHeight", uno::makeAny( fCharHeight
) );
456 xProperties
->setPropertyValue( "CharHeightAsian", uno::makeAny( fCharHeight
) );
457 xProperties
->setPropertyValue( "CharHeightComplex", uno::makeAny( fCharHeight
) );
458 xProperties
->setPropertyValue( "TextVerticalAdjust", uno::makeAny( drawing::TextVerticalAdjust_CENTER
) );
459 xProperties
->setPropertyValue( "TextHorizontalAdjust", uno::makeAny( drawing::TextHorizontalAdjust_CENTER
) );
460 xProperties
->setPropertyValue( "CharFontName", uno::makeAny( OUString("Albany") ) );
462 xTextShape
->setPosition( rPosition
);
464 m_aSelection
.setSelection( xTextShape
);
465 m_aSelection
.applySelection( m_pDrawViewWrapper
);
467 SdrObject
* pObj
= DrawViewWrapper::getSdrObject( xTextShape
);
470 m_pDrawViewWrapper
->BegUndo( SVX_RESSTR( RID_SVX_3D_UNDO_EXCHANGE_PASTE
) );
471 m_pDrawViewWrapper
->AddUndo( new SdrUndoInsertObj( *pObj
) );
472 m_pDrawViewWrapper
->EndUndo();
474 impl_switchDiagramPositioningToExcludingPositioning();
477 catch ( const uno::Exception
& ex
)
479 ASSERT_EXCEPTION( ex
);
485 void ChartController::executeDispatch_Copy()
487 if ( m_pDrawViewWrapper
)
489 OutlinerView
* pOutlinerView
= m_pDrawViewWrapper
->GetTextEditOutlinerView();
492 pOutlinerView
->Copy();
496 Reference
< datatransfer::XTransferable
> xTransferable
;
498 SolarMutexGuard aSolarGuard
;
499 if ( m_pDrawModelWrapper
)
501 SdrObject
* pSelectedObj
= 0;
502 ObjectIdentifier
aSelOID( m_aSelection
.getSelectedOID() );
503 if ( aSelOID
.isAutoGeneratedObject() )
505 pSelectedObj
= m_pDrawModelWrapper
->getNamedSdrObject( aSelOID
.getObjectCID() );
507 else if ( aSelOID
.isAdditionalShape() )
509 pSelectedObj
= DrawViewWrapper::getSdrObject( aSelOID
.getAdditionalShape() );
513 xTransferable
= Reference
< datatransfer::XTransferable
>( new ChartTransferable(
514 &m_pDrawModelWrapper
->getSdrModel(), pSelectedObj
, aSelOID
.isAdditionalShape() ) );
518 if ( xTransferable
.is() )
520 Reference
< datatransfer::clipboard::XClipboard
> xClipboard( TransferableHelper::GetSystemClipboard() );
521 if ( xClipboard
.is() )
523 xClipboard
->setContents( xTransferable
, Reference
< datatransfer::clipboard::XClipboardOwner
>() );
530 void ChartController::executeDispatch_Cut()
532 executeDispatch_Copy();
533 executeDispatch_Delete();
536 bool ChartController::isObjectDeleteable( const uno::Any
& rSelection
)
538 ObjectIdentifier
aSelOID( rSelection
);
539 if ( aSelOID
.isAutoGeneratedObject() )
541 OUString
aSelObjCID( aSelOID
.getObjectCID() );
542 ObjectType
aObjectType(ObjectIdentifier::getObjectType( aSelObjCID
));
546 case OBJECTTYPE_TITLE
:
547 case OBJECTTYPE_LEGEND
:
548 case OBJECTTYPE_DATA_SERIES
:
549 case OBJECTTYPE_LEGEND_ENTRY
:
550 case OBJECTTYPE_DATA_CURVE_EQUATION
:
551 case OBJECTTYPE_DATA_CURVE
:
552 case OBJECTTYPE_DATA_AVERAGE_LINE
:
553 case OBJECTTYPE_DATA_ERRORS_X
:
554 case OBJECTTYPE_DATA_ERRORS_Y
:
555 case OBJECTTYPE_DATA_ERRORS_Z
:
556 case OBJECTTYPE_DATA_LABELS
:
557 case OBJECTTYPE_DATA_LABEL
:
558 case OBJECTTYPE_AXIS
:
559 case OBJECTTYPE_GRID
:
560 case OBJECTTYPE_SUBGRID
:
566 else if ( aSelOID
.isAdditionalShape() )
574 bool ChartController::isShapeContext() const
576 if ( m_aSelection
.isAdditionalShapeSelected() ||
577 ( m_pDrawViewWrapper
&& m_pDrawViewWrapper
->AreObjectsMarked() &&
578 ( m_pDrawViewWrapper
->GetCurrentObjIdentifier() == OBJ_TEXT
) ) )
586 void ChartController::impl_ClearSelection()
588 if( m_aSelection
.hasSelection())
590 m_aSelection
.clearSelection();
591 impl_notifySelectionChangeListeners();
595 bool ChartController::executeDispatch_Delete()
597 bool bReturn
= false;
599 // remove the selected object
600 OUString
aCID( m_aSelection
.getSelectedCID() );
601 if( !aCID
.isEmpty() )
603 if( !isObjectDeleteable( uno::Any( aCID
) ) )
606 //remove chart object
607 uno::Reference
< chart2::XChartDocument
> xChartDoc( getModel(), uno::UNO_QUERY
);
608 if( !xChartDoc
.is() )
611 ObjectType
aObjectType( ObjectIdentifier::getObjectType( aCID
));
612 switch( aObjectType
)
614 case OBJECTTYPE_TITLE
:
616 // using assignment for broken gcc 3.3
617 UndoGuard aUndoGuard
= UndoGuard(
618 ActionDescriptionProvider::createDescription(
619 ActionDescriptionProvider::DELETE
, SCH_RESSTR( STR_OBJECT_TITLE
)),
621 TitleHelper::removeTitle(
622 ObjectIdentifier::getTitleTypeForCID( aCID
), getModel() );
627 case OBJECTTYPE_LEGEND
:
629 uno::Reference
< chart2::XDiagram
> xDiagram( xChartDoc
->getFirstDiagram());
632 uno::Reference
< beans::XPropertySet
> xLegendProp( xDiagram
->getLegend(), uno::UNO_QUERY
);
633 if( xLegendProp
.is())
635 // using assignment for broken gcc 3.3
636 UndoGuard aUndoGuard
= UndoGuard(
637 ActionDescriptionProvider::createDescription(
638 ActionDescriptionProvider::DELETE
, SCH_RESSTR( STR_OBJECT_LEGEND
)),
640 xLegendProp
->setPropertyValue( "Show", uno::makeAny( false ));
648 case OBJECTTYPE_DATA_SERIES
:
649 bReturn
= lcl_deleteDataSeries( aCID
, getModel(), m_xUndoManager
);
652 case OBJECTTYPE_LEGEND_ENTRY
:
654 ObjectType eParentObjectType
= ObjectIdentifier::getObjectType(
655 ObjectIdentifier::getFullParentParticle( aCID
));
656 if( eParentObjectType
== OBJECTTYPE_DATA_SERIES
)
658 bReturn
= lcl_deleteDataSeries( aCID
, getModel(), m_xUndoManager
);
660 else if( eParentObjectType
== OBJECTTYPE_DATA_CURVE
)
662 sal_Int32 nEndPos
= aCID
.lastIndexOf(':');
663 OUString aParentCID
= aCID
.copy(0, nEndPos
);
665 bReturn
= lcl_deleteDataCurve(aParentCID
, getModel(), m_xUndoManager
);
667 else if( eParentObjectType
== OBJECTTYPE_DATA_AVERAGE_LINE
)
669 executeDispatch_DeleteMeanValue();
675 case OBJECTTYPE_DATA_AVERAGE_LINE
:
677 uno::Reference
< chart2::XRegressionCurveContainer
> xRegCurveCnt(
678 ObjectIdentifier::getObjectPropertySet(
679 ObjectIdentifier::getFullParentParticle( aCID
), getModel()), uno::UNO_QUERY
);
680 if( xRegCurveCnt
.is())
682 // using assignment for broken gcc 3.3
683 UndoGuard aUndoGuard
= UndoGuard(
684 ActionDescriptionProvider::createDescription(
685 ActionDescriptionProvider::DELETE
, SCH_RESSTR( STR_OBJECT_AVERAGE_LINE
)),
687 RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt
);
694 case OBJECTTYPE_DATA_CURVE
:
696 bReturn
= lcl_deleteDataCurve( aCID
, getModel(), m_xUndoManager
);
700 case OBJECTTYPE_DATA_CURVE_EQUATION
:
702 uno::Reference
< beans::XPropertySet
> xEqProp(
703 ObjectIdentifier::getObjectPropertySet( aCID
, getModel()));
707 uno::Reference
< frame::XModel
> xModel( getModel() );
708 // using assignment for broken gcc 3.3
709 UndoGuard aUndoGuard
= UndoGuard(
710 ActionDescriptionProvider::createDescription(
711 ActionDescriptionProvider::DELETE
, SCH_RESSTR( STR_OBJECT_CURVE_EQUATION
)),
714 ControllerLockGuardUNO
aCtlLockGuard( xModel
);
715 xEqProp
->setPropertyValue( "ShowEquation", uno::makeAny( false ));
716 xEqProp
->setPropertyValue( "ShowCorrelationCoefficient", uno::makeAny( false ));
724 case OBJECTTYPE_DATA_ERRORS_X
:
725 case OBJECTTYPE_DATA_ERRORS_Y
:
726 case OBJECTTYPE_DATA_ERRORS_Z
:
728 uno::Reference
< beans::XPropertySet
> xErrorBarProp(
729 ObjectIdentifier::getObjectPropertySet( aCID
, getModel() ));
730 if( xErrorBarProp
.is())
734 if ( aObjectType
== OBJECTTYPE_DATA_ERRORS_X
)
735 nId
= STR_OBJECT_ERROR_BARS_X
;
736 else if ( aObjectType
== OBJECTTYPE_DATA_ERRORS_Y
)
737 nId
= STR_OBJECT_ERROR_BARS_Y
;
739 nId
= STR_OBJECT_ERROR_BARS_Z
;
741 uno::Reference
< frame::XModel
> xModel( getModel() );
742 // using assignment for broken gcc 3.3
743 UndoGuard aUndoGuard
= UndoGuard(
744 ActionDescriptionProvider::createDescription(
745 ActionDescriptionProvider::DELETE
, SCH_RESSTR( nId
)),
748 ControllerLockGuardUNO
aCtlLockGuard( xModel
);
749 xErrorBarProp
->setPropertyValue(
751 uno::makeAny( ::com::sun::star::chart::ErrorBarStyle::NONE
));
759 case OBJECTTYPE_DATA_LABELS
:
760 case OBJECTTYPE_DATA_LABEL
:
762 uno::Reference
< beans::XPropertySet
> xObjectProperties
=
763 ObjectIdentifier::getObjectPropertySet( aCID
, getModel() );
764 if( xObjectProperties
.is() )
766 UndoGuard aUndoGuard
= UndoGuard(
767 ActionDescriptionProvider::createDescription(
768 ActionDescriptionProvider::DELETE
,
769 SCH_RESSTR( aObjectType
== OBJECTTYPE_DATA_LABEL
? STR_OBJECT_LABEL
: STR_OBJECT_DATALABELS
)),
771 chart2::DataPointLabel aLabel
;
772 xObjectProperties
->getPropertyValue(CHART_UNONAME_LABEL
) >>= aLabel
;
773 aLabel
.ShowNumber
= false;
774 aLabel
.ShowNumberInPercent
= false;
775 aLabel
.ShowCategoryName
= false;
776 aLabel
.ShowLegendSymbol
= false;
777 if( aObjectType
== OBJECTTYPE_DATA_LABELS
)
779 uno::Reference
< chart2::XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( aCID
, getModel() ));
780 ::chart::DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries
, CHART_UNONAME_LABEL
, uno::makeAny(aLabel
) );
783 xObjectProperties
->setPropertyValue( CHART_UNONAME_LABEL
, uno::makeAny(aLabel
) );
789 case OBJECTTYPE_AXIS
:
791 executeDispatch_DeleteAxis();
795 case OBJECTTYPE_GRID
:
797 executeDispatch_DeleteMajorGrid();
801 case OBJECTTYPE_SUBGRID
:
803 executeDispatch_DeleteMinorGrid();
816 //remove additional shape
817 impl_ClearSelection();
819 SolarMutexGuard aSolarGuard
;
820 if ( m_pDrawViewWrapper
)
822 m_pDrawViewWrapper
->DeleteMarked();
830 void ChartController::executeDispatch_ToggleLegend()
832 Reference
< frame::XModel
> xModel( getModel() );
833 UndoGuard aUndoGuard
= UndoGuard(
834 SCH_RESSTR( STR_ACTION_TOGGLE_LEGEND
), m_xUndoManager
);
835 ChartModel
& rModel
= dynamic_cast<ChartModel
&>(*xModel
.get());
836 Reference
< beans::XPropertySet
> xLegendProp( LegendHelper::getLegend(rModel
), uno::UNO_QUERY
);
837 bool bChanged
= false;
838 if( xLegendProp
.is())
843 if( xLegendProp
->getPropertyValue( "Show") >>= bShow
)
845 xLegendProp
->setPropertyValue( "Show", uno::makeAny( ! bShow
));
849 catch( const uno::Exception
& ex
)
851 ASSERT_EXCEPTION( ex
);
856 xLegendProp
.set( LegendHelper::getLegend(rModel
, m_xCC
, true), uno::UNO_QUERY
);
857 if( xLegendProp
.is())
865 void ChartController::executeDispatch_ToggleGridHorizontal()
867 Reference
< frame::XModel
> xModel( getModel() );
868 UndoGuard aUndoGuard
= UndoGuard(
869 SCH_RESSTR( STR_ACTION_TOGGLE_GRID_HORZ
), m_xUndoManager
);
870 Reference
< chart2::XDiagram
> xDiagram( ChartModelHelper::findDiagram( getModel() ));
873 sal_Int32 nDimensionIndex
= 1;
874 sal_Int32 nCooSysIndex
= 0;
876 bool bHasMajorYGrid
= AxisHelper::isGridShown( nDimensionIndex
, nCooSysIndex
, true, xDiagram
);
877 bool bHasMinorYGrid
= AxisHelper::isGridShown( nDimensionIndex
, nCooSysIndex
, false, xDiagram
);
881 if ( bHasMinorYGrid
)
883 AxisHelper::hideGrid( nDimensionIndex
, nCooSysIndex
, true, xDiagram
);
884 AxisHelper::hideGrid( nDimensionIndex
, nCooSysIndex
, false, xDiagram
);
888 AxisHelper::showGrid( nDimensionIndex
, nCooSysIndex
, false, xDiagram
, m_xCC
);
893 AxisHelper::showGrid( nDimensionIndex
, nCooSysIndex
, true, xDiagram
, m_xCC
);
899 void ChartController::executeDispatch_ToggleGridVertical()
901 Reference
< frame::XModel
> xModel( getModel() );
902 UndoGuard aUndoGuard
= UndoGuard(
903 SCH_RESSTR( STR_ACTION_TOGGLE_GRID_VERTICAL
), m_xUndoManager
);
904 Reference
< chart2::XDiagram
> xDiagram( ChartModelHelper::findDiagram( getModel() ));
907 sal_Int32 nDimensionIndex
= 0;
908 sal_Int32 nCooSysIndex
= 0;
910 bool bHasMajorXGrid
= AxisHelper::isGridShown( nDimensionIndex
, nCooSysIndex
, true, xDiagram
);
911 bool bHasMinorXGrid
= AxisHelper::isGridShown( nDimensionIndex
, nCooSysIndex
, false, xDiagram
);
916 AxisHelper::hideGrid( nDimensionIndex
, nCooSysIndex
, true, xDiagram
);
917 AxisHelper::hideGrid( nDimensionIndex
, nCooSysIndex
, false, xDiagram
);
921 AxisHelper::showGrid( nDimensionIndex
, nCooSysIndex
, false, xDiagram
, m_xCC
);
926 AxisHelper::showGrid( nDimensionIndex
, nCooSysIndex
, true, xDiagram
, m_xCC
);
933 void ChartController::impl_ShapeControllerDispatch( const util::URL
& rURL
, const Sequence
< beans::PropertyValue
>& rArgs
)
935 Reference
< frame::XDispatch
> xDispatch( m_aDispatchContainer
.getShapeController() );
936 if ( xDispatch
.is() )
938 xDispatch
->dispatch( rURL
, rArgs
);
942 void ChartController::impl_switchDiagramPositioningToExcludingPositioning()
944 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription(
945 ActionDescriptionProvider::POS_SIZE
,
946 ObjectNameProvider::getName( OBJECTTYPE_DIAGRAM
)),
948 ChartModel
& rModel
= dynamic_cast<ChartModel
&>(*m_aModel
->getModel().get());
949 if (DiagramHelper::switchDiagramPositioningToExcludingPositioning(rModel
, true, true))
955 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */