DOCX import: fix lost objects anchored to an empty linked header

This is really similar to commit
04b2310aaa094794ceedaa1bb6ff1823a2d29d3e (DOCX import: fix lost objects
anchored to the single para of a linked header, 2020-01-10), except here
the header is not just a single-paragraph one, but has no text portions.

Update text-copy.docx to have a header which is not only a single
paragraph, but also has no character content. This keeps testing the
original case, but now also tests the more strict case (single paragraph
-> single empty paragraph).

Change-Id: I11bb062e77af1a83f717225ea5b4daef39e5a672
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86552
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
diff --git a/sw/qa/extras/ooxmlimport/data/text-copy.docx b/sw/qa/extras/ooxmlimport/data/text-copy.docx
index 9c871e6..03c0563 100644
--- a/sw/qa/extras/ooxmlimport/data/text-copy.docx
+++ b/sw/qa/extras/ooxmlimport/data/text-copy.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
index 11243d1..d75a8c0 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
@@ -287,6 +287,7 @@ DECLARE_OOXMLIMPORT_TEST(testTextCopy, "text-copy.docx")
{
    // The document has a header on the second page that is copied as part of the import process.
    // The header has a single paragraph: make sure shapes anchored to it are not lost.
    // Note that the single paragraph itself has no text portions.
    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
    uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(),
                                                                  uno::UNO_QUERY);
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 1d56e41..0cc15a9 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -1828,6 +1828,21 @@ DocumentContentOperationsManager::DocumentContentOperationsManager( SwDoc& i_rSw
{
}

/**
 * Checks if rStart..rEnd mark a range that makes sense to copy.
 *
 * bCopyText means that an empty range is OK, since paragraph-anchored objects may present.
 */
static bool IsEmptyRange(const SwPosition& rStart, const SwPosition& rEnd, bool bCopyText)
{
    bool bEmptyRange = rStart >= rEnd;
    if (bCopyText)
    {
        bEmptyRange = rStart > rEnd;
    }
    return bEmptyRange;
}

// Copy an area into this document or into another document
bool
DocumentContentOperationsManager::CopyRange( SwPaM& rPam, SwPosition& rPos, const bool bCopyAll, bool bCheckPos, bool bCopyText ) const
@@ -1838,7 +1853,7 @@ DocumentContentOperationsManager::CopyRange( SwPaM& rPam, SwPosition& rPos, cons
    bool bColumnSel = pDoc->IsClipBoard() && pDoc->IsColumnSelection();

    // Catch if there's no copy to do
    if( !rPam.HasMark() || ( *pStt >= *pEnd && !bColumnSel ) )
    if (!rPam.HasMark() || (IsEmptyRange(*pStt, *pEnd, bCopyText) && !bColumnSel))
        return false;

    // Prevent copying in Flys that are anchored in the area
@@ -4526,7 +4541,7 @@ bool DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
    SwPosition *const pEnd = rPam.End();

    // Catch when there's no copy to do.
    if( !rPam.HasMark() || ( *pStt >= *pEnd && !bColumnSel ) ||
    if (!rPam.HasMark() || (IsEmptyRange(*pStt, *pEnd, bCopyText) && !bColumnSel) ||
        //JP 29.6.2001: 88963 - don't copy if inspos is in region of start to end
        //JP 15.11.2001: don't test inclusive the end, ever exclusive
        ( pDoc == &m_rDoc && *pStt <= rPos && rPos < *pEnd ))