cui/source/inc/border.hxx | 1 - cui/source/tabpages/border.cxx | 34 +++++++++++++++------------------- include/editeng/borderline.hxx | 15 +++++++-------- 3 files changed, 22 insertions(+), 28 deletions(-)
New commits: commit c78861094f57198f4cd7117a85a5915358742209 Author: Mike Kaganski <[email protected]> AuthorDate: Sun Oct 8 13:14:11 2023 +0300 Commit: Mike Kaganski <[email protected]> CommitDate: Sun Oct 8 15:46:02 2023 +0200 Simplify a bit Change-Id: Icfa6d5bdc3c1a9e13f7e29d36a4a873a5c6bb05c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157684 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/cui/source/inc/border.hxx b/cui/source/inc/border.hxx index 586b05f9410b..accb555930dc 100644 --- a/cui/source/inc/border.hxx +++ b/cui/source/inc/border.hxx @@ -77,7 +77,6 @@ private: class SvxBorderTabPage : public SfxTabPage { static const WhichRangesContainer pRanges; - static const std::vector<int> m_aLineWidths; public: SvxBorderTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreAttrs); diff --git a/cui/source/tabpages/border.cxx b/cui/source/tabpages/border.cxx index 549ab533410a..ca2b7d61e2ef 100644 --- a/cui/source/tabpages/border.cxx +++ b/cui/source/tabpages/border.cxx @@ -78,22 +78,19 @@ const WhichRangesContainer SvxBorderTabPage::pRanges( namespace { -int lcl_twipsToPt(sal_Int64 nTwips) +constexpr int twipsToPt100(sal_Int64 nTwips) { - return vcl::ConvertDoubleValue(nTwips, 0, FieldUnit::TWIP, MapUnit::MapPoint) * 100; + return o3tl::convert(nTwips * 100, o3tl::Length::twip, o3tl::Length::pt); } +constexpr int s_LineWidths[] = { twipsToPt100(SvxBorderLineWidth::Hairline), + twipsToPt100(SvxBorderLineWidth::VeryThin), + twipsToPt100(SvxBorderLineWidth::Thin), + twipsToPt100(SvxBorderLineWidth::Medium), + twipsToPt100(SvxBorderLineWidth::Thick), + twipsToPt100(SvxBorderLineWidth::ExtraThick), + -1 }; } -const std::vector<int> SvxBorderTabPage::m_aLineWidths = { - lcl_twipsToPt(SvxBorderLineWidth::Hairline), - lcl_twipsToPt(SvxBorderLineWidth::VeryThin), - lcl_twipsToPt(SvxBorderLineWidth::Thin), - lcl_twipsToPt(SvxBorderLineWidth::Medium), - lcl_twipsToPt(SvxBorderLineWidth::Thick), - lcl_twipsToPt(SvxBorderLineWidth::ExtraThick), - -1 -}; - static void lcl_SetDecimalDigitsTo1(weld::MetricSpinButton& rField) { auto nMin = rField.denormalize(rField.get_min(FieldUnit::TWIP)); @@ -1243,10 +1240,10 @@ IMPL_LINK_NOARG(SvxBorderTabPage, ModifyWidthLBHdl_Impl, weld::ComboBox&, void) sal_Int32 nPos = m_xLineWidthLB->get_active(); sal_Int32 nRemovedType = 0; if (m_xLineWidthLB->get_values_changed_from_saved()) { - nRemovedType = m_aLineWidths.size() - m_xLineWidthLB->get_count(); + nRemovedType = std::size(s_LineWidths) - m_xLineWidthLB->get_count(); } - SetLineWidth(m_aLineWidths[nPos + nRemovedType], nRemovedType); + SetLineWidth(s_LineWidths[nPos + nRemovedType], nRemovedType); // Call the spinner handler to trigger all related modifications ModifyWidthMFHdl_Impl(*m_xLineWidthMF); @@ -1462,19 +1459,18 @@ void SvxBorderTabPage::SetLineWidth( sal_Int64 nWidth, sal_Int32 nRemovedType ) if ( nWidth >= 0 ) m_xLineWidthMF->set_value( nWidth, FieldUnit::POINT ); - auto it = std::find_if( m_aLineWidths.begin(), m_aLineWidths.end(), - [nWidth](const int val) -> bool { return val == nWidth; } ); + auto it = std::find( std::begin(s_LineWidths), std::end(s_LineWidths), nWidth ); - if ( it != m_aLineWidths.end() && *it >= 0 ) + if ( it != std::end(s_LineWidths) && *it >= 0 ) { // Select predefined value in combobox m_xLineWidthMF->hide(); - m_xLineWidthLB->set_active(std::distance(m_aLineWidths.begin(), it) - nRemovedType); + m_xLineWidthLB->set_active(std::distance(std::begin(s_LineWidths), it) - nRemovedType); } else { // This is not one of predefined values. Show spinner - m_xLineWidthLB->set_active(m_aLineWidths.size() - nRemovedType -1); + m_xLineWidthLB->set_active(std::size(s_LineWidths) - nRemovedType -1); m_xLineWidthMF->show(); } } diff --git a/include/editeng/borderline.hxx b/include/editeng/borderline.hxx index 596b8b59f413..851c16156dee 100644 --- a/include/editeng/borderline.hxx +++ b/include/editeng/borderline.hxx @@ -34,15 +34,14 @@ class IntlWrapper; // Line width defaults in twips // Thin matches Excel's default values // See tdf#48622 for the discussion leading to these defaults. -class SvxBorderLineWidth +namespace SvxBorderLineWidth { -public: - static const sal_Int16 Hairline = 1; // 0.05pt - static const sal_Int16 VeryThin = 10; // 0.5pt - static const sal_Int16 Thin = 15; // 0.75pt - static const sal_Int16 Medium = 30; // 1.5pt - static const sal_Int16 Thick = 45; // 2.25pt - static const sal_Int16 ExtraThick = 90; // 4.5pt +constexpr inline sal_Int16 Hairline = 1; // 0.05pt +constexpr inline sal_Int16 VeryThin = 10; // 0.5pt +constexpr inline sal_Int16 Thin = 15; // 0.75pt +constexpr inline sal_Int16 Medium = 30; // 1.5pt +constexpr inline sal_Int16 Thick = 45; // 2.25pt +constexpr inline sal_Int16 ExtraThick = 90; // 4.5pt }; // Abstracts over values from css::table::BorderLineStyle
