desktop/source/lib/init.cxx       |    7 +++----
 include/sfx2/viewsh.hxx           |    3 ++-
 sfx2/source/view/viewsh.cxx       |    2 +-
 starmath/inc/view.hxx             |    2 +-
 starmath/source/view.cxx          |    6 ++----
 sw/inc/view.hxx                   |    2 +-
 sw/inc/viscrs.hxx                 |    6 ++++--
 sw/source/core/crsr/viscrs.cxx    |   15 +++++----------
 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       |   14 ++++++--------
 12 files changed, 31 insertions(+), 38 deletions(-)

New commits:
commit b34577840b679b428490ae24fd644645ca5c76f0
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Aug 17 08:40:31 2022 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Aug 17 11:59:38 2022 +0200

    Return std::optional instead of using bool* argument
    
    Change-Id: I47f03411a6677f22291bea4dc06920ab9052349a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138399
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit 364e8272329ba893af4141ac054fdc71816bd44a)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138291
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 1533021c56a9..16bf1cb16542 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -2123,11 +2123,10 @@ void CallbackFlushHandler::enqueueUpdatedTypes()
 
 void CallbackFlushHandler::enqueueUpdatedType( int type, const SfxViewShell* 
viewShell, int viewId )
 {
-    bool ignore = false;
-    OString payload = viewShell->getLOKPayload( type, viewId, &ignore );
-    if(ignore)
+    std::optional<OString> payload = viewShell->getLOKPayload( type, viewId );
+    if(!payload)
         return; // No actual payload to send.
-    CallbackData callbackData(payload.getStr(), viewId);
+    CallbackData callbackData(payload->getStr(), viewId);
     m_queue1.emplace_back(type);
     m_queue2.emplace_back(callbackData);
     SAL_INFO("lok", "Queued updated [" << type << "]: [" << 
callbackData.getPayload()
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index 5d4ddb2ed21d..e2ef0475dbc6 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -21,6 +21,7 @@
 
 #include <sal/config.h>
 #include <memory>
+#include <optional>
 #include <sfx2/dllapi.h>
 #include <sal/types.h>
 #include <com/sun/star/uno/Reference.h>
@@ -352,7 +353,7 @@ public:
     // Returns current payload for nType, after 
libreOfficeKitViewUpdatedCallback() or
     // 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;
+    virtual std::optional<OString> getLOKPayload(int nType, int nViewId) 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 47171622f7c4..2098e05a283f 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -1555,7 +1555,7 @@ void SfxViewShell::flushPendingLOKInvalidateTiles()
     // SfxViewShell itself does not delay any tile invalidations.
 }
 
-OString SfxViewShell::getLOKPayload(int nType, int /*nViewId*/, bool* 
/*ignore*/) const
+std::optional<OString> SfxViewShell::getLOKPayload(int nType, int /*nViewId*/) 
const
 {
     // SfxViewShell itself currently doesn't handle any updated-payload types.
     SAL_WARN("sfx.view", "SfxViewShell::getLOKPayload unhandled type " << 
lokCallbackTypeToString(nType));
diff --git a/starmath/inc/view.hxx b/starmath/inc/view.hxx
index 7f0e584e17f3..f3dab0d58850 100644
--- a/starmath/inc/view.hxx
+++ b/starmath/inc/view.hxx
@@ -291,7 +291,7 @@ class SmViewShell final : public SfxViewShell
     virtual void OuterResizePixel(const Point &rOfs, const Size  &rSize) 
override;
     virtual void QueryObjAreaPixel( tools::Rectangle& rRect ) const override;
     virtual void SetZoomFactor( const Fraction &rX, const Fraction &rY ) 
override;
-    virtual OString getLOKPayload(int nType, int nViewId, bool* ignore) const 
override;
+    virtual std::optional<OString> getLOKPayload(int nType, int nViewId) const 
override;
 
 public:
 
diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx
index cb1f31fe7c3b..13e9e9653214 100644
--- a/starmath/source/view.cxx
+++ b/starmath/source/view.cxx
@@ -2271,7 +2271,7 @@ void SmViewShell::ZoomByItemSet(const SfxItemSet *pSet)
     }
 }
 
-OString SmViewShell::getLOKPayload(int nType, int nViewId, bool* ignore) const
+std::optional<OString> SmViewShell::getLOKPayload(int nType, int nViewId) const
 {
     switch (nType)
     {
@@ -2281,11 +2281,9 @@ OString SmViewShell::getLOKPayload(int nType, int 
nViewId, bool* ignore) const
         case LOK_CALLBACK_TEXT_SELECTION_START:
         case LOK_CALLBACK_TEXT_SELECTION_END:
         case LOK_CALLBACK_TEXT_VIEW_SELECTION:
-            if (ignore)
-                *ignore = true;
             return {};
     }
-    return SfxViewShell::getLOKPayload(nType, nViewId, ignore); // aborts
+    return SfxViewShell::getLOKPayload(nType, nViewId); // aborts
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx
index d074f0d552a7..514074e603c9 100644
--- a/sw/inc/view.hxx
+++ b/sw/inc/view.hxx
@@ -693,7 +693,7 @@ public:
 
     virtual tools::Rectangle getLOKVisibleArea() const override;
     virtual void flushPendingLOKInvalidateTiles() override;
-    virtual OString getLOKPayload(int nType, int nViewId, bool* ignore) const 
override;
+    virtual std::optional<OString> getLOKPayload(int nType, int nViewId) const 
override;
 };
 
 inline tools::Long SwView::GetXScroll() const
diff --git a/sw/inc/viscrs.hxx b/sw/inc/viscrs.hxx
index 6126f5ffa0c0..123ff61b2303 100644
--- a/sw/inc/viscrs.hxx
+++ b/sw/inc/viscrs.hxx
@@ -26,6 +26,8 @@
 #include "swregion.hxx"
 #include "swdllapi.h"
 
+#include <optional>
+
 namespace sdr::overlay { class OverlayObject; }
 
 class SwCursorShell;
@@ -61,7 +63,7 @@ public:
     void SetPosAndShow(SfxViewShell const * pViewShell);
     const vcl::Cursor& GetTextCursor() const;
 
-    OString getLOKPayload(int nType, int nViewId, bool* ignore) const;
+    std::optional<OString> getLOKPayload(int nType, int nViewId) const;
 };
 
 // From here classes/methods for selections.
@@ -123,7 +125,7 @@ public:
     static void Get1PixelInLogic( const SwViewShell& rSh,
                                     tools::Long* pX = nullptr, tools::Long* pY 
= nullptr );
 
-    OString getLOKPayload(int nType, int nViewId, bool* ignore) const;
+    std::optional<OString> getLOKPayload(int nType, int nViewId) 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 797bd8ecb7d8..6a67a6e913b5 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -270,7 +270,7 @@ void SwVisibleCursor::SetPosAndShow(SfxViewShell const * 
pViewShell)
     m_aTextCursor.Show();
 }
 
-OString SwVisibleCursor::getLOKPayload(int nType, int nViewId, bool*) const
+std::optional<OString> SwVisibleCursor::getLOKPayload(int nType, int nViewId) 
const
 {
     assert(nType == LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR || nType == 
LOK_CALLBACK_INVALIDATE_VIEW_CURSOR);
     if (comphelper::LibreOfficeKit::isActive())
@@ -515,7 +515,7 @@ void SwSelPaintRects::Show(std::vector<OString>* 
pSelectionRectangles)
         pSelectionRectangles->push_back(sRect);
 }
 
-OString SwSelPaintRects::getLOKPayload( int nType, int nViewId, bool* ignore ) 
const
+std::optional<OString> SwSelPaintRects::getLOKPayload(int nType, int nViewId) 
const
 {
     switch( nType )
     {
@@ -533,24 +533,19 @@ OString SwSelPaintRects::getLOKPayload( int nType, int 
nViewId, bool* ignore ) c
 
             // no selection rect
             if (!size())
-            {
-                *ignore = true;
-                return OString();
-            }
+                return {};
 
             if( nType == LOK_CALLBACK_TEXT_SELECTION_START )
             {
                 if (aStartRect.HasArea())
                     return aStartRect.SVRect().toString();
-                *ignore = true;
-                return OString();
+                return {};
             }
             else // LOK_CALLBACK_TEXT_SELECTION_END
             {
                 if (aEndRect.HasArea())
                     return aEndRect.SVRect().toString();
-                *ignore = true;
-                return OString();
+                return {};
             }
         }
         break;
diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx
index 134c7dc5dbf6..e87ee8a3945e 100644
--- a/sw/source/uibase/inc/wrtsh.hxx
+++ b/sw/source/uibase/inc/wrtsh.hxx
@@ -505,7 +505,7 @@ typedef bool (SwWrtShell::*FNSimpleMove)();
     void InvalidateOutlineContentVisibility();
     bool GetAttrOutlineContentVisible(const size_t nPos);
 
-    OString getLOKPayload(int nType, int nViewId, bool* ignore) const;
+    std::optional<OString> getLOKPayload(int nType, int nViewId) const;
 
 private:
 
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index 2715f7f7aa74..f58abbab53d4 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -1918,11 +1918,11 @@ void SwView::flushPendingLOKInvalidateTiles()
     pSh->FlushPendingLOKInvalidateTiles();
 }
 
-OString SwView::getLOKPayload(int nType, int nViewId, bool* ignore) const
+std::optional<OString> SwView::getLOKPayload(int nType, int nViewId) const
 {
     SwWrtShell* pSh = GetWrtShellPtr();
     assert(pSh);
-    return pSh->getLOKPayload(nType, nViewId, ignore);
+    return pSh->getLOKPayload(nType, nViewId);
 }
 
 OUString SwView::GetDataSourceName() const
diff --git a/sw/source/uibase/wrtsh/wrtsh4.cxx 
b/sw/source/uibase/wrtsh/wrtsh4.cxx
index 36cec11cc09c..b3fb83c15bb8 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, bool* ignore) const
+std::optional<OString> SwWrtShell::getLOKPayload(int nType, int nViewId) const
 {
     switch(nType)
     {
         case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
         case LOK_CALLBACK_INVALIDATE_VIEW_CURSOR:
-            return GetVisibleCursor()->getLOKPayload(nType, nViewId, ignore);
+            return GetVisibleCursor()->getLOKPayload(nType, nViewId);
         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, ignore );
+            return GetCursor_()->getLOKPayload(nType, nViewId);
     }
     abort();
 }
diff --git a/test/source/lokcallback.cxx b/test/source/lokcallback.cxx
index 323ba4af1f10..c938e1e699a8 100644
--- a/test/source/lokcallback.cxx
+++ b/test/source/lokcallback.cxx
@@ -151,10 +151,9 @@ void TestLokCallbackWrapper::flushLOKData()
 
     for (int type : updatedTypes)
     {
-        bool ignore = false;
-        OString payload = viewShell->getLOKPayload(type, m_viewId, &ignore);
-        if (!ignore)
-            libreOfficeKitViewCallback(type, payload.getStr());
+        std::optional<OString> payload = viewShell->getLOKPayload(type, 
m_viewId);
+        if (payload)
+            libreOfficeKitViewCallback(type, payload->getStr());
     }
     for (const PerViewIdData& data : updatedTypesPerViewId)
     {
@@ -162,10 +161,9 @@ void TestLokCallbackWrapper::flushLOKData()
             return shell->GetViewShellId().get() == data.sourceViewId;
         });
         assert(viewShell != nullptr);
-        bool ignore = false;
-        OString payload = viewShell->getLOKPayload(data.type, data.viewId, 
&ignore);
-        if (!ignore)
-            libreOfficeKitViewCallbackWithViewId(data.type, payload.getStr(), 
data.viewId);
+        std::optional<OString> payload = viewShell->getLOKPayload(data.type, 
data.viewId);
+        if (payload)
+            libreOfficeKitViewCallbackWithViewId(data.type, payload->getStr(), 
data.viewId);
     }
 }
 

Reply via email to