Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / main / ChartController_Tools.cxx
blob74f7e9ab6f7902a77922272e74707ce60bb39758
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <TitleHelper.hxx>
25 #include <ThreeDHelper.hxx>
26 #include <DataSeriesHelper.hxx>
27 #include "UndoGuard.hxx"
28 #include <ControllerLockGuard.hxx>
29 #include <ResId.hxx>
30 #include <strings.hrc>
31 #include <ObjectIdentifier.hxx>
32 #include <ReferenceSizeProvider.hxx>
33 #include <chartview/DrawModelWrapper.hxx>
34 #include "ChartTransferable.hxx"
35 #include <DrawViewWrapper.hxx>
36 #include <LegendHelper.hxx>
37 #include <AxisHelper.hxx>
38 #include <RegressionCurveHelper.hxx>
39 #include "ShapeController.hxx"
40 #include <DiagramHelper.hxx>
41 #include <ObjectNameProvider.hxx>
42 #include <unonames.hxx>
44 #include <com/sun/star/chart2/DataPointLabel.hpp>
45 #include <com/sun/star/beans/XPropertyState.hpp>
46 #include <com/sun/star/graphic/XGraphic.hpp>
47 #include <com/sun/star/text/XTextRange.hpp>
48 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
49 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
50 #include <com/sun/star/chart/ErrorBarStyle.hpp>
51 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
52 #include <com/sun/star/chart2/XChartDocument.hpp>
54 #include <editeng/editview.hxx>
55 #include <editeng/outliner.hxx>
56 #include <svx/ActionDescriptionProvider.hxx>
57 #include <vcl/transfer.hxx>
58 #include <sot/storage.hxx>
59 #include <vcl/graph.hxx>
60 #include <svx/unomodel.hxx>
61 #include <svx/svdmodel.hxx>
62 #include <unotools/streamwrap.hxx>
63 #include <vcl/svapp.hxx>
64 #include <svx/dialmgr.hxx>
65 #include <svx/strings.hrc>
66 #include <svx/svditer.hxx>
67 #include <svx/svdpage.hxx>
68 #include <svx/svdundo.hxx>
69 #include <svx/unoapi.hxx>
71 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
72 #include <tools/debug.hxx>
73 #include <tools/diagnose_ex.h>
74 #include <sal/log.hxx>
76 #include <memory>
78 using namespace ::com::sun::star;
80 using ::com::sun::star::uno::Reference;
81 using ::com::sun::star::uno::Sequence;
83 namespace chart
86 namespace
89 bool lcl_deleteDataSeries(
90 const OUString & rCID,
91 const Reference< frame::XModel > & xModel,
92 const Reference< document::XUndoManager > & xUndoManager )
94 bool bResult = false;
95 uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rCID, xModel ));
96 uno::Reference< chart2::XChartDocument > xChartDoc( xModel, uno::UNO_QUERY );
97 if( xSeries.is() && xChartDoc.is())
99 uno::Reference< chart2::XChartType > xChartType(
100 DataSeriesHelper::getChartTypeOfSeries( xSeries, xChartDoc->getFirstDiagram()));
101 if( xChartType.is())
103 UndoGuard aUndoGuard(
104 ActionDescriptionProvider::createDescription(
105 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_DATASERIES )),
106 xUndoManager );
108 Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( xModel ) );
109 uno::Reference< chart2::XAxis > xAxis( DiagramHelper::getAttachedAxis( xSeries, xDiagram ) );
111 DataSeriesHelper::deleteSeries( xSeries, xChartType );
113 AxisHelper::hideAxisIfNoDataIsAttached( xAxis, xDiagram );
115 bResult = true;
116 aUndoGuard.commit();
119 return bResult;
122 bool lcl_deleteDataCurve(
123 const OUString & rCID,
124 const Reference< frame::XModel > & xModel,
125 const Reference< document::XUndoManager > & xUndoManager )
127 bool bResult = false;
129 uno::Reference< beans::XPropertySet > xProperties(
130 ObjectIdentifier::getObjectPropertySet( rCID, xModel));
132 uno::Reference< chart2::XRegressionCurve > xRegressionCurve( xProperties, uno::UNO_QUERY );
134 if( xRegressionCurve.is())
136 uno::Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer(
137 ObjectIdentifier::getObjectPropertySet(
138 ObjectIdentifier::getFullParentParticle( rCID ), xModel), uno::UNO_QUERY );
140 if( xRegressionCurveContainer.is())
142 UndoGuard aUndoGuard(
143 ActionDescriptionProvider::createDescription(
144 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE )),
145 xUndoManager );
147 xRegressionCurveContainer->removeRegressionCurve( xRegressionCurve );
149 bResult = true;
150 aUndoGuard.commit();
153 return bResult;
156 } // anonymous namespace
158 std::unique_ptr<ReferenceSizeProvider> ChartController::impl_createReferenceSizeProvider()
160 awt::Size aPageSize( ChartModelHelper::getPageSize( getModel() ) );
162 return std::make_unique<ReferenceSizeProvider>(
163 aPageSize, Reference<chart2::XChartDocument>(getModel(), uno::UNO_QUERY));
166 void ChartController::impl_adaptDataSeriesAutoResize()
168 std::unique_ptr<ReferenceSizeProvider> pRefSizeProvider(impl_createReferenceSizeProvider());
169 if (pRefSizeProvider)
170 pRefSizeProvider->setValuesAtAllDataSeries();
173 void ChartController::executeDispatch_NewArrangement()
175 // remove manual positions at titles, legend and the diagram, remove manual
176 // size at the diagram
180 Reference< frame::XModel > xModel( getModel() );
181 Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( xModel ));
182 if( xDiagram.is())
184 UndoGuard aUndoGuard(
185 SchResId( STR_ACTION_REARRANGE_CHART ),
186 m_xUndoManager );
187 ControllerLockGuardUNO aCtlLockGuard( xModel );
189 // diagram
190 Reference< beans::XPropertyState > xState( xDiagram, uno::UNO_QUERY_THROW );
191 xState->setPropertyToDefault( "RelativeSize");
192 xState->setPropertyToDefault( "RelativePosition");
193 xState->setPropertyToDefault( "PosSizeExcludeAxes");
195 // 3d rotation
196 ThreeDHelper::set3DSettingsToDefault( uno::Reference< beans::XPropertySet >( xDiagram, uno::UNO_QUERY ) );
198 // legend
199 Reference< beans::XPropertyState > xLegendState( xDiagram->getLegend(), uno::UNO_QUERY );
200 if( xLegendState.is())
202 xLegendState->setPropertyToDefault( "RelativePosition");
203 xLegendState->setPropertyToDefault( "RelativeSize");
204 xLegendState->setPropertyToDefault( "AnchorPosition");
207 // titles
208 for( sal_Int32 eType = TitleHelper::TITLE_BEGIN;
209 eType < TitleHelper::NORMAL_TITLE_END;
210 ++eType )
212 Reference< beans::XPropertyState > xTitleState(
213 TitleHelper::getTitle(
214 static_cast< TitleHelper::eTitleType >( eType ), xModel ), uno::UNO_QUERY );
215 if( xTitleState.is())
216 xTitleState->setPropertyToDefault( "RelativePosition");
219 // regression curve equations
220 std::vector< Reference< chart2::XRegressionCurve > > aRegressionCurves(
221 RegressionCurveHelper::getAllRegressionCurvesNotMeanValueLine( xDiagram ));
223 // reset equation position
224 for( const auto& xCurve : aRegressionCurves )
225 RegressionCurveHelper::resetEquationPosition( xCurve );
227 aUndoGuard.commit();
230 catch( const uno::RuntimeException & )
232 DBG_UNHANDLED_EXCEPTION("chart2");
236 void ChartController::executeDispatch_ScaleText()
238 SolarMutexGuard aSolarGuard;
239 UndoGuard aUndoGuard(
240 SchResId( STR_ACTION_SCALE_TEXT ),
241 m_xUndoManager );
242 ControllerLockGuardUNO aCtlLockGuard( getModel() );
244 std::unique_ptr<ReferenceSizeProvider> pRefSizeProv(impl_createReferenceSizeProvider());
245 OSL_ASSERT(pRefSizeProv);
246 if (pRefSizeProv)
247 pRefSizeProv->toggleAutoResizeState();
249 aUndoGuard.commit();
252 void ChartController::executeDispatch_Paste()
254 SolarMutexGuard aGuard;
255 auto pChartWindow(GetChartWindow());
256 if( pChartWindow )
258 Graphic aGraphic;
259 // paste location: center of window
260 Point aPos = pChartWindow->PixelToLogic( tools::Rectangle( {}, pChartWindow->GetSizePixel()).Center());
262 // handle different formats
263 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pChartWindow ));
264 if( aDataHelper.GetTransferable().is())
266 if ( aDataHelper.HasFormat( SotClipboardFormatId::DRAWING ) )
268 tools::SvRef<SotStorageStream> xStm;
269 if ( aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING, xStm ) )
271 xStm->Seek( 0 );
272 Reference< io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ) );
274 std::unique_ptr< SdrModel > spModel(
275 new SdrModel());
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 tools::SvRef<SotStorageStream> xStm;
287 if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB, xStm ))
288 ReadGraphic( *xStm, aGraphic );
290 else if( aDataHelper.HasFormat( SotClipboardFormatId::GDIMETAFILE ))
292 // meta file
293 GDIMetaFile aMetafile;
294 if( aDataHelper.GetGDIMetaFile( SotClipboardFormatId::GDIMETAFILE, aMetafile ))
295 aGraphic = Graphic( aMetafile );
297 else if( aDataHelper.HasFormat( SotClipboardFormatId::BITMAP ))
299 // bitmap (non-graphic-manager)
300 BitmapEx aBmpEx;
301 if( aDataHelper.GetBitmapEx( SotClipboardFormatId::BITMAP, aBmpEx ))
302 aGraphic = Graphic( aBmpEx );
304 else if( aDataHelper.HasFormat( SotClipboardFormatId::STRING ))
306 OUString aString;
307 if( aDataHelper.GetString( SotClipboardFormatId::STRING, aString ) && m_pDrawModelWrapper )
309 if( m_pDrawViewWrapper )
311 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
312 if( pOutlinerView )//in case of edit mode insert into edited string
313 pOutlinerView->InsertText( aString );
314 else
316 impl_PasteStringAsTextShape( aString, awt::Point( 0, 0 ) );
323 if( aGraphic.GetType() != GraphicType::NONE )
325 Reference< graphic::XGraphic > xGraphic( aGraphic.GetXGraphic());
326 if( xGraphic.is())
327 impl_PasteGraphic( xGraphic, aPos );
332 // note: aPosition is ignored for now. The object is always pasted centered to
333 // the page
334 void ChartController::impl_PasteGraphic(
335 uno::Reference< graphic::XGraphic > const & xGraphic,
336 const ::Point & /* aPosition */ )
338 DBG_TESTSOLARMUTEX();
339 // note: the XPropertySet of the model is the old API. Also the property
340 // "AdditionalShapes" that is used there.
341 uno::Reference< beans::XPropertySet > xModelProp( getModel(), uno::UNO_QUERY );
342 DrawModelWrapper * pDrawModelWrapper( GetDrawModelWrapper());
343 if( ! (xGraphic.is() && xModelProp.is()))
344 return;
345 uno::Reference< lang::XMultiServiceFactory > xFact( pDrawModelWrapper->getShapeFactory());
346 uno::Reference< drawing::XShape > xGraphicShape(
347 xFact->createInstance( "com.sun.star.drawing.GraphicObjectShape" ), uno::UNO_QUERY );
348 uno::Reference< beans::XPropertySet > xGraphicShapeProp( xGraphicShape, uno::UNO_QUERY );
349 if( xGraphicShapeProp.is() && xGraphicShape.is())
351 uno::Reference< drawing::XShapes > xPage = pDrawModelWrapper->getMainDrawPage();
352 if( xPage.is())
354 xPage->add( xGraphicShape );
355 //need to change the model state manually
357 uno::Reference< util::XModifiable > xModifiable( getModel(), uno::UNO_QUERY );
358 if( xModifiable.is() )
359 xModifiable->setModified( true );
361 //select new shape
362 m_aSelection.setSelection( xGraphicShape );
363 m_aSelection.applySelection( m_pDrawViewWrapper.get() );
365 xGraphicShapeProp->setPropertyValue( "Graphic", uno::Any( xGraphic ));
366 uno::Reference< beans::XPropertySet > xGraphicProp( xGraphic, uno::UNO_QUERY );
368 awt::Size aGraphicSize( 1000, 1000 );
369 auto pChartWindow(GetChartWindow());
370 // first try size in 100th mm, then pixel size
371 if( ! ( xGraphicProp->getPropertyValue( "Size100thMM") >>= aGraphicSize ) &&
372 ( ( xGraphicProp->getPropertyValue( "SizePixel") >>= aGraphicSize ) && pChartWindow ))
374 ::Size aVCLSize( pChartWindow->PixelToLogic( Size( aGraphicSize.Width, aGraphicSize.Height )));
375 aGraphicSize.Width = aVCLSize.getWidth();
376 aGraphicSize.Height = aVCLSize.getHeight();
378 xGraphicShape->setSize( aGraphicSize );
379 xGraphicShape->setPosition( awt::Point( 0, 0 ) );
383 void ChartController::impl_PasteShapes( SdrModel* pModel )
385 DrawModelWrapper* pDrawModelWrapper( GetDrawModelWrapper() );
386 if ( pDrawModelWrapper && m_pDrawViewWrapper )
388 Reference< drawing::XDrawPage > xDestPage( pDrawModelWrapper->getMainDrawPage() );
389 SdrPage* pDestPage = GetSdrPageFromXDrawPage( xDestPage );
390 if ( pDestPage )
392 Reference< drawing::XShape > xSelShape;
393 m_pDrawViewWrapper->BegUndo( SvxResId( RID_SVX_3D_UNDO_EXCHANGE_PASTE ) );
394 sal_uInt16 nCount = pModel->GetPageCount();
395 for ( sal_uInt16 i = 0; i < nCount; ++i )
397 const SdrPage* pPage = pModel->GetPage( i );
398 SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
399 while ( aIter.IsMore() )
401 SdrObject* pObj(aIter.Next());
402 // Clone to new SdrModel
403 SdrObject* pNewObj(pObj ? pObj->CloneSdrObject(pDrawModelWrapper->getSdrModel()) : nullptr);
405 if ( pNewObj )
407 // set position
408 Reference< drawing::XShape > xShape( pNewObj->getUnoShape(), uno::UNO_QUERY );
409 if ( xShape.is() )
411 xShape->setPosition( awt::Point( 0, 0 ) );
414 pDestPage->InsertObject( pNewObj );
415 m_pDrawViewWrapper->AddUndo( std::make_unique<SdrUndoInsertObj>( *pNewObj ) );
416 xSelShape = xShape;
421 Reference< util::XModifiable > xModifiable( getModel(), uno::UNO_QUERY );
422 if ( xModifiable.is() )
424 xModifiable->setModified( true );
427 // select last inserted shape
428 m_aSelection.setSelection( xSelShape );
429 m_aSelection.applySelection( m_pDrawViewWrapper.get() );
431 m_pDrawViewWrapper->EndUndo();
433 impl_switchDiagramPositioningToExcludingPositioning();
438 void ChartController::impl_PasteStringAsTextShape( const OUString& rString, const awt::Point& rPosition )
440 DrawModelWrapper* pDrawModelWrapper( GetDrawModelWrapper() );
441 if ( pDrawModelWrapper && m_pDrawViewWrapper )
443 const Reference< lang::XMultiServiceFactory >& xShapeFactory( pDrawModelWrapper->getShapeFactory() );
444 const Reference< drawing::XDrawPage >& xDrawPage( pDrawModelWrapper->getMainDrawPage() );
445 OSL_ASSERT( xShapeFactory.is() && xDrawPage.is() );
447 if ( xShapeFactory.is() && xDrawPage.is() )
451 Reference< drawing::XShape > xTextShape(
452 xShapeFactory->createInstance( "com.sun.star.drawing.TextShape" ), uno::UNO_QUERY_THROW );
453 xDrawPage->add( xTextShape );
455 Reference< text::XTextRange > xRange( xTextShape, uno::UNO_QUERY_THROW );
456 xRange->setString( rString );
458 float fCharHeight = 10.0;
459 Reference< beans::XPropertySet > xProperties( xTextShape, uno::UNO_QUERY_THROW );
460 xProperties->setPropertyValue( "TextAutoGrowHeight", uno::Any( true ) );
461 xProperties->setPropertyValue( "TextAutoGrowWidth", uno::Any( true ) );
462 xProperties->setPropertyValue( "CharHeight", uno::Any( fCharHeight ) );
463 xProperties->setPropertyValue( "CharHeightAsian", uno::Any( fCharHeight ) );
464 xProperties->setPropertyValue( "CharHeightComplex", uno::Any( fCharHeight ) );
465 xProperties->setPropertyValue( "TextVerticalAdjust", uno::Any( drawing::TextVerticalAdjust_CENTER ) );
466 xProperties->setPropertyValue( "TextHorizontalAdjust", uno::Any( drawing::TextHorizontalAdjust_CENTER ) );
467 xProperties->setPropertyValue( "CharFontName", uno::Any( OUString("Albany") ) );
469 xTextShape->setPosition( rPosition );
471 m_aSelection.setSelection( xTextShape );
472 m_aSelection.applySelection( m_pDrawViewWrapper.get() );
474 SdrObject* pObj = DrawViewWrapper::getSdrObject( xTextShape );
475 if ( pObj )
477 m_pDrawViewWrapper->BegUndo( SvxResId( RID_SVX_3D_UNDO_EXCHANGE_PASTE ) );
478 m_pDrawViewWrapper->AddUndo( std::make_unique<SdrUndoInsertObj>( *pObj ) );
479 m_pDrawViewWrapper->EndUndo();
481 impl_switchDiagramPositioningToExcludingPositioning();
484 catch ( const uno::Exception& )
486 DBG_UNHANDLED_EXCEPTION("chart2");
492 void ChartController::executeDispatch_Copy()
494 SolarMutexGuard aSolarGuard;
495 if (!m_pDrawViewWrapper)
496 return;
498 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
499 if (pOutlinerView)
500 pOutlinerView->Copy();
501 else
503 SdrObject* pSelectedObj = nullptr;
504 ObjectIdentifier aSelOID(m_aSelection.getSelectedOID());
506 if (aSelOID.isAutoGeneratedObject())
507 pSelectedObj = m_pDrawModelWrapper->getNamedSdrObject( aSelOID.getObjectCID() );
508 else if (aSelOID.isAdditionalShape())
509 pSelectedObj = DrawViewWrapper::getSdrObject( aSelOID.getAdditionalShape() );
511 if (pSelectedObj)
513 Reference<datatransfer::clipboard::XClipboard> xClipboard(GetChartWindow()->GetClipboard());
514 if (xClipboard.is())
516 Reference< datatransfer::XTransferable > xTransferable(
517 new ChartTransferable(m_pDrawModelWrapper->getSdrModel(),
518 pSelectedObj, aSelOID.isAdditionalShape()));
519 xClipboard->setContents(xTransferable, Reference< datatransfer::clipboard::XClipboardOwner >());
525 void ChartController::executeDispatch_Cut()
527 executeDispatch_Copy();
528 executeDispatch_Delete();
531 bool ChartController::isObjectDeleteable( const uno::Any& rSelection )
533 ObjectIdentifier aSelOID( rSelection );
534 if ( aSelOID.isAutoGeneratedObject() )
536 const OUString& aSelObjCID( aSelOID.getObjectCID() );
537 ObjectType aObjectType(ObjectIdentifier::getObjectType( aSelObjCID ));
539 switch(aObjectType)
541 case OBJECTTYPE_TITLE:
542 case OBJECTTYPE_LEGEND:
543 case OBJECTTYPE_DATA_SERIES:
544 case OBJECTTYPE_LEGEND_ENTRY:
545 case OBJECTTYPE_DATA_CURVE_EQUATION:
546 case OBJECTTYPE_DATA_CURVE:
547 case OBJECTTYPE_DATA_AVERAGE_LINE:
548 case OBJECTTYPE_DATA_ERRORS_X:
549 case OBJECTTYPE_DATA_ERRORS_Y:
550 case OBJECTTYPE_DATA_ERRORS_Z:
551 case OBJECTTYPE_DATA_LABELS:
552 case OBJECTTYPE_DATA_LABEL:
553 case OBJECTTYPE_AXIS:
554 case OBJECTTYPE_GRID:
555 case OBJECTTYPE_SUBGRID:
556 return true;
557 default:
558 break;
561 else if ( aSelOID.isAdditionalShape() )
563 return true;
566 return false;
569 bool ChartController::isSelectedObjectDraggable() const
571 return m_aSelection.isDragableObjectSelected();
574 bool ChartController::isSelectedObjectResizable() const
576 return m_aSelection.isResizeableObjectSelected();
579 bool ChartController::isSelectedObjectRotatable() const
581 const ChartController* pThis = this;
582 const uno::Reference< frame::XModel >& xChartModel = const_cast<ChartController*>(pThis)->getModel();
583 return m_aSelection.isRotateableObjectSelected(xChartModel);
586 bool ChartController::isShapeContext() const
588 return m_aSelection.isAdditionalShapeSelected() ||
589 ( m_pDrawViewWrapper && m_pDrawViewWrapper->AreObjectsMarked() &&
590 ( m_pDrawViewWrapper->GetCurrentObjIdentifier() == OBJ_TEXT ) );
593 void ChartController::impl_ClearSelection()
595 if( m_aSelection.hasSelection())
597 m_aSelection.clearSelection();
598 impl_notifySelectionChangeListeners();
602 bool ChartController::executeDispatch_Delete()
604 bool bReturn = false;
606 // remove the selected object
607 OUString aCID( m_aSelection.getSelectedCID() );
608 if( !aCID.isEmpty() )
610 if( !isObjectDeleteable( uno::Any( aCID ) ) )
611 return false;
613 //remove chart object
614 uno::Reference< chart2::XChartDocument > xChartDoc( getModel(), uno::UNO_QUERY );
615 if( !xChartDoc.is() )
616 return false;
618 ObjectType aObjectType( ObjectIdentifier::getObjectType( aCID ));
619 switch( aObjectType )
621 case OBJECTTYPE_TITLE:
623 UndoGuard aUndoGuard(
624 ActionDescriptionProvider::createDescription(
625 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_TITLE )),
626 m_xUndoManager );
627 TitleHelper::removeTitle(
628 ObjectIdentifier::getTitleTypeForCID( aCID ), getModel() );
629 bReturn = true;
630 aUndoGuard.commit();
631 break;
633 case OBJECTTYPE_LEGEND:
635 uno::Reference< chart2::XDiagram > xDiagram( xChartDoc->getFirstDiagram());
636 if( xDiagram.is())
638 uno::Reference< beans::XPropertySet > xLegendProp( xDiagram->getLegend(), uno::UNO_QUERY );
639 if( xLegendProp.is())
641 UndoGuard aUndoGuard(
642 ActionDescriptionProvider::createDescription(
643 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_LEGEND )),
644 m_xUndoManager );
645 xLegendProp->setPropertyValue( "Show", uno::Any( false ));
646 bReturn = true;
647 aUndoGuard.commit();
650 break;
653 case OBJECTTYPE_DATA_SERIES:
654 bReturn = lcl_deleteDataSeries( aCID, getModel(), m_xUndoManager );
655 break;
657 case OBJECTTYPE_LEGEND_ENTRY:
659 ObjectType eParentObjectType = ObjectIdentifier::getObjectType(
660 ObjectIdentifier::getFullParentParticle( aCID ));
661 if( eParentObjectType == OBJECTTYPE_DATA_SERIES )
663 bReturn = lcl_deleteDataSeries( aCID, getModel(), m_xUndoManager );
665 else if( eParentObjectType == OBJECTTYPE_DATA_CURVE )
667 sal_Int32 nEndPos = aCID.lastIndexOf(':');
668 OUString aParentCID = aCID.copy(0, nEndPos);
670 bReturn = lcl_deleteDataCurve(aParentCID, getModel(), m_xUndoManager );
672 else if( eParentObjectType == OBJECTTYPE_DATA_AVERAGE_LINE )
674 executeDispatch_DeleteMeanValue();
675 bReturn = true;
677 break;
680 case OBJECTTYPE_DATA_AVERAGE_LINE:
682 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
683 ObjectIdentifier::getObjectPropertySet(
684 ObjectIdentifier::getFullParentParticle( aCID ), getModel()), uno::UNO_QUERY );
685 if( xRegCurveCnt.is())
687 UndoGuard aUndoGuard(
688 ActionDescriptionProvider::createDescription(
689 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_AVERAGE_LINE )),
690 m_xUndoManager );
691 RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt );
692 bReturn = true;
693 aUndoGuard.commit();
696 break;
698 case OBJECTTYPE_DATA_CURVE:
700 bReturn = lcl_deleteDataCurve( aCID, getModel(), m_xUndoManager );
702 break;
704 case OBJECTTYPE_DATA_CURVE_EQUATION:
706 uno::Reference< beans::XPropertySet > xEqProp(
707 ObjectIdentifier::getObjectPropertySet( aCID, getModel()));
709 if( xEqProp.is())
711 uno::Reference< frame::XModel > xModel( getModel() );
712 UndoGuard aUndoGuard(
713 ActionDescriptionProvider::createDescription(
714 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE_EQUATION )),
715 m_xUndoManager );
717 ControllerLockGuardUNO aCtlLockGuard( xModel );
718 xEqProp->setPropertyValue( "ShowEquation", uno::Any( false ));
719 xEqProp->setPropertyValue( "XName", uno::Any( OUString("x") ));
720 xEqProp->setPropertyValue( "YName", uno::Any( OUString("f(x)") ));
721 xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( false ));
723 bReturn = true;
724 aUndoGuard.commit();
727 break;
729 case OBJECTTYPE_DATA_ERRORS_X:
730 case OBJECTTYPE_DATA_ERRORS_Y:
731 case OBJECTTYPE_DATA_ERRORS_Z:
733 uno::Reference< beans::XPropertySet > xErrorBarProp(
734 ObjectIdentifier::getObjectPropertySet( aCID, getModel() ));
735 if( xErrorBarProp.is())
737 const char* pId;
739 if ( aObjectType == OBJECTTYPE_DATA_ERRORS_X )
740 pId = STR_OBJECT_ERROR_BARS_X;
741 else if ( aObjectType == OBJECTTYPE_DATA_ERRORS_Y )
742 pId = STR_OBJECT_ERROR_BARS_Y;
743 else
744 pId = STR_OBJECT_ERROR_BARS_Z;
746 uno::Reference< frame::XModel > xModel( getModel() );
747 UndoGuard aUndoGuard(
748 ActionDescriptionProvider::createDescription(
749 ActionDescriptionProvider::ActionType::Delete, SchResId(pId)),
750 m_xUndoManager);
752 ControllerLockGuardUNO aCtlLockGuard( xModel );
753 xErrorBarProp->setPropertyValue(
754 "ErrorBarStyle",
755 uno::Any( css::chart::ErrorBarStyle::NONE ));
757 bReturn = true;
758 aUndoGuard.commit();
760 break;
763 case OBJECTTYPE_DATA_LABELS:
764 case OBJECTTYPE_DATA_LABEL:
766 uno::Reference< beans::XPropertySet > xObjectProperties =
767 ObjectIdentifier::getObjectPropertySet( aCID, getModel() );
768 if( xObjectProperties.is() )
770 UndoGuard aUndoGuard(
771 ActionDescriptionProvider::createDescription(
772 ActionDescriptionProvider::ActionType::Delete,
773 SchResId( aObjectType == OBJECTTYPE_DATA_LABEL ? STR_OBJECT_LABEL : STR_OBJECT_DATALABELS )),
774 m_xUndoManager );
775 chart2::DataPointLabel aLabel;
776 xObjectProperties->getPropertyValue(CHART_UNONAME_LABEL) >>= aLabel;
777 aLabel.ShowNumber = false;
778 aLabel.ShowNumberInPercent = false;
779 aLabel.ShowCategoryName = false;
780 aLabel.ShowLegendSymbol = false;
781 if( aObjectType == OBJECTTYPE_DATA_LABELS )
783 uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( aCID, getModel() ));
784 ::chart::DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, CHART_UNONAME_LABEL, uno::Any(aLabel) );
786 else
787 xObjectProperties->setPropertyValue( CHART_UNONAME_LABEL, uno::Any(aLabel) );
788 bReturn = true;
789 aUndoGuard.commit();
791 break;
793 case OBJECTTYPE_AXIS:
795 executeDispatch_DeleteAxis();
796 bReturn = true;
797 break;
799 case OBJECTTYPE_GRID:
801 executeDispatch_DeleteMajorGrid();
802 bReturn = true;
803 break;
805 case OBJECTTYPE_SUBGRID:
807 executeDispatch_DeleteMinorGrid();
808 bReturn = true;
809 break;
812 default:
814 break;
818 else
820 //remove additional shape
821 impl_ClearSelection();
823 SolarMutexGuard aSolarGuard;
824 if ( m_pDrawViewWrapper )
826 m_pDrawViewWrapper->DeleteMarked();
827 bReturn = true;
831 return bReturn;
834 void ChartController::executeDispatch_ToggleLegend()
836 Reference< frame::XModel > xModel( getModel() );
837 UndoGuard aUndoGuard(
838 SchResId( STR_ACTION_TOGGLE_LEGEND ), m_xUndoManager );
839 ChartModel& rModel = dynamic_cast<ChartModel&>(*xModel);
840 Reference< beans::XPropertySet > xLegendProp( LegendHelper::getLegend(rModel), uno::UNO_QUERY );
841 bool bChanged = false;
842 if( xLegendProp.is())
846 bool bShow = false;
847 if( xLegendProp->getPropertyValue( "Show") >>= bShow )
849 xLegendProp->setPropertyValue( "Show", uno::Any( ! bShow ));
850 bChanged = true;
853 catch( const uno::Exception & )
855 DBG_UNHANDLED_EXCEPTION("chart2");
858 else
860 xLegendProp.set( LegendHelper::getLegend(rModel, m_xCC, true), uno::UNO_QUERY );
861 if( xLegendProp.is())
862 bChanged = true;
865 if( bChanged )
866 aUndoGuard.commit();
869 void ChartController::executeDispatch_ToggleGridHorizontal()
871 UndoGuard aUndoGuard(
872 SchResId( STR_ACTION_TOGGLE_GRID_HORZ ), m_xUndoManager );
873 Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( getModel() ));
874 if( xDiagram.is())
876 sal_Int32 nDimensionIndex = 1;
877 sal_Int32 nCooSysIndex = 0;
879 bool bHasMajorYGrid = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, true, xDiagram );
880 bool bHasMinorYGrid = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, false, xDiagram );
882 if( bHasMajorYGrid )
884 if ( bHasMinorYGrid )
886 AxisHelper::hideGrid( nDimensionIndex, nCooSysIndex, true, xDiagram );
887 AxisHelper::hideGrid( nDimensionIndex, nCooSysIndex, false, xDiagram );
889 else
891 AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, false, xDiagram );
894 else
896 AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, true, xDiagram );
898 aUndoGuard.commit();
902 void ChartController::executeDispatch_ToggleGridVertical()
904 UndoGuard aUndoGuard(
905 SchResId( STR_ACTION_TOGGLE_GRID_VERTICAL ), m_xUndoManager );
906 Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( getModel() ));
907 if( xDiagram.is())
909 sal_Int32 nDimensionIndex = 0;
910 sal_Int32 nCooSysIndex = 0;
912 bool bHasMajorXGrid = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, true, xDiagram );
913 bool bHasMinorXGrid = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, false, xDiagram );
914 if( bHasMajorXGrid )
916 if (bHasMinorXGrid)
918 AxisHelper::hideGrid( nDimensionIndex, nCooSysIndex, true, xDiagram );
919 AxisHelper::hideGrid( nDimensionIndex, nCooSysIndex, false, xDiagram );
921 else
923 AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, false, xDiagram );
926 else
928 AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, true, xDiagram );
931 aUndoGuard.commit();
935 void ChartController::executeDispatch_LOKSetTextSelection(int nType, int nX, int nY)
937 if (m_pDrawViewWrapper)
939 if (m_pDrawViewWrapper->IsTextEdit())
941 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
942 if (pOutlinerView)
944 EditView& rEditView = pOutlinerView->GetEditView();
945 Point aPoint(convertTwipToMm100(nX), convertTwipToMm100(nY));
946 switch (nType)
948 case LOK_SETTEXTSELECTION_START:
949 rEditView.SetCursorLogicPosition(aPoint, /*bPoint=*/false, /*bClearMark=*/false);
950 break;
951 case LOK_SETTEXTSELECTION_END:
952 rEditView.SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/false);
953 break;
954 case LOK_SETTEXTSELECTION_RESET:
955 rEditView.SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/true);
956 break;
957 default:
958 assert(false);
959 break;
966 void ChartController::executeDispatch_LOKPieSegmentDragging( int nOffset )
970 OUString aCID( m_aSelection.getSelectedCID() );
971 const uno::Reference< frame::XModel >& xChartModel = getModel();
972 if( xChartModel.is() )
974 Reference< beans::XPropertySet > xPointProperties(
975 ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
976 if( xPointProperties.is() )
977 xPointProperties->setPropertyValue( "Offset", uno::Any( nOffset / 100.0 ) );
980 catch( const uno::Exception & )
982 TOOLS_WARN_EXCEPTION("chart2", "" );
986 void ChartController::impl_ShapeControllerDispatch( const util::URL& rURL, const Sequence< beans::PropertyValue >& rArgs )
988 Reference< frame::XDispatch > xDispatch( m_aDispatchContainer.getShapeController() );
989 if ( xDispatch.is() )
991 xDispatch->dispatch( rURL, rArgs );
995 void ChartController::impl_switchDiagramPositioningToExcludingPositioning()
997 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription(
998 ActionDescriptionProvider::ActionType::PosSize,
999 ObjectNameProvider::getName( OBJECTTYPE_DIAGRAM)),
1000 m_xUndoManager );
1001 ChartModel& rModel = dynamic_cast<ChartModel&>(*m_aModel->getModel());
1002 if (DiagramHelper::switchDiagramPositioningToExcludingPositioning(rModel, true, true))
1003 aUndoGuard.commit();
1006 } // namespace chart
1008 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */