sw/inc/PostItMgr.hxx | 4 + sw/source/uibase/docvw/PostItMgr.cxx | 84 +++++++++++++++++++++++------------ sw/source/uibase/docvw/edtwin.cxx | 19 +++++++ sw/source/uibase/inc/edtwin.hxx | 1 sw/source/uibase/misc/swruler.cxx | 3 - 5 files changed, 80 insertions(+), 31 deletions(-)
New commits: commit b9368eab798a766b5a24658c783a6ee73dbf2caa Author: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> AuthorDate: Mon Jan 22 10:57:06 2024 +0100 Commit: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> CommitDate: Mon Jan 22 12:19:47 2024 +0100 tdf#159145 Allow changing width of comment column on right border not only on the ruler as implemented in ac2720dcbe4e51e7f6733a385b5f7b571c6431e9 Change-Id: Ib3709e97be312a7e20302ffa703e847f9efa3110 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162365 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> diff --git a/sw/inc/PostItMgr.hxx b/sw/inc/PostItMgr.hxx index ec6604c43a23..2278ae05ea6f 100644 --- a/sw/inc/PostItMgr.hxx +++ b/sw/inc/PostItMgr.hxx @@ -150,7 +150,8 @@ class SAL_DLLPUBLIC_RTTI SwPostItMgr final : public SfxListener bool ShowScrollbar(const tools::ULong aPage) const; bool HasNotes() const ; bool ShowNotes() const; - void SetSidebarWidth(sal_uInt16 nPx); + void SetSidebarWidth(Point aPoint); + tools::Rectangle GetSidebarRect(const Point& rPointLogic); tools::ULong GetSidebarWidth(bool bPx = false) const; tools::ULong GetSidebarBorderWidth(bool bPx = false) const; @@ -183,6 +184,7 @@ class SAL_DLLPUBLIC_RTTI SwPostItMgr final : public SfxListener bool IsHit(const Point &aPointPixel); /// Get the matching window that is responsible for handling mouse events of rPointLogic, if any. vcl::Window* IsHitSidebarWindow(const Point& rPointLogic); + bool IsHitSidebarDragArea(const Point& rPointLogic); Color GetArrowColor(sal_uInt16 aDirection, tools::ULong aPage) const; sw::annotation::SwAnnotationWin* GetAnnotationWin(const SwPostItField* pField) const; diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx index 24abcc14a2a5..7af447a63a5d 100644 --- a/sw/source/uibase/docvw/PostItMgr.cxx +++ b/sw/source/uibase/docvw/PostItMgr.cxx @@ -1979,32 +1979,25 @@ bool SwPostItMgr::ShowScrollbar(const tools::ULong aPage) const return false; } -bool SwPostItMgr::IsHit(const Point &aPointPixel) +bool SwPostItMgr::IsHit(const Point& aPointPixel) { - if (HasNotes() && ShowNotes()) - { - const Point aPoint = mpEditWin->PixelToLogic(aPointPixel); - const SwRootFrame* pLayout = mpWrtShell->GetLayout(); - SwRect aPageFrame; - const tools::ULong nPageNum = SwPostItHelper::getPageInfo( aPageFrame, pLayout, aPoint ); - if( nPageNum ) - { - tools::Rectangle aRect; - OSL_ENSURE(mPages.size()>nPageNum-1,"SwPostitMgr:: page container size wrong"); - aRect = mPages[nPageNum-1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT - ? tools::Rectangle(Point(aPageFrame.Left()-GetSidebarWidth()-GetSidebarBorderWidth(),aPageFrame.Top()),Size(GetSidebarWidth(),aPageFrame.Height())) - : tools::Rectangle( Point(aPageFrame.Right()+GetSidebarBorderWidth(),aPageFrame.Top()) , Size(GetSidebarWidth(),aPageFrame.Height())); - if (aRect.Contains(aPoint)) - { - // we hit the note's sidebar - // lets now test for the arrow area - if (mPages[nPageNum-1]->bScrollbar) - return ScrollbarHit(nPageNum,aPoint); - else - return false; - } - } - } + if (!HasNotes() || !ShowNotes()) + return false; + + const Point aPoint = mpEditWin->PixelToLogic(aPointPixel); + tools::Rectangle aRect(GetSidebarRect(aPoint)); + if (!aRect.Contains(aPoint)) + return false; + + // we hit the note's sidebar + // lets now test for the arrow area + SwRect aPageFrame; + const tools::ULong nPageNum + = SwPostItHelper::getPageInfo(aPageFrame, mpWrtShell->GetLayout(), aPoint); + if (!nPageNum) + return false; + if (mPages[nPageNum - 1]->bScrollbar) + return ScrollbarHit(nPageNum, aPoint); return false; } @@ -2038,6 +2031,38 @@ vcl::Window* SwPostItMgr::IsHitSidebarWindow(const Point& rPointLogic) return pRet; } +tools::Rectangle SwPostItMgr::GetSidebarRect(const Point& rPointLogic) +{ + const SwRootFrame* pLayout = mpWrtShell->GetLayout(); + SwRect aPageFrame; + const tools::ULong nPageNum = SwPostItHelper::getPageInfo(aPageFrame, pLayout, rPointLogic); + if (!nPageNum) + return tools::Rectangle(); + + OSL_ENSURE(mPages.size() > nPageNum - 1, "SwPostitMgr:: page container size wrong"); + return mPages[nPageNum - 1]->eSidebarPosition == sw::sidebarwindows::SidebarPosition::LEFT + ? tools::Rectangle( + Point(aPageFrame.Left() - GetSidebarWidth() - GetSidebarBorderWidth(), + aPageFrame.Top()), + Size(GetSidebarWidth(), aPageFrame.Height())) + : tools::Rectangle( + Point(aPageFrame.Right() + GetSidebarBorderWidth(), aPageFrame.Top()), + Size(GetSidebarWidth(), aPageFrame.Height())); +} + +bool SwPostItMgr::IsHitSidebarDragArea(const Point& rPointPx) +{ + if (!HasNotes() || !ShowNotes()) + return false; + const Point aPoint = mpEditWin->PixelToLogic(rPointPx); + tools::Rectangle aDragArea(GetSidebarRect(aPoint)); + aDragArea.SetPos(Point(aDragArea.TopRight().X() - 50, aDragArea.TopRight().Y())); + Size aS(aDragArea.GetSize()); + aS.setWidth(100); + aDragArea.SetSize(aS); + return aDragArea.Contains(aPoint); +} + tools::Rectangle SwPostItMgr::GetBottomScrollRect(const tools::ULong aPage) const { SwRect aPageRect = mPages[aPage-1]->mPageRect; @@ -2151,12 +2176,15 @@ bool SwPostItMgr::HasNotes() const return !mvPostItFields.empty(); } -void SwPostItMgr::SetSidebarWidth(sal_uInt16 nPx) +void SwPostItMgr::SetSidebarWidth(Point aMousePos) { sal_uInt16 nZoom = mpWrtShell->GetViewOptions()->GetZoom(); - double nFactor = static_cast<double>(nPx) / static_cast<double>(nZoom); + sal_uInt16 nPxWidth + = aMousePos.X() - mpEditWin->LogicToPixel(GetSidebarRect(aMousePos).TopLeft()).X(); + double nFactor = static_cast<double>(nPxWidth) / static_cast<double>(nZoom); nFactor = std::clamp(nFactor, 1.0, 8.0); - std::shared_ptr<comphelper::ConfigurationChanges> xChanges(comphelper::ConfigurationChanges::create()); + std::shared_ptr<comphelper::ConfigurationChanges> xChanges( + comphelper::ConfigurationChanges::create()); officecfg::Office::Writer::Notes::DisplayWidthFactor::set(nFactor, xChanges); xChanges->commit(); LayoutPostIts(); diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index dc5914bfa791..9c4a3e6c69ee 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -2945,6 +2945,12 @@ void SwEditWin::MouseButtonDown(const MouseEvent& _rMEvt) } } + if (m_rView.GetPostItMgr()->IsHitSidebarDragArea(aMEvt.GetPosPixel())) + { + mbIsDragSidebar = true; + return; + } + m_rView.GetPostItMgr()->SetActiveSidebarWin(nullptr); GrabFocus(); @@ -4061,6 +4067,11 @@ void SwEditWin::MouseMove(const MouseEvent& _rMEvt) return; } } + if (m_rView.GetPostItMgr()->IsHitSidebarDragArea(rMEvt.GetPosPixel())) + { + SetPointer(PointerStyle::HSizeBar); + return; + } //ignore key modifiers for format paintbrush { @@ -4613,6 +4624,13 @@ void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt) } } + if (mbIsDragSidebar) + { + m_rView.GetPostItMgr()->SetSidebarWidth(rMEvt.GetPosPixel()); + mbIsDragSidebar = false; + return; + } + bool bCallBase = true; bool bCallShadowCursor = m_bWasShdwCursor; @@ -5412,6 +5430,7 @@ SwEditWin::SwEditWin(vcl::Window *pParent, SwView &rMyView): m_bIsRowDrag(false), m_bUseInputLanguage(false), m_bObjectSelect(false), + mbIsDragSidebar(false), m_nKS_NUMDOWN_Count(0), m_nKS_NUMINDENTINC_Count(0), m_pFrameControlsManager(new SwFrameControlsManager(this)) diff --git a/sw/source/uibase/inc/edtwin.hxx b/sw/source/uibase/inc/edtwin.hxx index 3c180718c033..ec2df846c8ee 100644 --- a/sw/source/uibase/inc/edtwin.hxx +++ b/sw/source/uibase/inc/edtwin.hxx @@ -125,6 +125,7 @@ class SW_DLLPUBLIC SwEditWin final : public vcl::DocWindow, */ m_bUseInputLanguage: 1, m_bObjectSelect : 1, + mbIsDragSidebar : 1, m_bMaybeShowTooltipAfterBufferFlush : 1 = false; sal_uInt16 m_nKS_NUMDOWN_Count; // #i23725# diff --git a/sw/source/uibase/misc/swruler.cxx b/sw/source/uibase/misc/swruler.cxx index 7d9f6f1aba84..7f74f4afd6d7 100644 --- a/sw/source/uibase/misc/swruler.cxx +++ b/sw/source/uibase/misc/swruler.cxx @@ -257,8 +257,7 @@ void SwCommentRuler::MouseButtonUp(const MouseEvent& rMEvt) SvxRuler::MouseButtonUp(rMEvt); return; } - mpViewShell->GetPostItMgr()->SetSidebarWidth(rMEvt.GetPosPixel().X() - - GetCommentControlRegion().TopLeft().X()); + mpViewShell->GetPostItMgr()->SetSidebarWidth(rMEvt.GetPosPixel()); mbIsDrag = false; Invalidate(); }