sw/source/uibase/inc/prcntfld.hxx | 2 -- sw/source/uibase/utlui/prcntfld.cxx | 36 ++++++++---------------------------- 2 files changed, 8 insertions(+), 30 deletions(-)
New commits: commit 8d09c7badc6a12919a622126c87dc0fab32ca645 Author: Justin Luth <[email protected]> AuthorDate: Wed Nov 12 10:12:57 2025 -0500 Commit: Justin Luth <[email protected]> CommitDate: Thu Nov 13 15:02:53 2025 +0100 NFC cleanup after tdf#169219: value may be changed even if % isn't Avoided formatting changes in the logic-changing patch Change-Id: If5df5571056fc3032058d0e6171d164a7cb2b618 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193887 Tested-by: Jenkins Reviewed-by: Justin Luth <[email protected]> diff --git a/sw/source/uibase/utlui/prcntfld.cxx b/sw/source/uibase/utlui/prcntfld.cxx index 087fd76db4d4..a7f868397331 100644 --- a/sw/source/uibase/utlui/prcntfld.cxx +++ b/sw/source/uibase/utlui/prcntfld.cxx @@ -59,11 +59,9 @@ void SwPercentField::ShowPercent(bool bPercent, sal_uInt16 nMaxPercent) || (!bPercent && m_pField->get_unit() != FieldUnit::PERCENT)) return; - sal_Int64 nOldValue; - if (bPercent) { - nOldValue = get_value(); + sal_Int64 nOldValue = get_value(); m_eOldUnit = m_pField->get_unit(); m_nOldDigits = m_pField->get_digits(); @@ -81,26 +79,22 @@ void SwPercentField::ShowPercent(bool bPercent, sal_uInt16 nMaxPercent) m_pField->set_range(std::max(1, nPercent), nMaxPercent, FieldUnit::NONE); m_pField->set_increments(5, 10, FieldUnit::NONE); - { - nCurrentWidth - = vcl::ConvertValue(nOldValue, 0, m_nOldDigits, m_eOldUnit, FieldUnit::TWIP); - nCurrentWidth = UpscaleTwoDecimalPlaces(nCurrentWidth, m_nOldDigits); - nPercent = m_nRefValue ? (((nCurrentWidth * 10) / m_nRefValue + 5) / 10) : 0; - m_pField->set_value(nPercent, FieldUnit::NONE); - } + + nCurrentWidth = vcl::ConvertValue(nOldValue, 0, m_nOldDigits, m_eOldUnit, FieldUnit::TWIP); + nCurrentWidth = UpscaleTwoDecimalPlaces(nCurrentWidth, m_nOldDigits); + nPercent = m_nRefValue ? (((nCurrentWidth * 10) / m_nRefValue + 5) / 10) : 0; + m_pField->set_value(nPercent, FieldUnit::NONE); } else { - nOldValue = Convert(get_value(), m_pField->get_unit(), m_eOldUnit); + const sal_Int64 nValue = Convert(get_value(), m_pField->get_unit(), m_eOldUnit); m_pField->set_unit(m_eOldUnit); m_pField->set_digits(m_nOldDigits); m_pField->set_range(m_nOldMin, m_nOldMax, FieldUnit::NONE); m_pField->set_increments(m_nOldSpinSize, m_nOldPageSize, FieldUnit::NONE); - { - set_value(nOldValue, m_eOldUnit); - } + set_value(nValue, m_eOldUnit); } } commit 7c2f02497ccc026ccaf48fc3b0b109b78c93c592 Author: Justin Luth <[email protected]> AuthorDate: Wed Nov 12 10:04:53 2025 -0500 Commit: Justin Luth <[email protected]> CommitDate: Thu Nov 13 15:02:45 2025 +0100 tdf#169219 swrelpagesize ui: value may be changed even if % isn't Toggling "show percent" off was displaying the previous value if the percentage hadn't changed. However, the underlying m_nRefValue might have changed (like from 'Entire Page' to 'Entire Paragraph') and so even though the percentage might have remained unchanged (100%) the width represented by 100% would be different, so it is not legitimate to just 'show the value from last time'. The same logic would hold true for percentage with an unchanged width. The steps-to-reproduce depend on previous patches for this bug report. -open image properties. Set to 100% relative to Entire Page -toggle off showing percent: shows something like 4.1 inches -toggle on percent (100), and change relative to para, set back to 100% -toggle off showing percent: should show 2.5 inches, not 4... This has been in the code since initial implementation: commit 2ecf108c23c041619bb8b25338dca84ff89fe8eb Author: Caolán McNamara on Thu Dec 20 11:58:29 2012 +0000 make a PercentFieldWrap that wraps a MetricField Change-Id: If2e1761cd170ffffb6b99414e717001be0fadd59 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193886 Reviewed-by: Justin Luth <[email protected]> Tested-by: Jenkins diff --git a/sw/source/uibase/inc/prcntfld.hxx b/sw/source/uibase/inc/prcntfld.hxx index 401292970d43..918291d497f5 100644 --- a/sw/source/uibase/inc/prcntfld.hxx +++ b/sw/source/uibase/inc/prcntfld.hxx @@ -31,8 +31,6 @@ class SW_DLLPUBLIC SwPercentField sal_Int64 m_nOldMin; sal_Int64 m_nOldSpinSize; sal_Int64 m_nOldPageSize; - sal_Int64 m_nLastPercent; - sal_Int64 m_nLastValue; sal_uInt16 m_nOldDigits; FieldUnit m_eOldUnit; bool m_bLockAutoCalculation; //prevent recalculation of percent values when the diff --git a/sw/source/uibase/utlui/prcntfld.cxx b/sw/source/uibase/utlui/prcntfld.cxx index aa57a09d4c93..087fd76db4d4 100644 --- a/sw/source/uibase/utlui/prcntfld.cxx +++ b/sw/source/uibase/utlui/prcntfld.cxx @@ -24,8 +24,6 @@ SwPercentField::SwPercentField(std::unique_ptr<weld::MetricSpinButton> pControl) : m_pField(std::move(pControl)) , m_nOldMax(0) , m_nOldMin(0) - , m_nLastPercent(-1) - , m_nLastValue(-1) , m_nOldDigits(m_pField->get_digits()) , m_eOldUnit(FieldUnit::NONE) , m_bLockAutoCalculation(false) @@ -83,23 +81,16 @@ void SwPercentField::ShowPercent(bool bPercent, sal_uInt16 nMaxPercent) m_pField->set_range(std::max(1, nPercent), nMaxPercent, FieldUnit::NONE); m_pField->set_increments(5, 10, FieldUnit::NONE); - if (nOldValue != m_nLastValue) { nCurrentWidth = vcl::ConvertValue(nOldValue, 0, m_nOldDigits, m_eOldUnit, FieldUnit::TWIP); nCurrentWidth = UpscaleTwoDecimalPlaces(nCurrentWidth, m_nOldDigits); nPercent = m_nRefValue ? (((nCurrentWidth * 10) / m_nRefValue + 5) / 10) : 0; m_pField->set_value(nPercent, FieldUnit::NONE); - m_nLastPercent = nPercent; - m_nLastValue = nOldValue; } - else - m_pField->set_value(m_nLastPercent, FieldUnit::NONE); } else { - sal_Int64 nOldPercent = get_value(FieldUnit::PERCENT); - nOldValue = Convert(get_value(), m_pField->get_unit(), m_eOldUnit); m_pField->set_unit(m_eOldUnit); @@ -107,14 +98,9 @@ void SwPercentField::ShowPercent(bool bPercent, sal_uInt16 nMaxPercent) m_pField->set_range(m_nOldMin, m_nOldMax, FieldUnit::NONE); m_pField->set_increments(m_nOldSpinSize, m_nOldPageSize, FieldUnit::NONE); - if (nOldPercent != m_nLastPercent) { set_value(nOldValue, m_eOldUnit); - m_nLastPercent = nOldPercent; - m_nLastValue = nOldValue; } - else - set_value(m_nLastValue, m_eOldUnit); } }
