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

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


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

New commits:
commit 393226c68f782b4761443b32ff25e340aaca133e
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: Thu Feb 11 17:08:14 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>
    (cherry picked from commit c591ae91b25fd69e6424434b92894c57671253ca)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110760
    Tested-by: Jenkins

diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx
index 1c89089dd2bf..254ca1c4ec52 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -689,7 +689,7 @@ namespace sw::mark
         }
     }
 
-    void DropDownFieldmark::SendLOKMessage(SfxViewShell* pViewShell, std::string_view sAction)
+    void DropDownFieldmark::SendLOKShowMessage(SfxViewShell* pViewShell)
     {
         if (!comphelper::LibreOfficeKit::isActive())
             return;
@@ -697,51 +697,49 @@ namespace sw::mark
         if (!pViewShell || pViewShell->isLOKMobilePhone())
             return;
 
+        if (m_aPortionPaintArea.IsEmpty())
+            return;
+
         OStringBuffer sPayload;
-        if (sAction == "show")
+        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())
         {
-            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("], ");
-
-            // Selected item
-            auto pSelectedItemIter = pParameters->find(ODF_FORMDROPDOWN_RESULT);
-            sal_Int32 nSelection = -1;
-            if (pSelectedItemIter != pParameters->end())
-            {
-                pSelectedItemIter->second >>= nSelection;
-            }
-            sPayload.append("\"selected\": \"" + OString::number(nSelection) + "\", ");
-
-            // Placeholder text
-            sPayload.append("\"placeholderText\": \"" + OUStringToOString(SwResId(STR_DROP_DOWN_EMPTY_LIST), RTL_TEXTENCODING_UTF8) + "\"}}");
+            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
+        auto pSelectedItemIter = pParameters->find(ODF_FORMDROPDOWN_RESULT);
+        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)
+    {
+        OString sPayload = "{\"action\": \"hide\", \"type\": \"drop-down\"}";
+        pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_FORM_FIELD_BUTTON, sPayload.getStr());
+    }
+
     DateFieldmark::DateFieldmark(const SwPaM& rPaM)
         : FieldmarkWithDropDownButton(rPaM)
         , m_pNumberFormatter(nullptr)
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 2532406f9b1f..a62c371377f4 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -1540,25 +1540,25 @@ namespace sw::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 f487bb64078d..a954890f2caa 100644
--- a/sw/source/core/inc/bookmrk.hxx
+++ b/sw/source/core/inc/bookmrk.hxx
@@ -294,7 +294,8 @@ 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(SfxViewShell* pViewShell, std::string_view sAction);
+            void SendLOKShowMessage(SfxViewShell* pViewShell);
+            static void SendLOKHideMessage(SfxViewShell* pViewShell);
 
         private:
             SwRect m_aPortionPaintArea;


More information about the Libreoffice-commits mailing list