sw/inc/AnnotationWin.hxx                  |    2 
 sw/source/uibase/docvw/AnnotationWin2.cxx |  172 +++++++++++++++---------------
 sw/source/uibase/docvw/PostItMgr.cxx      |   98 +++++++++--------
 3 files changed, 143 insertions(+), 129 deletions(-)

New commits:
commit 5957bafc96d5f0b0eb45cdbc4450d0fd6b276065
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Tue Aug 8 11:32:53 2023 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Thu Aug 10 21:23:17 2023 +0200

    when notes are not shown don't do expensive comment size calculation...
    
    and positioning, etc.
    
    Change-Id: Ice2f1a506bc6ae6d463e51e3d98e075a88c93cc0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155453
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/inc/AnnotationWin.hxx b/sw/inc/AnnotationWin.hxx
index fb7741543f4a..08b8597a014f 100644
--- a/sw/inc/AnnotationWin.hxx
+++ b/sw/inc/AnnotationWin.hxx
@@ -90,8 +90,8 @@ class SAL_DLLPUBLIC_RTTI SwAnnotationWin final : public 
InterimItemWindow
                                   tools::Long nY,
                                   tools::Long nWidth,
                                   tools::Long nHeight,
-                                  const SwRect& aAnchorRect,
                                   const tools::Long PageBorder);
+        void SetAnchorRect(const SwRect& aAnchorRect);
         void SetPosAndSize();
         void TranslateTopPosition(const tools::Long aAmount);
         void CheckMetaText();
diff --git a/sw/source/uibase/docvw/AnnotationWin2.cxx 
b/sw/source/uibase/docvw/AnnotationWin2.cxx
index 9deb292da6ab..e8852a87f6e0 100644
--- a/sw/source/uibase/docvw/AnnotationWin2.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin2.cxx
@@ -240,13 +240,17 @@ void SwAnnotationWin::DrawForPage(OutputDevice* pDev, 
const Point& rPt)
 }
 
 void SwAnnotationWin::SetPosSizePixelRect(tools::Long nX, tools::Long nY, 
tools::Long nWidth, tools::Long nHeight,
-                                       const SwRect& aAnchorRect, const 
tools::Long aPageBorder)
+                                          const tools::Long aPageBorder)
 {
     mPosSize = tools::Rectangle(Point(nX,nY),Size(nWidth,nHeight));
+    mPageBorder = aPageBorder;
+}
+
+void SwAnnotationWin::SetAnchorRect(const SwRect& aAnchorRect)
+{
     if (!mAnchorRect.IsEmpty() && mAnchorRect != aAnchorRect)
         mbAnchorRectChanged = true;
     mAnchorRect = aAnchorRect;
-    mPageBorder = aPageBorder;
 }
 
 void SwAnnotationWin::SetSize( const Size& rNewSize )
@@ -534,105 +538,106 @@ void SwAnnotationWin::Rescale()
 
 void SwAnnotationWin::SetPosAndSize()
 {
-    bool bChange = false;
-
-    if (GetSizePixel() != mPosSize.GetSize())
+    const bool bShowNotes = mrMgr.ShowNotes();
+    if (bShowNotes)
     {
-        bChange = true;
-        SetSizePixel(mPosSize.GetSize());
+        bool bChange = false;
 
-        DoResize();
-    }
+        if (GetSizePixel() != mPosSize.GetSize())
+        {
+            bChange = true;
+            SetSizePixel(mPosSize.GetSize());
 
-    if (GetPosPixel().X() != mPosSize.Left() || (std::abs(GetPosPixel().Y() - 
mPosSize.Top()) > 5) )
-    {
-        bChange = true;
-        SetPosPixel(mPosSize.TopLeft());
+            DoResize();
+        }
 
-        Point aLineStart;
-        Point aLineEnd ;
-        switch ( meSidebarPosition )
+        if (GetPosPixel().X() != mPosSize.Left() || 
(std::abs(GetPosPixel().Y() - mPosSize.Top()) > 5) )
         {
-            case sw::sidebarwindows::SidebarPosition::LEFT:
+            bChange = true;
+            SetPosPixel(mPosSize.TopLeft());
+
+            Point aLineStart;
+            Point aLineEnd ;
+            switch ( meSidebarPosition )
             {
-                aLineStart = EditWin().PixelToLogic( 
Point(GetPosPixel().X()+GetSizePixel().Width(),GetPosPixel().Y()-1) );
-                aLineEnd = EditWin().PixelToLogic( 
Point(GetPosPixel().X(),GetPosPixel().Y()-1) );
+                case sw::sidebarwindows::SidebarPosition::LEFT:
+                {
+                    aLineStart = EditWin().PixelToLogic( 
Point(GetPosPixel().X()+GetSizePixel().Width(),GetPosPixel().Y()-1) );
+                    aLineEnd = EditWin().PixelToLogic( 
Point(GetPosPixel().X(),GetPosPixel().Y()-1) );
+                }
+                break;
+                case sw::sidebarwindows::SidebarPosition::RIGHT:
+                {
+                    aLineStart = EditWin().PixelToLogic( 
Point(GetPosPixel().X(),GetPosPixel().Y()-1) );
+                    aLineEnd = EditWin().PixelToLogic( 
Point(GetPosPixel().X()+GetSizePixel().Width(),GetPosPixel().Y()-1) );
+                }
+                break;
+                default:
+                    OSL_FAIL( "<SwAnnotationWin::SetPosAndSize()> - unexpected 
position of sidebar" );
+                break;
             }
-            break;
-            case sw::sidebarwindows::SidebarPosition::RIGHT:
+
+            // LOK has map mode disabled, and we still want to perform pixel ->
+            // twips conversion for the size of the line above the note.
+            if (comphelper::LibreOfficeKit::isActive() && 
!EditWin().IsMapModeEnabled())
             {
-                aLineStart = EditWin().PixelToLogic( 
Point(GetPosPixel().X(),GetPosPixel().Y()-1) );
-                aLineEnd = EditWin().PixelToLogic( 
Point(GetPosPixel().X()+GetSizePixel().Width(),GetPosPixel().Y()-1) );
+                EditWin().EnableMapMode();
+                Size aSize(aLineEnd.getX() - aLineStart.getX(), 
aLineEnd.getY() - aLineStart.getY());
+                aSize = EditWin().PixelToLogic(aSize);
+                aLineEnd = aLineStart;
+                aLineEnd.Move(aSize.getWidth(), aSize.getHeight());
+                EditWin().EnableMapMode(false);
             }
-            break;
-            default:
-                OSL_FAIL( "<SwAnnotationWin::SetPosAndSize()> - unexpected 
position of sidebar" );
-            break;
-        }
-
-        // LOK has map mode disabled, and we still want to perform pixel ->
-        // twips conversion for the size of the line above the note.
-        if (comphelper::LibreOfficeKit::isActive() && 
!EditWin().IsMapModeEnabled())
-        {
-            EditWin().EnableMapMode();
-            Size aSize(aLineEnd.getX() - aLineStart.getX(), aLineEnd.getY() - 
aLineStart.getY());
-            aSize = EditWin().PixelToLogic(aSize);
-            aLineEnd = aLineStart;
-            aLineEnd.Move(aSize.getWidth(), aSize.getHeight());
-            EditWin().EnableMapMode(false);
-        }
 
-        if (mpAnchor)
-        {
-            mpAnchor->SetAllPosition( basegfx::B2DPoint( mAnchorRect.Left() , 
mAnchorRect.Bottom() - 5* 15),
-                                      basegfx::B2DPoint( 
mAnchorRect.Left()-5*15 , mAnchorRect.Bottom()+5*15),
-                                      basegfx::B2DPoint( 
mAnchorRect.Left()+5*15 , mAnchorRect.Bottom()+5*15),
-                                      basegfx::B2DPoint( mAnchorRect.Left(), 
mAnchorRect.Bottom()+2*15),
-                                      basegfx::B2DPoint( mPageBorder 
,mAnchorRect.Bottom()+2*15),
-                                      basegfx::B2DPoint( 
aLineStart.X(),aLineStart.Y()),
-                                      basegfx::B2DPoint( 
aLineEnd.X(),aLineEnd.Y()));
-        }
-        else
-        {
-            mpAnchor = AnchorOverlayObject::CreateAnchorOverlayObject( mrView,
-                                                                       
mAnchorRect,
-                                                                       
mPageBorder,
-                                                                       
aLineStart,
-                                                                       
aLineEnd,
-                                                                       
mColorAnchor );
-            if ( mpAnchor )
+            if (mpAnchor)
             {
-                mpAnchor->setVisible(true);
-                mpAnchor->SetAnchorState(AnchorState::Tri);
-                if (HasChildPathFocus())
+                mpAnchor->SetAllPosition( basegfx::B2DPoint( 
mAnchorRect.Left() , mAnchorRect.Bottom() - 5* 15),
+                                          basegfx::B2DPoint( 
mAnchorRect.Left()-5*15 , mAnchorRect.Bottom()+5*15),
+                                          basegfx::B2DPoint( 
mAnchorRect.Left()+5*15 , mAnchorRect.Bottom()+5*15),
+                                          basegfx::B2DPoint( 
mAnchorRect.Left(), mAnchorRect.Bottom()+2*15),
+                                          basegfx::B2DPoint( mPageBorder 
,mAnchorRect.Bottom()+2*15),
+                                          basegfx::B2DPoint( 
aLineStart.X(),aLineStart.Y()),
+                                          basegfx::B2DPoint( 
aLineEnd.X(),aLineEnd.Y()));
+            }
+            else
+            {
+                mpAnchor = AnchorOverlayObject::CreateAnchorOverlayObject( 
mrView,
+                                                                           
mAnchorRect,
+                                                                           
mPageBorder,
+                                                                           
aLineStart,
+                                                                           
aLineEnd,
+                                                                           
mColorAnchor );
+                if ( mpAnchor )
                 {
-                    mpAnchor->setLineSolid(true);
+                    mpAnchor->setVisible(true);
+                    mpAnchor->SetAnchorState(AnchorState::Tri);
+                    if (HasChildPathFocus())
+                    {
+                        mpAnchor->setLineSolid(true);
+                    }
                 }
             }
         }
-    }
-    else
-    {
-        if ( mpAnchor &&
-             ( mpAnchor->getBasePosition() != basegfx::B2DPoint( 
mAnchorRect.Left() , mAnchorRect.Bottom()-5*15) ) )
+        else
         {
-            mpAnchor->SetTriPosition( basegfx::B2DPoint( mAnchorRect.Left() , 
mAnchorRect.Bottom() - 5* 15),
-                                      basegfx::B2DPoint( 
mAnchorRect.Left()-5*15 , mAnchorRect.Bottom()+5*15),
-                                      basegfx::B2DPoint( 
mAnchorRect.Left()+5*15 , mAnchorRect.Bottom()+5*15),
-                                      basegfx::B2DPoint( mAnchorRect.Left(), 
mAnchorRect.Bottom()+2*15),
-                                      basegfx::B2DPoint( mPageBorder , 
mAnchorRect.Bottom()+2*15));
+            if ( mpAnchor &&
+                 ( mpAnchor->getBasePosition() != basegfx::B2DPoint( 
mAnchorRect.Left() , mAnchorRect.Bottom()-5*15) ) )
+            {
+                mpAnchor->SetTriPosition( basegfx::B2DPoint( 
mAnchorRect.Left() , mAnchorRect.Bottom() - 5* 15),
+                                          basegfx::B2DPoint( 
mAnchorRect.Left()-5*15 , mAnchorRect.Bottom()+5*15),
+                                          basegfx::B2DPoint( 
mAnchorRect.Left()+5*15 , mAnchorRect.Bottom()+5*15),
+                                          basegfx::B2DPoint( 
mAnchorRect.Left(), mAnchorRect.Bottom()+2*15),
+                                          basegfx::B2DPoint( mPageBorder , 
mAnchorRect.Bottom()+2*15));
+            }
         }
-    }
 
-    if (mpShadow && bChange)
-    {
-        Point aStart = 
EditWin().PixelToLogic(GetPosPixel()+Point(0,GetSizePixel().Height()));
-        Point aEnd = 
EditWin().PixelToLogic(GetPosPixel()+Point(GetSizePixel().Width()-1,GetSizePixel().Height()));
-        mpShadow->SetPosition(basegfx::B2DPoint(aStart.X(),aStart.Y()), 
basegfx::B2DPoint(aEnd.X(),aEnd.Y()));
-    }
+        if (mpShadow && bChange)
+        {
+            Point aStart = 
EditWin().PixelToLogic(GetPosPixel()+Point(0,GetSizePixel().Height()));
+            Point aEnd = 
EditWin().PixelToLogic(GetPosPixel()+Point(GetSizePixel().Width()-1,GetSizePixel().Height()));
+            mpShadow->SetPosition(basegfx::B2DPoint(aStart.X(),aStart.Y()), 
basegfx::B2DPoint(aEnd.X(),aEnd.Y()));
+        }
 
-    if (mrMgr.ShowNotes())
-    {
         if (IsFollow() && !HasChildPathFocus())
         {
             // #i111964#
@@ -657,7 +662,6 @@ void SwAnnotationWin::SetPosAndSize()
         }
     }
 
-
     // text range overlay
     maAnnotationTextRanges.clear();
     if ( mrSidebarItem.maLayoutInfo.mnStartNodeIdx != SwNodeOffset(0)
@@ -717,7 +721,7 @@ void SwAnnotationWin::SetPosAndSize()
         }
     }
 
-    if (mrMgr.ShowNotes() && !maAnnotationTextRanges.empty())
+    if (bShowNotes && !maAnnotationTextRanges.empty())
     {
         if ( mpTextRangeOverlay != nullptr )
         {
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx 
b/sw/source/uibase/docvw/PostItMgr.cxx
index e0ceb396fc81..07343fa42e47 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -707,7 +707,11 @@ void SwPostItMgr::PreparePageContainer()
 
 void SwPostItMgr::LayoutPostIts()
 {
-    bool bEnableMapMode = comphelper::LibreOfficeKit::isActive() && 
!mpEditWin->IsMapModeEnabled();
+    const bool bLoKitActive = comphelper::LibreOfficeKit::isActive();
+    const bool bTiledAnnotations = 
comphelper::LibreOfficeKit::isTiledAnnotations();
+    const bool bShowNotes = ShowNotes();
+
+    const bool bEnableMapMode = bLoKitActive && !mpEditWin->IsMapModeEnabled();
     if (bEnableMapMode)
         mpEditWin->EnableMapMode();
 
@@ -727,38 +731,13 @@ void SwPostItMgr::LayoutPostIts()
             {
                 std::vector<SwAnnotationWin*> aVisiblePostItList;
                 tools::ULong                  lNeededHeight = 0;
-                tools::Long                    mlPageBorder = 0;
-                tools::Long                    mlPageEnd = 0;
 
                 for (auto const& pItem : pPage->mvSidebarItems)
                 {
                     VclPtr<SwAnnotationWin> pPostIt = pItem->mpPostIt;
 
-                    if (pPage->eSidebarPosition == 
sw::sidebarwindows::SidebarPosition::LEFT )
-                    {
-                        // x value for notes positioning
-                        mlPageBorder = mpEditWin->LogicToPixel( Point( 
pPage->mPageRect.Left(), 0)).X() - GetSidebarWidth(true);// - 
GetSidebarBorderWidth(true);
-                        //bending point
-                        mlPageEnd =
-                            
mpWrtShell->getIDocumentSettingAccess().get(DocumentSettingId::BROWSE_MODE)
-                            ? pItem->maLayoutInfo.mPagePrtArea.Left()
-                            : pPage->mPageRect.Left() + 350;
-                    }
-                    else if (pPage->eSidebarPosition == 
sw::sidebarwindows::SidebarPosition::RIGHT )
-                    {
-                        // x value for notes positioning
-                        mlPageBorder = mpEditWin->LogicToPixel( 
Point(pPage->mPageRect.Right(), 0)).X() + GetSidebarBorderWidth(true);
-                        //bending point
-                        mlPageEnd =
-                            
mpWrtShell->getIDocumentSettingAccess().get(DocumentSettingId::BROWSE_MODE)
-                            ? pItem->maLayoutInfo.mPagePrtArea.Right() :
-                            pPage->mPageRect.Right() - 350;
-                    }
-
                     if (pItem->mbShow)
                     {
-                        tools::Long Y = mpEditWin->LogicToPixel( 
Point(0,pItem->maLayoutInfo.mPosition.Bottom())).Y();
-                        tools::Long aPostItHeight = 0;
                         if (!pPostIt)
                         {
                             pPostIt = pItem->GetSidebarWindow( 
mpView->GetEditWin(),
@@ -779,16 +758,49 @@ void SwPostItMgr::LayoutPostIts()
                             
GetColorAnchor(pItem->maLayoutInfo.mRedlineAuthor));
                         pPostIt->SetSidebarPosition(pPage->eSidebarPosition);
                         
pPostIt->SetFollow(static_cast<bool>(pPostIt->CalcParent()));
-                        aPostItHeight = ( pPostIt->GetPostItTextHeight() < 
pPostIt->GetMinimumSizeWithoutMeta()
-                                          ? 
pPostIt->GetMinimumSizeWithoutMeta()
-                                          : pPostIt->GetPostItTextHeight() )
-                                        + pPostIt->GetMetaHeight();
-                        pPostIt->SetPosSizePixelRect( mlPageBorder ,
-                                                      Y - 
GetInitialAnchorDistance(),
-                                                      GetSidebarWidth(true),
-                                                      aPostItHeight,
-                                                      
pItem->maLayoutInfo.mPosition,
-                                                      mlPageEnd );
+
+                        tools::Long aPostItHeight = 0;
+                        if (bShowNotes)
+                        {
+                            tools::Long mlPageBorder = 0;
+                            tools::Long mlPageEnd = 0;
+
+                            if (pPage->eSidebarPosition == 
sw::sidebarwindows::SidebarPosition::LEFT )
+                            {
+                                // x value for notes positioning
+                                mlPageBorder = mpEditWin->LogicToPixel( Point( 
pPage->mPageRect.Left(), 0)).X() - GetSidebarWidth(true);// - 
GetSidebarBorderWidth(true);
+                                //bending point
+                                mlPageEnd =
+                                    
mpWrtShell->getIDocumentSettingAccess().get(DocumentSettingId::BROWSE_MODE)
+                                    ? pItem->maLayoutInfo.mPagePrtArea.Left()
+                                    : pPage->mPageRect.Left() + 350;
+                            }
+                            else if (pPage->eSidebarPosition == 
sw::sidebarwindows::SidebarPosition::RIGHT )
+                            {
+                                // x value for notes positioning
+                                mlPageBorder = mpEditWin->LogicToPixel( 
Point(pPage->mPageRect.Right(), 0)).X() + GetSidebarBorderWidth(true);
+                                //bending point
+                                mlPageEnd =
+                                    
mpWrtShell->getIDocumentSettingAccess().get(DocumentSettingId::BROWSE_MODE)
+                                    ? pItem->maLayoutInfo.mPagePrtArea.Right() 
:
+                                    pPage->mPageRect.Right() - 350;
+                            }
+
+                            tools::Long Y = mpEditWin->LogicToPixel( 
Point(0,pItem->maLayoutInfo.mPosition.Bottom())).Y();
+
+                            aPostItHeight = ( pPostIt->GetPostItTextHeight() < 
pPostIt->GetMinimumSizeWithoutMeta()
+                                              ? 
pPostIt->GetMinimumSizeWithoutMeta()
+                                              : pPostIt->GetPostItTextHeight() 
)
+                                            + pPostIt->GetMetaHeight();
+                            pPostIt->SetPosSizePixelRect( mlPageBorder ,
+                                                          Y - 
GetInitialAnchorDistance(),
+                                                          
GetSidebarWidth(true),
+                                                          aPostItHeight,
+                                                          mlPageEnd );
+                        }
+
+                        pPostIt->SetAnchorRect(pItem->maLayoutInfo.mPosition);
+
                         pPostIt->ChangeSidebarItem( *pItem );
 
                         if (pItem->mbFocus)
@@ -799,7 +811,8 @@ void SwPostItMgr::LayoutPostIts()
                         }
                         // only the visible postits are used for the final 
layout
                         aVisiblePostItList.push_back(pPostIt);
-                        lNeededHeight += pPostIt->IsFollow() ? aPostItHeight : 
aPostItHeight+GetSpaceBetween();
+                        if (bShowNotes)
+                            lNeededHeight += pPostIt->IsFollow() ? 
aPostItHeight : aPostItHeight+GetSpaceBetween();
                     }
                     else // we don't want to see it
                     {
@@ -808,13 +821,10 @@ void SwPostItMgr::LayoutPostIts()
                     }
                 }
 
-                if ((!aVisiblePostItList.empty()) && ShowNotes())
+                if (!aVisiblePostItList.empty() && ShowNotes())
                 {
                     bool bOldScrollbar = pPage->bScrollbar;
-                    if (ShowNotes())
-                        pPage->bScrollbar = LayoutByPage(aVisiblePostItList, 
pPage->mPageRect.SVRect(), lNeededHeight);
-                    else
-                        pPage->bScrollbar = false;
+                    pPage->bScrollbar = LayoutByPage(aVisiblePostItList, 
pPage->mPageRect.SVRect(), lNeededHeight);
                     if (!pPage->bScrollbar)
                     {
                         pPage->lOffset = 0;
@@ -893,7 +903,7 @@ void SwPostItMgr::LayoutPostIts()
 
                 for (auto const& visiblePostIt : aVisiblePostItList)
                 {
-                    if (comphelper::LibreOfficeKit::isActive() && 
!comphelper::LibreOfficeKit::isTiledAnnotations())
+                    if (bLoKitActive && !bTiledAnnotations)
                     {
                         if (visiblePostIt->GetSidebarItem().mbPendingLayout)
                             lcl_CommentNotification(mpView, 
CommentNotificationType::Add, &visiblePostIt->GetSidebarItem(), 0);
@@ -916,7 +926,7 @@ void SwPostItMgr::LayoutPostIts()
             }
         }
 
-        if (!ShowNotes())
+        if (!bShowNotes)
         {       // we do not want to see the notes anymore -> 
Options-Writer-View-Notes
             IDocumentRedlineAccess const& 
rIDRA(mpWrtShell->getIDocumentRedlineAccess());
             bool bRepair = false;

Reply via email to