diff options
Diffstat (limited to 'vcl/source/control/field.cxx')
-rw-r--r-- | vcl/source/control/field.cxx | 93 |
1 files changed, 60 insertions, 33 deletions
diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx index fd69457c8026..e34aa3752895 100644 --- a/vcl/source/control/field.cxx +++ b/vcl/source/control/field.cxx @@ -1,3 +1,4 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -50,7 +51,6 @@ #include "rtl/math.hxx" - #include <unotools/localedatawrapper.hxx> using namespace ::com::sun::star; @@ -699,9 +699,15 @@ sal_Int64 NumericFormatter::Denormalize( sal_Int64 nValue ) const { sal_Int64 nFactor = ImplPower10( GetDecimalDigits() ); if( nValue < 0 ) - return ((nValue-(nFactor/2)) / nFactor ); + { + sal_Int64 nHalf = nValue < ( SAL_MIN_INT64 + nFactor )? 0 : nFactor/2; + return ((nValue-nHalf) / nFactor ); + } else - return ((nValue+(nFactor/2)) / nFactor ); + { + sal_Int64 nHalf = nValue > ( SAL_MAX_INT64 - nFactor )? 0 : nFactor/2; + return ((nValue+nHalf) / nFactor ); + } } // ----------------------------------------------------------------------- @@ -1176,29 +1182,32 @@ static FieldUnit ImplMetricGetUnit( const XubString& rStr ) } #define K *1000L -#define M *1000000L +#define M *1000000LL #define X *5280L -static const sal_Int64 aImplFactor[FUNIT_MILE+1][FUNIT_MILE+1] = +// twip in km = 254 / 14 400 000 000 +// expressions too big for default size 32 bit need LL to avoid overflow + +static const sal_Int64 aImplFactor[FUNIT_LINE+1][FUNIT_LINE+1] = { /* -mm/100 mm cm m km twip point pica inch foot mile */ -{ 1, 100, 1 K, 100 K, 100 M, 2540, 2540, 2540, 2540,2540*12,2540*12 X }, -{ 1, 1, 10, 1 K, 1 M, 2540, 2540, 2540, 2540,2540*12,2540*12 X }, -{ 1, 1, 1, 100, 100 K, 254, 254, 254, 254, 254*12, 254*12 X }, -{ 1, 1, 1, 1, 1 K, 254, 254, 254, 254, 254*12, 254*12 X }, -{ 1, 1, 1, 1, 1, 0, 254, 254, 254, 254*12, 254*12 X }, -{ 1440,144 K,144 K,14400 K, 0, 1, 20, 240, 1440,1440*12,1440*12 X }, -{ 72, 7200, 7200, 720 K, 720 M, 1, 1, 12, 72, 72*12, 72*12 X }, -{ 6, 600, 600, 60 K, 60 M, 1, 1, 1, 6, 6*12, 6*12 X }, -{ 1, 100, 100, 10 K, 10 M, 1, 1, 1, 1, 12, 12 X }, -{ 1, 100, 100, 10 K, 10 M, 1, 1, 1, 1, 1, 1 X }, -{ 1, 100, 100, 10 K, 10 M, 1, 1, 1, 1, 1, 1 } +mm/100 mm cm m km twip point pica inch foot mile char line */ +{ 1, 100, 1 K, 100 K, 100 M, 2540, 2540, 2540, 2540,2540*12,2540*12 X , 53340, 396240}, +{ 1, 1, 10, 1 K, 1 M, 2540, 2540, 2540, 2540,2540*12,2540*12 X , 5334, 396240}, +{ 1, 1, 1, 100, 100 K, 254, 254, 254, 254, 254*12, 254*12 X , 5334, 39624}, +{ 1, 1, 1, 1, 1 K, 254, 254, 254, 254, 254*12, 254*12 X , 533400, 39624}, +{ 1, 1, 1, 1, 1, 254, 254, 254, 254, 254*12, 254*12 X ,533400 K, 39624}, +{ 1440,144 K,144 K,14400 K,14400LL M, 1, 20, 240, 1440,1440*12,1440*12 X , 210, 3120}, +{ 72, 7200, 7200, 720 K, 720 M, 1, 1, 12, 72, 72*12, 72*12 X , 210, 156}, +{ 6, 600, 600, 60 K, 60 M, 1, 1, 1, 6, 6*12, 6*12 X , 210, 10}, +{ 1, 100, 100, 10 K, 10 M, 1, 1, 1, 1, 12, 12 X , 210, 45}, +{ 1, 100, 100, 10 K, 10 M, 1, 1, 1, 1, 1, 1 X , 210, 45}, +{ 1, 100, 100, 10 K, 10 M, 1, 1, 1, 1, 1, 1 , 210, 45}, +{ 144, 1440,14400, 14400, 14400, 1, 20, 240, 1440,1440*12, 1440*12 X, 1, 156 }, +{ 720,72000,72000, 7200 K,7200LL M, 20, 10, 13, 11, 11*12, 11*12 X, 105, 1 } }; - #undef X #undef M #undef K -// twip in km 254/14400 M static FieldUnit eDefaultUnit = FUNIT_NONE; @@ -1235,7 +1244,7 @@ static FieldUnit ImplMap2FieldUnit( MapUnit meUnit, long& nDecDigits ) case MAP_TWIP : return FUNIT_TWIP; default: - DBG_ERROR( "default eInUnit" ); + OSL_FAIL( "default eInUnit" ); break; } return FUNIT_NONE; @@ -1251,13 +1260,18 @@ static double nonValueDoubleToValueDouble( double nValue ) sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits, FieldUnit eInUnit, FieldUnit eOutUnit ) { + double nDouble = nonValueDoubleToValueDouble( ConvertDoubleValue( + (double)nValue, mnBaseValue, nDecDigits, eInUnit, eOutUnit ) ); + // caution: precision loss in double cast - return static_cast<sal_Int64>( - // #150733# cast double to sal_Int64 can throw a - // EXCEPTION_FLT_INVALID_OPERATION on Windows - nonValueDoubleToValueDouble( - ConvertDoubleValue( (double)nValue, mnBaseValue, nDecDigits, - eInUnit, eOutUnit ) ) ); + sal_Int64 nLong = static_cast<sal_Int64>( nDouble ); + + if ( nDouble >= (double)SAL_MAX_INT64 ) + nLong = SAL_MAX_INT64; + else if ( nDouble <= (double)SAL_MIN_INT64 ) + nLong = SAL_MIN_INT64; + + return nLong; } // ----------------------------------------------------------------------- @@ -1266,8 +1280,6 @@ sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_uInt16 nDigits, MapUnit eInUnit, FieldUnit eOutUnit ) { return static_cast<sal_Int64>( - // #150733# cast double to sal_Int64 can throw a - // EXCEPTION_FLT_INVALID_OPERATION on Windows nonValueDoubleToValueDouble( ConvertDoubleValue( nValue, nDigits, eInUnit, eOutUnit ) ) ); } @@ -1278,8 +1290,6 @@ sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_uInt16 nDigits, FieldUnit eInUnit, MapUnit eOutUnit ) { return static_cast<sal_Int64>( - // #150733# cast double to sal_Int64 can throw a - // EXCEPTION_FLT_INVALID_OPERATION on Windows nonValueDoubleToValueDouble( ConvertDoubleValue( nValue, nDigits, eInUnit, eOutUnit ) ) ); } @@ -1348,7 +1358,7 @@ double MetricField::ConvertDoubleValue( double nValue, sal_uInt16 nDigits, eInUnit == MAP_APPFONT || eInUnit == MAP_RELATIVE ) { - DBG_ERROR( "invalid parameters" ); + OSL_FAIL( "invalid parameters" ); return nValue; } @@ -1405,7 +1415,7 @@ double MetricField::ConvertDoubleValue( double nValue, sal_uInt16 nDigits, eOutUnit == MAP_APPFONT || eOutUnit == MAP_RELATIVE ) { - DBG_ERROR( "invalid parameters" ); + OSL_FAIL( "invalid parameters" ); return nValue; } @@ -1424,7 +1434,6 @@ double MetricField::ConvertDoubleValue( double nValue, sal_uInt16 nDigits, { while ( nDecDigits ) { - nValue += 5; nValue /= 10; nDecDigits--; } @@ -1775,6 +1784,22 @@ MetricField::~MetricField() { } +void MetricField::SetUnit( FieldUnit nNewUnit ) +{ + sal_Int64 nRawMax = GetMax( nNewUnit ); + sal_Int64 nMax = Denormalize( nRawMax ); + sal_Int64 nMin = Denormalize( GetMin( nNewUnit ) ); + sal_Int64 nFirst = Denormalize( GetFirst( nNewUnit ) ); + sal_Int64 nLast = Denormalize( GetLast( nNewUnit ) ); + + MetricFormatter::SetUnit( nNewUnit ); + + SetMax( Normalize( nMax ), nNewUnit ); + SetMin( Normalize( nMin ), nNewUnit ); + SetFirst( Normalize( nFirst ), nNewUnit ); + SetLast( Normalize( nLast ), nNewUnit ); +} + // ----------------------------------------------------------------------- void MetricField::SetFirst( sal_Int64 nNewFirst, FieldUnit eInUnit ) @@ -2508,3 +2533,5 @@ sal_Int64 CurrencyBox::GetValue() const // Implementation not inline, because it is a virtual Function return CurrencyFormatter::GetValue(); } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |