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