[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - sw/source

Tamás Zolnai (via logerrit) logerrit at kemper.freedesktop.org
Wed Feb 10 15:51:31 UTC 2021


 sw/source/core/crsr/bookmrk.cxx |   76 +++++++++++++++++++---------------------
 sw/source/core/doc/docbm.cxx    |   10 ++---
 sw/source/core/inc/bookmrk.hxx  |    3 +
 3 files changed, 44 insertions(+), 45 deletions(-)

New commits:
commit c591ae91b25fd69e6424434b92894c57671253ca
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Wed Feb 10 15:07:08 2021 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Wed Feb 10 16:50:54 2021 +0100

    LOK: form field button: split SendLOKMessage() method.
    
    Hiding form fiel button can be static. We don't need to
    know which fieldmark has the actual button.
    
    Change-Id: I3f7d52c0f11c7dfbb0b4f50bc0c7c0302f50d815
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110711
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx
index 4a4aad532aaa..9d184f37daa1 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -652,7 +652,7 @@ namespace sw { namespace mark
         }
     }
 
-    void DropDownFieldmark::SendLOKMessage(SfxViewShell* pViewShell, const OString& sAction)
+    void DropDownFieldmark::SendLOKShowMessage(SfxViewShell* pViewShell)
     {
         if (!comphelper::LibreOfficeKit::isActive())
             return;
@@ -660,49 +660,47 @@ namespace sw { namespace mark
         if (!pViewShell || pViewShell->isLOKMobilePhone())
             return;
 
-        OStringBuffer sPayload;
-        if (sAction == "show")
-        {
-            if (m_aPortionPaintArea.IsEmpty())
-                return;
-
-            sPayload = OStringLiteral("{\"action\": \"show\","
-                       " \"type\": \"drop-down\", \"textArea\": \"") +
-                       m_aPortionPaintArea.SVRect().toString() + "\",";
-            // Add field params to the message
-            sPayload.append(" \"params\": { \"items\": [");
-
-            // List items
-            auto pParameters = this->GetParameters();
-            auto pListEntriesIter = pParameters->find(ODF_FORMDROPDOWN_LISTENTRY);
-            css::uno::Sequence<OUString> vListEntries;
-            if (pListEntriesIter != pParameters->end())
-            {
-                pListEntriesIter->second >>= vListEntries;
-                for (const OUString& sItem : std::as_const(vListEntries))
-                    sPayload.append("\"" + OUStringToOString(sItem, RTL_TEXTENCODING_UTF8) + "\", ");
-                sPayload.setLength(sPayload.getLength() - 2);
-            }
-            sPayload.append("], ");
+        if (m_aPortionPaintArea.IsEmpty())
+            return;
 
-            // Selected item
-            OUString sResultKey = ODF_FORMDROPDOWN_RESULT;
-            auto pSelectedItemIter = pParameters->find(sResultKey);
-            sal_Int32 nSelection = -1;
-            if (pSelectedItemIter != pParameters->end())
-            {
-                pSelectedItemIter->second >>= nSelection;
-            }
-            sPayload.append("\"selected\": \"" + OString::number(nSelection) + "\", ");
+        OStringBuffer sPayload;
+        sPayload = OStringLiteral("{\"action\": \"show\","
+                   " \"type\": \"drop-down\", \"textArea\": \"") +
+                   m_aPortionPaintArea.SVRect().toString() + "\",";
+        // Add field params to the message
+        sPayload.append(" \"params\": { \"items\": [");
 
-            // Placeholder text
-            sPayload.append("\"placeholderText\": \"" + OUStringToOString(SwResId(STR_DROP_DOWN_EMPTY_LIST), RTL_TEXTENCODING_UTF8) + "\"}}");
+        // List items
+        auto pParameters = this->GetParameters();
+        auto pListEntriesIter = pParameters->find(ODF_FORMDROPDOWN_LISTENTRY);
+        css::uno::Sequence<OUString> vListEntries;
+        if (pListEntriesIter != pParameters->end())
+        {
+            pListEntriesIter->second >>= vListEntries;
+            for (const OUString& sItem : std::as_const(vListEntries))
+                sPayload.append("\"" + OUStringToOString(sItem, RTL_TEXTENCODING_UTF8) + "\", ");
+            sPayload.setLength(sPayload.getLength() - 2);
         }
-        else
+        sPayload.append("], ");
+
+        // Selected item
+        OUString sResultKey = ODF_FORMDROPDOWN_RESULT;
+        auto pSelectedItemIter = pParameters->find(sResultKey);
+        sal_Int32 nSelection = -1;
+        if (pSelectedItemIter != pParameters->end())
         {
-            assert(sAction == "hide");
-            sPayload = "{\"action\": \"hide\", \"type\": \"drop-down\"}";
+            pSelectedItemIter->second >>= nSelection;
         }
+        sPayload.append("\"selected\": \"" + OString::number(nSelection) + "\", ");
+
+        // Placeholder text
+        sPayload.append("\"placeholderText\": \"" + OUStringToOString(SwResId(STR_DROP_DOWN_EMPTY_LIST), RTL_TEXTENCODING_UTF8) + "\"}}");
+        pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_FORM_FIELD_BUTTON, sPayload.toString().getStr());
+    }
+
+    void DropDownFieldmark::SendLOKHideMessage(SfxViewShell* pViewShell)
+    {
+        OStringBuffer sPayload = "{\"action\": \"hide\", \"type\": \"drop-down\"}";
         pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_FORM_FIELD_BUTTON, sPayload.toString().getStr());
     }
 
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index ab1bd2ab40b2..ac85fe88cfd0 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -1457,25 +1457,25 @@ namespace sw { namespace mark
             if (m_pLastActiveFieldmark->GetFieldname() == ODF_FORMDROPDOWN)
             {
                 auto pDrowDown = dynamic_cast<::sw::mark::DropDownFieldmark*>(m_pLastActiveFieldmark);
-                pDrowDown->SendLOKMessage(pViewShell, "show");
+                pDrowDown->SendLOKShowMessage(pViewShell);
             }
         }
         else
         {
             // Check whether we have any drop down fieldmark at all.
-            ::sw::mark::DropDownFieldmark* pDrowDown = nullptr;
+            bool bDropDownFieldExist = false;
             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);
+                    bDropDownFieldExist = true;
                     break;
                 }
             }
 
-            if (pDrowDown)
-                pDrowDown->SendLOKMessage(pViewShell, "hide");
+            if (bDropDownFieldExist)
+                ::sw::mark::DropDownFieldmark::SendLOKHideMessage(pViewShell);
         }
     }
 
diff --git a/sw/source/core/inc/bookmrk.hxx b/sw/source/core/inc/bookmrk.hxx
index b65aac2bd589..ba58688252f3 100644
--- a/sw/source/core/inc/bookmrk.hxx
+++ b/sw/source/core/inc/bookmrk.hxx
@@ -299,7 +299,8 @@ namespace sw {
             // 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(SfxViewShell* pViewShell, const OString& sAction);
+            void SendLOKShowMessage(SfxViewShell* pViewShell);
+            static void SendLOKHideMessage(SfxViewShell* pViewShell);
 
         private:
             SwRect m_aPortionPaintArea;


More information about the Libreoffice-commits mailing list