diff options
author | Tamás Zolnai <tamas.zolnai@collabora.com> | 2021-02-10 15:07:08 +0100 |
---|---|---|
committer | Tamás Zolnai <tamas.zolnai@collabora.com> | 2021-02-11 17:08:14 +0100 |
commit | 393226c68f782b4761443b32ff25e340aaca133e (patch) | |
tree | eb358cce21d72ae8d1a3bbd3ee68a0dd724379fa /sw/source | |
parent | 250eb2ee92f3f382c4a6ac3b643fc8e3b60c8be7 (diff) |
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@gmail.com>
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
(cherry picked from commit c591ae91b25fd69e6424434b92894c57671253ca)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110760
Tested-by: Jenkins
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/crsr/bookmrk.cxx | 74 | ||||
-rw-r--r-- | sw/source/core/doc/docbm.cxx | 10 | ||||
-rw-r--r-- | sw/source/core/inc/bookmrk.hxx | 3 |
3 files changed, 43 insertions, 44 deletions
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; |