summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-05-29 17:26:57 +0200
committerMiklos Vajna <vmiklos@collabora.com>2019-05-30 08:43:22 +0200
commit6bb241ccc61c6904efec95978fa17e33c0eb1df3 (patch)
treed1d6b92a09402765e2581b8bf5be81b3aac52f4d /xmloff
parent18d0d8541432782e9bf761992a8bda5d29ee6564 (diff)
ODT export: fix lost <text:user-field-decl> for fields in tables in headers
The problem was that XMLTextFieldExport::ExportFieldAutoStyle() assumed that the text of a field anchor is always the toplevel XText, which is true in case of body vs header text, but false in case header text vs text-in-table-in-header. So add an UNO property which exposes the parent of a table cell, this way text in header (regardless of it's in a table or not) will have the same XText, leading to writing the necessary <text:user-field-decl> element for the matching <text:user-field-get> definition. Change-Id: I077b8d7e9dfae4062539894318637e266b925382 Reviewed-on: https://gerrit.libreoffice.org/73176 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/text/txtflde.cxx29
1 files changed, 28 insertions, 1 deletions
diff --git a/xmloff/source/text/txtflde.cxx b/xmloff/source/text/txtflde.cxx
index df43562daf23..293362b8ab10 100644
--- a/xmloff/source/text/txtflde.cxx
+++ b/xmloff/source/text/txtflde.cxx
@@ -157,6 +157,31 @@ static sal_Char const FIELD_SERVICE_MEASURE[] = "Measure";
static sal_Char const FIELD_SERVICE_TABLE_FORMULA[] = "TableFormula";
static sal_Char const FIELD_SERVICE_DROP_DOWN[] = "DropDown";
+namespace
+{
+/// Walks up the parent chain of xText and returns the topmost text.
+uno::Reference<text::XText> GetToplevelText(const uno::Reference<text::XText>& xText)
+{
+ uno::Reference<text::XText> xRet = xText;
+ while (true)
+ {
+ uno::Reference<beans::XPropertySet> xPropertySet(xRet, uno::UNO_QUERY);
+ if (!xPropertySet.is())
+ return xRet;
+
+ if (!xPropertySet->getPropertySetInfo()->hasPropertyByName("ParentText"))
+ return xRet;
+
+ uno::Reference<text::XText> xParent;
+ if (xPropertySet->getPropertyValue("ParentText") >>= xParent)
+ xRet = xParent;
+ else
+ return xRet;
+ }
+ return xRet;
+}
+}
+
SvXMLEnumStringMapEntry<FieldIdEnum> const aFieldServiceNameMapping[] =
{
ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_SENDER, FIELD_ID_SENDER ),
@@ -749,7 +774,9 @@ void XMLTextFieldExport::ExportFieldAutoStyle(
Reference<XDependentTextField> xDepField(rTextField, UNO_QUERY);
if (xDepField.is())
{
- Reference<XText> xOurText = rTextField->getAnchor()->getText();
+ // The direct parent may be just the table cell, while we want the topmost parent, e.g.
+ // a header text.
+ Reference<XText> xOurText = GetToplevelText(rTextField->getAnchor()->getText());
map<Reference<XText>, set<OUString> >::iterator aMapIter =
pUsedMasters->find(xOurText);