[Libreoffice-commits] core.git: desktop/source sw/source

Tamás Zolnai (via logerrit) logerrit at kemper.freedesktop.org
Thu Feb 11 16:08:03 UTC 2021


 desktop/source/lib/init.cxx        |    1 +
 sw/source/core/crsr/bookmrk.cxx    |   26 +++++---------------------
 sw/source/core/doc/docbm.cxx       |   35 +++++++++++++++++++++++++++++++++++
 sw/source/core/inc/MarkManager.hxx |    2 ++
 sw/source/core/inc/bookmrk.hxx     |    4 ++--
 5 files changed, 45 insertions(+), 23 deletions(-)

New commits:
commit 250eb2ee92f3f382c4a6ac3b643fc8e3b60c8be7
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Wed Feb 10 12:23:52 2021 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Thu Feb 11 17:07:21 2021 +0100

    lok: rework form field button message handling.
    
    To make it work properly with more users editing
    the same document.
    
    Change-Id: I1f3d8ef9fc9c25b440a3dc36a40709723ed342f2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110710
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>
    (cherry picked from commit 20335d5ed549af25f02467c7da21df10c8df956a)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110759
    Tested-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 0931ffda08ac..95e76de18cdb 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1529,6 +1529,7 @@ void CallbackFlushHandler::queue(const int type, const char* data)
             case LOK_CALLBACK_TEXT_VIEW_SELECTION:
             case LOK_CALLBACK_VIEW_CURSOR_VISIBLE:
             case LOK_CALLBACK_CALC_FUNCTION_LIST:
+            case LOK_CALLBACK_FORM_FIELD_BUTTON:
             {
                 // deleting the duplicate of visible cursor message can cause hyperlink popup not to show up on second/or more click on the same place.
                 // If the hyperlink is not empty we can bypass that to show the popup
diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx
index 5ea199607d5e..1c89089dd2bf 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -661,7 +661,6 @@ namespace sw::mark
 
     DropDownFieldmark::~DropDownFieldmark()
     {
-        SendLOKMessage("hide");
     }
 
     void DropDownFieldmark::ShowButton(SwEditWin* pEditWin)
@@ -672,13 +671,11 @@ namespace sw::mark
                 m_pButton = VclPtr<DropDownFormFieldButton>::Create(pEditWin, *this);
             m_pButton->CalcPosAndSize(m_aPortionPaintArea);
             m_pButton->Show();
-            SendLOKMessage("show");
         }
     }
 
     void DropDownFieldmark::RemoveButton()
     {
-        SendLOKMessage("hide");
         FieldmarkWithDropDownButton::RemoveButton();
     }
 
@@ -689,32 +686,21 @@ namespace sw::mark
         {
             m_pButton->Show();
             m_pButton->CalcPosAndSize(m_aPortionPaintArea);
-            SendLOKMessage("show");
         }
     }
 
-    void DropDownFieldmark::SendLOKMessage(std::string_view sAction)
+    void DropDownFieldmark::SendLOKMessage(SfxViewShell* pViewShell, std::string_view sAction)
     {
-        const SfxViewShell* pViewShell = SfxViewShell::Current();
-        if (!pViewShell || pViewShell->isLOKMobilePhone())
-        {
-              return;
-        }
-
         if (!comphelper::LibreOfficeKit::isActive())
             return;
 
-        if (!m_pButton)
-          return;
-
-        SwEditWin* pEditWin = dynamic_cast<SwEditWin*>(m_pButton->GetParent());
-        if (!pEditWin)
+        if (!pViewShell || pViewShell->isLOKMobilePhone())
             return;
 
         OStringBuffer sPayload;
         if (sAction == "show")
         {
-            if(m_aPortionPaintArea.IsEmpty())
+            if (m_aPortionPaintArea.IsEmpty())
                 return;
 
             sPayload = OStringLiteral("{\"action\": \"show\","
@@ -750,12 +736,10 @@ namespace sw::mark
         }
         else
         {
+            assert(sAction == "hide");
             sPayload = "{\"action\": \"hide\", \"type\": \"drop-down\"}";
         }
-        if (sPayload.toString() != m_sLastSentLOKMsg) {
-            m_sLastSentLOKMsg = sPayload.toString();
-            pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_FORM_FIELD_BUTTON, m_sLastSentLOKMsg.getStr());
-        }
+        pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_FORM_FIELD_BUTTON, sPayload.toString().getStr());
     }
 
     DateFieldmark::DateFieldmark(const SwPaM& rPaM)
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index c71178e1f005..2532406f9b1f 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -47,6 +47,7 @@
 
 #include <libxml/xmlstring.h>
 #include <libxml/xmlwriter.h>
+#include <comphelper/lok.hxx>
 
 using namespace ::sw::mark;
 
@@ -1517,6 +1518,8 @@ namespace sw::mark
             if(pNewActiveFieldmark)
                 pNewActiveFieldmark->ShowButton(&rEditWin);
         }
+
+        LOKUpdateActiveField(pSwView);
     }
 
     void MarkManager::ClearFieldActivation()
@@ -1527,6 +1530,38 @@ namespace sw::mark
         m_pLastActiveFieldmark = nullptr;
     }
 
+    void MarkManager::LOKUpdateActiveField(SfxViewShell* pViewShell)
+    {
+        if (!comphelper::LibreOfficeKit::isActive())
+            return;
+
+        if (m_pLastActiveFieldmark)
+        {
+            if (m_pLastActiveFieldmark->GetFieldname() == ODF_FORMDROPDOWN)
+            {
+                auto pDrowDown = dynamic_cast<::sw::mark::DropDownFieldmark*>(m_pLastActiveFieldmark);
+                pDrowDown->SendLOKMessage(pViewShell, "show");
+            }
+        }
+        else
+        {
+            // Check whether we have any drop down fieldmark at all.
+            ::sw::mark::DropDownFieldmark* pDrowDown = nullptr;
+            for (auto aIter = m_vFieldmarks.begin(); aIter != m_vFieldmarks.end(); ++aIter)
+            {
+                IFieldmark *pMark = dynamic_cast<IFieldmark*>(*aIter);
+                if (pMark && pMark->GetFieldname() == ODF_FORMDROPDOWN)
+                {
+                    pDrowDown = dynamic_cast<::sw::mark::DropDownFieldmark*>(pMark);
+                    break;
+                }
+            }
+
+            if (pDrowDown)
+                pDrowDown->SendLOKMessage(pViewShell, "hide");
+        }
+    }
+
     IFieldmark* MarkManager::getDropDownFor(const SwPosition& rPos) const
     {
         IFieldmark *pMark = getFieldmarkAt(rPos);
diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx
index 1bbce7d19c21..94cd907b0f12 100644
--- a/sw/source/core/inc/MarkManager.hxx
+++ b/sw/source/core/inc/MarkManager.hxx
@@ -26,6 +26,7 @@
 #include <memory>
 
 class SwCursorShell;
+class SfxViewShell;
 
 namespace sw::mark {
     typedef std::unordered_map<OUString, sal_Int32> MarkBasenameMapUniqueOffset_t;
@@ -100,6 +101,7 @@ namespace sw::mark {
 
             virtual void NotifyCursorUpdate(const SwCursorShell& rCursorShell) override;
             virtual void ClearFieldActivation() override;
+            virtual void LOKUpdateActiveField(SfxViewShell* pViewShell);
 
             void dumpAsXml(xmlTextWriterPtr pWriter) const;
 
diff --git a/sw/source/core/inc/bookmrk.hxx b/sw/source/core/inc/bookmrk.hxx
index 272667432584..f487bb64078d 100644
--- a/sw/source/core/inc/bookmrk.hxx
+++ b/sw/source/core/inc/bookmrk.hxx
@@ -39,6 +39,7 @@ class SwDoc;
 class SwEditWin;
 class SwServerObject;
 class SvNumberFormatter;
+class SfxViewShell;
 
 namespace sw::mark {
         class MarkBase
@@ -293,11 +294,10 @@ namespace sw::mark {
             // This method should be called only by the portion so we can now the portion's painting area
             void SetPortionPaintArea(const SwRect& rPortionPaintArea);
 
-            void SendLOKMessage(std::string_view sAction);
+            void SendLOKMessage(SfxViewShell* pViewShell, std::string_view sAction);
 
         private:
             SwRect m_aPortionPaintArea;
-            OString m_sLastSentLOKMsg;
         };
 
         /// Fieldmark representing a date form field.


More information about the Libreoffice-commits mailing list