summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamás Zolnai <tamas.zolnai@collabora.com>2021-02-10 12:23:52 +0100
committerTamás Zolnai <tamas.zolnai@collabora.com>2021-02-10 16:50:37 +0100
commit20335d5ed549af25f02467c7da21df10c8df956a (patch)
tree47a61c7e745289eb30fddd895547b135ec83ccd6
parente8d1504ba7299d78dd825a512e8f04ef33900997 (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>
-rw-r--r--desktop/source/lib/init.cxx1
-rw-r--r--sw/source/core/crsr/bookmrk.cxx98
-rw-r--r--sw/source/core/doc/docbm.cxx35
-rw-r--r--sw/source/core/inc/MarkManager.hxx2
-rw-r--r--sw/source/core/inc/bookmrk.hxx4
5 files changed, 81 insertions, 59 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 922e39697011..e72f17e8c45a 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1539,6 +1539,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 472c0af54557..4a4aad532aaa 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -624,7 +624,6 @@ namespace sw { namespace mark
DropDownFieldmark::~DropDownFieldmark()
{
- SendLOKMessage("hide");
}
void DropDownFieldmark::ShowButton(SwEditWin* pEditWin)
@@ -635,13 +634,11 @@ namespace sw { namespace 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();
}
@@ -652,74 +649,61 @@ namespace sw { namespace mark
{
m_pButton->Show();
m_pButton->CalcPosAndSize(m_aPortionPaintArea);
- SendLOKMessage("show");
}
}
- void DropDownFieldmark::SendLOKMessage(const OString& sAction)
+ void DropDownFieldmark::SendLOKMessage(SfxViewShell* pViewShell, const OString& sAction)
{
- const SfxViewShell* pViewShell = SfxViewShell::Current();
+ if (!comphelper::LibreOfficeKit::isActive())
+ return;
+
if (!pViewShell || pViewShell->isLOKMobilePhone())
- {
- return;
- }
+ return;
- if (comphelper::LibreOfficeKit::isActive())
+ OStringBuffer sPayload;
+ if (sAction == "show")
{
- if (!m_pButton)
- return;
-
- SwEditWin* pEditWin = dynamic_cast<SwEditWin*>(m_pButton->GetParent());
- if (!pEditWin)
+ 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
- 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) + "\", ");
-
- // 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
+ OUString sResultKey = ODF_FORMDROPDOWN_RESULT;
+ auto pSelectedItemIter = pParameters->find(sResultKey);
+ sal_Int32 nSelection = -1;
+ if (pSelectedItemIter != pParameters->end())
{
- 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());
+ pSelectedItemIter->second >>= nSelection;
}
+ sPayload.append("\"selected\": \"" + OString::number(nSelection) + "\", ");
+
+ // Placeholder text
+ sPayload.append("\"placeholderText\": \"" + OUStringToOString(SwResId(STR_DROP_DOWN_EMPTY_LIST), RTL_TEXTENCODING_UTF8) + "\"}}");
+ }
+ else
+ {
+ assert(sAction == "hide");
+ sPayload = "{\"action\": \"hide\", \"type\": \"drop-down\"}";
}
+ 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 17db4aed5f4e..ab1bd2ab40b2 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -46,6 +46,7 @@
#include <libxml/xmlstring.h>
#include <libxml/xmlwriter.h>
+#include <comphelper/lok.hxx>
using namespace ::sw::mark;
@@ -1434,6 +1435,8 @@ namespace sw { namespace mark
if(pNewActiveFieldmark)
pNewActiveFieldmark->ShowButton(&rEditWin);
}
+
+ LOKUpdateActiveField(pSwView);
}
void MarkManager::ClearFieldActivation()
@@ -1444,6 +1447,38 @@ namespace sw { namespace 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 edf8121836b6..4ce7c18ce011 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 {
namespace mark {
@@ -98,6 +99,7 @@ namespace sw {
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 2fe0cf3a0d5e..b65aac2bd589 100644
--- a/sw/source/core/inc/bookmrk.hxx
+++ b/sw/source/core/inc/bookmrk.hxx
@@ -45,6 +45,7 @@ class SwDoc;
class SwEditWin;
class SwServerObject;
class SvNumberFormatter;
+class SfxViewShell;
namespace sw {
namespace mark {
@@ -298,11 +299,10 @@ 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(const OString& sAction);
+ void SendLOKMessage(SfxViewShell* pViewShell, const OString& sAction);
private:
SwRect m_aPortionPaintArea;
- OString m_sLastSentLOKMsg;
};
/// Fieldmark representing a date form field.