summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Francis <dennis.francis@collabora.com>2022-05-19 15:27:48 +0530
committerMiklos Vajna <vmiklos@collabora.com>2022-12-05 11:08:52 +0000
commit8be4a713e9f44bf05aebc0a3054654a18b4de065 (patch)
tree634bf3ad509ff560985440e2b4c711fba238978e
parent95921862bdecef95faa73501aadf17fd1aa14218 (diff)
sw: prefer view's redline author name...
to expand SwAuthorFieldType. Redline author name is set in SwXTextDocument::initializeForTiledRendering each time a new view is created. Change-Id: I316e0cae4399796682949de14b6d4b924833eb04 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134608 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143649
-rw-r--r--sw/qa/extras/tiledrendering/tiledrendering.cxx41
-rw-r--r--sw/source/core/fields/docufld.cxx11
2 files changed, 51 insertions, 1 deletions
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 28f67f9a8500..88b4dcc95d7f 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -19,6 +19,8 @@
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
+#include <com/sun/star/text/XTextField.hpp>
+#include <com/sun/star/text/AuthorDisplayFormat.hpp>
#include <com/sun/star/datatransfer/XTransferable2.hpp>
#include <test/helper/transferable.hxx>
@@ -3750,6 +3752,45 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testDateContentControl)
CPPUNIT_ASSERT_EQUAL(OUString("2022-05-30"), pTextNode->GetExpandText(pWrtShell->GetLayout()));
}
+CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testAuthorField)
+{
+ SwXTextDocument* pXTextDocument = createDoc();
+ const OUString sAuthor("Abcd Xyz");
+
+ uno::Sequence<beans::PropertyValue> aPropertyValues1(comphelper::InitPropertySequence(
+ {
+ {".uno:Author", uno::makeAny(sAuthor)},
+ }));
+ pXTextDocument->initializeForTiledRendering(aPropertyValues1);
+
+ auto insertAuthorField = [this]()
+ {
+ uno::Reference<lang::XMultiServiceFactory> const xMSF(mxComponent, uno::UNO_QUERY_THROW);
+ uno::Reference<text::XTextDocument> const xTD(mxComponent, uno::UNO_QUERY_THROW);
+
+ auto const xText = xTD->getText();
+ auto const xTextCursor = xText->createTextCursor();
+ CPPUNIT_ASSERT(xTextCursor.is());
+
+ xTextCursor->gotoEnd(false);
+
+ uno::Reference<text::XTextField> const xTextField(
+ xMSF->createInstance("com.sun.star.text.textfield.Author"), uno::UNO_QUERY_THROW);
+
+ uno::Reference<beans::XPropertySet> xTextFieldProps(xTextField, uno::UNO_QUERY_THROW);
+ xTextFieldProps->setPropertyValue("FullName", uno::Any(true));
+
+ xText->insertTextContent(xTextCursor, xTextField, false);
+ };
+
+ insertAuthorField();
+ Scheduler::ProcessEventsToIdle();
+
+ xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+
+ assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/Special[1]", "rText", sAuthor);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx
index a3b5d5a5e12d..0e5777e7bf9e 100644
--- a/sw/source/core/fields/docufld.cxx
+++ b/sw/source/core/fields/docufld.cxx
@@ -314,7 +314,16 @@ OUString SwAuthorFieldType::Expand(sal_uLong nFormat)
{
SvtUserOptions& rOpt = SW_MOD()->GetUserOptions();
if((nFormat & 0xff) == AF_NAME)
- return rOpt.GetFullName();
+ {
+ // Prefer the view's redline author name.
+ // (set in SwXTextDocument::initializeForTiledRendering)
+ std::size_t nAuthor = SW_MOD()->GetRedlineAuthor();
+ OUString sAuthor = SW_MOD()->GetRedlineAuthor(nAuthor);
+ if (sAuthor.isEmpty())
+ return rOpt.GetFullName();
+
+ return sAuthor;
+ }
return rOpt.GetID();
}