merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / controller / main / ChartController_Tools.cxx
blob6a96885ac46bc9c0e91a53fa27d589dc2934a22c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChartController_Tools.cxx,v $
10 * $Revision: 1.9.36.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "ChartController.hxx"
35 #include "ChartWindow.hxx"
36 #include "ChartModelHelper.hxx"
37 #include "TitleHelper.hxx"
38 #include "ThreeDHelper.hxx"
39 #include "DataSeriesHelper.hxx"
40 #include "UndoGuard.hxx"
41 #include "ControllerLockGuard.hxx"
42 #include "macros.hxx"
43 #include "ResId.hxx"
44 #include "Strings.hrc"
45 #include "ObjectIdentifier.hxx"
46 #include "ReferenceSizeProvider.hxx"
47 #include "chartview/ExplicitValueProvider.hxx"
48 #include "chartview/DrawModelWrapper.hxx"
49 #include "ChartTransferable.hxx"
50 #include "DrawViewWrapper.hxx"
51 #include "LegendHelper.hxx"
52 #include "AxisHelper.hxx"
53 #include "RegressionCurveHelper.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 <com/sun/star/drawing/XDrawPageSupplier.hpp>
67 #include <svx/ActionDescriptionProvider.hxx>
68 // for TransferableDataHelper/TransferableHelper
69 #include <svtools/transfer.hxx>
70 // for SotStorageStreamRef
71 #include <sot/storage.hxx>
72 // for Graphic
73 #include <vcl/graph.hxx>
74 // for SvxDrawingLayerImport/SvxUnoDrawingModel
75 #include <svx/unomodel.hxx>
76 // for SdrModel
77 #include <svx/svdmodel.hxx>
78 // for OInputStreamWrapper
79 #include <unotools/streamwrap.hxx>
80 // for SolarMutex
81 #include <vcl/svapp.hxx>
82 #include <vos/mutex.hxx>
83 // for OutlinerView
84 #include <svx/outliner.hxx>
86 using namespace ::com::sun::star;
88 using ::com::sun::star::uno::Reference;
89 using ::com::sun::star::uno::Sequence;
90 using ::rtl::OUString;
92 namespace
95 bool lcl_deleteDataSeries(
96 const OUString & rCID,
97 const Reference< frame::XModel > & xModel,
98 const Reference< chart2::XUndoManager > & xUndoManager )
100 bool bResult = false;
101 uno::Reference< chart2::XDataSeries > xSeries( ::chart::ObjectIdentifier::getDataSeriesForCID( rCID, xModel ));
102 uno::Reference< chart2::XChartDocument > xChartDoc( xModel, uno::UNO_QUERY );
103 if( xSeries.is() && xChartDoc.is())
105 uno::Reference< chart2::XChartType > xChartType(
106 ::chart::DataSeriesHelper::getChartTypeOfSeries( xSeries, xChartDoc->getFirstDiagram()));
107 if( xChartType.is())
109 ::chart::UndoGuard aUndoGuard(
110 ActionDescriptionProvider::createDescription(
111 ActionDescriptionProvider::DELETE, ::rtl::OUString( String( ::chart::SchResId( STR_OBJECT_DATASERIES )))),
112 xUndoManager, xModel );
113 ::chart::DataSeriesHelper::deleteSeries( xSeries, xChartType );
114 bResult = true;
115 aUndoGuard.commitAction();
118 return bResult;
121 bool lcl_deleteDataCurve(
122 const OUString & rCID,
123 const Reference< frame::XModel > & xModel,
124 const Reference< chart2::XUndoManager > & xUndoManager )
126 bool bResult = false;
127 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
128 ::chart::ObjectIdentifier::getObjectPropertySet(
129 ::chart::ObjectIdentifier::getSeriesParticleFromCID( rCID ), xModel ), uno::UNO_QUERY );
130 if( xRegCurveCnt.is())
132 ::chart::UndoGuard aUndoGuard(
133 ActionDescriptionProvider::createDescription(
134 ActionDescriptionProvider::DELETE, ::rtl::OUString( String( ::chart::SchResId( STR_OBJECT_CURVE )))),
135 xUndoManager, xModel );
136 ::chart::RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt );
137 bResult = true;
138 aUndoGuard.commitAction();
140 return bResult;
143 // void lcl_CopyPageContentToPage(
144 // const Reference< drawing::XDrawPage > & xSourcePage,
145 // const Reference< drawing::XDrawPage > & xDestPage )
146 // {
147 // try
148 // {
149 // Reference< container::XIndexAccess > xSourceIA( xSourcePage, uno::UNO_QUERY_THROW );
150 // sal_Int32 nCount( xSourceIA->getCount());
151 // for( sal_Int32 i=0; i<nCount; ++i )
152 // {
153 // Reference< drawing::XShape > xShape;
154 // if( xSourceIA->getByIndex( i ) >>= xShape )
155 // xDestPage->add( xShape );
156 // }
157 // }
158 // catch( const uno::Exception & ex )
159 // {
160 // ASSERT_EXCEPTION( ex );
161 // }
162 // }
164 // // copies all shapes on all pages of xSource to the only page of xDestination
165 // void lcl_CopyShapesToChart(
166 // const Reference< frame::XModel > & xSource, const Reference< frame::XModel > & xDestination )
167 // {
168 // try
169 // {
170 // Reference< drawing::XDrawPageSupplier > xDestPGSupp( xDestination, uno::UNO_QUERY_THROW );
171 // Reference< drawing::XDrawPage > xDestPage( xDestPGSupp->getDrawPage());
172 // Reference< drawing::XDrawPagesSupplier > xSourcePGsSupp( xSource, uno::UNO_QUERY_THROW );
173 // Reference< drawing::XDrawPages > xSourcePages( xSourcePGsSupp->getDrawPages());
175 // sal_Int32 nCount( xSourcePages->getCount());
176 // for( sal_Int32 i=0; i<nCount; ++i )
177 // {
178 // Reference< drawing::XDrawPage > xSourcePage( xSourcePages->getByIndex( i ), uno::UNO_QUERY_THROW );
179 // lcl_CopyPageContentToPage( xSourcePage, xDestPage );
180 // }
181 // }
182 // catch( const uno::Exception & ex )
183 // {
184 // ASSERT_EXCEPTION( ex );
185 // }
186 // }
188 } // anonymous namespace
190 namespace
192 void lcl_InsertStringAsTextShapeIntoDrawPage(
193 const Reference< lang::XMultiServiceFactory > & xShapeFactory,
194 const Reference< drawing::XDrawPage > & xDrawPage,
195 OUString & rString,
196 const awt::Point & aPosition )
198 OSL_ASSERT( xShapeFactory.is() && xDrawPage.is());
199 if( ! (xShapeFactory.is() && xDrawPage.is()))
200 return;
204 Reference< drawing::XShape > xTextShape(
205 xShapeFactory->createInstance( C2U("com.sun.star.drawing.TextShape")), uno::UNO_QUERY_THROW );
206 xDrawPage->add( xTextShape );
208 Reference< text::XTextRange > xRange( xTextShape, uno::UNO_QUERY_THROW );
209 xRange->setString( rString );
211 float fCharHeight = 10.0;
212 Reference< beans::XPropertySet > xProperties( xTextShape, uno::UNO_QUERY_THROW );
213 xProperties->setPropertyValue( C2U("TextAutoGrowHeight"), uno::makeAny( true ));
214 xProperties->setPropertyValue( C2U("TextAutoGrowWidth"), uno::makeAny( true ));
215 xProperties->setPropertyValue( C2U("CharHeight"), uno::makeAny( fCharHeight ));
216 xProperties->setPropertyValue( C2U("CharHeightAsian"), uno::makeAny( fCharHeight ));
217 xProperties->setPropertyValue( C2U("CharHeightComplex"), uno::makeAny( fCharHeight ));
218 xProperties->setPropertyValue( C2U("TextVerticalAdjust"), uno::makeAny( drawing::TextVerticalAdjust_CENTER ));
219 xProperties->setPropertyValue( C2U("TextHorizontalAdjust"), uno::makeAny( drawing::TextHorizontalAdjust_CENTER ));
220 xProperties->setPropertyValue( C2U("CharFontName"), uno::makeAny( C2U( "Albany" )));
222 awt::Point aAdaptedPos( aPosition );
223 aAdaptedPos.Y -= (xTextShape->getSize().Height / 2);
224 aAdaptedPos.X -= (xTextShape->getSize().Width / 2);
225 xTextShape->setPosition( aAdaptedPos );
227 catch( const uno::Exception & ex )
229 ASSERT_EXCEPTION( ex );
233 } // anonymous namespace
235 namespace chart
238 ::std::auto_ptr< ReferenceSizeProvider > ChartController::impl_createReferenceSizeProvider() const
240 awt::Size aPageSize( ChartModelHelper::getPageSize( m_aModel->getModel()) );
242 return ::std::auto_ptr< ReferenceSizeProvider >(
243 new ReferenceSizeProvider( aPageSize,
244 Reference< chart2::XChartDocument >( m_aModel->getModel(), uno::UNO_QUERY )));
247 void ChartController::impl_adaptDataSeriesAutoResize()
249 ::std::auto_ptr< ReferenceSizeProvider > apRefSizeProvider(
250 impl_createReferenceSizeProvider());
251 if( apRefSizeProvider.get())
252 apRefSizeProvider->setValuesAtAllDataSeries();
255 void ChartController::executeDispatch_NewArrangement()
257 // remove manual positions at titles, legend and the diagram, remove manual
258 // size at the diagram
262 Reference< frame::XModel > xModel( m_aModel->getModel());
263 Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( xModel ));
264 if( xDiagram.is())
266 // using assignment for broken gcc 3.3
267 UndoGuard aUndoGuard = UndoGuard(
268 ::rtl::OUString( String( SchResId( STR_ACTION_REARRANGE_CHART ))),
269 m_xUndoManager, xModel );
270 ControllerLockGuard aCtlLockGuard( xModel );
272 // diagram
273 Reference< beans::XPropertyState > xState( xDiagram, uno::UNO_QUERY_THROW );
274 xState->setPropertyToDefault( C2U("RelativeSize"));
275 xState->setPropertyToDefault( C2U("RelativePosition"));
277 // 3d rotation
278 ThreeDHelper::set3DSettingsToDefault( uno::Reference< beans::XPropertySet >( xDiagram, uno::UNO_QUERY ) );
280 // legend
281 Reference< beans::XPropertyState > xLegendState( xDiagram->getLegend(), uno::UNO_QUERY );
282 if( xLegendState.is())
283 xLegendState->setPropertyToDefault( C2U("RelativePosition"));
285 // titles
286 for( sal_Int32 eType = TitleHelper::TITLE_BEGIN;
287 eType < TitleHelper::NORMAL_TITLE_END;
288 ++eType )
290 Reference< beans::XPropertyState > xTitleState(
291 TitleHelper::getTitle(
292 static_cast< TitleHelper::eTitleType >( eType ), xModel ), uno::UNO_QUERY );
293 if( xTitleState.is())
294 xTitleState->setPropertyToDefault( C2U("RelativePosition"));
297 // regression curve equations
298 ::std::vector< Reference< chart2::XRegressionCurve > > aRegressionCurves(
299 RegressionCurveHelper::getAllRegressionCurvesNotMeanValueLine( xDiagram ));
300 ::std::for_each( aRegressionCurves.begin(), aRegressionCurves.end(),
301 RegressionCurveHelper::resetEquationPosition );
303 aUndoGuard.commitAction();
306 catch( uno::RuntimeException & ex )
308 ASSERT_EXCEPTION( ex );
312 void ChartController::executeDispatch_ScaleText()
314 ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
315 // using assignment for broken gcc 3.3
316 UndoGuard aUndoGuard = UndoGuard(
317 ::rtl::OUString( String( SchResId( STR_ACTION_SCALE_TEXT ))),
318 m_xUndoManager, m_aModel->getModel());
319 ControllerLockGuard aCtlLockGuard( m_aModel->getModel());
320 ::std::auto_ptr< ReferenceSizeProvider > apRefSizeProv( impl_createReferenceSizeProvider());
321 OSL_ASSERT( apRefSizeProv.get());
322 if( apRefSizeProv.get())
323 apRefSizeProv->toggleAutoResizeState();
324 aUndoGuard.commitAction();
327 void ChartController::executeDispatch_Paste()
329 if( m_pChartWindow )
331 Graphic aGraphic;
332 // paste location: center of window
333 Point aPos;
334 aPos = m_pChartWindow->PixelToLogic( Rectangle( aPos, m_pChartWindow->GetSizePixel()).Center());
336 // handle different formats
337 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( m_pChartWindow ));
338 if( aDataHelper.GetTransferable().is())
340 // if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ))
341 // {
342 // SotStorageStreamRef xStm;
343 // if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xStm ))
344 // {
345 // xStm->Seek( 0 );
346 // uno::Reference< io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ));
347 // SdrModel * pModel = new SdrModel();
348 // DrawModelWrapper * pDrawModelWrapper( this->GetDrawModelWrapper());
349 // if( SvxDrawingLayerImport( pModel, xInputStream ))
350 // lcl_CopyShapesToChart( *pModel, m_pDrawModelWrapper->getSdrModel());
351 // delete pModel;
352 // }
353 // }
354 // else
355 if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ))
357 // graphic exchange format (graphic manager bitmap format?)
358 SotStorageStreamRef xStm;
359 if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_SVXB, xStm ))
360 (*xStm) >> aGraphic;
362 else if( aDataHelper.HasFormat( FORMAT_GDIMETAFILE ))
364 // meta file
365 GDIMetaFile aMetafile;
366 if( aDataHelper.GetGDIMetaFile( FORMAT_GDIMETAFILE, aMetafile ))
367 aGraphic = Graphic( aMetafile );
369 else if( aDataHelper.HasFormat( FORMAT_BITMAP ))
371 // bitmap (non-graphic-manager)
372 Bitmap aBmp;
373 if( aDataHelper.GetBitmap( FORMAT_BITMAP, aBmp ))
374 aGraphic = Graphic( aBmp );
376 else if( aDataHelper.HasFormat( FORMAT_STRING ))
378 OUString aString;
379 if( aDataHelper.GetString( FORMAT_STRING, aString ) && m_pDrawModelWrapper )
381 if( m_pDrawViewWrapper )
383 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
384 if( pOutlinerView )//in case of edit mode insert into edited string
385 pOutlinerView->InsertText( aString );
386 else
388 awt::Point aTextPos;
389 awt::Size aPageSize( ChartModelHelper::getPageSize( m_aModel->getModel()));
390 aTextPos.X = (aPageSize.Width / 2);
391 aTextPos.Y = (aPageSize.Height / 2);
392 lcl_InsertStringAsTextShapeIntoDrawPage(
393 m_pDrawModelWrapper->getShapeFactory(),
394 m_pDrawModelWrapper->getMainDrawPage(),
395 aString, aTextPos );
402 if( aGraphic.GetType() != GRAPHIC_NONE )
404 Reference< graphic::XGraphic > xGraphic( aGraphic.GetXGraphic());
405 if( xGraphic.is())
406 impl_PasteGraphic( xGraphic, aPos );
411 // note: aPosition is ignored for now. The object is always pasted centered to
412 // the page
413 void ChartController::impl_PasteGraphic(
414 uno::Reference< graphic::XGraphic > & xGraphic,
415 const ::Point & /* aPosition */ )
417 // note: the XPropertySet of the model is the old API. Also the property
418 // "AdditionalShapes" that is used there.
419 uno::Reference< beans::XPropertySet > xModelProp( m_aModel->getModel(), uno::UNO_QUERY );
420 DrawModelWrapper * pDrawModelWrapper( this->GetDrawModelWrapper());
421 if( ! (xGraphic.is() && xModelProp.is()))
422 return;
423 uno::Reference< lang::XMultiServiceFactory > xFact( pDrawModelWrapper->getShapeFactory());
424 uno::Reference< drawing::XShape > xGraphicShape(
425 xFact->createInstance( C2U( "com.sun.star.drawing.GraphicObjectShape" )), uno::UNO_QUERY );
426 uno::Reference< beans::XPropertySet > xGraphicShapeProp( xGraphicShape, uno::UNO_QUERY );
427 if( xGraphicShapeProp.is() && xGraphicShape.is())
429 uno::Reference< drawing::XShapes > xPage( pDrawModelWrapper->getMainDrawPage(), uno::UNO_QUERY );
430 if( xPage.is())
432 xPage->add( xGraphicShape );
433 //need to change the model state manually
435 uno::Reference< util::XModifiable > xModifiable( m_aModel->getModel(), uno::UNO_QUERY );
436 if( xModifiable.is() )
437 xModifiable->setModified( true );
439 //select new shape
440 m_aSelection.setSelection( xGraphicShape );
441 m_aSelection.applySelection( m_pDrawViewWrapper );
443 xGraphicShapeProp->setPropertyValue( C2U("Graphic"), uno::makeAny( xGraphic ));
444 uno::Reference< beans::XPropertySet > xGraphicProp( xGraphic, uno::UNO_QUERY );
446 awt::Size aGraphicSize( 1000, 1000 );
447 awt::Point aShapePos( 100,100 );
448 // first try size in 100th mm, then pixel size
449 if( ! ( xGraphicProp->getPropertyValue( C2U("Size100thMM")) >>= aGraphicSize ) &&
450 ( ( xGraphicProp->getPropertyValue( C2U("SizePixel")) >>= aGraphicSize ) && m_pChartWindow ))
452 ::Size aVCLSize( m_pChartWindow->PixelToLogic( Size( aGraphicSize.Width, aGraphicSize.Height )));
453 aGraphicSize.Width = aVCLSize.getWidth();
454 aGraphicSize.Height = aVCLSize.getHeight();
456 xGraphicShape->setSize( aGraphicSize );
458 awt::Size aPageSize( ChartModelHelper::getPageSize( m_aModel->getModel()));
459 aShapePos.X = (aPageSize.Width / 2) - (aGraphicSize.Width / 2);
460 aShapePos.Y = (aPageSize.Height / 2) - (aGraphicSize.Height / 2);
461 xGraphicShape->setPosition( aShapePos );
465 void ChartController::executeDispatch_Copy()
468 Reference< datatransfer::XTransferable > xTransferable;
471 ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
472 SdrObject * pSelectedObj = 0;
473 if( m_pDrawViewWrapper && m_pDrawModelWrapper )
475 if( m_aSelection.getSelectedCID().getLength() )
476 pSelectedObj = m_pDrawModelWrapper->getNamedSdrObject( m_aSelection.getSelectedCID() );
477 else
478 pSelectedObj = DrawViewWrapper::getSdrObject( m_aSelection.getSelectedAdditionalShape() );
480 if( pSelectedObj )
482 xTransferable = Reference< datatransfer::XTransferable >( new ChartTransferable(
483 & m_pDrawModelWrapper->getSdrModel(), pSelectedObj ));
487 if( xTransferable.is() )
489 Reference< datatransfer::clipboard::XClipboard > xClipboard( TransferableHelper::GetSystemClipboard());
490 if( xClipboard.is())
491 xClipboard->setContents( xTransferable, Reference< datatransfer::clipboard::XClipboardOwner >() );
495 void ChartController::executeDispatch_Cut()
497 executeDispatch_Copy();
498 executeDispatch_Delete();
501 //static
502 bool ChartController::isObjectDeleteable( const uno::Any& rSelection )
504 OUString aSelObjCID;
505 if( (rSelection >>= aSelObjCID) && aSelObjCID.getLength() > 0 )
507 ObjectType aObjectType(ObjectIdentifier::getObjectType( aSelObjCID ));
508 if( (OBJECTTYPE_TITLE == aObjectType) || (OBJECTTYPE_LEGEND == aObjectType)
509 || (OBJECTTYPE_DATA_SERIES == aObjectType) )
510 return true;
511 if( (OBJECTTYPE_DATA_SERIES == aObjectType) || (OBJECTTYPE_LEGEND_ENTRY == aObjectType) )
512 return true;
513 if( (OBJECTTYPE_DATA_CURVE_EQUATION == aObjectType) || (OBJECTTYPE_DATA_CURVE == aObjectType) ||
514 (OBJECTTYPE_DATA_AVERAGE_LINE == aObjectType) || (OBJECTTYPE_DATA_ERRORS == aObjectType))
515 return true;
516 if( (OBJECTTYPE_DATA_LABELS == aObjectType) || (OBJECTTYPE_DATA_LABEL == aObjectType) )
517 return true;
520 return false;
523 void ChartController::impl_ClearSelection()
525 if( m_aSelection.hasSelection())
527 m_aSelection.clearSelection();
528 impl_notifySelectionChangeListeners();
532 bool ChartController::executeDispatch_Delete()
534 bool bReturn = false;
536 // remove the selected object
538 rtl::OUString aCID( m_aSelection.getSelectedCID() );
539 if( aCID.getLength() )
541 if( !isObjectDeleteable( uno::Any( aCID ) ) )
542 return false;
544 //remove chart object
545 impl_ClearSelection();
547 uno::Reference< chart2::XChartDocument > xChartDoc( m_aModel->getModel(), uno::UNO_QUERY );
548 if( !xChartDoc.is() )
549 return false;
551 ObjectType aObjectType( ObjectIdentifier::getObjectType( aCID ));
552 switch( aObjectType )
554 case OBJECTTYPE_TITLE:
556 // using assignment for broken gcc 3.3
557 UndoGuard aUndoGuard = UndoGuard(
558 ActionDescriptionProvider::createDescription(
559 ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_TITLE )))),
560 m_xUndoManager, m_aModel->getModel() );
561 TitleHelper::removeTitle(
562 ObjectIdentifier::getTitleTypeForCID( aCID ), m_aModel->getModel());
563 bReturn = true;
564 aUndoGuard.commitAction();
565 break;
567 case OBJECTTYPE_LEGEND:
569 uno::Reference< chart2::XDiagram > xDiagram( xChartDoc->getFirstDiagram());
570 if( xDiagram.is())
572 uno::Reference< beans::XPropertySet > xLegendProp( xDiagram->getLegend(), uno::UNO_QUERY );
573 if( xLegendProp.is())
575 // using assignment for broken gcc 3.3
576 UndoGuard aUndoGuard = UndoGuard(
577 ActionDescriptionProvider::createDescription(
578 ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_LEGEND )))),
579 m_xUndoManager, m_aModel->getModel() );
580 xLegendProp->setPropertyValue( C2U("Show"), uno::makeAny( false ));
581 bReturn = true;
582 aUndoGuard.commitAction();
585 break;
588 case OBJECTTYPE_DATA_SERIES:
589 bReturn = lcl_deleteDataSeries( aCID, m_aModel->getModel(), m_xUndoManager );
590 break;
592 case OBJECTTYPE_LEGEND_ENTRY:
594 ObjectType eParentObjectType = ObjectIdentifier::getObjectType(
595 ObjectIdentifier::getFullParentParticle( aCID ));
596 if( eParentObjectType == OBJECTTYPE_DATA_SERIES )
597 bReturn = lcl_deleteDataSeries( aCID, m_aModel->getModel(), m_xUndoManager );
598 else if( eParentObjectType == OBJECTTYPE_DATA_CURVE )
599 bReturn = lcl_deleteDataCurve( aCID, m_aModel->getModel(), m_xUndoManager );
600 break;
603 case OBJECTTYPE_DATA_AVERAGE_LINE:
605 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
606 ObjectIdentifier::getObjectPropertySet(
607 ObjectIdentifier::getFullParentParticle( aCID ), m_aModel->getModel()), uno::UNO_QUERY );
608 if( xRegCurveCnt.is())
610 // using assignment for broken gcc 3.3
611 UndoGuard aUndoGuard = UndoGuard(
612 ActionDescriptionProvider::createDescription(
613 ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_AVERAGE_LINE )))),
614 m_xUndoManager, m_aModel->getModel() );
615 RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt );
616 bReturn = true;
617 aUndoGuard.commitAction();
619 break;
622 case OBJECTTYPE_DATA_CURVE:
623 bReturn = lcl_deleteDataCurve( aCID, m_aModel->getModel(), m_xUndoManager );
624 break;
626 case OBJECTTYPE_DATA_CURVE_EQUATION:
628 uno::Reference< beans::XPropertySet > xEqProp(
629 ObjectIdentifier::getObjectPropertySet( aCID, m_aModel->getModel()));
630 if( xEqProp.is())
632 uno::Reference< frame::XModel > xModel( m_aModel->getModel());
633 // using assignment for broken gcc 3.3
634 UndoGuard aUndoGuard = UndoGuard(
635 ActionDescriptionProvider::createDescription(
636 ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE_EQUATION )))),
637 m_xUndoManager, xModel );
639 ControllerLockGuard aCtlLockGuard( xModel );
640 xEqProp->setPropertyValue( C2U("ShowEquation"), uno::makeAny( false ));
641 xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( false ));
643 bReturn = true;
644 aUndoGuard.commitAction();
646 break;
649 case OBJECTTYPE_DATA_ERRORS:
651 uno::Reference< beans::XPropertySet > xErrorBarProp(
652 ObjectIdentifier::getObjectPropertySet( aCID, m_aModel->getModel()));
653 if( xErrorBarProp.is())
655 uno::Reference< frame::XModel > xModel( m_aModel->getModel());
656 // using assignment for broken gcc 3.3
657 UndoGuard aUndoGuard = UndoGuard(
658 ActionDescriptionProvider::createDescription(
659 ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_ERROR_BARS )))),
660 m_xUndoManager, xModel );
662 ControllerLockGuard aCtlLockGuard( xModel );
663 xErrorBarProp->setPropertyValue(
664 C2U("ErrorBarStyle"),
665 uno::makeAny( ::com::sun::star::chart::ErrorBarStyle::NONE ));
667 bReturn = true;
668 aUndoGuard.commitAction();
670 break;
673 case OBJECTTYPE_DATA_LABELS:
674 case OBJECTTYPE_DATA_LABEL:
676 uno::Reference< beans::XPropertySet > xObjectProperties =
677 ObjectIdentifier::getObjectPropertySet( aCID, m_aModel->getModel() );
678 if( xObjectProperties.is() )
680 UndoGuard aUndoGuard = UndoGuard(
681 ActionDescriptionProvider::createDescription(
682 ActionDescriptionProvider::DELETE, ::rtl::OUString( String(
683 SchResId( aObjectType == OBJECTTYPE_DATA_LABEL ? STR_OBJECT_LABEL : STR_OBJECT_DATALABELS )))),
684 m_xUndoManager, m_aModel->getModel() );
685 chart2::DataPointLabel aLabel;
686 xObjectProperties->getPropertyValue( C2U( "Label" ) ) >>= aLabel;
687 aLabel.ShowNumber = false;
688 aLabel.ShowNumberInPercent = false;
689 aLabel.ShowCategoryName = false;
690 aLabel.ShowLegendSymbol = false;
691 if( aObjectType == OBJECTTYPE_DATA_LABELS )
693 uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( aCID, m_aModel->getModel() ));
694 ::chart::DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "Label" ), uno::makeAny(aLabel) );
696 else
697 xObjectProperties->setPropertyValue( C2U( "Label" ), uno::makeAny(aLabel) );
698 bReturn = true;
699 aUndoGuard.commitAction();
701 break;
704 default:
706 break;
710 else
712 //remove additional shape
713 uno::Reference< drawing::XShape > xShape( m_aSelection.getSelectedAdditionalShape() );
714 if( xShape.is() )
716 impl_ClearSelection();
718 ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
719 if( m_pDrawViewWrapper )
720 m_pDrawViewWrapper->UnmarkAll();
722 bReturn = DrawModelWrapper::removeShape( xShape );
725 return bReturn;
728 void ChartController::executeDispatch_ToggleLegend()
730 Reference< frame::XModel > xModel( m_aModel->getModel());
731 UndoGuard aUndoGuard = UndoGuard(
732 ::rtl::OUString( String( SchResId( STR_ACTION_TOGGLE_LEGEND ))), m_xUndoManager, xModel );
733 Reference< beans::XPropertySet > xLegendProp( LegendHelper::getLegend( xModel ), uno::UNO_QUERY );
734 bool bChanged = false;
735 if( xLegendProp.is())
739 bool bShow = false;
740 if( xLegendProp->getPropertyValue( C2U("Show")) >>= bShow )
742 xLegendProp->setPropertyValue( C2U("Show"), uno::makeAny( ! bShow ));
743 bChanged = true;
746 catch( const uno::Exception & ex )
748 ASSERT_EXCEPTION( ex );
751 else
753 xLegendProp.set( LegendHelper::getLegend( xModel, m_xCC, true ), uno::UNO_QUERY );
754 if( xLegendProp.is())
755 bChanged = true;
758 if( bChanged )
759 aUndoGuard.commitAction();
762 void ChartController::executeDispatch_ToggleGridHorizontal()
764 Reference< frame::XModel > xModel( m_aModel->getModel());
765 UndoGuard aUndoGuard = UndoGuard(
766 ::rtl::OUString( String( SchResId( STR_ACTION_TOGGLE_GRID_HORZ ))), m_xUndoManager, xModel );
767 Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( m_aModel->getModel()));
768 if( xDiagram.is())
770 sal_Int32 nDimensionIndex = 1;
771 sal_Int32 nCooSysIndex = 0;
772 bool bIsMainGrid = true;
774 bool bHasMainYGrid = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, bIsMainGrid, xDiagram );
776 if( bHasMainYGrid )
777 AxisHelper::hideGrid( nDimensionIndex, nCooSysIndex, bIsMainGrid, xDiagram );
778 else
779 AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, bIsMainGrid, xDiagram, m_xCC );
781 aUndoGuard.commitAction();
785 } // namespace chart