diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-11-15 09:53:20 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-11-15 11:34:49 +0100 |
commit | 6870c0c3385bf5d19e9c80bf973fca255ae38c08 (patch) | |
tree | 9abcb20a38b24b620b3380c053ae0aa47bc7172e /sw/source/uibase | |
parent | 1caf3f2554ffac3624d43defb4252a5b40945bbc (diff) |
sw: add new FieldCode parameter for the .uno:TextFormField command
The field code/command is the input of the field expand.
Also allow setting a field result, given that the entire point of
"unhandled" fieldmarks is that Writer itself doesn't know how to compute
the field result / expanded string.
Note that a field result can be a multi-paragraph and formatted content,
so far we only allow single-paragraph plain text.
Change-Id: I1739cb985d1d4ed8e45068f15a4e0d82fd118d83
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142726
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/source/uibase')
-rw-r--r-- | sw/source/uibase/shells/textfld.cxx | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index 54e19d7ec8c4..85dffcd7affc 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -694,6 +694,14 @@ FIELD_INSERT: aFieldType = pFieldType->GetValue(); } + OUString aFieldCode; + const SfxStringItem* pFieldCode = rReq.GetArg<SfxStringItem>(FN_PARAM_2); + if (pFieldCode) + { + // Allow specifying a field code/command. + aFieldCode = pFieldCode->GetValue(); + } + rSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT_FORM_FIELD, nullptr); SwPaM* pCursorPos = rSh.GetCursor(); @@ -701,14 +709,27 @@ FIELD_INSERT: { // Insert five En Space into the text field so the field has extent static constexpr OUStringLiteral vEnSpaces = u"\u2002\u2002\u2002\u2002\u2002"; - bool bSuccess = rSh.GetDoc()->getIDocumentContentOperations().InsertString(*pCursorPos, vEnSpaces); + OUString aFieldResult(vEnSpaces); + const SfxStringItem* pFieldResult = rReq.GetArg<SfxStringItem>(FN_PARAM_3); + if (pFieldResult) + { + // Allow specifying a field result / expanded value. + aFieldResult = pFieldResult->GetValue(); + } + + bool bSuccess = rSh.GetDoc()->getIDocumentContentOperations().InsertString(*pCursorPos, aFieldResult); if(bSuccess) { IDocumentMarkAccess* pMarksAccess = rSh.GetDoc()->getIDocumentMarkAccess(); - SwPaM aFieldPam(pCursorPos->GetPoint()->GetNode(), pCursorPos->GetPoint()->GetContentIndex() - vEnSpaces.getLength(), + SwPaM aFieldPam(pCursorPos->GetPoint()->GetNode(), pCursorPos->GetPoint()->GetContentIndex() - aFieldResult.getLength(), pCursorPos->GetPoint()->GetNode(), pCursorPos->GetPoint()->GetContentIndex()); - pMarksAccess->makeFieldBookmark(aFieldPam, OUString(), aFieldType, - aFieldPam.Start()); + sw::mark::IFieldmark* pFieldmark = pMarksAccess->makeFieldBookmark( + aFieldPam, OUString(), aFieldType, aFieldPam.Start()); + if (pFieldmark && !aFieldCode.isEmpty()) + { + pFieldmark->GetParameters()->insert( + std::pair<OUString, uno::Any>(ODF_CODE_PARAM, uno::Any(aFieldCode))); + } } } |