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;
318 aStrFrac.append(nFrac2Dec);
320 nDecPos = aStrFrac.indexOf(
'.');
323 aStr1.append(aStrFrac.getStr(), nDecPos);
324 aStr2.append(aStrFrac.getStr()+nDecPos+1);
332 if (aStr2.getLength() > nDecDigits)
334 if (aStr2[nDecDigits] >=
'5')
336 string::truncateToLength(aStr2, nDecDigits);
338 if (aStr2.getLength() < nDecDigits)
339 string::padToLength(aStr2, nDecDigits,
'0');
341 aStr = aStr1 + aStr2;
348 sal_Int32
nIndex = bNegative ? 1 : 0;
349 while (nIndex <
aStr.getLength() && aStr[nIndex] ==
'0')
351 if( nIndex <
aStr.getLength() )
370void ImplUpdateSeparatorString( OUString& io_rText,
371 std::u16string_view rOldDecSep, std::u16string_view rNewDecSep,
372 std::u16string_view rOldThSep, std::u16string_view rNewThSep )
374 OUStringBuffer
aBuf( io_rText.getLength() );
375 sal_Int32 nIndexDec = 0, nIndexTh = 0,
nIndex = 0;
378 while( nIndex != -1 )
380 nIndexDec = io_rText.indexOf( rOldDecSep, nIndex );
381 nIndexTh = io_rText.indexOf( rOldThSep, nIndex );
382 if( (nIndexTh != -1 && nIndexDec != -1 && nIndexTh < nIndexDec )
383 || (nIndexTh != -1 && nIndexDec == -1)
386 aBuf.append( pBuffer + nIndex, nIndexTh - nIndex );
387 aBuf.append( rNewThSep );
388 nIndex = nIndexTh + rOldThSep.size();
390 else if( nIndexDec != -1 )
392 aBuf.append( pBuffer + nIndex, nIndexDec - nIndex );
393 aBuf.append( rNewDecSep );
394 nIndex = nIndexDec + rOldDecSep.size();
398 aBuf.append( pBuffer + nIndex );
403 io_rText =
aBuf.makeStringAndClear();
406void ImplUpdateSeparators( std::u16string_view rOldDecSep, std::u16string_view rNewDecSep,
407 std::u16string_view rOldThSep, std::u16string_view rNewThSep,
410 bool bChangeDec = (rOldDecSep != rNewDecSep);
411 bool bChangeTh = (rOldThSep != rNewThSep );
413 if( !(bChangeDec || bChangeTh) )
418 OUString aText = pEdit->
GetText();
419 ImplUpdateSeparatorString( aText, rOldDecSep, rNewDecSep, rOldThSep, rNewThSep );
427 for ( sal_Int32 i=0;
i < nEntryCount;
i++ )
431 ImplUpdateSeparatorString( aText, rOldDecSep, rNewDecSep, rOldThSep, rNewThSep );
542void NumericFormatter::FormatValue(
Selection const * pNewSelection)
545 ImplSetText(CreateFieldText(mnLastValue), pNewSelection);
546 mbFormatting =
false;
549void NumericFormatter::ImplNumericReformat()
555NumericFormatter::NumericFormatter(
Edit* pEdit)
562 , mbFormatting(false)
568 , mbThousandSep(true)
573NumericFormatter::~NumericFormatter()
577void NumericFormatter::SetMin( sal_Int64 nNewMin )
580 if ( !IsEmptyFieldValue() )
584void NumericFormatter::SetMax( sal_Int64 nNewMax )
587 if ( !IsEmptyFieldValue() )
591void NumericFormatter::SetUseThousandSep(
bool bValue )
593 mbThousandSep = bValue;
597void NumericFormatter::SetDecimalDigits( sal_uInt16 nDigits )
599 mnDecimalDigits = nDigits;
603void NumericFormatter::SetValue( sal_Int64 nNewValue )
605 SetUserValue( nNewValue );
606 SetEmptyFieldValueData(
false );
609OUString NumericFormatter::CreateFieldText( sal_Int64 nValue )
const
611 return ImplGetLocaleDataWrapper().getNum( nValue, GetDecimalDigits(), IsUseThousandSep(),
true );
614void NumericFormatter::ImplSetUserValue( sal_Int64 nNewValue,
Selection const * pNewSelection )
616 nNewValue = ClipAgainstMinMax(nNewValue);
617 mnLastValue = nNewValue;
620 FormatValue(pNewSelection);
623void NumericFormatter::SetUserValue( sal_Int64 nNewValue )
625 ImplSetUserValue( nNewValue );
628sal_Int64 NumericFormatter::GetValueFromString(
const OUString& rStr)
const
630 sal_Int64 nTempValue;
632 if (ImplNumericGetValue(rStr, nTempValue,
633 GetDecimalDigits(), ImplGetLocaleDataWrapper()))
635 return ClipAgainstMinMax(nTempValue);
641OUString NumericFormatter::GetValueString()
const
644 getNum(
GetValue(), GetDecimalDigits(),
false,
false);
648void NumericFormatter::SetValueFromString(
const OUString& rStr)
652 if (ImplNumericGetValue(rStr, nValue, GetDecimalDigits(),
655 ImplNewFieldValue(nValue);
659 SAL_WARN(
"vcl",
"fail to convert the value: " << rStr );
663sal_Int64 NumericFormatter::GetValue()
const
668 return GetField() ? GetValueFromString(GetField()->GetText()) : 0;
671sal_Int64 NumericFormatter::Normalize( sal_Int64 nValue )
const
673 return (nValue * ImplPower10( GetDecimalDigits() ) );
676sal_Int64 NumericFormatter::Denormalize( sal_Int64 nValue )
const
678 sal_Int64 nFactor = ImplPower10( GetDecimalDigits() );
680 if ((nValue < ( SAL_MIN_INT64 + nFactor )) ||
681 (nValue > ( SAL_MAX_INT64 - nFactor )))
683 return ( nValue / nFactor );
688 sal_Int64 nHalf = nFactor / 2;
689 return ((nValue - nHalf) / nFactor );
693 sal_Int64 nHalf = nFactor / 2;
694 return ((nValue + nHalf) / nFactor );
698void NumericFormatter::Reformat()
703 if ( GetField()->GetText().isEmpty() && ImplGetEmptyFieldValue() )
706 ImplNumericReformat();
709void NumericFormatter::FieldUp()
712 sal_Int64 nRemainder =
nValue % mnSpinSize;
714 nValue = (nRemainder == 0) ? nValue + mnSpinSize : nValue + mnSpinSize - nRemainder;
716 nValue = (nRemainder == 0) ? nValue + mnSpinSize : nValue - nRemainder;
718 nValue = ClipAgainstMinMax(nValue);
720 ImplNewFieldValue( nValue );
723void NumericFormatter::FieldDown()
726 sal_Int64 nRemainder =
nValue % mnSpinSize;
728 nValue = (nRemainder == 0) ? nValue - mnSpinSize : nValue - nRemainder;
730 nValue = (nRemainder == 0) ? nValue - mnSpinSize : nValue - mnSpinSize - nRemainder;
732 nValue = ClipAgainstMinMax(nValue);
734 ImplNewFieldValue( nValue );
737void NumericFormatter::FieldFirst()
739 ImplNewFieldValue( mnFirst );
742void NumericFormatter::FieldLast()
744 ImplNewFieldValue( mnLast );
747void NumericFormatter::ImplNewFieldValue( sal_Int64 nNewValue )
757 Selection aSelection = GetField()->GetSelection();
759 OUString aText = GetField()->GetText();
761 if (
static_cast<sal_Int32
>(aSelection.
Max()) == aText.getLength() )
763 if ( !aSelection.
Len() )
768 sal_Int64 nOldLastValue = mnLastValue;
769 ImplSetUserValue( nNewValue, &aSelection );
770 mnLastValue = nOldLastValue;
773 if ( GetField()->GetText() != aText )
775 GetField()->SetModifyFlag();
776 GetField()->Modify();
780sal_Int64 NumericFormatter::ClipAgainstMinMax(sal_Int64 nValue)
const
784 else if (nValue < mnMin)
791 Size calcMinimumSize(
const Edit &rSpinField,
const NumericFormatter &rFormatter)
796 nTextLen = OUString(OUString::number(rFormatter.GetMin())).getLength();
797 string::padToLength(aBuf, nTextLen,
'9');
799 rFormatter.CreateFieldText(OUString::unacquired(aBuf).toInt64()));
802 nTextLen = OUString(OUString::number(rFormatter.GetMax())).getLength();
803 string::padToLength(aBuf, nTextLen,
'9');
805 rFormatter.CreateFieldText(OUString::unacquired(aBuf).toInt64()));
809 std::max(aMinTextSize.
Height(), aMaxTextSize.
Height()));
811 OUStringBuffer sBuf(
"999999999");
812 sal_uInt16 nDigits = rFormatter.GetDecimalDigits();
816 string::padToLength(aBuf,
aBuf.getLength() + nDigits,
'9');
819 aRet.
setWidth( std::min(aRet.Width(), aMaxTextSize.
Width()) );
827 , NumericFormatter(this)
834void NumericBox::dispose()
840Size NumericBox::CalcMinimumSize()
const
842 Size aRet(calcMinimumSize(*
this, *
this));
847 aRet.setWidth( std::max(aRet.Width(), aComboSugg.Width()) );
848 aRet.setHeight( std::max(aRet.Height(), aComboSugg.Height()) );
858 if ( ImplNumericProcessKeyInput( *rNEvt.
GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), ImplGetLocaleDataWrapper() ) )
868 MarkToBeReformatted(
false );
871 if ( MustBeReformatted() && (!GetText().isEmpty() || !IsEmptyFieldValueEnabled()) )
884 OUString sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
885 OUString sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
886 ImplResetLocaleDataWrapper();
887 OUString sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
888 OUString sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
889 ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep,
this );
894void NumericBox::Modify()
896 MarkToBeReformatted(
true );
900void NumericBox::ImplNumericReformat(
const OUString& rStr, sal_Int64& rValue,
903 if (ImplNumericGetValue(rStr, rValue, GetDecimalDigits(), ImplGetLocaleDataWrapper()))
905 sal_Int64 nTempVal = ClipAgainstMinMax(rValue);
906 rOutStr = CreateFieldText( nTempVal );
910void NumericBox::ReformatAll()
914 SetUpdateMode(
false );
915 sal_Int32 nEntryCount = GetEntryCount();
916 for ( sal_Int32 i=0;
i < nEntryCount;
i++ )
918 ImplNumericReformat( GetEntry( i ), nValue, aStr );
920 InsertEntry( aStr, i );
922 NumericFormatter::Reformat();
923 SetUpdateMode(
true );
930 return ImplNumericProcessKeyInput( rKEvt,
false, bUseThousandSep, rWrapper );
937 for (sal_Int32
i =
static_cast<sal_Int32
>(rStr.size())-1;
i >= 0; --
i)
948 return aStr.makeStringAndClear();
958 if (elem.second == rUnit)
967 FieldUnit StringToMetric(
const OUString &rMetricString)
970 OUString
aStr = rMetricString.toAsciiLowerCase().replaceAll(
" ",
"");
973 if ( elem.first == aStr )
977 return FieldUnit::NONE;
984 return StringToMetric(
aStr);
991 case MapUnit::Map100thMM :
993 return FieldUnit::MM;
994 case MapUnit::Map10thMM :
996 return FieldUnit::MM;
997 case MapUnit::MapMM :
998 return FieldUnit::MM;
999 case MapUnit::MapCM :
1000 return FieldUnit::CM;
1001 case MapUnit::Map1000thInch :
1003 return FieldUnit::INCH;
1004 case MapUnit::Map100thInch :
1006 return FieldUnit::INCH;
1007 case MapUnit::Map10thInch :
1009 return FieldUnit::INCH;
1010 case MapUnit::MapInch :
1011 return FieldUnit::INCH;
1012 case MapUnit::MapPoint :
1013 return FieldUnit::POINT;
1014 case MapUnit::MapTwip :
1015 return FieldUnit::TWIP;
1017 OSL_FAIL(
"default eInUnit" );
1020 return FieldUnit::NONE;
1030 sal_Int64
ConvertValue(sal_Int64 nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits,
1043 nLong =
static_cast<sal_Int64
>( std::round(nDouble) );
1053 return eOutUnit != FieldUnit::PERCENT
1054 && eOutUnit != FieldUnit::CUSTOM
1055 && eOutUnit != FieldUnit::NONE
1056 && eInUnit != MapUnit::MapPixel
1057 && eInUnit != MapUnit::MapSysFont
1058 && eInUnit != MapUnit::MapAppFont
1059 && eInUnit != MapUnit::MapRelative;
1075 nValue *= ImplPower10(nDigits);
1078 if ( eInUnit != eOutUnit )
1095 if ( !checkConversionUnits(eInUnit, eOutUnit) )
1097 OSL_FAIL(
"invalid parameters" );
1105 if (eFieldUnit == eOutUnit && nDigits == 0)
1110 return static_cast<sal_Int64
>(
1112 convertValue(
nValue, nDecDigits, eFieldUnit, eOutUnit ) ) );
1118 if ( eInUnit != eOutUnit )
1122 sal_Int64 nDiv = 100 * ImplPower10(nDecDigits);
1145 if ( !checkConversionUnits(eInUnit, eOutUnit) )
1147 OSL_FAIL(
"invalid parameters" );
1154 return convertValue(
nValue, nDecDigits, eFieldUnit, eOutUnit);
1160 if ( eInUnit == FieldUnit::PERCENT ||
1161 eInUnit == FieldUnit::CUSTOM ||
1162 eInUnit == FieldUnit::NONE ||
1163 eInUnit == FieldUnit::DEGREE ||
1164 eInUnit == FieldUnit::SECOND ||
1165 eInUnit == FieldUnit::MILLISECOND ||
1166 eInUnit == FieldUnit::PIXEL ||
1167 eOutUnit == MapUnit::MapPixel ||
1168 eOutUnit == MapUnit::MapSysFont ||
1169 eOutUnit == MapUnit::MapAppFont ||
1170 eOutUnit == MapUnit::MapRelative )
1172 OSL_FAIL(
"invalid parameters" );
1179 if ( nDecDigits < 0 )
1181 nValue *= ImplPower10(-nDecDigits);
1185 nValue /= ImplPower10(nDecDigits);
1188 if ( eFieldUnit != eInUnit )
1201 bool TextToValue(
const OUString& rStr,
double& rValue, sal_Int64 nBaseValue,
1206 if ( !ImplNumericGetValue( rStr,
nValue, nDecDigits, rLocaleDataWrapper ) )
1225 double nTempVal = rValue;
1227 if ( nTempVal >
GetMax() )
1228 nTempVal =
static_cast<double>(
GetMax());
1229 else if ( nTempVal <
GetMin())
1230 nTempVal =
static_cast<double>(
GetMin());
1235 : NumericFormatter(pEdit)
1246 if (eNewUnit == FieldUnit::MM_100TH)
1248 SetDecimalDigits( GetDecimalDigits() + 2 );
1271 if (
meUnit == FieldUnit::PERCENT)
1274 dValue /= ImplPower10(GetDecimalDigits());
1278 OUString
aStr = NumericFormatter::CreateFieldText(
nValue );
1280 if(
meUnit == FieldUnit::CUSTOM )
1285 if (
meUnit != FieldUnit::NONE &&
meUnit != FieldUnit::DEGREE &&
meUnit != FieldUnit::INCH &&
meUnit != FieldUnit::FOOT)
1287 if (
meUnit == FieldUnit::INCH)
1289 OUString sDoublePrime =
u"\u2033";
1290 if (aSuffix !=
"\"" && aSuffix != sDoublePrime)
1293 aSuffix = sDoublePrime;
1295 else if (
meUnit == FieldUnit::FOOT)
1297 OUString sPrime =
u"\u2032";
1298 if (aSuffix !=
"'" && aSuffix != sPrime)
1304 assert(
meUnit != FieldUnit::PERCENT);
1314 NumericFormatter::SetUserValue( nNewValue );
1322 nTempValue =
static_cast<double>(mnLastValue);
1325 if (nTempValue > mnMax)
1326 nTempValue =
static_cast<double>(mnMax);
1327 else if (nTempValue < mnMin)
1328 nTempValue =
static_cast<double>(mnMin);
1379 OUString aText = GetField()->GetText();
1383 double nTemp =
static_cast<double>(mnLastValue);
1385 mnLastValue =
static_cast<sal_Int64
>(nTemp);
1387 if ( !
aStr.isEmpty() )
1389 ImplSetText(
aStr );
1417 return calcMinimumSize(*
this, *
this);
1422 if (rKey ==
"digits")
1423 SetDecimalDigits(rValue.toInt32());
1424 else if (rKey ==
"spin-size")
1425 SetSpinSize(rValue.toInt32());
1433 sal_Int64 nRawMax =
GetMax( nNewUnit );
1434 sal_Int64 nMax = Denormalize( nRawMax );
1435 sal_Int64 nMin = Denormalize(
GetMin( nNewUnit ) );
1436 sal_Int64 nFirst = Denormalize(
GetFirst( nNewUnit ) );
1437 sal_Int64 nLast = Denormalize(
GetLast( nNewUnit ) );
1441 SetMax( Normalize( nMax ), nNewUnit );
1442 SetMin( Normalize( nMin ), nNewUnit );
1443 SetFirst( Normalize( nFirst ), nNewUnit );
1444 SetLast( Normalize( nLast ), nNewUnit );
1451 mnFirst = nNewFirst;
1487 MarkToBeReformatted(
false );
1490 if ( MustBeReformatted() && (!
GetText().isEmpty() || !IsEmptyFieldValueEnabled()) )
1503 OUString sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1504 OUString sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1505 ImplResetLocaleDataWrapper();
1506 OUString sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1507 OUString sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1508 ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep,
this );
1515 MarkToBeReformatted(
true );
1548 rJsonWriter.
put(
"unit", FieldUnitToString(
GetUnit()));
1550 getNum(
GetValue(), GetDecimalDigits(),
false,
false);
1551 rJsonWriter.
put(
"value", sValue);
1574 Size aRet(calcMinimumSize(*
this, *
this));
1600 MarkToBeReformatted(
false );
1603 if ( MustBeReformatted() && (!
GetText().isEmpty() || !IsEmptyFieldValueEnabled()) )
1616 OUString sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1617 OUString sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1618 ImplResetLocaleDataWrapper();
1619 OUString sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1620 OUString sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1621 ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep,
this );
1628 MarkToBeReformatted(
true );
1638 for ( sal_Int32
i=0;
i < nEntryCount;
i++ )
1652 return ImplNumericProcessKeyInput( rKEvt,
false, bUseThousandSep, rWrapper );
1659 return ImplNumericGetValue( rStr, rValue, nDecDigits, rWrapper,
true );
1662void CurrencyFormatter::ImplCurrencyReformat(
const OUString& rStr, OUString& rOutStr )
1665 if ( !ImplNumericGetValue( rStr, nValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(),
true ) )
1668 sal_Int64 nTempVal =
nValue;
1669 if ( nTempVal > GetMax() )
1670 nTempVal = GetMax();
1671 else if ( nTempVal < GetMin())
1672 nTempVal = GetMin();
1673 rOutStr = CreateFieldText( nTempVal );
1676CurrencyFormatter::CurrencyFormatter(
Edit* pField)
1677 : NumericFormatter(pField)
1681CurrencyFormatter::~CurrencyFormatter()
1685void CurrencyFormatter::SetValue( sal_Int64 nNewValue )
1687 SetUserValue( nNewValue );
1688 SetEmptyFieldValueData(
false );
1691OUString CurrencyFormatter::CreateFieldText( sal_Int64 nValue )
const
1693 return ImplGetLocaleDataWrapper().getCurr( nValue, GetDecimalDigits(),
1694 ImplGetLocaleDataWrapper().getCurrSymbol(),
1695 IsUseThousandSep() );
1698sal_Int64 CurrencyFormatter::GetValueFromString(
const OUString& rStr)
const
1700 sal_Int64 nTempValue;
1701 if (
ImplCurrencyGetValue( rStr, nTempValue, GetDecimalDigits(), ImplGetLocaleDataWrapper() ) )
1703 return ClipAgainstMinMax(nTempValue);
1709void CurrencyFormatter::Reformat()
1715 ImplCurrencyReformat( GetField()->GetText(), aStr );
1717 if ( !
aStr.isEmpty() )
1719 ImplSetText( aStr );
1720 sal_Int64 nTemp = mnLastValue;
1722 mnLastValue = nTemp;
1730 , CurrencyFormatter(this)
1735void CurrencyField::dispose()
1741bool CurrencyField::PreNotify(
NotifyEvent& rNEvt )
1752bool CurrencyField::EventNotify(
NotifyEvent& rNEvt )
1755 MarkToBeReformatted(
false );
1758 if ( MustBeReformatted() && (!GetText().isEmpty() || !IsEmptyFieldValueEnabled()) )
1771 OUString sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1772 OUString sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1773 ImplResetLocaleDataWrapper();
1774 OUString sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1775 OUString sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1776 ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep,
this );
1781void CurrencyField::Modify()
1783 MarkToBeReformatted(
true );
1787void CurrencyField::Up()
1793void CurrencyField::Down()
1799void CurrencyField::First()
1805void CurrencyField::Last()
1813 , CurrencyFormatter(this)
1818void CurrencyBox::dispose()
1835bool CurrencyBox::EventNotify(
NotifyEvent& rNEvt )
1838 MarkToBeReformatted(
false );
1841 if ( MustBeReformatted() && (!GetText().isEmpty() || !IsEmptyFieldValueEnabled()) )
1854 OUString sOldDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1855 OUString sOldThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1856 ImplResetLocaleDataWrapper();
1857 OUString sNewDecSep = ImplGetLocaleDataWrapper().getNumDecimalSep();
1858 OUString sNewThSep = ImplGetLocaleDataWrapper().getNumThousandSep();
1859 ImplUpdateSeparators( sOldDecSep, sNewDecSep, sOldThSep, sNewThSep,
this );
1864void CurrencyBox::Modify()
1866 MarkToBeReformatted(
true );
1870void CurrencyBox::ReformatAll()
1873 SetUpdateMode(
false );
1874 sal_Int32 nEntryCount = GetEntryCount();
1875 for ( sal_Int32 i=0;
i < nEntryCount;
i++ )
1877 ImplCurrencyReformat( GetEntry( i ), aStr );
1879 InsertEntry( aStr, i );
1881 CurrencyFormatter::Reformat();
1882 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 bool set_property(const OString &rKey, const OUString &rValue) override
virtual void SetText(const OUString &rStr) 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 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 bool set_property(const OString &rKey, const OUString &rValue) override
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 bool isAlpha(const sal_Unicode ch)
static OUString formatPercent(double dNumber, const LanguageTag &rLangTag)
static bool isControl(const sal_Unicode 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()