40BigInt ImplPower10( sal_uInt16 n )
45 for ( i=0;
i <
n;
i++ )
51OUString ImplGetCurr(
const LocaleDataWrapper& rLocaleDataWrapper,
const BigInt &rNumber, sal_uInt16 nDigits, std::u16string_view rCurrSymbol,
bool bShowThousandSep )
53 SAL_WARN_IF( nDigits >= 10,
"vcl",
"LongCurrency may only have 9 decimal places" );
56 return rLocaleDataWrapper.
getCurr(
static_cast<tools::Long>(rNumber), nDigits, rCurrSymbol, bShowThousandSep );
58 BigInt aTmp( ImplPower10( nDigits ) );
59 BigInt aInteger( rNumber );
62 BigInt aFraction( rNumber );
65 if ( !aInteger.IsZero() )
70 if ( rNumber.
IsNeg() )
73 OUStringBuffer aTemplate(rLocaleDataWrapper.
getCurr(
static_cast<tools::Long>(aFraction), nDigits, rCurrSymbol, bShowThousandSep ));
74 while( !aInteger.IsZero() )
79 if( !aInteger.IsZero() )
82 OUString aFractionStr = rLocaleDataWrapper.
getNum(
static_cast<tools::Long>(aFraction), 0 );
84 sal_Int32 nSPos = aTemplate.indexOf(
'1' );
87 if ( aFractionStr.getLength() == 1 )
88 aTemplate[ nSPos ] = aFractionStr[0];
91 aTemplate.remove( nSPos, 1 );
92 aTemplate.insert( nSPos, aFractionStr );
96 return aTemplate.makeStringAndClear();
102 OUString
aStr = rStr;
103 OUStringBuffer aStr1;
104 OUStringBuffer aStr2;
106 bool bNegative =
false;
109 if ( rStr.isEmpty() )
113 aStr = string::strip(aStr,
' ');
122 aStr1 =
aStr.subView( 0, nDecPos );
123 aStr2.append(
aStr.subView(nDecPos+1));
129 if ( (aStr[ 0 ] ==
'(') && (aStr[
aStr.getLength()-1 ] ==
')') )
133 for (sal_Int32 i=0;
i <
aStr.getLength();
i++ )
135 if ( (aStr[ i ] >=
'0') && (aStr[ i ] <=
'9') )
137 else if ( aStr[ i ] ==
'-' )
144 if ( !bNegative && !
aStr.isEmpty() )
147 if ( (nFormat == 3) || (nFormat == 6) ||
148 (nFormat == 7) || (nFormat == 10) )
150 for (sal_Int32 i =
aStr.getLength()-1; i > 0; i++ )
152 if ( (aStr[ i ] >=
'0') && (aStr[ i ] <=
'9') )
154 else if ( aStr[ i ] ==
'-' )
164 for (sal_Int32 i=0;
i < aStr1.getLength(); )
166 if ( (aStr1[ i ] >=
'0') && (aStr1[ i ] <=
'9') )
169 aStr1.remove( i, 1 );
171 for (sal_Int32 i=0;
i < aStr2.getLength(); )
173 if ((aStr2[i] >=
'0') && (aStr2[i] <=
'9'))
179 if ( aStr1.isEmpty() && aStr2.isEmpty())
182 if ( aStr1.isEmpty() )
185 aStr1.insert( 0,
'-');
189 if (aStr2.getLength() > nDecDigits)
191 if (aStr2[nDecDigits] >=
'5')
193 string::truncateToLength(aStr2, nDecDigits);
195 string::padToLength(aStr2, nDecDigits,
'0');
198 aStr = aStr1.makeStringAndClear();
228 const OUString& rCurrencySymbol = !m_aCurrencySymbol.isEmpty() ? m_aCurrencySymbol : rLocaleDataWrapper.
getCurrSymbol();
230 OUString aText = ImplGetCurr(rLocaleDataWrapper, fValue, GetDecimalDigits(), rCurrencySymbol, m_bThousandSep);
231 ImplSetTextImpl(aText,
nullptr);
250 sal_uInt16 nDecDigits,
252 LongCurrencyFormatter
const & rFormatter )
260 if ( nTempVal > nMax )
262 else if ( nTempVal < nMin )
265 rOutStr = ImplGetCurr( rLocaleDataWrapper, nTempVal, nDecDigits, rFormatter.GetCurrencySymbol(),
true );
270void LongCurrencyFormatter::ImpInit()
277 SetDecimalDigits( 0 );
280LongCurrencyFormatter::LongCurrencyFormatter(
Edit* pEdit)
286LongCurrencyFormatter::~LongCurrencyFormatter()
290OUString
const & LongCurrencyFormatter::GetCurrencySymbol()
const
295void LongCurrencyFormatter::SetValue(
const BigInt& rNewValue)
297 SetUserValue(rNewValue);
298 SetEmptyFieldValueData(
false );
301void LongCurrencyFormatter::SetUserValue(
BigInt nNewValue )
303 if ( nNewValue > mnMax )
305 else if ( nNewValue < mnMin )
307 mnLastValue = nNewValue;
313 if ( GetField()->HasFocus() )
315 Selection aSelection = GetField()->GetSelection();
316 GetField()->SetText( aStr );
317 GetField()->SetSelection( aSelection );
320 GetField()->SetText( aStr );
321 MarkToBeReformatted(
false );
324BigInt LongCurrencyFormatter::GetValue()
const
332 if ( nTempValue > mnMax )
334 else if ( nTempValue < mnMin )
342void LongCurrencyFormatter::Reformat()
347 if ( GetField()->GetText().isEmpty() && ImplGetEmptyFieldValue() )
356 if ( !
aStr.isEmpty() )
358 GetField()->SetText( aStr );
359 MarkToBeReformatted(
false );
366void LongCurrencyFormatter::ReformatAll()
371void LongCurrencyFormatter::SetDecimalDigits( sal_uInt16 nDigits )
376 mnDecimalDigits = nDigits;
384 , LongCurrencyFormatter(this)
389bool LongCurrencyBox::EventNotify(
NotifyEvent& rNEvt )
393 MarkToBeReformatted(
false );
397 if ( MustBeReformatted() )
406void LongCurrencyBox::Modify()
408 MarkToBeReformatted(
true );
412void LongCurrencyBox::ReformatAll()
415 SetUpdateMode(
false );
416 const sal_Int32 nEntryCount = GetEntryCount();
417 for ( sal_Int32 i=0;
i < nEntryCount; ++
i )
423 InsertEntry( aStr, i );
425 LongCurrencyFormatter::Reformat();
426 SetUpdateMode(
true );
const LocaleDataWrapper & GetLocaleDataWrapper() 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.
virtual void Modify() override
virtual bool EventNotify(NotifyEvent &rNEvt) override
sal_uInt16 getCurrNegativeFormat() const
OUString getCurr(sal_Int64 nNumber, sal_uInt16 nDecimals, std::u16string_view rCurrencySymbol, bool bUseThousandSep=true) const
OUString getNum(sal_Int64 nNumber, sal_uInt16 nDecimals, bool bUseThousandSep=true, bool bTrailingZeros=true) const
const OUString & getCurrSymbol() const
const OUString & getNumDecimalSepAlt() const
const OUString & getNumDecimalSep() const
NotifyEventType GetType() const
virtual void SetValue(tools::Long nNew) override
static bool ImplCurrencyGetValue(const OUString &rStr, sal_Int64 &rValue, sal_uInt16 nDecDigits, const LocaleDataWrapper &rWrapper)
#define SAL_WARN_IF(condition, area, stream)
static bool ImplLongCurrencyGetValue(const OUString &rStr, BigInt &rValue, sal_uInt16 nDecDigits, const LocaleDataWrapper &rLocaleDataWrapper)
bool ImplLongCurrencyReformat(const OUString &rStr, BigInt const &nMin, BigInt const &nMax, sal_uInt16 nDecDigits, const LocaleDataWrapper &rLocaleDataWrapper, OUString &rOutStr, LongCurrencyFormatter const &rFormatter)
const LocaleDataWrapper & GetLocaleDataWrapper(LanguageType nLang)
IMPL_LINK_NOARG(HexColorControl, OnAsyncModifyHdl, void *, void)
IMPL_LINK(CustomWeld, DoResize, const Size &, rSize, void)