diff options
author | Tamás Zolnai <tamas.zolnai@collabora.com> | 2021-02-10 12:23:52 +0100 |
---|---|---|
committer | Tamás Zolnai <tamas.zolnai@collabora.com> | 2021-02-11 17:07:21 +0100 |
commit | 250eb2ee92f3f382c4a6ac3b643fc8e3b60c8be7 (patch) | |
tree | 733d4633a73c1a6f06504d980f2137736ba03622 /sw | |
parent | 4a9d257bec7964c0b611b2d422b7842fc5ee38e0 (diff) |
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@gmail.com>
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
(cherry picked from commit 20335d5ed549af25f02467c7da21df10c8df956a)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110759
Tested-by: Tamás Zolnai <tamas.zolnai@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/crsr/bookmrk.cxx | 26 | ||||
-rw-r--r-- | sw/source/core/doc/docbm.cxx | 35 | ||||
-rw-r--r-- | sw/source/core/inc/MarkManager.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/inc/bookmrk.hxx | 4 |
4 files changed, 44 insertions, 23 deletions
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. |