update dev300-m58
[ooovba.git] / svx / source / items / numfmtsh.cxx
blob48bcbc5b615c57dbc6f578adb787d324992a4658
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: numfmtsh.cxx,v $
10 * $Revision: 1.20.128.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 // include ---------------------------------------------------------------
35 #include <tools/color.hxx>
37 #define _SVX_NUMFMTSH_CXX
38 #define _SVSTDARR_STRINGSDTOR
39 #include <tools/debug.hxx>
40 #include <i18npool/mslangid.hxx>
42 #define _ZFORLIST_DECLARE_TABLE
43 #include <svtools/zforlist.hxx>
44 #include <svtools/zformat.hxx>
46 #include <svtools/langtab.hxx>
47 #include <vcl/svapp.hxx>
49 #include <svx/numfmtsh.hxx>
50 // class SvxNumberFormatShell --------------------------------------------
52 const double SvxNumberFormatShell::DEFAULT_NUMVALUE = 1234.56789;
54 SV_IMPL_PTRARR( NfShCurrencyEntries, NfCurrencyEntry* );
56 // -----------------------------------------------------------------------
60 SvxNumberFormatShell* SvxNumberFormatShell::Create( SvNumberFormatter* pNumFormatter,
61 sal_uInt32 nFormatKey,
62 SvxNumberValueType eNumValType,
63 const String& rNumStr )
65 return new SvxNumberFormatShell(pNumFormatter,nFormatKey,
66 eNumValType,rNumStr );
69 SvxNumberFormatShell* SvxNumberFormatShell::Create( SvNumberFormatter* pNumFormatter,
70 sal_uInt32 nFormatKey,
71 SvxNumberValueType eNumValType,
72 double nNumVal,
73 const String* pNumStr )
75 return new SvxNumberFormatShell(pNumFormatter,nFormatKey,
76 eNumValType,nNumVal,pNumStr );
79 // -----------------------------------------------------------------------
81 #define _INIT \
82 pFormatter ( pNumFormatter ), \
83 pCurFmtTable ( NULL ), \
84 eValType ( eNumValType ), \
85 bUndoAddList ( sal_True ), \
86 nInitFormatKey ( nFormatKey ), \
87 nCurFormatKey ( nFormatKey ), \
88 pCurCurrencyEntry(NULL), \
89 bBankingSymbol (sal_False), \
90 nCurCurrencyEntryPos((sal_uInt16) SELPOS_NONE)
92 // -----------------------------------------------------------------------
94 SvxNumberFormatShell::SvxNumberFormatShell( SvNumberFormatter* pNumFormatter,
95 sal_uInt32 nFormatKey,
96 SvxNumberValueType eNumValType,
97 const String& rNumStr )
98 : _INIT
100 nValNum = DEFAULT_NUMVALUE;
102 switch ( eValType )
104 case SVX_VALUE_TYPE_STRING:
105 aValStr = rNumStr;
106 break;
107 case SVX_VALUE_TYPE_NUMBER:
108 case SVX_VALUE_TYPE_UNDEFINED:
109 default:
110 aValStr.Erase();
114 // -----------------------------------------------------------------------
116 SvxNumberFormatShell::SvxNumberFormatShell( SvNumberFormatter* pNumFormatter,
117 sal_uInt32 nFormatKey,
118 SvxNumberValueType eNumValType,
119 double nNumVal,
120 const String* pNumStr )
121 : _INIT
123 // #50441# When used in Writer, the SvxNumberInfoItem contains the
124 // original string in addition to the value
126 if ( pNumStr )
127 aValStr = *pNumStr;
129 switch ( eValType )
131 case SVX_VALUE_TYPE_NUMBER:
132 nValNum = nNumVal;
133 break;
134 case SVX_VALUE_TYPE_STRING:
135 case SVX_VALUE_TYPE_UNDEFINED:
136 default:
137 nValNum = DEFAULT_NUMVALUE;
141 // -----------------------------------------------------------------------
143 SvxNumberFormatShell::~SvxNumberFormatShell()
146 * An dieser Stelle wird abhaengig davon, ob die
147 * hinzugefuegten, benutzerdefinierten als gueltig
148 * erklaert wurden (ValidateNewEntries()), die
149 * Add-Liste wieder aus dem Zahlenformatierer entfernt.
151 * Loeschen von Formaten aus dem Formatierer passiert
152 * aus Undo-Gruenden nur in der aufrufenden Instanz.
155 if ( bUndoAddList )
157 // Hinzugefuegte Formate sind nicht gueltig:
158 // => wieder entfernen:
160 for ( sal_uInt16 i = 0; i < aAddList.Count(); ++i )
161 pFormatter->DeleteEntry( aAddList[i] );
164 //--------------------------------
165 // Add-/Remove-Listen leerraeumen:
166 //--------------------------------
167 aAddList.Remove( 0, aAddList.Count() );
168 aDelList.Remove( 0, aAddList.Count() );
170 if(aCurrencyFormatList.Count()>0)
171 aCurrencyFormatList.DeleteAndDestroy(0,aCurrencyFormatList.Count());
174 // -----------------------------------------------------------------------
176 sal_uInt32 SvxNumberFormatShell::GetUpdateDataCount() const
178 return aDelList.Count();
181 // -----------------------------------------------------------------------
183 void SvxNumberFormatShell::GetUpdateData( sal_uInt32* pDelArray, const sal_uInt32 nSize )
185 const sal_uInt32 nCount = aDelList.Count();
187 DBG_ASSERT( pDelArray && ( nSize == nCount ), "Array nicht initialisiert!" );
189 if ( pDelArray && ( nSize == nCount ) )
190 for ( sal_uInt16 i = 0; i < aDelList.Count(); ++i )
191 *pDelArray++ = aDelList[i];
194 // -----------------------------------------------------------------------
196 void SvxNumberFormatShell::CategoryChanged( sal_uInt16 nCatLbPos,
197 short& rFmtSelPos,
198 SvStrings& rFmtEntries )
200 short nOldCategory = nCurCategory;
201 PosToCategory_Impl( nCatLbPos, nCurCategory );
202 pCurFmtTable = &( pFormatter->GetEntryTable( nCurCategory,
203 nCurFormatKey,
204 eCurLanguage ) );
205 // reinitialize currency if category newly entered
206 if ( nCurCategory == NUMBERFORMAT_CURRENCY && nOldCategory != nCurCategory )
207 pCurCurrencyEntry = NULL;
208 rFmtSelPos = FillEntryList_Impl( rFmtEntries );
211 // -----------------------------------------------------------------------
213 void SvxNumberFormatShell::LanguageChanged( LanguageType eLangType,
214 short& rFmtSelPos,
215 SvStrings& rFmtEntries )
217 eCurLanguage = eLangType;
218 pCurFmtTable = &(pFormatter->ChangeCL( nCurCategory,
219 nCurFormatKey,
220 eCurLanguage ) );
221 rFmtSelPos = FillEntryList_Impl( rFmtEntries );
224 // -----------------------------------------------------------------------
226 void SvxNumberFormatShell::FormatChanged( sal_uInt16 nFmtLbPos,
227 String& rPreviewStr,
228 Color*& rpFontColor )
230 //nCurFormatKey = pCurFmtTable->GetKey( pCurFmtTable->GetObject( nFmtLbPos ) );
232 if(nFmtLbPos<aCurEntryList.Count())
234 nCurFormatKey=aCurEntryList[nFmtLbPos];
236 if(nCurFormatKey!=NUMBERFORMAT_ENTRY_NOT_FOUND)
238 GetPreviewString_Impl( rPreviewStr, rpFontColor );
240 else if(nCurCategory==NUMBERFORMAT_CURRENCY)
242 if(nFmtLbPos<aCurrencyFormatList.Count())
244 //nCurFormatKey=nFmtLbPos;
245 MakePrevStringFromVal(*aCurrencyFormatList[nFmtLbPos],
246 rPreviewStr,rpFontColor,nValNum);
251 // -----------------------------------------------------------------------
253 sal_Bool SvxNumberFormatShell::AddFormat( String& rFormat, xub_StrLen& rErrPos,
254 sal_uInt16& rCatLbSelPos, short& rFmtSelPos,
255 SvStrings& rFmtEntries )
257 sal_Bool bInserted = sal_False;
258 sal_uInt32 nAddKey = pFormatter->GetEntryKey( rFormat, eCurLanguage );
260 if ( nAddKey != NUMBERFORMAT_ENTRY_NOT_FOUND ) // bereits vorhanden?
262 if ( IsRemoved_Impl( nAddKey ) )
264 // Key suchen und loeschen
265 sal_Bool bFound = sal_False;
266 sal_uInt16 nAt = 0;
268 for ( sal_uInt16 i = 0; !bFound && i < aDelList.Count(); ++i )
270 if ( aDelList[i] == nAddKey )
272 bFound = sal_True;
273 nAt = i;
276 DBG_ASSERT( bFound, "Key not found" );
277 aDelList.Remove( nAt );
278 bInserted = sal_True;
280 else
282 DBG_ERROR( "Doppeltes Format!" );
285 else // neues Format
287 bInserted = pFormatter->PutEntry( rFormat, rErrPos,
288 nCurCategory, nAddKey,
289 eCurLanguage );
292 if ( bInserted ) // eingefuegt
294 nCurFormatKey = nAddKey;
295 DBG_ASSERT( !IsAdded_Impl( nCurFormatKey ), "Doppeltes Format!" );
296 aAddList.Insert( nCurFormatKey, aAddList.Count() );
298 // aktuelle Tabelle holen
299 pCurFmtTable = &(pFormatter->GetEntryTable( nCurCategory,
300 nCurFormatKey,
301 eCurLanguage ));
302 nCurCategory=pFormatter->GetType(nAddKey); //@@ ???
303 CategoryToPos_Impl( nCurCategory, rCatLbSelPos );
304 rFmtSelPos = FillEntryList_Impl( rFmtEntries );
306 else if ( rErrPos != 0 ) // Syntaxfehler
310 else // Doppelt einfuegen nicht moeglich
312 DBG_ERROR( "Doppeltes Format!" ); // oder doch?
315 return bInserted;
318 // -----------------------------------------------------------------------
320 sal_Bool SvxNumberFormatShell::RemoveFormat( const String& rFormat,
321 sal_uInt16& rCatLbSelPos,
322 short& rFmtSelPos,
323 SvStrings& rFmtEntries )
325 sal_uInt32 nDelKey = pFormatter->GetEntryKey( rFormat, eCurLanguage );
327 DBG_ASSERT( nDelKey != NUMBERFORMAT_ENTRY_NOT_FOUND, "Eintrag nicht gefunden!" );
328 DBG_ASSERT( !IsRemoved_Impl( nDelKey ), "Eintrag bereits geloescht!" );
330 if ( (nDelKey != NUMBERFORMAT_ENTRY_NOT_FOUND) && !IsRemoved_Impl( nDelKey ) )
332 aDelList.Insert( nDelKey, aDelList.Count() );
334 if ( IsAdded_Impl( nDelKey ) )
336 // Key suchen und loeschen
337 sal_Bool bFound = sal_False;
338 sal_uInt16 nAt = 0;
340 for ( sal_uInt16 i = 0; !bFound && i < aAddList.Count(); ++i )
342 if ( aAddList[i] == nDelKey )
344 bFound = sal_True;
345 nAt = i;
348 DBG_ASSERT( bFound, "Key not found" );
349 aAddList.Remove( nAt );
352 nCurCategory=pFormatter->GetType(nDelKey); //@@ 01.10.97
353 pCurFmtTable = &(pFormatter->GetEntryTable( nCurCategory,
354 nCurFormatKey,
355 eCurLanguage ));
357 nCurFormatKey=pFormatter->GetStandardFormat(nCurCategory,
358 eCurLanguage );
360 CategoryToPos_Impl( nCurCategory, rCatLbSelPos );
361 rFmtSelPos = FillEntryList_Impl( rFmtEntries );
362 //rFmtSelPos = (short) nCurFormatKey; //@@ 01.10.97
364 return sal_True;
367 // -----------------------------------------------------------------------
369 void SvxNumberFormatShell::MakeFormat( String& rFormat,
370 sal_Bool bThousand, sal_Bool bNegRed,
371 sal_uInt16 nPrecision, sal_uInt16 nLeadingZeroes,
372 sal_uInt16 nCurrencyPos)
374 if(aCurrencyFormatList.Count()>nCurrencyPos)
376 xub_StrLen rErrPos=0;
377 sal_uInt16 rCatLbSelPos=0;
378 short rFmtSelPos=0;
379 SvStrings aFmtEList;
381 sal_uInt32 nFound = pFormatter->TestNewString( *aCurrencyFormatList[nCurrencyPos], eCurLanguage );
383 if ( nFound == NUMBERFORMAT_ENTRY_NOT_FOUND )
385 AddFormat( *aCurrencyFormatList[nCurrencyPos],rErrPos,rCatLbSelPos,
386 rFmtSelPos,aFmtEList);
389 if(rErrPos==0)
391 pFormatter->GenerateFormat( rFormat, nCurFormatKey,
392 eCurLanguage,
393 bThousand, bNegRed,
394 nPrecision, nLeadingZeroes );
396 aFmtEList.DeleteAndDestroy(0,aFmtEList.Count());
398 else
400 pFormatter->GenerateFormat( rFormat, nCurFormatKey,
401 eCurLanguage,
402 bThousand, bNegRed,
403 nPrecision, nLeadingZeroes );
407 // -----------------------------------------------------------------------
409 void SvxNumberFormatShell::GetOptions( const String& rFormat,
410 sal_Bool& rThousand,
411 sal_Bool& rNegRed,
412 sal_uInt16& rPrecision,
413 sal_uInt16& rLeadingZeroes,
414 sal_uInt16& rCatLbPos )
417 sal_uInt32 nFmtKey = pFormatter->GetEntryKey( rFormat, eCurLanguage );
419 if(nFmtKey != NUMBERFORMAT_ENTRY_NOT_FOUND)
421 if ( nFmtKey != NUMBERFORMAT_ENTRY_NOT_FOUND )
423 pFormatter->GetFormatSpecialInfo( nFmtKey,
424 rThousand, rNegRed,
425 rPrecision, rLeadingZeroes );
427 CategoryToPos_Impl( pFormatter->GetType( nFmtKey ), rCatLbPos );
429 else
430 rCatLbPos = CAT_USERDEFINED;
432 else
434 sal_Bool bTestBanking=sal_False;
435 sal_uInt16 nPos=FindCurrencyTableEntry(rFormat, bTestBanking );
437 if(IsInTable(nPos,bTestBanking,rFormat) &&
438 pFormatter->GetFormatSpecialInfo( rFormat,rThousand, rNegRed,
439 rPrecision, rLeadingZeroes,eCurLanguage)==0)
441 rCatLbPos = CAT_CURRENCY;
443 else
444 rCatLbPos = CAT_USERDEFINED;
449 // -----------------------------------------------------------------------
451 void SvxNumberFormatShell::MakePreviewString( const String& rFormatStr,
452 String& rPreviewStr,
453 Color*& rpFontColor )
455 rpFontColor = NULL;
457 ULONG nExistingFormat = pFormatter->GetEntryKey( rFormatStr, eCurLanguage );
458 if ( nExistingFormat == NUMBERFORMAT_ENTRY_NOT_FOUND )
460 // real preview - not implemented in NumberFormatter for text formats
462 pFormatter->GetPreviewString( rFormatStr, nValNum, rPreviewStr,
463 &rpFontColor, eCurLanguage );
465 else
467 // format exists
469 // #50441# if a string was set in addition to the value, use it for text formats
470 BOOL bUseText = ( eValType == SVX_VALUE_TYPE_STRING ||
471 ( aValStr.Len() && ( pFormatter->GetType(nExistingFormat) & NUMBERFORMAT_TEXT ) ) );
472 if ( bUseText )
473 pFormatter->GetOutputString( aValStr, nExistingFormat,
474 rPreviewStr, &rpFontColor );
475 else
476 pFormatter->GetOutputString( nValNum, nExistingFormat,
477 rPreviewStr, &rpFontColor );
481 // -----------------------------------------------------------------------
483 sal_Bool SvxNumberFormatShell::IsUserDefined( const String& rFmtString )
485 sal_uInt32 nFound = pFormatter->GetEntryKey( rFmtString, eCurLanguage );
487 sal_Bool bFlag=sal_False;
488 if ( nFound != NUMBERFORMAT_ENTRY_NOT_FOUND )
490 bFlag=pFormatter->IsUserDefined( rFmtString, eCurLanguage );
492 if(bFlag)
494 const SvNumberformat* pNumEntry = pFormatter->GetEntry(nFound);
496 if(pNumEntry!=NULL && pNumEntry->HasNewCurrency())
498 sal_Bool bTestBanking;
499 sal_uInt16 nPos=FindCurrencyTableEntry(rFmtString,bTestBanking);
500 bFlag=!IsInTable(nPos,bTestBanking,rFmtString);
504 return bFlag;
507 // -----------------------------------------------------------------------
509 sal_Bool SvxNumberFormatShell::FindEntry( const String& rFmtString, sal_uInt32* pAt /* = NULL */ )
511 sal_Bool bRes=sal_False;
512 sal_uInt32 nFound = pFormatter->TestNewString( rFmtString, eCurLanguage );
514 if ( nFound == NUMBERFORMAT_ENTRY_NOT_FOUND )
516 sal_Bool bTestBanking=sal_False;
517 sal_uInt16 nPos=FindCurrencyTableEntry(rFmtString, bTestBanking );
519 if(IsInTable(nPos,bTestBanking,rFmtString))
521 nFound=NUMBERFORMAT_ENTRY_NEW_CURRENCY;
522 bRes=sal_True;
525 else
527 bRes=!IsRemoved_Impl( nFound );
530 if ( pAt )
531 *pAt = nFound;
533 return bRes;
537 // -----------------------------------------------------------------------
539 void SvxNumberFormatShell::GetInitSettings(
540 sal_uInt16& nCatLbPos,
541 LanguageType& rLangType,
542 sal_uInt16& nFmtLbSelPos,
543 SvStrings& rFmtEntries,
544 String& rPrevString,
545 Color*& rpPrevColor )
547 // -------------------------------------------------------------------
548 // Vorbedingung: Zahlenformatierer gefunden
549 DBG_ASSERT( pFormatter != NULL, "Zahlenformatierer nicht gefunden!" );
551 // sal_uInt16 nCount = 0;
552 short nSelPos = SELPOS_NONE;
553 // SvNumberFormatTable* pFmtTable = NULL;
555 // Sonderbehandlung fuer undefiniertes Zahlenformat:
556 if ( (eValType == SVX_VALUE_TYPE_UNDEFINED) && (nCurFormatKey == 0) )
557 PosToCategory_Impl( CAT_ALL, nCurCategory ); // Kategorie = Alle
558 else
559 nCurCategory = NUMBERFORMAT_UNDEFINED; // Kategorie = Undefiniert
561 pCurFmtTable = &(pFormatter->GetFirstEntryTable( nCurCategory,
562 nCurFormatKey,
563 eCurLanguage ));
567 CategoryToPos_Impl( nCurCategory, nCatLbPos );
568 rLangType = eCurLanguage;
570 nSelPos = FillEntryList_Impl( rFmtEntries );
572 DBG_ASSERT( nSelPos != SELPOS_NONE, "Leere Formatliste!" );
574 nFmtLbSelPos = (nSelPos != SELPOS_NONE) ? (sal_uInt16)nSelPos : 0;
575 GetPreviewString_Impl( rPrevString, rpPrevColor );
578 // -----------------------------------------------------------------------
580 short SvxNumberFormatShell::FillEntryList_Impl( SvStrings& rList )
582 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
583 * Rueckgabewert ist die Listenposition des aktuellen Formates.
584 * Ist die Liste leer oder gibt es kein aktuelles Format,
585 * so wird SELPOS_NONE geliefert.
587 short nSelPos=0;
588 aCurEntryList.Remove(nSelPos,aCurEntryList.Count());
589 sal_uInt16 nPrivCat = CAT_CURRENCY;
590 nSelPos=SELPOS_NONE;
592 if(nCurCategory==NUMBERFORMAT_ALL)
594 FillEListWithStd_Impl(rList,CAT_NUMBER,nSelPos);
595 FillEListWithStd_Impl(rList,CAT_PERCENT,nSelPos);
596 FillEListWithStd_Impl(rList,CAT_CURRENCY,nSelPos);
597 FillEListWithStd_Impl(rList,CAT_DATE,nSelPos);
598 FillEListWithStd_Impl(rList,CAT_TIME,nSelPos);
599 FillEListWithStd_Impl(rList,CAT_SCIENTIFIC,nSelPos);
600 FillEListWithStd_Impl(rList,CAT_FRACTION,nSelPos);
601 FillEListWithStd_Impl(rList,CAT_BOOLEAN,nSelPos);
602 FillEListWithStd_Impl(rList,CAT_TEXT,nSelPos);
604 else
606 CategoryToPos_Impl(nCurCategory, nPrivCat);
607 FillEListWithStd_Impl(rList,nPrivCat,nSelPos);
610 if( nPrivCat!=CAT_CURRENCY)
611 nSelPos=FillEListWithUsD_Impl(rList,nPrivCat,nSelPos);
613 return nSelPos;
616 void SvxNumberFormatShell::FillEListWithStd_Impl( SvStrings& rList,sal_uInt16 nPrivCat,short &nSelPos )
618 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
619 * Rueckgabewert ist die Listenposition des aktuellen Formates.
620 * Ist die Liste leer oder gibt es kein aktuelles Format,
621 * so wird SELPOS_NONE geliefert.
623 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
625 if(aCurrencyFormatList.Count()>0)
626 aCurrencyFormatList.DeleteAndDestroy(0,aCurrencyFormatList.Count());
628 if(nPrivCat==CAT_CURRENCY)
630 nSelPos=FillEListWithCurrency_Impl(rList,nSelPos);
632 else
634 NfIndexTableOffset eOffsetStart;
635 NfIndexTableOffset eOffsetEnd;
637 switch(nPrivCat)
639 case CAT_NUMBER :eOffsetStart=NF_NUMBER_START;
640 eOffsetEnd=NF_NUMBER_END;
641 break;
642 case CAT_PERCENT :eOffsetStart=NF_PERCENT_START;
643 eOffsetEnd=NF_PERCENT_END;
644 break;
645 case CAT_CURRENCY :eOffsetStart=NF_CURRENCY_START;
646 eOffsetEnd=NF_CURRENCY_END;
647 break;
648 case CAT_DATE :eOffsetStart=NF_DATE_START;
649 eOffsetEnd=NF_DATE_END;
650 break;
651 case CAT_TIME :eOffsetStart=NF_TIME_START;
652 eOffsetEnd=NF_TIME_END;
653 break;
654 case CAT_SCIENTIFIC :eOffsetStart=NF_SCIENTIFIC_START;
655 eOffsetEnd=NF_SCIENTIFIC_END;
656 break;
657 case CAT_FRACTION :eOffsetStart=NF_FRACTION_START;
658 eOffsetEnd=NF_FRACTION_END;
659 break;
660 case CAT_BOOLEAN :eOffsetStart=NF_BOOLEAN;
661 eOffsetEnd=NF_BOOLEAN;
662 break;
663 case CAT_TEXT :eOffsetStart=NF_TEXT;
664 eOffsetEnd=NF_TEXT;
665 break;
666 default :return;
669 nSelPos=FillEListWithFormats_Impl(rList,nSelPos,eOffsetStart,eOffsetEnd);
671 if(nPrivCat==CAT_DATE || nPrivCat==CAT_TIME)
673 nSelPos=FillEListWithDateTime_Impl(rList,nSelPos);
674 //if(nSelPos!=SELPOS_NONE) nSelPos=nTmpPos;
679 short SvxNumberFormatShell::FillEListWithFormats_Impl( SvStrings& rList,short nSelPos,
680 NfIndexTableOffset eOffsetStart,
681 NfIndexTableOffset eOffsetEnd)
683 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
684 * Rueckgabewert ist die Listenposition des aktuellen Formates.
685 * Ist die Liste leer oder gibt es kein aktuelles Format,
686 * so wird SELPOS_NONE geliefert.
688 sal_uInt16 nMyType;
690 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
692 const SvNumberformat* pNumEntry = pCurFmtTable->First();
693 // sal_uInt16 nCount = 0;
694 sal_uInt32 nNFEntry;
695 String aStrComment;
696 String aNewFormNInfo;
697 String aPrevString;
698 String a2PrevString;
700 short nMyCat = SELPOS_NONE;
701 // short nIq=0;
703 long nIndex;
705 for(nIndex=eOffsetStart;nIndex<=eOffsetEnd;nIndex++)
707 nNFEntry=pFormatter->GetFormatIndex((NfIndexTableOffset)nIndex,eCurLanguage);
709 pNumEntry = pFormatter->GetEntry(nNFEntry);
711 if(pNumEntry==NULL) continue;
713 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
714 aStrComment=pNumEntry->GetComment();
715 CategoryToPos_Impl(nMyCat,nMyType);
716 aNewFormNInfo= pNumEntry->GetFormatstring();
718 const StringPtr pStr = new String(aNewFormNInfo);
720 if ( nNFEntry == nCurFormatKey )
722 nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.Count() : SELPOS_NONE;
725 rList.Insert( pStr,rList.Count());
726 aCurEntryList.Insert( nNFEntry, aCurEntryList.Count() );
729 return nSelPos;
732 short SvxNumberFormatShell::FillEListWithDateTime_Impl( SvStrings& rList,short nSelPos)
734 sal_uInt16 nMyType;
736 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
738 const SvNumberformat* pNumEntry = pCurFmtTable->First();
739 // sal_uInt16 nCount = 0;
740 sal_uInt32 nNFEntry;
741 String aStrComment;
742 String aNewFormNInfo;
743 String aPrevString;
744 String a2PrevString;
746 short nMyCat = SELPOS_NONE;
747 // short nIq=0;
749 long nIndex;
751 for(nIndex=NF_DATETIME_START;nIndex<=NF_DATETIME_END;nIndex++)
753 nNFEntry=pFormatter->GetFormatIndex((NfIndexTableOffset)nIndex,eCurLanguage);
755 pNumEntry = pFormatter->GetEntry(nNFEntry);
756 if(pNumEntry!=NULL)
758 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
759 aStrComment=pNumEntry->GetComment();
760 CategoryToPos_Impl(nMyCat,nMyType);
761 aNewFormNInfo= pNumEntry->GetFormatstring();
763 const StringPtr pStr = new String(aNewFormNInfo);
765 if ( nNFEntry == nCurFormatKey )
767 nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.Count() : SELPOS_NONE;
770 rList.Insert( pStr,rList.Count());
771 aCurEntryList.Insert( nNFEntry, aCurEntryList.Count() );
775 return nSelPos;
778 short SvxNumberFormatShell::FillEListWithCurrency_Impl( SvStrings& rList,short nSelPos)
780 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
781 * Rueckgabewert ist die Listenposition des aktuellen Formates.
782 * Ist die Liste leer oder gibt es kein aktuelles Format,
783 * so wird SELPOS_NONE geliefert.
785 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
787 const NfCurrencyEntry* pTmpCurrencyEntry;
788 sal_Bool bTmpBanking;
789 XubString rSymbol;
791 sal_Bool bFlag=pFormatter->GetNewCurrencySymbolString(nCurFormatKey,rSymbol,
792 &pTmpCurrencyEntry,&bTmpBanking);
794 if((!bFlag && pCurCurrencyEntry==NULL) ||
795 (bFlag && pTmpCurrencyEntry==NULL && !rSymbol.Len()) ||
796 nCurCategory==NUMBERFORMAT_ALL)
798 if ( nCurCategory == NUMBERFORMAT_ALL )
799 FillEListWithUserCurrencys(rList,nSelPos);
800 nSelPos=FillEListWithSysCurrencys(rList,nSelPos);
802 else
804 nSelPos=FillEListWithUserCurrencys(rList,nSelPos);
807 return nSelPos;
811 short SvxNumberFormatShell::FillEListWithSysCurrencys( SvStrings& rList,short nSelPos)
813 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
814 * Rueckgabewert ist die Listenposition des aktuellen Formates.
815 * Ist die Liste leer oder gibt es kein aktuelles Format,
816 * so wird SELPOS_NONE geliefert.
818 sal_uInt16 nMyType;
820 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
822 const SvNumberformat* pNumEntry = pCurFmtTable->First();
823 sal_uInt16 nCount = 0;
824 sal_uInt32 nNFEntry;
825 String aStrComment;
826 String aNewFormNInfo;
827 String aPrevString;
828 String a2PrevString;
830 nCurCurrencyEntryPos=0;
832 short nMyCat = SELPOS_NONE;
833 // short nIq=0;
835 NfIndexTableOffset eOffsetStart=NF_CURRENCY_START;
836 NfIndexTableOffset eOffsetEnd=NF_CURRENCY_END;;
837 long nIndex;
839 for(nIndex=eOffsetStart;nIndex<=eOffsetEnd;nIndex++)
841 nNFEntry=pFormatter->GetFormatIndex((NfIndexTableOffset)nIndex,eCurLanguage);
843 pNumEntry = pFormatter->GetEntry(nNFEntry);
845 if(pNumEntry==NULL) continue;
847 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
848 aStrComment=pNumEntry->GetComment();
849 CategoryToPos_Impl(nMyCat,nMyType);
850 aNewFormNInfo= pNumEntry->GetFormatstring();
852 const StringPtr pStr = new String(aNewFormNInfo);
854 if ( nNFEntry == nCurFormatKey )
856 nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.Count() : SELPOS_NONE;
859 rList.Insert( pStr,rList.Count());
860 aCurEntryList.Insert( nNFEntry, aCurEntryList.Count() );
863 if(nCurCategory!=NUMBERFORMAT_ALL)
865 pNumEntry = pCurFmtTable->First();
866 nCount = 0;
867 while ( pNumEntry )
869 sal_uInt32 nKey = pCurFmtTable->GetCurKey();
871 nCount++;
873 if ( !IsRemoved_Impl( nKey ))
875 sal_Bool bUserNewCurrency=sal_False;
876 if(pNumEntry->HasNewCurrency())
878 const NfCurrencyEntry* pTmpCurrencyEntry;
879 sal_Bool bTmpBanking;
880 XubString rSymbol;
882 pFormatter->GetNewCurrencySymbolString(nKey,rSymbol,
883 &pTmpCurrencyEntry,&bTmpBanking);
885 bUserNewCurrency=(pTmpCurrencyEntry!=NULL);
888 if(!bUserNewCurrency &&(pNumEntry->GetType() & NUMBERFORMAT_DEFINED))
890 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
891 aStrComment=pNumEntry->GetComment();
892 CategoryToPos_Impl(nMyCat,nMyType);
893 aNewFormNInfo= pNumEntry->GetFormatstring();
895 const StringPtr pStr = new String(aNewFormNInfo);
897 if ( nKey == nCurFormatKey ) nSelPos =aCurEntryList.Count();
898 rList.Insert( pStr,rList.Count());
899 aCurEntryList.Insert( nKey, aCurEntryList.Count() );
902 pNumEntry = pCurFmtTable->Next();
905 return nSelPos;
908 short SvxNumberFormatShell::FillEListWithUserCurrencys( SvStrings& rList,short nSelPos)
910 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
911 * Rueckgabewert ist die Listenposition des aktuellen Formates.
912 * Ist die Liste leer oder gibt es kein aktuelles Format,
913 * so wird SELPOS_NONE geliefert.
915 sal_uInt16 nMyType;
917 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
919 sal_uInt16 nCount = 0;
920 String aStrComment;
921 String aNewFormNInfo;
922 String aPrevString;
923 String a2PrevString;
924 short nMyCat = SELPOS_NONE;
925 // short nIq=0;
927 const NfCurrencyEntry* pTmpCurrencyEntry;
928 sal_Bool bTmpBanking, bAdaptSelPos;
929 XubString rSymbol;
930 XubString rBankSymbol;
932 SvStrings aList;
933 SvULongs aKeyList;
935 /*sal_Bool bFlag=*/pFormatter->GetNewCurrencySymbolString(nCurFormatKey,rSymbol,
936 &pTmpCurrencyEntry,&bTmpBanking);
938 XubString rShortSymbol;
940 if(pCurCurrencyEntry==NULL)
942 // #110398# If no currency format was previously selected (we're not
943 // about to add another currency), try to select the initial currency
944 // format (nCurFormatKey) that was set in FormatChanged() after
945 // matching the format string entered in the dialog.
946 bAdaptSelPos = sal_True;
947 pCurCurrencyEntry=(NfCurrencyEntry*)pTmpCurrencyEntry;
948 bBankingSymbol=bTmpBanking;
949 nCurCurrencyEntryPos=FindCurrencyFormat(pTmpCurrencyEntry,bTmpBanking);
951 else
953 if (pTmpCurrencyEntry == pCurCurrencyEntry)
954 bAdaptSelPos = sal_True;
955 else
957 bAdaptSelPos = sal_False;
958 pTmpCurrencyEntry = pCurCurrencyEntry;
960 bTmpBanking=bBankingSymbol;
963 if(pTmpCurrencyEntry!=NULL)
965 pTmpCurrencyEntry->BuildSymbolString(rSymbol,sal_False);
966 pTmpCurrencyEntry->BuildSymbolString(rBankSymbol,sal_True);
967 pTmpCurrencyEntry->BuildSymbolString(rShortSymbol,bTmpBanking,sal_True);
970 const SvNumberformat* pNumEntry = pCurFmtTable->First();
972 while ( pNumEntry )
974 sal_uInt32 nKey = pCurFmtTable->GetCurKey();
976 nCount++;
978 if ( !IsRemoved_Impl( nKey ) )
980 if( pNumEntry->GetType() & NUMBERFORMAT_DEFINED ||
981 pNumEntry->IsAdditionalStandardDefined() )
983 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
984 aStrComment=pNumEntry->GetComment();
985 CategoryToPos_Impl(nMyCat,nMyType);
986 aNewFormNInfo= pNumEntry->GetFormatstring();
988 sal_Bool bInsFlag=sal_False;
989 if ( pNumEntry->HasNewCurrency() )
990 bInsFlag = sal_True; // merge locale formats into currency selection
991 else if( (!bTmpBanking && aNewFormNInfo.Search(rSymbol)!=STRING_NOTFOUND) ||
992 (bTmpBanking && aNewFormNInfo.Search(rBankSymbol)!=STRING_NOTFOUND) )
994 bInsFlag=sal_True;
996 else if(aNewFormNInfo.Search(rShortSymbol)!=STRING_NOTFOUND)
998 XubString rTstSymbol;
999 const NfCurrencyEntry* pTstCurrencyEntry;
1000 sal_Bool bTstBanking;
1002 /*sal_Bool bTstFlag=*/pFormatter->GetNewCurrencySymbolString(nKey,rTstSymbol,
1003 &pTstCurrencyEntry,&bTstBanking);
1005 if(pTmpCurrencyEntry==pTstCurrencyEntry && bTstBanking==bTmpBanking)
1007 bInsFlag=sal_True;
1012 if(bInsFlag)
1014 const StringPtr pStr = new String(aNewFormNInfo);
1016 aList.Insert( pStr,aList.Count());
1017 aKeyList.Insert( nKey, aKeyList.Count() );
1021 pNumEntry = pCurFmtTable->Next();
1024 NfWSStringsDtor aWSStringsDtor;
1025 sal_uInt16 nDefault;
1026 if ( pTmpCurrencyEntry && nCurCategory != NUMBERFORMAT_ALL )
1028 nDefault = pFormatter->GetCurrencyFormatStrings(
1029 aWSStringsDtor, *pTmpCurrencyEntry, bTmpBanking );
1030 if ( !bTmpBanking )
1031 pFormatter->GetCurrencyFormatStrings(
1032 aWSStringsDtor, *pTmpCurrencyEntry, TRUE );
1034 else
1035 nDefault = 0;
1036 if ( !bTmpBanking && nCurCategory != NUMBERFORMAT_ALL )
1037 { // append formats for all currencies defined in the current I18N locale
1038 const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable();
1039 sal_uInt16 nCurrCount = rCurrencyTable.Count();
1040 LanguageType eLang = MsLangId::getRealLanguage( eCurLanguage );
1041 for ( sal_uInt16 i=0; i < nCurrCount; ++i )
1043 const NfCurrencyEntry* pCurr = rCurrencyTable[i];
1044 if ( pCurr->GetLanguage() == eLang && pTmpCurrencyEntry != pCurr )
1046 pFormatter->GetCurrencyFormatStrings( aWSStringsDtor, *pCurr, FALSE );
1047 pFormatter->GetCurrencyFormatStrings( aWSStringsDtor, *pCurr, TRUE );
1052 sal_uInt16 i,nPos;
1053 sal_uInt16 nOldListCount = rList.Count();
1054 for( i=0, nPos=nOldListCount; i<aWSStringsDtor.Count(); i++)
1056 sal_Bool bFlag=sal_True;
1057 String aInsStr(*aWSStringsDtor[i]);
1058 sal_uInt16 j;
1059 for(j=0;j<aList.Count();j++)
1061 const StringPtr pTestStr=aList[j];
1063 if(*pTestStr==aInsStr)
1065 bFlag=sal_False;
1066 break;
1069 if(bFlag)
1071 rList.Insert(new String(aInsStr),nPos);
1072 aCurEntryList.Insert( NUMBERFORMAT_ENTRY_NOT_FOUND, nPos++);
1074 else
1076 rList.Insert(aList[j],nPos);
1077 aList.Remove(j);
1078 aCurEntryList.Insert( aKeyList[j],nPos++);
1079 aKeyList.Remove(j);
1083 for(i=0;i<aKeyList.Count();i++)
1085 if(aKeyList[i]!=NUMBERFORMAT_ENTRY_NOT_FOUND)
1087 rList.Insert(aList[i],rList.Count());
1088 aCurEntryList.Insert( aKeyList[i],aCurEntryList.Count());
1092 for(i=nOldListCount;i<rList.Count();i++)
1094 aCurrencyFormatList.Insert(new String(*rList[i]),aCurrencyFormatList.Count());
1096 if ( nSelPos == SELPOS_NONE && bAdaptSelPos && aCurEntryList[i] == nCurFormatKey )
1097 nSelPos = i;
1100 if ( nSelPos == SELPOS_NONE && nCurCategory != NUMBERFORMAT_ALL )
1101 nSelPos = nDefault;
1103 return nSelPos;
1107 short SvxNumberFormatShell::FillEListWithUsD_Impl( SvStrings& rList, sal_uInt16 nPrivCat, short nSelPos)
1109 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
1110 * Rueckgabewert ist die Listenposition des aktuellen Formates.
1111 * Ist die Liste leer oder gibt es kein aktuelles Format,
1112 * so wird SELPOS_NONE geliefert.
1114 sal_uInt16 nMyType;
1116 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
1118 const SvNumberformat* pNumEntry = pCurFmtTable->First();
1119 sal_uInt16 nCount = 0;
1120 String aStrComment;
1121 String aNewFormNInfo;
1122 String aPrevString;
1123 String a2PrevString;
1125 short nMyCat = SELPOS_NONE;
1126 // short nIq=0;
1127 sal_Bool bAdditional = (nPrivCat != CAT_USERDEFINED &&
1128 nCurCategory != NUMBERFORMAT_ALL);
1130 while ( pNumEntry )
1132 sal_uInt32 nKey = pCurFmtTable->GetCurKey();
1134 nCount++;
1136 if ( !IsRemoved_Impl( nKey ) )
1138 if( (pNumEntry->GetType() & NUMBERFORMAT_DEFINED) ||
1139 (bAdditional && pNumEntry->IsAdditionalStandardDefined()) )
1141 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
1142 aStrComment=pNumEntry->GetComment();
1143 CategoryToPos_Impl(nMyCat,nMyType);
1144 aNewFormNInfo= pNumEntry->GetFormatstring();
1146 sal_Bool bFlag=sal_True;
1147 if(pNumEntry->HasNewCurrency())
1149 sal_Bool bTestBanking;
1150 sal_uInt16 nPos=FindCurrencyTableEntry(aNewFormNInfo,bTestBanking);
1151 bFlag=!IsInTable(nPos,bTestBanking,aNewFormNInfo);
1153 if(bFlag)
1155 const StringPtr pStr = new String(aNewFormNInfo);
1157 if ( nKey == nCurFormatKey ) nSelPos =aCurEntryList.Count();
1158 rList.Insert( pStr,rList.Count());
1159 aCurEntryList.Insert( nKey, aCurEntryList.Count() );
1163 pNumEntry = pCurFmtTable->Next();
1165 return nSelPos;
1169 // -----------------------------------------------------------------------
1171 void SvxNumberFormatShell::GetPreviewString_Impl( String& rString, Color*& rpColor )
1173 rpColor = NULL;
1175 // #50441# if a string was set in addition to the value, use it for text formats
1176 BOOL bUseText = ( eValType == SVX_VALUE_TYPE_STRING ||
1177 ( aValStr.Len() && ( pFormatter->GetType(nCurFormatKey) & NUMBERFORMAT_TEXT ) ) );
1179 if ( bUseText )
1180 pFormatter->GetOutputString( aValStr, nCurFormatKey, rString, &rpColor );
1181 else
1182 pFormatter->GetOutputString( nValNum, nCurFormatKey, rString, &rpColor );
1185 // -----------------------------------------------------------------------
1187 sal_Bool SvxNumberFormatShell::IsRemoved_Impl( sal_uInt32 nKey )
1189 sal_Bool bFound = sal_False;
1190 for ( sal_uInt16 i = 0; !bFound && i < aDelList.Count(); ++i )
1191 if ( aDelList[i] == nKey )
1192 bFound = sal_True;
1193 return bFound;
1196 // -----------------------------------------------------------------------
1198 sal_Bool SvxNumberFormatShell::IsAdded_Impl( sal_uInt32 nKey )
1200 sal_Bool bFound = sal_False;
1201 for ( sal_uInt16 i = 0; !bFound && i < aAddList.Count(); ++i )
1202 if ( aAddList[i] == nKey )
1203 bFound = sal_True;
1204 return bFound;
1207 // -----------------------------------------------------------------------
1208 // Konvertierungs-Routinen:
1209 // ------------------------
1211 void SvxNumberFormatShell::PosToCategory_Impl( sal_uInt16 nPos, short& rCategory )
1213 // Kategorie ::com::sun::star::form-Positionen abbilden (->Resource)
1214 switch ( nPos )
1216 case CAT_USERDEFINED: rCategory = NUMBERFORMAT_DEFINED; break;
1217 case CAT_NUMBER: rCategory = NUMBERFORMAT_NUMBER; break;
1218 case CAT_PERCENT: rCategory = NUMBERFORMAT_PERCENT; break;
1219 case CAT_CURRENCY: rCategory = NUMBERFORMAT_CURRENCY; break;
1220 case CAT_DATE: rCategory = NUMBERFORMAT_DATE; break;
1221 case CAT_TIME: rCategory = NUMBERFORMAT_TIME; break;
1222 case CAT_SCIENTIFIC: rCategory = NUMBERFORMAT_SCIENTIFIC; break;
1223 case CAT_FRACTION: rCategory = NUMBERFORMAT_FRACTION; break;
1224 case CAT_BOOLEAN: rCategory = NUMBERFORMAT_LOGICAL; break;
1225 case CAT_TEXT: rCategory = NUMBERFORMAT_TEXT; break;
1226 case CAT_ALL:
1227 default: rCategory = NUMBERFORMAT_ALL; break;
1231 // -----------------------------------------------------------------------
1233 void SvxNumberFormatShell::CategoryToPos_Impl( short nCategory, sal_uInt16& rPos )
1235 // Kategorie auf ::com::sun::star::form-Positionen abbilden (->Resource)
1236 switch ( nCategory )
1238 case NUMBERFORMAT_DEFINED: rPos = CAT_USERDEFINED; break;
1239 case NUMBERFORMAT_NUMBER: rPos = CAT_NUMBER; break;
1240 case NUMBERFORMAT_PERCENT: rPos = CAT_PERCENT; break;
1241 case NUMBERFORMAT_CURRENCY: rPos = CAT_CURRENCY; break;
1242 case NUMBERFORMAT_DATETIME:
1243 case NUMBERFORMAT_DATE: rPos = CAT_DATE; break;
1244 case NUMBERFORMAT_TIME: rPos = CAT_TIME; break;
1245 case NUMBERFORMAT_SCIENTIFIC: rPos = CAT_SCIENTIFIC; break;
1246 case NUMBERFORMAT_FRACTION: rPos = CAT_FRACTION; break;
1247 case NUMBERFORMAT_LOGICAL: rPos = CAT_BOOLEAN; break;
1248 case NUMBERFORMAT_TEXT: rPos = CAT_TEXT; break;
1249 case NUMBERFORMAT_ALL:
1250 default: rPos = CAT_ALL;
1255 /*************************************************************************
1256 #* Member: MakePrevStringFromVal Datum:19.09.97
1257 #*------------------------------------------------------------------------
1259 #* Klasse: SvxNumberFormatShell
1261 #* Funktion: Formatiert die Zahl nValue abhaengig von rFormatStr
1262 #* und speichert das Ergebnis in rPreviewStr.
1264 #* Input: FormatString, Farbe, zu formatierende Zahl
1266 #* Output: Ausgabestring rPreviewStr
1268 #************************************************************************/
1270 void SvxNumberFormatShell::MakePrevStringFromVal(
1271 const String& rFormatStr,
1272 String& rPreviewStr,
1273 Color*& rpFontColor,
1274 double nValue)
1276 rpFontColor = NULL;
1277 pFormatter->GetPreviewString( rFormatStr, nValue, rPreviewStr, &rpFontColor, eCurLanguage );
1280 /*************************************************************************
1281 #* Member: GetComment4Entry Datum:30.10.97
1282 #*------------------------------------------------------------------------
1284 #* Klasse: SvxNumberFormatShell
1286 #* Funktion: Liefert den Kommentar fuer einen gegebenen
1287 #* Eintrag zurueck.
1289 #* Input: Nummer des Eintrags
1291 #* Output: Kommentar-String
1293 #************************************************************************/
1295 void SvxNumberFormatShell::SetComment4Entry(short nEntry,String aEntStr)
1297 SvNumberformat *pNumEntry;
1298 if(nEntry<0) return;
1299 sal_uInt32 nMyNfEntry=aCurEntryList[nEntry];
1300 pNumEntry = (SvNumberformat*)pFormatter->GetEntry(nMyNfEntry);
1301 if(pNumEntry!=NULL) pNumEntry->SetComment(aEntStr);
1304 /*************************************************************************
1305 #* Member: GetComment4Entry Datum:30.10.97
1306 #*------------------------------------------------------------------------
1308 #* Klasse: SvxNumberFormatShell
1310 #* Funktion: Liefert den Kommentar fuer einen gegebenen
1311 #* Eintrag zurueck.
1313 #* Input: Nummer des Eintrags
1315 #* Output: Kommentar-String
1317 #************************************************************************/
1319 String SvxNumberFormatShell::GetComment4Entry(short nEntry)
1321 const SvNumberformat *pNumEntry;
1323 if(nEntry < 0)
1324 return String();
1326 if(nEntry<aCurEntryList.Count())
1328 sal_uInt32 nMyNfEntry=aCurEntryList[nEntry];
1329 pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1330 if(pNumEntry!=NULL)
1331 return pNumEntry->GetComment();
1334 return String();
1337 /*************************************************************************
1338 #* Member: GetCategory4Entry Datum:30.10.97
1339 #*------------------------------------------------------------------------
1341 #* Klasse: SvxNumberFormatShell
1343 #* Funktion: Liefert die Kategorie- Nummer fuer einen gegebenen
1344 #* Eintrag zurueck.
1346 #* Input: Nummer des Eintrags
1348 #* Output: Kategorie- Nummer
1350 #************************************************************************/
1352 short SvxNumberFormatShell::GetCategory4Entry(short nEntry)
1354 const SvNumberformat *pNumEntry;
1355 if(nEntry<0) return 0;
1357 if(nEntry<aCurEntryList.Count())
1359 sal_uInt32 nMyNfEntry=aCurEntryList[nEntry];
1361 if(nMyNfEntry!=NUMBERFORMAT_ENTRY_NOT_FOUND)
1363 pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1364 sal_uInt16 nMyCat,nMyType;
1365 if(pNumEntry!=NULL)
1367 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
1368 CategoryToPos_Impl(nMyCat,nMyType);
1370 return (short) nMyType;
1372 return 0;
1374 else if(aCurrencyFormatList.Count()>0)
1376 return CAT_CURRENCY;
1379 return 0;
1383 /*************************************************************************
1384 #* Member: GetUserDefined4Entry Datum:31.10.97
1385 #*------------------------------------------------------------------------
1387 #* Klasse: SvxNumberFormatShell
1389 #* Funktion: Liefert die Information, ob ein Eintrag
1390 #* benutzerspezifisch ist zurueck.
1392 #* Input: Nummer des Eintrags
1394 #* Output: Benutzerspezifisch?
1396 #************************************************************************/
1398 sal_Bool SvxNumberFormatShell::GetUserDefined4Entry(short nEntry)
1400 const SvNumberformat *pNumEntry;
1401 if(nEntry<0) return 0;
1402 if(nEntry<aCurEntryList.Count())
1404 sal_uInt32 nMyNfEntry=aCurEntryList[nEntry];
1405 pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1407 if(pNumEntry!=NULL)
1409 if((pNumEntry->GetType() & NUMBERFORMAT_DEFINED)>0)
1411 return sal_True;
1415 return sal_False;
1419 /*************************************************************************
1420 #* Member: GetFormat4Entry Datum:30.10.97
1421 #*------------------------------------------------------------------------
1423 #* Klasse: SvxNumberFormatShell
1425 #* Funktion: Liefert den Format- String fuer einen gegebenen
1426 #* Eintrag zurueck.
1428 #* Input: Nummer des Eintrags
1430 #* Output: Format- String
1432 #************************************************************************/
1434 String SvxNumberFormatShell::GetFormat4Entry(short nEntry)
1436 const SvNumberformat *pNumEntry;
1438 if(nEntry < 0)
1439 return String();
1441 if(aCurrencyFormatList.Count()>0)
1443 if(aCurrencyFormatList.Count()>nEntry)
1444 return *aCurrencyFormatList[nEntry];
1446 else
1448 sal_uInt32 nMyNfEntry=aCurEntryList[nEntry];
1449 pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1451 if(pNumEntry!=NULL)
1452 return pNumEntry->GetFormatstring();
1454 return String();
1457 /*************************************************************************
1458 #* Member: GetListPos4Entry Datum:31.10.97
1459 #*------------------------------------------------------------------------
1461 #* Klasse: SvxNumberFormatShell
1463 #* Funktion: Liefert die Listen- Nummer fuer einen gegebenen
1464 #* Formatindex zurueck.
1466 #* Input: Nummer des Eintrags
1468 #* Output: Kategorie- Nummer
1470 #************************************************************************/
1472 short SvxNumberFormatShell::GetListPos4Entry(sal_uInt32 nIdx)
1474 short nSelP=SELPOS_NONE;
1475 if( aCurEntryList.Count() <= 0x7fff )
1477 for(short i=0;i<aCurEntryList.Count();i++)
1479 if(aCurEntryList[i]==nIdx)
1481 nSelP=i;
1482 break;
1486 else
1488 DBG_ERROR("svx::SvxNumberFormatShell::GetListPos4Entry(), list got to large!" );
1490 return nSelP;
1493 short SvxNumberFormatShell::GetListPos4Entry( const String& rFmtString )
1495 sal_uInt32 nAt=0;
1496 short nSelP=SELPOS_NONE;
1497 if(FindEntry(rFmtString, &nAt))
1499 if(NUMBERFORMAT_ENTRY_NOT_FOUND!=nAt && NUMBERFORMAT_ENTRY_NEW_CURRENCY!=nAt)
1501 nSelP=GetListPos4Entry(nAt);
1503 else
1505 if(aCurrencyFormatList.Count()>0)
1507 for(sal_uInt16 i=0;i<aCurrencyFormatList.Count();i++)
1509 if (rFmtString==*aCurrencyFormatList[i])
1511 nSelP=i;
1512 break;
1518 return nSelP;
1521 String SvxNumberFormatShell::GetStandardName() const
1523 return pFormatter->GetStandardName( eCurLanguage);
1526 void SvxNumberFormatShell::GetCurrencySymbols(SvStringsDtor& rList,const XubString& rStrEurope, sal_uInt16* pPos)
1529 const NfCurrencyEntry* pTmpCurrencyEntry=SvNumberFormatter::MatchSystemCurrency();
1531 sal_Bool bFlag=(pTmpCurrencyEntry==NULL);
1533 GetCurrencySymbols(rList,rStrEurope, bFlag);
1535 if(pPos!=NULL)
1537 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1538 sal_uInt16 nCount=rCurrencyTable.Count();
1540 *pPos=0;
1541 nCount=aCurCurrencyList.Count();
1543 if(bFlag)
1545 *pPos=1;
1546 nCurCurrencyEntryPos=1;
1548 else
1550 for(sal_uInt16 i=1;i<nCount;i++)
1552 if(aCurCurrencyList[i]!=(sal_uInt16)-1 &&
1553 pTmpCurrencyEntry==rCurrencyTable[aCurCurrencyList[i]])
1555 *pPos=i;
1556 nCurCurrencyEntryPos=i;
1557 break;
1565 void SvxNumberFormatShell::GetCurrencySymbols(SvStringsDtor& rList,const XubString& /*rStrEurope*/, sal_Bool bFlag)
1567 aCurCurrencyList.Remove(0,aCurCurrencyList.Count());
1569 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1570 sal_uInt16 nCount=rCurrencyTable.Count();
1572 SvtLanguageTable* pLanguageTable=new SvtLanguageTable;
1574 sal_uInt16 nStart=1;
1575 sal_uInt16 i,j;
1577 XubString aString(rCurrencyTable[0]->GetSymbol());
1578 aString += sal_Unicode(' ');
1579 aString += pLanguageTable->GetString(rCurrencyTable[0]->GetLanguage());
1581 WSStringPtr pStr = new XubString(aString);
1582 rList.Insert( pStr,rList.Count());
1583 sal_uInt16 nAuto=(sal_uInt16)-1;
1584 aCurCurrencyList.Insert(nAuto,aCurCurrencyList.Count());
1586 if(bFlag)
1588 pStr = new XubString(aString);
1589 rList.Insert( pStr,rList.Count());
1590 aCurCurrencyList.Insert((sal_uInt16)0,aCurCurrencyList.Count());
1591 ++nStart;
1594 for(i=1;i<nCount;i++)
1596 XubString _aString(rCurrencyTable[i]->GetSymbol());
1597 _aString += sal_Unicode(' ');
1598 _aString += pLanguageTable->GetString(rCurrencyTable[i]->GetLanguage());
1600 pStr = new XubString(_aString);
1602 for(j=nStart;j<rList.Count();j++)
1604 const StringPtr pTestStr=rList[j];
1606 if(*pTestStr>aString) break;
1608 rList.Insert( pStr,j);
1609 aCurCurrencyList.Insert(i,j);
1612 sal_uInt16 nCont = rList.Count();
1614 for(i=1;i<nCount;i++)
1616 sal_Bool bTest=sal_True;
1617 pStr = new XubString(rCurrencyTable[i]->GetBankSymbol());
1619 for(j=nCont;j<rList.Count();j++)
1621 const StringPtr pTestStr=rList[j];
1623 if(*pTestStr==*pStr)
1624 bTest=sal_False;
1625 else
1626 if(*pTestStr>*pStr) break;
1628 if(bTest)
1630 rList.Insert( pStr,j);
1631 aCurCurrencyList.Insert(i,j);
1635 delete pLanguageTable;
1638 void SvxNumberFormatShell::GetCurrencyFormats(SvStrings& aListDtor)
1640 if(pCurCurrencyEntry!=NULL)
1642 NfWSStringsDtor aWSStringsDtor;
1643 /*sal_uInt16 nDefault = */pFormatter->GetCurrencyFormatStrings( aWSStringsDtor,
1644 *pCurCurrencyEntry, bBankingSymbol );
1646 for(sal_uInt16 i=0;i<aWSStringsDtor.Count();i++)
1648 aListDtor.Insert(new String(*aWSStringsDtor[i]),aListDtor.Count());
1653 sal_Bool SvxNumberFormatShell::IsBankingSymbol(sal_uInt16 nPos)
1655 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1656 sal_uInt16 nCount=rCurrencyTable.Count();
1658 return (nPos>nCount);
1661 void SvxNumberFormatShell::SetCurrencySymbol(sal_uInt16 nPos)
1663 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1664 sal_uInt16 nCount=rCurrencyTable.Count();
1666 bBankingSymbol=(nPos>=nCount);
1668 if(nPos<aCurCurrencyList.Count())
1670 sal_uInt16 nCurrencyPos=aCurCurrencyList[nPos];
1671 if(nCurrencyPos!=(sal_uInt16)-1)
1673 pCurCurrencyEntry=rCurrencyTable[nCurrencyPos];
1674 nCurCurrencyEntryPos=nPos;
1676 else
1678 pCurCurrencyEntry=NULL;
1679 nCurCurrencyEntryPos=0;
1680 nCurFormatKey=pFormatter->GetFormatIndex(
1681 NF_CURRENCY_1000DEC2_RED, eCurLanguage);
1686 sal_uInt32 SvxNumberFormatShell::GetCurrencySymbol()
1688 return nCurCurrencyEntryPos;
1691 NfCurrencyEntry* SvxNumberFormatShell::GetCurCurrencyEntry()
1693 return pCurCurrencyEntry;
1696 void SvxNumberFormatShell::SetCurCurrencyEntry(NfCurrencyEntry* pCEntry)
1698 pCurCurrencyEntry=pCEntry;
1701 sal_Bool SvxNumberFormatShell::IsTmpCurrencyFormat( const String& rFmtString )
1703 sal_uInt32 nFound;
1704 /*sal_Bool bRes=*/FindEntry(rFmtString, &nFound);
1706 if(nFound==NUMBERFORMAT_ENTRY_NEW_CURRENCY)
1708 return sal_True;
1710 return sal_False;
1713 sal_uInt16 SvxNumberFormatShell::FindCurrencyFormat( const String& rFmtString )
1715 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1716 sal_uInt16 nCount=rCurrencyTable.Count();
1718 sal_Bool bTestBanking=sal_False;
1720 sal_uInt16 nPos=FindCurrencyTableEntry(rFmtString, bTestBanking);
1722 sal_uInt16 nStart=0;
1724 if(nPos!=(sal_uInt16)-1)
1726 if(bTestBanking && aCurCurrencyList.Count()>nPos)
1728 nStart=nCount;
1730 for(sal_uInt16 j=nStart;j<aCurCurrencyList.Count();j++)
1732 if(aCurCurrencyList[j]==nPos) return j;
1735 return (sal_uInt16) -1;
1738 sal_uInt16 SvxNumberFormatShell::FindCurrencyTableEntry( const String& rFmtString, sal_Bool &bTestBanking )
1740 sal_uInt16 nPos=(sal_uInt16) -1;
1742 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1743 sal_uInt16 nCount=rCurrencyTable.Count();
1745 const SvNumberformat* pFormat;
1746 String aSymbol, aExtension;
1747 sal_uInt32 nFound = pFormatter->TestNewString( rFmtString, eCurLanguage );
1748 if ( nFound != NUMBERFORMAT_ENTRY_NOT_FOUND &&
1749 ((pFormat = pFormatter->GetEntry( nFound )) != 0) &&
1750 pFormat->GetNewCurrencySymbol( aSymbol, aExtension ) )
1751 { // eventually match with format locale
1752 const NfCurrencyEntry* pTmpCurrencyEntry =
1753 SvNumberFormatter::GetCurrencyEntry( bTestBanking, aSymbol, aExtension,
1754 pFormat->GetLanguage() );
1755 if ( pTmpCurrencyEntry )
1757 for(sal_uInt16 i=0;i<nCount;i++)
1759 if(pTmpCurrencyEntry==rCurrencyTable[i])
1761 nPos=i;
1762 break;
1767 else
1768 { // search symbol string only
1769 for(sal_uInt16 i=0;i<nCount;i++)
1771 const NfCurrencyEntry* pTmpCurrencyEntry=rCurrencyTable[i];
1772 XubString _aSymbol, aBankSymbol;
1773 pTmpCurrencyEntry->BuildSymbolString(_aSymbol,sal_False);
1774 pTmpCurrencyEntry->BuildSymbolString(aBankSymbol,sal_True);
1776 if(rFmtString.Search(_aSymbol)!=STRING_NOTFOUND)
1778 bTestBanking=sal_False;
1779 nPos=i;
1780 break;
1782 else if(rFmtString.Search(aBankSymbol)!=STRING_NOTFOUND)
1784 bTestBanking=sal_True;
1785 nPos=i;
1786 break;
1791 return nPos;
1794 sal_uInt16 SvxNumberFormatShell::FindCurrencyFormat(const NfCurrencyEntry* pTmpCurrencyEntry,sal_Bool bTmpBanking)
1796 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1797 sal_uInt16 nCount=rCurrencyTable.Count();
1799 // sal_Bool bTestBanking=sal_False;
1800 sal_uInt16 nPos=0;
1801 for(sal_uInt16 i=0;i<nCount;i++)
1803 if(pTmpCurrencyEntry==rCurrencyTable[i])
1805 nPos=i;
1806 break;
1810 sal_uInt16 nStart=0;
1811 if(bTmpBanking && aCurCurrencyList.Count()>nPos)
1813 nStart=nCount;
1815 for(sal_uInt16 j=nStart;j<aCurCurrencyList.Count();j++)
1817 if(aCurCurrencyList[j]==nPos) return j;
1819 return (sal_uInt16) -1;
1822 sal_Bool SvxNumberFormatShell::IsInTable(sal_uInt16 nPos,sal_Bool bTmpBanking,const String &rFmtString)
1824 sal_Bool bFlag=sal_False;
1826 if(nPos!=(sal_uInt16)-1)
1828 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1829 sal_uInt16 nCount=rCurrencyTable.Count();
1831 if(nPos<nCount)
1833 NfWSStringsDtor aWSStringsDtor;
1834 sal_uInt16 nDefault;
1836 const NfCurrencyEntry* pTmpCurrencyEntry=rCurrencyTable[nPos];
1838 if ( pTmpCurrencyEntry!=NULL)
1840 nDefault = pFormatter->GetCurrencyFormatStrings( aWSStringsDtor,
1841 *pTmpCurrencyEntry, bTmpBanking );
1843 for(sal_uInt16 i=0;i<aWSStringsDtor.Count();i++)
1845 if(*aWSStringsDtor[i]==rFmtString)
1847 bFlag=sal_True;
1848 break;
1855 return bFlag;