diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2018-02-21 00:30:16 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2018-02-21 08:11:23 +0100 |
commit | f00e891f3369f7b8c2532634d9ff4ab19da17c33 (patch) | |
tree | 752901b046836b0aab906cd7966a178636bf290e /vcl | |
parent | ba8a70365ef459c967cd8a71a6d48ca53dd341bd (diff) |
tdf#115892: properly get the box' saved value
Previously textual value like "10,5 pt" was converted to int as simply
10 (multiplied by 10, it became 100), which compared as different from
unchanged value of 105. This made the fractional values to be treated
as always changed.
This patch uses the same code to convert saved value as is used for
current edit box value.
Change-Id: I09a84a6bf33b17e0192b79b31af21ef14d7e9c63
Reviewed-on: https://gerrit.libreoffice.org/50066
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/control/field.cxx | 71 |
1 files changed, 29 insertions, 42 deletions
diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx index d04886eeb228..6df9b1478285 100644 --- a/vcl/source/control/field.cxx +++ b/vcl/source/control/field.cxx @@ -582,15 +582,12 @@ void NumericFormatter::SetUserValue( sal_Int64 nNewValue ) ImplSetUserValue( nNewValue ); } -sal_Int64 NumericFormatter::GetValue() const +sal_Int64 NumericFormatter::GetValueFromString(const OUString& rStr) const { - if ( !GetField() ) - return 0; - sal_Int64 nTempValue; - if ( ImplNumericGetValue( GetField()->GetText(), nTempValue, - GetDecimalDigits(), ImplGetLocaleDataWrapper() ) ) + if (ImplNumericGetValue(rStr, nTempValue, + GetDecimalDigits(), ImplGetLocaleDataWrapper())) { return ClipAgainstMinMax(nTempValue); } @@ -598,6 +595,16 @@ sal_Int64 NumericFormatter::GetValue() const return mnLastValue; } +sal_Int64 NumericFormatter::GetValue() const +{ + return GetField() ? GetValueFromString(GetField()->GetText()) : 0; +} + +sal_Int64 NumericFormatter::GetSavedIntValue() const +{ + return GetField() ? GetValueFromString(GetField()->GetSavedValue()) : 0; +} + bool NumericFormatter::IsValueModified() const { if ( ImplGetEmptyFieldValue() ) @@ -1399,36 +1406,37 @@ void MetricFormatter::SetUserValue( sal_Int64 nNewValue, FieldUnit eInUnit ) NumericFormatter::SetUserValue( nNewValue ); } -sal_Int64 MetricFormatter::GetValue( FieldUnit eOutUnit ) const +sal_Int64 MetricFormatter::GetValueFromStringUnit(const OUString& rStr, FieldUnit eOutUnit) const { - if ( !GetField() ) - return 0; - double nTempValue; // caution: precision loss in double cast - if ( !ImplMetricGetValue( GetField()->GetText(), nTempValue, mnBaseValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit ) ) + if (!ImplMetricGetValue(rStr, nTempValue, mnBaseValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit)) nTempValue = static_cast<double>(mnLastValue); // caution: precision loss in double cast - if ( nTempValue > mnMax ) + if (nTempValue > mnMax) nTempValue = static_cast<double>(mnMax); - else if ( nTempValue < mnMin ) + else if (nTempValue < mnMin) nTempValue = static_cast<double>(mnMin); // convert to requested units - return MetricField::ConvertValue( static_cast<sal_Int64>(nTempValue), mnBaseValue, GetDecimalDigits(), meUnit, eOutUnit ); + return MetricField::ConvertValue(static_cast<sal_Int64>(nTempValue), mnBaseValue, GetDecimalDigits(), meUnit, eOutUnit); } -void MetricFormatter::SetValue( sal_Int64 nValue ) +sal_Int64 MetricFormatter::GetValueFromString(const OUString& rStr) const { - // Implementation not inline, because it is a virtual Function - SetValue( nValue, FUNIT_NONE ); + return GetValueFromStringUnit(rStr, FUNIT_NONE); +} + +sal_Int64 MetricFormatter::GetValue( FieldUnit eOutUnit ) const +{ + return GetField() ? GetValueFromStringUnit(GetField()->GetText(), eOutUnit) : 0; } -sal_Int64 MetricFormatter::GetValue() const +void MetricFormatter::SetValue( sal_Int64 nValue ) { // Implementation not inline, because it is a virtual Function - return GetValue( FUNIT_NONE ); + SetValue( nValue, FUNIT_NONE ); } void MetricFormatter::SetMin( sal_Int64 nNewMin, FieldUnit eInUnit ) @@ -1783,18 +1791,6 @@ sal_Int32 MetricBox::GetValuePos( sal_Int64 nValue, FieldUnit eInUnit ) const return ComboBox::GetEntryPos( CreateFieldText( nValue ) ); } -sal_Int64 MetricBox::GetValue( FieldUnit eOutUnit ) const -{ - // Implementation not inline, because it is a virtual Function - return MetricFormatter::GetValue( eOutUnit ); -} - -sal_Int64 MetricBox::GetValue() const -{ - // Implementation not inline, because it is a virtual Function - return GetValue( FUNIT_NONE ); -} - static bool ImplCurrencyProcessKeyInput( const KeyEvent& rKEvt, bool bUseThousandSep, const LocaleDataWrapper& rWrapper ) { @@ -1849,13 +1845,10 @@ OUString CurrencyFormatter::CreateFieldText( sal_Int64 nValue ) const IsUseThousandSep() ); } -sal_Int64 CurrencyFormatter::GetValue() const +sal_Int64 CurrencyFormatter::GetValueFromString(const OUString& rStr) const { - if ( !GetField() ) - return 0; - sal_Int64 nTempValue; - if ( ImplCurrencyGetValue( GetField()->GetText(), nTempValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() ) ) + if ( ImplCurrencyGetValue( rStr, nTempValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() ) ) { return ClipAgainstMinMax(nTempValue); } @@ -2043,10 +2036,4 @@ void CurrencyBox::ReformatAll() SetUpdateMode( true ); } -sal_Int64 CurrencyBox::GetValue() const -{ - // Implementation not inline, because it is a virtual Function - return CurrencyFormatter::GetValue(); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |