[Libreoffice-commits] core.git: desktop/qa desktop/source include/LibreOfficeKit include/vcl sw/inc sw/source
Tamás Zolnai (via logerrit)
logerrit at kemper.freedesktop.org
Fri May 8 20:43:13 UTC 2020
desktop/qa/desktop_lib/test_desktop_lib.cxx | 3 +-
desktop/source/lib/init.cxx | 33 +++++++++++++++++++++++++
include/LibreOfficeKit/LibreOfficeKit.h | 4 +++
include/LibreOfficeKit/LibreOfficeKit.hxx | 10 +++++++
include/vcl/ITiledRenderable.hxx | 11 ++++++++
sw/inc/unotxdoc.hxx | 3 ++
sw/source/uibase/uno/unotxdoc.cxx | 36 ++++++++++++++++++++++++++++
7 files changed, 99 insertions(+), 1 deletion(-)
New commits:
commit 36508d0110248f6683757602cd1668547dbfb253
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Wed May 6 14:33:10 2020 +0200
Commit: Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Fri May 8 22:42:35 2020 +0200
lok: MSForms: Handle event about item selection of a drop-down field.
Change-Id: I095013097348c98361b6614e4ddf1e9029923c7f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93659
Tested-by: Tamás Zolnai <tamas.zolnai at collabora.com>
Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 3344279f1a78..30dd2c60dc3c 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -2923,10 +2923,11 @@ void DesktopLOKTest::testABI()
CPPUNIT_ASSERT_EQUAL(documentClassOffset(58), offsetof(struct _LibreOfficeKitDocumentClass, paintWindowForView));
CPPUNIT_ASSERT_EQUAL(documentClassOffset(59), offsetof(struct _LibreOfficeKitDocumentClass, completeFunction));
CPPUNIT_ASSERT_EQUAL(documentClassOffset(60), offsetof(struct _LibreOfficeKitDocumentClass, setWindowTextSelection));
+ CPPUNIT_ASSERT_EQUAL(documentClassOffset(61), offsetof(struct _LibreOfficeKitDocumentClass, sendFormFieldEvent));
// Extending is fine, update this, and add new assert for the offsetof the
// new method
- CPPUNIT_ASSERT_EQUAL(documentClassOffset(61), sizeof(struct _LibreOfficeKitDocumentClass));
+ CPPUNIT_ASSERT_EQUAL(documentClassOffset(62), sizeof(struct _LibreOfficeKitDocumentClass));
}
CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index ccd32a035ff5..c7763b608a28 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1137,6 +1137,10 @@ static void doc_resizeWindow(LibreOfficeKitDocument* pThis, unsigned nLOKWindowI
const int nWidth, const int nHeight);
static void doc_completeFunction(LibreOfficeKitDocument* pThis, int nIndex);
+
+
+static void doc_sendFormFieldEvent(LibreOfficeKitDocument* pThis,
+ const char* pArguments);
} // extern "C"
namespace {
@@ -1252,6 +1256,8 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->createViewWithOptions = doc_createViewWithOptions;
m_pDocumentClass->completeFunction = doc_completeFunction;
+ m_pDocumentClass->sendFormFieldEvent = doc_sendFormFieldEvent;
+
gDocumentClass = m_pDocumentClass;
}
pClass = m_pDocumentClass.get();
@@ -5412,6 +5418,33 @@ static void doc_completeFunction(LibreOfficeKitDocument* pThis, int nIndex)
pDoc->completeFunction(nIndex);
}
+
+static void doc_sendFormFieldEvent(LibreOfficeKitDocument* pThis, const char* pArguments)
+{
+ SolarMutexGuard aGuard;
+
+ // Supported in Writer only
+ if (doc_getDocumentType(pThis) != LOK_DOCTYPE_TEXT)
+ return;
+
+ StringMap aMap(jsonToStringMap(pArguments));
+ ITiledRenderable* pDoc = getTiledRenderable(pThis);
+ if (!pDoc)
+ {
+ SetLastExceptionMsg("Document doesn't support tiled rendering!");
+ return;
+ }
+
+ // Sanity check
+ if (aMap.find("type") == aMap.end() || aMap.find("cmd") == aMap.end())
+ {
+ SetLastExceptionMsg("Wrong arguments for sendFormFieldEvent!");
+ return;
+ }
+
+ pDoc->executeFromFieldEvent(aMap);
+}
+
static char* lo_getError (LibreOfficeKit *pThis)
{
comphelper::ProfileZone aZone("lo_getError");
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 6203c11fb044..309744522004 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -446,6 +446,10 @@ struct _LibreOfficeKitDocumentClass
int nX,
int nY);
+ /// @see lok::Document::sendFormFieldEvent
+ void (*sendFormFieldEvent) (LibreOfficeKitDocument* pThis,
+ const char* pArguments);
+
#endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
};
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 4076637863fd..37eacdfb3649 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -779,6 +779,16 @@ public:
mpDoc->pClass->setWindowTextSelection(mpDoc, nWindowId, bSwap, nX, nY);
}
+ /**
+ * Posts an event for the form field at the cursor position.
+ *
+ * @param pArguments arguments of the event.
+ */
+ void sendFormFieldEvent(const char* pArguments)
+ {
+ mpDoc->pClass->sendFormFieldEvent(mpDoc, pArguments);
+ }
+
#endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
};
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index 841935aea930..32192796a08a 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -44,6 +44,9 @@ namespace vcl
class VCL_DLLPUBLIC ITiledRenderable
{
public:
+
+ typedef std::map<const OUString, OUString> StringMap;
+
virtual ~ITiledRenderable();
/**
@@ -296,6 +299,14 @@ public:
{
return false;
}
+
+ /**
+ * Execute a form field event in the document.
+ * E.g. select an item from a drop down field's list.
+ */
+ virtual void executeFromFieldEvent(const StringMap&)
+ {
+ }
};
} // namespace vcl
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index 59b859504ae1..dca0df658a8d 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -444,6 +444,9 @@ public:
/// @see vcl::ITiledRenderable::getPostIts().
OUString getPostIts() override;
+ /// @see vcl::ITiledRenderable::executeFromFieldEvent().
+ virtual void executeFromFieldEvent(const StringMap& aArguments) override;
+
// css::tiledrendering::XTiledRenderable
virtual void SAL_CALL paintTile( const ::css::uno::Any& Parent, ::sal_Int32 nOutputWidth, ::sal_Int32 nOutputHeight, ::sal_Int32 nTilePosX, ::sal_Int32 nTilePosY, ::sal_Int32 nTileWidth, ::sal_Int32 nTileHeight ) override;
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 063af2f70ccd..7c18ed5de296 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -160,6 +160,7 @@
#include <memory>
#include <redline.hxx>
#include <DocumentRedlineManager.hxx>
+#include <xmloff/odffields.hxx>
#define TWIPS_PER_PIXEL 15
@@ -3374,6 +3375,41 @@ OUString SwXTextDocument::getPostIts()
return OUString::fromUtf8(aStream.str().c_str());
}
+void SwXTextDocument::executeFromFieldEvent(const StringMap& aArguments)
+{
+ auto aIter = aArguments.find("type");
+ if (aIter != aArguments.end() && aIter->second == "drop-down")
+ {
+ aIter = aArguments.find("cmd");
+ if (aIter != aArguments.end() && aIter->second == "selected")
+ {
+ aIter = aArguments.find("data");
+ if (aIter != aArguments.end())
+ {
+ sal_Int32 nSelection = aIter->second.toInt32();
+ SwPosition aPos(*pDocShell->GetWrtShell()->GetCursor()->GetPoint());
+ sw::mark::IFieldmark* pFieldBM = pDocShell->GetWrtShell()->getIDocumentMarkAccess()->getFieldmarkFor(aPos);
+ if ( !pFieldBM )
+ {
+ --aPos.nContent;
+ pFieldBM = pDocShell->GetWrtShell()->getIDocumentMarkAccess()->getFieldmarkFor(aPos);
+ if (pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDROPDOWN)
+ {
+ if (nSelection >= 0)
+ {
+ OUString sKey = ODF_FORMDROPDOWN_RESULT;
+ (*pFieldBM->GetParameters())[sKey] <<= nSelection;
+ pFieldBM->Invalidate();
+ pDocShell->GetWrtShell()->SetModified();
+ pDocShell->GetView()->GetEditWin().LogicInvalidate(nullptr);
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
int SwXTextDocument::getPart()
{
SolarMutexGuard aGuard;
More information about the Libreoffice-commits
mailing list