sc/source/ui/sidebar/CellLineStyleControl.cxx  |   42 +++++++++++--------------
 sc/source/ui/sidebar/CellLineStyleValueSet.cxx |   14 +++-----
 sc/source/ui/sidebar/CellLineStyleValueSet.hxx |    4 +-
 3 files changed, 27 insertions(+), 33 deletions(-)

New commits:
commit e003c40c6319909da1e3f671765f347b35f51713
Author:     Michael Weghorn <[email protected]>
AuthorDate: Fri Nov 28 10:34:05 2025 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Sat Nov 29 06:52:16 2025 +0100

    sc: Use std::vector in CellLineStyleValueSet
    
    ... and CellLineStyleControl.
    
    In particular for CellLineStyleValueSet::SetUnit,
    passing a vector of strings is more obvious than
    passing a pointer to a string (as the pointer to
    the first element in the array).
    
    Change-Id: I2d521ee3472ef274d15e89a3f84f38060916d3c9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194765
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/sc/source/ui/sidebar/CellLineStyleControl.cxx 
b/sc/source/ui/sidebar/CellLineStyleControl.cxx
index d93b8cf70436..bd3999fd2487 100644
--- a/sc/source/ui/sidebar/CellLineStyleControl.cxx
+++ b/sc/source/ui/sidebar/CellLineStyleControl.cxx
@@ -46,26 +46,26 @@ CellLineStylePopup::CellLineStylePopup(weld::Toolbar* 
pParent, const OUString& r
     mxCellLineStyleValueSet->SetStyle(mxCellLineStyleValueSet->GetStyle()| 
WB_3DLOOK |  WB_NO_DIRECTSELECT);
 
     const vcl::I18nHelper& rI18nHelper = 
Application::GetSettings().GetLocaleI18nHelper();
-    OUString aStr[CELL_LINE_STYLE_ENTRIES];
-    aStr[0] = ScResId(STR_BORDER_HAIRLINE).replaceFirst("%s", 
rI18nHelper.GetNum(5, 2));
-    aStr[1] = ScResId(STR_BORDER_VERY_THIN).replaceFirst("%s", 
rI18nHelper.GetNum(50, 2));
-    aStr[2] = ScResId(STR_BORDER_THIN).replaceFirst("%s", 
rI18nHelper.GetNum(75, 2));
-    aStr[3] = ScResId(STR_BORDER_MEDIUM).replaceFirst("%s", 
rI18nHelper.GetNum(150, 2));
-    aStr[4] = ScResId(STR_BORDER_THICK).replaceFirst("%s", 
rI18nHelper.GetNum(225, 2));
-    aStr[5] = ScResId(STR_BORDER_EXTRA_THICK).replaceFirst("%s", 
rI18nHelper.GetNum(450, 2));
-
-    // Numbers in pt are the total width of the double line (inner + outer + 
distance)
-    aStr[6] = ScResId(STR_BORDER_DOUBLE_1).replaceFirst("%s", 
rI18nHelper.GetNum(110, 2));
-    aStr[7] = ScResId(STR_BORDER_DOUBLE_1).replaceFirst("%s", 
rI18nHelper.GetNum(235, 2));
-    aStr[8] = ScResId(STR_BORDER_DOUBLE_2).replaceFirst("%s", 
rI18nHelper.GetNum(300, 2));
-    aStr[9] = ScResId(STR_BORDER_DOUBLE_3).replaceFirst("%s", 
rI18nHelper.GetNum(305, 2));
-    aStr[10] = ScResId(STR_BORDER_DOUBLE_4).replaceFirst("%s", 
rI18nHelper.GetNum(450, 2));
-    mxCellLineStyleValueSet->SetUnit(&aStr[0]);
-
-    for (sal_uInt16 i = 1; i <= CELL_LINE_STYLE_ENTRIES; ++i)
+    const std::vector<OUString> aStrings = {
+        ScResId(STR_BORDER_HAIRLINE).replaceFirst("%s", rI18nHelper.GetNum(5, 
2)),
+        ScResId(STR_BORDER_VERY_THIN).replaceFirst("%s", 
rI18nHelper.GetNum(50, 2)),
+        ScResId(STR_BORDER_THIN).replaceFirst("%s", rI18nHelper.GetNum(75, 2)),
+        ScResId(STR_BORDER_MEDIUM).replaceFirst("%s", rI18nHelper.GetNum(150, 
2)),
+        ScResId(STR_BORDER_THICK).replaceFirst("%s", rI18nHelper.GetNum(225, 
2)),
+        ScResId(STR_BORDER_EXTRA_THICK).replaceFirst("%s", 
rI18nHelper.GetNum(450, 2)),
+        // Numbers in pt are the total width of the double line (inner + outer 
+ distance)
+        ScResId(STR_BORDER_DOUBLE_1).replaceFirst("%s", 
rI18nHelper.GetNum(110, 2)),
+        ScResId(STR_BORDER_DOUBLE_1).replaceFirst("%s", 
rI18nHelper.GetNum(235, 2)),
+        ScResId(STR_BORDER_DOUBLE_2).replaceFirst("%s", 
rI18nHelper.GetNum(300, 2)),
+        ScResId(STR_BORDER_DOUBLE_3).replaceFirst("%s", 
rI18nHelper.GetNum(305, 2)),
+        ScResId(STR_BORDER_DOUBLE_4).replaceFirst("%s", 
rI18nHelper.GetNum(450, 2))
+    };
+    mxCellLineStyleValueSet->SetUnit(aStrings);
+
+    for (size_t i = 1; i <= aStrings.size(); ++i)
     {
         mxCellLineStyleValueSet->InsertItem(i);
-        mxCellLineStyleValueSet->SetItemText(i, aStr[i-1]);
+        mxCellLineStyleValueSet->SetItemText(i, aStrings.at(i-1));
     }
 
     SetAllNoSel();
diff --git a/sc/source/ui/sidebar/CellLineStyleValueSet.cxx 
b/sc/source/ui/sidebar/CellLineStyleValueSet.cxx
index b147948a3060..91992313399f 100644
--- a/sc/source/ui/sidebar/CellLineStyleValueSet.cxx
+++ b/sc/source/ui/sidebar/CellLineStyleValueSet.cxx
@@ -49,12 +49,10 @@ void 
CellLineStyleValueSet::SetDrawingArea(weld::DrawingArea* pDrawingArea)
     
SetColor(Application::GetSettings().GetStyleSettings().GetListBoxWindowBackgroundColor());
 }
 
-void CellLineStyleValueSet::SetUnit(const OUString* str)
+void CellLineStyleValueSet::SetUnit(const std::vector<OUString>& rStrings)
 {
-    for (int i = 0; i < CELL_LINE_STYLE_ENTRIES; ++i)
-    {
-        maStrUnit[i] = str[i];
-    }
+    assert(rStrings.size() == CELL_LINE_STYLE_ENTRIES);
+    maStrUnit = rStrings;
 }
 
 void CellLineStyleValueSet::SetSelItem(sal_uInt16 nSel)
@@ -77,9 +75,9 @@ tools::Long CellLineStyleValueSet::GetMaxTextWidth(const 
vcl::RenderContext* pDe
     if (mnMaxTextWidth > 0)
         return mnMaxTextWidth;
 
-    for (int i = 0; i < CELL_LINE_STYLE_ENTRIES; ++i)
+    for (const OUString& rStr : maStrUnit)
     {
-        mnMaxTextWidth = std::max(pDev->GetTextWidth(maStrUnit[i]), 
mnMaxTextWidth);
+        mnMaxTextWidth = std::max(pDev->GetTextWidth(rStr), mnMaxTextWidth);
     }
     return mnMaxTextWidth;
 }
@@ -123,7 +121,7 @@ void CellLineStyleValueSet::UserDraw( const UserDrawEvent& 
rUDEvt )
     tools::Long nTLX = aBLPos.X() + 5,  nTLY = aBLPos.Y() + ( nRectHeight - 
nItemId )/2;
     tools::Long nTRX = aBLPos.X() + nRectWidth - nTextWidth - 15, nTRY = 
aBLPos.Y() + ( nRectHeight - nItemId )/2;
     Point aStart(aBLPos.X() + nRectWidth - nTextWidth - 5 , aBLPos.Y() + 
nRectHeight/6);
-    pDev->DrawText(aStart, maStrUnit[nItemId - 1]); //can't set 
DrawTextFlags::EndEllipsis here, or the text will disappear
+    pDev->DrawText(aStart, maStrUnit.at(nItemId - 1)); //can't set 
DrawTextFlags::EndEllipsis here, or the text will disappear
 
     //draw line
     if( nSelItem ==  nItemId )
diff --git a/sc/source/ui/sidebar/CellLineStyleValueSet.hxx 
b/sc/source/ui/sidebar/CellLineStyleValueSet.hxx
index 79dd08fb3960..eae1c1fbf457 100644
--- a/sc/source/ui/sidebar/CellLineStyleValueSet.hxx
+++ b/sc/source/ui/sidebar/CellLineStyleValueSet.hxx
@@ -30,13 +30,13 @@ class CellLineStyleValueSet : public ValueSet
 private:
     tools::Long mnMaxTextWidth;
     sal_uInt16 nSelItem;
-    OUString maStrUnit[CELL_LINE_STYLE_ENTRIES];
+    std::vector<OUString> maStrUnit;
 
 public:
     CellLineStyleValueSet();
     virtual ~CellLineStyleValueSet() override;
 
-    void SetUnit(const OUString* str);
+    void SetUnit(const std::vector<OUString>& rStrings);
     void SetSelItem(sal_uInt16 nSel);
     tools::Long GetMaxTextWidth(const vcl::RenderContext* pDev);
     virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
commit 19f61c10023a4197aad62e8790f92c60b587cb74
Author:     Michael Weghorn <[email protected]>
AuthorDate: Fri Nov 28 10:21:09 2025 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Sat Nov 29 06:52:08 2025 +0100

    sc: Merge two loops into one
    
    Change-Id: If8ce0d0790571f207afe7f6c25529c55acffb663
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194764
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/sc/source/ui/sidebar/CellLineStyleControl.cxx 
b/sc/source/ui/sidebar/CellLineStyleControl.cxx
index 767ae307979c..d93b8cf70436 100644
--- a/sc/source/ui/sidebar/CellLineStyleControl.cxx
+++ b/sc/source/ui/sidebar/CellLineStyleControl.cxx
@@ -45,11 +45,6 @@ CellLineStylePopup::CellLineStylePopup(weld::Toolbar* 
pParent, const OUString& r
 
     mxCellLineStyleValueSet->SetStyle(mxCellLineStyleValueSet->GetStyle()| 
WB_3DLOOK |  WB_NO_DIRECTSELECT);
 
-    for(sal_uInt16 i = 1 ; i <= CELL_LINE_STYLE_ENTRIES ; i++)
-    {
-        mxCellLineStyleValueSet->InsertItem(i);
-    }
-
     const vcl::I18nHelper& rI18nHelper = 
Application::GetSettings().GetLocaleI18nHelper();
     OUString aStr[CELL_LINE_STYLE_ENTRIES];
     aStr[0] = ScResId(STR_BORDER_HAIRLINE).replaceFirst("%s", 
rI18nHelper.GetNum(5, 2));
@@ -69,6 +64,7 @@ CellLineStylePopup::CellLineStylePopup(weld::Toolbar* 
pParent, const OUString& r
 
     for (sal_uInt16 i = 1; i <= CELL_LINE_STYLE_ENTRIES; ++i)
     {
+        mxCellLineStyleValueSet->InsertItem(i);
         mxCellLineStyleValueSet->SetItemText(i, aStr[i-1]);
     }
 

Reply via email to