sw/source/uibase/inc/prcntfld.hxx | 2 ++ sw/source/uibase/utlui/prcntfld.cxx | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-)
New commits: commit 6c67c4e9947490a00d0c6a565c178302de3095eb Author: Justin Luth <[email protected]> AuthorDate: Sat Nov 15 08:44:21 2025 -0500 Commit: Justin Luth <[email protected]> CommitDate: Sat Nov 15 22:06:37 2025 +0100 Revert "tdf#169219: value may be changed even if % isn't" This reverts my 26.2 commit 7c2f02497ccc026ccaf48fc3b0b109b78c93c592. (and the follow-up cleanup commit) I think I learned the reason for restoring the previous value. The calculation of the width based on a percentage is less precise than the decimal-place width value. In other words, it is more of an approximation. So, if the percentage was not changed, then use the precise width stored as the last value, instead of re-calculating a nearly-identical width. This means that toggling back and forth will not minutely change the width value. That precision might be very valuable. A follow-up commit will add a nLastRefValue, but with this commit I just want to cleanly revert back to the original code - without making any changes. Change-Id: Id940c9a71c8123f6cffbd623f656acfa88ed19a8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194051 Tested-by: Jenkins Reviewed-by: Justin Luth <[email protected]> diff --git a/sw/source/uibase/inc/prcntfld.hxx b/sw/source/uibase/inc/prcntfld.hxx index 918291d497f5..401292970d43 100644 --- a/sw/source/uibase/inc/prcntfld.hxx +++ b/sw/source/uibase/inc/prcntfld.hxx @@ -31,6 +31,8 @@ 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 a7f868397331..aa57a09d4c93 100644 --- a/sw/source/uibase/utlui/prcntfld.cxx +++ b/sw/source/uibase/utlui/prcntfld.cxx @@ -24,6 +24,8 @@ 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) @@ -59,9 +61,11 @@ void SwPercentField::ShowPercent(bool bPercent, sal_uInt16 nMaxPercent) || (!bPercent && m_pField->get_unit() != FieldUnit::PERCENT)) return; + sal_Int64 nOldValue; + if (bPercent) { - sal_Int64 nOldValue = get_value(); + nOldValue = get_value(); m_eOldUnit = m_pField->get_unit(); m_nOldDigits = m_pField->get_digits(); @@ -79,22 +83,38 @@ 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); + 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 { - const sal_Int64 nValue = Convert(get_value(), m_pField->get_unit(), m_eOldUnit); + sal_Int64 nOldPercent = get_value(FieldUnit::PERCENT); + + nOldValue = 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(nValue, m_eOldUnit); + if (nOldPercent != m_nLastPercent) + { + set_value(nOldValue, m_eOldUnit); + m_nLastPercent = nOldPercent; + m_nLastValue = nOldValue; + } + else + set_value(m_nLastValue, m_eOldUnit); } }
