sw/source/uibase/utlui/content.cxx |   61 +++++++++++++++++++++++++------------
 1 file changed, 42 insertions(+), 19 deletions(-)

New commits:
commit b250a748e6b28ea79e153ae9136fe2930ac9c3d8
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Mar 9 12:59:41 2021 +0300
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Mar 17 19:32:20 2021 +0100

    tdf#40427: use node index as position, not Y position on screen
    
    As mentioned in comment to SwContent::nYPosition in
    sw/source/uibase/inc/swcont.hxx:
    
      some subclasses appear to use this for a tools/gen.hxx-style
      geometric Y position, while e.g. SwOutlineContent wants to store
      the index in its subtree
    
    Abusing the nYPosition to store vertical position *on screen* gives
    wrong results when a following section is positioned on screen higher
    than a previous section - e.g., when multiple-page view is active.
    
    So just use the section's node as Y position of the Navigator entry.
    When the section is inside a fly frame, use the frame's anchor node.
    
    Change-Id: I6caf26aeb19d845129dc837138c37f42bbc18655
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112197
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit 4caf4403c1b862e7ccca94b9caee31394d019732)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112226
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/source/uibase/utlui/content.cxx 
b/sw/source/uibase/utlui/content.cxx
index 3129d7ee572f..87f526a17996 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -262,6 +262,26 @@ namespace
 
         return false;
     }
+
+// Gets "YPos" for SwRegionContent, i.e. a number used to sort sections in 
Navigator's list
+tools::Long getYPosForSection(const SwNodeIndex& rNodeIndex)
+{
+    sal_uLong nIndex = rNodeIndex.GetIndex();
+    if (rNodeIndex.GetNodes().GetEndOfExtras().GetIndex() >= nIndex)
+    {
+        // Not a node of BodyText
+        // Are we in a fly?
+        if (const auto pFlyFormat = rNodeIndex.GetNode().GetFlyFormat())
+        {
+            // Get node index of anchor
+            if (auto pSwPosition = pFlyFormat->GetAnchor().GetContentAnchor())
+            {
+                nIndex = getYPosForSection(pSwPosition->nNode);
+            }
+        }
+    }
+    return static_cast<tools::Long>(nIndex);
+}
 } // end of anonymous namespace
 
 SwContentType::SwContentType(SwWrtShell* pShell, ContentTypeId nType, 
sal_uInt8 nLevel) :
@@ -354,18 +374,20 @@ void SwContentType::Init(bool* pbInvalidateWindow)
                 pOldMember = std::move(m_pMember);
                 m_pMember.reset( new SwContentArr );
             }
-            const Point aNullPt;
             m_nMemberCount = m_pWrtShell->GetSectionFormatCount();
             for(size_t i = 0; i < m_nMemberCount; ++i)
             {
-                const SwSectionFormat* pFormat;
-                SectionType eTmpType;
-                if( (pFormat = 
&m_pWrtShell->GetSectionFormat(i))->IsInNodesArr() &&
-                (eTmpType = pFormat->GetSection()->GetType()) != 
SectionType::ToxContent
-                && SectionType::ToxHeader != eTmpType )
+                const SwSectionFormat* pFormat = 
&m_pWrtShell->GetSectionFormat(i);
+                if (!pFormat->IsInNodesArr())
+                    continue;
+                const SwSection* pSection = pFormat->GetSection();
+                if (SectionType eTmpType = pSection->GetType();
+                    eTmpType == SectionType::ToxContent || eTmpType == 
SectionType::ToxHeader)
+                    continue;
+                const SwNodeIndex* pNodeIndex = 
pFormat->GetContent().GetContentIdx();
+                if (pNodeIndex)
                 {
-                    const OUString& rSectionName =
-                        pFormat->GetSection()->GetSectionName();
+                    const OUString& rSectionName = pSection->GetSectionName();
                     sal_uInt8 nLevel = 0;
                     SwSectionFormat* pParentFormat = pFormat->GetParent();
                     while(pParentFormat)
@@ -375,8 +397,7 @@ void SwContentType::Init(bool* pbInvalidateWindow)
                     }
 
                     std::unique_ptr<SwContent> pCnt(new SwRegionContent(this, 
rSectionName,
-                            nLevel,
-                            pFormat->FindLayoutRect( false, &aNullPt ).Top()));
+                            nLevel, getYPosForSection(*pNodeIndex)));
 
                     SwPtrMsgPoolItem aAskItem( RES_CONTENT_VISIBLE, nullptr );
                     if( !pFormat->GetInfo( aAskItem ) &&
@@ -676,17 +697,20 @@ void SwContentType::FillMemberList(bool* 
pbLevelOrVisibilityChanged)
         break;
         case ContentTypeId::REGION    :
         {
-            const Point aNullPt;
             m_nMemberCount = m_pWrtShell->GetSectionFormatCount();
             for(size_t i = 0; i < m_nMemberCount; ++i)
             {
-                const SwSectionFormat* pFormat;
-                SectionType eTmpType;
-                if( (pFormat = 
&m_pWrtShell->GetSectionFormat(i))->IsInNodesArr() &&
-                (eTmpType = pFormat->GetSection()->GetType()) != 
SectionType::ToxContent
-                && SectionType::ToxHeader != eTmpType )
+                const SwSectionFormat* pFormat = 
&m_pWrtShell->GetSectionFormat(i);
+                if (!pFormat->IsInNodesArr())
+                    continue;
+                const SwSection* pSection = pFormat->GetSection();
+                if (SectionType eTmpType = pSection->GetType();
+                    eTmpType == SectionType::ToxContent || eTmpType == 
SectionType::ToxHeader)
+                    continue;
+                const SwNodeIndex* pNodeIndex = 
pFormat->GetContent().GetContentIdx();
+                if (pNodeIndex)
                 {
-                    OUString sSectionName = 
pFormat->GetSection()->GetSectionName();
+                    const OUString& sSectionName = pSection->GetSectionName();
 
                     sal_uInt8 nLevel = 0;
                     SwSectionFormat* pParentFormat = pFormat->GetParent();
@@ -697,8 +721,7 @@ void SwContentType::FillMemberList(bool* 
pbLevelOrVisibilityChanged)
                     }
 
                     std::unique_ptr<SwContent> pCnt(new SwRegionContent(this, 
sSectionName,
-                            nLevel,
-                            pFormat->FindLayoutRect( false, &aNullPt ).Top()));
+                            nLevel, getYPosForSection(*pNodeIndex)));
                     if( !pFormat->GetInfo( aAskItem ) &&
                         !aAskItem.pObject )     // not visible
                         pCnt->SetInvisible();
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to