diff options
-rw-r--r-- | include/vcl/field.hxx | 2 | ||||
-rw-r--r-- | vcl/source/control/field.cxx | 44 |
2 files changed, 18 insertions, 28 deletions
diff --git a/include/vcl/field.hxx b/include/vcl/field.hxx index 1bf15e177a36..546b1c9704ab 100644 --- a/include/vcl/field.hxx +++ b/include/vcl/field.hxx @@ -184,6 +184,8 @@ public: void SetMax( sal_Int64 nNewMax ); sal_Int64 GetMax() const { return mnMax; } + sal_Int64 ClipAgainstMinMax(sal_Int64 nValue) const; + void SetFirst( sal_Int64 nNewFirst ) { mnFirst = nNewFirst; } sal_Int64 GetFirst() const { return mnFirst; } void SetLast( sal_Int64 nNewLast ) { mnLast = nNewLast; } diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx index e57c7f6533e5..697238112eb4 100644 --- a/vcl/source/control/field.cxx +++ b/vcl/source/control/field.cxx @@ -417,11 +417,7 @@ bool NumericFormatter::ImplNumericReformat( const OUString& rStr, sal_Int64& rVa return true; else { - sal_Int64 nTempVal = rValue; - if ( nTempVal > mnMax ) - nTempVal = mnMax; - else if ( nTempVal < mnMin ) - nTempVal = mnMin; + sal_Int64 nTempVal = ClipAgainstMinMax(rValue); if ( GetErrorHdl().IsSet() && (rValue != nTempVal) ) { @@ -487,11 +483,7 @@ void NumericFormatter::ImplLoadRes( const ResId& rResId ) if ( NUMERICFORMATTER_VALUE & nMask ) { - mnFieldValue = pMgr->ReadLong(); - if ( mnFieldValue > mnMax ) - mnFieldValue = mnMax; - else if ( mnFieldValue < mnMin ) - mnFieldValue = mnMin; + mnFieldValue = ClipAgainstMinMax(pMgr->ReadLong()); mnLastValue = mnFieldValue; } @@ -554,10 +546,7 @@ OUString NumericFormatter::CreateFieldText( sal_Int64 nValue ) const void NumericFormatter::ImplSetUserValue( sal_Int64 nNewValue, Selection* pNewSelection ) { - if ( nNewValue > mnMax ) - nNewValue = mnMax; - else if ( nNewValue < mnMin ) - nNewValue = mnMin; + nNewValue = ClipAgainstMinMax(nNewValue); mnLastValue = nNewValue; if ( GetField() ) @@ -579,11 +568,7 @@ sal_Int64 NumericFormatter::GetValue() const if ( ImplNumericGetValue( GetField()->GetText(), nTempValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() ) ) { - if ( nTempValue > mnMax ) - nTempValue = mnMax; - else if ( nTempValue < mnMin ) - nTempValue = mnMin; - return nTempValue; + return ClipAgainstMinMax(nTempValue); } else return mnLastValue; @@ -656,8 +641,7 @@ void NumericFormatter::FieldUp() else nValue = (nRemainder == 0) ? nValue + mnSpinSize : nValue - nRemainder; - if ( nValue > mnMax ) - nValue = mnMax; + nValue = ClipAgainstMinMax(nValue); ImplNewFieldValue( nValue ); } @@ -671,8 +655,7 @@ void NumericFormatter::FieldDown() else nValue = (nRemainder == 0) ? nValue - mnSpinSize : nValue - mnSpinSize - nRemainder; - if ( nValue < mnMin ) - nValue = mnMin; + nValue = ClipAgainstMinMax(mnMin); ImplNewFieldValue( nValue ); } @@ -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 ) : SpinField( pParent, nWinStyle ) { @@ -1944,11 +1936,7 @@ sal_Int64 CurrencyFormatter::GetValue() const sal_Int64 nTempValue; if ( ImplCurrencyGetValue( GetField()->GetText(), nTempValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() ) ) { - if ( nTempValue > mnMax ) - nTempValue = mnMax; - else if ( nTempValue < mnMin ) - nTempValue = mnMin; - return nTempValue; + return ClipAgainstMinMax(nTempValue); } else return mnLastValue; |