diff options
Diffstat (limited to 'chart2/source/controller/main/ChartController_Tools.cxx')
-rw-r--r-- | chart2/source/controller/main/ChartController_Tools.cxx | 560 |
1 files changed, 411 insertions, 149 deletions
diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx index 7b9c28de63e5..0539106c18d8 100644 --- a/chart2/source/controller/main/ChartController_Tools.cxx +++ b/chart2/source/controller/main/ChartController_Tools.cxx @@ -20,9 +20,9 @@ #include <ChartController.hxx> #include <ChartWindow.hxx> #include <ChartModel.hxx> -#include <ChartModelHelper.hxx> +#include <ChartType.hxx> #include <TitleHelper.hxx> -#include <ThreeDHelper.hxx> +#include <DataSeries.hxx> #include <DataSeriesHelper.hxx> #include "UndoGuard.hxx" #include <ControllerLockGuard.hxx> @@ -33,8 +33,11 @@ #include <chartview/DrawModelWrapper.hxx> #include "ChartTransferable.hxx" #include <DrawViewWrapper.hxx> +#include <Legend.hxx> #include <LegendHelper.hxx> +#include <Axis.hxx> #include <AxisHelper.hxx> +#include <RegressionCurveModel.hxx> #include <RegressionCurveHelper.hxx> #include "ShapeController.hxx" #include <DiagramHelper.hxx> @@ -42,15 +45,16 @@ #include <ObjectNameProvider.hxx> #include <unonames.hxx> +#include <com/sun/star/awt/FontWeight.hpp> +#include <com/sun/star/awt/Gradient.hpp> #include <com/sun/star/chart2/DataPointLabel.hpp> -#include <com/sun/star/beans/XPropertyState.hpp> #include <com/sun/star/graphic/XGraphic.hpp> #include <com/sun/star/drawing/TextVerticalAdjust.hpp> #include <com/sun/star/drawing/TextHorizontalAdjust.hpp> #include <com/sun/star/chart/ErrorBarStyle.hpp> #include <com/sun/star/chart2/XRegressionCurveContainer.hpp> -#include <com/sun/star/chart2/XChartDocument.hpp> +#include <docmodel/uno/UnoGradientTools.hxx> #include <editeng/editview.hxx> #include <editeng/outliner.hxx> #include <svx/ActionDescriptionProvider.hxx> @@ -70,12 +74,11 @@ #include <svx/unoapi.hxx> #include <svx/unopage.hxx> #include <svx/unoshape.hxx> -#include <svx/xgrad.hxx> #include <PropertyHelper.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <tools/debug.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <tools/UnitConversion.hxx> #include <memory> @@ -92,16 +95,16 @@ namespace { bool lcl_deleteDataSeries( - const OUString & rCID, + std::u16string_view rCID, const rtl::Reference<::chart::ChartModel> & xModel, const Reference< document::XUndoManager > & xUndoManager ) { bool bResult = false; - uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rCID, xModel )); + rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rCID, xModel ); if( xSeries.is() && xModel.is()) { - uno::Reference< chart2::XChartType > xChartType( - DataSeriesHelper::getChartTypeOfSeries( xSeries, xModel->getFirstDiagram())); + rtl::Reference< ::chart::ChartType > xChartType = + DataSeriesHelper::getChartTypeOfSeries( xSeries, xModel->getFirstChartDiagram()); if( xChartType.is()) { UndoGuard aUndoGuard( @@ -109,10 +112,10 @@ bool lcl_deleteDataSeries( ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_DATASERIES )), xUndoManager ); - rtl::Reference< Diagram > xDiagram = ChartModelHelper::findDiagram( xModel ); - uno::Reference< chart2::XAxis > xAxis( DiagramHelper::getAttachedAxis( xSeries, xDiagram ) ); + rtl::Reference< Diagram > xDiagram = xModel->getFirstChartDiagram(); + rtl::Reference< Axis > xAxis = xDiagram->getAttachedAxis( xSeries ); - DataSeriesHelper::deleteSeries( xSeries, xChartType ); + xChartType->deleteSeries( xSeries ); AxisHelper::hideAxisIfNoDataIsAttached( xAxis, xDiagram ); @@ -124,7 +127,7 @@ bool lcl_deleteDataSeries( } bool lcl_deleteDataCurve( - const OUString & rCID, + std::u16string_view rCID, const rtl::Reference<::chart::ChartModel> & xModel, const Reference< document::XUndoManager > & xUndoManager ) { @@ -157,20 +160,66 @@ bool lcl_deleteDataCurve( return bResult; } +bool lcl_arePropertiesSame(const std::vector<Reference<beans::XPropertySet>>& xProperties, + OUString& aPropName) +{ + if (xProperties.size() == 1) + return true; + if (xProperties.size() < 1) + return false; + + uno::Any aValue = xProperties[0]->getPropertyValue(aPropName); + for (std::size_t i = 1; i < xProperties.size(); i++) + { + if (aValue != xProperties[i]->getPropertyValue(aPropName)) + return false; + } + return true; +} + +// Cf. ChartColorWrapper::operator() +std::pair<css::uno::Reference<css::beans::XPropertySet>, ObjectType> +getSelectedGraphObject(const css::uno::Any& rSelection, const rtl::Reference<ChartModel>& pModel) +{ + if (OUString sCID; rSelection >>= sCID) + { + auto xPropSet(ObjectIdentifier::getObjectPropertySet(sCID, pModel)); + ObjectType eType = ObjectIdentifier::getObjectType(sCID); + if (eType == ObjectType::OBJECTTYPE_DIAGRAM) + { + if (auto xDiagram = xPropSet.query<css::chart2::XDiagram>()) + { + xPropSet = xDiagram->getWall(); + eType = ObjectType::OBJECTTYPE_DIAGRAM_WALL; + } + } + + return { xPropSet, eType }; + } + + if (css::uno::Reference<css::beans::XPropertySet> xSelection; rSelection >>= xSelection) + return { xSelection, ObjectType::OBJECTTYPE_SHAPE }; + + return {}; +} + +css::uno::Reference<css::beans::XPropertySet> getSelectedGraphObject(ChartController& rController) +{ + return getSelectedGraphObject(rController.getSelection(), rController.getChartModel()).first; +} + } // anonymous namespace -std::unique_ptr<ReferenceSizeProvider> ChartController::impl_createReferenceSizeProvider() +ReferenceSizeProvider ChartController::impl_createReferenceSizeProvider() { - awt::Size aPageSize( ChartModelHelper::getPageSize( getChartModel() ) ); + awt::Size aPageSize( getChartModel()->getPageSize() ); - return std::make_unique<ReferenceSizeProvider>(aPageSize, getChartModel()); + return ReferenceSizeProvider(aPageSize, getChartModel()); } void ChartController::impl_adaptDataSeriesAutoResize() { - std::unique_ptr<ReferenceSizeProvider> pRefSizeProvider(impl_createReferenceSizeProvider()); - if (pRefSizeProvider) - pRefSizeProvider->setValuesAtAllDataSeries(); + impl_createReferenceSizeProvider().setValuesAtAllDataSeries(); } void ChartController::executeDispatch_NewArrangement() @@ -181,7 +230,7 @@ void ChartController::executeDispatch_NewArrangement() try { rtl::Reference<::chart::ChartModel> xModel( getChartModel() ); - rtl::Reference< Diagram > xDiagram = ChartModelHelper::findDiagram( xModel ); + rtl::Reference< Diagram > xDiagram = xModel->getFirstChartDiagram(); if( xDiagram.is()) { UndoGuard aUndoGuard( @@ -190,20 +239,20 @@ void ChartController::executeDispatch_NewArrangement() ControllerLockGuardUNO aCtlLockGuard( xModel ); // diagram - xDiagram->setPropertyToDefault( "RelativeSize"); - xDiagram->setPropertyToDefault( "RelativePosition"); - xDiagram->setPropertyToDefault( "PosSizeExcludeAxes"); + xDiagram->setPropertyToDefault( u"RelativeSize"_ustr); + xDiagram->setPropertyToDefault( u"RelativePosition"_ustr); + xDiagram->setPropertyToDefault( u"PosSizeExcludeAxes"_ustr); // 3d rotation - ThreeDHelper::set3DSettingsToDefault( xDiagram ); + xDiagram->set3DSettingsToDefault(); // legend - Reference< beans::XPropertyState > xLegendState( xDiagram->getLegend(), uno::UNO_QUERY ); - if( xLegendState.is()) + rtl::Reference< Legend > xLegend = xDiagram->getLegend2(); + if( xLegend.is()) { - xLegendState->setPropertyToDefault( "RelativePosition"); - xLegendState->setPropertyToDefault( "RelativeSize"); - xLegendState->setPropertyToDefault( "AnchorPosition"); + xLegend->setPropertyToDefault( u"RelativePosition"_ustr); + xLegend->setPropertyToDefault( u"RelativeSize"_ustr); + xLegend->setPropertyToDefault( u"AnchorPosition"_ustr); } // titles @@ -211,16 +260,16 @@ void ChartController::executeDispatch_NewArrangement() eType < TitleHelper::NORMAL_TITLE_END; ++eType ) { - Reference< beans::XPropertyState > xTitleState( + rtl::Reference< Title > xTitleState = TitleHelper::getTitle( - static_cast< TitleHelper::eTitleType >( eType ), xModel ), uno::UNO_QUERY ); + static_cast< TitleHelper::eTitleType >( eType ), xModel ); if( xTitleState.is()) - xTitleState->setPropertyToDefault( "RelativePosition"); + xTitleState->setPropertyToDefault( u"RelativePosition"_ustr); } // regression curve equations - std::vector< Reference< chart2::XRegressionCurve > > aRegressionCurves( - RegressionCurveHelper::getAllRegressionCurvesNotMeanValueLine( xDiagram )); + std::vector< rtl::Reference< RegressionCurveModel > > aRegressionCurves = + xDiagram->getAllRegressionCurvesNotMeanValueLine(); // reset equation position for( const auto& xCurve : aRegressionCurves ) @@ -243,14 +292,239 @@ void ChartController::executeDispatch_ScaleText() m_xUndoManager ); ControllerLockGuardUNO aCtlLockGuard( getChartModel() ); - std::unique_ptr<ReferenceSizeProvider> pRefSizeProv(impl_createReferenceSizeProvider()); - OSL_ASSERT(pRefSizeProv); - if (pRefSizeProv) - pRefSizeProv->toggleAutoResizeState(); + impl_createReferenceSizeProvider().toggleAutoResizeState(); aUndoGuard.commit(); } +void ChartController::executeDispatch_FontBold( + const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties) +{ + OUString aPropName = u"CharWeight"_ustr; + float nFontWeight = awt::FontWeight::NORMAL; + if (lcl_arePropertiesSame(xProperties, aPropName)) + { + xProperties[0]->getPropertyValue(aPropName) >>= nFontWeight; + } + nFontWeight = (nFontWeight == awt::FontWeight::NORMAL) ? awt::FontWeight::BOLD + : awt::FontWeight::NORMAL; + for (std::size_t i = 0; i < xProperties.size(); i++) + xProperties[i]->setPropertyValue(aPropName, uno::Any(nFontWeight)); +} + +void ChartController::executeDispatch_FontName( + const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties, + const css::uno::Sequence<css::beans::PropertyValue>& rArgs) +{ + // the sent font may have a lot of properties that we could set. + // but now we set only this + awt::FontDescriptor aFont; + rArgs[0].Value >>= aFont; + for (std::size_t i = 0; i < xProperties.size(); i++) + xProperties[i]->setPropertyValue(u"CharFontName"_ustr, css::uno::Any(aFont.Name)); +} + +void ChartController::executeDispatch_FontHeight( + const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties, + const css::uno::Sequence<css::beans::PropertyValue>& rArgs) +{ + for (std::size_t i = 0; i < xProperties.size(); i++) + xProperties[i]->setPropertyValue(u"CharHeight"_ustr, rArgs[0].Value); +} + +void ChartController::executeDispatch_FontItalic( + const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties) +{ + OUString aPropName = u"CharPosture"_ustr; + awt::FontSlant nFontItalic = awt::FontSlant::FontSlant_NONE; + if (lcl_arePropertiesSame(xProperties, aPropName)) + { + xProperties[0]->getPropertyValue(aPropName) >>= nFontItalic; + } + nFontItalic = (nFontItalic == awt::FontSlant::FontSlant_NONE ? awt::FontSlant::FontSlant_ITALIC + : awt::FontSlant::FontSlant_NONE); + for (std::size_t i = 0; i < xProperties.size(); i++) + xProperties[i]->setPropertyValue(aPropName, css::uno::Any(nFontItalic)); +} + +void ChartController::executeDispatch_FontUnderline( + const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties, + const css::uno::Sequence<css::beans::PropertyValue>& rArgs) +{ + OUString aPropName = u"CharUnderline"_ustr; + sal_Int16 nFontUnderline = 0; + sal_Int32 nFontUnderline32 = 0; + if (!(rArgs[0].Value >>= nFontUnderline) && (rArgs[0].Value >>= nFontUnderline32)) + { + nFontUnderline = nFontUnderline32; + } + else + { + if (lcl_arePropertiesSame(xProperties, aPropName)) + { + xProperties[0]->getPropertyValue(aPropName) >>= nFontUnderline; + } + nFontUnderline = (nFontUnderline == 0 ? 1 : 0); + } + + for (std::size_t i = 0; i < xProperties.size(); i++) + xProperties[i]->setPropertyValue(aPropName, css::uno::Any(nFontUnderline)); +} + +void ChartController::executeDispatch_FontStrikeout( + const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties) +{ + OUString aPropName = u"CharStrikeout"_ustr; + sal_Int16 nFontStrikeout = 0; + if (lcl_arePropertiesSame(xProperties, aPropName)) + { + xProperties[0]->getPropertyValue(aPropName) >>= nFontStrikeout; + } + nFontStrikeout = (nFontStrikeout == 0 ? 1 : 0); + for (std::size_t i = 0; i < xProperties.size(); i++) + xProperties[i]->setPropertyValue(aPropName, css::uno::Any(nFontStrikeout)); +} + +void ChartController::executeDispatch_FontShadowed( + const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties) +{ + OUString aPropName = u"CharShadowed"_ustr; + bool bFontShadowed = false; + if (lcl_arePropertiesSame(xProperties, aPropName)) + { + xProperties[0]->getPropertyValue(aPropName) >>= bFontShadowed; + } + for (std::size_t i = 0; i < xProperties.size(); i++) + xProperties[i]->setPropertyValue(u"CharShadowed"_ustr, css::uno::Any(!bFontShadowed)); +} + +void ChartController::executeDispatch_FontColor( + const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties, + const css::uno::Sequence<css::beans::PropertyValue>& rArgs) +{ + for (std::size_t i = 0; i < xProperties.size(); i++) + xProperties[i]->setPropertyValue(u"CharColor"_ustr, rArgs[0].Value); +} + +void ChartController::executeDispatch_FontGrow( + const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties) +{ + for (std::size_t i = 0; i < xProperties.size(); i++) + { + float nFontHeight = 0; + xProperties[i]->getPropertyValue(u"CharHeight"_ustr) >>= nFontHeight; + if (nFontHeight > 0) + { + nFontHeight = ceil(nFontHeight); //round + nFontHeight += 1; + if (nFontHeight > 999) + nFontHeight = 999; + xProperties[i]->setPropertyValue(u"CharHeight"_ustr, css::uno::Any(nFontHeight)); + } + } +} + +void ChartController::executeDispatch_FontShrink( + const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties) +{ + for (std::size_t i = 0; i < xProperties.size(); i++) + { + float nFontHeight = 0; + xProperties[i]->getPropertyValue(u"CharHeight"_ustr) >>= nFontHeight; + if (nFontHeight > 0) + { + if (nFontHeight - ceil(nFontHeight) >= 0.4) + nFontHeight = ceil(nFontHeight); //round + else + { + nFontHeight -= 1; + if (nFontHeight < 2) + nFontHeight = 2; + } + xProperties[i]->setPropertyValue(u"CharHeight"_ustr, css::uno::Any(nFontHeight)); + } + } +} + +void ChartController::executeDispatch_FontReset( + const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties) +{ + for (std::size_t i = 0; i < xProperties.size(); i++) + { + xProperties[i]->setPropertyValue(u"CharFontName"_ustr, + css::uno::Any(OUString("Liberation Sans"))); + xProperties[i]->setPropertyValue(u"CharHeight"_ustr, css::uno::Any(float(13))); + xProperties[i]->setPropertyValue(u"CharWeight"_ustr, uno::Any(float(100))); + xProperties[i]->setPropertyValue(u"CharPosture"_ustr, + css::uno::Any(awt::FontSlant::FontSlant_NONE)); + xProperties[i]->setPropertyValue(u"CharUnderline"_ustr, css::uno::Any(sal_Int16(0))); + xProperties[i]->setPropertyValue(u"CharStrikeout"_ustr, css::uno::Any(sal_Int16(0))); + xProperties[i]->setPropertyValue(u"CharShadowed"_ustr, css::uno::Any(false)); + xProperties[i]->setPropertyValue(u"CharColor"_ustr, css::uno::Any(Color(0))); + + xProperties[i]->setPropertyValue(u"CharKerning"_ustr, css::uno::Any(sal_Int16(0))); + xProperties[i]->setPropertyValue(u"CharEscapement"_ustr, css::uno::Any(sal_Int16(0))); + xProperties[i]->setPropertyValue(u"CharEscapementHeight"_ustr, + css::uno::Any(sal_Int8(100))); + } +} + +void ChartController::executeDispatch_FontSpacing( + const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties, + const css::uno::Sequence<css::beans::PropertyValue>& rArgs) +{ + sal_Int16 nKerning = 0; + rArgs[0].Value >>= nKerning; + for (std::size_t i = 0; i < xProperties.size(); i++) + xProperties[i]->setPropertyValue(u"CharKerning"_ustr, css::uno::Any(nKerning)); +} + +void ChartController::executeDispatch_FontSuperScript( + const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties) +{ + sal_Int16 nCharEscapement = 0; + xProperties[0]->getPropertyValue(u"CharEscapement"_ustr) >>= nCharEscapement; + for (std::size_t i = 0; i < xProperties.size(); i++) + { + if (nCharEscapement > 0) + { + xProperties[i]->setPropertyValue(u"CharEscapement"_ustr, css::uno::Any(sal_Int16(0))); + xProperties[i]->setPropertyValue(u"CharEscapementHeight"_ustr, + css::uno::Any(sal_Int8(100))); + } + else + { + xProperties[i]->setPropertyValue(u"CharEscapement"_ustr, + css::uno::Any(sal_Int16(14000))); + xProperties[i]->setPropertyValue(u"CharEscapementHeight"_ustr, + css::uno::Any(sal_Int8(58))); + } + } +} + +void ChartController::executeDispatch_FontSubScript( + const std::vector<css::uno::Reference<css::beans::XPropertySet>>& xProperties) +{ + sal_Int16 nCharEscapement = 0; + xProperties[0]->getPropertyValue(u"CharEscapement"_ustr) >>= nCharEscapement; + for (std::size_t i = 0; i < xProperties.size(); i++) + { + if (nCharEscapement < 0) + { + xProperties[i]->setPropertyValue(u"CharEscapement"_ustr, css::uno::Any(sal_Int16(0))); + xProperties[i]->setPropertyValue(u"CharEscapementHeight"_ustr, + css::uno::Any(sal_Int8(100))); + } + else + { + xProperties[i]->setPropertyValue(u"CharEscapement"_ustr, + css::uno::Any(sal_Int16(-14000))); + xProperties[i]->setPropertyValue(u"CharEscapementHeight"_ustr, + css::uno::Any(sal_Int8(58))); + } + } +} + void ChartController::executeDispatch_Paste() { SolarMutexGuard aGuard; @@ -260,7 +534,7 @@ void ChartController::executeDispatch_Paste() Graphic aGraphic; // paste location: center of window - Point aPos = pChartWindow->PixelToLogic( tools::Rectangle( {}, pChartWindow->GetSizePixel()).Center()); + Point aPos = pChartWindow->PixelToLogic( tools::Rectangle(Point{}, pChartWindow->GetSizePixel()).Center()); // handle different formats TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pChartWindow )); @@ -268,8 +542,7 @@ void ChartController::executeDispatch_Paste() { if ( aDataHelper.HasFormat( SotClipboardFormatId::DRAWING ) ) { - tools::SvRef<SotTempStream> xStm; - if ( aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING, xStm ) ) + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING) ) { xStm->Seek( 0 ); Reference< io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ) ); @@ -286,8 +559,7 @@ void ChartController::executeDispatch_Paste() else if ( aDataHelper.HasFormat( SotClipboardFormatId::SVXB ) ) { // graphic exchange format (graphic manager bitmap format?) - tools::SvRef<SotTempStream> xStm; - if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB, xStm )) + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::SVXB )) { TypeSerializer aSerializer(*xStm); aSerializer.readGraphic(aGraphic); @@ -315,8 +587,8 @@ void ChartController::executeDispatch_Paste() if( m_pDrawViewWrapper ) { OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView(); - if( pOutlinerView )//in case of edit mode insert into edited string - pOutlinerView->InsertText( aString ); + if (pOutlinerView)//in case of edit mode insert the formatted string + pOutlinerView->PasteSpecial(); else { impl_PasteStringAsTextShape( aString, awt::Point( 0, 0 ) ); @@ -343,38 +615,50 @@ void ChartController::impl_PasteGraphic( DBG_TESTSOLARMUTEX(); // note: the XPropertySet of the model is the old API. Also the property // "AdditionalShapes" that is used there. - uno::Reference< beans::XPropertySet > xModelProp( getModel(), uno::UNO_QUERY ); + rtl::Reference< ChartModel > xModel = getChartModel(); DrawModelWrapper * pDrawModelWrapper( GetDrawModelWrapper()); - if( ! (xGraphic.is() && xModelProp.is())) + if( ! (xGraphic.is() && xModel.is())) return; rtl::Reference<SvxGraphicObject> xGraphicShape = new SvxGraphicObject(nullptr); xGraphicShape->setShapeKind(SdrObjKind::Graphic); - uno::Reference< drawing::XShapes > xPage = pDrawModelWrapper->getMainDrawPage(); + rtl::Reference< SvxDrawPage > xPage = pDrawModelWrapper->getMainDrawPage(); if( xPage.is()) { xPage->add( xGraphicShape ); //need to change the model state manually - { - uno::Reference< util::XModifiable > xModifiable( getModel(), uno::UNO_QUERY ); - if( xModifiable.is() ) - xModifiable->setModified( true ); - } + xModel->setModified( true ); //select new shape m_aSelection.setSelection( xGraphicShape ); m_aSelection.applySelection( m_pDrawViewWrapper.get() ); } - xGraphicShape->SvxShape::setPropertyValue( "Graphic", uno::Any( xGraphic )); + xGraphicShape->SvxShape::setPropertyValue( u"Graphic"_ustr, uno::Any( xGraphic )); awt::Size aGraphicSize( 1000, 1000 ); + bool bGotGraphicSize = false; + try + { + bGotGraphicSize = xGraphicShape->SvxShape::getPropertyValue( u"Size100thMM"_ustr) >>= aGraphicSize; + } + catch (css::beans::UnknownPropertyException& ) + {} auto pChartWindow(GetChartWindow()); // first try size in 100th mm, then pixel size - if( ! ( xGraphicShape->SvxShape::getPropertyValue( "Size100thMM") >>= aGraphicSize ) && - ( ( xGraphicShape->SvxShape::getPropertyValue( "SizePixel") >>= aGraphicSize ) && pChartWindow )) + if( !bGotGraphicSize ) { - ::Size aVCLSize( pChartWindow->PixelToLogic( Size( aGraphicSize.Width, aGraphicSize.Height ))); - aGraphicSize.Width = aVCLSize.getWidth(); - aGraphicSize.Height = aVCLSize.getHeight(); + bool bGotSizePixel = false; + try + { + bGotSizePixel = xGraphicShape->SvxShape::getPropertyValue( u"SizePixel"_ustr) >>= aGraphicSize; + } + catch (css::beans::UnknownPropertyException& ) + {} + if ( bGotSizePixel && pChartWindow ) + { + ::Size aVCLSize( pChartWindow->PixelToLogic( Size( aGraphicSize.Width, aGraphicSize.Height ))); + aGraphicSize.Width = aVCLSize.getWidth(); + aGraphicSize.Height = aVCLSize.getHeight(); + } } xGraphicShape->setSize( aGraphicSize ); xGraphicShape->setPosition( awt::Point( 0, 0 ) ); @@ -386,7 +670,7 @@ void ChartController::impl_PasteShapes( SdrModel* pModel ) if ( !(pDrawModelWrapper && m_pDrawViewWrapper) ) return; - Reference< drawing::XDrawPage > xDestPage( pDrawModelWrapper->getMainDrawPage() ); + rtl::Reference< SvxDrawPage > xDestPage( pDrawModelWrapper->getMainDrawPage() ); SdrPage* pDestPage = GetSdrPageFromXDrawPage( xDestPage ); if ( !pDestPage ) return; @@ -402,7 +686,9 @@ void ChartController::impl_PasteShapes( SdrModel* pModel ) { SdrObject* pObj(aIter.Next()); // Clone to new SdrModel - SdrObject* pNewObj(pObj ? pObj->CloneSdrObject(pDrawModelWrapper->getSdrModel()) : nullptr); + rtl::Reference<SdrObject> pNewObj; + if (pObj) + pNewObj = pObj->CloneSdrObject(pDrawModelWrapper->getSdrModel()); if ( pNewObj ) { @@ -413,14 +699,14 @@ void ChartController::impl_PasteShapes( SdrModel* pModel ) xShape->setPosition( awt::Point( 0, 0 ) ); } - pDestPage->InsertObject( pNewObj ); + pDestPage->InsertObject( pNewObj.get() ); m_pDrawViewWrapper->AddUndo( std::make_unique<SdrUndoInsertObj>( *pNewObj ) ); - xSelShape = xShape; + xSelShape = std::move(xShape); } } } - Reference< util::XModifiable > xModifiable( getModel(), uno::UNO_QUERY ); + rtl::Reference< ChartModel > xModifiable = getChartModel(); if ( xModifiable.is() ) { xModifiable->setModified( true ); @@ -441,7 +727,7 @@ void ChartController::impl_PasteStringAsTextShape( const OUString& rString, cons if ( !(pDrawModelWrapper && m_pDrawViewWrapper) ) return; - const Reference< drawing::XDrawPage >& xDrawPage( pDrawModelWrapper->getMainDrawPage() ); + const rtl::Reference< SvxDrawPage > xDrawPage( pDrawModelWrapper->getMainDrawPage() ); OSL_ASSERT( xDrawPage.is() ); if ( !xDrawPage ) @@ -456,14 +742,14 @@ void ChartController::impl_PasteStringAsTextShape( const OUString& rString, cons xTextShape->setString( rString ); float fCharHeight = 10.0; - xTextShape->SvxShape::setPropertyValue( "TextAutoGrowHeight", uno::Any( true ) ); - xTextShape->SvxShape::setPropertyValue( "TextAutoGrowWidth", uno::Any( true ) ); - xTextShape->SvxShape::setPropertyValue( "CharHeight", uno::Any( fCharHeight ) ); - xTextShape->SvxShape::setPropertyValue( "CharHeightAsian", uno::Any( fCharHeight ) ); - xTextShape->SvxShape::setPropertyValue( "CharHeightComplex", uno::Any( fCharHeight ) ); - xTextShape->SvxShape::setPropertyValue( "TextVerticalAdjust", uno::Any( drawing::TextVerticalAdjust_CENTER ) ); - xTextShape->SvxShape::setPropertyValue( "TextHorizontalAdjust", uno::Any( drawing::TextHorizontalAdjust_CENTER ) ); - xTextShape->SvxShape::setPropertyValue( "CharFontName", uno::Any( OUString("Albany") ) ); + xTextShape->SvxShape::setPropertyValue( u"TextAutoGrowHeight"_ustr, uno::Any( true ) ); + xTextShape->SvxShape::setPropertyValue( u"TextAutoGrowWidth"_ustr, uno::Any( true ) ); + xTextShape->SvxShape::setPropertyValue( u"CharHeight"_ustr, uno::Any( fCharHeight ) ); + xTextShape->SvxShape::setPropertyValue( u"CharHeightAsian"_ustr, uno::Any( fCharHeight ) ); + xTextShape->SvxShape::setPropertyValue( u"CharHeightComplex"_ustr, uno::Any( fCharHeight ) ); + xTextShape->SvxShape::setPropertyValue( u"TextVerticalAdjust"_ustr, uno::Any( drawing::TextVerticalAdjust_CENTER ) ); + xTextShape->SvxShape::setPropertyValue( u"TextHorizontalAdjust"_ustr, uno::Any( drawing::TextHorizontalAdjust_CENTER ) ); + xTextShape->SvxShape::setPropertyValue( u"CharFontName"_ustr, uno::Any( u"Albany"_ustr ) ); xTextShape->setPosition( rPosition ); @@ -566,10 +852,17 @@ bool ChartController::isObjectDeleteable( const uno::Any& rSelection ) bool ChartController::isShapeContext() const { return m_aSelection.isAdditionalShapeSelected() || - ( m_pDrawViewWrapper && m_pDrawViewWrapper->AreObjectsMarked() && + ( m_pDrawViewWrapper && m_pDrawViewWrapper->GetMarkedObjectList().GetMarkCount() != 0 && ( m_pDrawViewWrapper->GetCurrentObjIdentifier() == SdrObjKind::Text ) ); } +bool ChartController::IsTextEdit() const +{ + // only Title objects and additional shapes are editable textshapes in chart + return m_pDrawViewWrapper && m_pDrawViewWrapper->IsTextEdit() && + (m_aSelection.isTitleObjectSelected() || m_aSelection.isAdditionalShapeSelected()); +} + void ChartController::impl_ClearSelection() { if( m_aSelection.hasSelection()) @@ -591,7 +884,7 @@ bool ChartController::executeDispatch_Delete() return false; //remove chart object - uno::Reference< chart2::XChartDocument > xChartDoc( getModel(), uno::UNO_QUERY ); + rtl::Reference< ChartModel > xChartDoc = getChartModel(); if( !xChartDoc.is() ) return false; @@ -612,17 +905,17 @@ bool ChartController::executeDispatch_Delete() } case OBJECTTYPE_LEGEND: { - uno::Reference< chart2::XDiagram > xDiagram( xChartDoc->getFirstDiagram()); + rtl::Reference< Diagram > xDiagram( xChartDoc->getFirstChartDiagram()); if( xDiagram.is()) { - uno::Reference< beans::XPropertySet > xLegendProp( xDiagram->getLegend(), uno::UNO_QUERY ); - if( xLegendProp.is()) + rtl::Reference< Legend > xLegend( xDiagram->getLegend2() ); + if( xLegend.is()) { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_LEGEND )), m_xUndoManager ); - xLegendProp->setPropertyValue( "Show", uno::Any( false )); + xLegend->setPropertyValue( u"Show"_ustr, uno::Any( false )); bReturn = true; aUndoGuard.commit(); } @@ -695,10 +988,10 @@ bool ChartController::executeDispatch_Delete() m_xUndoManager ); { ControllerLockGuardUNO aCtlLockGuard( xModel ); - xEqProp->setPropertyValue( "ShowEquation", uno::Any( false )); - xEqProp->setPropertyValue( "XName", uno::Any( OUString("x") )); - xEqProp->setPropertyValue( "YName", uno::Any( OUString("f(x)") )); - xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( false )); + xEqProp->setPropertyValue( u"ShowEquation"_ustr, uno::Any( false )); + xEqProp->setPropertyValue( u"XName"_ustr, uno::Any( u"x"_ustr )); + xEqProp->setPropertyValue( u"YName"_ustr, uno::Any( u"f(x)"_ustr )); + xEqProp->setPropertyValue( u"ShowCorrelationCoefficient"_ustr, uno::Any( false )); } bReturn = true; aUndoGuard.commit(); @@ -731,7 +1024,7 @@ bool ChartController::executeDispatch_Delete() { ControllerLockGuardUNO aCtlLockGuard( xModel ); xErrorBarProp->setPropertyValue( - "ErrorBarStyle", + u"ErrorBarStyle"_ustr, uno::Any( css::chart::ErrorBarStyle::NONE )); } bReturn = true; @@ -762,9 +1055,9 @@ bool ChartController::executeDispatch_Delete() aLabel.ShowSeriesName = false; if( aObjectType == OBJECTTYPE_DATA_LABELS ) { - uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( aCID, getChartModel() )); - DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, CHART_UNONAME_LABEL, uno::Any(aLabel) ); - DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, CHART_UNONAME_CUSTOM_LABEL_FIELDS, uno::Any() ); + rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( aCID, getChartModel() ); + xSeries->setPropertyAlsoToAllAttributedDataPoints( CHART_UNONAME_LABEL, uno::Any(aLabel) ); + xSeries->setPropertyAlsoToAllAttributedDataPoints( CHART_UNONAME_CUSTOM_LABEL_FIELDS, uno::Any() ); } else { @@ -819,20 +1112,19 @@ bool ChartController::executeDispatch_Delete() void ChartController::executeDispatch_ToggleLegend() { - Reference< frame::XModel > xModel( getModel() ); + rtl::Reference< ChartModel > xModel = getChartModel(); UndoGuard aUndoGuard( SchResId( STR_ACTION_TOGGLE_LEGEND ), m_xUndoManager ); - ChartModel& rModel = dynamic_cast<ChartModel&>(*xModel); - Reference< beans::XPropertySet > xLegendProp( LegendHelper::getLegend(rModel), uno::UNO_QUERY ); + rtl::Reference< Legend > xLegendProp = LegendHelper::getLegend(*xModel); bool bChanged = false; if( xLegendProp.is()) { try { bool bShow = false; - if( xLegendProp->getPropertyValue( "Show") >>= bShow ) + if( xLegendProp->getPropertyValue( u"Show"_ustr) >>= bShow ) { - xLegendProp->setPropertyValue( "Show", uno::Any( ! bShow )); + xLegendProp->setPropertyValue( u"Show"_ustr, uno::Any( ! bShow )); bChanged = true; } } @@ -843,7 +1135,7 @@ void ChartController::executeDispatch_ToggleLegend() } else { - xLegendProp.set( LegendHelper::getLegend(rModel, m_xCC, true), uno::UNO_QUERY ); + xLegendProp = LegendHelper::getLegend(*xModel, m_xCC, true); if( xLegendProp.is()) bChanged = true; } @@ -918,18 +1210,22 @@ void ChartController::executeDispatch_ToggleGridVertical() aUndoGuard.commit(); } -void ChartController::executeDispatch_FillColor(sal_uInt32 nColor) +void ChartController::executeDispatch_FillColor(const css::uno::Any& rColor) { try { - OUString aCID( m_aSelection.getSelectedCID() ); rtl::Reference<::chart::ChartModel> xChartModel = getChartModel(); if( xChartModel.is() ) { - Reference< beans::XPropertySet > xPointProperties( - ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) ); + const auto [xPointProperties, eType] + = getSelectedGraphObject(getSelection(), xChartModel); if( xPointProperties.is() ) - xPointProperties->setPropertyValue( "FillColor", uno::Any( nColor ) ); + xPointProperties->setPropertyValue(u"FillColor"_ustr, rColor); + + if (eType == OBJECTTYPE_DATA_SERIES || eType == OBJECTTYPE_DATA_POINT) + { + xChartModel->clearColorPalette(); + } } } catch( const uno::Exception& ) @@ -938,10 +1234,10 @@ void ChartController::executeDispatch_FillColor(sal_uInt32 nColor) } } -void ChartController::executeDispatch_FillGradient(OUString sJSONGradient) +void ChartController::executeDispatch_FillGradient(std::u16string_view sJSONGradient) { - XGradient aXGradient = XGradient::fromJSON(sJSONGradient); - css::awt::Gradient aGradient = aXGradient.toGradientUNO(); + basegfx::BGradient aBGradient = basegfx::BGradient::fromJSON(sJSONGradient); + css::awt::Gradient aGradient = model::gradient::createUnoGradient2(aBGradient); try { @@ -955,15 +1251,16 @@ void ChartController::executeDispatch_FillGradient(OUString sJSONGradient) if( xPropSet.is() ) { - OUString aPrefferedName = OUString::number(static_cast<sal_Int32>(aXGradient.GetStartColor())) - + OUString::number(static_cast<sal_Int32>(aXGradient.GetEndColor())) - + OUString::number(static_cast<sal_Int32>(aXGradient.GetAngle().get())); + OUString aPrefferedName = + OUString::number(static_cast<sal_Int32>(Color(aBGradient.GetColorStops().front().getStopColor()))) + + OUString::number(static_cast<sal_Int32>(Color(aBGradient.GetColorStops().back().getStopColor()))) + + OUString::number(static_cast<sal_Int32>(aBGradient.GetAngle().get())); OUString aNewName = PropertyHelper::addGradientUniqueNameToTable(css::uno::Any(aGradient), xChartModel, aPrefferedName); - xPropSet->setPropertyValue("FillGradientName", css::uno::Any(aNewName)); + xPropSet->setPropertyValue(u"FillGradientName"_ustr, css::uno::Any(aNewName)); } } } @@ -973,29 +1270,12 @@ void ChartController::executeDispatch_FillGradient(OUString sJSONGradient) } } -void ChartController::executeDispatch_LineColor(sal_uInt32 nColor) +void ChartController::executeDispatch_LineColor(const css::uno::Any& rColor) { try { - OUString aCID( m_aSelection.getSelectedCID() ); - rtl::Reference<::chart::ChartModel> xChartModel = getChartModel(); - if( xChartModel.is() ) - { - Reference< beans::XPropertySet > xPropSet( - ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) ); - - ObjectType eType = ObjectIdentifier::getObjectType(aCID); - if (eType == OBJECTTYPE_DIAGRAM) - { - css::uno::Reference<css::chart2::XDiagram> xDiagram( - xPropSet, css::uno::UNO_QUERY); - if (xDiagram.is()) - xPropSet.set(xDiagram->getWall()); - } - - if( xPropSet.is() ) - xPropSet->setPropertyValue( "LineColor", css::uno::makeAny( Color(ColorTransparency, nColor) ) ); - } + if (css::uno::Reference<css::beans::XPropertySet> xPropSet = getSelectedGraphObject(*this)) + xPropSet->setPropertyValue(u"LineColor"_ustr, rColor); } catch( const uno::Exception& ) { @@ -1003,29 +1283,12 @@ void ChartController::executeDispatch_LineColor(sal_uInt32 nColor) } } -void ChartController::executeDispatch_LineWidth(sal_uInt32 nWidth) +void ChartController::executeDispatch_LineWidth(const css::uno::Any& rWidth) { try { - OUString aCID( m_aSelection.getSelectedCID() ); - rtl::Reference<::chart::ChartModel> xChartModel = getChartModel(); - if( xChartModel.is() ) - { - Reference< beans::XPropertySet > xPropSet( - ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) ); - - ObjectType eType = ObjectIdentifier::getObjectType(aCID); - if (eType == OBJECTTYPE_DIAGRAM) - { - css::uno::Reference<css::chart2::XDiagram> xDiagram( - xPropSet, css::uno::UNO_QUERY); - if (xDiagram.is()) - xPropSet.set(xDiagram->getWall()); - } - - if( xPropSet.is() ) - xPropSet->setPropertyValue( "LineWidth", css::uno::makeAny( nWidth ) ); - } + if (css::uno::Reference<css::beans::XPropertySet> xPropSet = getSelectedGraphObject(*this)) + xPropSet->setPropertyValue(u"LineWidth"_ustr, rWidth); } catch( const uno::Exception& ) { @@ -1075,7 +1338,7 @@ void ChartController::executeDispatch_LOKPieSegmentDragging( int nOffset ) Reference< beans::XPropertySet > xPointProperties( ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) ); if( xPointProperties.is() ) - xPointProperties->setPropertyValue( "Offset", uno::Any( nOffset / 100.0 ) ); + xPointProperties->setPropertyValue( u"Offset"_ustr, uno::Any( nOffset / 100.0 ) ); } } catch( const uno::Exception & ) @@ -1099,8 +1362,7 @@ void ChartController::impl_switchDiagramPositioningToExcludingPositioning() ActionDescriptionProvider::ActionType::PosSize, ObjectNameProvider::getName( OBJECTTYPE_DIAGRAM)), m_xUndoManager ); - ChartModel& rModel = dynamic_cast<ChartModel&>(*m_aModel->getModel()); - if (DiagramHelper::switchDiagramPositioningToExcludingPositioning(rModel, true, true)) + if (DiagramHelper::switchDiagramPositioningToExcludingPositioning(*getChartModel(), true, true)) aUndoGuard.commit(); } |