diff options
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/uibase/shells/shells.cxx | 27 | ||||
-rw-r--r-- | sw/sdi/swriter.sdi | 2 | ||||
-rw-r--r-- | sw/source/uibase/shells/textfld.cxx | 10 |
3 files changed, 37 insertions, 2 deletions
diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx index 55b388860adc..c107913e6469 100644 --- a/sw/qa/uibase/shells/shells.cxx +++ b/sw/qa/uibase/shells/shells.cxx @@ -25,6 +25,7 @@ #include <comphelper/processfactory.hxx> #include <comphelper/propertyvalue.hxx> #include <unotools/ucbstreamhelper.hxx> +#include <xmloff/odffields.hxx> #include <IDocumentContentOperations.hxx> #include <cmdid.h> @@ -269,6 +270,32 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testContentControlPageBreak) CPPUNIT_ASSERT_EQUAL(1, getPages()); } +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertTextFormField) +{ + // Given an empty document: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + + // 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 90c4a2b2b864..ca4aaf56ca8b 100644 --- a/sw/sdi/swriter.sdi +++ b/sw/sdi/swriter.sdi @@ -8221,7 +8221,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 344a246747e1..54e19d7ec8c4 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()->GetNode(), pCursorPos->GetPoint()->GetContentIndex() - vEnSpaces.getLength(), pCursorPos->GetPoint()->GetNode(), pCursorPos->GetPoint()->GetContentIndex()); - pMarksAccess->makeFieldBookmark(aFieldPam, OUString(), ODF_FORMTEXT, + pMarksAccess->makeFieldBookmark(aFieldPam, OUString(), aFieldType, aFieldPam.Start()); } } |