update dev300-m57
[ooovba.git] / lotuswordpro / source / filter / lwpnumericfmt.cxx
blobcf72b5821bc1ef979bbf6dad96333a137b47815c
1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 /**
56 * @file
57 * For LWP filter architecture prototype - table cell numerics format
59 /*************************************************************************
60 * Change History
61 Mar 2005 Created
62 ************************************************************************/
64 #include "lwpnumericfmt.hxx"
66 ///////////////////////////////////////////////////////////////////
67 LwpCurrencyPool LwpNumericFormat::m_aCurrencyInfo;
69 /**
71 * @date 03/26/2005
72 * @param
73 * @param
74 * @return
76 String LwpCurrencyPool::GetCurrencySymbol(sal_uInt16 nFormat)
78 return m_aCurrencyInfo[nFormat].sSymbol;
81 /**
83 * @date 03/26/2005
84 * @param
85 * @param
86 * @return sal_Bool.
88 sal_Bool LwpCurrencyPool::IsSymbolPost(sal_uInt16 nFormat)
90 return m_aCurrencyInfo[nFormat].bPost;;
93 /**
95 * @date 03/26/2005
96 * @param
97 * @param
98 * @return sal_Bool.
100 sal_Bool LwpCurrencyPool::IsShowSpace(sal_uInt16 nFormat)
102 return m_aCurrencyInfo[nFormat].bShowSpace;
104 //////////////////////////////////////////////////////////////////////
107 * @date 03/26/2005
108 * @param
109 * @param
110 * @return
112 XFStyle* LwpLayoutNumerics::Convert()
114 return cNumerics.Convert();
119 * @date 03/26/2005
120 * @param
121 * @param
122 * @return sal_Bool.
124 void LwpLayoutNumerics::Read()
126 LwpVirtualPiece::Read();
128 if(LwpFileHeader::m_nFileRevision >= 0x000b)
130 cNumerics.Read();
131 m_pObjStrm->SkipExtra();
134 ///////////////////////////////////////////////////////////////////
138 * @date 03/26/2005
139 * @param
140 * @param
141 * @return sal_Bool.
143 void LwpNumericFormatSubset::QuickRead(LwpObjectStream* pStrm)
145 cColor.Read(pStrm);
146 cPrefix.Read(pStrm);
147 cSuffix.Read(pStrm);
148 cSubFlags = pStrm->QuickReaduInt16();
150 pStrm->SkipExtra();
154 * @date 03/26/2005
155 * @param
156 * @param
157 * @return.
159 LwpColor LwpNumericFormatSubset::GetColor()
161 if (cSubFlags&0x04)
163 return cColor;
165 else
167 return LwpColor();
170 LwpNumericFormatSubset::LwpNumericFormatSubset():cSubFlags(0)
173 LwpNumericFormatSubset::~LwpNumericFormatSubset()
177 ///////////////////////////////////////////////////////////////////////////////////
178 LwpNumericFormat::LwpNumericFormat(LwpObjectStream * pStrm):cDecimalPlaces(0),cFormat(FMT_DEFAULT)
180 assert(pStrm);
181 m_pObjStrm = pStrm;
184 * Read number format from wordpro file
185 * @date 03/26/2005
186 * @param
187 * @param
188 * @return
190 void LwpNumericFormat::Read()
192 LwpObjectStream* pStrm = m_pObjStrm;
194 if(LwpFileHeader::m_nFileRevision >= 0x000b)
196 cFlags = pStrm->QuickReaduInt16();
197 cDecimalPlaces = pStrm->QuickReaduInt16();
198 cFormat = pStrm->QuickReaduInt16();
200 cAnyNumber.QuickRead(pStrm);
201 cZero.QuickRead(pStrm);
202 cNegative.QuickRead(pStrm);
204 pStrm->SkipExtra();
209 * @date 03/26/2005
210 * @param
211 * @param
212 * @return sal_Bool.
214 sal_Bool
215 LwpNumericFormat::IsCurrencyFormat(USHORT Format)
217 switch (Format)
219 case FMT_ARGENTINEANPESO:
220 case FMT_AUSTRALIANDOLLAR:
221 case FMT_AUSTRIANSCHILLING:
222 case FMT_BELGIANFRANC:
223 case FMT_BRAZILIANCRUZEIRO:
224 case FMT_BRITISHPOUND:
225 case FMT_CANADIANDOLLAR:
226 case FMT_CHINESEYUAN:
227 case FMT_CZECHKORUNA:
228 case FMT_DANISHKRONE:
229 case FMT_ECU:
230 case FMT_FINNISHMARKKA:
231 case FMT_FRENCHFRANC:
232 case FMT_GREEKDRACHMA:
233 case FMT_HONGKONGDOLLAR:
234 case FMT_HUNGARIANFORINT:
235 case FMT_INDIANRUPEE:
236 case FMT_INDONESIANRUPIAH:
237 case FMT_IRISHPUNT:
238 case FMT_LUXEMBOURGFRANC:
239 case FMT_MALAYSIANRINGGIT:
240 case FMT_MEXICANPESO:
241 case FMT_NETHERLANDSGUILDER:
242 case FMT_NEWZEALANDDOLLAR:
243 case FMT_NORWEGIANKRONE:
244 case FMT_POLISHZLOTY:
245 case FMT_PORTUGUESEESCUDO:
246 case FMT_ROMANIANLEI:
247 case FMT_RUSSIANRUBLE:
248 case FMT_SINGAPOREDOLLAR:
249 case FMT_SLOVAKIANKORUNA:
250 case FMT_SLOVENIANTHOLAR:
251 case FMT_SOUTHAFRICANRAND:
252 case FMT_SOUTHKOREANWON:
253 case FMT_SWEDISHKRONA:
254 case FMT_SWISSFRANC:
255 case FMT_TAIWANDOLLAR:
256 case FMT_THAIBAHT:
257 case FMT_USDOLLAR:
258 case FMT_OTHERCURRENCY:
259 case FMT_GERMANMARK:
260 case FMT_ITALIANLIRA:
261 case FMT_JAPANESEYEN:
262 case FMT_SPANISHPESETA:
263 case FMT_EURO:
264 return sal_True;
266 default:
267 return sal_False;
272 * @date 03/26/2005
273 * @param
274 * @param
275 * @return.
277 USHORT
278 LwpNumericFormat::GetDecimalPlaces(void)
280 if (IsDecimalPlacesOverridden())
281 return cDecimalPlaces;
282 return GetDefaultDecimalPlaces(cFormat);
285 * Make the currency string.
286 * @date 03/26/2005
287 * @param
288 * @param
289 * @return
291 void LwpNumericFormat::GetCurrencyStr(LwpNumericFormatSubset aNumber, String& aPrefix, String& aSuffix, sal_Bool bNegtive)
293 aPrefix = aNumber.GetPrefix();
294 aSuffix = aNumber.GetSuffix();
296 //Make the default prefix and suffix
297 String aSymbol = m_aCurrencyInfo.GetCurrencySymbol(cFormat);
298 sal_Bool bPost = m_aCurrencyInfo.IsSymbolPost(cFormat);
299 sal_Bool bShowSpace = m_aCurrencyInfo.IsShowSpace(cFormat);
300 if ( aNumber.IsDefaultPrefix())
302 if (bNegtive)
304 aPrefix = String::CreateFromAscii("(");
306 if (!bPost)
308 aPrefix += aSymbol;
309 if (bShowSpace)
311 aPrefix +=String::CreateFromAscii(" ");
315 if ( aNumber.IsDefaultSuffix())
317 if (bPost)
319 aSuffix = aSymbol;
320 if (bShowSpace)
322 aSuffix.Insert(String::CreateFromAscii(" "),0);
327 if (bNegtive)
329 aSuffix += String::CreateFromAscii(")");
335 * @date 03/26/2005
336 * @param
337 * @param
338 * @return
340 void LwpNumericFormat::SetNumberType(XFNumberStyle* pStyle)
342 switch(cFormat)
344 case FMT_PERCENT:
346 pStyle->SetNumberType(enumXFNumberPercent);
348 break;
350 case FMT_COMMA:
352 pStyle->SetNumberType(enumXFNumberNumber);
353 pStyle->SetGroup();
355 break;
356 case FMT_SCIENTIFIC:
358 pStyle->SetNumberType(enumXFNumberScientific);
360 break;
361 case FMT_FIXED:
362 case FMT_GENERAL:
364 pStyle->SetNumberType(enumXFNumberNumber);
366 break;
367 default://including text type, which is not a style of number format in SODC
369 pStyle->SetNumberType(enumXFText);
371 break;
375 * Make the xml content of number format
376 * @date 03/26/2005
377 * @param
378 * @param
379 * @return XFStyle*
381 XFStyle* LwpNumericFormat::Convert()
383 XFNumberStyle* pStyle = new XFNumberStyle;
384 String aPrefix, aSuffix,aNegPrefix,aNegSuffix;
385 LwpColor aColor, aNegativeColor;
387 if (IsCurrencyFormat(cFormat))
389 pStyle->SetNumberType(enuMXFNumberCurrency);
390 pStyle->SetGroup();
391 GetCurrencyStr(cAnyNumber, aPrefix, aSuffix);
392 GetCurrencyStr(cNegative, aNegPrefix, aNegSuffix,sal_True);
394 else
396 SetNumberType(pStyle);
397 {//Anynumber
398 aPrefix = cAnyNumber.GetPrefix();
399 //Set suffix
400 aSuffix = cAnyNumber.GetSuffix();
401 //Set color
402 aColor = cAnyNumber.GetColor();
405 if (!IsNegativeOverridden())
407 aNegPrefix = aPrefix;
408 aNegSuffix = aSuffix;
409 aNegativeColor = aColor;
411 else
412 {//negative
413 aNegPrefix = cNegative.GetPrefix();
414 aNegSuffix = cNegative.GetSuffix();
415 aNegativeColor = cNegative.GetColor();
417 if (FMT_COMMA==cFormat)
419 if (cNegative.IsDefaultPrefix() && aNegPrefix.Len() == 0)
421 aNegPrefix = String::CreateFromAscii("(");
423 if (cNegative.IsDefaultSuffix() && aNegSuffix.Len() == 0)
425 aNegSuffix = String::CreateFromAscii(")");
431 pStyle->SetDecimalDigits(GetDecimalPlaces());
433 aPrefix = reencode(aPrefix);
434 aSuffix = reencode(aSuffix);
435 aNegPrefix = reencode(aNegPrefix);
436 aNegSuffix = reencode(aNegSuffix);
438 {//Anynumber
439 //Set prefix
440 pStyle->SetPrefix(aPrefix);
441 //Set suffix
442 pStyle->SetSurfix(aSuffix);
443 pStyle->SetColor( XFColor( (sal_uInt8)aColor.GetRed(),
444 (sal_uInt8)aColor.GetGreen(),
445 (sal_uInt8)aColor.GetBlue()) );
447 {//Negtive
448 pStyle->SetNegativeStyle( aNegPrefix, aNegSuffix, XFColor((sal_uInt8)aNegativeColor.GetRed(),
449 (sal_uInt8)aNegativeColor.GetGreen(),
450 (sal_uInt8)aNegativeColor.GetBlue()) );
453 return pStyle;
457 * @descrption for SODC_2754
458 * @date 04/04/2006
459 * @param
460 * @param
461 * @return fix wrong encoding of POUND symbol
463 OUString LwpNumericFormat::reencode(OUString sCode)
465 const sal_Unicode * pString = sCode.getStr();
466 sal_uInt16 nLen = sCode.getLength();
467 sal_Bool bFound = sal_False;
468 sal_uInt16 i;
469 sal_Unicode *pBuff = new sal_Unicode[sCode.getLength()];
471 for (i=0; i< sCode.getLength() - 1; i++)
473 if ( (pString[i] == 0x00a1) && (pString[i+1] == 0x00ea))
475 bFound = sal_True;
476 break;
478 pBuff[i] = pString[i];
480 if (bFound)
482 pBuff[i] = 0xffe1;
483 for (sal_uInt32 j=i+1; j < sCode.getLength() - 1; j++)
485 pBuff[j] = pString[j+1];
487 OUString sRet(pBuff, nLen - 1);
488 delete [] pBuff;
489 return sRet;
492 delete [] pBuff;
493 return sCode;
498 * @date 03/26/2005
499 * @param
500 * @param
501 * @return
503 USHORT
504 LwpNumericFormat::GetDefaultDecimalPlaces(USHORT Format)
506 switch (Format)
508 case FMT_ARGENTINEANPESO:
509 case FMT_AUSTRALIANDOLLAR:
510 case FMT_AUSTRIANSCHILLING:
511 case FMT_BELGIANFRANC:
512 case FMT_BRAZILIANCRUZEIRO:
513 case FMT_BRITISHPOUND:
514 case FMT_CANADIANDOLLAR:
515 case FMT_CHINESEYUAN:
516 case FMT_CZECHKORUNA:
517 case FMT_DANISHKRONE:
518 case FMT_ECU:
519 case FMT_FINNISHMARKKA:
520 case FMT_FRENCHFRANC:
521 case FMT_GERMANMARK:
522 case FMT_HONGKONGDOLLAR:
523 case FMT_HUNGARIANFORINT:
524 case FMT_INDIANRUPEE:
525 case FMT_INDONESIANRUPIAH:
526 case FMT_IRISHPUNT:
527 case FMT_LUXEMBOURGFRANC:
528 case FMT_MALAYSIANRINGGIT:
529 case FMT_MEXICANPESO:
530 case FMT_NETHERLANDSGUILDER:
531 case FMT_NEWZEALANDDOLLAR:
532 case FMT_NORWEGIANKRONE:
533 case FMT_POLISHZLOTY:
534 case FMT_PORTUGUESEESCUDO:
535 case FMT_ROMANIANLEI:
536 case FMT_RUSSIANRUBLE:
537 case FMT_SINGAPOREDOLLAR:
538 case FMT_SLOVAKIANKORUNA:
539 case FMT_SLOVENIANTHOLAR:
540 case FMT_SOUTHAFRICANRAND:
541 case FMT_SOUTHKOREANWON:
542 case FMT_SWEDISHKRONA:
543 case FMT_SWISSFRANC:
544 case FMT_TAIWANDOLLAR:
545 case FMT_THAIBAHT:
546 case FMT_USDOLLAR:
547 case FMT_OTHERCURRENCY:
548 case FMT_EURO:
549 return 2;
551 case FMT_GREEKDRACHMA:
552 case FMT_ITALIANLIRA:
553 case FMT_JAPANESEYEN:
554 case FMT_SPANISHPESETA:
555 return 0;
557 case FMT_DEFAULT:
558 case FMT_GENERAL:
559 case FMT_FIXED:
560 case FMT_COMMA:
561 case FMT_PERCENT:
562 case FMT_SCIENTIFIC:
563 default:
564 return 2;