Kaydet (Commit) e1a5ae39 authored tarafından Caolán McNamara's avatar Caolán McNamara

Related: fdo#83010 move NumericFormatter clipping to min/max into one place

Change-Id: I60cfe651a6ec25fc7e482192d908acca25c1ad8b
üst 259ab763
...@@ -184,6 +184,8 @@ public: ...@@ -184,6 +184,8 @@ public:
void SetMax( sal_Int64 nNewMax ); void SetMax( sal_Int64 nNewMax );
sal_Int64 GetMax() const { return mnMax; } sal_Int64 GetMax() const { return mnMax; }
sal_Int64 ClipAgainstMinMax(sal_Int64 nValue) const;
void SetFirst( sal_Int64 nNewFirst ) { mnFirst = nNewFirst; } void SetFirst( sal_Int64 nNewFirst ) { mnFirst = nNewFirst; }
sal_Int64 GetFirst() const { return mnFirst; } sal_Int64 GetFirst() const { return mnFirst; }
void SetLast( sal_Int64 nNewLast ) { mnLast = nNewLast; } void SetLast( sal_Int64 nNewLast ) { mnLast = nNewLast; }
......
...@@ -417,11 +417,7 @@ bool NumericFormatter::ImplNumericReformat( const OUString& rStr, sal_Int64& rVa ...@@ -417,11 +417,7 @@ bool NumericFormatter::ImplNumericReformat( const OUString& rStr, sal_Int64& rVa
return true; return true;
else else
{ {
sal_Int64 nTempVal = rValue; sal_Int64 nTempVal = ClipAgainstMinMax(rValue);
if ( nTempVal > mnMax )
nTempVal = mnMax;
else if ( nTempVal < mnMin )
nTempVal = mnMin;
if ( GetErrorHdl().IsSet() && (rValue != nTempVal) ) if ( GetErrorHdl().IsSet() && (rValue != nTempVal) )
{ {
...@@ -487,11 +483,7 @@ void NumericFormatter::ImplLoadRes( const ResId& rResId ) ...@@ -487,11 +483,7 @@ void NumericFormatter::ImplLoadRes( const ResId& rResId )
if ( NUMERICFORMATTER_VALUE & nMask ) if ( NUMERICFORMATTER_VALUE & nMask )
{ {
mnFieldValue = pMgr->ReadLong(); mnFieldValue = ClipAgainstMinMax(pMgr->ReadLong());
if ( mnFieldValue > mnMax )
mnFieldValue = mnMax;
else if ( mnFieldValue < mnMin )
mnFieldValue = mnMin;
mnLastValue = mnFieldValue; mnLastValue = mnFieldValue;
} }
...@@ -554,10 +546,7 @@ OUString NumericFormatter::CreateFieldText( sal_Int64 nValue ) const ...@@ -554,10 +546,7 @@ OUString NumericFormatter::CreateFieldText( sal_Int64 nValue ) const
void NumericFormatter::ImplSetUserValue( sal_Int64 nNewValue, Selection* pNewSelection ) void NumericFormatter::ImplSetUserValue( sal_Int64 nNewValue, Selection* pNewSelection )
{ {
if ( nNewValue > mnMax ) nNewValue = ClipAgainstMinMax(nNewValue);
nNewValue = mnMax;
else if ( nNewValue < mnMin )
nNewValue = mnMin;
mnLastValue = nNewValue; mnLastValue = nNewValue;
if ( GetField() ) if ( GetField() )
...@@ -579,11 +568,7 @@ sal_Int64 NumericFormatter::GetValue() const ...@@ -579,11 +568,7 @@ sal_Int64 NumericFormatter::GetValue() const
if ( ImplNumericGetValue( GetField()->GetText(), nTempValue, if ( ImplNumericGetValue( GetField()->GetText(), nTempValue,
GetDecimalDigits(), ImplGetLocaleDataWrapper() ) ) GetDecimalDigits(), ImplGetLocaleDataWrapper() ) )
{ {
if ( nTempValue > mnMax ) return ClipAgainstMinMax(nTempValue);
nTempValue = mnMax;
else if ( nTempValue < mnMin )
nTempValue = mnMin;
return nTempValue;
} }
else else
return mnLastValue; return mnLastValue;
...@@ -656,8 +641,7 @@ void NumericFormatter::FieldUp() ...@@ -656,8 +641,7 @@ void NumericFormatter::FieldUp()
else else
nValue = (nRemainder == 0) ? nValue + mnSpinSize : nValue - nRemainder; nValue = (nRemainder == 0) ? nValue + mnSpinSize : nValue - nRemainder;
if ( nValue > mnMax ) nValue = ClipAgainstMinMax(nValue);
nValue = mnMax;
ImplNewFieldValue( nValue ); ImplNewFieldValue( nValue );
} }
...@@ -671,8 +655,7 @@ void NumericFormatter::FieldDown() ...@@ -671,8 +655,7 @@ void NumericFormatter::FieldDown()
else else
nValue = (nRemainder == 0) ? nValue - mnSpinSize : nValue - mnSpinSize - nRemainder; nValue = (nRemainder == 0) ? nValue - mnSpinSize : nValue - mnSpinSize - nRemainder;
if ( nValue < mnMin ) nValue = ClipAgainstMinMax(mnMin);
nValue = mnMin;
ImplNewFieldValue( nValue ); ImplNewFieldValue( nValue );
} }
...@@ -720,6 +703,15 @@ void NumericFormatter::ImplNewFieldValue( sal_Int64 nNewValue ) ...@@ -720,6 +703,15 @@ void NumericFormatter::ImplNewFieldValue( sal_Int64 nNewValue )
} }
} }
sal_Int64 NumericFormatter::ClipAgainstMinMax(sal_Int64 nValue) const
{
if (nValue > mnMax)
nValue = mnMax;
else if (nValue < mnMin)
nValue = mnMin;
return nValue;
}
NumericField::NumericField( vcl::Window* pParent, WinBits nWinStyle ) : NumericField::NumericField( vcl::Window* pParent, WinBits nWinStyle ) :
SpinField( pParent, nWinStyle ) SpinField( pParent, nWinStyle )
{ {
...@@ -1944,11 +1936,7 @@ sal_Int64 CurrencyFormatter::GetValue() const ...@@ -1944,11 +1936,7 @@ sal_Int64 CurrencyFormatter::GetValue() const
sal_Int64 nTempValue; sal_Int64 nTempValue;
if ( ImplCurrencyGetValue( GetField()->GetText(), nTempValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() ) ) if ( ImplCurrencyGetValue( GetField()->GetText(), nTempValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() ) )
{ {
if ( nTempValue > mnMax ) return ClipAgainstMinMax(nTempValue);
nTempValue = mnMax;
else if ( nTempValue < mnMin )
nTempValue = mnMin;
return nTempValue;
} }
else else
return mnLastValue; return mnLastValue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment