sw/inc/unostyle.hxx                 |    1 +
 sw/source/core/unocore/unostyle.cxx |   23 +++++++++++++++++------
 2 files changed, 18 insertions(+), 6 deletions(-)

New commits:
commit 6d5d5c8065365a949b0c0b5ba0c9d071d20ff4da
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Thu Dec 12 18:51:09 2024 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Dec 13 13:22:37 2024 +0100

    GetCountOrName returns a UI name
    
    But the caller in SwXStyleFamily::getByIndex was treating the
    return value like a programmatic name.
    
    Change-Id: I6b3779be834f713e09a026fdcbf965753a77cc9a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178381
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    Tested-by: Jenkins
    (cherry picked from commit e7763739ae04193190a29e5127f047de2f5f35af)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178411

diff --git a/sw/inc/unostyle.hxx b/sw/inc/unostyle.hxx
index 4ea326d23c1e..908797ffda12 100644
--- a/sw/inc/unostyle.hxx
+++ b/sw/inc/unostyle.hxx
@@ -416,6 +416,7 @@ class SW_DLLPUBLIC SwXStyleFamily final : public 
cppu::WeakImplHelper
 
     SwXStyle* FindStyle(std::u16string_view rStyleName) const;
     sal_Int32 GetCountOrName(OUString* pString, sal_Int32 nIndex = 
SAL_MAX_INT32);
+    rtl::Reference<SwXBaseStyle> getStyle(SfxStyleSheetBase* pBase, const 
OUString& rStyleName);
     static const StyleFamilyEntry& InitEntry(SfxStyleFamily eFamily);
 public:
     SwXStyleFamily(SwDocShell* pDocShell, const SfxStyleFamily eFamily);
diff --git a/sw/source/core/unocore/unostyle.cxx 
b/sw/source/core/unocore/unostyle.cxx
index 68e632fac5c7..4f9d17063b76 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -912,16 +912,22 @@ uno::Any SwXStyleFamily::getByIndex(sal_Int32 nIndex)
         throw lang::IndexOutOfBoundsException();
     if(!m_pBasePool)
         throw uno::RuntimeException();
-    OUString sStyleName;
+
+    OUString sStyleProgName;
     try
     {
-        SwStyleNameMapper::FillProgName(m_rEntry.translateIndex(nIndex), 
sStyleName);
+        SwStyleNameMapper::FillProgName(m_rEntry.translateIndex(nIndex), 
sStyleProgName);
     } catch(...) {}
-    if (sStyleName.isEmpty())
-        GetCountOrName(&sStyleName, nIndex);
-    if(sStyleName.isEmpty())
+    if (!sStyleProgName.isEmpty())
+        return getByName(sStyleProgName);
+
+    OUString sStyleUIName;
+    GetCountOrName(&sStyleUIName, nIndex);
+    if(sStyleUIName.isEmpty())
         throw lang::IndexOutOfBoundsException();
-    return getByName(sStyleName);
+
+    SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleUIName, 
m_rEntry.family());
+    return uno::Any(uno::Reference<style::XStyle>(getStyle(pBase, 
sStyleUIName)));
 }
 
 uno::Any SwXStyleFamily::getByName(const OUString& rName)
@@ -963,6 +969,11 @@ rtl::Reference<SwXBaseStyle> 
SwXStyleFamily::getStyleByName(const OUString& rPro
     SfxStyleSheetBase* pBase = m_pBasePool->Find(sStyleName, 
m_rEntry.family());
     if(!pBase)
         throw container::NoSuchElementException(rProgName);
+    return getStyle(pBase, sStyleName);
+}
+
+rtl::Reference<SwXBaseStyle> SwXStyleFamily::getStyle(SfxStyleSheetBase* 
pBase, const OUString& sStyleName)
+{
     rtl::Reference<SwXBaseStyle> xStyle = FindStyle(sStyleName);
     if(!xStyle.is())
         switch (m_rEntry.family())

Reply via email to