desktop/source/lib/init.cxx       |    5 +++--
 include/sfx2/viewsh.hxx           |    5 +++--
 sfx2/source/view/viewsh.cxx       |    2 +-
 sw/inc/view.hxx                   |    2 +-
 sw/inc/viscrs.hxx                 |    4 ++--
 sw/source/core/crsr/viscrs.cxx    |    6 ++++--
 sw/source/uibase/inc/wrtsh.hxx    |    2 +-
 sw/source/uibase/uiview/view.cxx  |    4 ++--
 sw/source/uibase/wrtsh/wrtsh4.cxx |    6 +++---
 test/source/lokcallback.cxx       |   10 ++++++----
 10 files changed, 26 insertions(+), 20 deletions(-)

New commits:
commit c33f23598f9bc5ed80c95b18e373c91b68b2511e
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Fri Nov 12 10:56:54 2021 +0100
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Fri Nov 12 12:10:00 2021 +0100

    make it explicit whether to ignore the result of getLOKPayload()
    
    Returning an empty string to signify 'ignore' was a poor design,
    as some messages types actually may have valid empty messages.
    
    Change-Id: Ia82d3d97d150bc5ef412a1bd4b1091d9b2d84385
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125089
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index d3353e441474..e71e62929903 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -2197,8 +2197,9 @@ void CallbackFlushHandler::enqueueUpdatedTypes()
 
 void CallbackFlushHandler::enqueueUpdatedType( int type, SfxViewShell* 
viewShell, int viewId )
 {
-    OString payload = viewShell->getLOKPayload( type, viewId );
-    if(payload.isEmpty())
+    bool ignore = false;
+    OString payload = viewShell->getLOKPayload( type, viewId, &ignore );
+    if(ignore)
         return; // No actual payload to send.
     CallbackData callbackData(payload.getStr(), viewId);
     m_queue1.emplace_back(type);
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index f0d71bc542e6..26a2324c7ca0 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -345,8 +345,9 @@ public:
     virtual void libreOfficeKitViewUpdatedCallback(int nType) const override;
     virtual void libreOfficeKitViewUpdatedCallbackPerViewId(int nType, int 
nViewId, int nSourceViewId) const override;
     // Returns current payload for nType, after 
libreOfficeKitViewUpdatedCallback() or
-    // libreOfficeKitViewUpdatedCallbackPerViewId() were called.
-    virtual OString getLOKPayload(int nType, int nViewId) const;
+    // libreOfficeKitViewUpdatedCallbackPerViewId() were called. If no payload 
should
+    // be generated, the ignore flag should be set.
+    virtual OString getLOKPayload(int nType, int nViewId, bool* ignore) const;
 
     /// Set if we are doing tiled searching.
     void setTiledSearching(bool bTiledSearching);
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 325c9ffa71cc..d1c0e48ba18e 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -1552,7 +1552,7 @@ void SfxViewShell::flushPendingLOKInvalidateTiles()
     // SfxViewShell itself does not delay any tile invalidations.
 }
 
-OString SfxViewShell::getLOKPayload(int nType, int /*nViewId*/) const
+OString SfxViewShell::getLOKPayload(int nType, int /*nViewId*/, bool* 
/*ignore*/) const
 {
     // SfxViewShell itself currently doesn't handle any updated-payload types.
     SAL_WARN("sfx.view", "SfxViewShell::getLOKPayload unhandled type " << 
lokCallbackTypeToString(nType));
diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx
index b793614f58f7..0f062d3bedf3 100644
--- a/sw/inc/view.hxx
+++ b/sw/inc/view.hxx
@@ -680,7 +680,7 @@ public:
 
     virtual tools::Rectangle getLOKVisibleArea() const override;
     virtual void flushPendingLOKInvalidateTiles() override;
-    virtual OString getLOKPayload(int nType, int nViewId) const override;
+    virtual OString getLOKPayload(int nType, int nViewId, bool* ignore) const 
override;
 };
 
 inline tools::Long SwView::GetXScroll() const
diff --git a/sw/inc/viscrs.hxx b/sw/inc/viscrs.hxx
index b2ceb9c67c79..dc7e020ad103 100644
--- a/sw/inc/viscrs.hxx
+++ b/sw/inc/viscrs.hxx
@@ -61,7 +61,7 @@ public:
     void SetPosAndShow(SfxViewShell const * pViewShell);
     const vcl::Cursor& GetTextCursor() const;
 
-    OString getLOKPayload(int nType, int nViewId) const;
+    OString getLOKPayload(int nType, int nViewId, bool* ignore) const;
 };
 
 // From here classes/methods for selections.
@@ -115,7 +115,7 @@ public:
     static void Get1PixelInLogic( const SwViewShell& rSh,
                                     tools::Long* pX = nullptr, tools::Long* pY 
= nullptr );
 
-    OString getLOKPayload(int nType, int nViewId) const;
+    OString getLOKPayload(int nType, int nViewId, bool* ignore) const;
 };
 
 class SW_DLLPUBLIC SwShellCursor : public virtual SwCursor, public 
SwSelPaintRects
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index 7d9564295fab..f81f9750b312 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -265,7 +265,7 @@ void SwVisibleCursor::SetPosAndShow(SfxViewShell const * 
pViewShell)
     m_aTextCursor.Show();
 }
 
-OString SwVisibleCursor::getLOKPayload(int nType, int nViewId) const
+OString SwVisibleCursor::getLOKPayload(int nType, int nViewId, bool*) const
 {
     assert(nType == LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR || nType == 
LOK_CALLBACK_INVALIDATE_VIEW_CURSOR);
     if (comphelper::LibreOfficeKit::isActive())
@@ -508,7 +508,7 @@ void SwSelPaintRects::Show(std::vector<OString>* 
pSelectionRectangles)
         pSelectionRectangles->push_back(sRect);
 }
 
-OString SwSelPaintRects::getLOKPayload( int nType, int nViewId ) const
+OString SwSelPaintRects::getLOKPayload( int nType, int nViewId, bool* ignore ) 
const
 {
     switch( nType )
     {
@@ -528,12 +528,14 @@ OString SwSelPaintRects::getLOKPayload( int nType, int 
nViewId ) const
             {
                 if (aStartRect.HasArea())
                     return aStartRect.SVRect().toString();
+                *ignore = true;
                 return OString();
             }
             else // LOK_CALLBACK_TEXT_SELECTION_END
             {
                 if (aEndRect.HasArea())
                     return aEndRect.SVRect().toString();
+                *ignore = true;
                 return OString();
             }
         }
diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx
index 3374c10e55dc..4cc8c0ffa166 100644
--- a/sw/source/uibase/inc/wrtsh.hxx
+++ b/sw/source/uibase/inc/wrtsh.hxx
@@ -493,7 +493,7 @@ typedef bool (SwWrtShell::*FNSimpleMove)();
     void ToggleOutlineContentVisibility(SwNode* pNd, bool bForceFold = false);
     void ToggleOutlineContentVisibility(const size_t nPos, bool bForceFold = 
false);
 
-    OString getLOKPayload(int nType, int nViewId) const;
+    OString getLOKPayload(int nType, int nViewId, bool* ignore) const;
 
 private:
 
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index ebf2a31fc08c..fc1e3593e803 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -1892,11 +1892,11 @@ void SwView::flushPendingLOKInvalidateTiles()
     pSh->FlushPendingLOKInvalidateTiles();
 }
 
-OString SwView::getLOKPayload(int nType, int nViewId) const
+OString SwView::getLOKPayload(int nType, int nViewId, bool* ignore) const
 {
     SwWrtShell* pSh = GetWrtShellPtr();
     assert(pSh);
-    return pSh->getLOKPayload(nType, nViewId);
+    return pSh->getLOKPayload(nType, nViewId, ignore);
 }
 
 OUString SwView::GetDataSourceName() const
diff --git a/sw/source/uibase/wrtsh/wrtsh4.cxx 
b/sw/source/uibase/wrtsh/wrtsh4.cxx
index 0bafa1e75941..36cec11cc09c 100644
--- a/sw/source/uibase/wrtsh/wrtsh4.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh4.cxx
@@ -234,18 +234,18 @@ bool SwWrtShell::BwdPara_()
     return bRet;
 }
 
-OString SwWrtShell::getLOKPayload(int nType, int nViewId) const
+OString SwWrtShell::getLOKPayload(int nType, int nViewId, bool* ignore) const
 {
     switch(nType)
     {
         case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
         case LOK_CALLBACK_INVALIDATE_VIEW_CURSOR:
-            return GetVisibleCursor()->getLOKPayload(nType, nViewId);
+            return GetVisibleCursor()->getLOKPayload(nType, nViewId, ignore);
         case LOK_CALLBACK_TEXT_SELECTION:
         case LOK_CALLBACK_TEXT_SELECTION_START:
         case LOK_CALLBACK_TEXT_SELECTION_END:
         case LOK_CALLBACK_TEXT_VIEW_SELECTION:
-            return GetCursor_()->getLOKPayload( nType, nViewId );
+            return GetCursor_()->getLOKPayload( nType, nViewId, ignore );
     }
     abort();
 }
diff --git a/test/source/lokcallback.cxx b/test/source/lokcallback.cxx
index 0f6970d2af9c..440aae461eee 100644
--- a/test/source/lokcallback.cxx
+++ b/test/source/lokcallback.cxx
@@ -151,8 +151,9 @@ void TestLokCallbackWrapper::flushLOKData()
 
     for (int type : updatedTypes)
     {
-        OString payload = viewShell->getLOKPayload(type, m_viewId);
-        if (!payload.isEmpty())
+        bool ignore = false;
+        OString payload = viewShell->getLOKPayload(type, m_viewId, &ignore);
+        if (!ignore)
             libreOfficeKitViewCallback(type, payload.getStr());
     }
     for (const PerViewIdData& data : updatedTypesPerViewId)
@@ -161,8 +162,9 @@ void TestLokCallbackWrapper::flushLOKData()
             return shell->GetViewShellId().get() == data.sourceViewId;
         });
         assert(viewShell != nullptr);
-        OString payload = viewShell->getLOKPayload(data.type, data.viewId);
-        if (!payload.isEmpty())
+        bool ignore = false;
+        OString payload = viewShell->getLOKPayload(data.type, data.viewId, 
&ignore);
+        if (!ignore)
             libreOfficeKitViewCallbackWithViewId(data.type, payload.getStr(), 
data.viewId);
     }
 }

Reply via email to