merge the formfield patch from ooo-build
[ooovba.git] / svx / source / items / numfmtsh.cxx
blob96ce38d50b01471a8141e18e83fb3e7ddb69170a
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>
48 #include <comphelper/processfactory.hxx>
50 #include <svx/numfmtsh.hxx>
51 // class SvxNumberFormatShell --------------------------------------------
53 const double SvxNumberFormatShell::DEFAULT_NUMVALUE = 1234.56789;
55 SV_IMPL_PTRARR( NfShCurrencyEntries, NfCurrencyEntry* );
57 // -----------------------------------------------------------------------
61 SvxNumberFormatShell* SvxNumberFormatShell::Create( SvNumberFormatter* pNumFormatter,
62 sal_uInt32 nFormatKey,
63 SvxNumberValueType eNumValType,
64 const String& rNumStr )
66 return new SvxNumberFormatShell(pNumFormatter,nFormatKey,
67 eNumValType,rNumStr );
70 SvxNumberFormatShell* SvxNumberFormatShell::Create( SvNumberFormatter* pNumFormatter,
71 sal_uInt32 nFormatKey,
72 SvxNumberValueType eNumValType,
73 double nNumVal,
74 const String* pNumStr )
76 return new SvxNumberFormatShell(pNumFormatter,nFormatKey,
77 eNumValType,nNumVal,pNumStr );
80 // -----------------------------------------------------------------------
82 #define _INIT \
83 pFormatter ( pNumFormatter ), \
84 pCurFmtTable ( NULL ), \
85 eValType ( eNumValType ), \
86 bUndoAddList ( sal_True ), \
87 nInitFormatKey ( nFormatKey ), \
88 nCurFormatKey ( nFormatKey ), \
89 pCurCurrencyEntry(NULL), \
90 bBankingSymbol (sal_False), \
91 nCurCurrencyEntryPos((sal_uInt16) SELPOS_NONE)
93 // -----------------------------------------------------------------------
95 SvxNumberFormatShell::SvxNumberFormatShell( SvNumberFormatter* pNumFormatter,
96 sal_uInt32 nFormatKey,
97 SvxNumberValueType eNumValType,
98 const String& rNumStr )
99 : _INIT
101 nValNum = DEFAULT_NUMVALUE;
103 switch ( eValType )
105 case SVX_VALUE_TYPE_STRING:
106 aValStr = rNumStr;
107 break;
108 case SVX_VALUE_TYPE_NUMBER:
109 case SVX_VALUE_TYPE_UNDEFINED:
110 default:
111 aValStr.Erase();
115 // -----------------------------------------------------------------------
117 SvxNumberFormatShell::SvxNumberFormatShell( SvNumberFormatter* pNumFormatter,
118 sal_uInt32 nFormatKey,
119 SvxNumberValueType eNumValType,
120 double nNumVal,
121 const String* pNumStr )
122 : _INIT
124 // #50441# When used in Writer, the SvxNumberInfoItem contains the
125 // original string in addition to the value
127 if ( pNumStr )
128 aValStr = *pNumStr;
130 switch ( eValType )
132 case SVX_VALUE_TYPE_NUMBER:
133 nValNum = nNumVal;
134 break;
135 case SVX_VALUE_TYPE_STRING:
136 case SVX_VALUE_TYPE_UNDEFINED:
137 default:
138 nValNum = DEFAULT_NUMVALUE;
142 // -----------------------------------------------------------------------
144 SvxNumberFormatShell::~SvxNumberFormatShell()
147 * An dieser Stelle wird abhaengig davon, ob die
148 * hinzugefuegten, benutzerdefinierten als gueltig
149 * erklaert wurden (ValidateNewEntries()), die
150 * Add-Liste wieder aus dem Zahlenformatierer entfernt.
152 * Loeschen von Formaten aus dem Formatierer passiert
153 * aus Undo-Gruenden nur in der aufrufenden Instanz.
156 if ( bUndoAddList )
158 // Hinzugefuegte Formate sind nicht gueltig:
159 // => wieder entfernen:
161 for ( sal_uInt16 i = 0; i < aAddList.Count(); ++i )
162 pFormatter->DeleteEntry( aAddList[i] );
165 //--------------------------------
166 // Add-/Remove-Listen leerraeumen:
167 //--------------------------------
168 aAddList.Remove( 0, aAddList.Count() );
169 aDelList.Remove( 0, aAddList.Count() );
171 if(aCurrencyFormatList.Count()>0)
172 aCurrencyFormatList.DeleteAndDestroy(0,aCurrencyFormatList.Count());
175 // -----------------------------------------------------------------------
177 sal_uInt32 SvxNumberFormatShell::GetUpdateDataCount() const
179 return aDelList.Count();
182 // -----------------------------------------------------------------------
184 void SvxNumberFormatShell::GetUpdateData( sal_uInt32* pDelArray, const sal_uInt32 nSize )
186 const sal_uInt32 nCount = aDelList.Count();
188 DBG_ASSERT( pDelArray && ( nSize == nCount ), "Array nicht initialisiert!" );
190 if ( pDelArray && ( nSize == nCount ) )
191 for ( sal_uInt16 i = 0; i < aDelList.Count(); ++i )
192 *pDelArray++ = aDelList[i];
195 // -----------------------------------------------------------------------
197 void SvxNumberFormatShell::CategoryChanged( sal_uInt16 nCatLbPos,
198 short& rFmtSelPos,
199 SvStrings& rFmtEntries )
201 short nOldCategory = nCurCategory;
202 PosToCategory_Impl( nCatLbPos, nCurCategory );
203 pCurFmtTable = &( pFormatter->GetEntryTable( nCurCategory,
204 nCurFormatKey,
205 eCurLanguage ) );
206 // reinitialize currency if category newly entered
207 if ( nCurCategory == NUMBERFORMAT_CURRENCY && nOldCategory != nCurCategory )
208 pCurCurrencyEntry = NULL;
209 rFmtSelPos = FillEntryList_Impl( rFmtEntries );
212 // -----------------------------------------------------------------------
214 void SvxNumberFormatShell::LanguageChanged( LanguageType eLangType,
215 short& rFmtSelPos,
216 SvStrings& rFmtEntries )
218 eCurLanguage = eLangType;
219 pCurFmtTable = &(pFormatter->ChangeCL( nCurCategory,
220 nCurFormatKey,
221 eCurLanguage ) );
222 rFmtSelPos = FillEntryList_Impl( rFmtEntries );
225 // -----------------------------------------------------------------------
227 void SvxNumberFormatShell::FormatChanged( sal_uInt16 nFmtLbPos,
228 String& rPreviewStr,
229 Color*& rpFontColor )
231 //nCurFormatKey = pCurFmtTable->GetKey( pCurFmtTable->GetObject( nFmtLbPos ) );
233 if(nFmtLbPos<aCurEntryList.Count())
235 nCurFormatKey=aCurEntryList[nFmtLbPos];
237 if(nCurFormatKey!=NUMBERFORMAT_ENTRY_NOT_FOUND)
239 GetPreviewString_Impl( rPreviewStr, rpFontColor );
241 else if(nCurCategory==NUMBERFORMAT_CURRENCY)
243 if(nFmtLbPos<aCurrencyFormatList.Count())
245 //nCurFormatKey=nFmtLbPos;
246 MakePrevStringFromVal(*aCurrencyFormatList[nFmtLbPos],
247 rPreviewStr,rpFontColor,nValNum);
252 // -----------------------------------------------------------------------
254 sal_Bool SvxNumberFormatShell::AddFormat( String& rFormat, xub_StrLen& rErrPos,
255 sal_uInt16& rCatLbSelPos, short& rFmtSelPos,
256 SvStrings& rFmtEntries )
258 sal_Bool bInserted = sal_False;
259 sal_uInt32 nAddKey = pFormatter->GetEntryKey( rFormat, eCurLanguage );
261 if ( nAddKey != NUMBERFORMAT_ENTRY_NOT_FOUND ) // bereits vorhanden?
263 if ( IsRemoved_Impl( nAddKey ) )
265 // Key suchen und loeschen
266 sal_Bool bFound = sal_False;
267 sal_uInt16 nAt = 0;
269 for ( sal_uInt16 i = 0; !bFound && i < aDelList.Count(); ++i )
271 if ( aDelList[i] == nAddKey )
273 bFound = sal_True;
274 nAt = i;
277 DBG_ASSERT( bFound, "Key not found" );
278 aDelList.Remove( nAt );
279 bInserted = sal_True;
281 else
283 DBG_ERROR( "Doppeltes Format!" );
286 else // neues Format
288 bInserted = pFormatter->PutEntry( rFormat, rErrPos,
289 nCurCategory, nAddKey,
290 eCurLanguage );
293 if ( bInserted ) // eingefuegt
295 nCurFormatKey = nAddKey;
296 DBG_ASSERT( !IsAdded_Impl( nCurFormatKey ), "Doppeltes Format!" );
297 aAddList.Insert( nCurFormatKey, aAddList.Count() );
299 // aktuelle Tabelle holen
300 pCurFmtTable = &(pFormatter->GetEntryTable( nCurCategory,
301 nCurFormatKey,
302 eCurLanguage ));
303 nCurCategory=pFormatter->GetType(nAddKey); //@@ ???
304 CategoryToPos_Impl( nCurCategory, rCatLbSelPos );
305 rFmtSelPos = FillEntryList_Impl( rFmtEntries );
307 else if ( rErrPos != 0 ) // Syntaxfehler
311 else // Doppelt einfuegen nicht moeglich
313 DBG_ERROR( "Doppeltes Format!" ); // oder doch?
316 return bInserted;
319 // -----------------------------------------------------------------------
321 sal_Bool SvxNumberFormatShell::RemoveFormat( const String& rFormat,
322 sal_uInt16& rCatLbSelPos,
323 short& rFmtSelPos,
324 SvStrings& rFmtEntries )
326 sal_uInt32 nDelKey = pFormatter->GetEntryKey( rFormat, eCurLanguage );
328 DBG_ASSERT( nDelKey != NUMBERFORMAT_ENTRY_NOT_FOUND, "Eintrag nicht gefunden!" );
329 DBG_ASSERT( !IsRemoved_Impl( nDelKey ), "Eintrag bereits geloescht!" );
331 if ( (nDelKey != NUMBERFORMAT_ENTRY_NOT_FOUND) && !IsRemoved_Impl( nDelKey ) )
333 aDelList.Insert( nDelKey, aDelList.Count() );
335 if ( IsAdded_Impl( nDelKey ) )
337 // Key suchen und loeschen
338 sal_Bool bFound = sal_False;
339 sal_uInt16 nAt = 0;
341 for ( sal_uInt16 i = 0; !bFound && i < aAddList.Count(); ++i )
343 if ( aAddList[i] == nDelKey )
345 bFound = sal_True;
346 nAt = i;
349 DBG_ASSERT( bFound, "Key not found" );
350 aAddList.Remove( nAt );
353 nCurCategory=pFormatter->GetType(nDelKey); //@@ 01.10.97
354 pCurFmtTable = &(pFormatter->GetEntryTable( nCurCategory,
355 nCurFormatKey,
356 eCurLanguage ));
358 nCurFormatKey=pFormatter->GetStandardFormat(nCurCategory,
359 eCurLanguage );
361 CategoryToPos_Impl( nCurCategory, rCatLbSelPos );
362 rFmtSelPos = FillEntryList_Impl( rFmtEntries );
363 //rFmtSelPos = (short) nCurFormatKey; //@@ 01.10.97
365 return sal_True;
368 // -----------------------------------------------------------------------
370 void SvxNumberFormatShell::MakeFormat( String& rFormat,
371 sal_Bool bThousand, sal_Bool bNegRed,
372 sal_uInt16 nPrecision, sal_uInt16 nLeadingZeroes,
373 sal_uInt16 nCurrencyPos)
375 if(aCurrencyFormatList.Count()>nCurrencyPos)
377 xub_StrLen rErrPos=0;
378 sal_uInt16 rCatLbSelPos=0;
379 short rFmtSelPos=0;
380 SvStrings aFmtEList;
382 sal_uInt32 nFound = pFormatter->TestNewString( *aCurrencyFormatList[nCurrencyPos], eCurLanguage );
384 if ( nFound == NUMBERFORMAT_ENTRY_NOT_FOUND )
386 AddFormat( *aCurrencyFormatList[nCurrencyPos],rErrPos,rCatLbSelPos,
387 rFmtSelPos,aFmtEList);
390 if(rErrPos==0)
392 pFormatter->GenerateFormat( rFormat, nCurFormatKey,
393 eCurLanguage,
394 bThousand, bNegRed,
395 nPrecision, nLeadingZeroes );
397 aFmtEList.DeleteAndDestroy(0,aFmtEList.Count());
399 else
401 pFormatter->GenerateFormat( rFormat, nCurFormatKey,
402 eCurLanguage,
403 bThousand, bNegRed,
404 nPrecision, nLeadingZeroes );
408 // -----------------------------------------------------------------------
410 void SvxNumberFormatShell::GetOptions( const String& rFormat,
411 sal_Bool& rThousand,
412 sal_Bool& rNegRed,
413 sal_uInt16& rPrecision,
414 sal_uInt16& rLeadingZeroes,
415 sal_uInt16& rCatLbPos )
418 sal_uInt32 nFmtKey = pFormatter->GetEntryKey( rFormat, eCurLanguage );
420 if(nFmtKey != NUMBERFORMAT_ENTRY_NOT_FOUND)
422 if ( nFmtKey != NUMBERFORMAT_ENTRY_NOT_FOUND )
424 pFormatter->GetFormatSpecialInfo( nFmtKey,
425 rThousand, rNegRed,
426 rPrecision, rLeadingZeroes );
428 CategoryToPos_Impl( pFormatter->GetType( nFmtKey ), rCatLbPos );
430 else
431 rCatLbPos = CAT_USERDEFINED;
433 else
435 sal_Bool bTestBanking=sal_False;
436 sal_uInt16 nPos=FindCurrencyTableEntry(rFormat, bTestBanking );
438 if(IsInTable(nPos,bTestBanking,rFormat) &&
439 pFormatter->GetFormatSpecialInfo( rFormat,rThousand, rNegRed,
440 rPrecision, rLeadingZeroes,eCurLanguage)==0)
442 rCatLbPos = CAT_CURRENCY;
444 else
445 rCatLbPos = CAT_USERDEFINED;
450 // -----------------------------------------------------------------------
452 void SvxNumberFormatShell::MakePreviewString( const String& rFormatStr,
453 String& rPreviewStr,
454 Color*& rpFontColor )
456 rpFontColor = NULL;
458 ULONG nExistingFormat = pFormatter->GetEntryKey( rFormatStr, eCurLanguage );
459 if ( nExistingFormat == NUMBERFORMAT_ENTRY_NOT_FOUND )
461 // real preview - not implemented in NumberFormatter for text formats
463 pFormatter->GetPreviewString( rFormatStr, nValNum, rPreviewStr,
464 &rpFontColor, eCurLanguage );
466 else
468 // format exists
470 // #50441# if a string was set in addition to the value, use it for text formats
471 BOOL bUseText = ( eValType == SVX_VALUE_TYPE_STRING ||
472 ( aValStr.Len() && ( pFormatter->GetType(nExistingFormat) & NUMBERFORMAT_TEXT ) ) );
473 if ( bUseText )
474 pFormatter->GetOutputString( aValStr, nExistingFormat,
475 rPreviewStr, &rpFontColor );
476 else
477 pFormatter->GetOutputString( nValNum, nExistingFormat,
478 rPreviewStr, &rpFontColor );
482 // -----------------------------------------------------------------------
484 sal_Bool SvxNumberFormatShell::IsUserDefined( const String& rFmtString )
486 sal_uInt32 nFound = pFormatter->GetEntryKey( rFmtString, eCurLanguage );
488 sal_Bool bFlag=sal_False;
489 if ( nFound != NUMBERFORMAT_ENTRY_NOT_FOUND )
491 bFlag=pFormatter->IsUserDefined( rFmtString, eCurLanguage );
493 if(bFlag)
495 const SvNumberformat* pNumEntry = pFormatter->GetEntry(nFound);
497 if(pNumEntry!=NULL && pNumEntry->HasNewCurrency())
499 sal_Bool bTestBanking;
500 sal_uInt16 nPos=FindCurrencyTableEntry(rFmtString,bTestBanking);
501 bFlag=!IsInTable(nPos,bTestBanking,rFmtString);
505 return bFlag;
508 // -----------------------------------------------------------------------
510 sal_Bool SvxNumberFormatShell::FindEntry( const String& rFmtString, sal_uInt32* pAt /* = NULL */ )
512 sal_Bool bRes=sal_False;
513 sal_uInt32 nFound = pFormatter->TestNewString( rFmtString, eCurLanguage );
515 if ( nFound == NUMBERFORMAT_ENTRY_NOT_FOUND )
517 sal_Bool bTestBanking=sal_False;
518 sal_uInt16 nPos=FindCurrencyTableEntry(rFmtString, bTestBanking );
520 if(IsInTable(nPos,bTestBanking,rFmtString))
522 nFound=NUMBERFORMAT_ENTRY_NEW_CURRENCY;
523 bRes=sal_True;
526 else
528 bRes=!IsRemoved_Impl( nFound );
531 if ( pAt )
532 *pAt = nFound;
534 return bRes;
538 // -----------------------------------------------------------------------
540 void SvxNumberFormatShell::GetInitSettings(
541 sal_uInt16& nCatLbPos,
542 LanguageType& rLangType,
543 sal_uInt16& nFmtLbSelPos,
544 SvStrings& rFmtEntries,
545 String& rPrevString,
546 Color*& rpPrevColor )
548 // -------------------------------------------------------------------
549 // Vorbedingung: Zahlenformatierer gefunden
550 DBG_ASSERT( pFormatter != NULL, "Zahlenformatierer nicht gefunden!" );
552 // sal_uInt16 nCount = 0;
553 short nSelPos = SELPOS_NONE;
554 // SvNumberFormatTable* pFmtTable = NULL;
556 // Sonderbehandlung fuer undefiniertes Zahlenformat:
557 if ( (eValType == SVX_VALUE_TYPE_UNDEFINED) && (nCurFormatKey == 0) )
558 PosToCategory_Impl( CAT_ALL, nCurCategory ); // Kategorie = Alle
559 else
560 nCurCategory = NUMBERFORMAT_UNDEFINED; // Kategorie = Undefiniert
562 pCurFmtTable = &(pFormatter->GetFirstEntryTable( nCurCategory,
563 nCurFormatKey,
564 eCurLanguage ));
568 CategoryToPos_Impl( nCurCategory, nCatLbPos );
569 rLangType = eCurLanguage;
571 nSelPos = FillEntryList_Impl( rFmtEntries );
573 DBG_ASSERT( nSelPos != SELPOS_NONE, "Leere Formatliste!" );
575 nFmtLbSelPos = (nSelPos != SELPOS_NONE) ? (sal_uInt16)nSelPos : 0;
576 GetPreviewString_Impl( rPrevString, rpPrevColor );
579 // -----------------------------------------------------------------------
581 short SvxNumberFormatShell::FillEntryList_Impl( SvStrings& rList )
583 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
584 * Rueckgabewert ist die Listenposition des aktuellen Formates.
585 * Ist die Liste leer oder gibt es kein aktuelles Format,
586 * so wird SELPOS_NONE geliefert.
588 short nSelPos=0;
589 aCurEntryList.Remove(nSelPos,aCurEntryList.Count());
590 sal_uInt16 nPrivCat = CAT_CURRENCY;
591 nSelPos=SELPOS_NONE;
593 if(nCurCategory==NUMBERFORMAT_ALL)
595 FillEListWithStd_Impl(rList,CAT_NUMBER,nSelPos);
596 FillEListWithStd_Impl(rList,CAT_PERCENT,nSelPos);
597 FillEListWithStd_Impl(rList,CAT_CURRENCY,nSelPos);
598 FillEListWithStd_Impl(rList,CAT_DATE,nSelPos);
599 FillEListWithStd_Impl(rList,CAT_TIME,nSelPos);
600 FillEListWithStd_Impl(rList,CAT_SCIENTIFIC,nSelPos);
601 FillEListWithStd_Impl(rList,CAT_FRACTION,nSelPos);
602 FillEListWithStd_Impl(rList,CAT_BOOLEAN,nSelPos);
603 FillEListWithStd_Impl(rList,CAT_TEXT,nSelPos);
605 else
607 CategoryToPos_Impl(nCurCategory, nPrivCat);
608 FillEListWithStd_Impl(rList,nPrivCat,nSelPos);
611 if( nPrivCat!=CAT_CURRENCY)
612 nSelPos=FillEListWithUsD_Impl(rList,nPrivCat,nSelPos);
614 return nSelPos;
617 void SvxNumberFormatShell::FillEListWithStd_Impl( SvStrings& rList,sal_uInt16 nPrivCat,short &nSelPos )
619 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
620 * Rueckgabewert ist die Listenposition des aktuellen Formates.
621 * Ist die Liste leer oder gibt es kein aktuelles Format,
622 * so wird SELPOS_NONE geliefert.
624 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
626 if(aCurrencyFormatList.Count()>0)
627 aCurrencyFormatList.DeleteAndDestroy(0,aCurrencyFormatList.Count());
629 if(nPrivCat==CAT_CURRENCY)
631 nSelPos=FillEListWithCurrency_Impl(rList,nSelPos);
633 else
635 NfIndexTableOffset eOffsetStart;
636 NfIndexTableOffset eOffsetEnd;
638 switch(nPrivCat)
640 case CAT_NUMBER :eOffsetStart=NF_NUMBER_START;
641 eOffsetEnd=NF_NUMBER_END;
642 break;
643 case CAT_PERCENT :eOffsetStart=NF_PERCENT_START;
644 eOffsetEnd=NF_PERCENT_END;
645 break;
646 case CAT_CURRENCY :eOffsetStart=NF_CURRENCY_START;
647 eOffsetEnd=NF_CURRENCY_END;
648 break;
649 case CAT_DATE :eOffsetStart=NF_DATE_START;
650 eOffsetEnd=NF_DATE_END;
651 break;
652 case CAT_TIME :eOffsetStart=NF_TIME_START;
653 eOffsetEnd=NF_TIME_END;
654 break;
655 case CAT_SCIENTIFIC :eOffsetStart=NF_SCIENTIFIC_START;
656 eOffsetEnd=NF_SCIENTIFIC_END;
657 break;
658 case CAT_FRACTION :eOffsetStart=NF_FRACTION_START;
659 eOffsetEnd=NF_FRACTION_END;
660 break;
661 case CAT_BOOLEAN :eOffsetStart=NF_BOOLEAN;
662 eOffsetEnd=NF_BOOLEAN;
663 break;
664 case CAT_TEXT :eOffsetStart=NF_TEXT;
665 eOffsetEnd=NF_TEXT;
666 break;
667 default :return;
670 nSelPos=FillEListWithFormats_Impl(rList,nSelPos,eOffsetStart,eOffsetEnd);
672 if(nPrivCat==CAT_DATE || nPrivCat==CAT_TIME)
674 nSelPos=FillEListWithDateTime_Impl(rList,nSelPos);
675 //if(nSelPos!=SELPOS_NONE) nSelPos=nTmpPos;
680 short SvxNumberFormatShell::FillEListWithFormats_Impl( SvStrings& rList,short nSelPos,
681 NfIndexTableOffset eOffsetStart,
682 NfIndexTableOffset eOffsetEnd)
684 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
685 * Rueckgabewert ist die Listenposition des aktuellen Formates.
686 * Ist die Liste leer oder gibt es kein aktuelles Format,
687 * so wird SELPOS_NONE geliefert.
689 sal_uInt16 nMyType;
691 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
693 const SvNumberformat* pNumEntry = pCurFmtTable->First();
694 // sal_uInt16 nCount = 0;
695 sal_uInt32 nNFEntry;
696 String aStrComment;
697 String aNewFormNInfo;
698 String aPrevString;
699 String a2PrevString;
701 short nMyCat = SELPOS_NONE;
702 // short nIq=0;
704 long nIndex;
706 for(nIndex=eOffsetStart;nIndex<=eOffsetEnd;nIndex++)
708 nNFEntry=pFormatter->GetFormatIndex((NfIndexTableOffset)nIndex,eCurLanguage);
710 pNumEntry = pFormatter->GetEntry(nNFEntry);
712 if(pNumEntry==NULL) continue;
714 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
715 aStrComment=pNumEntry->GetComment();
716 CategoryToPos_Impl(nMyCat,nMyType);
717 aNewFormNInfo= pNumEntry->GetFormatstring();
719 const StringPtr pStr = new String(aNewFormNInfo);
721 if ( nNFEntry == nCurFormatKey )
723 nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.Count() : SELPOS_NONE;
726 rList.Insert( pStr,rList.Count());
727 aCurEntryList.Insert( nNFEntry, aCurEntryList.Count() );
730 return nSelPos;
733 short SvxNumberFormatShell::FillEListWithDateTime_Impl( SvStrings& rList,short nSelPos)
735 sal_uInt16 nMyType;
737 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
739 const SvNumberformat* pNumEntry = pCurFmtTable->First();
740 // sal_uInt16 nCount = 0;
741 sal_uInt32 nNFEntry;
742 String aStrComment;
743 String aNewFormNInfo;
744 String aPrevString;
745 String a2PrevString;
747 short nMyCat = SELPOS_NONE;
748 // short nIq=0;
750 long nIndex;
752 for(nIndex=NF_DATETIME_START;nIndex<=NF_DATETIME_END;nIndex++)
754 nNFEntry=pFormatter->GetFormatIndex((NfIndexTableOffset)nIndex,eCurLanguage);
756 pNumEntry = pFormatter->GetEntry(nNFEntry);
757 if(pNumEntry!=NULL)
759 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
760 aStrComment=pNumEntry->GetComment();
761 CategoryToPos_Impl(nMyCat,nMyType);
762 aNewFormNInfo= pNumEntry->GetFormatstring();
764 const StringPtr pStr = new String(aNewFormNInfo);
766 if ( nNFEntry == nCurFormatKey )
768 nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.Count() : SELPOS_NONE;
771 rList.Insert( pStr,rList.Count());
772 aCurEntryList.Insert( nNFEntry, aCurEntryList.Count() );
776 return nSelPos;
779 short SvxNumberFormatShell::FillEListWithCurrency_Impl( SvStrings& rList,short nSelPos)
781 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
782 * Rueckgabewert ist die Listenposition des aktuellen Formates.
783 * Ist die Liste leer oder gibt es kein aktuelles Format,
784 * so wird SELPOS_NONE geliefert.
786 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
788 const NfCurrencyEntry* pTmpCurrencyEntry;
789 sal_Bool bTmpBanking;
790 XubString rSymbol;
792 sal_Bool bFlag=pFormatter->GetNewCurrencySymbolString(nCurFormatKey,rSymbol,
793 &pTmpCurrencyEntry,&bTmpBanking);
795 if((!bFlag && pCurCurrencyEntry==NULL) ||
796 (bFlag && pTmpCurrencyEntry==NULL && !rSymbol.Len()) ||
797 nCurCategory==NUMBERFORMAT_ALL)
799 if ( nCurCategory == NUMBERFORMAT_ALL )
800 FillEListWithUserCurrencys(rList,nSelPos);
801 nSelPos=FillEListWithSysCurrencys(rList,nSelPos);
803 else
805 nSelPos=FillEListWithUserCurrencys(rList,nSelPos);
808 return nSelPos;
812 short SvxNumberFormatShell::FillEListWithSysCurrencys( SvStrings& rList,short nSelPos)
814 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
815 * Rueckgabewert ist die Listenposition des aktuellen Formates.
816 * Ist die Liste leer oder gibt es kein aktuelles Format,
817 * so wird SELPOS_NONE geliefert.
819 sal_uInt16 nMyType;
821 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
823 const SvNumberformat* pNumEntry = pCurFmtTable->First();
824 sal_uInt16 nCount = 0;
825 sal_uInt32 nNFEntry;
826 String aStrComment;
827 String aNewFormNInfo;
828 String aPrevString;
829 String a2PrevString;
831 nCurCurrencyEntryPos=0;
833 short nMyCat = SELPOS_NONE;
834 // short nIq=0;
836 NfIndexTableOffset eOffsetStart=NF_CURRENCY_START;
837 NfIndexTableOffset eOffsetEnd=NF_CURRENCY_END;;
838 long nIndex;
840 for(nIndex=eOffsetStart;nIndex<=eOffsetEnd;nIndex++)
842 nNFEntry=pFormatter->GetFormatIndex((NfIndexTableOffset)nIndex,eCurLanguage);
844 pNumEntry = pFormatter->GetEntry(nNFEntry);
846 if(pNumEntry==NULL) continue;
848 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
849 aStrComment=pNumEntry->GetComment();
850 CategoryToPos_Impl(nMyCat,nMyType);
851 aNewFormNInfo= pNumEntry->GetFormatstring();
853 const StringPtr pStr = new String(aNewFormNInfo);
855 if ( nNFEntry == nCurFormatKey )
857 nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.Count() : SELPOS_NONE;
860 rList.Insert( pStr,rList.Count());
861 aCurEntryList.Insert( nNFEntry, aCurEntryList.Count() );
864 if(nCurCategory!=NUMBERFORMAT_ALL)
866 pNumEntry = pCurFmtTable->First();
867 nCount = 0;
868 while ( pNumEntry )
870 sal_uInt32 nKey = pCurFmtTable->GetCurKey();
872 nCount++;
874 if ( !IsRemoved_Impl( nKey ))
876 sal_Bool bUserNewCurrency=sal_False;
877 if(pNumEntry->HasNewCurrency())
879 const NfCurrencyEntry* pTmpCurrencyEntry;
880 sal_Bool bTmpBanking;
881 XubString rSymbol;
883 pFormatter->GetNewCurrencySymbolString(nKey,rSymbol,
884 &pTmpCurrencyEntry,&bTmpBanking);
886 bUserNewCurrency=(pTmpCurrencyEntry!=NULL);
889 if(!bUserNewCurrency &&(pNumEntry->GetType() & NUMBERFORMAT_DEFINED))
891 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
892 aStrComment=pNumEntry->GetComment();
893 CategoryToPos_Impl(nMyCat,nMyType);
894 aNewFormNInfo= pNumEntry->GetFormatstring();
896 const StringPtr pStr = new String(aNewFormNInfo);
898 if ( nKey == nCurFormatKey ) nSelPos =aCurEntryList.Count();
899 rList.Insert( pStr,rList.Count());
900 aCurEntryList.Insert( nKey, aCurEntryList.Count() );
903 pNumEntry = pCurFmtTable->Next();
906 return nSelPos;
909 short SvxNumberFormatShell::FillEListWithUserCurrencys( SvStrings& rList,short nSelPos)
911 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
912 * Rueckgabewert ist die Listenposition des aktuellen Formates.
913 * Ist die Liste leer oder gibt es kein aktuelles Format,
914 * so wird SELPOS_NONE geliefert.
916 sal_uInt16 nMyType;
918 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
920 sal_uInt16 nCount = 0;
921 String aStrComment;
922 String aNewFormNInfo;
923 String aPrevString;
924 String a2PrevString;
925 short nMyCat = SELPOS_NONE;
926 // short nIq=0;
928 const NfCurrencyEntry* pTmpCurrencyEntry;
929 sal_Bool bTmpBanking, bAdaptSelPos;
930 XubString rSymbol;
931 XubString rBankSymbol;
933 SvStrings aList;
934 SvULongs aKeyList;
936 /*sal_Bool bFlag=*/pFormatter->GetNewCurrencySymbolString(nCurFormatKey,rSymbol,
937 &pTmpCurrencyEntry,&bTmpBanking);
939 XubString rShortSymbol;
941 if(pCurCurrencyEntry==NULL)
943 // #110398# If no currency format was previously selected (we're not
944 // about to add another currency), try to select the initial currency
945 // format (nCurFormatKey) that was set in FormatChanged() after
946 // matching the format string entered in the dialog.
947 bAdaptSelPos = sal_True;
948 pCurCurrencyEntry=(NfCurrencyEntry*)pTmpCurrencyEntry;
949 bBankingSymbol=bTmpBanking;
950 nCurCurrencyEntryPos=FindCurrencyFormat(pTmpCurrencyEntry,bTmpBanking);
952 else
954 if (pTmpCurrencyEntry == pCurCurrencyEntry)
955 bAdaptSelPos = sal_True;
956 else
958 bAdaptSelPos = sal_False;
959 pTmpCurrencyEntry = pCurCurrencyEntry;
961 bTmpBanking=bBankingSymbol;
964 if(pTmpCurrencyEntry!=NULL)
966 pTmpCurrencyEntry->BuildSymbolString(rSymbol,sal_False);
967 pTmpCurrencyEntry->BuildSymbolString(rBankSymbol,sal_True);
968 pTmpCurrencyEntry->BuildSymbolString(rShortSymbol,bTmpBanking,sal_True);
971 const SvNumberformat* pNumEntry = pCurFmtTable->First();
973 while ( pNumEntry )
975 sal_uInt32 nKey = pCurFmtTable->GetCurKey();
977 nCount++;
979 if ( !IsRemoved_Impl( nKey ) )
981 if( pNumEntry->GetType() & NUMBERFORMAT_DEFINED ||
982 pNumEntry->IsAdditionalStandardDefined() )
984 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
985 aStrComment=pNumEntry->GetComment();
986 CategoryToPos_Impl(nMyCat,nMyType);
987 aNewFormNInfo= pNumEntry->GetFormatstring();
989 sal_Bool bInsFlag=sal_False;
990 if ( pNumEntry->HasNewCurrency() )
991 bInsFlag = sal_True; // merge locale formats into currency selection
992 else if( (!bTmpBanking && aNewFormNInfo.Search(rSymbol)!=STRING_NOTFOUND) ||
993 (bTmpBanking && aNewFormNInfo.Search(rBankSymbol)!=STRING_NOTFOUND) )
995 bInsFlag=sal_True;
997 else if(aNewFormNInfo.Search(rShortSymbol)!=STRING_NOTFOUND)
999 XubString rTstSymbol;
1000 const NfCurrencyEntry* pTstCurrencyEntry;
1001 sal_Bool bTstBanking;
1003 /*sal_Bool bTstFlag=*/pFormatter->GetNewCurrencySymbolString(nKey,rTstSymbol,
1004 &pTstCurrencyEntry,&bTstBanking);
1006 if(pTmpCurrencyEntry==pTstCurrencyEntry && bTstBanking==bTmpBanking)
1008 bInsFlag=sal_True;
1013 if(bInsFlag)
1015 const StringPtr pStr = new String(aNewFormNInfo);
1017 aList.Insert( pStr,aList.Count());
1018 aKeyList.Insert( nKey, aKeyList.Count() );
1022 pNumEntry = pCurFmtTable->Next();
1025 NfWSStringsDtor aWSStringsDtor;
1026 sal_uInt16 nDefault;
1027 if ( pTmpCurrencyEntry && nCurCategory != NUMBERFORMAT_ALL )
1029 nDefault = pFormatter->GetCurrencyFormatStrings(
1030 aWSStringsDtor, *pTmpCurrencyEntry, bTmpBanking );
1031 if ( !bTmpBanking )
1032 pFormatter->GetCurrencyFormatStrings(
1033 aWSStringsDtor, *pTmpCurrencyEntry, TRUE );
1035 else
1036 nDefault = 0;
1037 if ( !bTmpBanking && nCurCategory != NUMBERFORMAT_ALL )
1038 { // append formats for all currencies defined in the current I18N locale
1039 const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable();
1040 sal_uInt16 nCurrCount = rCurrencyTable.Count();
1041 LanguageType eLang = MsLangId::getRealLanguage( eCurLanguage );
1042 for ( sal_uInt16 i=0; i < nCurrCount; ++i )
1044 const NfCurrencyEntry* pCurr = rCurrencyTable[i];
1045 if ( pCurr->GetLanguage() == eLang && pTmpCurrencyEntry != pCurr )
1047 pFormatter->GetCurrencyFormatStrings( aWSStringsDtor, *pCurr, FALSE );
1048 pFormatter->GetCurrencyFormatStrings( aWSStringsDtor, *pCurr, TRUE );
1053 sal_uInt16 i,nPos;
1054 sal_uInt16 nOldListCount = rList.Count();
1055 for( i=0, nPos=nOldListCount; i<aWSStringsDtor.Count(); i++)
1057 sal_Bool bFlag=sal_True;
1058 String aInsStr(*aWSStringsDtor[i]);
1059 sal_uInt16 j;
1060 for(j=0;j<aList.Count();j++)
1062 const StringPtr pTestStr=aList[j];
1064 if(*pTestStr==aInsStr)
1066 bFlag=sal_False;
1067 break;
1070 if(bFlag)
1072 rList.Insert(new String(aInsStr),nPos);
1073 aCurEntryList.Insert( NUMBERFORMAT_ENTRY_NOT_FOUND, nPos++);
1075 else
1077 rList.Insert(aList[j],nPos);
1078 aList.Remove(j);
1079 aCurEntryList.Insert( aKeyList[j],nPos++);
1080 aKeyList.Remove(j);
1084 for(i=0;i<aKeyList.Count();i++)
1086 if(aKeyList[i]!=NUMBERFORMAT_ENTRY_NOT_FOUND)
1088 rList.Insert(aList[i],rList.Count());
1089 aCurEntryList.Insert( aKeyList[i],aCurEntryList.Count());
1093 for(i=nOldListCount;i<rList.Count();i++)
1095 aCurrencyFormatList.Insert(new String(*rList[i]),aCurrencyFormatList.Count());
1097 if ( nSelPos == SELPOS_NONE && bAdaptSelPos && aCurEntryList[i] == nCurFormatKey )
1098 nSelPos = i;
1101 if ( nSelPos == SELPOS_NONE && nCurCategory != NUMBERFORMAT_ALL )
1102 nSelPos = nDefault;
1104 return nSelPos;
1108 short SvxNumberFormatShell::FillEListWithUsD_Impl( SvStrings& rList, sal_uInt16 nPrivCat, short nSelPos)
1110 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
1111 * Rueckgabewert ist die Listenposition des aktuellen Formates.
1112 * Ist die Liste leer oder gibt es kein aktuelles Format,
1113 * so wird SELPOS_NONE geliefert.
1115 sal_uInt16 nMyType;
1117 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
1119 const SvNumberformat* pNumEntry = pCurFmtTable->First();
1120 sal_uInt16 nCount = 0;
1121 String aStrComment;
1122 String aNewFormNInfo;
1123 String aPrevString;
1124 String a2PrevString;
1126 short nMyCat = SELPOS_NONE;
1127 // short nIq=0;
1128 sal_Bool bAdditional = (nPrivCat != CAT_USERDEFINED &&
1129 nCurCategory != NUMBERFORMAT_ALL);
1131 while ( pNumEntry )
1133 sal_uInt32 nKey = pCurFmtTable->GetCurKey();
1135 nCount++;
1137 if ( !IsRemoved_Impl( nKey ) )
1139 if( (pNumEntry->GetType() & NUMBERFORMAT_DEFINED) ||
1140 (bAdditional && pNumEntry->IsAdditionalStandardDefined()) )
1142 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
1143 aStrComment=pNumEntry->GetComment();
1144 CategoryToPos_Impl(nMyCat,nMyType);
1145 aNewFormNInfo= pNumEntry->GetFormatstring();
1147 sal_Bool bFlag=sal_True;
1148 if(pNumEntry->HasNewCurrency())
1150 sal_Bool bTestBanking;
1151 sal_uInt16 nPos=FindCurrencyTableEntry(aNewFormNInfo,bTestBanking);
1152 bFlag=!IsInTable(nPos,bTestBanking,aNewFormNInfo);
1154 if(bFlag)
1156 const StringPtr pStr = new String(aNewFormNInfo);
1158 if ( nKey == nCurFormatKey ) nSelPos =aCurEntryList.Count();
1159 rList.Insert( pStr,rList.Count());
1160 aCurEntryList.Insert( nKey, aCurEntryList.Count() );
1164 pNumEntry = pCurFmtTable->Next();
1166 return nSelPos;
1170 // -----------------------------------------------------------------------
1172 void SvxNumberFormatShell::GetPreviewString_Impl( String& rString, Color*& rpColor )
1174 rpColor = NULL;
1176 // #50441# if a string was set in addition to the value, use it for text formats
1177 BOOL bUseText = ( eValType == SVX_VALUE_TYPE_STRING ||
1178 ( aValStr.Len() && ( pFormatter->GetType(nCurFormatKey) & NUMBERFORMAT_TEXT ) ) );
1180 if ( bUseText )
1181 pFormatter->GetOutputString( aValStr, nCurFormatKey, rString, &rpColor );
1182 else
1183 pFormatter->GetOutputString( nValNum, nCurFormatKey, rString, &rpColor );
1186 // -----------------------------------------------------------------------
1188 sal_Bool SvxNumberFormatShell::IsRemoved_Impl( sal_uInt32 nKey )
1190 sal_Bool bFound = sal_False;
1191 for ( sal_uInt16 i = 0; !bFound && i < aDelList.Count(); ++i )
1192 if ( aDelList[i] == nKey )
1193 bFound = sal_True;
1194 return bFound;
1197 // -----------------------------------------------------------------------
1199 sal_Bool SvxNumberFormatShell::IsAdded_Impl( sal_uInt32 nKey )
1201 sal_Bool bFound = sal_False;
1202 for ( sal_uInt16 i = 0; !bFound && i < aAddList.Count(); ++i )
1203 if ( aAddList[i] == nKey )
1204 bFound = sal_True;
1205 return bFound;
1208 // -----------------------------------------------------------------------
1209 // Konvertierungs-Routinen:
1210 // ------------------------
1212 void SvxNumberFormatShell::PosToCategory_Impl( sal_uInt16 nPos, short& rCategory )
1214 // Kategorie ::com::sun::star::form-Positionen abbilden (->Resource)
1215 switch ( nPos )
1217 case CAT_USERDEFINED: rCategory = NUMBERFORMAT_DEFINED; break;
1218 case CAT_NUMBER: rCategory = NUMBERFORMAT_NUMBER; break;
1219 case CAT_PERCENT: rCategory = NUMBERFORMAT_PERCENT; break;
1220 case CAT_CURRENCY: rCategory = NUMBERFORMAT_CURRENCY; break;
1221 case CAT_DATE: rCategory = NUMBERFORMAT_DATE; break;
1222 case CAT_TIME: rCategory = NUMBERFORMAT_TIME; break;
1223 case CAT_SCIENTIFIC: rCategory = NUMBERFORMAT_SCIENTIFIC; break;
1224 case CAT_FRACTION: rCategory = NUMBERFORMAT_FRACTION; break;
1225 case CAT_BOOLEAN: rCategory = NUMBERFORMAT_LOGICAL; break;
1226 case CAT_TEXT: rCategory = NUMBERFORMAT_TEXT; break;
1227 case CAT_ALL:
1228 default: rCategory = NUMBERFORMAT_ALL; break;
1232 // -----------------------------------------------------------------------
1234 void SvxNumberFormatShell::CategoryToPos_Impl( short nCategory, sal_uInt16& rPos )
1236 // Kategorie auf ::com::sun::star::form-Positionen abbilden (->Resource)
1237 switch ( nCategory )
1239 case NUMBERFORMAT_DEFINED: rPos = CAT_USERDEFINED; break;
1240 case NUMBERFORMAT_NUMBER: rPos = CAT_NUMBER; break;
1241 case NUMBERFORMAT_PERCENT: rPos = CAT_PERCENT; break;
1242 case NUMBERFORMAT_CURRENCY: rPos = CAT_CURRENCY; break;
1243 case NUMBERFORMAT_DATETIME:
1244 case NUMBERFORMAT_DATE: rPos = CAT_DATE; break;
1245 case NUMBERFORMAT_TIME: rPos = CAT_TIME; break;
1246 case NUMBERFORMAT_SCIENTIFIC: rPos = CAT_SCIENTIFIC; break;
1247 case NUMBERFORMAT_FRACTION: rPos = CAT_FRACTION; break;
1248 case NUMBERFORMAT_LOGICAL: rPos = CAT_BOOLEAN; break;
1249 case NUMBERFORMAT_TEXT: rPos = CAT_TEXT; break;
1250 case NUMBERFORMAT_ALL:
1251 default: rPos = CAT_ALL;
1256 /*************************************************************************
1257 #* Member: MakePrevStringFromVal Datum:19.09.97
1258 #*------------------------------------------------------------------------
1260 #* Klasse: SvxNumberFormatShell
1262 #* Funktion: Formatiert die Zahl nValue abhaengig von rFormatStr
1263 #* und speichert das Ergebnis in rPreviewStr.
1265 #* Input: FormatString, Farbe, zu formatierende Zahl
1267 #* Output: Ausgabestring rPreviewStr
1269 #************************************************************************/
1271 void SvxNumberFormatShell::MakePrevStringFromVal(
1272 const String& rFormatStr,
1273 String& rPreviewStr,
1274 Color*& rpFontColor,
1275 double nValue)
1277 rpFontColor = NULL;
1278 pFormatter->GetPreviewString( rFormatStr, nValue, rPreviewStr, &rpFontColor, eCurLanguage );
1281 /*************************************************************************
1282 #* Member: GetComment4Entry Datum:30.10.97
1283 #*------------------------------------------------------------------------
1285 #* Klasse: SvxNumberFormatShell
1287 #* Funktion: Liefert den Kommentar fuer einen gegebenen
1288 #* Eintrag zurueck.
1290 #* Input: Nummer des Eintrags
1292 #* Output: Kommentar-String
1294 #************************************************************************/
1296 void SvxNumberFormatShell::SetComment4Entry(short nEntry,String aEntStr)
1298 SvNumberformat *pNumEntry;
1299 if(nEntry<0) return;
1300 sal_uInt32 nMyNfEntry=aCurEntryList[nEntry];
1301 pNumEntry = (SvNumberformat*)pFormatter->GetEntry(nMyNfEntry);
1302 if(pNumEntry!=NULL) pNumEntry->SetComment(aEntStr);
1305 /*************************************************************************
1306 #* Member: GetComment4Entry Datum:30.10.97
1307 #*------------------------------------------------------------------------
1309 #* Klasse: SvxNumberFormatShell
1311 #* Funktion: Liefert den Kommentar fuer einen gegebenen
1312 #* Eintrag zurueck.
1314 #* Input: Nummer des Eintrags
1316 #* Output: Kommentar-String
1318 #************************************************************************/
1320 String SvxNumberFormatShell::GetComment4Entry(short nEntry)
1322 const SvNumberformat *pNumEntry;
1324 if(nEntry < 0)
1325 return String();
1327 if(nEntry<aCurEntryList.Count())
1329 sal_uInt32 nMyNfEntry=aCurEntryList[nEntry];
1330 pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1331 if(pNumEntry!=NULL)
1332 return pNumEntry->GetComment();
1335 return String();
1338 /*************************************************************************
1339 #* Member: GetCategory4Entry Datum:30.10.97
1340 #*------------------------------------------------------------------------
1342 #* Klasse: SvxNumberFormatShell
1344 #* Funktion: Liefert die Kategorie- Nummer fuer einen gegebenen
1345 #* Eintrag zurueck.
1347 #* Input: Nummer des Eintrags
1349 #* Output: Kategorie- Nummer
1351 #************************************************************************/
1353 short SvxNumberFormatShell::GetCategory4Entry(short nEntry)
1355 const SvNumberformat *pNumEntry;
1356 if(nEntry<0) return 0;
1358 if(nEntry<aCurEntryList.Count())
1360 sal_uInt32 nMyNfEntry=aCurEntryList[nEntry];
1362 if(nMyNfEntry!=NUMBERFORMAT_ENTRY_NOT_FOUND)
1364 pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1365 sal_uInt16 nMyCat,nMyType;
1366 if(pNumEntry!=NULL)
1368 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
1369 CategoryToPos_Impl(nMyCat,nMyType);
1371 return (short) nMyType;
1373 return 0;
1375 else if(aCurrencyFormatList.Count()>0)
1377 return CAT_CURRENCY;
1380 return 0;
1384 /*************************************************************************
1385 #* Member: GetUserDefined4Entry Datum:31.10.97
1386 #*------------------------------------------------------------------------
1388 #* Klasse: SvxNumberFormatShell
1390 #* Funktion: Liefert die Information, ob ein Eintrag
1391 #* benutzerspezifisch ist zurueck.
1393 #* Input: Nummer des Eintrags
1395 #* Output: Benutzerspezifisch?
1397 #************************************************************************/
1399 sal_Bool SvxNumberFormatShell::GetUserDefined4Entry(short nEntry)
1401 const SvNumberformat *pNumEntry;
1402 if(nEntry<0) return 0;
1403 if(nEntry<aCurEntryList.Count())
1405 sal_uInt32 nMyNfEntry=aCurEntryList[nEntry];
1406 pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1408 if(pNumEntry!=NULL)
1410 if((pNumEntry->GetType() & NUMBERFORMAT_DEFINED)>0)
1412 return sal_True;
1416 return sal_False;
1420 /*************************************************************************
1421 #* Member: GetFormat4Entry Datum:30.10.97
1422 #*------------------------------------------------------------------------
1424 #* Klasse: SvxNumberFormatShell
1426 #* Funktion: Liefert den Format- String fuer einen gegebenen
1427 #* Eintrag zurueck.
1429 #* Input: Nummer des Eintrags
1431 #* Output: Format- String
1433 #************************************************************************/
1435 String SvxNumberFormatShell::GetFormat4Entry(short nEntry)
1437 const SvNumberformat *pNumEntry;
1439 if(nEntry < 0)
1440 return String();
1442 if(aCurrencyFormatList.Count()>0)
1444 if(aCurrencyFormatList.Count()>nEntry)
1445 return *aCurrencyFormatList[nEntry];
1447 else
1449 sal_uInt32 nMyNfEntry=aCurEntryList[nEntry];
1450 pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1452 if(pNumEntry!=NULL)
1453 return pNumEntry->GetFormatstring();
1455 return String();
1458 /*************************************************************************
1459 #* Member: GetListPos4Entry Datum:31.10.97
1460 #*------------------------------------------------------------------------
1462 #* Klasse: SvxNumberFormatShell
1464 #* Funktion: Liefert die Listen- Nummer fuer einen gegebenen
1465 #* Formatindex zurueck.
1467 #* Input: Nummer des Eintrags
1469 #* Output: Kategorie- Nummer
1471 #************************************************************************/
1473 short SvxNumberFormatShell::GetListPos4Entry(sal_uInt32 nIdx)
1475 short nSelP=SELPOS_NONE;
1476 if( aCurEntryList.Count() <= 0x7fff )
1478 for(short i=0;i<aCurEntryList.Count();i++)
1480 if(aCurEntryList[i]==nIdx)
1482 nSelP=i;
1483 break;
1487 else
1489 DBG_ERROR("svx::SvxNumberFormatShell::GetListPos4Entry(), list got to large!" );
1491 return nSelP;
1494 short SvxNumberFormatShell::GetListPos4Entry( const String& rFmtString )
1496 sal_uInt32 nAt=0;
1497 short nSelP=SELPOS_NONE;
1498 if(FindEntry(rFmtString, &nAt))
1500 if(NUMBERFORMAT_ENTRY_NOT_FOUND!=nAt && NUMBERFORMAT_ENTRY_NEW_CURRENCY!=nAt)
1502 nSelP=GetListPos4Entry(nAt);
1504 else
1506 if(aCurrencyFormatList.Count()>0)
1508 for(sal_uInt16 i=0;i<aCurrencyFormatList.Count();i++)
1510 if (rFmtString==*aCurrencyFormatList[i])
1512 nSelP=i;
1513 break;
1519 return nSelP;
1522 String SvxNumberFormatShell::GetStandardName() const
1524 return pFormatter->GetStandardName( eCurLanguage);
1527 void SvxNumberFormatShell::GetCurrencySymbols( SvStringsDtor& rList, sal_uInt16* pPos )
1530 const NfCurrencyEntry* pTmpCurrencyEntry=SvNumberFormatter::MatchSystemCurrency();
1532 sal_Bool bFlag=(pTmpCurrencyEntry==NULL);
1534 GetCurrencySymbols( rList, bFlag);
1536 if(pPos!=NULL)
1538 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1539 sal_uInt16 nTableCount=rCurrencyTable.Count();
1541 *pPos=0;
1542 sal_uInt16 nCount=aCurCurrencyList.Count();
1544 if(bFlag)
1546 *pPos=1;
1547 nCurCurrencyEntryPos=1;
1549 else
1551 for(sal_uInt16 i=1;i<nCount;i++)
1553 const sal_uInt16 j = aCurCurrencyList[i];
1554 if (j != (sal_uInt16)-1 && j < nTableCount &&
1555 pTmpCurrencyEntry == rCurrencyTable[j])
1557 *pPos=i;
1558 nCurCurrencyEntryPos=i;
1559 break;
1567 void SvxNumberFormatShell::GetCurrencySymbols( SvStringsDtor& rList, sal_Bool bFlag )
1569 aCurCurrencyList.Remove(0,aCurCurrencyList.Count());
1571 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1572 sal_uInt16 nCount=rCurrencyTable.Count();
1574 SvtLanguageTable* pLanguageTable=new SvtLanguageTable;
1576 sal_uInt16 nStart=1;
1577 sal_uInt16 i,j;
1579 XubString aString( ApplyLreOrRleEmbedding( rCurrencyTable[0]->GetSymbol()));
1580 aString += sal_Unicode(' ');
1581 aString += ApplyLreOrRleEmbedding( pLanguageTable->GetString( rCurrencyTable[0]->GetLanguage()));
1583 WSStringPtr pStr = new XubString(aString);
1584 rList.Insert( pStr,rList.Count());
1585 sal_uInt16 nAuto=(sal_uInt16)-1;
1586 aCurCurrencyList.Insert(nAuto,aCurCurrencyList.Count());
1588 if(bFlag)
1590 pStr = new XubString(aString);
1591 rList.Insert( pStr,rList.Count());
1592 aCurCurrencyList.Insert((sal_uInt16)0,aCurCurrencyList.Count());
1593 ++nStart;
1596 CollatorWrapper aCollator( ::comphelper::getProcessServiceFactory());
1597 aCollator.loadDefaultCollator( Application::GetSettings().GetLocale(), 0);
1599 const String aTwoSpace( RTL_CONSTASCII_USTRINGPARAM( " "));
1601 for(i=1;i<nCount;i++)
1603 XubString aStr( ApplyLreOrRleEmbedding( rCurrencyTable[i]->GetBankSymbol()));
1604 aStr += aTwoSpace;
1605 aStr += ApplyLreOrRleEmbedding( rCurrencyTable[i]->GetSymbol());
1606 aStr += aTwoSpace;
1607 aStr += ApplyLreOrRleEmbedding( pLanguageTable->GetString( rCurrencyTable[i]->GetLanguage()));
1609 pStr = new XubString(aStr);
1610 #if 0
1611 fprintf( stderr, "currency entry: %s\n", ByteString( *pStr, RTL_TEXTENCODING_UTF8).GetBuffer());
1612 #endif
1613 for(j=nStart;j<rList.Count();j++)
1615 const StringPtr pTestStr=rList[j];
1616 if (aCollator.compareString( *pStr, *pTestStr) < 0)
1617 break; // insert before first greater than
1619 rList.Insert( pStr,j);
1620 aCurCurrencyList.Insert(i,j);
1623 // Append ISO codes to symbol list.
1624 // XXX If this is to be changed, various other places would had to be
1625 // adapted that assume this order!
1626 sal_uInt16 nCont = rList.Count();
1628 for(i=1;i<nCount;i++)
1630 bool bInsert = true;
1631 pStr = new XubString( ApplyLreOrRleEmbedding( rCurrencyTable[i]->GetBankSymbol()));
1633 for (j = nCont; j < rList.Count() && bInsert; ++j)
1635 const StringPtr pTestStr=rList[j];
1637 if(*pTestStr==*pStr)
1638 bInsert = false;
1639 else
1640 if (aCollator.compareString( *pStr, *pTestStr) < 0)
1641 break; // insert before first greater than
1643 if(bInsert)
1645 rList.Insert( pStr,j);
1646 aCurCurrencyList.Insert(i,j);
1650 delete pLanguageTable;
1653 void SvxNumberFormatShell::GetCurrencyFormats(SvStrings& aListDtor)
1655 if(pCurCurrencyEntry!=NULL)
1657 NfWSStringsDtor aWSStringsDtor;
1658 /*sal_uInt16 nDefault = */pFormatter->GetCurrencyFormatStrings( aWSStringsDtor,
1659 *pCurCurrencyEntry, bBankingSymbol );
1661 for(sal_uInt16 i=0;i<aWSStringsDtor.Count();i++)
1663 aListDtor.Insert(new String(*aWSStringsDtor[i]),aListDtor.Count());
1668 sal_Bool SvxNumberFormatShell::IsBankingSymbol(sal_uInt16 nPos)
1670 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1671 sal_uInt16 nCount=rCurrencyTable.Count();
1673 return (nPos>nCount);
1676 void SvxNumberFormatShell::SetCurrencySymbol(sal_uInt16 nPos)
1678 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1679 sal_uInt16 nCount=rCurrencyTable.Count();
1681 bBankingSymbol=(nPos>=nCount);
1683 if(nPos<aCurCurrencyList.Count())
1685 sal_uInt16 nCurrencyPos=aCurCurrencyList[nPos];
1686 if(nCurrencyPos!=(sal_uInt16)-1)
1688 pCurCurrencyEntry=rCurrencyTable[nCurrencyPos];
1689 nCurCurrencyEntryPos=nPos;
1691 else
1693 pCurCurrencyEntry=NULL;
1694 nCurCurrencyEntryPos=0;
1695 nCurFormatKey=pFormatter->GetFormatIndex(
1696 NF_CURRENCY_1000DEC2_RED, eCurLanguage);
1701 sal_uInt32 SvxNumberFormatShell::GetCurrencySymbol()
1703 return nCurCurrencyEntryPos;
1706 NfCurrencyEntry* SvxNumberFormatShell::GetCurCurrencyEntry()
1708 return pCurCurrencyEntry;
1711 void SvxNumberFormatShell::SetCurCurrencyEntry(NfCurrencyEntry* pCEntry)
1713 pCurCurrencyEntry=pCEntry;
1716 sal_Bool SvxNumberFormatShell::IsTmpCurrencyFormat( const String& rFmtString )
1718 sal_uInt32 nFound;
1719 /*sal_Bool bRes=*/FindEntry(rFmtString, &nFound);
1721 if(nFound==NUMBERFORMAT_ENTRY_NEW_CURRENCY)
1723 return sal_True;
1725 return sal_False;
1728 sal_uInt16 SvxNumberFormatShell::FindCurrencyFormat( const String& rFmtString )
1730 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1731 sal_uInt16 nCount=rCurrencyTable.Count();
1733 sal_Bool bTestBanking=sal_False;
1735 sal_uInt16 nPos=FindCurrencyTableEntry(rFmtString, bTestBanking);
1737 sal_uInt16 nStart=0;
1739 if(nPos!=(sal_uInt16)-1)
1741 if(bTestBanking && aCurCurrencyList.Count()>nPos)
1743 nStart=nCount;
1745 for(sal_uInt16 j=nStart;j<aCurCurrencyList.Count();j++)
1747 if(aCurCurrencyList[j]==nPos) return j;
1750 return (sal_uInt16) -1;
1753 sal_uInt16 SvxNumberFormatShell::FindCurrencyTableEntry( const String& rFmtString, sal_Bool &bTestBanking )
1755 sal_uInt16 nPos=(sal_uInt16) -1;
1757 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1758 sal_uInt16 nCount=rCurrencyTable.Count();
1760 const SvNumberformat* pFormat;
1761 String aSymbol, aExtension;
1762 sal_uInt32 nFound = pFormatter->TestNewString( rFmtString, eCurLanguage );
1763 if ( nFound != NUMBERFORMAT_ENTRY_NOT_FOUND &&
1764 ((pFormat = pFormatter->GetEntry( nFound )) != 0) &&
1765 pFormat->GetNewCurrencySymbol( aSymbol, aExtension ) )
1766 { // eventually match with format locale
1767 const NfCurrencyEntry* pTmpCurrencyEntry =
1768 SvNumberFormatter::GetCurrencyEntry( bTestBanking, aSymbol, aExtension,
1769 pFormat->GetLanguage() );
1770 if ( pTmpCurrencyEntry )
1772 for(sal_uInt16 i=0;i<nCount;i++)
1774 if(pTmpCurrencyEntry==rCurrencyTable[i])
1776 nPos=i;
1777 break;
1782 else
1783 { // search symbol string only
1784 for(sal_uInt16 i=0;i<nCount;i++)
1786 const NfCurrencyEntry* pTmpCurrencyEntry=rCurrencyTable[i];
1787 XubString _aSymbol, aBankSymbol;
1788 pTmpCurrencyEntry->BuildSymbolString(_aSymbol,sal_False);
1789 pTmpCurrencyEntry->BuildSymbolString(aBankSymbol,sal_True);
1791 if(rFmtString.Search(_aSymbol)!=STRING_NOTFOUND)
1793 bTestBanking=sal_False;
1794 nPos=i;
1795 break;
1797 else if(rFmtString.Search(aBankSymbol)!=STRING_NOTFOUND)
1799 bTestBanking=sal_True;
1800 nPos=i;
1801 break;
1806 return nPos;
1809 sal_uInt16 SvxNumberFormatShell::FindCurrencyFormat(const NfCurrencyEntry* pTmpCurrencyEntry,sal_Bool bTmpBanking)
1811 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1812 sal_uInt16 nCount=rCurrencyTable.Count();
1814 // sal_Bool bTestBanking=sal_False;
1815 sal_uInt16 nPos=0;
1816 for(sal_uInt16 i=0;i<nCount;i++)
1818 if(pTmpCurrencyEntry==rCurrencyTable[i])
1820 nPos=i;
1821 break;
1825 sal_uInt16 nStart=0;
1826 if(bTmpBanking && aCurCurrencyList.Count()>nPos)
1828 nStart=nCount;
1830 for(sal_uInt16 j=nStart;j<aCurCurrencyList.Count();j++)
1832 if(aCurCurrencyList[j]==nPos) return j;
1834 return (sal_uInt16) -1;
1837 sal_Bool SvxNumberFormatShell::IsInTable(sal_uInt16 nPos,sal_Bool bTmpBanking,const String &rFmtString)
1839 sal_Bool bFlag=sal_False;
1841 if(nPos!=(sal_uInt16)-1)
1843 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1844 sal_uInt16 nCount=rCurrencyTable.Count();
1846 if(nPos<nCount)
1848 NfWSStringsDtor aWSStringsDtor;
1849 sal_uInt16 nDefault;
1851 const NfCurrencyEntry* pTmpCurrencyEntry=rCurrencyTable[nPos];
1853 if ( pTmpCurrencyEntry!=NULL)
1855 nDefault = pFormatter->GetCurrencyFormatStrings( aWSStringsDtor,
1856 *pTmpCurrencyEntry, bTmpBanking );
1858 for(sal_uInt16 i=0;i<aWSStringsDtor.Count();i++)
1860 if(*aWSStringsDtor[i]==rFmtString)
1862 bFlag=sal_True;
1863 break;
1870 return bFlag;