tdf#114801: Cannot use the highlight 'bucket' function with docx file

Change-Id: I00df0022a20e83d76484d7c6e7b903ecd3c54aa0
Reviewed-on: https://gerrit.libreoffice.org/70347
Tested-by: Jenkins
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
(cherry picked from commit 84d4125b28c384f9ac6285737a5bb9093978798e)
Reviewed-on: https://gerrit.libreoffice.org/70454
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index 4ccbd77..0f4a669 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -4750,7 +4750,7 @@
                    m_pApplyTempl->nUndo =
                        std::min(m_pApplyTempl->nUndo, rSh.GetDoc()->GetIDocumentUndoRedo().GetUndoActionCount());
                    if (nId == RES_CHRATR_BACKGROUND)
                        rSh.SetAttrItem( SvxBrushItem( m_aWaterCanTextBackColor, nId ) );
                        ApplyCharBackground(m_aWaterCanTextBackColor, rSh);
                    else
                        rSh.SetAttrItem( SvxColorItem( m_aWaterCanTextColor, nId ) );
                    rSh.UnSetVisibleCursor();
diff --git a/sw/source/uibase/inc/uitool.hxx b/sw/source/uibase/inc/uitool.hxx
index 68def8b..384005a 100644
--- a/sw/source/uibase/inc/uitool.hxx
+++ b/sw/source/uibase/inc/uitool.hxx
@@ -37,6 +37,7 @@
class SwTabCols;
class DateTime;
class SfxViewFrame;
class SwEditShell;

// switch a metric
SW_DLLPUBLIC void SetMetric(MetricFormatter& rCtrl, FieldUnit eUnit);
@@ -60,6 +61,17 @@
**/
SW_DLLPUBLIC void ConvertAttrGenToChar(SfxItemSet& rSet, const SfxItemSet& rOrigSet);


/**
* Apply characeter background on the shell. Need to use this to hide the mixed
* charachter background and character highlighting attribute, which were
* added for MSO compatibility where there are two kind of character background.
*
* @param[in]       rBackgroundColor    the color to apply on the shell
* @param[in,out]   rShell              the shell on which we apply the new attirbute
**/
SW_DLLPUBLIC void ApplyCharBackground(const Color& rBackgroundColor, SwWrtShell& rShell);

// SfxItemSets <-> PageDesc
void ItemSetToPageDesc( const SfxItemSet& rSet, SwPageDesc& rPageDesc );
void PageDescToItemSet( const SwPageDesc& rPageDesc, SfxItemSet& rSet);
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index 5a77cbe..dde3a8a 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -1195,11 +1195,9 @@
            {
                if (nSlot != SID_ATTR_CHAR_COLOR_EXT)
                {
                    rWrtSh.StartUndo( SwUndoId::INSATTR );

                    SfxItemSet aCoreSet( rWrtSh.GetView().GetPool(), svl::Items<
                                         RES_CHRATR_BACKGROUND, RES_CHRATR_BACKGROUND,
                                         RES_CHRATR_GRABBAG, RES_CHRATR_GRABBAG>{} );
                                         RES_CHRATR_BACKGROUND, RES_CHRATR_BACKGROUND>{} );

                    rWrtSh.GetCurAttr( aCoreSet );

                    // Remove highlight if already set of the same color
@@ -1207,25 +1205,7 @@
                    if ( aSet == rBrushItem.GetColor() )
                        aSet = COL_TRANSPARENT;

                    rWrtSh.SetAttrItem( SvxBrushItem(aSet, RES_CHRATR_BACKGROUND) );

                    // Remove MS specific highlight when background is set
                    rWrtSh.SetAttrItem( SvxBrushItem(RES_CHRATR_HIGHLIGHT) );

                    // Remove shading marker
                    const SfxPoolItem *pTmpItem;
                    if( SfxItemState::SET == aCoreSet.GetItemState( RES_CHRATR_GRABBAG, false, &pTmpItem ) )
                    {
                        SfxGrabBagItem aGrabBag(*static_cast<const SfxGrabBagItem*>(pTmpItem));
                        std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
                        auto aIterator = rMap.find("CharShadingMarker");
                        if( aIterator != rMap.end() )
                        {
                            aIterator->second <<= false;
                        }
                        rWrtSh.SetAttrItem( aGrabBag );
                    }
                    rWrtSh.EndUndo( SwUndoId::INSATTR );
                    ApplyCharBackground(aSet, rWrtSh);
                }
                else
                    rWrtSh.SetAttrItem(
diff --git a/sw/source/uibase/utlui/uitool.cxx b/sw/source/uibase/utlui/uitool.cxx
index aa679eb..93dfd44 100644
--- a/sw/source/uibase/utlui/uitool.cxx
+++ b/sw/source/uibase/utlui/uitool.cxx
@@ -74,6 +74,7 @@
#include <docary.hxx>
#include <charfmt.hxx>
#include <SwStyleNameMapper.hxx>
#include <editsh.hxx>
// 50 cm 28350

#define MAXHEIGHT 28350
@@ -177,6 +178,39 @@
    rSet.ClearItem( RES_BACKGROUND );
}

void ApplyCharBackground(const Color& rBackgroundColor, SwWrtShell& rShell)
{
    rShell.StartUndo(SwUndoId::INSATTR);

    SfxItemSet aCoreSet(rShell.GetView().GetPool(), svl::Items<
        RES_CHRATR_GRABBAG, RES_CHRATR_GRABBAG>{});

    rShell.GetCurAttr(aCoreSet);

    // Set char background
    rShell.SetAttrItem(SvxBrushItem(rBackgroundColor, RES_CHRATR_BACKGROUND));

    // Highlight is an MS specific thing, so remove it at the first time when LO modifies
    // this part of the imported document.
    rShell.SetAttrItem(SvxBrushItem(RES_CHRATR_HIGHLIGHT));

    // Remove shading marker
    const SfxPoolItem *pTmpItem;
    if (SfxItemState::SET == aCoreSet.GetItemState(RES_CHRATR_GRABBAG, false, &pTmpItem))
    {
        SfxGrabBagItem aGrabBag(*static_cast<const SfxGrabBagItem*>(pTmpItem));
        std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
        auto aIterator = rMap.find("CharShadingMarker");
        if (aIterator != rMap.end())
        {
            aIterator->second <<= false;
        }
        rShell.SetAttrItem(aGrabBag);
    }

    rShell.EndUndo(SwUndoId::INSATTR);
}

// Fill header footer

static void FillHdFt(SwFrameFormat* pFormat, const  SfxItemSet& rSet)