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>
diff --git a/cui/source/tabpages/chardlg.cxx b/cui/source/tabpages/chardlg.cxx
index 1e641d0..cc34b31 100644
--- a/cui/source/tabpages/chardlg.cxx
+++ b/cui/source/tabpages/chardlg.cxx
@@ -1040,14 +1040,8 @@ bool SvxCharNamePage::FillItemSet_Impl( SfxItemSet& rSet, LanguageGroup eLangGrp
if ( pSizeBox->GetText().isEmpty() ) // GetValue() returns the min-value
nSize = 0;
long nSavedSize = pSizeBox->GetSavedValue().toInt32();
bool bRel = true;
if ( !pSizeBox->IsRelative() )
{
nSavedSize *= 10;
bRel = false;
}
long nSavedSize = static_cast<long>(pSizeBox->GetSavedIntValue());
const bool bRel = pSizeBox->IsRelative();
switch ( eLangGrp )
{
diff --git a/include/svtools/ctrlbox.hxx b/include/svtools/ctrlbox.hxx
index b446b7a..5e557e2 100644
--- a/include/svtools/ctrlbox.hxx
+++ b/include/svtools/ctrlbox.hxx
@@ -362,6 +362,7 @@ class SVT_DLLPUBLIC FontSizeBox : public MetricBox
protected:
virtual OUString CreateFieldText( sal_Int64 nValue ) const override;
virtual sal_Int64 GetValueFromStringUnit(const OUString& rStr, FieldUnit eOutUnit) const override;
public:
FontSizeBox( vcl::Window* pParent, WinBits nWinStyle );
@@ -384,8 +385,6 @@ public:
virtual void SetValue( sal_Int64 nNewValue, FieldUnit eInUnit ) override;
virtual void SetValue( sal_Int64 nNewValue ) override;
virtual sal_Int64 GetValue( FieldUnit eOutUnit ) const override;
virtual sal_Int64 GetValue() const override;
private:
FontSizeBox( const FontSizeBox& ) = delete;
diff --git a/include/vcl/field.hxx b/include/vcl/field.hxx
index 0380259..6154211 100644
--- a/include/vcl/field.hxx
+++ b/include/vcl/field.hxx
@@ -155,7 +155,8 @@ public:
void SetUserValue( sal_Int64 nNewValue );
virtual void SetValue( sal_Int64 nNewValue );
virtual sal_Int64 GetValue() const;
sal_Int64 GetValue() const;
sal_Int64 GetSavedIntValue() const;
virtual OUString CreateFieldText( sal_Int64 nValue ) const;
bool IsValueModified() const;
@@ -186,6 +187,8 @@ protected:
SAL_DLLPRIVATE void ImplNewFieldValue( sal_Int64 nNewValue );
SAL_DLLPRIVATE void ImplSetUserValue( sal_Int64 nNewValue, Selection const * pNewSelection = nullptr );
virtual sal_Int64 GetValueFromString(const OUString& rStr) const;
private:
SAL_DLLPRIVATE void ImplInit();
@@ -225,8 +228,8 @@ public:
virtual void SetValue( sal_Int64 nValue ) override;
using NumericFormatter::SetUserValue;
void SetUserValue( sal_Int64 nNewValue, FieldUnit eInUnit );
virtual sal_Int64 GetValue( FieldUnit eOutUnit ) const;
virtual sal_Int64 GetValue() const override;
using NumericFormatter::GetValue;
sal_Int64 GetValue( FieldUnit eOutUnit ) const;
virtual OUString CreateFieldText( sal_Int64 nValue ) const override;
sal_Int64 GetCorrectedValue( FieldUnit eOutUnit ) const;
@@ -242,6 +245,9 @@ protected:
SAL_DLLPRIVATE bool ImplMetricReformat( const OUString& rStr, double& rValue, OUString& rOutStr );
virtual sal_Int64 GetValueFromString(const OUString& rStr) const override;
virtual sal_Int64 GetValueFromStringUnit(const OUString& rStr, FieldUnit eOutUnit) const;
private:
SAL_DLLPRIVATE void ImplInit();
@@ -255,6 +261,7 @@ class VCL_DLLPUBLIC CurrencyFormatter : public NumericFormatter
protected:
CurrencyFormatter();
SAL_DLLPRIVATE bool ImplCurrencyReformat( const OUString& rStr, OUString& rOutStr );
virtual sal_Int64 GetValueFromString(const OUString& rStr) const override;
public:
virtual ~CurrencyFormatter() override;
@@ -262,7 +269,6 @@ public:
virtual void Reformat() override;
virtual void SetValue( sal_Int64 nNewValue ) override;
virtual sal_Int64 GetValue() const override;
virtual OUString CreateFieldText( sal_Int64 nValue ) const override;
};
@@ -661,8 +667,7 @@ public:
FieldUnit eInUnit = FUNIT_NONE ) const;
// Needed, because GetValue() with nPos hide these functions
virtual sal_Int64 GetValue( FieldUnit eOutUnit ) const override;
virtual sal_Int64 GetValue() const override;
using MetricFormatter::GetValue;
virtual void dispose() override;
};
@@ -681,7 +686,6 @@ public:
virtual void ReformatAll() override;
virtual sal_Int64 GetValue() const override;
virtual void dispose() override;
};
diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index 29665a7..82cd893 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -1562,23 +1562,17 @@ void FontSizeBox::SetValue( sal_Int64 nNewValue )
SetValue( nNewValue, FUNIT_NONE );
}
sal_Int64 FontSizeBox::GetValue( FieldUnit eOutUnit ) const
sal_Int64 FontSizeBox::GetValueFromStringUnit(const OUString& rStr, FieldUnit eOutUnit) const
{
if ( !bRelative )
{
FontSizeNames aFontSizeNames( GetSettings().GetUILanguageTag().getLanguageType() );
sal_Int64 nValue = aFontSizeNames.Name2Size( GetText() );
if ( nValue)
sal_Int64 nValue = aFontSizeNames.Name2Size( rStr );
if ( nValue )
return MetricField::ConvertValue( nValue, GetBaseValue(), GetDecimalDigits(), GetUnit(), eOutUnit );
}
return MetricBox::GetValue( eOutUnit );
}
sal_Int64 FontSizeBox::GetValue() const
{
// implementation not inline, because it is a virtual function
return GetValue( FUNIT_NONE );
return MetricBox::GetValueFromStringUnit( rStr, eOutUnit );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx
index d04886e..6df9b14 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,24 +1406,31 @@ 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);
}
sal_Int64 MetricFormatter::GetValueFromString(const OUString& rStr) const
{
return GetValueFromStringUnit(rStr, FUNIT_NONE);
}
sal_Int64 MetricFormatter::GetValue( FieldUnit eOutUnit ) const
{
return GetField() ? GetValueFromStringUnit(GetField()->GetText(), eOutUnit) : 0;
}
void MetricFormatter::SetValue( sal_Int64 nValue )
@@ -1425,12 +1439,6 @@ void MetricFormatter::SetValue( sal_Int64 nValue )
SetValue( nValue, FUNIT_NONE );
}
sal_Int64 MetricFormatter::GetValue() const
{
// Implementation not inline, because it is a virtual Function
return GetValue( FUNIT_NONE );
}
void MetricFormatter::SetMin( sal_Int64 nNewMin, FieldUnit eInUnit )
{
// convert to requested units
@@ -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: */