sw/source/uibase/inc/prcntfld.hxx | 3 +++ sw/source/uibase/utlui/prcntfld.cxx | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
New commits: commit e029e619db0b12106cd561ea96d7004d5cb19bfc Author: Justin Luth <[email protected]> AuthorDate: Sat Nov 15 09:02:20 2025 -0500 Commit: Justin Luth <[email protected]> CommitDate: Sat Nov 15 22:09:32 2025 +0100 tdf#169219 swrelpagesize ui: value may be changed even if % isn't #2 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 always 'show the value from last time'. The same logic holds 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 Try #1 ignored the fact that using a percentage to calculate the width is somewhat imprecise, so minor drift could occur. Change-Id: I1998506e64d8ba247d11772f77d02e565ea5ddcb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194052 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 401292970d43..2b30f377223d 100644 --- a/sw/source/uibase/inc/prcntfld.hxx +++ b/sw/source/uibase/inc/prcntfld.hxx @@ -32,7 +32,10 @@ class SW_DLLPUBLIC SwPercentField sal_Int64 m_nOldSpinSize; sal_Int64 m_nOldPageSize; sal_Int64 m_nLastPercent; + // Re-use the high-precision value, + // since re-calculating a value based on the percent may be a bit different because of rounding. sal_Int64 m_nLastValue; + sal_Int64 m_nLastRefValue; 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..503df074d971 100644 --- a/sw/source/uibase/utlui/prcntfld.cxx +++ b/sw/source/uibase/utlui/prcntfld.cxx @@ -26,6 +26,7 @@ SwPercentField::SwPercentField(std::unique_ptr<weld::MetricSpinButton> pControl) , m_nOldMin(0) , m_nLastPercent(-1) , m_nLastValue(-1) + , m_nLastRefValue(-1) , m_nOldDigits(m_pField->get_digits()) , m_eOldUnit(FieldUnit::NONE) , m_bLockAutoCalculation(false) @@ -83,7 +84,7 @@ 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) + if (nOldValue != m_nLastValue || m_nRefValue != m_nLastRefValue) { nCurrentWidth = vcl::ConvertValue(nOldValue, 0, m_nOldDigits, m_eOldUnit, FieldUnit::TWIP); @@ -92,6 +93,7 @@ void SwPercentField::ShowPercent(bool bPercent, sal_uInt16 nMaxPercent) m_pField->set_value(nPercent, FieldUnit::NONE); m_nLastPercent = nPercent; m_nLastValue = nOldValue; + m_nLastRefValue = m_nRefValue; } else m_pField->set_value(m_nLastPercent, FieldUnit::NONE); @@ -107,11 +109,12 @@ 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) + if (nOldPercent != m_nLastPercent || m_nRefValue != m_nLastRefValue) { set_value(nOldValue, m_eOldUnit); m_nLastPercent = nOldPercent; m_nLastValue = nOldValue; + m_nLastRefValue = m_nRefValue; } else set_value(m_nLastValue, m_eOldUnit);
