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 <ChartModel.hxx>
23 #include <ChartModelHelper.hxx>
24 #include <ChartType.hxx>
25 #include <TitleHelper.hxx>
26 #include <DataSeries.hxx>
27 #include <DataSeriesHelper.hxx>
28 #include "UndoGuard.hxx"
29 #include <ControllerLockGuard.hxx>
31 #include <strings.hrc>
32 #include <ObjectIdentifier.hxx>
33 #include <ReferenceSizeProvider.hxx>
34 #include <chartview/DrawModelWrapper.hxx>
35 #include "ChartTransferable.hxx"
36 #include <DrawViewWrapper.hxx>
38 #include <LegendHelper.hxx>
40 #include <AxisHelper.hxx>
41 #include <RegressionCurveModel.hxx>
42 #include <RegressionCurveHelper.hxx>
43 #include "ShapeController.hxx"
44 #include <DiagramHelper.hxx>
45 #include <Diagram.hxx>
46 #include <ObjectNameProvider.hxx>
47 #include <unonames.hxx>
49 #include <com/sun/star/awt/Gradient.hpp>
50 #include <com/sun/star/chart2/DataPointLabel.hpp>
51 #include <com/sun/star/graphic/XGraphic.hpp>
52 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
53 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
54 #include <com/sun/star/chart/ErrorBarStyle.hpp>
55 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
57 #include <docmodel/uno/UnoGradientTools.hxx>
58 #include <editeng/editview.hxx>
59 #include <editeng/outliner.hxx>
60 #include <svx/ActionDescriptionProvider.hxx>
61 #include <vcl/transfer.hxx>
62 #include <sot/storage.hxx>
63 #include <vcl/graph.hxx>
64 #include <vcl/TypeSerializer.hxx>
65 #include <svx/unomodel.hxx>
66 #include <svx/svdmodel.hxx>
67 #include <unotools/streamwrap.hxx>
68 #include <vcl/svapp.hxx>
69 #include <svx/dialmgr.hxx>
70 #include <svx/strings.hrc>
71 #include <svx/svditer.hxx>
72 #include <svx/svdpage.hxx>
73 #include <svx/svdundo.hxx>
74 #include <svx/unoapi.hxx>
75 #include <svx/unopage.hxx>
76 #include <svx/unoshape.hxx>
77 #include <PropertyHelper.hxx>
79 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
80 #include <tools/debug.hxx>
81 #include <comphelper/diagnose_ex.hxx>
82 #include <tools/UnitConversion.hxx>
86 using namespace ::com::sun::star
;
88 using ::com::sun::star::uno::Reference
;
89 using ::com::sun::star::uno::Sequence
;
97 bool lcl_deleteDataSeries(
98 std::u16string_view rCID
,
99 const rtl::Reference
<::chart::ChartModel
> & xModel
,
100 const Reference
< document::XUndoManager
> & xUndoManager
)
102 bool bResult
= false;
103 rtl::Reference
< DataSeries
> xSeries
= ObjectIdentifier::getDataSeriesForCID( rCID
, xModel
);
104 if( xSeries
.is() && xModel
.is())
106 rtl::Reference
< ::chart::ChartType
> xChartType
=
107 DataSeriesHelper::getChartTypeOfSeries( xSeries
, xModel
->getFirstChartDiagram());
110 UndoGuard
aUndoGuard(
111 ActionDescriptionProvider::createDescription(
112 ActionDescriptionProvider::ActionType::Delete
, SchResId( STR_OBJECT_DATASERIES
)),
115 rtl::Reference
< Diagram
> xDiagram
= xModel
->getFirstChartDiagram();
116 rtl::Reference
< Axis
> xAxis
= xDiagram
->getAttachedAxis( xSeries
);
118 DataSeriesHelper::deleteSeries( xSeries
, xChartType
);
120 AxisHelper::hideAxisIfNoDataIsAttached( xAxis
, xDiagram
);
129 bool lcl_deleteDataCurve(
130 std::u16string_view rCID
,
131 const rtl::Reference
<::chart::ChartModel
> & xModel
,
132 const Reference
< document::XUndoManager
> & xUndoManager
)
134 bool bResult
= false;
136 uno::Reference
< beans::XPropertySet
> xProperties(
137 ObjectIdentifier::getObjectPropertySet( rCID
, xModel
));
139 uno::Reference
< chart2::XRegressionCurve
> xRegressionCurve( xProperties
, uno::UNO_QUERY
);
141 if( xRegressionCurve
.is())
143 uno::Reference
< chart2::XRegressionCurveContainer
> xRegressionCurveContainer(
144 ObjectIdentifier::getObjectPropertySet(
145 ObjectIdentifier::getFullParentParticle( rCID
), xModel
), uno::UNO_QUERY
);
147 if( xRegressionCurveContainer
.is())
149 UndoGuard
aUndoGuard(
150 ActionDescriptionProvider::createDescription(
151 ActionDescriptionProvider::ActionType::Delete
, SchResId( STR_OBJECT_CURVE
)),
154 xRegressionCurveContainer
->removeRegressionCurve( xRegressionCurve
);
163 } // anonymous namespace
165 ReferenceSizeProvider
ChartController::impl_createReferenceSizeProvider()
167 awt::Size
aPageSize( ChartModelHelper::getPageSize( getChartModel() ) );
169 return ReferenceSizeProvider(aPageSize
, getChartModel());
172 void ChartController::impl_adaptDataSeriesAutoResize()
174 impl_createReferenceSizeProvider().setValuesAtAllDataSeries();
177 void ChartController::executeDispatch_NewArrangement()
179 // remove manual positions at titles, legend and the diagram, remove manual
180 // size at the diagram
184 rtl::Reference
<::chart::ChartModel
> xModel( getChartModel() );
185 rtl::Reference
< Diagram
> xDiagram
= xModel
->getFirstChartDiagram();
188 UndoGuard
aUndoGuard(
189 SchResId( STR_ACTION_REARRANGE_CHART
),
191 ControllerLockGuardUNO
aCtlLockGuard( xModel
);
194 xDiagram
->setPropertyToDefault( u
"RelativeSize"_ustr
);
195 xDiagram
->setPropertyToDefault( u
"RelativePosition"_ustr
);
196 xDiagram
->setPropertyToDefault( u
"PosSizeExcludeAxes"_ustr
);
199 xDiagram
->set3DSettingsToDefault();
202 rtl::Reference
< Legend
> xLegend
= xDiagram
->getLegend2();
205 xLegend
->setPropertyToDefault( u
"RelativePosition"_ustr
);
206 xLegend
->setPropertyToDefault( u
"RelativeSize"_ustr
);
207 xLegend
->setPropertyToDefault( u
"AnchorPosition"_ustr
);
211 for( sal_Int32 eType
= TitleHelper::TITLE_BEGIN
;
212 eType
< TitleHelper::NORMAL_TITLE_END
;
215 rtl::Reference
< Title
> xTitleState
=
216 TitleHelper::getTitle(
217 static_cast< TitleHelper::eTitleType
>( eType
), xModel
);
218 if( xTitleState
.is())
219 xTitleState
->setPropertyToDefault( u
"RelativePosition"_ustr
);
222 // regression curve equations
223 std::vector
< rtl::Reference
< RegressionCurveModel
> > aRegressionCurves
=
224 xDiagram
->getAllRegressionCurvesNotMeanValueLine();
226 // reset equation position
227 for( const auto& xCurve
: aRegressionCurves
)
228 RegressionCurveHelper::resetEquationPosition( xCurve
);
233 catch( const uno::RuntimeException
& )
235 DBG_UNHANDLED_EXCEPTION("chart2");
239 void ChartController::executeDispatch_ScaleText()
241 SolarMutexGuard aSolarGuard
;
242 UndoGuard
aUndoGuard(
243 SchResId( STR_ACTION_SCALE_TEXT
),
245 ControllerLockGuardUNO
aCtlLockGuard( getChartModel() );
247 impl_createReferenceSizeProvider().toggleAutoResizeState();
252 void ChartController::executeDispatch_Paste()
254 SolarMutexGuard aGuard
;
255 auto pChartWindow(GetChartWindow());
260 // paste location: center of window
261 Point aPos
= pChartWindow
->PixelToLogic( tools::Rectangle(Point
{}, pChartWindow
->GetSizePixel()).Center());
263 // handle different formats
264 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pChartWindow
));
265 if( aDataHelper
.GetTransferable().is())
267 if ( aDataHelper
.HasFormat( SotClipboardFormatId::DRAWING
) )
269 if (std::unique_ptr
<SvStream
> xStm
= aDataHelper
.GetSotStorageStream( SotClipboardFormatId::DRAWING
) )
272 Reference
< io::XInputStream
> xInputStream( new utl::OInputStreamWrapper( *xStm
) );
274 std::unique_ptr
< SdrModel
> spModel(
277 if ( SvxDrawingLayerImport( spModel
.get(), xInputStream
) )
279 impl_PasteShapes( spModel
.get() );
283 else if ( aDataHelper
.HasFormat( SotClipboardFormatId::SVXB
) )
285 // graphic exchange format (graphic manager bitmap format?)
286 if (std::unique_ptr
<SvStream
> xStm
= aDataHelper
.GetSotStorageStream( SotClipboardFormatId::SVXB
))
288 TypeSerializer
aSerializer(*xStm
);
289 aSerializer
.readGraphic(aGraphic
);
292 else if( aDataHelper
.HasFormat( SotClipboardFormatId::GDIMETAFILE
))
295 GDIMetaFile aMetafile
;
296 if( aDataHelper
.GetGDIMetaFile( SotClipboardFormatId::GDIMETAFILE
, aMetafile
))
297 aGraphic
= Graphic( aMetafile
);
299 else if( aDataHelper
.HasFormat( SotClipboardFormatId::BITMAP
))
301 // bitmap (non-graphic-manager)
303 if( aDataHelper
.GetBitmapEx( SotClipboardFormatId::BITMAP
, aBmpEx
))
304 aGraphic
= Graphic( aBmpEx
);
306 else if( aDataHelper
.HasFormat( SotClipboardFormatId::STRING
))
309 if( aDataHelper
.GetString( SotClipboardFormatId::STRING
, aString
) && m_pDrawModelWrapper
)
311 if( m_pDrawViewWrapper
)
313 OutlinerView
* pOutlinerView
= m_pDrawViewWrapper
->GetTextEditOutlinerView();
314 if (pOutlinerView
)//in case of edit mode insert the formatted string
315 pOutlinerView
->PasteSpecial();
318 impl_PasteStringAsTextShape( aString
, awt::Point( 0, 0 ) );
325 if( aGraphic
.GetType() != GraphicType::NONE
)
327 Reference
< graphic::XGraphic
> xGraphic( aGraphic
.GetXGraphic());
329 impl_PasteGraphic( xGraphic
, aPos
);
333 // note: aPosition is ignored for now. The object is always pasted centered to
335 void ChartController::impl_PasteGraphic(
336 uno::Reference
< graphic::XGraphic
> const & xGraphic
,
337 const ::Point
& /* aPosition */ )
339 DBG_TESTSOLARMUTEX();
340 // note: the XPropertySet of the model is the old API. Also the property
341 // "AdditionalShapes" that is used there.
342 rtl::Reference
< ChartModel
> xModel
= getChartModel();
343 DrawModelWrapper
* pDrawModelWrapper( GetDrawModelWrapper());
344 if( ! (xGraphic
.is() && xModel
.is()))
346 rtl::Reference
<SvxGraphicObject
> xGraphicShape
= new SvxGraphicObject(nullptr);
347 xGraphicShape
->setShapeKind(SdrObjKind::Graphic
);
349 uno::Reference
< drawing::XShapes
> xPage
= pDrawModelWrapper
->getMainDrawPage();
352 xPage
->add( xGraphicShape
);
353 //need to change the model state manually
354 xModel
->setModified( true );
356 m_aSelection
.setSelection( xGraphicShape
);
357 m_aSelection
.applySelection( m_pDrawViewWrapper
.get() );
359 xGraphicShape
->SvxShape::setPropertyValue( u
"Graphic"_ustr
, uno::Any( xGraphic
));
361 awt::Size
aGraphicSize( 1000, 1000 );
362 bool bGotGraphicSize
= false;
365 bGotGraphicSize
= xGraphicShape
->SvxShape::getPropertyValue( u
"Size100thMM"_ustr
) >>= aGraphicSize
;
367 catch (css::beans::UnknownPropertyException
& )
369 auto pChartWindow(GetChartWindow());
370 // first try size in 100th mm, then pixel size
371 if( !bGotGraphicSize
)
373 bool bGotSizePixel
= false;
376 bGotSizePixel
= xGraphicShape
->SvxShape::getPropertyValue( u
"SizePixel"_ustr
) >>= aGraphicSize
;
378 catch (css::beans::UnknownPropertyException
& )
380 if ( bGotSizePixel
&& pChartWindow
)
382 ::Size
aVCLSize( pChartWindow
->PixelToLogic( Size( aGraphicSize
.Width
, aGraphicSize
.Height
)));
383 aGraphicSize
.Width
= aVCLSize
.getWidth();
384 aGraphicSize
.Height
= aVCLSize
.getHeight();
387 xGraphicShape
->setSize( aGraphicSize
);
388 xGraphicShape
->setPosition( awt::Point( 0, 0 ) );
391 void ChartController::impl_PasteShapes( SdrModel
* pModel
)
393 DrawModelWrapper
* pDrawModelWrapper( GetDrawModelWrapper() );
394 if ( !(pDrawModelWrapper
&& m_pDrawViewWrapper
) )
397 Reference
< drawing::XDrawPage
> xDestPage( pDrawModelWrapper
->getMainDrawPage() );
398 SdrPage
* pDestPage
= GetSdrPageFromXDrawPage( xDestPage
);
402 Reference
< drawing::XShape
> xSelShape
;
403 m_pDrawViewWrapper
->BegUndo( SvxResId( RID_SVX_3D_UNDO_EXCHANGE_PASTE
) );
404 sal_uInt16 nCount
= pModel
->GetPageCount();
405 for ( sal_uInt16 i
= 0; i
< nCount
; ++i
)
407 const SdrPage
* pPage
= pModel
->GetPage( i
);
408 SdrObjListIter
aIter( pPage
, SdrIterMode::DeepNoGroups
);
409 while ( aIter
.IsMore() )
411 SdrObject
* pObj(aIter
.Next());
412 // Clone to new SdrModel
413 rtl::Reference
<SdrObject
> pNewObj
;
415 pNewObj
= pObj
->CloneSdrObject(pDrawModelWrapper
->getSdrModel());
420 Reference
< drawing::XShape
> xShape( pNewObj
->getUnoShape(), uno::UNO_QUERY
);
423 xShape
->setPosition( awt::Point( 0, 0 ) );
426 pDestPage
->InsertObject( pNewObj
.get() );
427 m_pDrawViewWrapper
->AddUndo( std::make_unique
<SdrUndoInsertObj
>( *pNewObj
) );
428 xSelShape
= std::move(xShape
);
433 rtl::Reference
< ChartModel
> xModifiable
= getChartModel();
434 if ( xModifiable
.is() )
436 xModifiable
->setModified( true );
439 // select last inserted shape
440 m_aSelection
.setSelection( xSelShape
);
441 m_aSelection
.applySelection( m_pDrawViewWrapper
.get() );
443 m_pDrawViewWrapper
->EndUndo();
445 impl_switchDiagramPositioningToExcludingPositioning();
448 void ChartController::impl_PasteStringAsTextShape( const OUString
& rString
, const awt::Point
& rPosition
)
450 DrawModelWrapper
* pDrawModelWrapper( GetDrawModelWrapper() );
451 if ( !(pDrawModelWrapper
&& m_pDrawViewWrapper
) )
454 const Reference
< drawing::XDrawPage
> xDrawPage( pDrawModelWrapper
->getMainDrawPage() );
455 OSL_ASSERT( xDrawPage
.is() );
462 rtl::Reference
<SvxShapeText
> xTextShape
= new SvxShapeText(nullptr);
463 xTextShape
->setShapeKind(SdrObjKind::Text
);
464 xDrawPage
->add( xTextShape
);
466 xTextShape
->setString( rString
);
468 float fCharHeight
= 10.0;
469 xTextShape
->SvxShape::setPropertyValue( u
"TextAutoGrowHeight"_ustr
, uno::Any( true ) );
470 xTextShape
->SvxShape::setPropertyValue( u
"TextAutoGrowWidth"_ustr
, uno::Any( true ) );
471 xTextShape
->SvxShape::setPropertyValue( u
"CharHeight"_ustr
, uno::Any( fCharHeight
) );
472 xTextShape
->SvxShape::setPropertyValue( u
"CharHeightAsian"_ustr
, uno::Any( fCharHeight
) );
473 xTextShape
->SvxShape::setPropertyValue( u
"CharHeightComplex"_ustr
, uno::Any( fCharHeight
) );
474 xTextShape
->SvxShape::setPropertyValue( u
"TextVerticalAdjust"_ustr
, uno::Any( drawing::TextVerticalAdjust_CENTER
) );
475 xTextShape
->SvxShape::setPropertyValue( u
"TextHorizontalAdjust"_ustr
, uno::Any( drawing::TextHorizontalAdjust_CENTER
) );
476 xTextShape
->SvxShape::setPropertyValue( u
"CharFontName"_ustr
, uno::Any( u
"Albany"_ustr
) );
478 xTextShape
->setPosition( rPosition
);
480 m_aSelection
.setSelection( xTextShape
);
481 m_aSelection
.applySelection( m_pDrawViewWrapper
.get() );
483 SdrObject
* pObj
= DrawViewWrapper::getSdrObject( xTextShape
);
486 m_pDrawViewWrapper
->BegUndo( SvxResId( RID_SVX_3D_UNDO_EXCHANGE_PASTE
) );
487 m_pDrawViewWrapper
->AddUndo( std::make_unique
<SdrUndoInsertObj
>( *pObj
) );
488 m_pDrawViewWrapper
->EndUndo();
490 impl_switchDiagramPositioningToExcludingPositioning();
493 catch ( const uno::Exception
& )
495 DBG_UNHANDLED_EXCEPTION("chart2");
499 void ChartController::executeDispatch_Copy()
501 SolarMutexGuard aSolarGuard
;
502 if (!m_pDrawViewWrapper
)
505 OutlinerView
* pOutlinerView
= m_pDrawViewWrapper
->GetTextEditOutlinerView();
507 pOutlinerView
->Copy();
510 SdrObject
* pSelectedObj
= nullptr;
511 ObjectIdentifier
aSelOID(m_aSelection
.getSelectedOID());
513 if (aSelOID
.isAutoGeneratedObject())
514 pSelectedObj
= m_pDrawModelWrapper
->getNamedSdrObject( aSelOID
.getObjectCID() );
515 else if (aSelOID
.isAdditionalShape())
516 pSelectedObj
= DrawViewWrapper::getSdrObject( aSelOID
.getAdditionalShape() );
520 Reference
<datatransfer::clipboard::XClipboard
> xClipboard(GetChartWindow()->GetClipboard());
523 Reference
< datatransfer::XTransferable
> xTransferable(
524 new ChartTransferable(m_pDrawModelWrapper
->getSdrModel(),
525 pSelectedObj
, aSelOID
.isAdditionalShape()));
526 xClipboard
->setContents(xTransferable
, Reference
< datatransfer::clipboard::XClipboardOwner
>());
532 void ChartController::executeDispatch_Cut()
534 executeDispatch_Copy();
535 executeDispatch_Delete();
538 bool ChartController::isObjectDeleteable( const uno::Any
& rSelection
)
540 ObjectIdentifier
aSelOID( rSelection
);
541 if ( aSelOID
.isAutoGeneratedObject() )
543 const OUString
& aSelObjCID( aSelOID
.getObjectCID() );
544 ObjectType
aObjectType(ObjectIdentifier::getObjectType( aSelObjCID
));
548 case OBJECTTYPE_TITLE
:
549 case OBJECTTYPE_LEGEND
:
550 case OBJECTTYPE_DATA_SERIES
:
551 case OBJECTTYPE_LEGEND_ENTRY
:
552 case OBJECTTYPE_DATA_CURVE_EQUATION
:
553 case OBJECTTYPE_DATA_CURVE
:
554 case OBJECTTYPE_DATA_AVERAGE_LINE
:
555 case OBJECTTYPE_DATA_ERRORS_X
:
556 case OBJECTTYPE_DATA_ERRORS_Y
:
557 case OBJECTTYPE_DATA_ERRORS_Z
:
558 case OBJECTTYPE_DATA_LABELS
:
559 case OBJECTTYPE_DATA_LABEL
:
560 case OBJECTTYPE_AXIS
:
561 case OBJECTTYPE_GRID
:
562 case OBJECTTYPE_SUBGRID
:
568 else if ( aSelOID
.isAdditionalShape() )
576 bool ChartController::isShapeContext() const
578 return m_aSelection
.isAdditionalShapeSelected() ||
579 ( m_pDrawViewWrapper
&& m_pDrawViewWrapper
->GetMarkedObjectList().GetMarkCount() != 0 &&
580 ( m_pDrawViewWrapper
->GetCurrentObjIdentifier() == SdrObjKind::Text
) );
583 bool ChartController::IsTextEdit() const
585 // only Title objects and additional shapes are editable textshapes in chart
586 return m_pDrawViewWrapper
&& m_pDrawViewWrapper
->IsTextEdit() &&
587 (m_aSelection
.isTitleObjectSelected() || m_aSelection
.isAdditionalShapeSelected());
590 void ChartController::impl_ClearSelection()
592 if( m_aSelection
.hasSelection())
594 m_aSelection
.clearSelection();
595 impl_notifySelectionChangeListeners();
599 bool ChartController::executeDispatch_Delete()
601 bool bReturn
= false;
603 // remove the selected object
604 OUString
aCID( m_aSelection
.getSelectedCID() );
605 if( !aCID
.isEmpty() )
607 if( !isObjectDeleteable( uno::Any( aCID
) ) )
610 //remove chart object
611 rtl::Reference
< ChartModel
> xChartDoc
= getChartModel();
612 if( !xChartDoc
.is() )
615 ObjectType
aObjectType( ObjectIdentifier::getObjectType( aCID
));
616 switch( aObjectType
)
618 case OBJECTTYPE_TITLE
:
620 UndoGuard
aUndoGuard(
621 ActionDescriptionProvider::createDescription(
622 ActionDescriptionProvider::ActionType::Delete
, SchResId( STR_OBJECT_TITLE
)),
624 TitleHelper::removeTitle(
625 ObjectIdentifier::getTitleTypeForCID( aCID
), getChartModel() );
630 case OBJECTTYPE_LEGEND
:
632 rtl::Reference
< Diagram
> xDiagram( xChartDoc
->getFirstChartDiagram());
635 rtl::Reference
< Legend
> xLegend( xDiagram
->getLegend2() );
638 UndoGuard
aUndoGuard(
639 ActionDescriptionProvider::createDescription(
640 ActionDescriptionProvider::ActionType::Delete
, SchResId( STR_OBJECT_LEGEND
)),
642 xLegend
->setPropertyValue( u
"Show"_ustr
, uno::Any( false ));
650 case OBJECTTYPE_DATA_SERIES
:
651 bReturn
= lcl_deleteDataSeries( aCID
, getChartModel(), m_xUndoManager
);
654 case OBJECTTYPE_LEGEND_ENTRY
:
656 ObjectType eParentObjectType
= ObjectIdentifier::getObjectType(
657 ObjectIdentifier::getFullParentParticle( aCID
));
658 if( eParentObjectType
== OBJECTTYPE_DATA_SERIES
)
660 bReturn
= lcl_deleteDataSeries( aCID
, getChartModel(), m_xUndoManager
);
662 else if( eParentObjectType
== OBJECTTYPE_DATA_CURVE
)
664 sal_Int32 nEndPos
= aCID
.lastIndexOf(':');
665 OUString aParentCID
= aCID
.copy(0, nEndPos
);
667 bReturn
= lcl_deleteDataCurve(aParentCID
, getChartModel(), m_xUndoManager
);
669 else if( eParentObjectType
== OBJECTTYPE_DATA_AVERAGE_LINE
)
671 executeDispatch_DeleteMeanValue();
677 case OBJECTTYPE_DATA_AVERAGE_LINE
:
679 uno::Reference
< chart2::XRegressionCurveContainer
> xRegCurveCnt(
680 ObjectIdentifier::getObjectPropertySet(
681 ObjectIdentifier::getFullParentParticle( aCID
), getChartModel()), uno::UNO_QUERY
);
682 if( xRegCurveCnt
.is())
684 UndoGuard
aUndoGuard(
685 ActionDescriptionProvider::createDescription(
686 ActionDescriptionProvider::ActionType::Delete
, SchResId( STR_OBJECT_AVERAGE_LINE
)),
688 RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt
);
695 case OBJECTTYPE_DATA_CURVE
:
697 bReturn
= lcl_deleteDataCurve( aCID
, getChartModel(), m_xUndoManager
);
701 case OBJECTTYPE_DATA_CURVE_EQUATION
:
703 uno::Reference
< beans::XPropertySet
> xEqProp(
704 ObjectIdentifier::getObjectPropertySet( aCID
, getChartModel()));
708 rtl::Reference
<::chart::ChartModel
> xModel( getChartModel() );
709 UndoGuard
aUndoGuard(
710 ActionDescriptionProvider::createDescription(
711 ActionDescriptionProvider::ActionType::Delete
, SchResId( STR_OBJECT_CURVE_EQUATION
)),
714 ControllerLockGuardUNO
aCtlLockGuard( xModel
);
715 xEqProp
->setPropertyValue( u
"ShowEquation"_ustr
, uno::Any( false ));
716 xEqProp
->setPropertyValue( u
"XName"_ustr
, uno::Any( u
"x"_ustr
));
717 xEqProp
->setPropertyValue( u
"YName"_ustr
, uno::Any( u
"f(x)"_ustr
));
718 xEqProp
->setPropertyValue( u
"ShowCorrelationCoefficient"_ustr
, uno::Any( false ));
726 case OBJECTTYPE_DATA_ERRORS_X
:
727 case OBJECTTYPE_DATA_ERRORS_Y
:
728 case OBJECTTYPE_DATA_ERRORS_Z
:
730 uno::Reference
< beans::XPropertySet
> xErrorBarProp(
731 ObjectIdentifier::getObjectPropertySet( aCID
, getChartModel() ));
732 if( xErrorBarProp
.is())
736 if ( aObjectType
== OBJECTTYPE_DATA_ERRORS_X
)
737 pId
= STR_OBJECT_ERROR_BARS_X
;
738 else if ( aObjectType
== OBJECTTYPE_DATA_ERRORS_Y
)
739 pId
= STR_OBJECT_ERROR_BARS_Y
;
741 pId
= STR_OBJECT_ERROR_BARS_Z
;
743 rtl::Reference
<::chart::ChartModel
> xModel( getChartModel() );
744 UndoGuard
aUndoGuard(
745 ActionDescriptionProvider::createDescription(
746 ActionDescriptionProvider::ActionType::Delete
, SchResId(pId
)),
749 ControllerLockGuardUNO
aCtlLockGuard( xModel
);
750 xErrorBarProp
->setPropertyValue(
751 u
"ErrorBarStyle"_ustr
,
752 uno::Any( css::chart::ErrorBarStyle::NONE
));
760 case OBJECTTYPE_DATA_LABELS
:
761 case OBJECTTYPE_DATA_LABEL
:
763 uno::Reference
< beans::XPropertySet
> xObjectProperties
=
764 ObjectIdentifier::getObjectPropertySet( aCID
, getChartModel() );
765 if( xObjectProperties
.is() )
767 UndoGuard
aUndoGuard(
768 ActionDescriptionProvider::createDescription(
769 ActionDescriptionProvider::ActionType::Delete
,
770 SchResId( aObjectType
== OBJECTTYPE_DATA_LABEL
? STR_OBJECT_LABEL
: STR_OBJECT_DATALABELS
)),
772 chart2::DataPointLabel aLabel
;
773 xObjectProperties
->getPropertyValue(CHART_UNONAME_LABEL
) >>= aLabel
;
774 aLabel
.ShowNumber
= false;
775 aLabel
.ShowNumberInPercent
= false;
776 aLabel
.ShowCategoryName
= false;
777 aLabel
.ShowLegendSymbol
= false;
778 aLabel
.ShowCustomLabel
= false;
779 aLabel
.ShowSeriesName
= false;
780 if( aObjectType
== OBJECTTYPE_DATA_LABELS
)
782 rtl::Reference
< DataSeries
> xSeries
= ObjectIdentifier::getDataSeriesForCID( aCID
, getChartModel() );
783 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries
, CHART_UNONAME_LABEL
, uno::Any(aLabel
) );
784 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries
, CHART_UNONAME_CUSTOM_LABEL_FIELDS
, uno::Any() );
788 xObjectProperties
->setPropertyValue(CHART_UNONAME_LABEL
, uno::Any(aLabel
));
789 xObjectProperties
->setPropertyValue(CHART_UNONAME_CUSTOM_LABEL_FIELDS
, uno::Any());
796 case OBJECTTYPE_AXIS
:
798 executeDispatch_DeleteAxis();
802 case OBJECTTYPE_GRID
:
804 executeDispatch_DeleteMajorGrid();
808 case OBJECTTYPE_SUBGRID
:
810 executeDispatch_DeleteMinorGrid();
823 //remove additional shape
824 impl_ClearSelection();
826 SolarMutexGuard aSolarGuard
;
827 if ( m_pDrawViewWrapper
)
829 m_pDrawViewWrapper
->DeleteMarked();
837 void ChartController::executeDispatch_ToggleLegend()
839 rtl::Reference
< ChartModel
> xModel
= getChartModel();
840 UndoGuard
aUndoGuard(
841 SchResId( STR_ACTION_TOGGLE_LEGEND
), m_xUndoManager
);
842 rtl::Reference
< Legend
> xLegendProp
= LegendHelper::getLegend(*xModel
);
843 bool bChanged
= false;
844 if( xLegendProp
.is())
849 if( xLegendProp
->getPropertyValue( u
"Show"_ustr
) >>= bShow
)
851 xLegendProp
->setPropertyValue( u
"Show"_ustr
, uno::Any( ! bShow
));
855 catch( const uno::Exception
& )
857 DBG_UNHANDLED_EXCEPTION("chart2");
862 xLegendProp
= LegendHelper::getLegend(*xModel
, m_xCC
, true);
863 if( xLegendProp
.is())
871 void ChartController::executeDispatch_ToggleGridHorizontal()
873 UndoGuard
aUndoGuard(
874 SchResId( STR_ACTION_TOGGLE_GRID_HORZ
), m_xUndoManager
);
875 rtl::Reference
< Diagram
> xDiagram( getFirstDiagram() );
879 sal_Int32 nDimensionIndex
= 1;
880 sal_Int32 nCooSysIndex
= 0;
882 bool bHasMajorYGrid
= AxisHelper::isGridShown( nDimensionIndex
, nCooSysIndex
, true, xDiagram
);
883 bool bHasMinorYGrid
= AxisHelper::isGridShown( nDimensionIndex
, nCooSysIndex
, false, xDiagram
);
887 if ( bHasMinorYGrid
)
889 AxisHelper::hideGrid( nDimensionIndex
, nCooSysIndex
, true, xDiagram
);
890 AxisHelper::hideGrid( nDimensionIndex
, nCooSysIndex
, false, xDiagram
);
894 AxisHelper::showGrid( nDimensionIndex
, nCooSysIndex
, false, xDiagram
);
899 AxisHelper::showGrid( nDimensionIndex
, nCooSysIndex
, true, xDiagram
);
904 void ChartController::executeDispatch_ToggleGridVertical()
906 UndoGuard
aUndoGuard(
907 SchResId( STR_ACTION_TOGGLE_GRID_VERTICAL
), m_xUndoManager
);
908 rtl::Reference
< Diagram
> xDiagram( getFirstDiagram() );
912 sal_Int32 nDimensionIndex
= 0;
913 sal_Int32 nCooSysIndex
= 0;
915 bool bHasMajorXGrid
= AxisHelper::isGridShown( nDimensionIndex
, nCooSysIndex
, true, xDiagram
);
916 bool bHasMinorXGrid
= AxisHelper::isGridShown( nDimensionIndex
, nCooSysIndex
, false, xDiagram
);
921 AxisHelper::hideGrid( nDimensionIndex
, nCooSysIndex
, true, xDiagram
);
922 AxisHelper::hideGrid( nDimensionIndex
, nCooSysIndex
, false, xDiagram
);
926 AxisHelper::showGrid( nDimensionIndex
, nCooSysIndex
, false, xDiagram
);
931 AxisHelper::showGrid( nDimensionIndex
, nCooSysIndex
, true, xDiagram
);
937 void ChartController::executeDispatch_FillColor(sal_uInt32 nColor
)
941 OUString
aCID( m_aSelection
.getSelectedCID() );
942 rtl::Reference
<::chart::ChartModel
> xChartModel
= getChartModel();
943 if( xChartModel
.is() )
945 Reference
< beans::XPropertySet
> xPointProperties(
946 ObjectIdentifier::getObjectPropertySet( aCID
, xChartModel
) );
947 if( xPointProperties
.is() )
948 xPointProperties
->setPropertyValue( u
"FillColor"_ustr
, uno::Any( nColor
) );
951 catch( const uno::Exception
& )
953 DBG_UNHANDLED_EXCEPTION( "chart2" );
957 void ChartController::executeDispatch_FillGradient(std::u16string_view sJSONGradient
)
959 basegfx::BGradient aBGradient
= basegfx::BGradient::fromJSON(sJSONGradient
);
960 css::awt::Gradient aGradient
= model::gradient::createUnoGradient2(aBGradient
);
964 OUString
aCID( m_aSelection
.getSelectedCID() );
965 rtl::Reference
<::chart::ChartModel
> xChartModel
= getChartModel();
967 if( xChartModel
.is() )
969 Reference
< beans::XPropertySet
> xPropSet(
970 ObjectIdentifier::getObjectPropertySet( aCID
, xChartModel
) );
974 OUString aPrefferedName
=
975 OUString::number(static_cast<sal_Int32
>(Color(aBGradient
.GetColorStops().front().getStopColor())))
976 + OUString::number(static_cast<sal_Int32
>(Color(aBGradient
.GetColorStops().back().getStopColor())))
977 + OUString::number(static_cast<sal_Int32
>(aBGradient
.GetAngle().get()));
979 OUString aNewName
= PropertyHelper::addGradientUniqueNameToTable(css::uno::Any(aGradient
),
983 xPropSet
->setPropertyValue(u
"FillGradientName"_ustr
, css::uno::Any(aNewName
));
987 catch( const uno::Exception
& )
989 TOOLS_WARN_EXCEPTION("chart2", "" );
993 void ChartController::executeDispatch_LineColor(sal_uInt32 nColor
)
997 OUString
aCID( m_aSelection
.getSelectedCID() );
998 rtl::Reference
<::chart::ChartModel
> xChartModel
= getChartModel();
999 if( xChartModel
.is() )
1001 Reference
< beans::XPropertySet
> xPropSet(
1002 ObjectIdentifier::getObjectPropertySet( aCID
, xChartModel
) );
1004 ObjectType eType
= ObjectIdentifier::getObjectType(aCID
);
1005 if (eType
== OBJECTTYPE_DIAGRAM
)
1007 css::uno::Reference
<css::chart2::XDiagram
> xDiagram(
1008 xPropSet
, css::uno::UNO_QUERY
);
1010 xPropSet
.set(xDiagram
->getWall());
1014 xPropSet
->setPropertyValue( u
"LineColor"_ustr
, css::uno::Any( Color(ColorTransparency
, nColor
) ) );
1017 catch( const uno::Exception
& )
1019 DBG_UNHANDLED_EXCEPTION( "chart2" );
1023 void ChartController::executeDispatch_LineWidth(sal_uInt32 nWidth
)
1027 OUString
aCID( m_aSelection
.getSelectedCID() );
1028 rtl::Reference
<::chart::ChartModel
> xChartModel
= getChartModel();
1029 if( xChartModel
.is() )
1031 Reference
< beans::XPropertySet
> xPropSet(
1032 ObjectIdentifier::getObjectPropertySet( aCID
, xChartModel
) );
1034 ObjectType eType
= ObjectIdentifier::getObjectType(aCID
);
1035 if (eType
== OBJECTTYPE_DIAGRAM
)
1037 css::uno::Reference
<css::chart2::XDiagram
> xDiagram(
1038 xPropSet
, css::uno::UNO_QUERY
);
1040 xPropSet
.set(xDiagram
->getWall());
1044 xPropSet
->setPropertyValue( u
"LineWidth"_ustr
, css::uno::Any( nWidth
) );
1047 catch( const uno::Exception
& )
1049 DBG_UNHANDLED_EXCEPTION( "chart2" );
1053 void ChartController::executeDispatch_LOKSetTextSelection(int nType
, int nX
, int nY
)
1055 if (!m_pDrawViewWrapper
)
1058 if (!m_pDrawViewWrapper
->IsTextEdit())
1061 OutlinerView
* pOutlinerView
= m_pDrawViewWrapper
->GetTextEditOutlinerView();
1065 EditView
& rEditView
= pOutlinerView
->GetEditView();
1066 Point
aPoint(convertTwipToMm100(nX
), convertTwipToMm100(nY
));
1069 case LOK_SETTEXTSELECTION_START
:
1070 rEditView
.SetCursorLogicPosition(aPoint
, /*bPoint=*/false, /*bClearMark=*/false);
1072 case LOK_SETTEXTSELECTION_END
:
1073 rEditView
.SetCursorLogicPosition(aPoint
, /*bPoint=*/true, /*bClearMark=*/false);
1075 case LOK_SETTEXTSELECTION_RESET
:
1076 rEditView
.SetCursorLogicPosition(aPoint
, /*bPoint=*/true, /*bClearMark=*/true);
1084 void ChartController::executeDispatch_LOKPieSegmentDragging( int nOffset
)
1088 OUString
aCID( m_aSelection
.getSelectedCID() );
1089 rtl::Reference
<::chart::ChartModel
> xChartModel
= getChartModel();
1090 if( xChartModel
.is() )
1092 Reference
< beans::XPropertySet
> xPointProperties(
1093 ObjectIdentifier::getObjectPropertySet( aCID
, xChartModel
) );
1094 if( xPointProperties
.is() )
1095 xPointProperties
->setPropertyValue( u
"Offset"_ustr
, uno::Any( nOffset
/ 100.0 ) );
1098 catch( const uno::Exception
& )
1100 TOOLS_WARN_EXCEPTION("chart2", "" );
1104 void ChartController::impl_ShapeControllerDispatch( const util::URL
& rURL
, const Sequence
< beans::PropertyValue
>& rArgs
)
1106 Reference
< frame::XDispatch
> xDispatch( m_aDispatchContainer
.getShapeController() );
1107 if ( xDispatch
.is() )
1109 xDispatch
->dispatch( rURL
, rArgs
);
1113 void ChartController::impl_switchDiagramPositioningToExcludingPositioning()
1115 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription(
1116 ActionDescriptionProvider::ActionType::PosSize
,
1117 ObjectNameProvider::getName( OBJECTTYPE_DIAGRAM
)),
1119 if (DiagramHelper::switchDiagramPositioningToExcludingPositioning(*getChartModel(), true, true))
1120 aUndoGuard
.commit();
1123 } // namespace chart
1125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */