summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-02-21 00:30:16 +0300
committerAndras Timar <andras.timar@collabora.com>2018-03-25 20:14:06 +0200
commit73629949c1d6245f7fad419b677cf92a49ffd18a (patch)
tree65b6fab1a7759b3f32cf355a1de868650870e743 /vcl
parent3ac438cde11c4cbe32a1c09e9fe885a0b0accc2c (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. Reviewed-on: https://gerrit.libreoffice.org/50066 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> (cherry picked from commit f00e891f3369f7b8c2532634d9ff4ab19da17c33) Change-Id: I09a84a6bf33b17e0192b79b31af21ef14d7e9c63
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/control/field.cxx77
1 files changed, 32 insertions, 45 deletions
diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx
index 220da283ba86..c1dbb33417c4 100644
--- a/vcl/source/control/field.cxx
+++ b/vcl/source/control/field.cxx
@@ -576,15 +576,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);
}
@@ -592,6 +589,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() )
@@ -1393,36 +1400,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 ) )
- nTempValue = (double)mnLastValue;
+ if (!ImplMetricGetValue(rStr, nTempValue, mnBaseValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit))
+ nTempValue = static_cast<double>(mnLastValue);
// caution: precision loss in double cast
- if ( nTempValue > mnMax )
- nTempValue = (double)mnMax;
- else if ( nTempValue < mnMin )
- nTempValue = (double)mnMin;
+ if (nTempValue > mnMax)
+ nTempValue = static_cast<double>(mnMax);
+ else if (nTempValue < mnMin)
+ nTempValue = static_cast<double>(mnMin);
// convert to requested units
- return MetricField::ConvertValue( (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 )
@@ -1777,18 +1785,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 )
{
@@ -1843,13 +1839,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);
}
@@ -2037,10 +2030,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: */