xref: /AOO41X/main/chart2/source/controller/main/ChartController_Tools.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_chart2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "ChartController.hxx"
32*cdf0e10cSrcweir #include "ChartWindow.hxx"
33*cdf0e10cSrcweir #include "ChartModelHelper.hxx"
34*cdf0e10cSrcweir #include "TitleHelper.hxx"
35*cdf0e10cSrcweir #include "ThreeDHelper.hxx"
36*cdf0e10cSrcweir #include "DataSeriesHelper.hxx"
37*cdf0e10cSrcweir #include "UndoGuard.hxx"
38*cdf0e10cSrcweir #include "ControllerLockGuard.hxx"
39*cdf0e10cSrcweir #include "macros.hxx"
40*cdf0e10cSrcweir #include "ResId.hxx"
41*cdf0e10cSrcweir #include "Strings.hrc"
42*cdf0e10cSrcweir #include "ObjectIdentifier.hxx"
43*cdf0e10cSrcweir #include "ReferenceSizeProvider.hxx"
44*cdf0e10cSrcweir #include "chartview/ExplicitValueProvider.hxx"
45*cdf0e10cSrcweir #include "chartview/DrawModelWrapper.hxx"
46*cdf0e10cSrcweir #include "ChartTransferable.hxx"
47*cdf0e10cSrcweir #include "DrawViewWrapper.hxx"
48*cdf0e10cSrcweir #include "LegendHelper.hxx"
49*cdf0e10cSrcweir #include "AxisHelper.hxx"
50*cdf0e10cSrcweir #include "RegressionCurveHelper.hxx"
51*cdf0e10cSrcweir #include "ShapeController.hxx"
52*cdf0e10cSrcweir #include "DiagramHelper.hxx"
53*cdf0e10cSrcweir #include "ObjectNameProvider.hxx"
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir #include <com/sun/star/chart2/DataPointLabel.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyState.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/drawing/CameraGeometry.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphic.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/text/XTextRange.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
63*cdf0e10cSrcweir #include <com/sun/star/chart/ErrorBarStyle.hpp>
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir #include <svx/ActionDescriptionProvider.hxx>
66*cdf0e10cSrcweir // for TransferableDataHelper/TransferableHelper
67*cdf0e10cSrcweir #include <svtools/transfer.hxx>
68*cdf0e10cSrcweir // for SotStorageStreamRef
69*cdf0e10cSrcweir #include <sot/storage.hxx>
70*cdf0e10cSrcweir // for Graphic
71*cdf0e10cSrcweir #include <vcl/graph.hxx>
72*cdf0e10cSrcweir // for SvxDrawingLayerImport/SvxUnoDrawingModel
73*cdf0e10cSrcweir #include <svx/unomodel.hxx>
74*cdf0e10cSrcweir // for SdrModel
75*cdf0e10cSrcweir #include <svx/svdmodel.hxx>
76*cdf0e10cSrcweir // for OInputStreamWrapper
77*cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
78*cdf0e10cSrcweir // for SolarMutex
79*cdf0e10cSrcweir #include <vcl/svapp.hxx>
80*cdf0e10cSrcweir #include <vos/mutex.hxx>
81*cdf0e10cSrcweir #include <svx/dialmgr.hxx>
82*cdf0e10cSrcweir #include <svx/dialogs.hrc>
83*cdf0e10cSrcweir // for OutlinerView
84*cdf0e10cSrcweir #include <editeng/outliner.hxx>
85*cdf0e10cSrcweir #include <svx/svditer.hxx>
86*cdf0e10cSrcweir #include <svx/svdpage.hxx>
87*cdf0e10cSrcweir #include <svx/svdundo.hxx>
88*cdf0e10cSrcweir #include <svx/unoapi.hxx>
89*cdf0e10cSrcweir #include <svx/unopage.hxx>
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir #include <boost/scoped_ptr.hpp>
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir using namespace ::com::sun::star;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
96*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
97*cdf0e10cSrcweir using ::rtl::OUString;
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir namespace
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir bool lcl_deleteDataSeries(
103*cdf0e10cSrcweir     const OUString & rCID,
104*cdf0e10cSrcweir     const Reference< frame::XModel > & xModel,
105*cdf0e10cSrcweir     const Reference< document::XUndoManager > & xUndoManager )
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir     bool bResult = false;
108*cdf0e10cSrcweir     uno::Reference< chart2::XDataSeries > xSeries( ::chart::ObjectIdentifier::getDataSeriesForCID( rCID, xModel ));
109*cdf0e10cSrcweir     uno::Reference< chart2::XChartDocument > xChartDoc( xModel, uno::UNO_QUERY );
110*cdf0e10cSrcweir     if( xSeries.is() && xChartDoc.is())
111*cdf0e10cSrcweir     {
112*cdf0e10cSrcweir         uno::Reference< chart2::XChartType > xChartType(
113*cdf0e10cSrcweir             ::chart::DataSeriesHelper::getChartTypeOfSeries( xSeries, xChartDoc->getFirstDiagram()));
114*cdf0e10cSrcweir         if( xChartType.is())
115*cdf0e10cSrcweir         {
116*cdf0e10cSrcweir             ::chart::UndoGuard aUndoGuard(
117*cdf0e10cSrcweir                 ActionDescriptionProvider::createDescription(
118*cdf0e10cSrcweir                     ActionDescriptionProvider::DELETE, String( ::chart::SchResId( STR_OBJECT_DATASERIES ))),
119*cdf0e10cSrcweir                 xUndoManager );
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir             Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( xModel ) );
122*cdf0e10cSrcweir             uno::Reference< chart2::XAxis > xAxis( ::chart::DiagramHelper::getAttachedAxis( xSeries, xDiagram ) );
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir             ::chart::DataSeriesHelper::deleteSeries( xSeries, xChartType );
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir             ::chart::AxisHelper::hideAxisIfNoDataIsAttached( xAxis, xDiagram );
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir             bResult = true;
129*cdf0e10cSrcweir             aUndoGuard.commit();
130*cdf0e10cSrcweir         }
131*cdf0e10cSrcweir     }
132*cdf0e10cSrcweir     return bResult;
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir bool lcl_deleteDataCurve(
136*cdf0e10cSrcweir     const OUString & rCID,
137*cdf0e10cSrcweir     const Reference< frame::XModel > & xModel,
138*cdf0e10cSrcweir     const Reference< document::XUndoManager > & xUndoManager )
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir     bool bResult = false;
141*cdf0e10cSrcweir     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
142*cdf0e10cSrcweir         ::chart::ObjectIdentifier::getObjectPropertySet(
143*cdf0e10cSrcweir             ::chart::ObjectIdentifier::getSeriesParticleFromCID( rCID ), xModel ), uno::UNO_QUERY );
144*cdf0e10cSrcweir     if( xRegCurveCnt.is())
145*cdf0e10cSrcweir     {
146*cdf0e10cSrcweir         ::chart::UndoGuard aUndoGuard(
147*cdf0e10cSrcweir             ActionDescriptionProvider::createDescription(
148*cdf0e10cSrcweir                 ActionDescriptionProvider::DELETE, String( ::chart::SchResId( STR_OBJECT_CURVE ))),
149*cdf0e10cSrcweir             xUndoManager );
150*cdf0e10cSrcweir         ::chart::RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt );
151*cdf0e10cSrcweir         bResult = true;
152*cdf0e10cSrcweir         aUndoGuard.commit();
153*cdf0e10cSrcweir     }
154*cdf0e10cSrcweir     return bResult;
155*cdf0e10cSrcweir }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir // void lcl_CopyPageContentToPage(
158*cdf0e10cSrcweir //     const Reference< drawing::XDrawPage > & xSourcePage,
159*cdf0e10cSrcweir //     const Reference< drawing::XDrawPage > & xDestPage )
160*cdf0e10cSrcweir // {
161*cdf0e10cSrcweir //     try
162*cdf0e10cSrcweir //     {
163*cdf0e10cSrcweir //         Reference< container::XIndexAccess > xSourceIA( xSourcePage, uno::UNO_QUERY_THROW );
164*cdf0e10cSrcweir //         sal_Int32 nCount( xSourceIA->getCount());
165*cdf0e10cSrcweir //         for( sal_Int32 i=0; i<nCount; ++i )
166*cdf0e10cSrcweir //         {
167*cdf0e10cSrcweir //             Reference< drawing::XShape > xShape;
168*cdf0e10cSrcweir //             if( xSourceIA->getByIndex( i ) >>= xShape )
169*cdf0e10cSrcweir //                 xDestPage->add( xShape );
170*cdf0e10cSrcweir //         }
171*cdf0e10cSrcweir //     }
172*cdf0e10cSrcweir //     catch( const uno::Exception & ex )
173*cdf0e10cSrcweir //     {
174*cdf0e10cSrcweir //         ASSERT_EXCEPTION( ex );
175*cdf0e10cSrcweir //     }
176*cdf0e10cSrcweir // }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir // // copies all shapes on all pages of xSource to the only page of xDestination
179*cdf0e10cSrcweir // void lcl_CopyShapesToChart(
180*cdf0e10cSrcweir //     const Reference< frame::XModel > & xSource, const Reference< frame::XModel > & xDestination )
181*cdf0e10cSrcweir // {
182*cdf0e10cSrcweir //     try
183*cdf0e10cSrcweir //     {
184*cdf0e10cSrcweir //         Reference< drawing::XDrawPageSupplier > xDestPGSupp( xDestination, uno::UNO_QUERY_THROW );
185*cdf0e10cSrcweir //         Reference< drawing::XDrawPage > xDestPage( xDestPGSupp->getDrawPage());
186*cdf0e10cSrcweir //         Reference< drawing::XDrawPagesSupplier > xSourcePGsSupp( xSource, uno::UNO_QUERY_THROW );
187*cdf0e10cSrcweir //         Reference< drawing::XDrawPages > xSourcePages( xSourcePGsSupp->getDrawPages());
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir //         sal_Int32 nCount( xSourcePages->getCount());
190*cdf0e10cSrcweir //         for( sal_Int32 i=0; i<nCount; ++i )
191*cdf0e10cSrcweir //         {
192*cdf0e10cSrcweir //             Reference< drawing::XDrawPage > xSourcePage( xSourcePages->getByIndex( i ), uno::UNO_QUERY_THROW );
193*cdf0e10cSrcweir //             lcl_CopyPageContentToPage( xSourcePage, xDestPage );
194*cdf0e10cSrcweir //         }
195*cdf0e10cSrcweir //     }
196*cdf0e10cSrcweir //     catch( const uno::Exception & ex )
197*cdf0e10cSrcweir //     {
198*cdf0e10cSrcweir //         ASSERT_EXCEPTION( ex );
199*cdf0e10cSrcweir //     }
200*cdf0e10cSrcweir // }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir } // anonymous namespace
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir namespace chart
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir ::std::auto_ptr< ReferenceSizeProvider > ChartController::impl_createReferenceSizeProvider()
209*cdf0e10cSrcweir {
210*cdf0e10cSrcweir     awt::Size aPageSize( ChartModelHelper::getPageSize( getModel() ) );
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir     return ::std::auto_ptr< ReferenceSizeProvider >(
213*cdf0e10cSrcweir         new ReferenceSizeProvider( aPageSize,
214*cdf0e10cSrcweir             Reference< chart2::XChartDocument >( getModel(), uno::UNO_QUERY )));
215*cdf0e10cSrcweir }
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir void ChartController::impl_adaptDataSeriesAutoResize()
218*cdf0e10cSrcweir {
219*cdf0e10cSrcweir     ::std::auto_ptr< ReferenceSizeProvider > apRefSizeProvider(
220*cdf0e10cSrcweir         impl_createReferenceSizeProvider());
221*cdf0e10cSrcweir     if( apRefSizeProvider.get())
222*cdf0e10cSrcweir         apRefSizeProvider->setValuesAtAllDataSeries();
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir void ChartController::executeDispatch_NewArrangement()
226*cdf0e10cSrcweir {
227*cdf0e10cSrcweir     // remove manual positions at titles, legend and the diagram, remove manual
228*cdf0e10cSrcweir     // size at the diagram
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir     try
231*cdf0e10cSrcweir     {
232*cdf0e10cSrcweir         Reference< frame::XModel > xModel( getModel() );
233*cdf0e10cSrcweir         Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( xModel ));
234*cdf0e10cSrcweir         if( xDiagram.is())
235*cdf0e10cSrcweir         {
236*cdf0e10cSrcweir             // using assignment for broken gcc 3.3
237*cdf0e10cSrcweir             UndoGuard aUndoGuard = UndoGuard(
238*cdf0e10cSrcweir                 String( SchResId( STR_ACTION_REARRANGE_CHART )),
239*cdf0e10cSrcweir                 m_xUndoManager );
240*cdf0e10cSrcweir             ControllerLockGuard aCtlLockGuard( xModel );
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir             // diagram
243*cdf0e10cSrcweir             Reference< beans::XPropertyState > xState( xDiagram, uno::UNO_QUERY_THROW );
244*cdf0e10cSrcweir             xState->setPropertyToDefault( C2U("RelativeSize"));
245*cdf0e10cSrcweir             xState->setPropertyToDefault( C2U("RelativePosition"));
246*cdf0e10cSrcweir             xState->setPropertyToDefault( C2U("PosSizeExcludeAxes"));
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir             // 3d rotation
249*cdf0e10cSrcweir             ThreeDHelper::set3DSettingsToDefault( uno::Reference< beans::XPropertySet >( xDiagram, uno::UNO_QUERY ) );
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir             // legend
252*cdf0e10cSrcweir             Reference< beans::XPropertyState > xLegendState( xDiagram->getLegend(), uno::UNO_QUERY );
253*cdf0e10cSrcweir             if( xLegendState.is())
254*cdf0e10cSrcweir             {
255*cdf0e10cSrcweir                 xLegendState->setPropertyToDefault( C2U("RelativePosition"));
256*cdf0e10cSrcweir                 xLegendState->setPropertyToDefault( C2U("RelativeSize"));
257*cdf0e10cSrcweir                 xLegendState->setPropertyToDefault( C2U("AnchorPosition"));
258*cdf0e10cSrcweir             }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir             // titles
261*cdf0e10cSrcweir             for( sal_Int32 eType = TitleHelper::TITLE_BEGIN;
262*cdf0e10cSrcweir                  eType < TitleHelper::NORMAL_TITLE_END;
263*cdf0e10cSrcweir                  ++eType )
264*cdf0e10cSrcweir             {
265*cdf0e10cSrcweir                 Reference< beans::XPropertyState > xTitleState(
266*cdf0e10cSrcweir                     TitleHelper::getTitle(
267*cdf0e10cSrcweir                         static_cast< TitleHelper::eTitleType >( eType ), xModel ), uno::UNO_QUERY );
268*cdf0e10cSrcweir                 if( xTitleState.is())
269*cdf0e10cSrcweir                     xTitleState->setPropertyToDefault( C2U("RelativePosition"));
270*cdf0e10cSrcweir             }
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir             // regression curve equations
273*cdf0e10cSrcweir             ::std::vector< Reference< chart2::XRegressionCurve > > aRegressionCurves(
274*cdf0e10cSrcweir                 RegressionCurveHelper::getAllRegressionCurvesNotMeanValueLine( xDiagram ));
275*cdf0e10cSrcweir             ::std::for_each( aRegressionCurves.begin(), aRegressionCurves.end(),
276*cdf0e10cSrcweir                       RegressionCurveHelper::resetEquationPosition );
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir             aUndoGuard.commit();
279*cdf0e10cSrcweir         }
280*cdf0e10cSrcweir     }
281*cdf0e10cSrcweir     catch( uno::RuntimeException & ex )
282*cdf0e10cSrcweir     {
283*cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
284*cdf0e10cSrcweir     }
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir void ChartController::executeDispatch_ScaleText()
288*cdf0e10cSrcweir {
289*cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
290*cdf0e10cSrcweir     // using assignment for broken gcc 3.3
291*cdf0e10cSrcweir     UndoGuard aUndoGuard = UndoGuard(
292*cdf0e10cSrcweir         String( SchResId( STR_ACTION_SCALE_TEXT )),
293*cdf0e10cSrcweir         m_xUndoManager );
294*cdf0e10cSrcweir     ControllerLockGuard aCtlLockGuard( getModel() );
295*cdf0e10cSrcweir     ::std::auto_ptr< ReferenceSizeProvider > apRefSizeProv( impl_createReferenceSizeProvider());
296*cdf0e10cSrcweir     OSL_ASSERT( apRefSizeProv.get());
297*cdf0e10cSrcweir     if( apRefSizeProv.get())
298*cdf0e10cSrcweir         apRefSizeProv->toggleAutoResizeState();
299*cdf0e10cSrcweir     aUndoGuard.commit();
300*cdf0e10cSrcweir }
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir void ChartController::executeDispatch_Paste()
303*cdf0e10cSrcweir {
304*cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
305*cdf0e10cSrcweir     if( m_pChartWindow )
306*cdf0e10cSrcweir     {
307*cdf0e10cSrcweir         Graphic aGraphic;
308*cdf0e10cSrcweir         // paste location: center of window
309*cdf0e10cSrcweir         Point aPos;
310*cdf0e10cSrcweir         aPos = m_pChartWindow->PixelToLogic( Rectangle( aPos, m_pChartWindow->GetSizePixel()).Center());
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir         // handle different formats
313*cdf0e10cSrcweir         TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( m_pChartWindow ));
314*cdf0e10cSrcweir         if( aDataHelper.GetTransferable().is())
315*cdf0e10cSrcweir         {
316*cdf0e10cSrcweir             if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) )
317*cdf0e10cSrcweir             {
318*cdf0e10cSrcweir                 SotStorageStreamRef xStm;
319*cdf0e10cSrcweir                 if ( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xStm ) )
320*cdf0e10cSrcweir                 {
321*cdf0e10cSrcweir                     xStm->Seek( 0 );
322*cdf0e10cSrcweir                     Reference< io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ) );
323*cdf0e10cSrcweir                     ::boost::scoped_ptr< SdrModel > spModel( new SdrModel() );
324*cdf0e10cSrcweir                     if ( SvxDrawingLayerImport( spModel.get(), xInputStream ) )
325*cdf0e10cSrcweir                     {
326*cdf0e10cSrcweir                         impl_PasteShapes( spModel.get() );
327*cdf0e10cSrcweir                     }
328*cdf0e10cSrcweir                 }
329*cdf0e10cSrcweir             }
330*cdf0e10cSrcweir             else if ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ) )
331*cdf0e10cSrcweir             {
332*cdf0e10cSrcweir                 // graphic exchange format (graphic manager bitmap format?)
333*cdf0e10cSrcweir                 SotStorageStreamRef xStm;
334*cdf0e10cSrcweir                 if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_SVXB, xStm ))
335*cdf0e10cSrcweir                     (*xStm) >> aGraphic;
336*cdf0e10cSrcweir             }
337*cdf0e10cSrcweir             else if( aDataHelper.HasFormat( FORMAT_GDIMETAFILE ))
338*cdf0e10cSrcweir             {
339*cdf0e10cSrcweir                 // meta file
340*cdf0e10cSrcweir                 GDIMetaFile aMetafile;
341*cdf0e10cSrcweir                 if( aDataHelper.GetGDIMetaFile( FORMAT_GDIMETAFILE, aMetafile ))
342*cdf0e10cSrcweir                     aGraphic = Graphic( aMetafile );
343*cdf0e10cSrcweir             }
344*cdf0e10cSrcweir             else if( aDataHelper.HasFormat( FORMAT_BITMAP ))
345*cdf0e10cSrcweir             {
346*cdf0e10cSrcweir                 // bitmap (non-graphic-manager)
347*cdf0e10cSrcweir                 Bitmap aBmp;
348*cdf0e10cSrcweir                 if( aDataHelper.GetBitmap( FORMAT_BITMAP, aBmp ))
349*cdf0e10cSrcweir                     aGraphic = Graphic( aBmp );
350*cdf0e10cSrcweir             }
351*cdf0e10cSrcweir             else if( aDataHelper.HasFormat( FORMAT_STRING ))
352*cdf0e10cSrcweir             {
353*cdf0e10cSrcweir                 OUString aString;
354*cdf0e10cSrcweir                 if( aDataHelper.GetString( FORMAT_STRING, aString ) && m_pDrawModelWrapper )
355*cdf0e10cSrcweir                 {
356*cdf0e10cSrcweir                     if( m_pDrawViewWrapper )
357*cdf0e10cSrcweir                     {
358*cdf0e10cSrcweir                         OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
359*cdf0e10cSrcweir                         if( pOutlinerView )//in case of edit mode insert into edited string
360*cdf0e10cSrcweir                             pOutlinerView->InsertText( aString );
361*cdf0e10cSrcweir                         else
362*cdf0e10cSrcweir                         {
363*cdf0e10cSrcweir                             impl_PasteStringAsTextShape( aString, awt::Point( 0, 0 ) );
364*cdf0e10cSrcweir                         }
365*cdf0e10cSrcweir                     }
366*cdf0e10cSrcweir                 }
367*cdf0e10cSrcweir             }
368*cdf0e10cSrcweir         }
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir         if( aGraphic.GetType() != GRAPHIC_NONE )
371*cdf0e10cSrcweir         {
372*cdf0e10cSrcweir             Reference< graphic::XGraphic > xGraphic( aGraphic.GetXGraphic());
373*cdf0e10cSrcweir             if( xGraphic.is())
374*cdf0e10cSrcweir                 impl_PasteGraphic( xGraphic, aPos );
375*cdf0e10cSrcweir         }
376*cdf0e10cSrcweir     }
377*cdf0e10cSrcweir }
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir // note: aPosition is ignored for now. The object is always pasted centered to
380*cdf0e10cSrcweir // the page
381*cdf0e10cSrcweir void ChartController::impl_PasteGraphic(
382*cdf0e10cSrcweir     uno::Reference< graphic::XGraphic > & xGraphic,
383*cdf0e10cSrcweir     const ::Point & /* aPosition */ )
384*cdf0e10cSrcweir {
385*cdf0e10cSrcweir     // note: the XPropertySet of the model is the old API. Also the property
386*cdf0e10cSrcweir     // "AdditionalShapes" that is used there.
387*cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xModelProp( getModel(), uno::UNO_QUERY );
388*cdf0e10cSrcweir     DrawModelWrapper * pDrawModelWrapper( this->GetDrawModelWrapper());
389*cdf0e10cSrcweir     if( ! (xGraphic.is() && xModelProp.is()))
390*cdf0e10cSrcweir         return;
391*cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xFact( pDrawModelWrapper->getShapeFactory());
392*cdf0e10cSrcweir     uno::Reference< drawing::XShape > xGraphicShape(
393*cdf0e10cSrcweir         xFact->createInstance( C2U( "com.sun.star.drawing.GraphicObjectShape" )), uno::UNO_QUERY );
394*cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xGraphicShapeProp( xGraphicShape, uno::UNO_QUERY );
395*cdf0e10cSrcweir     if( xGraphicShapeProp.is() && xGraphicShape.is())
396*cdf0e10cSrcweir     {
397*cdf0e10cSrcweir         uno::Reference< drawing::XShapes > xPage( pDrawModelWrapper->getMainDrawPage(), uno::UNO_QUERY );
398*cdf0e10cSrcweir         if( xPage.is())
399*cdf0e10cSrcweir         {
400*cdf0e10cSrcweir             xPage->add( xGraphicShape );
401*cdf0e10cSrcweir             //need to change the model state manually
402*cdf0e10cSrcweir             {
403*cdf0e10cSrcweir                 uno::Reference< util::XModifiable > xModifiable( getModel(), uno::UNO_QUERY );
404*cdf0e10cSrcweir                 if( xModifiable.is() )
405*cdf0e10cSrcweir                     xModifiable->setModified( true );
406*cdf0e10cSrcweir             }
407*cdf0e10cSrcweir             //select new shape
408*cdf0e10cSrcweir             m_aSelection.setSelection( xGraphicShape );
409*cdf0e10cSrcweir             m_aSelection.applySelection( m_pDrawViewWrapper );
410*cdf0e10cSrcweir         }
411*cdf0e10cSrcweir         xGraphicShapeProp->setPropertyValue( C2U("Graphic"), uno::makeAny( xGraphic ));
412*cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xGraphicProp( xGraphic, uno::UNO_QUERY );
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir         awt::Size aGraphicSize( 1000, 1000 );
415*cdf0e10cSrcweir         // first try size in 100th mm, then pixel size
416*cdf0e10cSrcweir         if( ! ( xGraphicProp->getPropertyValue( C2U("Size100thMM")) >>= aGraphicSize ) &&
417*cdf0e10cSrcweir             ( ( xGraphicProp->getPropertyValue( C2U("SizePixel")) >>= aGraphicSize ) && m_pChartWindow ))
418*cdf0e10cSrcweir         {
419*cdf0e10cSrcweir             ::Size aVCLSize( m_pChartWindow->PixelToLogic( Size( aGraphicSize.Width, aGraphicSize.Height )));
420*cdf0e10cSrcweir             aGraphicSize.Width = aVCLSize.getWidth();
421*cdf0e10cSrcweir             aGraphicSize.Height = aVCLSize.getHeight();
422*cdf0e10cSrcweir         }
423*cdf0e10cSrcweir         xGraphicShape->setSize( aGraphicSize );
424*cdf0e10cSrcweir         xGraphicShape->setPosition( awt::Point( 0, 0 ) );
425*cdf0e10cSrcweir     }
426*cdf0e10cSrcweir }
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir void ChartController::impl_PasteShapes( SdrModel* pModel )
429*cdf0e10cSrcweir {
430*cdf0e10cSrcweir     DrawModelWrapper* pDrawModelWrapper( this->GetDrawModelWrapper() );
431*cdf0e10cSrcweir     if ( pDrawModelWrapper && m_pDrawViewWrapper )
432*cdf0e10cSrcweir     {
433*cdf0e10cSrcweir         Reference< drawing::XDrawPage > xDestPage( pDrawModelWrapper->getMainDrawPage() );
434*cdf0e10cSrcweir         SdrPage* pDestPage = GetSdrPageFromXDrawPage( xDestPage );
435*cdf0e10cSrcweir         if ( pDestPage )
436*cdf0e10cSrcweir         {
437*cdf0e10cSrcweir             Reference< drawing::XShape > xSelShape;
438*cdf0e10cSrcweir             m_pDrawViewWrapper->BegUndo( SVX_RESSTR( RID_SVX_3D_UNDO_EXCHANGE_PASTE ) );
439*cdf0e10cSrcweir             sal_uInt16 nCount = pModel->GetPageCount();
440*cdf0e10cSrcweir             for ( sal_uInt16 i = 0; i < nCount; ++i )
441*cdf0e10cSrcweir             {
442*cdf0e10cSrcweir                 const SdrPage* pPage = pModel->GetPage( i );
443*cdf0e10cSrcweir                 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
444*cdf0e10cSrcweir                 while ( aIter.IsMore() )
445*cdf0e10cSrcweir                 {
446*cdf0e10cSrcweir                     SdrObject* pObj = aIter.Next();
447*cdf0e10cSrcweir                     SdrObject* pNewObj = ( pObj ? pObj->Clone() : NULL );
448*cdf0e10cSrcweir                     if ( pNewObj )
449*cdf0e10cSrcweir                     {
450*cdf0e10cSrcweir                         pNewObj->SetModel( &pDrawModelWrapper->getSdrModel() );
451*cdf0e10cSrcweir                         pNewObj->SetPage( pDestPage );
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir                         // set position
454*cdf0e10cSrcweir                         Reference< drawing::XShape > xShape( pNewObj->getUnoShape(), uno::UNO_QUERY );
455*cdf0e10cSrcweir                         if ( xShape.is() )
456*cdf0e10cSrcweir                         {
457*cdf0e10cSrcweir                             xShape->setPosition( awt::Point( 0, 0 ) );
458*cdf0e10cSrcweir                         }
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir                         pDestPage->InsertObject( pNewObj );
461*cdf0e10cSrcweir                         m_pDrawViewWrapper->AddUndo( new SdrUndoInsertObj( *pNewObj ) );
462*cdf0e10cSrcweir                         xSelShape = xShape;
463*cdf0e10cSrcweir                     }
464*cdf0e10cSrcweir                 }
465*cdf0e10cSrcweir             }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir             Reference< util::XModifiable > xModifiable( getModel(), uno::UNO_QUERY );
468*cdf0e10cSrcweir             if ( xModifiable.is() )
469*cdf0e10cSrcweir             {
470*cdf0e10cSrcweir                 xModifiable->setModified( true );
471*cdf0e10cSrcweir             }
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir             // select last inserted shape
474*cdf0e10cSrcweir             m_aSelection.setSelection( xSelShape );
475*cdf0e10cSrcweir             m_aSelection.applySelection( m_pDrawViewWrapper );
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir             m_pDrawViewWrapper->EndUndo();
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir             impl_switchDiagramPositioningToExcludingPositioning();
480*cdf0e10cSrcweir         }
481*cdf0e10cSrcweir     }
482*cdf0e10cSrcweir }
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir void ChartController::impl_PasteStringAsTextShape( const OUString& rString, const awt::Point& rPosition )
485*cdf0e10cSrcweir {
486*cdf0e10cSrcweir     DrawModelWrapper* pDrawModelWrapper( this->GetDrawModelWrapper() );
487*cdf0e10cSrcweir     if ( pDrawModelWrapper && m_pDrawViewWrapper )
488*cdf0e10cSrcweir     {
489*cdf0e10cSrcweir         const Reference< lang::XMultiServiceFactory >& xShapeFactory( pDrawModelWrapper->getShapeFactory() );
490*cdf0e10cSrcweir         const Reference< drawing::XDrawPage >& xDrawPage( pDrawModelWrapper->getMainDrawPage() );
491*cdf0e10cSrcweir         OSL_ASSERT( xShapeFactory.is() && xDrawPage.is() );
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir         if ( xShapeFactory.is() && xDrawPage.is() )
494*cdf0e10cSrcweir         {
495*cdf0e10cSrcweir             try
496*cdf0e10cSrcweir             {
497*cdf0e10cSrcweir                 Reference< drawing::XShape > xTextShape(
498*cdf0e10cSrcweir                     xShapeFactory->createInstance( C2U( "com.sun.star.drawing.TextShape" ) ), uno::UNO_QUERY_THROW );
499*cdf0e10cSrcweir                 xDrawPage->add( xTextShape );
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir                 Reference< text::XTextRange > xRange( xTextShape, uno::UNO_QUERY_THROW );
502*cdf0e10cSrcweir                 xRange->setString( rString );
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir                 float fCharHeight = 10.0;
505*cdf0e10cSrcweir                 Reference< beans::XPropertySet > xProperties( xTextShape, uno::UNO_QUERY_THROW );
506*cdf0e10cSrcweir                 xProperties->setPropertyValue( C2U( "TextAutoGrowHeight" ), uno::makeAny( true ) );
507*cdf0e10cSrcweir                 xProperties->setPropertyValue( C2U( "TextAutoGrowWidth" ), uno::makeAny( true ) );
508*cdf0e10cSrcweir                 xProperties->setPropertyValue( C2U( "CharHeight" ), uno::makeAny( fCharHeight ) );
509*cdf0e10cSrcweir                 xProperties->setPropertyValue( C2U( "CharHeightAsian" ), uno::makeAny( fCharHeight ) );
510*cdf0e10cSrcweir                 xProperties->setPropertyValue( C2U( "CharHeightComplex" ), uno::makeAny( fCharHeight ) );
511*cdf0e10cSrcweir                 xProperties->setPropertyValue( C2U( "TextVerticalAdjust" ), uno::makeAny( drawing::TextVerticalAdjust_CENTER ) );
512*cdf0e10cSrcweir                 xProperties->setPropertyValue( C2U( "TextHorizontalAdjust" ), uno::makeAny( drawing::TextHorizontalAdjust_CENTER ) );
513*cdf0e10cSrcweir                 xProperties->setPropertyValue( C2U( "CharFontName" ), uno::makeAny( C2U( "Albany" ) ) );
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir                 xTextShape->setPosition( rPosition );
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir                 m_aSelection.setSelection( xTextShape );
518*cdf0e10cSrcweir                 m_aSelection.applySelection( m_pDrawViewWrapper );
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir                 SdrObject* pObj = DrawViewWrapper::getSdrObject( xTextShape );
521*cdf0e10cSrcweir                 if ( pObj )
522*cdf0e10cSrcweir                 {
523*cdf0e10cSrcweir                     m_pDrawViewWrapper->BegUndo( SVX_RESSTR( RID_SVX_3D_UNDO_EXCHANGE_PASTE ) );
524*cdf0e10cSrcweir                     m_pDrawViewWrapper->AddUndo( new SdrUndoInsertObj( *pObj ) );
525*cdf0e10cSrcweir                     m_pDrawViewWrapper->EndUndo();
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir                     impl_switchDiagramPositioningToExcludingPositioning();
528*cdf0e10cSrcweir                 }
529*cdf0e10cSrcweir             }
530*cdf0e10cSrcweir             catch ( const uno::Exception& ex )
531*cdf0e10cSrcweir             {
532*cdf0e10cSrcweir                 ASSERT_EXCEPTION( ex );
533*cdf0e10cSrcweir             }
534*cdf0e10cSrcweir         }
535*cdf0e10cSrcweir     }
536*cdf0e10cSrcweir }
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir void ChartController::executeDispatch_Copy()
539*cdf0e10cSrcweir {
540*cdf0e10cSrcweir     if ( m_pDrawViewWrapper )
541*cdf0e10cSrcweir     {
542*cdf0e10cSrcweir         OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
543*cdf0e10cSrcweir         if ( pOutlinerView )
544*cdf0e10cSrcweir         {
545*cdf0e10cSrcweir             pOutlinerView->Copy();
546*cdf0e10cSrcweir         }
547*cdf0e10cSrcweir         else
548*cdf0e10cSrcweir         {
549*cdf0e10cSrcweir             Reference< datatransfer::XTransferable > xTransferable;
550*cdf0e10cSrcweir             {
551*cdf0e10cSrcweir                 ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
552*cdf0e10cSrcweir                 SdrObject* pSelectedObj = 0;
553*cdf0e10cSrcweir                 if ( m_pDrawModelWrapper )
554*cdf0e10cSrcweir                 {
555*cdf0e10cSrcweir                     ObjectIdentifier aSelOID( m_aSelection.getSelectedOID() );
556*cdf0e10cSrcweir                     if ( aSelOID.isAutoGeneratedObject() )
557*cdf0e10cSrcweir                     {
558*cdf0e10cSrcweir                         pSelectedObj = m_pDrawModelWrapper->getNamedSdrObject( aSelOID.getObjectCID() );
559*cdf0e10cSrcweir                     }
560*cdf0e10cSrcweir                     else if ( aSelOID.isAdditionalShape() )
561*cdf0e10cSrcweir                     {
562*cdf0e10cSrcweir                         pSelectedObj = DrawViewWrapper::getSdrObject( aSelOID.getAdditionalShape() );
563*cdf0e10cSrcweir                     }
564*cdf0e10cSrcweir                     if ( pSelectedObj )
565*cdf0e10cSrcweir                     {
566*cdf0e10cSrcweir                         xTransferable = Reference< datatransfer::XTransferable >( new ChartTransferable(
567*cdf0e10cSrcweir                                 &m_pDrawModelWrapper->getSdrModel(), pSelectedObj, aSelOID.isAdditionalShape() ) );
568*cdf0e10cSrcweir                     }
569*cdf0e10cSrcweir                 }
570*cdf0e10cSrcweir             }
571*cdf0e10cSrcweir             if ( xTransferable.is() )
572*cdf0e10cSrcweir             {
573*cdf0e10cSrcweir                 Reference< datatransfer::clipboard::XClipboard > xClipboard( TransferableHelper::GetSystemClipboard() );
574*cdf0e10cSrcweir                 if ( xClipboard.is() )
575*cdf0e10cSrcweir                 {
576*cdf0e10cSrcweir                     xClipboard->setContents( xTransferable, Reference< datatransfer::clipboard::XClipboardOwner >() );
577*cdf0e10cSrcweir                 }
578*cdf0e10cSrcweir             }
579*cdf0e10cSrcweir         }
580*cdf0e10cSrcweir     }
581*cdf0e10cSrcweir }
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir void ChartController::executeDispatch_Cut()
584*cdf0e10cSrcweir {
585*cdf0e10cSrcweir     executeDispatch_Copy();
586*cdf0e10cSrcweir     executeDispatch_Delete();
587*cdf0e10cSrcweir }
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir bool ChartController::isObjectDeleteable( const uno::Any& rSelection )
590*cdf0e10cSrcweir {
591*cdf0e10cSrcweir     ObjectIdentifier aSelOID( rSelection );
592*cdf0e10cSrcweir     if ( aSelOID.isAutoGeneratedObject() )
593*cdf0e10cSrcweir     {
594*cdf0e10cSrcweir         OUString aSelObjCID( aSelOID.getObjectCID() );
595*cdf0e10cSrcweir         ObjectType aObjectType(ObjectIdentifier::getObjectType( aSelObjCID ));
596*cdf0e10cSrcweir         if( (OBJECTTYPE_TITLE == aObjectType) || (OBJECTTYPE_LEGEND == aObjectType) )
597*cdf0e10cSrcweir             return true;
598*cdf0e10cSrcweir         if( (OBJECTTYPE_DATA_SERIES == aObjectType) || (OBJECTTYPE_LEGEND_ENTRY == aObjectType) )
599*cdf0e10cSrcweir             return true;
600*cdf0e10cSrcweir         if( (OBJECTTYPE_DATA_CURVE_EQUATION == aObjectType) || (OBJECTTYPE_DATA_CURVE == aObjectType) ||
601*cdf0e10cSrcweir             (OBJECTTYPE_DATA_AVERAGE_LINE == aObjectType) || (OBJECTTYPE_DATA_ERRORS == aObjectType))
602*cdf0e10cSrcweir             return true;
603*cdf0e10cSrcweir         if( (OBJECTTYPE_DATA_LABELS == aObjectType) || (OBJECTTYPE_DATA_LABEL == aObjectType) )
604*cdf0e10cSrcweir             return true;
605*cdf0e10cSrcweir         if( (OBJECTTYPE_AXIS == aObjectType) || (OBJECTTYPE_GRID == aObjectType) || (OBJECTTYPE_SUBGRID == aObjectType) )
606*cdf0e10cSrcweir             return true;
607*cdf0e10cSrcweir     }
608*cdf0e10cSrcweir     else if ( aSelOID.isAdditionalShape() )
609*cdf0e10cSrcweir     {
610*cdf0e10cSrcweir         return true;
611*cdf0e10cSrcweir     }
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir     return false;
614*cdf0e10cSrcweir }
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir bool ChartController::isShapeContext() const
617*cdf0e10cSrcweir {
618*cdf0e10cSrcweir     if ( m_aSelection.isAdditionalShapeSelected() ||
619*cdf0e10cSrcweir          ( m_pDrawViewWrapper && m_pDrawViewWrapper->AreObjectsMarked() &&
620*cdf0e10cSrcweir            ( m_pDrawViewWrapper->GetCurrentObjIdentifier() == OBJ_TEXT ) ) )
621*cdf0e10cSrcweir     {
622*cdf0e10cSrcweir         return true;
623*cdf0e10cSrcweir     }
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir     return false;
626*cdf0e10cSrcweir }
627*cdf0e10cSrcweir 
628*cdf0e10cSrcweir void ChartController::impl_ClearSelection()
629*cdf0e10cSrcweir {
630*cdf0e10cSrcweir     if( m_aSelection.hasSelection())
631*cdf0e10cSrcweir     {
632*cdf0e10cSrcweir         m_aSelection.clearSelection();
633*cdf0e10cSrcweir         impl_notifySelectionChangeListeners();
634*cdf0e10cSrcweir     }
635*cdf0e10cSrcweir }
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir bool ChartController::executeDispatch_Delete()
638*cdf0e10cSrcweir {
639*cdf0e10cSrcweir     bool bReturn = false;
640*cdf0e10cSrcweir 
641*cdf0e10cSrcweir     // remove the selected object
642*cdf0e10cSrcweir     //
643*cdf0e10cSrcweir     rtl::OUString aCID( m_aSelection.getSelectedCID() );
644*cdf0e10cSrcweir     if( aCID.getLength() )
645*cdf0e10cSrcweir     {
646*cdf0e10cSrcweir         if( !isObjectDeleteable( uno::Any( aCID ) ) )
647*cdf0e10cSrcweir             return false;
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir         //remove chart object
650*cdf0e10cSrcweir         uno::Reference< chart2::XChartDocument > xChartDoc( getModel(), uno::UNO_QUERY );
651*cdf0e10cSrcweir         if( !xChartDoc.is() )
652*cdf0e10cSrcweir             return false;
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir         ObjectType aObjectType( ObjectIdentifier::getObjectType( aCID ));
655*cdf0e10cSrcweir         switch( aObjectType )
656*cdf0e10cSrcweir         {
657*cdf0e10cSrcweir             case OBJECTTYPE_TITLE:
658*cdf0e10cSrcweir             {
659*cdf0e10cSrcweir                 // using assignment for broken gcc 3.3
660*cdf0e10cSrcweir                 UndoGuard aUndoGuard = UndoGuard(
661*cdf0e10cSrcweir                     ActionDescriptionProvider::createDescription(
662*cdf0e10cSrcweir                         ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_TITLE ))),
663*cdf0e10cSrcweir                     m_xUndoManager );
664*cdf0e10cSrcweir                 TitleHelper::removeTitle(
665*cdf0e10cSrcweir                     ObjectIdentifier::getTitleTypeForCID( aCID ), getModel() );
666*cdf0e10cSrcweir                 bReturn = true;
667*cdf0e10cSrcweir                 aUndoGuard.commit();
668*cdf0e10cSrcweir                 break;
669*cdf0e10cSrcweir             }
670*cdf0e10cSrcweir             case OBJECTTYPE_LEGEND:
671*cdf0e10cSrcweir             {
672*cdf0e10cSrcweir                 uno::Reference< chart2::XDiagram > xDiagram( xChartDoc->getFirstDiagram());
673*cdf0e10cSrcweir                 if( xDiagram.is())
674*cdf0e10cSrcweir                 {
675*cdf0e10cSrcweir                     uno::Reference< beans::XPropertySet > xLegendProp( xDiagram->getLegend(), uno::UNO_QUERY );
676*cdf0e10cSrcweir                     if( xLegendProp.is())
677*cdf0e10cSrcweir                     {
678*cdf0e10cSrcweir                         // using assignment for broken gcc 3.3
679*cdf0e10cSrcweir                         UndoGuard aUndoGuard = UndoGuard(
680*cdf0e10cSrcweir                             ActionDescriptionProvider::createDescription(
681*cdf0e10cSrcweir                                 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_LEGEND ))),
682*cdf0e10cSrcweir                             m_xUndoManager );
683*cdf0e10cSrcweir                         xLegendProp->setPropertyValue( C2U("Show"), uno::makeAny( false ));
684*cdf0e10cSrcweir                         bReturn = true;
685*cdf0e10cSrcweir                         aUndoGuard.commit();
686*cdf0e10cSrcweir                     }
687*cdf0e10cSrcweir                 }
688*cdf0e10cSrcweir                 break;
689*cdf0e10cSrcweir             }
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir             case OBJECTTYPE_DATA_SERIES:
692*cdf0e10cSrcweir                 bReturn = lcl_deleteDataSeries( aCID, getModel(), m_xUndoManager );
693*cdf0e10cSrcweir                 break;
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir             case OBJECTTYPE_LEGEND_ENTRY:
696*cdf0e10cSrcweir             {
697*cdf0e10cSrcweir                 ObjectType eParentObjectType = ObjectIdentifier::getObjectType(
698*cdf0e10cSrcweir                     ObjectIdentifier::getFullParentParticle( aCID ));
699*cdf0e10cSrcweir                 if( eParentObjectType == OBJECTTYPE_DATA_SERIES )
700*cdf0e10cSrcweir                     bReturn = lcl_deleteDataSeries( aCID, getModel(), m_xUndoManager );
701*cdf0e10cSrcweir                 else if( eParentObjectType == OBJECTTYPE_DATA_CURVE )
702*cdf0e10cSrcweir                     bReturn = lcl_deleteDataCurve( aCID, getModel(), m_xUndoManager );
703*cdf0e10cSrcweir                 else if( eParentObjectType == OBJECTTYPE_DATA_AVERAGE_LINE )
704*cdf0e10cSrcweir                 {
705*cdf0e10cSrcweir                     executeDispatch_DeleteMeanValue();
706*cdf0e10cSrcweir                     bReturn = true;
707*cdf0e10cSrcweir                 }
708*cdf0e10cSrcweir                 break;
709*cdf0e10cSrcweir             }
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir             case OBJECTTYPE_DATA_AVERAGE_LINE:
712*cdf0e10cSrcweir             {
713*cdf0e10cSrcweir                 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
714*cdf0e10cSrcweir                     ObjectIdentifier::getObjectPropertySet(
715*cdf0e10cSrcweir                         ObjectIdentifier::getFullParentParticle( aCID ), getModel()), uno::UNO_QUERY );
716*cdf0e10cSrcweir                 if( xRegCurveCnt.is())
717*cdf0e10cSrcweir                 {
718*cdf0e10cSrcweir                     // using assignment for broken gcc 3.3
719*cdf0e10cSrcweir                     UndoGuard aUndoGuard = UndoGuard(
720*cdf0e10cSrcweir                         ActionDescriptionProvider::createDescription(
721*cdf0e10cSrcweir                             ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_AVERAGE_LINE ))),
722*cdf0e10cSrcweir                         m_xUndoManager );
723*cdf0e10cSrcweir                     RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt );
724*cdf0e10cSrcweir                     bReturn = true;
725*cdf0e10cSrcweir                     aUndoGuard.commit();
726*cdf0e10cSrcweir                 }
727*cdf0e10cSrcweir                 break;
728*cdf0e10cSrcweir             }
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir             case OBJECTTYPE_DATA_CURVE:
731*cdf0e10cSrcweir                 bReturn = lcl_deleteDataCurve( aCID, getModel(), m_xUndoManager );
732*cdf0e10cSrcweir                 break;
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir             case OBJECTTYPE_DATA_CURVE_EQUATION:
735*cdf0e10cSrcweir             {
736*cdf0e10cSrcweir                 uno::Reference< beans::XPropertySet > xEqProp(
737*cdf0e10cSrcweir                     ObjectIdentifier::getObjectPropertySet( aCID, getModel()));
738*cdf0e10cSrcweir                 if( xEqProp.is())
739*cdf0e10cSrcweir                 {
740*cdf0e10cSrcweir                     uno::Reference< frame::XModel > xModel( getModel() );
741*cdf0e10cSrcweir                     // using assignment for broken gcc 3.3
742*cdf0e10cSrcweir                     UndoGuard aUndoGuard = UndoGuard(
743*cdf0e10cSrcweir                         ActionDescriptionProvider::createDescription(
744*cdf0e10cSrcweir                             ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
745*cdf0e10cSrcweir                         m_xUndoManager );
746*cdf0e10cSrcweir                     {
747*cdf0e10cSrcweir                         ControllerLockGuard aCtlLockGuard( xModel );
748*cdf0e10cSrcweir                         xEqProp->setPropertyValue( C2U("ShowEquation"), uno::makeAny( false ));
749*cdf0e10cSrcweir                         xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( false ));
750*cdf0e10cSrcweir                     }
751*cdf0e10cSrcweir                     bReturn = true;
752*cdf0e10cSrcweir                     aUndoGuard.commit();
753*cdf0e10cSrcweir                 }
754*cdf0e10cSrcweir                 break;
755*cdf0e10cSrcweir             }
756*cdf0e10cSrcweir 
757*cdf0e10cSrcweir             case OBJECTTYPE_DATA_ERRORS:
758*cdf0e10cSrcweir             {
759*cdf0e10cSrcweir                 uno::Reference< beans::XPropertySet > xErrorBarProp(
760*cdf0e10cSrcweir                     ObjectIdentifier::getObjectPropertySet( aCID, getModel() ));
761*cdf0e10cSrcweir                 if( xErrorBarProp.is())
762*cdf0e10cSrcweir                 {
763*cdf0e10cSrcweir                     uno::Reference< frame::XModel > xModel( getModel() );
764*cdf0e10cSrcweir                     // using assignment for broken gcc 3.3
765*cdf0e10cSrcweir                     UndoGuard aUndoGuard = UndoGuard(
766*cdf0e10cSrcweir                         ActionDescriptionProvider::createDescription(
767*cdf0e10cSrcweir                             ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_ERROR_BARS ))),
768*cdf0e10cSrcweir                         m_xUndoManager );
769*cdf0e10cSrcweir                     {
770*cdf0e10cSrcweir                         ControllerLockGuard aCtlLockGuard( xModel );
771*cdf0e10cSrcweir                         xErrorBarProp->setPropertyValue(
772*cdf0e10cSrcweir                             C2U("ErrorBarStyle"),
773*cdf0e10cSrcweir                             uno::makeAny( ::com::sun::star::chart::ErrorBarStyle::NONE ));
774*cdf0e10cSrcweir                     }
775*cdf0e10cSrcweir                     bReturn = true;
776*cdf0e10cSrcweir                     aUndoGuard.commit();
777*cdf0e10cSrcweir                 }
778*cdf0e10cSrcweir                 break;
779*cdf0e10cSrcweir             }
780*cdf0e10cSrcweir 
781*cdf0e10cSrcweir             case OBJECTTYPE_DATA_LABELS:
782*cdf0e10cSrcweir             case OBJECTTYPE_DATA_LABEL:
783*cdf0e10cSrcweir             {
784*cdf0e10cSrcweir                 uno::Reference< beans::XPropertySet > xObjectProperties =
785*cdf0e10cSrcweir                     ObjectIdentifier::getObjectPropertySet( aCID, getModel() );
786*cdf0e10cSrcweir                 if( xObjectProperties.is() )
787*cdf0e10cSrcweir                 {
788*cdf0e10cSrcweir                     UndoGuard aUndoGuard = UndoGuard(
789*cdf0e10cSrcweir                         ActionDescriptionProvider::createDescription(
790*cdf0e10cSrcweir                         ActionDescriptionProvider::DELETE, ::rtl::OUString( String(
791*cdf0e10cSrcweir                             SchResId( aObjectType == OBJECTTYPE_DATA_LABEL ? STR_OBJECT_LABEL : STR_OBJECT_DATALABELS )))),
792*cdf0e10cSrcweir                                 m_xUndoManager );
793*cdf0e10cSrcweir                     chart2::DataPointLabel aLabel;
794*cdf0e10cSrcweir                     xObjectProperties->getPropertyValue( C2U( "Label" ) ) >>= aLabel;
795*cdf0e10cSrcweir                     aLabel.ShowNumber = false;
796*cdf0e10cSrcweir                     aLabel.ShowNumberInPercent = false;
797*cdf0e10cSrcweir                     aLabel.ShowCategoryName = false;
798*cdf0e10cSrcweir                     aLabel.ShowLegendSymbol = false;
799*cdf0e10cSrcweir                     if( aObjectType == OBJECTTYPE_DATA_LABELS )
800*cdf0e10cSrcweir                     {
801*cdf0e10cSrcweir                         uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( aCID, getModel() ));
802*cdf0e10cSrcweir                         ::chart::DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "Label" ), uno::makeAny(aLabel) );
803*cdf0e10cSrcweir                     }
804*cdf0e10cSrcweir                     else
805*cdf0e10cSrcweir                         xObjectProperties->setPropertyValue( C2U( "Label" ), uno::makeAny(aLabel) );
806*cdf0e10cSrcweir                     bReturn = true;
807*cdf0e10cSrcweir                     aUndoGuard.commit();
808*cdf0e10cSrcweir                 }
809*cdf0e10cSrcweir                 break;
810*cdf0e10cSrcweir             }
811*cdf0e10cSrcweir             case OBJECTTYPE_AXIS:
812*cdf0e10cSrcweir             {
813*cdf0e10cSrcweir                 executeDispatch_DeleteAxis();
814*cdf0e10cSrcweir                 bReturn = true;
815*cdf0e10cSrcweir                 break;
816*cdf0e10cSrcweir             }
817*cdf0e10cSrcweir             case OBJECTTYPE_GRID:
818*cdf0e10cSrcweir             {
819*cdf0e10cSrcweir                 executeDispatch_DeleteMajorGrid();
820*cdf0e10cSrcweir                 bReturn = true;
821*cdf0e10cSrcweir                 break;
822*cdf0e10cSrcweir             }
823*cdf0e10cSrcweir             case OBJECTTYPE_SUBGRID:
824*cdf0e10cSrcweir             {
825*cdf0e10cSrcweir                 executeDispatch_DeleteMinorGrid();
826*cdf0e10cSrcweir                 bReturn = true;
827*cdf0e10cSrcweir                 break;
828*cdf0e10cSrcweir             }
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir             default:
831*cdf0e10cSrcweir             {
832*cdf0e10cSrcweir                 break;
833*cdf0e10cSrcweir             }
834*cdf0e10cSrcweir         }
835*cdf0e10cSrcweir     }
836*cdf0e10cSrcweir     else
837*cdf0e10cSrcweir     {
838*cdf0e10cSrcweir         //remove additional shape
839*cdf0e10cSrcweir         impl_ClearSelection();
840*cdf0e10cSrcweir         {
841*cdf0e10cSrcweir             ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
842*cdf0e10cSrcweir             if ( m_pDrawViewWrapper )
843*cdf0e10cSrcweir             {
844*cdf0e10cSrcweir                 m_pDrawViewWrapper->DeleteMarked();
845*cdf0e10cSrcweir                 bReturn = true;
846*cdf0e10cSrcweir             }
847*cdf0e10cSrcweir         }
848*cdf0e10cSrcweir     }
849*cdf0e10cSrcweir     return bReturn;
850*cdf0e10cSrcweir }
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir void ChartController::executeDispatch_ToggleLegend()
853*cdf0e10cSrcweir {
854*cdf0e10cSrcweir     Reference< frame::XModel > xModel( getModel() );
855*cdf0e10cSrcweir     UndoGuard aUndoGuard = UndoGuard(
856*cdf0e10cSrcweir         String( SchResId( STR_ACTION_TOGGLE_LEGEND )), m_xUndoManager );
857*cdf0e10cSrcweir     Reference< beans::XPropertySet > xLegendProp( LegendHelper::getLegend( xModel ), uno::UNO_QUERY );
858*cdf0e10cSrcweir     bool bChanged = false;
859*cdf0e10cSrcweir     if( xLegendProp.is())
860*cdf0e10cSrcweir     {
861*cdf0e10cSrcweir         try
862*cdf0e10cSrcweir         {
863*cdf0e10cSrcweir             bool bShow = false;
864*cdf0e10cSrcweir             if( xLegendProp->getPropertyValue( C2U("Show")) >>= bShow )
865*cdf0e10cSrcweir             {
866*cdf0e10cSrcweir                 xLegendProp->setPropertyValue( C2U("Show"), uno::makeAny( ! bShow ));
867*cdf0e10cSrcweir                 bChanged = true;
868*cdf0e10cSrcweir             }
869*cdf0e10cSrcweir         }
870*cdf0e10cSrcweir         catch( const uno::Exception & ex )
871*cdf0e10cSrcweir         {
872*cdf0e10cSrcweir             ASSERT_EXCEPTION( ex );
873*cdf0e10cSrcweir         }
874*cdf0e10cSrcweir     }
875*cdf0e10cSrcweir     else
876*cdf0e10cSrcweir     {
877*cdf0e10cSrcweir         xLegendProp.set( LegendHelper::getLegend( xModel, m_xCC, true ), uno::UNO_QUERY );
878*cdf0e10cSrcweir         if( xLegendProp.is())
879*cdf0e10cSrcweir             bChanged = true;
880*cdf0e10cSrcweir     }
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir     if( bChanged )
883*cdf0e10cSrcweir         aUndoGuard.commit();
884*cdf0e10cSrcweir }
885*cdf0e10cSrcweir 
886*cdf0e10cSrcweir void ChartController::executeDispatch_ToggleGridHorizontal()
887*cdf0e10cSrcweir {
888*cdf0e10cSrcweir     Reference< frame::XModel > xModel( getModel() );
889*cdf0e10cSrcweir     UndoGuard aUndoGuard = UndoGuard(
890*cdf0e10cSrcweir         String( SchResId( STR_ACTION_TOGGLE_GRID_HORZ )), m_xUndoManager );
891*cdf0e10cSrcweir     Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( getModel() ));
892*cdf0e10cSrcweir     if( xDiagram.is())
893*cdf0e10cSrcweir     {
894*cdf0e10cSrcweir         sal_Int32 nDimensionIndex = 1;
895*cdf0e10cSrcweir         sal_Int32 nCooSysIndex = 0;
896*cdf0e10cSrcweir         bool bIsMainGrid = true;
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir         bool bHasMainYGrid = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, bIsMainGrid, xDiagram );
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir         if( bHasMainYGrid )
901*cdf0e10cSrcweir             AxisHelper::hideGrid( nDimensionIndex, nCooSysIndex, bIsMainGrid, xDiagram );
902*cdf0e10cSrcweir         else
903*cdf0e10cSrcweir             AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, bIsMainGrid, xDiagram, m_xCC );
904*cdf0e10cSrcweir 
905*cdf0e10cSrcweir         aUndoGuard.commit();
906*cdf0e10cSrcweir     }
907*cdf0e10cSrcweir }
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir void ChartController::impl_ShapeControllerDispatch( const util::URL& rURL, const Sequence< beans::PropertyValue >& rArgs )
910*cdf0e10cSrcweir {
911*cdf0e10cSrcweir     Reference< frame::XDispatch > xDispatch( m_aDispatchContainer.getShapeController() );
912*cdf0e10cSrcweir     if ( xDispatch.is() )
913*cdf0e10cSrcweir     {
914*cdf0e10cSrcweir         xDispatch->dispatch( rURL, rArgs );
915*cdf0e10cSrcweir     }
916*cdf0e10cSrcweir }
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir void ChartController::impl_switchDiagramPositioningToExcludingPositioning()
919*cdf0e10cSrcweir {
920*cdf0e10cSrcweir     UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription(
921*cdf0e10cSrcweir         ActionDescriptionProvider::POS_SIZE,
922*cdf0e10cSrcweir         ObjectNameProvider::getName( OBJECTTYPE_DIAGRAM)),
923*cdf0e10cSrcweir         m_xUndoManager );
924*cdf0e10cSrcweir     if( DiagramHelper::switchDiagramPositioningToExcludingPositioning( m_aModel->getModel(), true, true ) )
925*cdf0e10cSrcweir         aUndoGuard.commit();
926*cdf0e10cSrcweir }
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir } //  namespace chart
929