sc/inc/strings.hrc                             |   10 +++
 sc/source/ui/sidebar/CellLineStyleControl.cxx  |   71 +++++++++++++++----------
 sc/source/ui/sidebar/CellLineStyleValueSet.cxx |   32 ++++++++---
 sc/source/ui/sidebar/CellLineStyleValueSet.hxx |    5 +
 4 files changed, 83 insertions(+), 35 deletions(-)

New commits:
commit cd116a1b6775777f393990cc3419733164dee52f
Author:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
AuthorDate: Thu Nov 4 11:34:22 2021 +0100
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
CommitDate: Mon Nov 8 10:42:59 2021 +0100

    tdf#48622 Adapt sidebar line styles to new defaults
    
    Change-Id: I81287d90c2250838391fa79d2f6455219ea822c8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124680
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>

diff --git a/sc/inc/strings.hrc b/sc/inc/strings.hrc
index 7204a16eb1b6..ff7094dae69f 100644
--- a/sc/inc/strings.hrc
+++ b/sc/inc/strings.hrc
@@ -365,5 +365,15 @@
 #define STR_NO_USER_DATA_AVAILABLE                  
NC_("sharedocumentdlg|nouserdata", "No user data available.")
 #define STR_EXCLUSIVE_ACCESS                        
NC_("sharedocumentdlg|exclusive", "(exclusive access)")
 #define STR_NO_NAMED_RANGES_AVAILABLE               
NC_("STR_NO_NAMED_RANGES_AVAILABLE", "No named ranges available in the selected 
document")
+#define STR_BORDER_HAIRLINE                         NC_("STR_BORDER_HAIRLINE", 
"Hairline (%s pt)")
+#define STR_BORDER_VERY_THIN                        
NC_("STR_BORDER_VERY_THIN", "Very thin (%s pt)")
+#define STR_BORDER_THIN                             NC_("STR_BORDER_THIN", 
"Thin (%s pt)")
+#define STR_BORDER_MEDIUM                           NC_("STR_BORDER_MEDIUM", 
"Medium (%s pt)")
+#define STR_BORDER_THICK                            NC_("STR_BORDER_THICK", 
"Thick (%s pt)")
+#define STR_BORDER_EXTRA_THICK                      
NC_("STR_BORDER_EXTRA_THICK", "Extra thick (%s pt)")
+#define STR_BORDER_DOUBLE_1                         NC_("STR_BORDER_DOUBLE_1", 
"Double Hairline (%s pt)")
+#define STR_BORDER_DOUBLE_2                         NC_("STR_BORDER_DOUBLE_2", 
"Thin/Medium (%s pt)")
+#define STR_BORDER_DOUBLE_3                         NC_("STR_BORDER_DOUBLE_3", 
"Medium/Hairline (%s pt)")
+#define STR_BORDER_DOUBLE_4                         NC_("STR_BORDER_DOUBLE_4", 
"Medium/Medium (%s pt)")
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/sidebar/CellLineStyleControl.cxx 
b/sc/source/ui/sidebar/CellLineStyleControl.cxx
index 2f7e255f5eaf..5c27ee5a51b1 100644
--- a/sc/source/ui/sidebar/CellLineStyleControl.cxx
+++ b/sc/source/ui/sidebar/CellLineStyleControl.cxx
@@ -27,6 +27,8 @@
 #include <sfx2/bindings.hxx>
 #include <sfx2/dispatch.hxx>
 #include <svx/svxids.hrc>
+#include <scresid.hxx>
+#include <strings.hrc>
 
 namespace sc::sidebar {
 
@@ -51,22 +53,25 @@ void CellLineStylePopup::Initialize()
 
     mxCellLineStyleValueSet->SetStyle(mxCellLineStyleValueSet->GetStyle()| 
WB_3DLOOK |  WB_NO_DIRECTSELECT);
 
-    for(sal_uInt16 i = 1 ; i <= 9 ; i++)
+    for(sal_uInt16 i = 1 ; i <= CELL_LINE_STYLE_ENTRIES ; i++)
     {
         mxCellLineStyleValueSet->InsertItem(i);
     }
 
-
     const vcl::I18nHelper& rI18nHelper = 
Application::GetSettings().GetLocaleI18nHelper();
-    maStr[0] = rI18nHelper.GetNum( 5, 2 ) + "pt";
-    maStr[1] = rI18nHelper.GetNum( 250, 2 ) + "pt";
-    maStr[2] = rI18nHelper.GetNum( 400, 2 ) + "pt";
-    maStr[3] = rI18nHelper.GetNum( 500, 2 ) + "pt";
-    maStr[4] = rI18nHelper.GetNum( 110, 2 ) + "pt";
-    maStr[5] = rI18nHelper.GetNum( 260, 2 ) + "pt";
-    maStr[6] = rI18nHelper.GetNum( 450, 2 ) + "pt";
-    maStr[7] = rI18nHelper.GetNum( 505, 2 ) + "pt";
-    maStr[8] = rI18nHelper.GetNum( 750, 2 ) + "pt";
+    maStr[0] = ScResId(STR_BORDER_HAIRLINE).replaceFirst("%s", 
rI18nHelper.GetNum(5, 2));
+    maStr[1] = ScResId(STR_BORDER_VERY_THIN).replaceFirst("%s", 
rI18nHelper.GetNum(50, 2));
+    maStr[2] = ScResId(STR_BORDER_THIN).replaceFirst("%s", 
rI18nHelper.GetNum(75, 2));
+    maStr[3] = ScResId(STR_BORDER_MEDIUM).replaceFirst("%s", 
rI18nHelper.GetNum(150, 2));
+    maStr[4] = ScResId(STR_BORDER_THICK).replaceFirst("%s", 
rI18nHelper.GetNum(225, 2));
+    maStr[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)
+    maStr[6] = ScResId(STR_BORDER_DOUBLE_1).replaceFirst("%s", 
rI18nHelper.GetNum(110, 2));
+    maStr[7] = ScResId(STR_BORDER_DOUBLE_1).replaceFirst("%s", 
rI18nHelper.GetNum(235, 2));
+    maStr[8] = ScResId(STR_BORDER_DOUBLE_2).replaceFirst("%s", 
rI18nHelper.GetNum(300, 2));
+    maStr[9] = ScResId(STR_BORDER_DOUBLE_3).replaceFirst("%s", 
rI18nHelper.GetNum(305, 2));
+    maStr[10] = ScResId(STR_BORDER_DOUBLE_4).replaceFirst("%s", 
rI18nHelper.GetNum(450, 2));
     mxCellLineStyleValueSet->SetUnit(&maStr[0]);
 
     for (sal_uInt16 i = 1; i <= CELL_LINE_STYLE_ENTRIES; ++i)
@@ -108,39 +113,45 @@ IMPL_LINK_NOARG(CellLineStylePopup, VSSelectHdl, 
ValueSet*, void)
             n1 = SvxBorderLineWidth::Hairline;
             break;
         case 2:
-            n1 = SvxBorderLineWidth::Medium;
+            n1 = SvxBorderLineWidth::VeryThin;
             break;
         case 3:
-            n1 = SvxBorderLineWidth::Thick;
+            n1 = SvxBorderLineWidth::Thin;
             break;
         case 4:
-            n1 = SvxBorderLineWidth::ExtraThick;
+            n1 = SvxBorderLineWidth::Medium;
             break;
         case 5:
+            n1 = SvxBorderLineWidth::Thick;
+            break;
+        case 6:
+            n1 = SvxBorderLineWidth::ExtraThick;
+            break;
+        case 7:
             n1 = SvxBorderLineWidth::Hairline;
             n2 = SvxBorderLineWidth::Hairline;
             n3 = SvxBorderLineWidth::Medium;
             nStyle = SvxBorderLineStyle::DOUBLE;
             break;
-        case 6:
+        case 8:
             n1 = SvxBorderLineWidth::Hairline;
             n2 = SvxBorderLineWidth::Hairline;
             n3 = SvxBorderLineWidth::Thick;
             nStyle = SvxBorderLineStyle::DOUBLE;
             break;
-        case 7:
+        case 9:
             n1 = SvxBorderLineWidth::Thin;
             n2 = SvxBorderLineWidth::Medium;
             n3 = SvxBorderLineWidth::Thin;
             nStyle = SvxBorderLineStyle::DOUBLE;
             break;
-        case 8:
+        case 10:
             n1 = SvxBorderLineWidth::Medium;
             n2 = SvxBorderLineWidth::Hairline;
             n3 = SvxBorderLineWidth::Medium;
             nStyle = SvxBorderLineStyle::DOUBLE;
             break;
-        case 9:
+        case 11:
             n1 = SvxBorderLineWidth::Medium;
             n2 = SvxBorderLineWidth::Medium;
             n3 = SvxBorderLineWidth::Medium;
@@ -177,38 +188,46 @@ void CellLineStylePopup::SetLineStyleSelect(sal_uInt16 
out, sal_uInt16 in, sal_u
     {
         mxCellLineStyleValueSet->SetSelItem(1);
     }
-    else if(out == SvxBorderLineWidth::Medium && in == 0 && dis == 0) //2
+    else if(out == SvxBorderLineWidth::VeryThin && in == 0 && dis == 0) //2
     {
         mxCellLineStyleValueSet->SetSelItem(2);
     }
-    else if(out == SvxBorderLineWidth::Thick && in == 0 && dis == 0) //3
+    else if(out == SvxBorderLineWidth::Thin && in == 0 && dis == 0) //3
     {
         mxCellLineStyleValueSet->SetSelItem(3);
     }
-    else if(out == SvxBorderLineWidth::ExtraThick && in == 0 && dis == 0) //4
+    else if(out == SvxBorderLineWidth::Medium && in == 0 && dis == 0) //4
     {
         mxCellLineStyleValueSet->SetSelItem(4);
     }
-    else if(out == SvxBorderLineWidth::Hairline && in == 
SvxBorderLineWidth::Hairline && dis == SvxBorderLineWidth::Thin) //5
+    else if(out == SvxBorderLineWidth::Thick && in == 0 && dis == 0) //5
     {
         mxCellLineStyleValueSet->SetSelItem(5);
     }
-    else if(out == SvxBorderLineWidth::Hairline && in == 
SvxBorderLineWidth::Hairline && dis == SvxBorderLineWidth::Medium) //6
+    else if(out == SvxBorderLineWidth::ExtraThick && in == 0 && dis == 0) //6
     {
         mxCellLineStyleValueSet->SetSelItem(6);
     }
-    else if(out == SvxBorderLineWidth::Thin && in == 
SvxBorderLineWidth::Medium && dis == SvxBorderLineWidth::Thin) //7
+    else if(out == SvxBorderLineWidth::Hairline && in == 
SvxBorderLineWidth::Hairline && dis == SvxBorderLineWidth::Thin) //7
     {
         mxCellLineStyleValueSet->SetSelItem(7);
     }
-    else if(out == SvxBorderLineWidth::Medium && in == 
SvxBorderLineWidth::Hairline && dis == SvxBorderLineWidth::Medium) //8
+    else if(out == SvxBorderLineWidth::Hairline && in == 
SvxBorderLineWidth::Hairline && dis == SvxBorderLineWidth::Medium) //8
     {
         mxCellLineStyleValueSet->SetSelItem(8);
     }
-    else if(out == SvxBorderLineWidth::Medium && in == 
SvxBorderLineWidth::Medium && dis == SvxBorderLineWidth::Medium) //9
+    else if(out == SvxBorderLineWidth::Thin && in == 
SvxBorderLineWidth::Medium && dis == SvxBorderLineWidth::Thin) //9
     {
         mxCellLineStyleValueSet->SetSelItem(9);
     }
+    else if(out == SvxBorderLineWidth::Medium && in == 
SvxBorderLineWidth::Hairline && dis == SvxBorderLineWidth::Medium) //10
+    {
+        mxCellLineStyleValueSet->SetSelItem(10);
+    }
+    else if(out == SvxBorderLineWidth::Medium && in == 
SvxBorderLineWidth::Medium && dis == SvxBorderLineWidth::Medium) //11
+    {
+        mxCellLineStyleValueSet->SetSelItem(11);
+    }
 
     else
     {
diff --git a/sc/source/ui/sidebar/CellLineStyleValueSet.cxx 
b/sc/source/ui/sidebar/CellLineStyleValueSet.cxx
index c993f59a2a41..11eb55723745 100644
--- a/sc/source/ui/sidebar/CellLineStyleValueSet.cxx
+++ b/sc/source/ui/sidebar/CellLineStyleValueSet.cxx
@@ -27,6 +27,7 @@ namespace sc::sidebar {
 
 CellLineStyleValueSet::CellLineStyleValueSet()
     : ValueSet(nullptr)
+    , mnMaxTextWidth(0)
     , nSelItem(0)
 {
 }
@@ -38,12 +39,13 @@ CellLineStyleValueSet::~CellLineStyleValueSet()
 void CellLineStyleValueSet::SetDrawingArea(weld::DrawingArea* pDrawingArea)
 {
     ValueSet::SetDrawingArea(pDrawingArea);
-    Size aSize = pDrawingArea->get_ref_device().LogicToPixel(Size(80, 12 * 9), 
MapMode(MapUnit::MapAppFont));
+    Size aSize = pDrawingArea->get_ref_device().LogicToPixel(Size(120, 12 * 
CELL_LINE_STYLE_ENTRIES),
+                                                             
MapMode(MapUnit::MapAppFont));
     pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
     SetOutputSizePixel(aSize);
 
     SetColCount();
-    SetLineCount( 9);
+    SetLineCount(CELL_LINE_STYLE_ENTRIES);
 }
 
 void CellLineStyleValueSet::SetUnit(const OUString* str)
@@ -69,6 +71,18 @@ void CellLineStyleValueSet::SetSelItem(sal_uInt16 nSel)
     }
 }
 
+tools::Long CellLineStyleValueSet::GetMaxTextWidth(vcl::RenderContext* pDev)
+{
+    if (mnMaxTextWidth > 0)
+        return mnMaxTextWidth;
+
+    for (int i = 0; i < CELL_LINE_STYLE_ENTRIES; ++i)
+    {
+        mnMaxTextWidth = std::max(pDev->GetTextWidth(maStrUnit[i]), 
mnMaxTextWidth);
+    }
+    return mnMaxTextWidth;
+}
+
 void CellLineStyleValueSet::UserDraw( const UserDrawEvent& rUDEvt )
 {
     tools::Rectangle aRect = rUDEvt.GetRect();
@@ -111,7 +125,7 @@ void CellLineStyleValueSet::UserDraw( const UserDrawEvent& 
rUDEvt )
         aFont.SetColor(rStyleSettings.GetFieldTextColor()); //high contrast
 
     pDev->SetFont(aFont);
-    tools::Long nTextWidth = pDev->GetTextWidth(maStrUnit[nItemId - 1]);
+    tools::Long nTextWidth = GetMaxTextWidth(pDev);
     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);
@@ -135,25 +149,27 @@ void CellLineStyleValueSet::UserDraw( const 
UserDrawEvent& rUDEvt )
         case 2:
         case 3:
         case 4:
+        case 5:
+        case 6:
             pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + nItemId 
* 2 - 1 ));
             break;
-        case 5:
+        case 7:
             pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
             pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 3 , nTRX, nTRY + 4 ));
             break;
-        case 6:
+        case 8:
             pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
             pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 6 ));
             break;
-        case 7:
+        case 9:
             pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
             pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 3 , nTRX, nTRY + 6 ));
             break;
-        case 8:
+        case 10:
             pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 3 ));
             pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 6 ));
             break;
-        case 9:
+        case 11:
             pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 3 ));
             pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 8 ));
             break;
diff --git a/sc/source/ui/sidebar/CellLineStyleValueSet.hxx 
b/sc/source/ui/sidebar/CellLineStyleValueSet.hxx
index b730c687e98e..5ab78f0137ff 100644
--- a/sc/source/ui/sidebar/CellLineStyleValueSet.hxx
+++ b/sc/source/ui/sidebar/CellLineStyleValueSet.hxx
@@ -19,14 +19,16 @@
 #pragma once
 
 #include <svtools/valueset.hxx>
+#include <tools/long.hxx>
 
-#define CELL_LINE_STYLE_ENTRIES 9
+#define CELL_LINE_STYLE_ENTRIES 11
 
 namespace sc::sidebar
 {
 class CellLineStyleValueSet : public ValueSet
 {
 private:
+    tools::Long mnMaxTextWidth;
     sal_uInt16 nSelItem;
     OUString maStrUnit[CELL_LINE_STYLE_ENTRIES];
 
@@ -36,6 +38,7 @@ public:
 
     void SetUnit(const OUString* str);
     void SetSelItem(sal_uInt16 nSel);
+    tools::Long GetMaxTextWidth(vcl::RenderContext* pDev);
     virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
     virtual void UserDraw(const UserDrawEvent& rUDEvt) override;
 };

Reply via email to