fdo#77219 Image property Z-index [behindDoc] not preserved after RT

Problem description:
For the images who has the "Text wrapping" property set as Behind Text
 is not preserved after saving the file in DOCX format using LO.

Reviewed on:
	https://gerrit.libreoffice.org/9065

Change-Id: Ic8555103909c0f1ed1cb58fba4dc2ef2f84cc9dd
diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx
index d4bdbcf..6167a19 100644
--- a/oox/source/vml/vmlshape.cxx
+++ b/oox/source/vml/vmlshape.cxx
@@ -336,6 +336,20 @@ Reference< XShape > ShapeBase::convertAndInsert( const Reference< XShapes >& rxS
                    aGrabBag[length].Value = uno::makeAny( maTypeModel.maZIndex.toInt32() );
                    propertySet->setPropertyValue( "FrameInteropGrabBag", uno::makeAny(aGrabBag) );
                }
                else
                {
                    if( maTypeModel.maZIndex.toInt32() )
                    {
                        uno::Sequence<beans::PropertyValue> aGrabBag;
                        uno::Reference<beans::XPropertySet> propertySet (xShape, uno::UNO_QUERY);
                        propertySet->getPropertyValue("InteropGrabBag") >>= aGrabBag;
                        sal_Int32 length = aGrabBag.getLength();
                        aGrabBag.realloc( length+1 );
                        aGrabBag[length].Name = "VML-Z-ORDER";
                        aGrabBag[length].Value = uno::makeAny( maTypeModel.maZIndex.toInt32() );
                        propertySet->setPropertyValue( "InteropGrabBag", uno::makeAny(aGrabBag) );
                    }
                }
                Reference< XControlShape > xControlShape( xShape, uno::UNO_QUERY );
                if ( xControlShape.is() && !getTypeModel().mbVisible )
                {
diff --git a/sw/qa/extras/ooxmlexport/data/test77219.docx b/sw/qa/extras/ooxmlexport/data/test77219.docx
new file mode 100644
index 0000000..29aca1b
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/test77219.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 1e4067e..e7f57e6 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -3121,6 +3121,14 @@ DECLARE_OOXMLEXPORT_TEST(test76734_2K7, "test76734_2K7.docx")
    assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p[1]/w:r[3]/mc:AlternateContent[1]/mc:Choice[1]", "Requires", "wps");
}

DECLARE_OOXMLEXPORT_TEST(test77219, "test77219.docx")
{
    xmlDocPtr pXmlDoc = parseExport("word/document.xml");
    if (!pXmlDoc)
        return;
    assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p[6]/w:r[1]/mc:AlternateContent[1]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]", "behindDoc", "1");
}

DECLARE_OOXMLEXPORT_TEST(testFDO76597, "fdo76597.docx")
{
    // check XML
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 6e3388b..f727d6f 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -743,7 +743,7 @@ DECLARE_OOXMLIMPORT_TEST(testN779627, "n779627.docx")
     * Another problem tested with this document is that the roundrect is
     * centered vertically and horizontally.
     */
    uno::Reference<beans::XPropertySet> xShapeProperties( getShape(4), uno::UNO_QUERY );
    uno::Reference<beans::XPropertySet> xShapeProperties( getShape(1), uno::UNO_QUERY );
    uno::Reference<drawing::XShapeDescriptor> xShapeDescriptor(xShapeProperties, uno::UNO_QUERY);
    // If this goes wrong, probably the index of the shape is changed and the test should be adjusted.
    CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.RectangleShape"), xShapeDescriptor->getShapeType());
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 51810b3..3a6dfef 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1742,11 +1742,7 @@ void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape 
#endif
            text::TextContentAnchorType nAnchorType(text::TextContentAnchorType_AT_PARAGRAPH);
            xProps->getPropertyValue(rPropNameSupplier.GetName( PROP_ANCHOR_TYPE )) >>= nAnchorType;

            if (!m_bInHeaderFooterImport)
                xProps->setPropertyValue(
                        rPropNameSupplier.GetName( PROP_OPAQUE ),
                        uno::makeAny( true ) );
            bool checkZOredrStatus = false;
            if (xSInfo->supportsService("com.sun.star.text.TextFrame"))
            {
                // Extract the special "btLr text frame" mode, requested by oox, if needed.
@@ -1754,7 +1750,7 @@ void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape 
                uno::Reference<beans::XPropertySet> xShapePropertySet(xShape, uno::UNO_QUERY);
                uno::Sequence<beans::PropertyValue> aGrabBag;
                xShapePropertySet->getPropertyValue("FrameInteropGrabBag") >>= aGrabBag;
                bool checkBtLrStatus = false;bool checkZOredrStatus = false;
                bool checkBtLrStatus = false;

                for (int i = 0; i < aGrabBag.getLength(); ++i)
                {
@@ -1793,6 +1789,29 @@ void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape 
                if( pos != paragraphContext->end())
                    xProps->setPropertyValue( rPropNameSupplier.GetName( PROP_BOTTOM_MARGIN ), (*pos).second.getValue() );
            }
            else
            {
                uno::Reference<beans::XPropertySet> xShapePropertySet(xShape, uno::UNO_QUERY);
                uno::Sequence<beans::PropertyValue> aGrabBag;
                xShapePropertySet->getPropertyValue("InteropGrabBag") >>= aGrabBag;
                for (int i = 0; i < aGrabBag.getLength(); ++i)
                {
                    if (aGrabBag[i].Name == "VML-Z-ORDER")
                    {
                        GraphicZOrderHelper* pZOrderHelper = m_rDMapper.graphicZOrderHelper();
                        sal_Int32 zOrder(0);
                        aGrabBag[i].Value >>= zOrder;
                        xShapePropertySet->setPropertyValue( "ZOrder", uno::makeAny(pZOrderHelper->findZOrder(zOrder)));
                        pZOrderHelper->addItem(xShapePropertySet, zOrder);
                        xShapePropertySet->setPropertyValue(rPropNameSupplier.GetName( PROP_OPAQUE ), uno::makeAny( false ) );
                        checkZOredrStatus = true;
                    }
                }
            }
            if (!m_bInHeaderFooterImport && !checkZOredrStatus)
                xProps->setPropertyValue(
                        rPropNameSupplier.GetName( PROP_OPAQUE ),
                        uno::makeAny( true ) );
        }
    }
    catch ( const uno::Exception& e )