sw/qa/uitest/data/tdf163894.fodt        |   28 +++++++++++++++
 sw/qa/uitest/writer_tests7/tdf163894.py |   59 ++++++++++++++++++++++++++++++++
 sw/source/ui/fldui/fldref.cxx           |   18 +++++++++
 3 files changed, 105 insertions(+)

New commits:
commit fce6492756e4657008ed1ce734a08929aa19c264
Author:     László Németh <[email protected]>
AuthorDate: Mon Feb 9 13:22:20 2026 +0100
Commit:     László Németh <[email protected]>
CommitDate: Wed Feb 18 13:50:28 2026 +0100

    tdf#163894 sw DOCX: add character styles to style-ref window
    
    Allow to refer and check character styles in the cross-reference
    dialog window, fixing also the associated interoperability issues.
    Now it's possible to check the (previously unknown) reference
    character style in the DOCX import, also to create new style-ref
    fields referring the character styles used in the document.
    
    Follow-up to commit 955f0f9b5e7f1d4ba42eb314478cc6924b4b63a7
    "tdf#163894 sw DOCX: fix style-ref with character style",
    commit d4fdafa103bfea94a279d7069ddc50ba92f67d01 "tdf#160402
    writerfilter,sw: STYLEREF field can refer to character style"
    and commit 32c588dd1164aa2fc4c8120ddb74bd510cc082f9
    "tdf#86790: Add support for a word-style styleref".
    
    Change-Id: I4cb34e8b470114d3beb4573ae14caea5900ac0ca
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199590
    Tested-by: Jenkins
    Reviewed-by: László Németh <[email protected]>

diff --git a/sw/qa/uitest/data/tdf163894.fodt b/sw/qa/uitest/data/tdf163894.fodt
new file mode 100644
index 000000000000..e4d47bae050f
--- /dev/null
+++ b/sw/qa/uitest/data/tdf163894.fodt
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document xmlns:css3t="http://www.w3.org/TR/css3-text/"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:dc="http://purl.org/dc/elements/1.1/"; xmlns:c
 alcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:
 meta:1.0" 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 office:version="1.4" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:settings>
+ </office:settings>
+ <office:styles>
+  <style:style style:name="Emphasis" style:family="text">
+    <style:text-properties fo:font-style="italic" 
style:font-style-asian="italic" style:font-style-complex="italic"/>
+  </style:style>
+ </office:styles>
+ <office:automatic-styles>
+  <style:style style:name="P1" style:family="paragraph" 
style:parent-style-name="Standard">
+   <style:paragraph-properties style:writing-mode="lr-tb"/>
+  </style:style>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard">
+   <style:header>
+    <text:p text:style-name="Header">Styleref: <loext:style-ref 
text:reference-format="text" text:ref-name="Emphasis">Etiam eget dui. 
</loext:style-ref></text:p>
+   </style:header>
+  </style:master-page>
+ </office:master-styles>
+ <office:body>
+  <office:text>
+   <text:p text:style-name="P1"><text:span text:style-name="T2">Mauris 
</text:span><text:span text:style-name="Emphasis"><text:span 
text:style-name="T2">Etiam eget dui. </text:span></text:span><text:span 
text:style-name="Emphasis"><text:span 
text:style-name="T1">A</text:span></text:span><text:span 
text:style-name="Emphasis"><text:span text:style-name="T2">liquet pede. 
</text:span></text:span><text:span text:style-name="Emphasis">Donec. 
</text:span>Suspendisse dui purus. Ut nonummy.</text:p>
+  </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/uitest/writer_tests7/tdf163894.py 
b/sw/qa/uitest/writer_tests7/tdf163894.py
new file mode 100755
index 000000000000..bcf7ef8e9196
--- /dev/null
+++ b/sw/qa/uitest/writer_tests7/tdf163894.py
@@ -0,0 +1,59 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
+from libreoffice.uno.propertyvalue import mkPropertyValues
+
+class tdf163894(UITestCase):
+
+    FIELD_CONTENT = "Etiam eget dui. Aliquet pede. Donec. "
+    PARA_CONTENT = "Mauris Etiam eget dui. Aliquet pede. Donec. Suspendisse 
dui purus. Ut nonummy."
+
+    def test_tdf163894(self):
+        with self.ui_test.load_file(get_url_for_data_file("tdf163894.fodt")) 
as writer_doc:
+            # check visibility of the referred character style in the dialog 
window
+            with 
self.ui_test.execute_modeless_dialog_through_command(".uno:InsertReferenceField",
 close_button="cancel") as xDialog:
+                # Select set reference type
+                xTreelistType = xDialog.getChild("type-ref")
+                xTreeEntry = xTreelistType.getChild('5')
+                self.assertEqual(get_state_as_dict(xTreeEntry)["Text"], 
"Styles")
+                xTreeEntry.executeAction("SELECT", tuple())
+
+                # check character styles in the STYLES list
+
+                # This was failed (missing character styles used in the 
document)
+                xSelect = xDialog.getChild("select-ref")
+                self.assertEqual("5", get_state_as_dict(xSelect)["Children"])
+                self.assertEqual("Emphasis", 
get_state_as_dict(xSelect.getChild(1))["Text"])
+
+                # select character style "Emphasis"
+
+                xSelectEntry = xSelect.getChild("1")
+                self.assertEqual(get_state_as_dict(xSelectEntry)["Text"], 
"Emphasis")
+                xSelectEntry.executeAction("SELECT", tuple())
+
+                # Insert a cross reference for the character style "Emphasis"
+
+                xInsert = xDialog.getChild("ok")
+                xInsert.executeAction("CLICK", tuple())
+
+            # FIXME style-ref doesn't work in the same paragraph, yet
+            # so insert a new paragraph to get a working style-ref field
+            # instead of "Reference source not found"
+            xWriterDoc = self.xUITest.getTopFocusWindow()
+            xWriterEdit = xWriterDoc.getChild("writer_edit")
+            xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"RETURN"}))
+            xToolkit = 
self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
+            xToolkit.waitUntilAllIdlesDispatched()
+            output_text = writer_doc.Text.getString().replace('
', '
')
+            # text of the document starts with the new cross-reference
+            self.assertEqual(self.FIELD_CONTENT + "
" + self.PARA_CONTENT, output_text)
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/ui/fldui/fldref.cxx b/sw/source/ui/fldui/fldref.cxx
index c66009494d59..30beca4e3cd6 100644
--- a/sw/source/ui/fldui/fldref.cxx
+++ b/sw/source/ui/fldui/fldref.cxx
@@ -723,6 +723,24 @@ void SwFieldRefPage::UpdateSubType(const OUString& 
filterString)
                 pStyle = stylesheetIterator->Next();
             }
 
+            // add character styles
+
+            stylesheetIterator
+                = pStyleSheetPool->CreateIterator(SfxStyleFamily::Char, 
SfxStyleSearchBits::Used);
+
+            pStyle = stylesheetIterator->First();
+            while (pStyle != nullptr)
+            {
+                bool isSubstring = MatchSubstring(pStyle->GetName(), 
filterString);
+
+                if (isSubstring)
+                {
+                    m_xSelectionLB->append_text(pStyle->GetName());
+                }
+
+                pStyle = stylesheetIterator->Next();
+            }
+
             if (IsFieldEdit() && pRefField) {
                 sOldSel = pRefField->GetPar1();
                 m_xStylerefFromBottomCB->set_active((pRefField->GetFlags() & 
REFFLDFLAG_STYLE_FROM_BOTTOM) == REFFLDFLAG_STYLE_FROM_BOTTOM);

Reply via email to