tdf#160906 use SfxPoolItemHolder

to avoid handling already deleted SfxPoolItems.

Change-Id: I1f1f8f93cae8db7f7c8df66c2c7f3c02b59a39c3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167274
Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Tested-by: Jenkins
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167376
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
diff --git a/forms/source/richtext/parametrizedattributedispatcher.cxx b/forms/source/richtext/parametrizedattributedispatcher.cxx
index d6666e2..bc226de 100644
--- a/forms/source/richtext/parametrizedattributedispatcher.cxx
+++ b/forms/source/richtext/parametrizedattributedispatcher.cxx
@@ -89,7 +89,7 @@ namespace frm
    }


    const SfxPoolItem* OParametrizedAttributeDispatcher::convertDispatchArgsToItem( const Sequence< PropertyValue >& _rArguments )
    SfxPoolItemHolder OParametrizedAttributeDispatcher::convertDispatchArgsToItem( const Sequence< PropertyValue >& _rArguments )
    {
        // get the real slot id. This may differ from our attribute id: for instance, both
        // SID_ATTR_CHAR_HEIGHT and SID_ATTR_CHAR_LATIN_HEIGHT are mapped to the same which id
@@ -98,16 +98,16 @@ namespace frm
        SfxAllItemSet aParameterSet( getEditView()->GetEmptyItemSet() );
        TransformParameters( nSlotId, _rArguments, aParameterSet );

        const SfxPoolItem* pArgument = nullptr;
        if ( aParameterSet.Count() )
        {
            OSL_ENSURE( aParameterSet.Count() == 1, "OParametrizedAttributeDispatcher::convertDispatchArgsToItem: Arguments which form more than 1 item? How this?" );
            WhichId nAttributeWhich = aParameterSet.GetPool()->GetWhich( nSlotId );
            pArgument = aParameterSet.GetItem( nAttributeWhich );
            OSL_ENSURE( pArgument, "OParametrizedAttributeDispatcher::convertDispatchArgsToItem: suspicious: there were arguments, but they're not for my slot!" );
            SfxPoolItemHolder aArgument(*aParameterSet.GetPool(), aParameterSet.GetItem(nAttributeWhich));
            OSL_ENSURE( aArgument.getItem(), "OParametrizedAttributeDispatcher::convertDispatchArgsToItem: suspicious: there were arguments, but they're not for my slot!" );
            return aArgument;
        }

        return pArgument;
        return SfxPoolItemHolder();
    }


@@ -117,8 +117,8 @@ namespace frm
        OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OParametrizedAttributeDispatcher::dispatch: invalid URL!" );
        if ( m_pMasterDispatcher )
        {
            const SfxPoolItem* pConvertedArgument = convertDispatchArgsToItem( _rArguments );
            m_pMasterDispatcher->executeAttribute( m_nAttributeId, pConvertedArgument );
            const SfxPoolItemHolder aConvertedArgument(convertDispatchArgsToItem(_rArguments));
            m_pMasterDispatcher->executeAttribute(m_nAttributeId, aConvertedArgument.getItem());
        }
    }

diff --git a/forms/source/richtext/parametrizedattributedispatcher.hxx b/forms/source/richtext/parametrizedattributedispatcher.hxx
index 6984473..8a68486 100644
--- a/forms/source/richtext/parametrizedattributedispatcher.hxx
+++ b/forms/source/richtext/parametrizedattributedispatcher.hxx
@@ -21,7 +21,7 @@

#include "attributedispatcher.hxx"

class SfxPoolItem;
class SfxPoolItemHolder;

namespace frm
{
@@ -47,10 +47,10 @@ namespace frm

    protected:
        // own overridables
        /** convert the arguments as got in a XDispatch::dispatch call into an SfxPoolItem, which can
        /** convert the arguments as got in a XDispatch::dispatch call into an SfxPoolItemHolder, which can
            be used with a IMultiAttributeDispatcher::executeAttribute
        */
        virtual const SfxPoolItem* convertDispatchArgsToItem(
        virtual SfxPoolItemHolder convertDispatchArgsToItem(
            const css::uno::Sequence< css::beans::PropertyValue >& _rArguments );
    };

diff --git a/forms/source/richtext/specialdispatchers.cxx b/forms/source/richtext/specialdispatchers.cxx
index d75e065..ab01cd9 100644
--- a/forms/source/richtext/specialdispatchers.cxx
+++ b/forms/source/richtext/specialdispatchers.cxx
@@ -23,6 +23,7 @@
#include <editeng/editview.hxx>
#include <editeng/scriptspaceitem.hxx>
#include <osl/diagnose.h>
#include <svl/itemset.hxx>


namespace frm
@@ -140,7 +141,7 @@ namespace frm
    }


    const SfxPoolItem* OAsianFontLayoutDispatcher::convertDispatchArgsToItem( const Sequence< PropertyValue >& _rArguments )
    SfxPoolItemHolder OAsianFontLayoutDispatcher::convertDispatchArgsToItem( const Sequence< PropertyValue >& _rArguments )
    {
        // look for the "Enable" parameter
        const PropertyValue* pLookup = _rArguments.getConstArray();
@@ -155,13 +156,18 @@ namespace frm
        {
            bool bEnable = true;
            OSL_VERIFY( pLookup->Value >>= bEnable );

            if ( m_nAttributeId == sal_uInt16(SID_ATTR_PARA_SCRIPTSPACE) )
                return new SvxScriptSpaceItem( bEnable, static_cast<WhichId>(m_nAttributeId) );
            return new SfxBoolItem( static_cast<WhichId>(m_nAttributeId), bEnable );
                return SfxPoolItemHolder(
                    *getEditView()->GetEmptyItemSet().GetPool(),
                    new SvxScriptSpaceItem(bEnable, static_cast<WhichId>(m_nAttributeId)));
            return SfxPoolItemHolder(
                *getEditView()->GetEmptyItemSet().GetPool(),
                new SfxBoolItem(static_cast<WhichId>(m_nAttributeId), bEnable));
        }

        OSL_FAIL( "OAsianFontLayoutDispatcher::convertDispatchArgsToItem: did not find the one and only argument!" );
        return nullptr;
        return SfxPoolItemHolder();
    }


diff --git a/forms/source/richtext/specialdispatchers.hxx b/forms/source/richtext/specialdispatchers.hxx
index 9b4bfa1..cca2b75 100644
--- a/forms/source/richtext/specialdispatchers.hxx
+++ b/forms/source/richtext/specialdispatchers.hxx
@@ -80,7 +80,7 @@ namespace frm

    protected:
        // OParametrizedAttributeDispatcher
        virtual const SfxPoolItem* convertDispatchArgsToItem(
        virtual SfxPoolItemHolder convertDispatchArgsToItem(
            const css::uno::Sequence< css::beans::PropertyValue >& _rArguments ) override;
    };