chart2/source/controller/main/ChartController_Tools.cxx |   79 +++++++---------
 1 file changed, 37 insertions(+), 42 deletions(-)

New commits:
commit 5e5ec014ab0b71250f0a2676d3947c596dd77716
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon Jul 7 07:55:16 2025 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Jul 7 11:05:19 2025 +0200

    cool#12283: when diagram is selected, apply color to its wall
    
    This is the same as in ChartColorWrapper::operator().
    
    Change-Id: I1d80a35d9100a15e5eeda619fecb6f721f06ce13
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187457
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/chart2/source/controller/main/ChartController_Tools.cxx 
b/chart2/source/controller/main/ChartController_Tools.cxx
index 4c92ffe50158..702c5fa1ad19 100644
--- a/chart2/source/controller/main/ChartController_Tools.cxx
+++ b/chart2/source/controller/main/ChartController_Tools.cxx
@@ -178,6 +178,37 @@ bool lcl_arePropertiesSame(const 
std::vector<Reference<beans::XPropertySet>>& xP
     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
 
 ReferenceSizeProvider ChartController::impl_createReferenceSizeProvider()
@@ -1184,16 +1215,14 @@ void 
ChartController::executeDispatch_FillColor(sal_uInt32 nColor)
 {
     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( u"FillColor"_ustr, 
uno::Any( nColor ) );
 
-            ObjectType eType = ObjectIdentifier::getObjectType(aCID);
             if (eType == OBJECTTYPE_DATA_SERIES || eType == 
OBJECTTYPE_DATA_POINT)
             {
                 xChartModel->clearColorPalette();
@@ -1246,25 +1275,8 @@ void 
ChartController::executeDispatch_LineColor(sal_uInt32 nColor)
 {
     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( u"LineColor"_ustr, css::uno::Any( 
Color(ColorTransparency, nColor) ) );
-        }
+        if (css::uno::Reference<css::beans::XPropertySet> xPropSet = 
getSelectedGraphObject(*this))
+            xPropSet->setPropertyValue( u"LineColor"_ustr, css::uno::Any( 
Color(ColorTransparency, nColor) ) );
     }
     catch( const uno::Exception& )
     {
@@ -1276,25 +1288,8 @@ void 
ChartController::executeDispatch_LineWidth(sal_uInt32 nWidth)
 {
     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( u"LineWidth"_ustr, css::uno::Any( 
nWidth ) );
-        }
+        if (css::uno::Reference<css::beans::XPropertySet> xPropSet = 
getSelectedGraphObject(*this))
+            xPropSet->setPropertyValue( u"LineWidth"_ustr, css::uno::Any( 
nWidth ) );
     }
     catch( const uno::Exception& )
     {

Reply via email to