svx/source/inc/StylesPreviewWindow.hxx              |    6 ++
 svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx |   19 ++++----
 svx/source/tbxctrls/StylesPreviewWindow.cxx         |   46 +++++++++-----------
 3 files changed, 37 insertions(+), 34 deletions(-)

New commits:
commit 392947ed9db1c13d87dacc7cab9b4b896a1a931c
Author:     Szymon Kłos <[email protected]>
AuthorDate: Mon Nov 24 11:53:43 2025 +0000
Commit:     Szymon Kłos <[email protected]>
CommitDate: Wed Dec 31 08:23:47 2025 +0100

    notebookbar: human-readable type for style entries
    
    - we use 2 strings as styles are identified by the name
    - in the UI we want to show translated string but to
      deduplicate standard styles we use common, English
      name
    
    Change-Id: I4046d54f67d0496bd7ec63e840491091dae39995
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194437
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196325
    Reviewed-by: Szymon Kłos <[email protected]>
    Tested-by: Jenkins

diff --git a/svx/source/inc/StylesPreviewWindow.hxx 
b/svx/source/inc/StylesPreviewWindow.hxx
index 4013a256b2e9..b03b385c086c 100644
--- a/svx/source/inc/StylesPreviewWindow.hxx
+++ b/svx/source/inc/StylesPreviewWindow.hxx
@@ -28,7 +28,11 @@
 #include <vcl/weld/IconView.hxx>
 
 // pair of id and name, name can be translated to other language
-typedef std::pair<OUString, OUString> StylePreviewDescriptor;
+struct StylePreviewDescriptor
+{
+    OUString commonName; // English: Heading 1
+    OUString translatedName; //  German: Überschrift 1
+};
 typedef std::vector<StylePreviewDescriptor> StylePreviewList;
 
 class StylesPreviewWindow_Base;
diff --git a/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx 
b/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx
index c5a9cadc4cd2..11793e718156 100644
--- a/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx
+++ b/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx
@@ -73,10 +73,11 @@ void StylesPreviewToolBoxControl::InitializeStyles(
                 {
                     css::uno::Reference<css::beans::XPropertySet> xStyle;
                     xParaStyles->getByName(rStyle) >>= xStyle;
-                    OUString sName;
-                    xStyle->getPropertyValue(u"DisplayName"_ustr) >>= sName;
-                    if (!sName.isEmpty())
-                        
m_aDefaultStyles.push_back(StylePreviewDescriptor(rStyle, sName));
+                    OUString sTranslatedName;
+                    xStyle->getPropertyValue(u"DisplayName"_ustr) >>= 
sTranslatedName;
+                    if (!sTranslatedName.isEmpty())
+                        m_aDefaultStyles.emplace_back<StylePreviewDescriptor>(
+                            { rStyle, sTranslatedName });
                 }
                 catch (const css::container::NoSuchElementException&)
                 {
@@ -104,12 +105,12 @@ void StylesPreviewToolBoxControl::InitializeStyles(
                             xCellStyles->getByName(sStyleName), 
css::uno::UNO_QUERY);
                         if (xStyle)
                         {
-                            OUString sName;
-                            xStyle->getPropertyValue(u"DisplayName"_ustr) >>= 
sName;
-                            if (!sName.isEmpty())
+                            OUString sTranslatedName;
+                            xStyle->getPropertyValue(u"DisplayName"_ustr) >>= 
sTranslatedName;
+                            if (!sTranslatedName.isEmpty())
                             {
-                                m_aDefaultStyles.push_back(
-                                    StylePreviewDescriptor(sStyleName, sName));
+                                
m_aDefaultStyles.emplace_back<StylePreviewDescriptor>(
+                                    { sStyleName, sTranslatedName });
                             }
                         }
                     }
diff --git a/svx/source/tbxctrls/StylesPreviewWindow.cxx 
b/svx/source/tbxctrls/StylesPreviewWindow.cxx
index 983228980851..f300d70b514c 100644
--- a/svx/source/tbxctrls/StylesPreviewWindow.cxx
+++ b/svx/source/tbxctrls/StylesPreviewWindow.cxx
@@ -315,8 +315,8 @@ void StyleItemController::DrawEntry(vcl::RenderContext& 
rRenderContext)
         return;
 
     pStyle = pPool->First(m_eStyleFamily);
-    while (pStyle && pStyle->GetName() != m_aStyleName.first
-           && pStyle->GetName() != m_aStyleName.second)
+    while (pStyle && pStyle->GetName() != m_aStyleName.commonName
+           && pStyle->GetName() != m_aStyleName.translatedName)
         pStyle = pPool->Next();
 
     if (!pStyle)
@@ -403,7 +403,7 @@ void 
StyleItemController::DrawContentBackground(vcl::RenderContext& rRenderConte
 void StyleItemController::DrawHighlight(vcl::RenderContext& rRenderContext, 
Color aFontBack)
 {
     tools::Rectangle aTextRect;
-    rRenderContext.GetTextBoundRect(aTextRect, m_aStyleName.second);
+    rRenderContext.GetTextBoundRect(aTextRect, m_aStyleName.translatedName);
 
     Size aSize = aTextRect.GetSize();
     aSize.AdjustHeight(aSize.getHeight());
@@ -422,17 +422,18 @@ void 
StyleItemController::DrawHighlight(vcl::RenderContext& rRenderContext, Colo
 
 void StyleItemController::DrawText(vcl::RenderContext& rRenderContext)
 {
-    const SalLayoutGlyphs* layoutGlyphs
-        = SalLayoutGlyphsCache::self()->GetLayoutGlyphs(&rRenderContext, 
m_aStyleName.second);
+    const SalLayoutGlyphs* layoutGlyphs = 
SalLayoutGlyphsCache::self()->GetLayoutGlyphs(
+        &rRenderContext, m_aStyleName.translatedName);
     tools::Rectangle aTextRect;
-    rRenderContext.GetTextBoundRect(aTextRect, m_aStyleName.second, 0, 0, -1, 
0, {}, {},
+    rRenderContext.GetTextBoundRect(aTextRect, m_aStyleName.translatedName, 0, 
0, -1, 0, {}, {},
                                     layoutGlyphs);
 
     Point aPos(0, 0);
     aPos.AdjustX(LEFT_MARGIN);
     aPos.AdjustY((rRenderContext.GetOutputHeightPixel() - aTextRect.Bottom()) 
/ 2);
 
-    rRenderContext.DrawText(aPos, m_aStyleName.second, 0, -1, nullptr, 
nullptr, layoutGlyphs);
+    rRenderContext.DrawText(aPos, m_aStyleName.translatedName, 0, -1, nullptr, 
nullptr,
+                            layoutGlyphs);
 }
 
 StylesPreviewWindow_Base::StylesPreviewWindow_Base(
@@ -525,7 +526,8 @@ void StylesPreviewWindow_Base::UpdateSelection()
 
     for (StylePreviewList::size_type i = 0; i < m_aAllStyles.size(); ++i)
     {
-        if (m_aAllStyles[i].first == m_sSelectedStyle || 
m_aAllStyles[i].second == m_sSelectedStyle)
+        if (m_aAllStyles[i].commonName == m_sSelectedStyle
+            || m_aAllStyles[i].translatedName == m_sSelectedStyle)
         {
             m_xStylesView->select(i);
             break;
@@ -568,7 +570,7 @@ IMPL_LINK(StylesPreviewWindow_Base, GetPreviewImage, const 
weld::encoded_image_q
     const weld::TreeIter& rIter = std::get<1>(rQuery);
     OUString sStyleId(m_xStylesView->get_id(rIter));
     OUString sStyleName(m_xStylesView->get_text(rIter));
-    OString sBase64Png(GetCachedPreviewJson(StylePreviewDescriptor(sStyleId, 
sStyleName)));
+    OString sBase64Png(GetCachedPreviewJson({ sStyleId, sStyleName }));
     if (sBase64Png.isEmpty())
         return false;
 
@@ -580,9 +582,9 @@ IMPL_LINK(StylesPreviewWindow_Base, GetPreviewImage, const 
weld::encoded_image_q
 
 Bitmap StylesPreviewWindow_Base::GetCachedPreview(const 
StylePreviewDescriptor& rStyle)
 {
-    auto aFound = StylePreviewCache::Get().find(rStyle.second);
+    auto aFound = StylePreviewCache::Get().find(rStyle.translatedName);
     if (aFound != StylePreviewCache::Get().end())
-        return StylePreviewCache::Get()[rStyle.second];
+        return StylePreviewCache::Get()[rStyle.translatedName];
     else
     {
         ScopedVclPtrInstance<VirtualDevice> pImg;
@@ -592,7 +594,7 @@ Bitmap StylesPreviewWindow_Base::GetCachedPreview(const 
StylePreviewDescriptor&
         StyleItemController aStyleController(rStyle);
         aStyleController.Paint(*pImg);
         Bitmap aBitmap(pImg->GetBitmap(Point(0, 0), aSize));
-        StylePreviewCache::Get()[rStyle.second] = aBitmap;
+        StylePreviewCache::Get()[rStyle.translatedName] = aBitmap;
 
         return aBitmap;
     }
@@ -600,13 +602,13 @@ Bitmap StylesPreviewWindow_Base::GetCachedPreview(const 
StylePreviewDescriptor&
 
 OString StylesPreviewWindow_Base::GetCachedPreviewJson(const 
StylePreviewDescriptor& rStyle)
 {
-    auto aJsonFound = StylePreviewCache::GetJson().find(rStyle.second);
+    auto aJsonFound = StylePreviewCache::GetJson().find(rStyle.translatedName);
     if (aJsonFound != StylePreviewCache::GetJson().end())
-        return StylePreviewCache::GetJson()[rStyle.second];
+        return StylePreviewCache::GetJson()[rStyle.translatedName];
 
     Bitmap aBitmap = GetCachedPreview(rStyle);
     OString sResult = extractPngString(aBitmap);
-    StylePreviewCache::GetJson()[rStyle.second] = sResult;
+    StylePreviewCache::GetJson()[rStyle.translatedName] = sResult;
     return sResult;
 }
 
@@ -629,11 +631,11 @@ inline void lcl_AppendParaStyles(StylePreviewList& 
rAllStyles, SfxStyleSheetBase
         // do not duplicate
         const auto aFound = std::find_if(
             rAllStyles.begin(), rAllStyles.end(), [sName](const 
StylePreviewDescriptor& element) {
-                return element.first == sName || element.second == sName;
+                return element.commonName == sName || element.translatedName 
== sName;
             });
 
         if (aFound == rAllStyles.end())
-            rAllStyles.push_back(StylePreviewDescriptor(sName, sName));
+            rAllStyles.emplace_back<StylePreviewDescriptor>({ sName, sName });
 
         pStyle = xIter->Next();
     }
@@ -665,13 +667,9 @@ void StylesPreviewWindow_Base::UpdateStylesList()
     const bool bNeedInsertPreview = !comphelper::LibreOfficeKit::isActive();
     for (const auto& rStyle : m_aAllStyles)
     {
-        if (bNeedInsertPreview)
-        {
-            Bitmap aPreview = GetCachedPreview(rStyle);
-            m_xStylesView->append(rStyle.first, rStyle.second, &aPreview);
-        }
-        else
-            m_xStylesView->append(rStyle.first, rStyle.second, nullptr);
+        Bitmap aPreview = GetCachedPreview(rStyle);
+        Bitmap* pPreview = bNeedInsertPreview ? &aPreview : nullptr;
+        m_xStylesView->append(rStyle.commonName, rStyle.translatedName, 
pPreview);
     }
     m_xStylesView->thaw();
 }

Reply via email to