LibreOffice Module chart2 (master) 1
ChartController_Tools.cxx
Go to the documentation of this file.
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#include <ChartController.hxx>
21#include <ChartWindow.hxx>
22#include <ChartModel.hxx>
23#include <ChartModelHelper.hxx>
24#include <ChartType.hxx>
25#include <TitleHelper.hxx>
26#include <ThreeDHelper.hxx>
27#include <DataSeries.hxx>
28#include <DataSeriesHelper.hxx>
29#include "UndoGuard.hxx"
31#include <ResId.hxx>
32#include <strings.hrc>
33#include <ObjectIdentifier.hxx>
36#include "ChartTransferable.hxx"
37#include <DrawViewWrapper.hxx>
38#include <Legend.hxx>
39#include <LegendHelper.hxx>
40#include <Axis.hxx>
41#include <AxisHelper.hxx>
44#include "ShapeController.hxx"
45#include <DiagramHelper.hxx>
46#include <Diagram.hxx>
48#include <unonames.hxx>
49
50#include <com/sun/star/chart2/DataPointLabel.hpp>
51#include <com/sun/star/beans/XPropertyState.hpp>
52#include <com/sun/star/graphic/XGraphic.hpp>
53#include <com/sun/star/drawing/TextVerticalAdjust.hpp>
54#include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
55#include <com/sun/star/chart/ErrorBarStyle.hpp>
56#include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
57
58#include <editeng/editview.hxx>
59#include <editeng/outliner.hxx>
61#include <vcl/transfer.hxx>
62#include <sot/storage.hxx>
63#include <vcl/graph.hxx>
65#include <svx/unomodel.hxx>
66#include <svx/svdmodel.hxx>
68#include <vcl/svapp.hxx>
69#include <svx/dialmgr.hxx>
70#include <svx/strings.hrc>
71#include <svx/svditer.hxx>
72#include <svx/svdpage.hxx>
73#include <svx/svdundo.hxx>
74#include <svx/unoapi.hxx>
75#include <svx/unopage.hxx>
76#include <svx/unoshape.hxx>
77#include <PropertyHelper.hxx>
78
79#include <LibreOfficeKit/LibreOfficeKitEnums.h>
80#include <tools/debug.hxx>
83
84#include <memory>
85
86using namespace ::com::sun::star;
87
88using ::com::sun::star::uno::Reference;
89using ::com::sun::star::uno::Sequence;
90
91namespace chart
92{
93
94namespace
95{
96
97bool lcl_deleteDataSeries(
98 std::u16string_view rCID,
100 const Reference< document::XUndoManager > & xUndoManager )
101{
102 bool bResult = false;
104 if( xSeries.is() && xModel.is())
105 {
107 DataSeriesHelper::getChartTypeOfSeries( xSeries, xModel->getFirstChartDiagram());
108 if( xChartType.is())
109 {
110 UndoGuard aUndoGuard(
113 xUndoManager );
114
115 rtl::Reference< Diagram > xDiagram = xModel->getFirstChartDiagram();
116 rtl::Reference< Axis > xAxis = xDiagram->getAttachedAxis( xSeries );
117
118 DataSeriesHelper::deleteSeries( xSeries, xChartType );
119
121
122 bResult = true;
123 aUndoGuard.commit();
124 }
125 }
126 return bResult;
127}
128
129bool lcl_deleteDataCurve(
130 std::u16string_view rCID,
132 const Reference< document::XUndoManager > & xUndoManager )
133{
134 bool bResult = false;
135
136 uno::Reference< beans::XPropertySet > xProperties(
138
139 uno::Reference< chart2::XRegressionCurve > xRegressionCurve( xProperties, uno::UNO_QUERY );
140
141 if( xRegressionCurve.is())
142 {
143 uno::Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer(
145 ObjectIdentifier::getFullParentParticle( rCID ), xModel), uno::UNO_QUERY );
146
147 if( xRegressionCurveContainer.is())
148 {
149 UndoGuard aUndoGuard(
152 xUndoManager );
153
154 xRegressionCurveContainer->removeRegressionCurve( xRegressionCurve );
155
156 bResult = true;
157 aUndoGuard.commit();
158 }
159 }
160 return bResult;
161}
162
163} // anonymous namespace
164
165std::unique_ptr<ReferenceSizeProvider> ChartController::impl_createReferenceSizeProvider()
166{
167 awt::Size aPageSize( ChartModelHelper::getPageSize( getChartModel() ) );
168
169 return std::make_unique<ReferenceSizeProvider>(aPageSize, getChartModel());
170}
171
173{
174 std::unique_ptr<ReferenceSizeProvider> pRefSizeProvider(impl_createReferenceSizeProvider());
175 if (pRefSizeProvider)
176 pRefSizeProvider->setValuesAtAllDataSeries();
177}
178
180{
181 // remove manual positions at titles, legend and the diagram, remove manual
182 // size at the diagram
183
184 try
185 {
187 rtl::Reference< Diagram > xDiagram = xModel->getFirstChartDiagram();
188 if( xDiagram.is())
189 {
190 UndoGuard aUndoGuard(
191 SchResId( STR_ACTION_REARRANGE_CHART ),
193 ControllerLockGuardUNO aCtlLockGuard( xModel );
194
195 // diagram
196 xDiagram->setPropertyToDefault( "RelativeSize");
197 xDiagram->setPropertyToDefault( "RelativePosition");
198 xDiagram->setPropertyToDefault( "PosSizeExcludeAxes");
199
200 // 3d rotation
201 xDiagram->set3DSettingsToDefault();
202
203 // legend
204 rtl::Reference< Legend > xLegend = xDiagram->getLegend2();
205 if( xLegend.is())
206 {
207 xLegend->setPropertyToDefault( "RelativePosition");
208 xLegend->setPropertyToDefault( "RelativeSize");
209 xLegend->setPropertyToDefault( "AnchorPosition");
210 }
211
212 // titles
213 for( sal_Int32 eType = TitleHelper::TITLE_BEGIN;
215 ++eType )
216 {
217 rtl::Reference< Title > xTitleState =
219 static_cast< TitleHelper::eTitleType >( eType ), xModel );
220 if( xTitleState.is())
221 xTitleState->setPropertyToDefault( "RelativePosition");
222 }
223
224 // regression curve equations
225 std::vector< rtl::Reference< RegressionCurveModel > > aRegressionCurves =
226 xDiagram->getAllRegressionCurvesNotMeanValueLine();
227
228 // reset equation position
229 for( const auto& xCurve : aRegressionCurves )
231
232 aUndoGuard.commit();
233 }
234 }
235 catch( const uno::RuntimeException & )
236 {
237 DBG_UNHANDLED_EXCEPTION("chart2");
238 }
239}
240
242{
243 SolarMutexGuard aSolarGuard;
244 UndoGuard aUndoGuard(
245 SchResId( STR_ACTION_SCALE_TEXT ),
247 ControllerLockGuardUNO aCtlLockGuard( getChartModel() );
248
249 std::unique_ptr<ReferenceSizeProvider> pRefSizeProv(impl_createReferenceSizeProvider());
250 OSL_ASSERT(pRefSizeProv);
251 if (pRefSizeProv)
252 pRefSizeProv->toggleAutoResizeState();
253
254 aUndoGuard.commit();
255}
256
258{
259 SolarMutexGuard aGuard;
260 auto pChartWindow(GetChartWindow());
261 if( !pChartWindow )
262 return;
263
264 Graphic aGraphic;
265 // paste location: center of window
266 Point aPos = pChartWindow->PixelToLogic( tools::Rectangle( {}, pChartWindow->GetSizePixel()).Center());
267
268 // handle different formats
270 if( aDataHelper.GetTransferable().is())
271 {
272 if ( aDataHelper.HasFormat( SotClipboardFormatId::DRAWING ) )
273 {
275 if ( aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING, xStm ) )
276 {
277 xStm->Seek( 0 );
278 Reference< io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ) );
279
280 std::unique_ptr< SdrModel > spModel(
281 new SdrModel());
282
283 if ( SvxDrawingLayerImport( spModel.get(), xInputStream ) )
284 {
285 impl_PasteShapes( spModel.get() );
286 }
287 }
288 }
289 else if ( aDataHelper.HasFormat( SotClipboardFormatId::SVXB ) )
290 {
291 // graphic exchange format (graphic manager bitmap format?)
293 if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB, xStm ))
294 {
295 TypeSerializer aSerializer(*xStm);
296 aSerializer.readGraphic(aGraphic);
297 }
298 }
299 else if( aDataHelper.HasFormat( SotClipboardFormatId::GDIMETAFILE ))
300 {
301 // meta file
302 GDIMetaFile aMetafile;
303 if( aDataHelper.GetGDIMetaFile( SotClipboardFormatId::GDIMETAFILE, aMetafile ))
304 aGraphic = Graphic( aMetafile );
305 }
306 else if( aDataHelper.HasFormat( SotClipboardFormatId::BITMAP ))
307 {
308 // bitmap (non-graphic-manager)
309 BitmapEx aBmpEx;
310 if( aDataHelper.GetBitmapEx( SotClipboardFormatId::BITMAP, aBmpEx ))
311 aGraphic = Graphic( aBmpEx );
312 }
313 else if( aDataHelper.HasFormat( SotClipboardFormatId::STRING ))
314 {
315 OUString aString;
316 if( aDataHelper.GetString( SotClipboardFormatId::STRING, aString ) && m_pDrawModelWrapper )
317 {
319 {
320 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
321 if( pOutlinerView )//in case of edit mode insert into edited string
322 pOutlinerView->InsertText( aString );
323 else
324 {
325 impl_PasteStringAsTextShape( aString, awt::Point( 0, 0 ) );
326 }
327 }
328 }
329 }
330 }
331
332 if( aGraphic.GetType() != GraphicType::NONE )
333 {
334 Reference< graphic::XGraphic > xGraphic( aGraphic.GetXGraphic());
335 if( xGraphic.is())
336 impl_PasteGraphic( xGraphic, aPos );
337 }
338}
339
340// note: aPosition is ignored for now. The object is always pasted centered to
341// the page
344 const ::Point & /* aPosition */ )
345{
347 // note: the XPropertySet of the model is the old API. Also the property
348 // "AdditionalShapes" that is used there.
350 DrawModelWrapper * pDrawModelWrapper( GetDrawModelWrapper());
351 if( ! (xGraphic.is() && xModel.is()))
352 return;
353 rtl::Reference<SvxGraphicObject> xGraphicShape = new SvxGraphicObject(nullptr);
354 xGraphicShape->setShapeKind(SdrObjKind::Graphic);
355
356 uno::Reference< drawing::XShapes > xPage = pDrawModelWrapper->getMainDrawPage();
357 if( xPage.is())
358 {
359 xPage->add( xGraphicShape );
360 //need to change the model state manually
361 xModel->setModified( true );
362 //select new shape
363 m_aSelection.setSelection( xGraphicShape );
365 }
366 xGraphicShape->SvxShape::setPropertyValue( "Graphic", uno::Any( xGraphic ));
367
368 awt::Size aGraphicSize( 1000, 1000 );
369 bool bGotGraphicSize = false;
370 try
371 {
372 bGotGraphicSize = xGraphicShape->SvxShape::getPropertyValue( "Size100thMM") >>= aGraphicSize;
373 }
374 catch (css::beans::UnknownPropertyException& )
375 {}
376 auto pChartWindow(GetChartWindow());
377 // first try size in 100th mm, then pixel size
378 if( !bGotGraphicSize )
379 {
380 bool bGotSizePixel = false;
381 try
382 {
383 bGotSizePixel = xGraphicShape->SvxShape::getPropertyValue( "SizePixel") >>= aGraphicSize;
384 }
385 catch (css::beans::UnknownPropertyException& )
386 {}
387 if ( bGotSizePixel && pChartWindow )
388 {
389 ::Size aVCLSize( pChartWindow->PixelToLogic( Size( aGraphicSize.Width, aGraphicSize.Height )));
390 aGraphicSize.Width = aVCLSize.getWidth();
391 aGraphicSize.Height = aVCLSize.getHeight();
392 }
393 }
394 xGraphicShape->setSize( aGraphicSize );
395 xGraphicShape->setPosition( awt::Point( 0, 0 ) );
396}
397
399{
400 DrawModelWrapper* pDrawModelWrapper( GetDrawModelWrapper() );
401 if ( !(pDrawModelWrapper && m_pDrawViewWrapper) )
402 return;
403
404 Reference< drawing::XDrawPage > xDestPage( pDrawModelWrapper->getMainDrawPage() );
405 SdrPage* pDestPage = GetSdrPageFromXDrawPage( xDestPage );
406 if ( !pDestPage )
407 return;
408
410 m_pDrawViewWrapper->BegUndo( SvxResId( RID_SVX_3D_UNDO_EXCHANGE_PASTE ) );
411 sal_uInt16 nCount = pModel->GetPageCount();
412 for ( sal_uInt16 i = 0; i < nCount; ++i )
413 {
414 const SdrPage* pPage = pModel->GetPage( i );
415 SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
416 while ( aIter.IsMore() )
417 {
418 SdrObject* pObj(aIter.Next());
419 // Clone to new SdrModel
421 if (pObj)
422 pNewObj = pObj->CloneSdrObject(pDrawModelWrapper->getSdrModel());
423
424 if ( pNewObj )
425 {
426 // set position
427 Reference< drawing::XShape > xShape( pNewObj->getUnoShape(), uno::UNO_QUERY );
428 if ( xShape.is() )
429 {
430 xShape->setPosition( awt::Point( 0, 0 ) );
431 }
432
433 pDestPage->InsertObject( pNewObj.get() );
434 m_pDrawViewWrapper->AddUndo( std::make_unique<SdrUndoInsertObj>( *pNewObj ) );
435 xSelShape = xShape;
436 }
437 }
438 }
439
441 if ( xModifiable.is() )
442 {
443 xModifiable->setModified( true );
444 }
445
446 // select last inserted shape
447 m_aSelection.setSelection( xSelShape );
449
450 m_pDrawViewWrapper->EndUndo();
451
453}
454
455void ChartController::impl_PasteStringAsTextShape( const OUString& rString, const awt::Point& rPosition )
456{
457 DrawModelWrapper* pDrawModelWrapper( GetDrawModelWrapper() );
458 if ( !(pDrawModelWrapper && m_pDrawViewWrapper) )
459 return;
460
461 const Reference< drawing::XDrawPage >& xDrawPage( pDrawModelWrapper->getMainDrawPage() );
462 OSL_ASSERT( xDrawPage.is() );
463
464 if ( !xDrawPage )
465 return;
466
467 try
468 {
469 rtl::Reference<SvxShapeText> xTextShape = new SvxShapeText(nullptr);
470 xTextShape->setShapeKind(SdrObjKind::Text);
471 xDrawPage->add( xTextShape );
472
473 xTextShape->setString( rString );
474
475 float fCharHeight = 10.0;
476 xTextShape->SvxShape::setPropertyValue( "TextAutoGrowHeight", uno::Any( true ) );
477 xTextShape->SvxShape::setPropertyValue( "TextAutoGrowWidth", uno::Any( true ) );
478 xTextShape->SvxShape::setPropertyValue( "CharHeight", uno::Any( fCharHeight ) );
479 xTextShape->SvxShape::setPropertyValue( "CharHeightAsian", uno::Any( fCharHeight ) );
480 xTextShape->SvxShape::setPropertyValue( "CharHeightComplex", uno::Any( fCharHeight ) );
481 xTextShape->SvxShape::setPropertyValue( "TextVerticalAdjust", uno::Any( drawing::TextVerticalAdjust_CENTER ) );
482 xTextShape->SvxShape::setPropertyValue( "TextHorizontalAdjust", uno::Any( drawing::TextHorizontalAdjust_CENTER ) );
483 xTextShape->SvxShape::setPropertyValue( "CharFontName", uno::Any( OUString("Albany") ) );
484
485 xTextShape->setPosition( rPosition );
486
487 m_aSelection.setSelection( xTextShape );
489
490 SdrObject* pObj = DrawViewWrapper::getSdrObject( xTextShape );
491 if ( pObj )
492 {
493 m_pDrawViewWrapper->BegUndo( SvxResId( RID_SVX_3D_UNDO_EXCHANGE_PASTE ) );
494 m_pDrawViewWrapper->AddUndo( std::make_unique<SdrUndoInsertObj>( *pObj ) );
495 m_pDrawViewWrapper->EndUndo();
496
498 }
499 }
500 catch ( const uno::Exception& )
501 {
502 DBG_UNHANDLED_EXCEPTION("chart2");
503 }
504}
505
507{
508 SolarMutexGuard aSolarGuard;
510 return;
511
512 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
513 if (pOutlinerView)
514 pOutlinerView->Copy();
515 else
516 {
517 SdrObject* pSelectedObj = nullptr;
519
520 if (aSelOID.isAutoGeneratedObject())
521 pSelectedObj = m_pDrawModelWrapper->getNamedSdrObject( aSelOID.getObjectCID() );
522 else if (aSelOID.isAdditionalShape())
523 pSelectedObj = DrawViewWrapper::getSdrObject( aSelOID.getAdditionalShape() );
524
525 if (pSelectedObj)
526 {
528 if (xClipboard.is())
529 {
531 new ChartTransferable(m_pDrawModelWrapper->getSdrModel(),
532 pSelectedObj, aSelOID.isAdditionalShape()));
533 xClipboard->setContents(xTransferable, Reference< datatransfer::clipboard::XClipboardOwner >());
534 }
535 }
536 }
537}
538
540{
543}
544
546{
547 ObjectIdentifier aSelOID( rSelection );
548 if ( aSelOID.isAutoGeneratedObject() )
549 {
550 const OUString& aSelObjCID( aSelOID.getObjectCID() );
551 ObjectType aObjectType(ObjectIdentifier::getObjectType( aSelObjCID ));
552
553 switch(aObjectType)
554 {
555 case OBJECTTYPE_TITLE:
567 case OBJECTTYPE_AXIS:
568 case OBJECTTYPE_GRID:
570 return true;
571 default:
572 break;
573 }
574 }
575 else if ( aSelOID.isAdditionalShape() )
576 {
577 return true;
578 }
579
580 return false;
581}
582
584{
586 ( m_pDrawViewWrapper && m_pDrawViewWrapper->AreObjectsMarked() &&
587 ( m_pDrawViewWrapper->GetCurrentObjIdentifier() == SdrObjKind::Text ) );
588}
589
591{
593 {
596 }
597}
598
600{
601 bool bReturn = false;
602
603 // remove the selected object
604 OUString aCID( m_aSelection.getSelectedCID() );
605 if( !aCID.isEmpty() )
606 {
607 if( !isObjectDeleteable( uno::Any( aCID ) ) )
608 return false;
609
610 //remove chart object
612 if( !xChartDoc.is() )
613 return false;
614
615 ObjectType aObjectType( ObjectIdentifier::getObjectType( aCID ));
616 switch( aObjectType )
617 {
618 case OBJECTTYPE_TITLE:
619 {
620 UndoGuard aUndoGuard(
626 bReturn = true;
627 aUndoGuard.commit();
628 break;
629 }
631 {
632 rtl::Reference< Diagram > xDiagram( xChartDoc->getFirstChartDiagram());
633 if( xDiagram.is())
634 {
635 rtl::Reference< Legend > xLegend( xDiagram->getLegend2() );
636 if( xLegend.is())
637 {
638 UndoGuard aUndoGuard(
642 xLegend->setPropertyValue( "Show", uno::Any( false ));
643 bReturn = true;
644 aUndoGuard.commit();
645 }
646 }
647 break;
648 }
649
651 bReturn = lcl_deleteDataSeries( aCID, getChartModel(), m_xUndoManager );
652 break;
653
655 {
658 if( eParentObjectType == OBJECTTYPE_DATA_SERIES )
659 {
660 bReturn = lcl_deleteDataSeries( aCID, getChartModel(), m_xUndoManager );
661 }
662 else if( eParentObjectType == OBJECTTYPE_DATA_CURVE )
663 {
664 sal_Int32 nEndPos = aCID.lastIndexOf(':');
665 OUString aParentCID = aCID.copy(0, nEndPos);
666
667 bReturn = lcl_deleteDataCurve(aParentCID, getChartModel(), m_xUndoManager );
668 }
669 else if( eParentObjectType == OBJECTTYPE_DATA_AVERAGE_LINE )
670 {
672 bReturn = true;
673 }
674 break;
675 }
676
678 {
681 ObjectIdentifier::getFullParentParticle( aCID ), getChartModel()), uno::UNO_QUERY );
682 if( xRegCurveCnt.is())
683 {
684 UndoGuard aUndoGuard(
686 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_AVERAGE_LINE )),
689 bReturn = true;
690 aUndoGuard.commit();
691 }
692 }
693 break;
694
696 {
697 bReturn = lcl_deleteDataCurve( aCID, getChartModel(), m_xUndoManager );
698 }
699 break;
700
702 {
705
706 if( xEqProp.is())
707 {
709 UndoGuard aUndoGuard(
711 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE_EQUATION )),
713 {
714 ControllerLockGuardUNO aCtlLockGuard( xModel );
715 xEqProp->setPropertyValue( "ShowEquation", uno::Any( false ));
716 xEqProp->setPropertyValue( "XName", uno::Any( OUString("x") ));
717 xEqProp->setPropertyValue( "YName", uno::Any( OUString("f(x)") ));
718 xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( false ));
719 }
720 bReturn = true;
721 aUndoGuard.commit();
722 }
723 }
724 break;
725
729 {
732 if( xErrorBarProp.is())
733 {
734 TranslateId pId;
735
736 if ( aObjectType == OBJECTTYPE_DATA_ERRORS_X )
737 pId = STR_OBJECT_ERROR_BARS_X;
738 else if ( aObjectType == OBJECTTYPE_DATA_ERRORS_Y )
739 pId = STR_OBJECT_ERROR_BARS_Y;
740 else
741 pId = STR_OBJECT_ERROR_BARS_Z;
742
744 UndoGuard aUndoGuard(
748 {
749 ControllerLockGuardUNO aCtlLockGuard( xModel );
750 xErrorBarProp->setPropertyValue(
751 "ErrorBarStyle",
752 uno::Any( css::chart::ErrorBarStyle::NONE ));
753 }
754 bReturn = true;
755 aUndoGuard.commit();
756 }
757 break;
758 }
759
762 {
763 uno::Reference< beans::XPropertySet > xObjectProperties =
765 if( xObjectProperties.is() )
766 {
767 UndoGuard aUndoGuard(
770 SchResId( aObjectType == OBJECTTYPE_DATA_LABEL ? STR_OBJECT_LABEL : STR_OBJECT_DATALABELS )),
772 chart2::DataPointLabel aLabel;
773 xObjectProperties->getPropertyValue(CHART_UNONAME_LABEL) >>= aLabel;
774 aLabel.ShowNumber = false;
775 aLabel.ShowNumberInPercent = false;
776 aLabel.ShowCategoryName = false;
777 aLabel.ShowLegendSymbol = false;
778 aLabel.ShowCustomLabel = false;
779 aLabel.ShowSeriesName = false;
780 if( aObjectType == OBJECTTYPE_DATA_LABELS )
781 {
785 }
786 else
787 {
788 xObjectProperties->setPropertyValue(CHART_UNONAME_LABEL, uno::Any(aLabel));
789 xObjectProperties->setPropertyValue(CHART_UNONAME_CUSTOM_LABEL_FIELDS, uno::Any());
790 }
791 bReturn = true;
792 aUndoGuard.commit();
793 }
794 break;
795 }
796 case OBJECTTYPE_AXIS:
797 {
799 bReturn = true;
800 break;
801 }
802 case OBJECTTYPE_GRID:
803 {
805 bReturn = true;
806 break;
807 }
809 {
811 bReturn = true;
812 break;
813 }
814
815 default:
816 {
817 break;
818 }
819 }
820 }
821 else
822 {
823 //remove additional shape
825 {
826 SolarMutexGuard aSolarGuard;
827 if ( m_pDrawViewWrapper )
828 {
829 m_pDrawViewWrapper->DeleteMarked();
830 bReturn = true;
831 }
832 }
833 }
834 return bReturn;
835}
836
838{
840 UndoGuard aUndoGuard(
841 SchResId( STR_ACTION_TOGGLE_LEGEND ), m_xUndoManager );
843 bool bChanged = false;
844 if( xLegendProp.is())
845 {
846 try
847 {
848 bool bShow = false;
849 if( xLegendProp->getPropertyValue( "Show") >>= bShow )
850 {
851 xLegendProp->setPropertyValue( "Show", uno::Any( ! bShow ));
852 bChanged = true;
853 }
854 }
855 catch( const uno::Exception & )
856 {
857 DBG_UNHANDLED_EXCEPTION("chart2");
858 }
859 }
860 else
861 {
862 xLegendProp = LegendHelper::getLegend(*xModel, m_xCC, true);
863 if( xLegendProp.is())
864 bChanged = true;
865 }
866
867 if( bChanged )
868 aUndoGuard.commit();
869}
870
872{
873 UndoGuard aUndoGuard(
874 SchResId( STR_ACTION_TOGGLE_GRID_HORZ ), m_xUndoManager );
876 if( !xDiagram.is())
877 return;
878
879 sal_Int32 nDimensionIndex = 1;
880 sal_Int32 nCooSysIndex = 0;
881
882 bool bHasMajorYGrid = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, true, xDiagram );
883 bool bHasMinorYGrid = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, false, xDiagram );
884
885 if( bHasMajorYGrid )
886 {
887 if ( bHasMinorYGrid )
888 {
889 AxisHelper::hideGrid( nDimensionIndex, nCooSysIndex, true, xDiagram );
890 AxisHelper::hideGrid( nDimensionIndex, nCooSysIndex, false, xDiagram );
891 }
892 else
893 {
894 AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, false, xDiagram );
895 }
896 }
897 else
898 {
899 AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, true, xDiagram );
900 }
901 aUndoGuard.commit();
902}
903
905{
906 UndoGuard aUndoGuard(
907 SchResId( STR_ACTION_TOGGLE_GRID_VERTICAL ), m_xUndoManager );
909 if( !xDiagram.is())
910 return;
911
912 sal_Int32 nDimensionIndex = 0;
913 sal_Int32 nCooSysIndex = 0;
914
915 bool bHasMajorXGrid = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, true, xDiagram );
916 bool bHasMinorXGrid = AxisHelper::isGridShown( nDimensionIndex, nCooSysIndex, false, xDiagram );
917 if( bHasMajorXGrid )
918 {
919 if (bHasMinorXGrid)
920 {
921 AxisHelper::hideGrid( nDimensionIndex, nCooSysIndex, true, xDiagram );
922 AxisHelper::hideGrid( nDimensionIndex, nCooSysIndex, false, xDiagram );
923 }
924 else
925 {
926 AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, false, xDiagram );
927 }
928 }
929 else
930 {
931 AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, true, xDiagram );
932 }
933
934 aUndoGuard.commit();
935}
936
938{
939 try
940 {
941 OUString aCID( m_aSelection.getSelectedCID() );
943 if( xChartModel.is() )
944 {
945 Reference< beans::XPropertySet > xPointProperties(
946 ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
947 if( xPointProperties.is() )
948 xPointProperties->setPropertyValue( "FillColor", uno::Any( nColor ) );
949 }
950 }
951 catch( const uno::Exception& )
952 {
953 DBG_UNHANDLED_EXCEPTION( "chart2" );
954 }
955}
956
957void ChartController::executeDispatch_FillGradient(std::u16string_view sJSONGradient)
958{
959 basegfx::BGradient aBGradient = basegfx::BGradient::fromJSON(sJSONGradient);
960 css::awt::Gradient aGradient = aBGradient.getAsGradient2();
961
962 try
963 {
964 OUString aCID( m_aSelection.getSelectedCID() );
966
967 if( xChartModel.is() )
968 {
970 ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
971
972 if( xPropSet.is() )
973 {
974 OUString aPrefferedName =
975 OUString::number(static_cast<sal_Int32>(Color(aBGradient.GetColorStops().front().getStopColor())))
976 + OUString::number(static_cast<sal_Int32>(Color(aBGradient.GetColorStops().back().getStopColor())))
977 + OUString::number(static_cast<sal_Int32>(aBGradient.GetAngle().get()));
978
979 OUString aNewName = PropertyHelper::addGradientUniqueNameToTable(css::uno::Any(aGradient),
980 xChartModel,
981 aPrefferedName);
982
983 xPropSet->setPropertyValue("FillGradientName", css::uno::Any(aNewName));
984 }
985 }
986 }
987 catch( const uno::Exception & )
988 {
989 TOOLS_WARN_EXCEPTION("chart2", "" );
990 }
991}
992
994{
995 try
996 {
997 OUString aCID( m_aSelection.getSelectedCID() );
999 if( xChartModel.is() )
1000 {
1002 ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
1003
1006 {
1007 css::uno::Reference<css::chart2::XDiagram> xDiagram(
1008 xPropSet, css::uno::UNO_QUERY);
1009 if (xDiagram.is())
1010 xPropSet.set(xDiagram->getWall());
1011 }
1012
1013 if( xPropSet.is() )
1014 xPropSet->setPropertyValue( "LineColor", css::uno::Any( Color(ColorTransparency, nColor) ) );
1015 }
1016 }
1017 catch( const uno::Exception& )
1018 {
1019 DBG_UNHANDLED_EXCEPTION( "chart2" );
1020 }
1021}
1022
1024{
1025 try
1026 {
1027 OUString aCID( m_aSelection.getSelectedCID() );
1029 if( xChartModel.is() )
1030 {
1032 ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
1033
1036 {
1037 css::uno::Reference<css::chart2::XDiagram> xDiagram(
1038 xPropSet, css::uno::UNO_QUERY);
1039 if (xDiagram.is())
1040 xPropSet.set(xDiagram->getWall());
1041 }
1042
1043 if( xPropSet.is() )
1044 xPropSet->setPropertyValue( "LineWidth", css::uno::Any( nWidth ) );
1045 }
1046 }
1047 catch( const uno::Exception& )
1048 {
1049 DBG_UNHANDLED_EXCEPTION( "chart2" );
1050 }
1051}
1052
1054{
1055 if (!m_pDrawViewWrapper)
1056 return;
1057
1058 if (!m_pDrawViewWrapper->IsTextEdit())
1059 return;
1060
1061 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
1062 if (!pOutlinerView)
1063 return;
1064
1065 EditView& rEditView = pOutlinerView->GetEditView();
1067 switch (nType)
1068 {
1069 case LOK_SETTEXTSELECTION_START:
1070 rEditView.SetCursorLogicPosition(aPoint, /*bPoint=*/false, /*bClearMark=*/false);
1071 break;
1072 case LOK_SETTEXTSELECTION_END:
1073 rEditView.SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/false);
1074 break;
1075 case LOK_SETTEXTSELECTION_RESET:
1076 rEditView.SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/true);
1077 break;
1078 default:
1079 assert(false);
1080 break;
1081 }
1082}
1083
1085{
1086 try
1087 {
1088 OUString aCID( m_aSelection.getSelectedCID() );
1090 if( xChartModel.is() )
1091 {
1092 Reference< beans::XPropertySet > xPointProperties(
1093 ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
1094 if( xPointProperties.is() )
1095 xPointProperties->setPropertyValue( "Offset", uno::Any( nOffset / 100.0 ) );
1096 }
1097 }
1098 catch( const uno::Exception & )
1099 {
1100 TOOLS_WARN_EXCEPTION("chart2", "" );
1101 }
1102}
1103
1105{
1107 if ( xDispatch.is() )
1108 {
1109 xDispatch->dispatch( rURL, rArgs );
1110 }
1111}
1112
1114{
1120 aUndoGuard.commit();
1121}
1122
1123} // namespace chart
1124
1125/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr auto convertTwipToMm100(N n)
static OUString createDescription(ActionType eActionType, std::u16string_view rObjectName)
void SetCursorLogicPosition(const Point &rPosition, bool bPoint, bool bClearMark)
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
GraphicType GetType() const
void InsertText(const OUString &rNew, bool bSelect=false)
EditView & GetEditView() const
const SdrPage * GetPage(sal_uInt16 nPgNum) const
sal_uInt16 GetPageCount() const
SdrObject * Next()
bool IsMore() const
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
virtual rtl::Reference< SdrObject > CloneSdrObject(SdrModel &rTargetModel) const=0
constexpr tools::Long getHeight() const
constexpr tools::Long getWidth() const
bool GetString(SotClipboardFormatId nFormat, OUString &rStr) const
bool GetSotStorageStream(SotClipboardFormatId nFormat, tools::SvRef< SotTempStream > &rStreamRef) const
bool GetGDIMetaFile(SotClipboardFormatId nFormat, GDIMetaFile &rMtf, size_t nMaxActions=0) const
static TransferableDataHelper CreateFromSystemClipboard(vcl::Window *pWindow)
bool HasFormat(SotClipboardFormatId nFormat) const
const css::uno::Reference< css::datatransfer::XTransferable > & GetTransferable() const
bool GetBitmapEx(SotClipboardFormatId nFormat, BitmapEx &rBmp) const
void readGraphic(Graphic &rGraphic)
const basegfx::BColorStops & GetColorStops() const
css::awt::Gradient2 getAsGradient2() const
Degree10 GetAngle() const
static BGradient fromJSON(std::u16string_view rJSON)
static void hideGrid(sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid, const rtl::Reference< ::chart::Diagram > &xDiagram)
Definition: AxisHelper.cxx:493
static void hideAxisIfNoDataIsAttached(const rtl::Reference< ::chart::Axis > &xAxis, const rtl::Reference< ::chart::Diagram > &xDiagram)
Definition: AxisHelper.cxx:475
static bool isGridShown(sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid, const rtl::Reference< ::chart::Diagram > &xDiagram)
Definition: AxisHelper.cxx:525
static void showGrid(sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid, const rtl::Reference< ::chart::Diagram > &xDiagram)
Definition: AxisHelper.cxx:414
void executeDispatch_LineColor(sal_uInt32 nColor)
rtl::Reference<::chart::ChartModel > getChartModel()
void executeDispatch_FillGradient(std::u16string_view sJSONGradient)
std::unique_ptr< DrawViewWrapper > m_pDrawViewWrapper
css::uno::Reference< css::document::XUndoManager > m_xUndoManager
void executeDispatch_LOKPieSegmentDragging(int nOffset)
std::unique_ptr< ReferenceSizeProvider > impl_createReferenceSizeProvider()
void executeDispatch_FillColor(sal_uInt32 nColor)
void executeDispatch_LOKSetTextSelection(int nType, int nX, int nY)
ChartWindow * GetChartWindow() const
void impl_PasteGraphic(css::uno::Reference< css::graphic::XGraphic > const &xGraphic, const ::Point &aPosition)
std::shared_ptr< DrawModelWrapper > m_pDrawModelWrapper
DrawModelWrapper * GetDrawModelWrapper()
CommandDispatchContainer m_aDispatchContainer
void impl_switchDiagramPositioningToExcludingPositioning()
void executeDispatch_LineWidth(sal_uInt32 nWidth)
static bool isObjectDeleteable(const css::uno::Any &rSelection)
rtl::Reference<::chart::Diagram > getFirstDiagram()
void impl_ShapeControllerDispatch(const css::util::URL &rURL, const css::uno::Sequence< css::beans::PropertyValue > &rArgs)
void impl_PasteShapes(SdrModel *pModel)
css::uno::Reference< css::uno::XComponentContext > m_xCC
void impl_PasteStringAsTextShape(const OUString &rString, const css::awt::Point &rPosition)
static css::awt::Size getPageSize(const rtl::Reference<::chart::ChartModel > &xModel)
This guard calls lockControllers at the given Model in the CTOR and unlockControllers in the DTOR.
static bool switchDiagramPositioningToExcludingPositioning(ChartModel &rModel, bool bResetModifiedState, bool bConvertAlsoFromAutoPositioning)
const rtl::Reference< SvxDrawPage > & getMainDrawPage()
static SdrObject * getSdrObject(const css::uno::Reference< css::drawing::XShape > &xShape)
static rtl::Reference< ::chart::Legend > getLegend(ChartModel &rModel, const css::uno::Reference< css::uno::XComponentContext > &xContext=nullptr, bool bCreate=false)
static rtl::Reference< ::chart::DataSeries > getDataSeriesForCID(std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel > &xChartModel)
const OUString & getObjectCID() const
static TitleHelper::eTitleType getTitleTypeForCID(std::u16string_view rCID)
const css::uno::Reference< css::drawing::XShape > & getAdditionalShape() const
static css::uno::Reference< css::beans::XPropertySet > getObjectPropertySet(std::u16string_view rObjectCID, const rtl::Reference< ::chart::ChartModel > &xChartDocument)
static std::u16string_view getFullParentParticle(std::u16string_view rCID)
ObjectType getObjectType() const
static OUString getName(ObjectType eObjectType, bool bPlural=false)
bool hasSelection() const
bool isAdditionalShapeSelected() const
const ObjectIdentifier & getSelectedOID() const
OUString const & getSelectedCID() const
void applySelection(DrawViewWrapper *pDrawViewWrapper)
bool setSelection(const OUString &rCID)
static void removeTitle(eTitleType nTitleIndex, const rtl::Reference< ::chart::ChartModel > &xModel)
static rtl::Reference< ::chart::Title > getTitle(eTitleType nTitleIndex, ChartModel &rModel)
A guard which does nothing, unless you explicitly call commitAction.
Definition: UndoGuard.hxx:37
ColorTransparency
int nCount
#define DBG_TESTSOLARMUTEX()
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
SVXCORE_DLLPUBLIC OUString SvxResId(TranslateId aId)
Reference< XDispatch > xDispatch
DocumentType eType
OOO_DLLPUBLIC_CHARTTOOLS void setPropertyAlsoToAllAttributedDataPoints(const rtl::Reference< ::chart::DataSeries > &xSeries, const OUString &rPropertyName, const css::uno::Any &rPropertyValue)
OOO_DLLPUBLIC_CHARTTOOLS void deleteSeries(const rtl::Reference< ::chart::DataSeries > &xSeries, const rtl::Reference< ::chart::ChartType > &xChartType)
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference< ::chart::ChartType > getChartTypeOfSeries(const rtl::Reference< ::chart::DataSeries > &xSeries, const rtl::Reference< ::chart::Diagram > &xDiagram)
OOO_DLLPUBLIC_CHARTTOOLS OUString addGradientUniqueNameToTable(const css::uno::Any &rValue, const css::uno::Reference< css::lang::XMultiServiceFactory > &xFact, const OUString &rPreferredName)
adds a gradient with a unique name to the gradient obtained by the given factory.
OOO_DLLPUBLIC_CHARTTOOLS void resetEquationPosition(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS void removeMeanValueLine(css::uno::Reference< css::chart2::XRegressionCurveContainer > const &xRegCnt)
@ OBJECTTYPE_DATA_SERIES
@ OBJECTTYPE_DATA_LABELS
@ OBJECTTYPE_DIAGRAM
@ OBJECTTYPE_LEGEND_ENTRY
@ OBJECTTYPE_DATA_ERRORS_X
@ OBJECTTYPE_SUBGRID
@ OBJECTTYPE_DATA_ERRORS_Y
@ OBJECTTYPE_DATA_CURVE_EQUATION
@ OBJECTTYPE_DATA_AVERAGE_LINE
@ OBJECTTYPE_DATA_ERRORS_Z
@ OBJECTTYPE_DATA_CURVE
@ OBJECTTYPE_DATA_LABEL
OUString OOO_DLLPUBLIC_CHARTTOOLS SchResId(TranslateId aId)
Definition: ResId.cxx:24
int i
QPRO_FUNC_TYPE nType
UNDERLYING_TYPE get() const
Reference< XModel > xModel
Center
OUString aLabel
SVXCORE_DLLPUBLIC SdrPage * GetSdrPageFromXDrawPage(const css::uno::Reference< css::drawing::XDrawPage > &xDrawPage) noexcept
SVXCORE_DLLPUBLIC bool SvxDrawingLayerImport(SdrModel *pModel, const css::uno::Reference< css::io::XInputStream > &xInputStream)
constexpr OUStringLiteral CHART_UNONAME_CUSTOM_LABEL_FIELDS
Definition: unonames.hxx:36
constexpr OUStringLiteral CHART_UNONAME_LABEL
Definition: unonames.hxx:24