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.Grand@me.com>
(cherry picked from commit 6c986c718630ab21e6d9b5d353ddf1534e2dda41)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160573
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
(cherry picked from commit f0bdecd4470c41428187434161960e6103e8e8ec)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160585
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
diff --git a/chart2/Library_chartcore.mk b/chart2/Library_chartcore.mk
index 54bc946..942a71d 100644
--- a/chart2/Library_chartcore.mk
+++ b/chart2/Library_chartcore.mk
@@ -56,6 +56,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 90e0b06..48e21ec 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 7939ccf..74f25f4 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 6233bcc..33cab43 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();
}

/**