officecfg/registry/schema/org/openoffice/Office/Writer.xcs |   11 ++
 sw/inc/PostItMgr.hxx                                       |    1 
 sw/source/uibase/docvw/AnnotationWin2.cxx                  |    3 
 sw/source/uibase/docvw/PostItMgr.cxx                       |   15 +++
 sw/source/uibase/inc/swruler.hxx                           |    6 +
 sw/source/uibase/misc/swruler.cxx                          |   51 +++++++++++--
 6 files changed, 79 insertions(+), 8 deletions(-)

New commits:
commit ac2720dcbe4e51e7f6733a385b5f7b571c6431e9
Author:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
AuthorDate: Thu Jan 4 14:23:21 2024 +0100
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
CommitDate: Thu Jan 11 09:03:38 2024 +0100

    tdf#73953 sw: Allow resizing the comment section
    
    Change-Id: If2920b31a82b3f3d42038e75f3637be9802711fb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161616
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>

diff --git a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs 
b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs
index c3908721cbc3..ead842b58e91 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs
@@ -4911,6 +4911,17 @@
         </info>
         <value>false</value>
       </prop>
+      <prop oor:name="DisplayWidthFactor" oor:type="xs:double" 
oor:nillable="false">
+        <!-- UIHints: Can be changed by scaling the comment section width -->
+        <info>
+          <desc>Defines the width of the comment bar in Writer. Factor between 
1 and 8.</desc>
+        </info>
+        <value>1.8</value>
+        <constraints>
+          <minInclusive oor:value="1"/>
+          <maxInclusive oor:value="8"/>
+        </constraints>
+      </prop>
     </group>
     <group oor:name="WordCount">
       <info>
diff --git a/sw/inc/PostItMgr.hxx b/sw/inc/PostItMgr.hxx
index 98d9f4f2ef30..510a4fa55a2a 100644
--- a/sw/inc/PostItMgr.hxx
+++ b/sw/inc/PostItMgr.hxx
@@ -191,6 +191,7 @@ class SAL_DLLPUBLIC_RTTI SwPostItMgr final : public 
SfxListener
         bool HasNotes() const ;
         bool ShowNotes() const;
         bool IsShowAnchor() const { return mbIsShowAnchor;}
+        void SetSidebarWidth(sal_uInt16 nPx);
         tools::ULong GetSidebarWidth(bool bPx = false) const;
         tools::ULong GetSidebarBorderWidth(bool bPx = false) const;
 
diff --git a/sw/source/uibase/docvw/AnnotationWin2.cxx 
b/sw/source/uibase/docvw/AnnotationWin2.cxx
index a1780f9132c8..e3bc460d941c 100644
--- a/sw/source/uibase/docvw/AnnotationWin2.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin2.cxx
@@ -564,7 +564,10 @@ void SwAnnotationWin::SetPosAndSize()
         {
             bChange = true;
             SetPosPixel(mPosSize.TopLeft());
+        }
 
+        if (bChange)
+        {
             Point aLineStart;
             Point aLineEnd ;
             switch ( meSidebarPosition )
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx 
b/sw/source/uibase/docvw/PostItMgr.cxx
index 12c5e4f52d11..e50641a9176e 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -56,6 +56,7 @@
 #include <SwRewriter.hxx>
 #include <tools/color.hxx>
 #include <unotools/datetime.hxx>
+#include <officecfg/Office/Writer.hxx>
 
 #include <swmodule.hxx>
 #include <strings.hrc>
@@ -2154,6 +2155,17 @@ bool SwPostItMgr::HasNotes() const
     return !mvPostItFields.empty();
 }
 
+void SwPostItMgr::SetSidebarWidth(sal_uInt16 nPx)
+{
+    sal_uInt16 nZoom = mpWrtShell->GetViewOptions()->GetZoom();
+    double nFactor = static_cast<double>(nPx) /  static_cast<double>(nZoom);
+    nFactor = std::clamp(nFactor, 1.0, 8.0);
+    std::shared_ptr<comphelper::ConfigurationChanges> 
xChanges(comphelper::ConfigurationChanges::create());
+    officecfg::Office::Writer::Notes::DisplayWidthFactor::set(nFactor, 
xChanges);
+    xChanges->commit();
+    LayoutPostIts();
+}
+
 tools::ULong SwPostItMgr::GetSidebarWidth(bool bPx) const
 {
     bool bEnableMapMode = !mpWrtShell->GetOut()->IsMapModeEnabled();
@@ -2164,7 +2176,8 @@ tools::ULong SwPostItMgr::GetSidebarWidth(bool bPx) const
         double fScaleX = 
double(mpWrtShell->GetOut()->GetMapMode().GetScaleX());
         nZoom = fScaleX * 100;
     }
-    tools::ULong aWidth = static_cast<tools::ULong>(nZoom * 1.8);
+    tools::ULong aWidth = static_cast<tools::ULong>(
+        nZoom * officecfg::Office::Writer::Notes::DisplayWidthFactor::get());
 
     if (bPx)
         return aWidth;
diff --git a/sw/source/uibase/inc/swruler.hxx b/sw/source/uibase/inc/swruler.hxx
index 6c903f9ca9a5..f18f8721fc8a 100644
--- a/sw/source/uibase/inc/swruler.hxx
+++ b/sw/source/uibase/inc/swruler.hxx
@@ -48,6 +48,8 @@ public:
 private:
     SwViewShell * mpViewShell;     //< Shell to check if there is any comments 
on doc and their visibility
     VclPtr<SwEditWin> mpSwWin;         //< Used to get SwView to change the 
SideBar visibility
+    /// User is currently dragging the thing
+    bool        mbIsDrag;
     bool        mbIsHighlighted; //< If comment control is highlighted (mouse 
is over it)
     Timer       maFadeTimer;     //< Timer for high/'low'light fading
     int         mnFadeRate;      //< From 0 to 100. 0 means not highlighted.
@@ -60,6 +62,8 @@ private:
      * When on comment control, it toggles the comment panel visibility.
      */
     virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
+
+    virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
     /**
      * Callback function to handle a mouse move event.
      *
@@ -80,6 +84,8 @@ private:
      */
     virtual void Update() override;
 
+    tools::Rectangle GetDragArea();
+
     /**
      * Get the rectangle area that should be used to draw the comment control.
      *
diff --git a/sw/source/uibase/misc/swruler.cxx 
b/sw/source/uibase/misc/swruler.cxx
index 59c28e0ca201..aeed7ea677c5 100644
--- a/sw/source/uibase/misc/swruler.cxx
+++ b/sw/source/uibase/misc/swruler.cxx
@@ -12,6 +12,7 @@
 #include <swruler.hxx>
 
 #include <viewsh.hxx>
+#include <viewopt.hxx>
 #include <edtwin.hxx>
 #include <PostItMgr.hxx>
 #include <view.hxx>
@@ -20,6 +21,7 @@
 #include <tools/UnitConversion.hxx>
 #include <vcl/commandevent.hxx>
 #include <vcl/event.hxx>
+#include <vcl/ptrstyle.hxx>
 #include <vcl/window.hxx>
 #include <vcl/settings.hxx>
 #include <tools/json_writer.hxx>
@@ -199,6 +201,9 @@ void SwCommentRuler::Command(const CommandEvent& rCEvt)
 
 void SwCommentRuler::MouseMove(const MouseEvent& rMEvt)
 {
+    if (mbIsDrag)
+        return;
+
     SvxRuler::MouseMove(rMEvt);
     if (!mpViewShell->GetPostItMgr() || 
!mpViewShell->GetPostItMgr()->HasNotes())
         return;
@@ -206,6 +211,9 @@ void SwCommentRuler::MouseMove(const MouseEvent& rMEvt)
     UpdateCommentHelpText();
 
     Point aMousePos = rMEvt.GetPosPixel();
+    if (GetDragArea().Contains(aMousePos))
+        SetPointer(PointerStyle::HSizeBar);
+
     bool bWasHighlighted = mbIsHighlighted;
     mbIsHighlighted = GetCommentControlRegion().Contains(aMousePos);
     if (mbIsHighlighted != bWasHighlighted)
@@ -216,23 +224,44 @@ void SwCommentRuler::MouseMove(const MouseEvent& rMEvt)
 void SwCommentRuler::MouseButtonDown(const MouseEvent& rMEvt)
 {
     Point aMousePos = rMEvt.GetPosPixel();
-    if (!rMEvt.IsLeft() || IsTracking() || 
!GetCommentControlRegion().Contains(aMousePos))
+    if (!rMEvt.IsLeft() || IsTracking()
+        || (!GetCommentControlRegion().Contains(aMousePos) && 
!GetDragArea().Contains(aMousePos)))
     {
         SvxRuler::MouseButtonDown(rMEvt);
         return;
     }
 
-    // Toggle notes visibility
-    SwView& rView = mpSwWin->GetView();
-    SfxRequest aRequest(rView.GetViewFrame(), SID_TOGGLE_NOTES);
-    rView.ExecViewOptions(aRequest);
+    if (GetDragArea().Contains(aMousePos))
+    {
+        mbIsDrag = true;
+    }
+    else
+    {
+        // Toggle notes visibility
+        SwView& rView = mpSwWin->GetView();
+        SfxRequest aRequest(rView.GetViewFrame(), SID_TOGGLE_NOTES);
+        rView.ExecViewOptions(aRequest);
 
-    // It is inside comment control, so update help text
-    UpdateCommentHelpText();
+        // It is inside comment control, so update help text
+        UpdateCommentHelpText();
+    }
 
     Invalidate();
 }
 
+void SwCommentRuler::MouseButtonUp(const MouseEvent& rMEvt)
+{
+    if (!mbIsDrag)
+    {
+        SvxRuler::MouseButtonUp(rMEvt);
+        return;
+    }
+    mpViewShell->GetPostItMgr()->SetSidebarWidth(rMEvt.GetPosPixel().X()
+                                                 - 
GetCommentControlRegion().TopLeft().X());
+    mbIsDrag = false;
+    Invalidate();
+}
+
 void SwCommentRuler::CreateJsonNotification(tools::JsonWriter& rJsonWriter)
 {
     // Note that GetMargin1(), GetMargin2(), GetNullOffset(), and 
GetPageOffset() return values in
@@ -308,6 +337,14 @@ void SwCommentRuler::UpdateCommentHelpText()
     SetQuickHelpText(SwResId(pTooltipResId));
 }
 
+tools::Rectangle SwCommentRuler::GetDragArea()
+{
+    tools::Rectangle base(GetCommentControlRegion());
+    base.Move(Size(base.GetWidth() - 5, 0));
+    base.SetWidth(10);
+    return base;
+}
+
 // TODO Make Ruler return its central rectangle instead of margins.
 tools::Rectangle SwCommentRuler::GetCommentControlRegion()
 {

Reply via email to