chart2/Library_chartcore.mk            |    1 +
 chart2/source/tools/PropertyHelper.cxx |   23 +++++++++++++++++++----
 svx/source/unodraw/unogtabl.cxx        |    5 +++--
 svx/source/unodraw/unottabl.cxx        |    5 +++--
 4 files changed, 26 insertions(+), 8 deletions(-)

New commits:
commit 6c986c718630ab21e6d9b5d353ddf1534e2dda41
Author:     Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de>
AuthorDate: Fri Dec 8 12:42:37 2023 +0100
Commit:     Armin Le Grand <armin.le.gr...@me.com>
CommitDate: Mon Dec 11 10:29:32 2023 +0100

    tdf#158421 use correct awt:Gradient2 in Chart lists
    
    Change-Id: I5fa02c2660d59981f540cde8bd6eaaaaddb30e65
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160463
    Tested-by: Jenkins
    Reviewed-by: Armin Le Grand <armin.le.gr...@me.com>

diff --git a/chart2/Library_chartcore.mk b/chart2/Library_chartcore.mk
index ea427820a726..b61390ec42ea 100644
--- a/chart2/Library_chartcore.mk
+++ b/chart2/Library_chartcore.mk
@@ -55,6 +55,7 @@ $(eval $(call gb_Library_use_libraries,chartcore,\
     ucbhelper \
     utl \
     vcl \
+    docmodel \
 ))
 
 $(eval $(call 
gb_Library_set_componentfile,chartcore,chart2/source/chartcore,services))
diff --git a/chart2/source/tools/PropertyHelper.cxx 
b/chart2/source/tools/PropertyHelper.cxx
index 90e0b06cdf59..48e21eccaf25 100644
--- a/chart2/source/tools/PropertyHelper.cxx
+++ b/chart2/source/tools/PropertyHelper.cxx
@@ -20,6 +20,7 @@
 #include <PropertyHelper.hxx>
 #include <com/sun/star/container/XNameContainer.hpp>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <docmodel/uno/UnoGradientTools.hxx>
 #include <comphelper/sequence.hxx>
 #include <osl/diagnose.h>
 #include <comphelper/diagnose_ex.hxx>
@@ -113,15 +114,29 @@ OUString lcl_addNamedPropertyUniqueNameToTable(
     const OUString & rPreferredName )
 {
     if( ! xNameContainer.is() ||
-        ! rValue.hasValue() ||
-        ( rValue.getValueType() != xNameContainer->getElementType()))
+        ! rValue.hasValue() )
+        return rPreferredName;
+
+    Any aValue(rValue);
+
+    if ( rValue.has<css::awt::Gradient>())
+    {
+        // tdf#158421 the lists for Gradients needs awt::Gradient2
+        // as type, convert input data if needed (and warn about it,
+        // the caller should be changed to offer the needed type)
+        SAL_WARN("chart2","input value needs to be awt::Gradient2");
+        const basegfx::BGradient aTemp(model::gradient::getFromAny(rValue));
+        aValue <<= model::gradient::createUnoGradient2(aTemp);
+    }
+
+    if ( aValue.getValueType() != xNameContainer->getElementType())
         return rPreferredName;
 
     try
     {
         Reference< container::XNameAccess > xNameAccess( xNameContainer, 
uno::UNO_QUERY_THROW );
         const uno::Sequence<OUString> aElementNames = 
xNameAccess->getElementNames();
-        auto it = std::find_if( aElementNames.begin(), aElementNames.end(), 
lcl_EqualsElement( rValue, xNameAccess ));
+        auto it = std::find_if( aElementNames.begin(), aElementNames.end(), 
lcl_EqualsElement( aValue, xNameAccess ));
 
         // element found => return name
         if( it != aElementNames.end())
@@ -159,7 +174,7 @@ OUString lcl_addNamedPropertyUniqueNameToTable(
         }
 
         OSL_ASSERT( !aUniqueName.isEmpty());
-        xNameContainer->insertByName( aUniqueName, rValue );
+        xNameContainer->insertByName( aUniqueName, aValue );
         return aUniqueName;
     }
     catch( const uno::Exception & )
diff --git a/svx/source/unodraw/unogtabl.cxx b/svx/source/unodraw/unogtabl.cxx
index 7939ccfd0e89..74f25f4a1397 100644
--- a/svx/source/unodraw/unogtabl.cxx
+++ b/svx/source/unodraw/unogtabl.cxx
@@ -17,7 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include <com/sun/star/awt/Gradient.hpp>
+#include <com/sun/star/awt/Gradient2.hpp>
 #include "UnoNameItemTable.hxx"
 
 #include <svx/svdmodel.hxx>
@@ -65,7 +65,8 @@ NameOrIndex* SvxUnoGradientTable::createItem() const { return 
new XFillGradientI
 // XElementAccess
 uno::Type SAL_CALL SvxUnoGradientTable::getElementType()
 {
-    return cppu::UnoType<awt::Gradient>::get();
+    // tdf#158421 use newer extended type for the list
+    return cppu::UnoType<awt::Gradient2>::get();
 }
 
 /**
diff --git a/svx/source/unodraw/unottabl.cxx b/svx/source/unodraw/unottabl.cxx
index 6233bccb9a0b..33cab4364937 100644
--- a/svx/source/unodraw/unottabl.cxx
+++ b/svx/source/unodraw/unottabl.cxx
@@ -17,7 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include <com/sun/star/awt/Gradient.hpp>
+#include <com/sun/star/awt/Gradient2.hpp>
 #include <svx/xflftrit.hxx>
 
 #include <svx/svdmodel.hxx>
@@ -71,7 +71,8 @@ NameOrIndex* SvxUnoTransGradientTable::createItem() const
 // XElementAccess
 uno::Type SAL_CALL SvxUnoTransGradientTable::getElementType()
 {
-    return cppu::UnoType<awt::Gradient>::get();
+    // tdf#158421 use newer extended type for the list
+    return cppu::UnoType<awt::Gradient2>::get();
 }
 
 /**

Reply via email to