[Libreoffice-commits] core.git: Branch 'private/mst/sw_redlinehide_3' - sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Oct 24 15:47:50 UTC 2018


 sw/source/uibase/inc/content.hxx   |    2 -
 sw/source/uibase/inc/swcont.hxx    |    9 +---
 sw/source/uibase/utlui/content.cxx |   73 +++++++++++++++++++++----------------
 3 files changed, 47 insertions(+), 37 deletions(-)

New commits:
commit 6885ae394e7d23d5da9dbde163b913e9073d92ff
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Oct 24 12:09:40 2018 +0200
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Wed Oct 24 13:05:44 2018 +0200

    sw_redlinehide_3: adapt SwContentTree/SwOutlineContent to gaps
    
    The SwOutlineContent::GetPos() returns the outline position in the
    document model / IDocumentOutlineNodesAccess; rename it to make that
    more clear.
    
    Also it's already possible to have gaps in the list entries by setting
    the outline level so that inner levels are filtered; the
    SwContentTree::ExecCommand() doesn't appear to handle this properly,
    it needs some tweaks to skip over the outline nodes that don't have list
    entries.
    
    The GetYPos() does not contain the outline index, it contains the list
    entry index.
    
    Change-Id: Ifae0b9648ce61bb9aa470172ef989b2532370138

diff --git a/sw/source/uibase/inc/content.hxx b/sw/source/uibase/inc/content.hxx
index ba47cb1f116d..83c73f7b84b2 100644
--- a/sw/source/uibase/inc/content.hxx
+++ b/sw/source/uibase/inc/content.hxx
@@ -49,7 +49,7 @@ class SwOutlineContent : public SwContent
             SwContent(pCnt, rName, nYPos),
             nOutlinePos(nArrPos), nOutlineLevel(nLevel), bIsMoveable(bMove) {}
 
-    sal_uInt16  GetPos() const {return nOutlinePos;}
+    SwOutlineNodes::size_type GetOutlinePos() const {return nOutlinePos;}
     sal_uInt8   GetOutlineLevel() const {return nOutlineLevel;}
     bool        IsMoveable() const {return bIsMoveable;};
 };
diff --git a/sw/source/uibase/inc/swcont.hxx b/sw/source/uibase/inc/swcont.hxx
index 54d80fc7ccbe..3d0aaf69a113 100644
--- a/sw/source/uibase/inc/swcont.hxx
+++ b/sw/source/uibase/inc/swcont.hxx
@@ -72,10 +72,9 @@ class SwContent : public SwTypeNumber
     const SwContentType*    pParent;
     OUString const          sContentName;
     long const              nYPosition;
-        // most subclasses appear to use this for a tools/gen.hxx-style
-        // geometric Y position, while SwOutlineContent wants to store a
-        // SwOutlineNodes::size_type value (where all such values used in
-        // practice hopefully fit into 'long')
+        // 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
     bool                    bInvisible;
 public:
         SwContent(const SwContentType* pCnt, const OUString& rName, long nYPos );
@@ -96,8 +95,6 @@ public:
         return ListBox::NaturalSortCompare(sContentName, rCont.sContentName) < 0;
     }
 
-    long        GetYPos() const {return nYPosition;}
-
     bool        IsInvisible() const {return bInvisible;}
     void        SetInvisible(){ bInvisible = true;}
 };
diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx
index 614fa1a9b8bc..6b86090fbe4b 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -1131,10 +1131,9 @@ static void* lcl_GetOutlineKey( SwContentTree* pTree, SwOutlineContent const * p
     if( pTree && pContent )
     {
         SwWrtShell* pShell = pTree->GetWrtShell();
-        long nPos = pContent->GetYPos();
+        auto const nPos = pContent->GetOutlinePos();
 
         key = static_cast<void*>(pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos ));
-
     }
     return key;
 }
@@ -1488,8 +1487,8 @@ bool  SwContentTree::Expand( SvTreeListEntry* pParent )
                 {
                     if(pChild->HasChildren())
                     {
-                        assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pChild->GetUserData())));
-                        long nPos = static_cast<SwContent*>(pChild->GetUserData())->GetYPos();
+                        assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pChild->GetUserData())));
+                        auto const nPos = static_cast<SwOutlineContent*>(pChild->GetUserData())->GetOutlinePos();
                         void* key = static_cast<void*>(pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos ));
                         aCurrOutLineNodeMap.emplace( key, false );
                         std::map<void*, bool>::iterator iter = mOutLineNodeMap.find( key );
@@ -1509,8 +1508,8 @@ bool  SwContentTree::Expand( SvTreeListEntry* pParent )
         else if( lcl_IsContent(pParent) )
         {
             SwWrtShell* pShell = GetWrtShell();
-            assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pParent->GetUserData())));
-            long nPos = static_cast<SwContent*>(pParent->GetUserData())->GetYPos();
+            assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pParent->GetUserData())));
+            auto const nPos = static_cast<SwOutlineContent*>(pParent->GetUserData())->GetOutlinePos();
             void* key = static_cast<void*>(pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos ));
             mOutLineNodeMap[key] = true;
         }
@@ -1541,8 +1540,8 @@ bool  SwContentTree::Collapse( SvTreeListEntry* pParent )
         else if( lcl_IsContent(pParent) )
         {
             SwWrtShell* pShell = GetWrtShell();
-            assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pParent->GetUserData())));
-            long nPos = static_cast<SwContent*>(pParent->GetUserData())->GetYPos();
+            assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pParent->GetUserData())));
+            auto const nPos = static_cast<SwOutlineContent*>(pParent->GetUserData())->GetOutlinePos();
             void* key = static_cast<void*>(pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos ));
             mOutLineNodeMap[key] = false;
         }
@@ -1780,7 +1779,7 @@ void SwContentTree::Display( bool bActive )
                 while( nullptr != (pEntry = Next(pEntry)) )
                 {
                     assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
-                    if(static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetPos() == nActPos)
+                    if (static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos() == nActPos)
                     {
                         MakeVisible(pEntry);
                         Select(pEntry);
@@ -1855,7 +1854,7 @@ bool SwContentTree::FillTransferData( TransferDataContainer& rTransfer,
     {
         case ContentTypeId::OUTLINE:
         {
-            const SwOutlineNodes::size_type nPos = static_cast<SwOutlineContent*>(pCnt)->GetPos();
+            const SwOutlineNodes::size_type nPos = static_cast<SwOutlineContent*>(pCnt)->GetOutlinePos();
             OSL_ENSURE(nPos < pWrtShell->getIDocumentOutlineNodesAccess()->getOutlineNodesCount(),
                        "outlinecnt changed");
 
@@ -2112,7 +2111,7 @@ bool SwContentTree::HasContentChanged()
             while( nullptr != (pFirstEntry = Next(pFirstEntry)) )
             {
                 assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pFirstEntry->GetUserData())));
-                if(static_cast<SwOutlineContent*>(pFirstEntry->GetUserData())->GetPos() == nActPos)
+                if (static_cast<SwOutlineContent*>(pFirstEntry->GetUserData())->GetOutlinePos() == nActPos)
                 {
                     if(FirstSelected() != pFirstEntry)
                     {
@@ -2419,8 +2418,9 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
     }
 
     bool bStartedAction = false;
-    for (auto pCurrentEntry : selected)
+    for (auto const pCurrentEntry : selected)
     {
+        assert(pCurrentEntry && lcl_IsContent(pCurrentEntry));
         if (pCurrentEntry && lcl_IsContent(pCurrentEntry))
         {
             assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pCurrentEntry->GetUserData())));
@@ -2428,7 +2428,7 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
                 static_cast<SwContent*>(pCurrentEntry->GetUserData())->GetParent()->GetType()
                                             ==  ContentTypeId::OUTLINE)
             {
-                nActPos = static_cast<SwOutlineContent*>(pCurrentEntry->GetUserData())->GetPos();
+                nActPos = static_cast<SwOutlineContent*>(pCurrentEntry->GetUserData())->GetOutlinePos();
             }
         }
         if (nActPos == SwOutlineNodes::npos || (bUpDown && !pShell->IsOutlineMovable(nActPos)))
@@ -2447,9 +2447,10 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
         pShell->MakeOutlineSel(nActPos, nActPos, bOutlineWithChildren);
         if (bUpDown)
         {
+            sal_uLong const nEntryAbsPos(GetModel()->GetAbsPos(pCurrentEntry));
             SwOutlineNodes::difference_type nDir = bUp ? -1 : 1;
             if (!bOutlineWithChildren && ((nDir == -1 && nActPos > 0) ||
-                               (nDir == 1 && nActPos < GetEntryCount() - 2)))
+                       (nDir == 1 && nEntryAbsPos < GetEntryCount() - 2)))
             {
                 pShell->MoveOutlinePara( nDir );
                 // Set cursor back to the current position
@@ -2468,8 +2469,8 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
                     assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
                     if (nActLevel >= static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlineLevel())
                         break;
+                    nActEndPos = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
                     pEntry = Next(pEntry);
-                    nActEndPos++;
                 }
                 if (nDir == 1)
                 {
@@ -2478,7 +2479,7 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
                     {
                         // pEntry now points to the entry following the last
                         // selected entry.
-                        SwOutlineNodes::size_type nDest = nActEndPos + 1;
+                        SwOutlineNodes::size_type nDest = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
                         // here needs to found the next entry after next.
                         // The selection must be inserted in front of that.
                         while (pEntry)
@@ -2486,12 +2487,17 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
                             pEntry = Next(pEntry);
                             assert(pEntry == nullptr || !lcl_IsContent(pEntry) || dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
                             // nDest++ may only executed if pEntry != 0
-                            if (pEntry && nDest++ &&
-                                (!lcl_IsContent(pEntry)
-                                 || nActLevel >= static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlineLevel()))
+                            if (pEntry)
                             {
-                                nDest--;
-                                break;
+                                if (!lcl_IsContent(pEntry) ||
+                                    nActLevel >= static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlineLevel())
+                                {
+                                    break;
+                                }
+                                else
+                                {
+                                    nDest = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
+                                }
                             }
                         }
                         nDir = nDest - nActEndPos;
@@ -2507,9 +2513,16 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
                     pEntry = pCurrentEntry;
                     while (pEntry && nDest)
                     {
-                        nDest--;
                         pEntry = Prev(pEntry);
                         assert(pEntry == nullptr || !lcl_IsContent(pEntry) || dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
+                        if (pEntry && lcl_IsContent(pEntry))
+                        {
+                            nDest = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
+                        }
+                        else
+                        {
+                            nDest = 0; // presumably?
+                        }
                         if (pEntry &&
                             (!lcl_IsContent(pEntry)
                              || nActLevel >= static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlineLevel()))
@@ -2552,7 +2565,7 @@ void SwContentTree::ExecCommand(const OUString& rCmd, bool bOutlineWithChildren)
             while (nullptr != (pFirst = Next(pFirst)) && lcl_IsContent(pFirst))
             {
                 assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pFirst->GetUserData())));
-                if (static_cast<SwOutlineContent*>(pFirst->GetUserData())->GetPos() == nCurrPos)
+                if (static_cast<SwOutlineContent*>(pFirst->GetUserData())->GetOutlinePos() == nCurrPos)
                 {
                     Select(pFirst);
                     MakeVisible(pFirst);
@@ -2653,13 +2666,13 @@ TriState SwContentTree::NotifyMoving( SvTreeListEntry*  pTarget,
     {
         SwOutlineNodes::size_type nTargetPos = 0;
         assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
-        SwOutlineNodes::size_type nSourcePos = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetPos();
+        SwOutlineNodes::size_type nSourcePos = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
         if(!lcl_IsContent(pTarget))
             nTargetPos = SwOutlineNodes::npos;
         else
         {
             assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pTarget->GetUserData())));
-            nTargetPos = static_cast<SwOutlineContent*>(pTarget->GetUserData())->GetPos();
+            nTargetPos = static_cast<SwOutlineContent*>(pTarget->GetUserData())->GetOutlinePos();
         }
         if( MAXLEVEL > m_nOutlineLevel && // Not all layers are displayed.
                         nTargetPos != SwOutlineNodes::npos)
@@ -2668,7 +2681,7 @@ TriState SwContentTree::NotifyMoving( SvTreeListEntry*  pTarget,
             if(pNext)
             {
                 assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pNext->GetUserData())));
-                nTargetPos = static_cast<SwOutlineContent*>(pNext->GetUserData())->GetPos() -1;
+                nTargetPos = static_cast<SwOutlineContent*>(pNext->GetUserData())->GetOutlinePos() - 1;
             }
             else
                 nTargetPos = static_cast<sal_uInt16>(GetWrtShell()->getIDocumentOutlineNodesAccess()->getOutlineNodesCount())- 1;
@@ -2697,13 +2710,13 @@ TriState SwContentTree::NotifyCopying( SvTreeListEntry*  pTarget,
     {
         SwOutlineNodes::size_type nTargetPos = 0;
         assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
-        SwOutlineNodes::size_type nSourcePos = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetPos();
+        SwOutlineNodes::size_type nSourcePos = static_cast<SwOutlineContent*>(pEntry->GetUserData())->GetOutlinePos();
         if(!lcl_IsContent(pTarget))
             nTargetPos = SwOutlineNodes::npos;
         else
         {
             assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pTarget->GetUserData())));
-            nTargetPos = static_cast<SwOutlineContent*>(pTarget->GetUserData())->GetPos();
+            nTargetPos = static_cast<SwOutlineContent*>(pTarget->GetUserData())->GetOutlinePos();
         }
 
         if( MAXLEVEL > m_nOutlineLevel && // Not all layers are displayed.
@@ -2713,7 +2726,7 @@ TriState SwContentTree::NotifyCopying( SvTreeListEntry*  pTarget,
             if(pNext)
             {
                 assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pNext->GetUserData())));
-                nTargetPos = static_cast<SwOutlineContent*>(pNext->GetUserData())->GetPos() - 1;
+                nTargetPos = static_cast<SwOutlineContent*>(pNext->GetUserData())->GetOutlinePos() - 1;
             }
             else
                 nTargetPos = static_cast<sal_uInt16>(GetWrtShell()->getIDocumentOutlineNodesAccess()->getOutlineNodesCount()) - 1;
@@ -3448,7 +3461,7 @@ void SwContentTree::GotoContent(SwContent* pCnt)
     {
         case ContentTypeId::OUTLINE   :
         {
-            m_pActiveShell->GotoOutline(static_cast<SwOutlineContent*>(pCnt)->GetPos());
+            m_pActiveShell->GotoOutline(static_cast<SwOutlineContent*>(pCnt)->GetOutlinePos());
         }
         break;
         case ContentTypeId::TABLE     :


More information about the Libreoffice-commits mailing list