include/svx/ruler.hxx             |    7 +++
 svx/source/dialog/svxruler.cxx    |   48 ++++++++++++++++++++++++++
 sw/source/uibase/inc/swruler.hxx  |    5 --
 sw/source/uibase/misc/swruler.cxx |   68 --------------------------------------
 sw/source/uibase/uiview/view.cxx  |    2 -
 5 files changed, 55 insertions(+), 75 deletions(-)

New commits:
commit 9f26e04c8f97af9139e2f4be335fe6999d26a387
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu May 16 19:52:32 2024 +0900
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri May 17 08:45:01 2024 +0200

    svx: move lok's NotifyKit in the ruler to the SvxRuler super-class
    
    We want to make the ruler work in other components and also not
    only for horizontal orientation. For this we want the NotifyKit
    already in the SvxRuler, which is used by all rulers. This change
    moves the functionality to the from SwCommentRuler to SvxRuler and
    partially reverts the previous attempt as changing the ruler
    instance for vertical ruelr to SwCommentRuler caused test failures.
    
    Change-Id: Ie618b5dc5b936f9dc53d09b624eefdbc506d98f5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167740
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/include/svx/ruler.hxx b/include/svx/ruler.hxx
index 486515f1822a..f9d91412b229 100644
--- a/include/svx/ruler.hxx
+++ b/include/svx/ruler.hxx
@@ -40,6 +40,7 @@ class SfxRectangleItem;
 class SvxObjectItem;
 class SfxBoolItem;
 struct SvxRuler_Impl;
+namespace tools { class JsonWriter; }
 
 enum class RulerChangeType
 {
@@ -162,6 +163,8 @@ class SVX_DLLPUBLIC SvxRuler: public Ruler, public 
SfxListener
     void UpdateColumns();
     void UpdateObject();
 
+    void NotifyKit();
+
     // Convert position to stick to ruler ticks
     tools::Long MakePositionSticky(tools::Long rValue, tools::Long 
aPointOfReference, bool aSnapToFrameMargin = true) const;
 
@@ -230,6 +233,8 @@ class SVX_DLLPUBLIC SvxRuler: public Ruler, public 
SfxListener
     void UpdateParaContents_Impl(tools::Long lDiff, UpdateType);
 
 protected:
+    bool isHorizontal() { return bHorz; }
+
     virtual void    Command( const CommandEvent& rCEvt ) override;
     virtual void    Click() override;
     virtual bool    StartDrag() override;
@@ -275,6 +280,8 @@ public:
         Update();
     }
 
+    void CreateJsonNotification(tools::JsonWriter& rJsonWriter);
+
     //#i24363# tab stops relative to indent
     void SetTabsRelativeToIndent( bool bRel );
     void SetValues(RulerChangeType type, tools::Long value);
diff --git a/svx/source/dialog/svxruler.cxx b/svx/source/dialog/svxruler.cxx
index 17c4edaa930d..14b7ce6d79d6 100644
--- a/svx/source/dialog/svxruler.cxx
+++ b/svx/source/dialog/svxruler.cxx
@@ -36,6 +36,7 @@
 #include <svx/dialmgr.hxx>
 #include <svx/ruler.hxx>
 #include <svx/rulritem.hxx>
+#include <sfx2/viewsh.hxx>
 #include <editeng/editids.hrc>
 #include <editeng/tstpitem.hxx>
 #include <editeng/lrspitem.hxx>
@@ -44,7 +45,10 @@
 #include <rtl/math.hxx>
 #include <o3tl/string_view.hxx>
 #include <svl/itemset.hxx>
-
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <tools/json_writer.hxx>
+#include <tools/UnitConversion.hxx>
+#include <comphelper/lok.hxx>
 #include "rlrcitem.hxx"
 #include <memory>
 
@@ -1141,6 +1145,46 @@ void SvxRuler::SetNullOffsetLogic(tools::Long lVal) // 
Setting of the logic Null
     Update();
 }
 
+void SvxRuler::CreateJsonNotification(tools::JsonWriter& rJsonWriter)
+{
+    rJsonWriter.put("margin1", convertTwipToMm100(GetMargin1()));
+    rJsonWriter.put("margin2", convertTwipToMm100(GetMargin2()));
+    rJsonWriter.put("leftOffset", convertTwipToMm100(GetNullOffset()));
+    rJsonWriter.put("pageOffset", convertTwipToMm100(GetPageOffset()));
+
+    rJsonWriter.put("pageWidth", convertTwipToMm100(GetPageWidth()));
+    {
+        auto tabsNode = rJsonWriter.startNode("tabs");
+
+        // The RulerTab array elements that GetTabs() returns have their nPos 
field in twips. So these
+        // too are actual mm100.
+        for (auto const& tab : GetTabs())
+        {
+            auto tabNode = rJsonWriter.startNode("");
+            rJsonWriter.put("position", convertTwipToMm100(tab.nPos));
+            rJsonWriter.put("style", tab.nStyle);
+        }
+    }
+
+    RulerUnitData aUnitData = GetCurrentRulerUnit();
+    rJsonWriter.put("unit", aUnitData.aUnitStr);
+}
+
+void SvxRuler::NotifyKit()
+{
+    if (!comphelper::LibreOfficeKit::isActive())
+        return;
+    SfxViewShell* pViewShell = SfxViewShell::Current();
+    if (!pViewShell)
+        return;
+
+    tools::JsonWriter aJsonWriter;
+    CreateJsonNotification(aJsonWriter);
+    OString pJsonData = aJsonWriter.finishAndGetAsOString();
+    LibreOfficeKitCallbackType eType = isHorizontal() ? 
LOK_CALLBACK_RULER_UPDATE : LOK_CALLBACK_VERTICAL_RULER_UPDATE;
+    pViewShell->libreOfficeKitViewCallback(eType, pJsonData);
+}
+
 void SvxRuler::Update()
 {
     /* Perform update of view */
@@ -1159,6 +1203,8 @@ void SvxRuler::Update()
 
     if(nFlags & SvxRulerSupportFlags::TABS)
       UpdateTabs();
+
+    NotifyKit();
 }
 
 tools::Long SvxRuler::GetPageWidth() const
diff --git a/sw/source/uibase/inc/swruler.hxx b/sw/source/uibase/inc/swruler.hxx
index 430c089abfe0..2dc14e98fd87 100644
--- a/sw/source/uibase/inc/swruler.hxx
+++ b/sw/source/uibase/inc/swruler.hxx
@@ -18,7 +18,6 @@ class SwViewShell;
 class View;
 namespace vcl { class Window; }
 class SwEditWin;
-namespace tools { class JsonWriter; }
 
 /**
  * An horizontal ruler with a control for comment panel visibility for Writer.
@@ -43,8 +42,6 @@ public:
      * \param rRect ignored
      */
     virtual void Paint( vcl::RenderContext& rRenderContext, const 
tools::Rectangle& rRect ) override;
-    void CreateJsonNotification(tools::JsonWriter& rJsonWriter);
-    bool IsHorizontal() const { return mbHorizontal; }
 
 private:
     SwViewShell * mpViewShell;     //< Shell to check if there is any comments 
on doc and their visibility
@@ -53,9 +50,7 @@ private:
     Timer       maFadeTimer;     //< Timer for high/'low'light fading
     int         mnFadeRate;      //< From 0 to 100. 0 means not highlighted.
     ScopedVclPtr<VirtualDevice> maVirDev;      //< VirtualDevice of this 
window. Just for convenience.
-    bool mbHorizontal;     // Check if ruler is horizontal or not
 
-    void NotifyKit();
     /**
      * Callback function to handle a mouse button down event.
      *
diff --git a/sw/source/uibase/misc/swruler.cxx 
b/sw/source/uibase/misc/swruler.cxx
index bce0e27489ca..ac2e0a89ea78 100644
--- a/sw/source/uibase/misc/swruler.cxx
+++ b/sw/source/uibase/misc/swruler.cxx
@@ -17,15 +17,12 @@
 #include <view.hxx>
 #include <cmdid.h>
 #include <sfx2/request.hxx>
-#include <tools/UnitConversion.hxx>
 #include <vcl/commandevent.hxx>
 #include <vcl/event.hxx>
 #include <vcl/window.hxx>
 #include <vcl/settings.hxx>
-#include <tools/json_writer.hxx>
 #include <strings.hrc>
 #include <comphelper/lok.hxx>
-#include <LibreOfficeKit/LibreOfficeKitEnums.h>
 
 #define CONTROL_BORDER_WIDTH 1
 
@@ -96,7 +93,6 @@ SwCommentRuler::SwCommentRuler(SwViewShell* pViewSh, 
vcl::Window* pParent, SwEdi
     vcl::Font aFont(maVirDev->GetFont());
     aFont.SetFontHeight(aFont.GetFontHeight() + 1);
     maVirDev->SetFont(aFont);
-    mbHorizontal = nWinStyle & WB_HSCROLL;
 }
 
 SwCommentRuler::~SwCommentRuler() { disposeOnce(); }
@@ -234,76 +230,12 @@ void SwCommentRuler::MouseButtonDown(const MouseEvent& 
rMEvt)
     Invalidate();
 }
 
-void SwCommentRuler::CreateJsonNotification(tools::JsonWriter& rJsonWriter)
-{
-    // Note that GetMargin1(), GetMargin2(), GetNullOffset(), and 
GetPageOffset() return values in
-    // pixels. Not twips. So "converting" the returned values with 
convertTwipToMm100() is quite
-    // wrong. (Also, even if the return values actually were in twips, it is 
questionable why we
-    // would want to pass them in mm100, as all other length values in the 
LOKit protocol apparently
-    // are in twips.)
-
-    // Anyway, as the consuming code in Online mostly seems to work anyway, it 
is likely that it
-    // would work as well even if the values in pixels were passed without a 
bogus "conversion" to
-    // mm100. But let's keep this as is for now.
-
-    // Also note that in desktop LibreOffice, these pixel values for the ruler 
of course change as
-    // one changes the zoom level. (Can be seen if one temporarily modifies 
the NotifyKit() function
-    // below to call this CreateJsonNotification() function and print its 
result in all cases even
-    // without LibreOfficeKit::isActive().) But in both web-based Online and 
in the iOS app, the
-    // zoom level from the point of view of this code here apparently does not 
change even if one
-    // zooms from the Online code's point of view.
-    rJsonWriter.put("margin1", convertTwipToMm100(GetMargin1()));
-    rJsonWriter.put("margin2", convertTwipToMm100(GetMargin2()));
-    rJsonWriter.put("leftOffset", convertTwipToMm100(GetNullOffset()));
-    rJsonWriter.put("pageOffset", convertTwipToMm100(GetPageOffset()));
-
-    // GetPageWidth() on the other hand does return a value in twips.
-    // So here convertTwipToMm100() really does produce actual mm100. Fun.
-    rJsonWriter.put("pageWidth", convertTwipToMm100(GetPageWidth()));
-    {
-        auto tabsNode = rJsonWriter.startNode("tabs");
-
-        // The RulerTab array elements that GetTabs() returns have their nPos 
field in twips. So these
-        // too are actual mm100.
-        for (auto const& tab : GetTabs())
-        {
-            auto tabNode = rJsonWriter.startNode("");
-            rJsonWriter.put("position", convertTwipToMm100(tab.nPos));
-            rJsonWriter.put("style", tab.nStyle);
-        }
-    }
-
-    RulerUnitData aUnitData = GetCurrentRulerUnit();
-    rJsonWriter.put("unit", aUnitData.aUnitStr);
-}
-
-void SwCommentRuler::NotifyKit()
-{
-    if (!comphelper::LibreOfficeKit::isActive())
-        return;
-
-    tools::JsonWriter aJsonWriter;
-    CreateJsonNotification(aJsonWriter);
-    OString pJsonData = aJsonWriter.finishAndGetAsOString();
-    if (mbHorizontal)
-    {
-        
mpViewShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_RULER_UPDATE,
-                                                                   pJsonData);
-    }
-    else
-    {
-        mpViewShell->GetSfxViewShell()->libreOfficeKitViewCallback(
-            LOK_CALLBACK_VERTICAL_RULER_UPDATE, pJsonData);
-    }
-}
-
 void SwCommentRuler::Update()
 {
     tools::Rectangle aPreviousControlRect = GetCommentControlRegion();
     SvxRuler::Update();
     if (aPreviousControlRect != GetCommentControlRegion())
         Invalidate();
-    NotifyKit();
 }
 
 void SwCommentRuler::UpdateCommentHelpText()
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index 25d3f101ddb9..7ed676df1aca 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -938,7 +938,7 @@ SwView::SwView(SfxViewFrame& _rFrame, SfxViewShell* pOldSh)
                 GetViewFrame().GetBindings(),
                 WB_STDRULER | WB_EXTRAFIELD | WB_BORDER);
 
-    m_pVRuler = VclPtr<SwCommentRuler>::Create(m_pWrtShell.get(), 
&GetViewFrame().GetWindow(), m_pEditWin,
+    m_pVRuler = VclPtr<SvxRuler>::Create(&GetViewFrame().GetWindow(), 
m_pEditWin,
                 SvxRulerSupportFlags::TABS |
                 SvxRulerSupportFlags::PARAGRAPH_MARGINS_VERTICAL |
                 SvxRulerSupportFlags::BORDERS |

Reply via email to