Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <comphelper/string.hxx>
30 : : #include <sot/object.hxx>
31 : : #include <sot/factory.hxx>
32 : : #include <tools/debug.hxx>
33 : : #include <tools/bigint.hxx>
34 : :
35 : : #include <tools/rc.h>
36 : :
37 : : #include <vcl/event.hxx>
38 : : #include <vcl/svapp.hxx>
39 : : #include <vcl/longcurr.hxx>
40 : :
41 : : #include <svdata.hxx>
42 : :
43 : : #include <unotools/localedatawrapper.hxx>
44 : :
45 : : using namespace ::comphelper;
46 : :
47 : : // =======================================================================
48 : :
49 : : #define FORMAT_LONGCURRENCY 4
50 : :
51 : : // =======================================================================
52 : :
53 : 0 : static BigInt ImplPower10( sal_uInt16 n )
54 : : {
55 : : sal_uInt16 i;
56 : 0 : BigInt nValue = 1;
57 : :
58 [ # # ]: 0 : for ( i=0; i < n; i++ )
59 [ # # ]: 0 : nValue *= 10;
60 : :
61 : 0 : return nValue;
62 : : }
63 : :
64 : : // -----------------------------------------------------------------------
65 : :
66 : 0 : static XubString ImplGetCurr( const LocaleDataWrapper& rLocaleDataWrapper, const BigInt &rNumber, sal_uInt16 nDigits, const String& rCurrSymbol, sal_Bool bShowThousandSep )
67 : : {
68 : : DBG_ASSERT( nDigits < 10, "LongCurrency duerfen nur maximal 9 Nachkommastellen haben" );
69 : :
70 [ # # ][ # # ]: 0 : if ( rNumber.IsZero() || (long)rNumber )
[ # # ][ # # ]
[ # # ]
71 [ # # ][ # # ]: 0 : return rLocaleDataWrapper.getCurr( (long)rNumber, nDigits, rCurrSymbol, bShowThousandSep );
[ # # ][ # # ]
72 : :
73 [ # # ]: 0 : BigInt aTmp( ImplPower10( nDigits ) );
74 [ # # ]: 0 : BigInt aInteger( rNumber );
75 [ # # ]: 0 : aInteger.Abs();
76 [ # # ]: 0 : aInteger /= aTmp;
77 [ # # ]: 0 : BigInt aFraction( rNumber );
78 [ # # ]: 0 : aFraction.Abs();
79 [ # # ]: 0 : aFraction %= aTmp;
80 [ # # ][ # # ]: 0 : if ( !aInteger.IsZero() )
81 : : {
82 [ # # ]: 0 : aFraction += aTmp;
83 [ # # ]: 0 : aTmp = 1000000000L;
84 : : }
85 [ # # ][ # # ]: 0 : if ( rNumber.IsNeg() )
86 [ # # ][ # # ]: 0 : aFraction *= -1;
87 : :
88 [ # # ][ # # ]: 0 : XubString aTemplate = rLocaleDataWrapper.getCurr( (long)aFraction, nDigits, rCurrSymbol, bShowThousandSep );
[ # # ][ # # ]
89 [ # # ][ # # ]: 0 : while( !aInteger.IsZero() )
90 : : {
91 [ # # ]: 0 : aFraction = aInteger;
92 [ # # ]: 0 : aFraction %= aTmp;
93 [ # # ]: 0 : aInteger /= aTmp;
94 [ # # ][ # # ]: 0 : if( !aInteger.IsZero() )
95 [ # # ]: 0 : aFraction += aTmp;
96 : :
97 [ # # ][ # # ]: 0 : XubString aFractionStr = rLocaleDataWrapper.getNum( (long)aFraction, 0 );
[ # # ]
98 : :
99 [ # # ]: 0 : xub_StrLen nSPos = aTemplate.Search( '1' );
100 [ # # ]: 0 : if ( aFractionStr.Len() == 1 )
101 [ # # ]: 0 : aTemplate.SetChar( nSPos, aFractionStr.GetChar( 0 ) );
102 : : else
103 : : {
104 [ # # ]: 0 : aTemplate.Erase( nSPos, 1 );
105 [ # # ]: 0 : aTemplate.Insert( aFractionStr, nSPos );
106 : : }
107 [ # # ]: 0 : }
108 : :
109 [ # # ][ # # ]: 0 : return aTemplate;
110 : : }
111 : :
112 : : // -----------------------------------------------------------------------
113 : :
114 : 0 : static sal_Bool ImplNumericProcessKeyInput( Edit*, const KeyEvent& rKEvt,
115 : : sal_Bool bStrictFormat, sal_Bool bThousandSep,
116 : : const LocaleDataWrapper& rLocaleDataWrapper )
117 : : {
118 [ # # ]: 0 : if ( !bStrictFormat )
119 : 0 : return sal_False;
120 : : else
121 : : {
122 : 0 : sal_Unicode cChar = rKEvt.GetCharCode();
123 : 0 : sal_uInt16 nGroup = rKEvt.GetKeyCode().GetGroup();
124 : :
125 [ # # ][ # # ]: 0 : if ( (nGroup == KEYGROUP_FKEYS) || (nGroup == KEYGROUP_CURSOR) ||
[ # # ][ # # ]
[ # # # #
# # ][ # # ]
[ # # ][ # # ]
126 : : (nGroup == KEYGROUP_MISC) ||
127 : : ((cChar >= '0') && (cChar <= '9')) ||
128 : 0 : (bThousandSep && string::equals(rLocaleDataWrapper.getNumThousandSep(), cChar)) ||
129 : 0 : (string::equals(rLocaleDataWrapper.getNumDecimalSep(), cChar) ) ||
130 : : (cChar == '-') )
131 : 0 : return sal_False;
132 : : else
133 : 0 : return sal_True;
134 : : }
135 : : }
136 : :
137 : : // -----------------------------------------------------------------------
138 : :
139 : 0 : static sal_Bool ImplNumericGetValue( const XubString& rStr, BigInt& rValue,
140 : : sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper,
141 : : sal_Bool bCurrency = sal_False )
142 : : {
143 [ # # ]: 0 : XubString aStr = rStr;
144 [ # # ]: 0 : XubString aStr1;
145 [ # # ]: 0 : XubString aStr2;
146 : : sal_uInt16 nDecPos;
147 : 0 : sal_Bool bNegative = sal_False;
148 : : xub_StrLen i;
149 : :
150 : : // Reaktion auf leeren String
151 [ # # ]: 0 : if ( !rStr.Len() )
152 : 0 : return sal_False;
153 : :
154 : : // Fuehrende und nachfolgende Leerzeichen entfernen
155 [ # # ][ # # ]: 0 : aStr = string::strip(aStr, ' ');
[ # # ]
156 : :
157 : : // Position des Dezimalpunktes suchen
158 [ # # ][ # # ]: 0 : nDecPos = aStr.Search( rLocaleDataWrapper.getNumDecimalSep() );
[ # # ][ # # ]
159 : :
160 [ # # ]: 0 : if ( nDecPos != STRING_NOTFOUND )
161 : : {
162 [ # # ][ # # ]: 0 : aStr1 = aStr.Copy( 0, nDecPos );
[ # # ]
163 [ # # ][ # # ]: 0 : aStr2 = aStr.Copy( nDecPos+1 );
[ # # ]
164 : : }
165 : : else
166 [ # # ]: 0 : aStr1 = aStr;
167 : :
168 : : // Negativ ?
169 [ # # ]: 0 : if ( bCurrency )
170 : : {
171 [ # # ][ # # ]: 0 : if ( (aStr.GetChar( 0 ) == '(') && (aStr.GetChar( aStr.Len()-1 ) == ')') )
[ # # ]
172 : 0 : bNegative = sal_True;
173 [ # # ]: 0 : if ( !bNegative )
174 : : {
175 [ # # ]: 0 : for ( i=0; i < aStr.Len(); i++ )
176 : : {
177 [ # # ][ # # ]: 0 : if ( (aStr.GetChar( i ) >= '0') && (aStr.GetChar( i ) <= '9') )
[ # # ]
178 : 0 : break;
179 [ # # ]: 0 : else if ( aStr.GetChar( i ) == '-' )
180 : : {
181 : 0 : bNegative = sal_True;
182 : 0 : break;
183 : : }
184 : : }
185 : : }
186 [ # # ][ # # ]: 0 : if ( !bNegative && bCurrency && aStr.Len() )
[ # # ][ # # ]
187 : : {
188 [ # # ]: 0 : sal_uInt16 nFormat = rLocaleDataWrapper.getCurrNegativeFormat();
189 [ # # ][ # # ]: 0 : if ( (nFormat == 3) || (nFormat == 6) ||
[ # # ][ # # ]
190 : : (nFormat == 7) || (nFormat == 10) )
191 : : {
192 [ # # ]: 0 : for ( i = (sal_uInt16)(aStr.Len()-1); i > 0; i++ )
193 : : {
194 [ # # ][ # # ]: 0 : if ( (aStr.GetChar( i ) >= '0') && (aStr.GetChar( i ) <= '9') )
[ # # ]
195 : 0 : break;
196 [ # # ]: 0 : else if ( aStr.GetChar( i ) == '-' )
197 : : {
198 : 0 : bNegative = sal_True;
199 : 0 : break;
200 : : }
201 : : }
202 : : }
203 : : }
204 : : }
205 : : else
206 : : {
207 [ # # ]: 0 : if ( aStr1.GetChar( 0 ) == '-' )
208 : 0 : bNegative = sal_True;
209 : : }
210 : :
211 : : // Alle unerwuenschten Zeichen rauswerfen
212 [ # # ]: 0 : for ( i=0; i < aStr1.Len(); )
213 : : {
214 [ # # ][ # # ]: 0 : if ( (aStr1.GetChar( i ) >= '0') && (aStr1.GetChar( i ) <= '9') )
[ # # ]
215 : 0 : i++;
216 : : else
217 [ # # ]: 0 : aStr1.Erase( i, 1 );
218 : : }
219 [ # # ]: 0 : for ( i=0; i < aStr2.Len(); )
220 : : {
221 [ # # ][ # # ]: 0 : if ( (aStr2.GetChar( i ) >= '0') && (aStr2.GetChar( i ) <= '9') )
[ # # ]
222 : 0 : i++;
223 : : else
224 [ # # ]: 0 : aStr2.Erase( i, 1 );
225 : : }
226 : :
227 [ # # ][ # # ]: 0 : if ( !aStr1.Len() && !aStr2.Len() )
[ # # ]
228 : 0 : return sal_False;
229 : :
230 [ # # ]: 0 : if ( !aStr1.Len() )
231 [ # # ]: 0 : aStr1.Insert( '0' );
232 [ # # ]: 0 : if ( bNegative )
233 [ # # ]: 0 : aStr1.Insert( '-', 0 );
234 : :
235 : : // Nachkommateil zurechtstutzen und dabei runden
236 : 0 : sal_Bool bRound = sal_False;
237 [ # # ]: 0 : if ( aStr2.Len() > nDecDigits )
238 : : {
239 [ # # ]: 0 : if ( aStr2.GetChar( nDecDigits ) >= '5' )
240 : 0 : bRound = sal_True;
241 [ # # ]: 0 : aStr2.Erase( nDecDigits );
242 : : }
243 [ # # ]: 0 : if ( aStr2.Len() < nDecDigits )
244 [ # # ]: 0 : aStr2.Expand( nDecDigits, '0' );
245 : :
246 [ # # ]: 0 : aStr = aStr1;
247 [ # # ]: 0 : aStr += aStr2;
248 : :
249 : : // Bereichsueberpruefung
250 [ # # ][ # # ]: 0 : BigInt nValue( aStr );
251 [ # # ]: 0 : if ( bRound )
252 : : {
253 [ # # ]: 0 : if ( !bNegative )
254 [ # # ][ # # ]: 0 : nValue+=1;
255 : : else
256 [ # # ][ # # ]: 0 : nValue-=1;
257 : : }
258 : :
259 [ # # ]: 0 : rValue = nValue;
260 : :
261 [ # # ][ # # ]: 0 : return sal_True;
[ # # ]
262 : : }
263 : :
264 : : // =======================================================================
265 : :
266 : 0 : static sal_Bool ImplLongCurrencyProcessKeyInput( Edit* pEdit, const KeyEvent& rKEvt,
267 : : sal_Bool, sal_Bool bUseThousandSep, const LocaleDataWrapper& rLocaleDataWrapper )
268 : : {
269 : : // Es gibt hier kein sinnvolles StrictFormat, also alle
270 : : // Zeichen erlauben
271 : 0 : return ImplNumericProcessKeyInput( pEdit, rKEvt, sal_False, bUseThousandSep, rLocaleDataWrapper );
272 : : }
273 : :
274 : : // -----------------------------------------------------------------------
275 : :
276 : 0 : inline sal_Bool ImplLongCurrencyGetValue( const XubString& rStr, BigInt& rValue,
277 : : sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper )
278 : : {
279 : : // Zahlenwert holen
280 : 0 : return ImplNumericGetValue( rStr, rValue, nDecDigits, rLocaleDataWrapper, sal_True );
281 : : }
282 : :
283 : : // -----------------------------------------------------------------------
284 : :
285 : 0 : sal_Bool ImplLongCurrencyReformat( const XubString& rStr, BigInt nMin, BigInt nMax,
286 : : sal_uInt16 nDecDigits,
287 : : const LocaleDataWrapper& rLocaleDataWrapper, String& rOutStr,
288 : : LongCurrencyFormatter& rFormatter )
289 : : {
290 [ # # ]: 0 : BigInt nValue;
291 [ # # ][ # # ]: 0 : if ( !ImplNumericGetValue( rStr, nValue, nDecDigits, rLocaleDataWrapper, sal_True ) )
292 : 0 : return sal_True;
293 : : else
294 : : {
295 [ # # ]: 0 : BigInt nTempVal = nValue;
296 [ # # ][ # # ]: 0 : if ( nTempVal > nMax )
297 [ # # ]: 0 : nTempVal = nMax;
298 [ # # ][ # # ]: 0 : else if ( nTempVal < nMin )
299 [ # # ]: 0 : nTempVal = nMin;
300 : :
301 [ # # ][ # # ]: 0 : if ( rFormatter.GetErrorHdl().IsSet() && (nValue != nTempVal) )
[ # # ][ # # ]
[ # # ]
302 : : {
303 [ # # ]: 0 : rFormatter.mnCorrectedValue = nTempVal;
304 [ # # ][ # # ]: 0 : if ( !rFormatter.GetErrorHdl().Call( &rFormatter ) )
305 : : {
306 [ # # ]: 0 : rFormatter.mnCorrectedValue = 0;
307 : 0 : return sal_False;
308 : : }
309 : : else
310 : : {
311 [ # # ]: 0 : rFormatter.mnCorrectedValue = 0;
312 : : }
313 : : }
314 : :
315 [ # # ][ # # ]: 0 : rOutStr = ImplGetCurr( rLocaleDataWrapper, nTempVal, nDecDigits, rFormatter.GetCurrencySymbol(), rFormatter.IsUseThousandSep() );
[ # # ][ # # ]
[ # # ]
316 : 0 : return sal_True;
317 : : }
318 : : }
319 : :
320 : :
321 : : // =======================================================================
322 : :
323 : 0 : void LongCurrencyFormatter::ImpInit()
324 : : {
325 : 0 : mnFieldValue = 0;
326 : 0 : mnLastValue = 0;
327 : 0 : mnMin = 0;
328 : 0 : mnMax = 0x7FFFFFFF;
329 [ # # ]: 0 : mnMax *= 0x7FFFFFFF;
330 : 0 : mnCorrectedValue = 0;
331 : 0 : mnDecimalDigits = 0;
332 : 0 : mnType = FORMAT_LONGCURRENCY;
333 : 0 : mbThousandSep = sal_True;
334 : 0 : SetDecimalDigits( 0 );
335 : 0 : }
336 : :
337 : : // -----------------------------------------------------------------------
338 : :
339 [ # # ][ # # ]: 0 : LongCurrencyFormatter::LongCurrencyFormatter()
[ # # ][ # # ]
[ # # ]
340 : : {
341 [ # # ]: 0 : ImpInit();
342 : 0 : }
343 : :
344 : : // -----------------------------------------------------------------------
345 : :
346 : 0 : LongCurrencyFormatter::~LongCurrencyFormatter()
347 : : {
348 [ # # ]: 0 : }
349 : :
350 : : // -----------------------------------------------------------------------
351 : :
352 : 0 : void LongCurrencyFormatter::SetCurrencySymbol( const String& rStr )
353 : : {
354 : 0 : maCurrencySymbol= rStr;
355 : 0 : ReformatAll();
356 : 0 : }
357 : :
358 : : // -----------------------------------------------------------------------
359 : :
360 : 0 : String LongCurrencyFormatter::GetCurrencySymbol() const
361 : : {
362 [ # # ]: 0 : return !maCurrencySymbol.isEmpty() ? maCurrencySymbol : GetLocaleDataWrapper().getCurrSymbol();
363 : : }
364 : :
365 : : // -----------------------------------------------------------------------
366 : :
367 : 0 : void LongCurrencyFormatter::SetValue( BigInt nNewValue )
368 : : {
369 [ # # ]: 0 : SetUserValue( nNewValue );
370 : 0 : mnFieldValue = mnLastValue;
371 : 0 : SetEmptyFieldValueData( sal_False );
372 : 0 : }
373 : :
374 : : // -----------------------------------------------------------------------
375 : :
376 : 0 : void LongCurrencyFormatter::SetUserValue( BigInt nNewValue )
377 : : {
378 [ # # ][ # # ]: 0 : if ( nNewValue > mnMax )
379 [ # # ]: 0 : nNewValue = mnMax;
380 [ # # ][ # # ]: 0 : else if ( nNewValue < mnMin )
381 [ # # ]: 0 : nNewValue = mnMin;
382 [ # # ]: 0 : mnLastValue = nNewValue;
383 : :
384 [ # # ]: 0 : if ( !GetField() )
385 : 0 : return;
386 : :
387 [ # # ][ # # ]: 0 : XubString aStr = ImplGetCurr( GetLocaleDataWrapper(), nNewValue, GetDecimalDigits(), GetCurrencySymbol(), IsUseThousandSep() );
[ # # ][ # # ]
[ # # ]
388 [ # # ][ # # ]: 0 : if ( GetField()->HasFocus() )
389 : : {
390 [ # # ]: 0 : Selection aSelection = GetField()->GetSelection();
391 [ # # ]: 0 : GetField()->SetText( aStr );
392 [ # # ]: 0 : GetField()->SetSelection( aSelection );
393 : : }
394 : : else
395 [ # # ]: 0 : GetField()->SetText( aStr );
396 [ # # ]: 0 : MarkToBeReformatted( sal_False );
397 : : }
398 : :
399 : : // -----------------------------------------------------------------------
400 : :
401 : 0 : BigInt LongCurrencyFormatter::GetValue() const
402 : : {
403 [ # # ]: 0 : if ( !GetField() )
404 [ # # ]: 0 : return 0;
405 : :
406 [ # # ]: 0 : BigInt nTempValue;
407 [ # # ][ # # ]: 0 : if ( ImplLongCurrencyGetValue( GetField()->GetText(), nTempValue, GetDecimalDigits(), GetLocaleDataWrapper() ) )
[ # # ][ # # ]
[ # # ][ # # ]
408 : : {
409 [ # # ][ # # ]: 0 : if ( nTempValue > mnMax )
410 [ # # ]: 0 : nTempValue = mnMax;
411 [ # # ][ # # ]: 0 : else if ( nTempValue < mnMin )
412 [ # # ]: 0 : nTempValue = mnMin;
413 [ # # ]: 0 : return nTempValue;
414 : : }
415 : : else
416 [ # # ]: 0 : return mnLastValue;
417 : : }
418 : :
419 : : // -----------------------------------------------------------------------
420 : :
421 : 0 : void LongCurrencyFormatter::Reformat()
422 : : {
423 [ # # ]: 0 : if ( !GetField() )
424 : : return;
425 : :
426 [ # # ][ # # ]: 0 : if ( !GetField()->GetText().Len() && ImplGetEmptyFieldValue() )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
427 : : return;
428 : :
429 [ # # ]: 0 : XubString aStr;
430 : 0 : sal_Bool bOK = ImplLongCurrencyReformat( GetField()->GetText(), mnMin, mnMax,
431 [ # # ][ # # ]: 0 : GetDecimalDigits(), GetLocaleDataWrapper(), aStr, *this );
[ # # ]
[ # # # # ]
[ # # ][ # # ]
432 [ # # ]: 0 : if ( !bOK )
433 : : return;
434 : :
435 [ # # ]: 0 : if ( aStr.Len() )
436 : : {
437 [ # # ]: 0 : GetField()->SetText( aStr );
438 : 0 : MarkToBeReformatted( sal_False );
439 [ # # ][ # # ]: 0 : ImplLongCurrencyGetValue( aStr, mnLastValue, GetDecimalDigits(), GetLocaleDataWrapper() );
[ # # ]
440 : : }
441 : : else
442 [ # # ][ # # ]: 0 : SetValue( mnLastValue );
[ # # ][ # # ]
443 : : }
444 : :
445 : : // -----------------------------------------------------------------------
446 : :
447 : 0 : void LongCurrencyFormatter::ReformatAll()
448 : : {
449 : 0 : Reformat();
450 : 0 : }
451 : :
452 : : // -----------------------------------------------------------------------
453 : :
454 : 0 : void LongCurrencyFormatter::SetMin( BigInt nNewMin )
455 : : {
456 : 0 : mnMin = nNewMin;
457 : 0 : ReformatAll();
458 : 0 : }
459 : :
460 : : // -----------------------------------------------------------------------
461 : :
462 : 0 : void LongCurrencyFormatter::SetMax( BigInt nNewMax )
463 : : {
464 : 0 : mnMax = nNewMax;
465 : 0 : ReformatAll();
466 : 0 : }
467 : :
468 : : // -----------------------------------------------------------------------
469 : :
470 : 0 : void LongCurrencyFormatter::SetUseThousandSep( sal_Bool b )
471 : : {
472 : 0 : mbThousandSep = b;
473 : 0 : ReformatAll();
474 : 0 : }
475 : :
476 : :
477 : : // -----------------------------------------------------------------------
478 : :
479 : 0 : void LongCurrencyFormatter::SetDecimalDigits( sal_uInt16 nDigits )
480 : : {
481 : : // DBG_ASSERT( nDigits < 10, "LongCurrency duerfen nur maximal 9 Nachkommastellen haben" );
482 : :
483 [ # # ]: 0 : if ( nDigits > 9 )
484 : 0 : nDigits = 9;
485 : :
486 : 0 : mnDecimalDigits = nDigits;
487 : 0 : ReformatAll();
488 : 0 : }
489 : :
490 : : // -----------------------------------------------------------------------
491 : :
492 : 0 : sal_uInt16 LongCurrencyFormatter::GetDecimalDigits() const
493 : : {
494 : 0 : return mnDecimalDigits;
495 : : }
496 : :
497 : : // =======================================================================
498 : :
499 : 0 : void ImplNewLongCurrencyFieldValue( LongCurrencyField* pField, BigInt nNewValue )
500 : : {
501 [ # # ]: 0 : Selection aSelect = pField->GetSelection();
502 : 0 : aSelect.Justify();
503 [ # # ]: 0 : XubString aText = pField->GetText();
504 [ # # ]: 0 : sal_Bool bLastSelected = ((xub_StrLen)aSelect.Max() == aText.Len()) ? sal_True : sal_False;
505 : :
506 [ # # ]: 0 : BigInt nOldLastValue = pField->mnLastValue;
507 [ # # ][ # # ]: 0 : pField->SetUserValue( nNewValue );
508 [ # # ]: 0 : pField->mnLastValue = nOldLastValue;
509 : :
510 [ # # ]: 0 : if ( bLastSelected )
511 : : {
512 [ # # ]: 0 : if ( !aSelect.Len() )
513 : 0 : aSelect.Min() = SELECTION_MAX;
514 : 0 : aSelect.Max() = SELECTION_MAX;
515 : : }
516 [ # # ]: 0 : pField->SetSelection( aSelect );
517 [ # # ]: 0 : pField->SetModifyFlag();
518 [ # # ][ # # ]: 0 : pField->Modify();
519 : 0 : }
520 : :
521 : : // =======================================================================
522 : :
523 : 0 : LongCurrencyField::LongCurrencyField( Window* pParent, WinBits nWinStyle ) :
524 [ # # ][ # # ]: 0 : SpinField( pParent, nWinStyle )
[ # # ][ # # ]
525 : : {
526 : 0 : SetField( this );
527 [ # # ]: 0 : mnSpinSize = 1;
528 [ # # ]: 0 : mnFirst = mnMin;
529 [ # # ]: 0 : mnLast = mnMax;
530 : :
531 [ # # ]: 0 : Reformat();
532 : 0 : }
533 : :
534 : : // -----------------------------------------------------------------------
535 : :
536 [ # # ]: 0 : LongCurrencyField::~LongCurrencyField()
537 : : {
538 [ # # ]: 0 : }
539 : :
540 : : // -----------------------------------------------------------------------
541 : :
542 : 0 : long LongCurrencyField::PreNotify( NotifyEvent& rNEvt )
543 : : {
544 [ # # ]: 0 : if( rNEvt.GetType() == EVENT_KEYINPUT )
545 : : {
546 [ # # ]: 0 : if ( ImplLongCurrencyProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), GetLocaleDataWrapper() ) )
547 : 0 : return 1;
548 : : }
549 : 0 : return SpinField::PreNotify( rNEvt );
550 : : }
551 : :
552 : : // -----------------------------------------------------------------------
553 : :
554 : 0 : long LongCurrencyField::Notify( NotifyEvent& rNEvt )
555 : : {
556 [ # # ]: 0 : if( rNEvt.GetType() == EVENT_GETFOCUS )
557 : : {
558 : 0 : MarkToBeReformatted( sal_False );
559 : : }
560 [ # # ]: 0 : else if( rNEvt.GetType() == EVENT_LOSEFOCUS )
561 : : {
562 [ # # ]: 0 : if ( MustBeReformatted() )
563 : : {
564 : 0 : Reformat();
565 : 0 : SpinField::Modify();
566 : : }
567 : : }
568 : 0 : return SpinField::Notify( rNEvt );
569 : : }
570 : :
571 : : // -----------------------------------------------------------------------
572 : :
573 : 0 : void LongCurrencyField::Modify()
574 : : {
575 : 0 : MarkToBeReformatted( sal_True );
576 : 0 : SpinField::Modify();
577 : 0 : }
578 : :
579 : : // -----------------------------------------------------------------------
580 : :
581 : 0 : void LongCurrencyField::Up()
582 : : {
583 [ # # ]: 0 : BigInt nValue = GetValue();
584 [ # # ]: 0 : nValue += mnSpinSize;
585 [ # # ][ # # ]: 0 : if ( nValue > mnMax )
586 [ # # ]: 0 : nValue = mnMax;
587 : :
588 [ # # ][ # # ]: 0 : ImplNewLongCurrencyFieldValue( this, nValue );
589 [ # # ]: 0 : SpinField::Up();
590 : 0 : }
591 : :
592 : : // -----------------------------------------------------------------------
593 : :
594 : 0 : void LongCurrencyField::Down()
595 : : {
596 [ # # ]: 0 : BigInt nValue = GetValue();
597 [ # # ]: 0 : nValue -= mnSpinSize;
598 [ # # ][ # # ]: 0 : if ( nValue < mnMin )
599 [ # # ]: 0 : nValue = mnMin;
600 : :
601 [ # # ][ # # ]: 0 : ImplNewLongCurrencyFieldValue( this, nValue );
602 [ # # ]: 0 : SpinField::Down();
603 : 0 : }
604 : :
605 : : // -----------------------------------------------------------------------
606 : :
607 : 0 : void LongCurrencyField::First()
608 : : {
609 [ # # ]: 0 : ImplNewLongCurrencyFieldValue( this, mnFirst );
610 : 0 : SpinField::First();
611 : 0 : }
612 : :
613 : : // -----------------------------------------------------------------------
614 : :
615 : 0 : void LongCurrencyField::Last()
616 : : {
617 [ # # ]: 0 : ImplNewLongCurrencyFieldValue( this, mnLast );
618 : 0 : SpinField::Last();
619 : 0 : }
620 : :
621 : : // =======================================================================
622 : :
623 : 0 : LongCurrencyBox::LongCurrencyBox( Window* pParent, WinBits nWinStyle ) :
624 [ # # ]: 0 : ComboBox( pParent, nWinStyle )
625 : : {
626 : 0 : SetField( this );
627 [ # # ]: 0 : Reformat();
628 : 0 : }
629 : :
630 : : // -----------------------------------------------------------------------
631 : :
632 [ # # ]: 0 : LongCurrencyBox::~LongCurrencyBox()
633 : : {
634 [ # # ]: 0 : }
635 : :
636 : : // -----------------------------------------------------------------------
637 : :
638 : 0 : long LongCurrencyBox::PreNotify( NotifyEvent& rNEvt )
639 : : {
640 [ # # ]: 0 : if( rNEvt.GetType() == EVENT_KEYINPUT )
641 : : {
642 [ # # ]: 0 : if ( ImplLongCurrencyProcessKeyInput( GetField(), *rNEvt.GetKeyEvent(), IsStrictFormat(), IsUseThousandSep(), GetLocaleDataWrapper() ) )
643 : 0 : return 1;
644 : : }
645 : 0 : return ComboBox::PreNotify( rNEvt );
646 : : }
647 : :
648 : : // -----------------------------------------------------------------------
649 : :
650 : 0 : long LongCurrencyBox::Notify( NotifyEvent& rNEvt )
651 : : {
652 [ # # ]: 0 : if( rNEvt.GetType() == EVENT_GETFOCUS )
653 : : {
654 : 0 : MarkToBeReformatted( sal_False );
655 : : }
656 [ # # ]: 0 : else if( rNEvt.GetType() == EVENT_LOSEFOCUS )
657 : : {
658 [ # # ]: 0 : if ( MustBeReformatted() )
659 : : {
660 : 0 : Reformat();
661 : 0 : ComboBox::Modify();
662 : : }
663 : : }
664 : 0 : return ComboBox::Notify( rNEvt );
665 : : }
666 : :
667 : : // -----------------------------------------------------------------------
668 : :
669 : 0 : void LongCurrencyBox::Modify()
670 : : {
671 : 0 : MarkToBeReformatted( sal_True );
672 : 0 : ComboBox::Modify();
673 : 0 : }
674 : :
675 : : // -----------------------------------------------------------------------
676 : :
677 : 0 : void LongCurrencyBox::ReformatAll()
678 : : {
679 [ # # ]: 0 : XubString aStr;
680 [ # # ]: 0 : SetUpdateMode( sal_False );
681 [ # # ]: 0 : sal_uInt16 nEntryCount = GetEntryCount();
682 [ # # ]: 0 : for ( sal_uInt16 i=0; i < nEntryCount; i++ )
683 : : {
684 : : ImplLongCurrencyReformat( GetEntry( i ), mnMin, mnMax,
685 [ # # ][ # # ]: 0 : GetDecimalDigits(), GetLocaleDataWrapper(),
686 [ # # ][ # # ]: 0 : aStr, *this );
[ # # ][ # # ]
[ # # ]
687 [ # # ]: 0 : RemoveEntry( i );
688 [ # # ]: 0 : InsertEntry( aStr, i );
689 : : }
690 [ # # ]: 0 : LongCurrencyFormatter::Reformat();
691 [ # # ][ # # ]: 0 : SetUpdateMode( sal_True );
692 : 0 : }
693 : :
694 : : // =======================================================================
695 : :
696 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|