sw/qa/uibase/shells/shells.cxx | 26 ++++++++++++++++++++++++++ sw/sdi/swriter.sdi | 2 +- sw/source/uibase/shells/textfld.cxx | 10 +++++++++- 3 files changed, 36 insertions(+), 2 deletions(-)
New commits: commit 9f481c1eba14566c649c45ddbf15b66e6e42cc30 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Nov 14 14:21:31 2022 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Nov 15 11:09:07 2022 +0100 sw: add new FieldType parameter for the .uno:TextFormField command Currently LOK clients can't insert fieldmarks which are comparable to the ones Zotero's Word extension inserts into DOCX files. There is already a .uno:TextFormField UNO command to insert fieldmarks, but it has a hardcoded field type set to ODF_FORMTEXT, which is not what we need. Fix this by adding a new, optional FieldType parameter to the existing UNO command. The field code/command and the result is not yet possible to customize. (cherry picked from commit 1ff360c29c99a570bfe59c69d8f589d4f2b59135) Conflicts: sw/qa/uibase/shells/shells.cxx sw/source/uibase/shells/textfld.cxx Change-Id: I5625858af950f718220eebeef8fb90267693db7a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142725 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx index 4bde6eab7ac6..3d5342f7a121 100644 --- a/sw/qa/uibase/shells/shells.cxx +++ b/sw/qa/uibase/shells/shells.cxx @@ -24,6 +24,7 @@ #include <editeng/editobj.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/propertyvalue.hxx> +#include <xmloff/odffields.hxx> #include <IDocumentContentOperations.hxx> #include <cmdid.h> @@ -238,6 +239,31 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testContentControlPageBreak) CPPUNIT_ASSERT_EQUAL(1, getPages()); } +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertTextFormField) +{ + // Given an empty document: + SwDoc* pDoc = createSwDoc(); + + // When inserting an ODF_UNHANDLED fieldmark: + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(OUString(ODF_UNHANDLED))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + + // Then make sure that it's type/name is correct: + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwCursor* pCursor = pWrtShell->GetCursor(); + pCursor->SttEndDoc(/*bSttDoc=*/true); + sw::mark::IFieldmark* pFieldmark + = pDoc->getIDocumentMarkAccess()->getFieldmarkAt(*pCursor->GetPoint()); + CPPUNIT_ASSERT(pFieldmark); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: vnd.oasis.opendocument.field.UNHANDLED + // - Actual : vnd.oasis.opendocument.field.FORMTEXT + // i.e. the custom type parameter was ignored. + CPPUNIT_ASSERT_EQUAL(OUString(ODF_UNHANDLED), pFieldmark->GetFieldname()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi index e34d663bf29b..7aa6aab89a17 100644 --- a/sw/sdi/swriter.sdi +++ b/sw/sdi/swriter.sdi @@ -8203,7 +8203,7 @@ SfxBoolItem ShowInlineTooltips FN_SHOW_INLINETOOLTIPS ] SfxVoidItem TextFormField FN_INSERT_TEXT_FORMFIELD - +(SfxStringItem FieldType FN_PARAM_1) [ AutoUpdate = TRUE, FastCall = FALSE, diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index 474d76ce0030..17030cba23a3 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -686,6 +686,14 @@ FIELD_INSERT: case FN_INSERT_TEXT_FORMFIELD: { + OUString aFieldType(ODF_FORMTEXT); + const SfxStringItem* pFieldType = rReq.GetArg<SfxStringItem>(FN_PARAM_1); + if (pFieldType) + { + // Allow overwriting the default type. + aFieldType = pFieldType->GetValue(); + } + rSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT_FORM_FIELD, nullptr); SwPaM* pCursorPos = rSh.GetCursor(); @@ -699,7 +707,7 @@ FIELD_INSERT: IDocumentMarkAccess* pMarksAccess = rSh.GetDoc()->getIDocumentMarkAccess(); SwPaM aFieldPam(pCursorPos->GetPoint()->nNode, pCursorPos->GetPoint()->nContent.GetIndex() - vEnSpaces.getLength(), pCursorPos->GetPoint()->nNode, pCursorPos->GetPoint()->nContent.GetIndex()); - pMarksAccess->makeFieldBookmark(aFieldPam, OUString(), ODF_FORMTEXT, + pMarksAccess->makeFieldBookmark(aFieldPam, OUString(), aFieldType, aFieldPam.Start()); } }