27#include <osl/diagnose.h>
45#include <rtl/math.hxx>
48#include <boost/property_tree/ptree.hpp>
57std::string FieldUnitToString(
FieldUnit unit)
79 case FieldUnit::POINT:
100 case FieldUnit::CUSTOM:
103 case FieldUnit::PERCENT:
106 case FieldUnit::MM_100TH:
109 case FieldUnit::PIXEL:
112 case FieldUnit::DEGREE:
115 case FieldUnit::SECOND:
118 case FieldUnit::MILLISECOND:
119 return "millisecond";
125sal_Int64 ImplPower10( sal_uInt16 n )
130 for ( i=0;
i <
n;
i++ )
136bool ImplNumericProcessKeyInput(
const KeyEvent& rKEvt,
137 bool bStrictFormat,
bool bThousandSep,
140 if ( !bStrictFormat )
150 ((cChar >=
'0') && (cChar <=
'9')) ||
152 (bThousandSep && rLocaleDataWrapper.
getNumThousandSep() == OUStringChar(cChar)) ||
158bool ImplNumericGetValue(
const OUString& rStr, sal_Int64& rValue,
160 bool bCurrency =
false )
162 OUString
aStr = rStr;
163 OUStringBuffer aStr1, aStr2, aStrNum, aStrDenom;
164 bool bNegative =
false;
166 sal_Int32 nDecPos, nFracDivPos;
170 if ( rStr.isEmpty() )
182 nFracDivPos =
aStr.indexOf(
'/' );
188 sal_Int32 nFracNumPos =
aStr.lastIndexOf(
' ', nFracDivPos);
191 if(nFracNumPos != -1 )
193 aStr1.append(
aStr.subView(0, nFracNumPos));
194 aStrNum.append(
aStr.subView(nFracNumPos+1, nFracDivPos-nFracNumPos-1));
195 aStrDenom.append(
aStr.subView(nFracDivPos+1));
200 aStrNum.append(
aStr.subView(0, nFracDivPos));
201 aStrDenom.append(
aStr.subView(nFracDivPos+1));
206 else if ( nDecPos >= 0)
208 aStr1.append(
aStr.subView(0, nDecPos));
209 aStr2.append(
aStr.subView(nDecPos+1));
217 if (
aStr.startsWith(
"(") &&
aStr.endsWith(
")") )
221 for (sal_Int32 i=0;
i <
aStr.getLength();
i++ )
223 if ( (aStr[i] >=
'0') && (aStr[i] <=
'9') )
225 else if ( aStr[i] ==
'-' )
232 if (!bNegative && !
aStr.isEmpty())
235 if ( (nFormat == 3) || (nFormat == 6) ||
236 (nFormat == 7) || (nFormat == 10) )
238 for (sal_Int32 i =
aStr.getLength()-1; i > 0; --i )
240 if ( (aStr[i] >=
'0') && (aStr[i] <=
'9') )
242 else if ( aStr[i] ==
'-' )
253 if ( !aStr1.isEmpty() && aStr1[0] ==
'-')
255 if ( !aStrNum.isEmpty() && aStrNum[0] ==
'-')
261 for (sal_Int32 i=0;
i < aStr1.getLength(); )
263 if ( (aStr1[i] >=
'0') && (aStr1[i] <=
'9') )
266 aStr1.remove( i, 1 );
270 for (sal_Int32 i=0;
i < aStr2.getLength(); )
272 if ((aStr2[i] >=
'0') && (aStr2[i] <=
'9'))
280 for (sal_Int32 i=0;
i < aStrNum.getLength(); )
282 if ((aStrNum[i] >=
'0') && (aStrNum[i] <=
'9'))
285 aStrNum.remove(i, 1);
288 for (sal_Int32 i=0;
i < aStrDenom.getLength(); )
290 if ((aStrDenom[i] >=
'0') && (aStrDenom[i] <=
'9'))
293 aStrDenom.remove(i, 1);
298 if ( !bFrac && aStr1.isEmpty() && aStr2.isEmpty() )
300 else if ( bFrac && aStr1.isEmpty() && (aStrNum.isEmpty() || aStrDenom.isEmpty()) )
303 if ( aStr1.isEmpty() )
306 aStr1.insert(0,
"-");
315 if (nDenom == 0)
return false;
316 double nFrac2Dec = nWholeNum +
static_cast<double>(nNum)/nDenom;
317 OUStringBuffer aStrFrac(OUString::number(nFrac2Dec));
319 nDecPos = aStrFrac.indexOf(
'.');
322 aStr1.append(aStrFrac.getStr(), nDecPos);
323 aStr2.append(aStrFrac.getStr()+nDecPos+1);
331 if (aStr2.getLength() > nDecDigits)
333 if (aStr2[nDecDigits] >=
'5')
335 string::truncateToLength(aStr2, nDecDigits);
337 if (aStr2.getLength() < nDecDigits)
338 string::padToLength(aStr2, nDecDigits,
'0');
340 aStr = aStr1 + aStr2;
347 sal_Int32
nIndex = bNegative ? 1 : 0;
348 while (nIndex <
aStr.getLength() && aStr[nIndex] ==
'0')
350 if( nIndex <
aStr.getLength() )
369void ImplUpdateSeparatorString( OUString& io_rText,
370 std::u16string_view rOldDecSep, std::u16string_view rNewDecSep,
371 std::u16string_view rOldThSep, std::u16string_view rNewThSep )
373 OUStringBuffer
aBuf( io_rText.getLength() );
374 sal_Int32 nIndexDec = 0, nIndexTh = 0,
nIndex = 0;
377 while( nIndex != -1 )
379 nIndexDec = io_rText.indexOf( rOldDecSep, nIndex );
380 nIndexTh = io_rText.indexOf( rOldThSep, nIndex );
381 if( (nIndexTh != -1 && nIndexDec != -1 && nIndexTh < nIndexDec )
382 || (nIndexTh != -1 && nIndexDec == -1)
385 aBuf.append( OUString::Concat(std::u16string_view(pBuffer + nIndex, nIndexTh - nIndex )) + rNewThSep );
386 nIndex = nIndexTh + rOldThSep.size();
388 else if( nIndexDec != -1 )
390 aBuf.append( OUString::Concat(std::u16string_view(pBuffer + nIndex, nIndexDec - nIndex )) + rNewDecSep );
391 nIndex = nIndexDec + rOldDecSep.size();
395 aBuf.append( pBuffer + nIndex );
400 io_rText =
aBuf.makeStringAndClear();
403void ImplUpdateSeparators( std::u16string_view rOldDecSep, std::u16string_view rNewDecSep,
404 std::u16string_view rOldThSep, std::u16string_view rNewThSep,
407 bool bChangeDec = (rOldDecSep != rNewDecSep);
408 bool bChangeTh = (rOldThSep != rNewThSep );
410 if( !(bChangeDec || bChangeTh) )
415 OUString aText = pEdit->
GetText();
416 ImplUpdateSeparatorString( aText, rOldDecSep, rNewDecSep, rOldThSep, rNewThSep );
424 for ( sal_Int32 i=0;
i < nEntryCount;
i++ )
428 ImplUpdateSeparatorString( aText, rOldDecSep, rNewDecSep, rOldThSep, rNewThSep );
539void NumericFormatter::FormatValue(
Selection const * pNewSelection)
542 ImplSetText(CreateFieldText(mnLastValue), pNewSelection);
543 mbFormatting =
false;
546void NumericFormatter::ImplNumericReformat()
552NumericFormatter::NumericFormatter(
Edit* pEdit)
559 , mbFormatting(false)
565 , mbThousandSep(true)
570NumericFormatter::~NumericFormatter()
574void NumericFormatter::SetMin( sal_Int64 nNewMin )
577 if ( !IsEmptyFieldValue() )
581void NumericFormatter::SetMax( sal_Int64 nNewMax )
584 if ( !IsEmptyFieldValue() )
588void NumericFormatter::SetUseThousandSep(
bool bValue )
590 mbThousandSep = bValue;
594void NumericFormatter::SetDecimalDigits( sal_uInt16 nDigits )
596 mnDecimalDigits = nDigits;
600void NumericFormatter::SetValue( sal_Int64 nNewValue )
602 SetUserValue( nNewValue );
603 SetEmptyFieldValueData(
false );
606OUString NumericFormatter::CreateFieldText( sal_Int64 nValue )
const
608 return ImplGetLocaleDataWrapper().getNum( nValue, GetDecimalDigits(), IsUseThousandSep(),
true );
611void NumericFormatter::ImplSetUserValue( sal_Int64 nNewValue,
Selection const * pNewSelection )
613 nNewValue = ClipAgainstMinMax(nNewValue);
614 mnLastValue = nNewValue;
617 FormatValue(pNewSelection);
620void NumericFormatter::SetUserValue( sal_Int64 nNewValue )
622 ImplSetUserValue( nNewValue );
625sal_Int64 NumericFormatter::GetValueFromString(
const OUString& rStr)
const
627 sal_Int64 nTempValue;
629 if (ImplNumericGetValue(rStr, nTempValue,
630 GetDecimalDigits(), ImplGetLocaleDataWrapper()))
632 return ClipAgainstMinMax(nTempValue);
638OUString NumericFormatter::GetValueString()
const
641 getNum(
GetValue(), GetDecimalDigits(),
false,
false);
645void NumericFormatter::SetValueFromString(
const OUString& rStr)
649 if (ImplNumericGetValue(rStr, nValue, GetDecimalDigits(),
652 ImplNewFieldValue(nValue);
656 SAL_WARN(
"vcl",
"fail to convert the value: " << rStr );
660sal_Int64 NumericFormatter::GetValue()
const
665 return GetField() ? GetValueFromString(GetField()->GetText()) : 0;
668sal_Int64 NumericFormatter::Normalize( sal_Int64 nValue )
const
670 return (nValue * ImplPower10( GetDecimalDigits() ) );
673sal_Int64 NumericFormatter::Denormalize( sal_Int64 nValue )
const
675 sal_Int64 nFactor = ImplPower10( GetDecimalDigits() );
677 if ((nValue < ( SAL_MIN_INT64 + nFactor )) ||
678 (nValue > ( SAL_MAX_INT64 - nFactor )))
680 return ( nValue / nFactor );
685 sal_Int64 nHalf = nFactor / 2;
686 return ((nValue - nHalf) / nFactor );
690 sal_Int64 nHalf = nFactor / 2;
691 return ((nValue + nHalf) / nFactor );
695void NumericFormatter::Reformat()
700 if ( GetField()->GetText().isEmpty() && ImplGetEmptyFieldValue() )
703 ImplNumericReformat();
706void NumericFormatter::FieldUp()
709 sal_Int64 nRemainder =
nValue % mnSpinSize;
711 nValue = (nRemainder == 0) ? nValue + mnSpinSize : nValue + mnSpinSize - nRemainder;
713 nValue = (nRemainder == 0) ? nValue + mnSpinSize : nValue - nRemainder;
715 nValue = ClipAgainstMinMax(nValue);
717 ImplNewFieldValue( nValue );
720void NumericFormatter::FieldDown()
723 sal_Int64 nRemainder =
nValue % mnSpinSize;
725 nValue = (nRemainder == 0) ? nValue - mnSpinSize : nValue - nRemainder;
727 nValue = (nRemainder == 0) ? nValue - mnSpinSize : nValue - mnSpinSize - nRemainder;
729 nValue = ClipAgainstMinMax(nValue);
731 ImplNewFieldValue( nValue );
734void NumericFormatter::FieldFirst()
736 ImplNewFieldValue( mnFirst );
739void NumericFormatter::FieldLast()
741 ImplNewFieldValue( mnLast );
744void NumericFormatter::ImplNewFieldValue( sal_Int64 nNewValue )
754 Selection aSelection = GetField()->GetSelection();
756 OUString aText = GetField()->GetText();
758 if (
static_cast<sal_Int32
>(aSelection.
Max()) == aText.getLength() )
760 if ( !aSelection.
Len() )
765 sal_Int64 nOldLastValue = mnLastValue;
766 ImplSetUserValue( nNewValue, &aSelection );
767 mnLastValue = nOldLastValue;
770 if ( GetField()->GetText() != aText )
772 GetField()->SetModifyFlag();
773 GetField()->Modify();
777sal_Int64 NumericFormatter::ClipAgainstMinMax(sal_Int64 nValue)
const
781 else if (nValue < mnMin)
788 Size calcMinimumSize(
const Edit &rSpinField,
const NumericFormatter &rFormatter)
793 nTextLen = std::u16string_view(OUString::number(rFormatter.GetMin())).size();
794 string::padToLength(aBuf, nTextLen,
'9');
796 rFormatter.CreateFieldText(OUString::unacquired(aBuf).toInt64()));
799 nTextLen = std::u16string_view(OUString::number(rFormatter.GetMax())).size();
800 string::padToLength(aBuf, nTextLen,
'9');
802 rFormatter.CreateFieldText(OUString::unacquired(aBuf).toInt64()));
806 std::max(aMinTextSize.
Height(), aMaxTextSize.
Height()));
808 OUStringBuffer sBuf(
"999999999");
809 sal_uInt16 nDigits = rFormatter.GetDecimalDigits();
813 string::padToLength(aBuf,
aBuf.getLength() + nDigits,
'9');
816 aRet.
setWidth( std::min(aRet.Width(), aMaxTextSize.
Width()) );
824 , NumericFormatter(this)
831void NumericBox::dispose()
837Size NumericBox::CalcMinimumSize()
const
839 Size aRet(calcMinimumSize(*
this, *
this));
844 aRet.setWidth( std::max(aRet.Width(), aComboSugg.Width()) );
845 aRet.setHeight( std::max(aRet.Height(), aComboSugg.Height()) );
855 if ( ImplNumericProcessKeyInput( *rNEvt.
GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), ImplGetLocaleDataWrapper() ) )
865 MarkToBeReformatted(
false );
868 if ( MustBeReformatted() && (!GetText().isEmpty() || !IsEmptyFieldValueEnabled()) )
881 OUString sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
882 OUString sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
883 ImplResetLocaleDataWrapper();
884 OUString sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
885 OUString sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
886 ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep,
this );
891void NumericBox::Modify()
893 MarkToBeReformatted(
true );
897void NumericBox::ImplNumericReformat(
const OUString& rStr, sal_Int64& rValue,
900 if (ImplNumericGetValue(rStr, rValue, GetDecimalDigits(), ImplGetLocaleDataWrapper()))
902 sal_Int64 nTempVal = ClipAgainstMinMax(rValue);
903 rOutStr = CreateFieldText( nTempVal );
907void NumericBox::ReformatAll()
911 SetUpdateMode(
false );
912 sal_Int32 nEntryCount = GetEntryCount();
913 for ( sal_Int32 i=0;
i < nEntryCount;
i++ )
915 ImplNumericReformat( GetEntry( i ), nValue, aStr );
917 InsertEntry( aStr, i );
919 NumericFormatter::Reformat();
920 SetUpdateMode(
true );
927 return ImplNumericProcessKeyInput( rKEvt,
false, bUseThousandSep, rWrapper );
934 for (sal_Int32
i =
static_cast<sal_Int32
>(rStr.size())-1;
i >= 0; --
i)
945 return aStr.makeStringAndClear();
955 if (elem.second == rUnit)
964 FieldUnit StringToMetric(
const OUString &rMetricString)
967 OUString
aStr = rMetricString.toAsciiLowerCase().replaceAll(
" ",
"");
970 if ( elem.first == aStr )
974 return FieldUnit::NONE;
981 return StringToMetric(
aStr);
988 case MapUnit::Map100thMM :
990 return FieldUnit::MM;
991 case MapUnit::Map10thMM :
993 return FieldUnit::MM;
994 case MapUnit::MapMM :
995 return FieldUnit::MM;
996 case MapUnit::MapCM :
997 return FieldUnit::CM;
998 case MapUnit::Map1000thInch :
1000 return FieldUnit::INCH;
1001 case MapUnit::Map100thInch :
1003 return FieldUnit::INCH;
1004 case MapUnit::Map10thInch :
1006 return FieldUnit::INCH;
1007 case MapUnit::MapInch :
1008 return FieldUnit::INCH;
1009 case MapUnit::MapPoint :
1010 return FieldUnit::POINT;
1011 case MapUnit::MapTwip :
1012 return FieldUnit::TWIP;
1014 OSL_FAIL(
"default eInUnit" );
1017 return FieldUnit::NONE;
1027 sal_Int64
ConvertValue(sal_Int64 nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits,
1040 nLong =
static_cast<sal_Int64
>( std::round(nDouble) );
1050 return eOutUnit != FieldUnit::PERCENT
1051 && eOutUnit != FieldUnit::CUSTOM
1052 && eOutUnit != FieldUnit::NONE
1053 && eInUnit != MapUnit::MapPixel
1054 && eInUnit != MapUnit::MapSysFont
1055 && eInUnit != MapUnit::MapAppFont
1056 && eInUnit != MapUnit::MapRelative;
1072 nValue *= ImplPower10(nDigits);
1075 if ( eInUnit != eOutUnit )
1092 if ( !checkConversionUnits(eInUnit, eOutUnit) )
1094 OSL_FAIL(
"invalid parameters" );
1102 if (eFieldUnit == eOutUnit && nDigits == 0)
1107 return static_cast<sal_Int64
>(
1109 convertValue(
nValue, nDecDigits, eFieldUnit, eOutUnit ) ) );
1115 if ( eInUnit != eOutUnit )
1119 sal_Int64 nDiv = 100 * ImplPower10(nDecDigits);
1142 if ( !checkConversionUnits(eInUnit, eOutUnit) )
1144 OSL_FAIL(
"invalid parameters" );
1151 return convertValue(
nValue, nDecDigits, eFieldUnit, eOutUnit);
1157 if ( eInUnit == FieldUnit::PERCENT ||
1158 eInUnit == FieldUnit::CUSTOM ||
1159 eInUnit == FieldUnit::NONE ||
1160 eInUnit == FieldUnit::DEGREE ||
1161 eInUnit == FieldUnit::SECOND ||
1162 eInUnit == FieldUnit::MILLISECOND ||
1163 eInUnit == FieldUnit::PIXEL ||
1164 eOutUnit == MapUnit::MapPixel ||
1165 eOutUnit == MapUnit::MapSysFont ||
1166 eOutUnit == MapUnit::MapAppFont ||
1167 eOutUnit == MapUnit::MapRelative )
1169 OSL_FAIL(
"invalid parameters" );
1176 if ( nDecDigits < 0 )
1178 nValue *= ImplPower10(-nDecDigits);
1182 nValue /= ImplPower10(nDecDigits);
1185 if ( eFieldUnit != eInUnit )
1198 bool TextToValue(
const OUString& rStr,
double& rValue, sal_Int64 nBaseValue,
1203 if ( !ImplNumericGetValue( rStr,
nValue, nDecDigits, rLocaleDataWrapper ) )
1222 double nTempVal = rValue;
1224 if ( nTempVal >
GetMax() )
1225 nTempVal =
static_cast<double>(
GetMax());
1226 else if ( nTempVal <
GetMin())
1227 nTempVal =
static_cast<double>(
GetMin());
1232 : NumericFormatter(pEdit)
1243 if (eNewUnit == FieldUnit::MM_100TH)
1245 SetDecimalDigits( GetDecimalDigits() + 2 );
1268 if (
meUnit == FieldUnit::PERCENT)
1271 dValue /= ImplPower10(GetDecimalDigits());
1275 OUString
aStr = NumericFormatter::CreateFieldText(
nValue );
1277 if(
meUnit == FieldUnit::CUSTOM )
1282 if (
meUnit != FieldUnit::NONE &&
meUnit != FieldUnit::DEGREE &&
meUnit != FieldUnit::INCH &&
meUnit != FieldUnit::FOOT)
1284 if (
meUnit == FieldUnit::INCH)
1286 OUString sDoublePrime =
u"\u2033";
1287 if (aSuffix !=
"\"" && aSuffix != sDoublePrime)
1290 aSuffix = sDoublePrime;
1292 else if (
meUnit == FieldUnit::FOOT)
1294 OUString sPrime =
u"\u2032";
1295 if (aSuffix !=
"'" && aSuffix != sPrime)
1301 assert(
meUnit != FieldUnit::PERCENT);
1311 NumericFormatter::SetUserValue( nNewValue );
1319 nTempValue =
static_cast<double>(mnLastValue);
1322 if (nTempValue > mnMax)
1323 nTempValue =
static_cast<double>(mnMax);
1324 else if (nTempValue < mnMin)
1325 nTempValue =
static_cast<double>(mnMin);
1376 OUString aText = GetField()->GetText();
1380 double nTemp =
static_cast<double>(mnLastValue);
1382 mnLastValue =
static_cast<sal_Int64
>(nTemp);
1384 if ( !
aStr.isEmpty() )
1386 ImplSetText(
aStr );
1414 return calcMinimumSize(*
this, *
this);
1419 if (rKey ==
"digits")
1420 SetDecimalDigits(rValue.toInt32());
1421 else if (rKey ==
"spin-size")
1422 SetSpinSize(rValue.toInt32());
1430 sal_Int64 nRawMax =
GetMax( nNewUnit );
1431 sal_Int64 nMax = Denormalize( nRawMax );
1432 sal_Int64 nMin = Denormalize(
GetMin( nNewUnit ) );
1433 sal_Int64 nFirst = Denormalize(
GetFirst( nNewUnit ) );
1434 sal_Int64 nLast = Denormalize(
GetLast( nNewUnit ) );
1438 SetMax( Normalize( nMax ), nNewUnit );
1439 SetMin( Normalize( nMin ), nNewUnit );
1440 SetFirst( Normalize( nFirst ), nNewUnit );
1441 SetLast( Normalize( nLast ), nNewUnit );
1448 mnFirst = nNewFirst;
1484 MarkToBeReformatted(
false );
1487 if ( MustBeReformatted() && (!
GetText().isEmpty() || !IsEmptyFieldValueEnabled()) )
1500 OUString sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1501 OUString sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1502 ImplResetLocaleDataWrapper();
1503 OUString sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1504 OUString sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1505 ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep,
this );
1512 MarkToBeReformatted(
true );
1545 rJsonWriter.
put(
"unit", FieldUnitToString(
GetUnit()));
1547 getNum(
GetValue(), GetDecimalDigits(),
false,
false);
1548 rJsonWriter.
put(
"value", sValue);
1571 Size aRet(calcMinimumSize(*
this, *
this));
1597 MarkToBeReformatted(
false );
1600 if ( MustBeReformatted() && (!
GetText().isEmpty() || !IsEmptyFieldValueEnabled()) )
1613 OUString sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1614 OUString sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1615 ImplResetLocaleDataWrapper();
1616 OUString sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1617 OUString sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1618 ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep,
this );
1625 MarkToBeReformatted(
true );
1635 for ( sal_Int32
i=0;
i < nEntryCount;
i++ )
1649 return ImplNumericProcessKeyInput( rKEvt,
false, bUseThousandSep, rWrapper );
1656 return ImplNumericGetValue( rStr, rValue, nDecDigits, rWrapper,
true );
1659void CurrencyFormatter::ImplCurrencyReformat(
const OUString& rStr, OUString& rOutStr )
1662 if ( !ImplNumericGetValue( rStr, nValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(),
true ) )
1665 sal_Int64 nTempVal =
nValue;
1666 if ( nTempVal > GetMax() )
1667 nTempVal = GetMax();
1668 else if ( nTempVal < GetMin())
1669 nTempVal = GetMin();
1670 rOutStr = CreateFieldText( nTempVal );
1673CurrencyFormatter::CurrencyFormatter(
Edit* pField)
1674 : NumericFormatter(pField)
1678CurrencyFormatter::~CurrencyFormatter()
1682void CurrencyFormatter::SetValue( sal_Int64 nNewValue )
1684 SetUserValue( nNewValue );
1685 SetEmptyFieldValueData(
false );
1688OUString CurrencyFormatter::CreateFieldText( sal_Int64 nValue )
const
1690 return ImplGetLocaleDataWrapper().getCurr( nValue, GetDecimalDigits(),
1691 ImplGetLocaleDataWrapper().getCurrSymbol(),
1692 IsUseThousandSep() );
1695sal_Int64 CurrencyFormatter::GetValueFromString(
const OUString& rStr)
const
1697 sal_Int64 nTempValue;
1698 if (
ImplCurrencyGetValue( rStr, nTempValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() ) )
1700 return ClipAgainstMinMax(nTempValue);
1706void CurrencyFormatter::Reformat()
1712 ImplCurrencyReformat( GetField()->GetText(), aStr );
1714 if ( !
aStr.isEmpty() )
1716 ImplSetText( aStr );
1717 sal_Int64 nTemp = mnLastValue;
1719 mnLastValue = nTemp;
1727 , CurrencyFormatter(this)
1732void CurrencyField::dispose()
1738bool CurrencyField::PreNotify(
NotifyEvent& rNEvt )
1749bool CurrencyField::EventNotify(
NotifyEvent& rNEvt )
1752 MarkToBeReformatted(
false );
1755 if ( MustBeReformatted() && (!GetText().isEmpty() || !IsEmptyFieldValueEnabled()) )
1768 OUString sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1769 OUString sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1770 ImplResetLocaleDataWrapper();
1771 OUString sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1772 OUString sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1773 ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep,
this );
1778void CurrencyField::Modify()
1780 MarkToBeReformatted(
true );
1784void CurrencyField::Up()
1790void CurrencyField::Down()
1796void CurrencyField::First()
1802void CurrencyField::Last()
1810 , CurrencyFormatter(this)
1815void CurrencyBox::dispose()
1832bool CurrencyBox::EventNotify(
NotifyEvent& rNEvt )
1835 MarkToBeReformatted(
false );
1838 if ( MustBeReformatted() && (!GetText().isEmpty() || !IsEmptyFieldValueEnabled()) )
1851 OUString sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1852 OUString sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1853 ImplResetLocaleDataWrapper();
1854 OUString sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1855 OUString sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1856 ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep,
this );
1861void CurrencyBox::Modify()
1863 MarkToBeReformatted(
true );
1867void CurrencyBox::ReformatAll()
1870 SetUpdateMode(
false );
1871 sal_Int32 nEntryCount = GetEntryCount();
1872 for ( sal_Int32 i=0;
i < nEntryCount;
i++ )
1874 ImplCurrencyReformat( GetEntry( i ), aStr );
1876 InsertEntry( aStr, i );
1878 CurrencyFormatter::Reformat();
1879 SetUpdateMode(
true );
constexpr o3tl::Length FieldToO3tlLength(FieldUnit eU, o3tl::Length ePixelValue=o3tl::Length::px)
const LanguageTag & GetLanguageTag() const
const LocaleDataWrapper & GetNeutralLocaleDataWrapper() const
static const AllSettings & GetSettings()
Gets the application's settings.
A widget used to choose from a list of items and which has an entry.
void RemoveEntryAt(sal_Int32 nPos)
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
void SetEntryData(sal_Int32 nPos, void *pNewData)
virtual void Modify() override
sal_Int32 GetEntryCount() const
bool IsDropDownBox() const
Size CalcMinimumSize() const override
OUString GetEntry(sal_Int32 nPos) const
sal_Int32 InsertEntry(const OUString &rStr, sal_Int32 nPos=COMBOBOX_APPEND)
void * GetEntryData(sal_Int32 nPos) const
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects.
virtual bool EventNotify(NotifyEvent &rNEvt) override
DataChangedEventType GetType() const
AllSettingsFlags GetFlags() const
virtual void SetText(const OUString &rStr) override
virtual bool set_property(const OUString &rKey, const OUString &rValue) override
virtual bool PreNotify(NotifyEvent &rNEvt) override
virtual const Selection & GetSelection() const
virtual void DumpAsPropertyTree(tools::JsonWriter &rJsonWriter) override
Dumps itself and potentially its children to a property tree, to be written easily to JSON.
virtual Size CalcMinimumSizeForText(const OUString &rString) const
virtual OUString GetText() const override
sal_Unicode GetCharCode() const
const vcl::KeyCode & GetKeyCode() const
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
sal_uInt16 getCurrNegativeFormat() const
const OUString & getNumThousandSep() const
const OUString & getNumDecimalSepAlt() const
const OUString & getNumDecimalSep() const
MetricBox(vcl::Window *pParent, WinBits nWinStyle)
virtual Size CalcMinimumSize() const override
virtual void Modify() override
virtual bool PreNotify(NotifyEvent &rNEvt) override
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects.
virtual void ReformatAll() override
virtual bool EventNotify(NotifyEvent &rNEvt) override
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
virtual bool PreNotify(NotifyEvent &rNEvt) override
virtual bool set_property(const OUString &rKey, const OUString &rValue) override
virtual void DumpAsPropertyTree(tools::JsonWriter &) override
Dumps itself and potentially its children to a property tree, to be written easily to JSON.
sal_Int64 GetFirst(FieldUnit eOutUnit) const
virtual void Down() override
virtual void First() override
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects.
virtual void Last() override
MetricField(vcl::Window *pParent, WinBits nWinStyle)
virtual FactoryFunction GetUITestFactory() const override
virtual void SetUnit(FieldUnit meUnit) override
sal_Int64 GetLast(FieldUnit eOutUnit) const
virtual Size CalcMinimumSize() const override
void SetLast(sal_Int64 nNewLast, FieldUnit eInUnit)
void SetFirst(sal_Int64 nNewFirst, FieldUnit eInUnit)
virtual void Modify() override
virtual void Up() override
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
virtual bool EventNotify(NotifyEvent &rNEvt) override
const KeyEvent * GetKeyEvent() const
NotifyEventType GetType() const
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
virtual bool EventNotify(NotifyEvent &rNEvt) override
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
virtual bool PreNotify(NotifyEvent &rNEvt) override
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects.
static OUString formatPercent(double dNumber, const LanguageTag &rLangTag)
static bool isAlpha(const sal_uInt32 ch)
static bool isControl(const sal_uInt32 ch)
sal_uInt16 GetGroup() const
void SetUpdateMode(bool bUpdate)
bool IsUpdateMode() const
const AllSettings & GetSettings() const
virtual void SetValue(tools::Long nNew) override
static OUString ImplMetricToString(FieldUnit rUnit)
static OUString ImplMetricGetUnitText(std::u16string_view rStr)
static bool ImplCurrencyProcessKeyInput(const KeyEvent &rKEvt, bool bUseThousandSep, const LocaleDataWrapper &rWrapper)
static bool ImplCurrencyGetValue(const OUString &rStr, sal_Int64 &rValue, sal_uInt16 nDecDigits, const LocaleDataWrapper &rWrapper)
static bool ImplMetricProcessKeyInput(const KeyEvent &rKEvt, bool bUseThousandSep, const LocaleDataWrapper &rWrapper)
static double nonValueDoubleToValueDouble(double nValue)
static FieldUnit ImplMap2FieldUnit(MapUnit meUnit, tools::Long &nDecDigits)
static FieldUnit ImplMetricGetUnit(std::u16string_view rStr)
std::function< std::unique_ptr< UIObject >(vcl::Window *)> FactoryFunction
constexpr sal_uInt16 KEYGROUP_MISC
constexpr sal_uInt16 KEYGROUP_FKEYS
constexpr sal_uInt16 KEYGROUP_CURSOR
#define SAL_WARN(area, stream)
sal_Int64 toInt64(std::u16string_view str, sal_Int16 radix=10)
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
bool TextToValue(const OUString &rStr, double &rValue, sal_Int64 nBaseValue, sal_uInt16 nDecDigits, const LocaleDataWrapper &rLocaleDataWrapper, FieldUnit eUnit)
double ConvertDoubleValue(double nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits, FieldUnit eInUnit, FieldUnit eOutUnit)
sal_Int64 ConvertValue(sal_Int64 nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits, FieldUnit eInUnit, FieldUnit eOutUnit)
const FieldUnitStringList & ImplGetFieldUnits()
const FieldUnitStringList & ImplGetCleanedFieldUnits()