sw/source/uibase/dochdl/swdtflvr.cxx |   48 ++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 23 deletions(-)

New commits:
commit 7a8dc25defee31edbb75a2f8c35f92ee2d3f3a83
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Feb 23 10:04:03 2021 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Feb 23 10:48:01 2021 +0100

    sw lok: simplify SwTransferable::isComplex()
    
    Commit 169a87563a3940299811d874b4df0ad13591771c (LOK: Implement
    getSelectionType, 2019-06-24) implemented detecting complex selections
    by copying the selection to a new SwDoc, which probably had two
    benefits: first, the created SwPaM instance didn't touch the document;
    second, this means no bounds has to be set when scanning nodes: the
    entire document is the selection.
    
    Later commit 7fe30d1cb00c576469d6cbe5606268a9cdf35bd3 (LOK: detect
    Graphics in isComplex for Writer, 2019-06-25) got rid of the SwPaM
    (which would register itself into text nodes), so now it's possible to
    not touch the document, even if we work on the original document.
    
    Instead, solve the partial scanning by iterating over the list of
    selections. This is meant to be faster, and also less likely to crash in
    case some internal document model invariant is broken.
    
    No testcase, testComplexSelection in CppunitTest_desktop_lib already
    covers thie behavior.
    
    Change-Id: Ia528c06a48defd06c5e34ed7d61621e5ce10bb06
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111377
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx 
b/sw/source/uibase/dochdl/swdtflvr.cxx
index 1e0e01acbc59..43271806c411 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -119,6 +119,7 @@
 #include <iodetect.hxx>
 #include <unotextrange.hxx>
 #include <unoframe.hxx>
+#include <txatbase.hxx>
 #include <vcl/uitest/logger.hxx>
 #include <vcl/uitest/eventdescription.hxx>
 
@@ -426,33 +427,34 @@ namespace
 
 sal_Bool SAL_CALL SwTransferable::isComplex()
 {
-    // Copy into a new Doc so we don't mess with the existing one.
-    //FIXME: We *should* be able to avoid this and improve the performance.
-    m_pClpDocFac.reset(new SwDocFac);
-    SwDoc& rTmpDoc = lcl_GetDoc(*m_pClpDocFac);
-
-    rTmpDoc.getIDocumentFieldsAccess()
-        .LockExpFields(); // never update fields - leave text as it is
-    lclOverWriteDoc(*m_pWrtShell, rTmpDoc);
-
     sal_Int32 nTextLength = 0;
-    const SwNode* pEndOfContent = 
&m_pWrtShell->GetDoc()->GetNodes().GetEndOfContent();
-    SwNodes& aNodes = rTmpDoc.GetNodes();
-    for( sal_uLong nIndex = 0; nIndex < aNodes.Count(); ++nIndex)
+    SwNodes& aNodes = m_pWrtShell->GetDoc()->GetNodes();
+    for (SwPaM& rPaM : m_pWrtShell->GetCursor()->GetRingContainer())
     {
-        SwNode& rNd = *aNodes[nIndex];
-        if (&rNd == pEndOfContent)
-            break;
+        for (sal_uLong nIndex = rPaM.GetMark()->nNode.GetIndex();
+             nIndex <= rPaM.GetPoint()->nNode.GetIndex(); ++nIndex)
+        {
+            SwNode& rNd = *aNodes[nIndex];
 
-        if (rNd.IsOLENode() || rNd.IsGrfNode())
-            return true; // Complex
+            SwTextNode* pTextNode = rNd.GetTextNode();
+            if (pTextNode)
+            {
+                if (pTextNode->HasHints())
+                {
+                    for (size_t nHint = 0; pTextNode->GetSwpHints().Count(); 
++nHint)
+                    {
+                        SwTextAttr* pHint = 
pTextNode->GetSwpHints().Get(nHint);
+                        if (pHint->Which() == RES_TXTATR_FLYCNT)
+                        {
+                            return true; // Complex
+                        }
+                    }
+                }
 
-        SwTextNode* pTextNode = rNd.GetTextNode();
-        if (pTextNode)
-        {
-            nTextLength += pTextNode->GetText().getLength();
-            if (nTextLength >= 1024 * 512)
-                return true; // Complex
+                nTextLength += pTextNode->GetText().getLength();
+                if (nTextLength >= 1024 * 512)
+                    return true; // Complex
+            }
         }
     }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to