fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / items / numfmtsh.cxx
blobae6fbe7358d6a9a4f6928d79ca33cf5e1901c93c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/color.hxx>
22 #include <tools/debug.hxx>
23 #include <i18nlangtag/mslangid.hxx>
25 #include <svl/zforlist.hxx>
26 #include <svl/zformat.hxx>
28 #include <svtools/langtab.hxx>
29 #include <vcl/svapp.hxx>
30 #include <comphelper/processfactory.hxx>
32 #include <svx/numfmtsh.hxx>
34 #include <limits>
36 // class SvxNumberFormatShell --------------------------------------------
38 const double SvxNumberFormatShell::DEFAULT_NUMVALUE = 1234.56789;
40 // -----------------------------------------------------------------------
44 SvxNumberFormatShell* SvxNumberFormatShell::Create( SvNumberFormatter* pNumFormatter,
45 sal_uInt32 nFormatKey,
46 SvxNumberValueType eNumValType,
47 const String& rNumStr )
49 return new SvxNumberFormatShell(pNumFormatter,nFormatKey,
50 eNumValType,rNumStr );
53 SvxNumberFormatShell* SvxNumberFormatShell::Create( SvNumberFormatter* pNumFormatter,
54 sal_uInt32 nFormatKey,
55 SvxNumberValueType eNumValType,
56 double nNumVal,
57 const String* pNumStr )
59 return new SvxNumberFormatShell(pNumFormatter,nFormatKey,
60 eNumValType,nNumVal,pNumStr );
63 // -----------------------------------------------------------------------
65 SvxNumberFormatShell::SvxNumberFormatShell( SvNumberFormatter* pNumFormatter,
66 sal_uInt32 nFormatKey,
67 SvxNumberValueType eNumValType,
68 const String& rNumStr ) :
69 pFormatter ( pNumFormatter ),
70 pCurFmtTable ( NULL ),
71 eValType ( eNumValType ),
72 bUndoAddList ( true ),
73 nCurFormatKey ( nFormatKey ),
74 pCurCurrencyEntry(NULL),
75 bBankingSymbol (false),
76 nCurCurrencyEntryPos((sal_uInt16) SELPOS_NONE),
77 bUseStarFormat (false)
79 nValNum = DEFAULT_NUMVALUE;
81 switch ( eValType )
83 case SVX_VALUE_TYPE_STRING:
84 aValStr = rNumStr;
85 break;
86 case SVX_VALUE_TYPE_NUMBER:
87 case SVX_VALUE_TYPE_UNDEFINED:
88 default:
89 aValStr.Erase();
93 // -----------------------------------------------------------------------
95 SvxNumberFormatShell::SvxNumberFormatShell( SvNumberFormatter* pNumFormatter,
96 sal_uInt32 nFormatKey,
97 SvxNumberValueType eNumValType,
98 double nNumVal,
99 const String* pNumStr ) :
100 pFormatter ( pNumFormatter ),
101 pCurFmtTable ( NULL ),
102 eValType ( eNumValType ),
103 bUndoAddList ( true ),
104 nCurFormatKey ( nFormatKey ),
105 pCurCurrencyEntry(NULL),
106 bBankingSymbol (false),
107 nCurCurrencyEntryPos((sal_uInt16) SELPOS_NONE),
108 bUseStarFormat (false)
110 // #50441# When used in Writer, the SvxNumberInfoItem contains the
111 // original string in addition to the value
113 if ( pNumStr )
114 aValStr = *pNumStr;
116 switch ( eValType )
118 case SVX_VALUE_TYPE_NUMBER:
119 nValNum = nNumVal;
120 break;
121 case SVX_VALUE_TYPE_STRING:
122 case SVX_VALUE_TYPE_UNDEFINED:
123 default:
124 nValNum = DEFAULT_NUMVALUE;
128 // -----------------------------------------------------------------------
130 SvxNumberFormatShell::~SvxNumberFormatShell()
133 * An dieser Stelle wird abhaengig davon, ob die
134 * hinzugefuegten, benutzerdefinierten als gueltig
135 * erklaert wurden (ValidateNewEntries()), die
136 * Add-Liste wieder aus dem Zahlenformatierer entfernt.
138 * Loeschen von Formaten aus dem Formatierer passiert
139 * aus Undo-Gruenden nur in der aufrufenden Instanz.
142 if ( bUndoAddList )
144 // Hinzugefuegte Formate sind nicht gueltig:
145 // => wieder entfernen:
147 for ( std::vector<sal_uInt32>::const_iterator it(aAddList.begin()); it != aAddList.end(); ++it )
148 pFormatter->DeleteEntry( *it );
151 for ( std::vector<String*>::const_iterator it(aCurrencyFormatList.begin());
152 it != aCurrencyFormatList.end(); ++it )
153 delete *it;
156 // -----------------------------------------------------------------------
158 size_t SvxNumberFormatShell::GetUpdateDataCount() const
160 return aDelList.size();
163 // -----------------------------------------------------------------------
165 void SvxNumberFormatShell::GetUpdateData( sal_uInt32* pDelArray, const sal_uInt32 nSize )
167 const size_t nListSize = aDelList.size();
169 DBG_ASSERT( pDelArray && ( nSize == nListSize ), "Array nicht initialisiert!" );
171 if ( pDelArray && ( nSize == nListSize ) )
172 for (std::vector<sal_uInt32>::const_iterator it(aDelList.begin()); it != aDelList.end(); ++it )
173 *pDelArray++ = *it;
176 // -----------------------------------------------------------------------
178 void SvxNumberFormatShell::CategoryChanged( sal_uInt16 nCatLbPos,
179 short& rFmtSelPos,
180 std::vector<String*>& rFmtEntries )
182 short nOldCategory = nCurCategory;
183 PosToCategory_Impl( nCatLbPos, nCurCategory );
184 pCurFmtTable = &( pFormatter->GetEntryTable( nCurCategory,
185 nCurFormatKey,
186 eCurLanguage ) );
187 // reinitialize currency if category newly entered
188 if ( nCurCategory == NUMBERFORMAT_CURRENCY && nOldCategory != nCurCategory )
189 pCurCurrencyEntry = NULL;
190 rFmtSelPos = FillEntryList_Impl( rFmtEntries );
193 // -----------------------------------------------------------------------
195 void SvxNumberFormatShell::LanguageChanged( LanguageType eLangType,
196 short& rFmtSelPos,
197 std::vector<String*>& rFmtEntries )
199 eCurLanguage = eLangType;
200 pCurFmtTable = &(pFormatter->ChangeCL( nCurCategory,
201 nCurFormatKey,
202 eCurLanguage ) );
203 rFmtSelPos = FillEntryList_Impl( rFmtEntries );
206 // -----------------------------------------------------------------------
208 void SvxNumberFormatShell::FormatChanged( sal_uInt16 nFmtLbPos,
209 String& rPreviewStr,
210 Color*& rpFontColor )
212 if( static_cast<size_t>(nFmtLbPos) < aCurEntryList.size() )
214 nCurFormatKey = aCurEntryList[nFmtLbPos];
216 if( nCurFormatKey != NUMBERFORMAT_ENTRY_NOT_FOUND )
218 GetPreviewString_Impl( rPreviewStr, rpFontColor );
220 else if( nCurCategory == NUMBERFORMAT_CURRENCY )
222 if( static_cast<size_t>(nFmtLbPos) < aCurrencyFormatList.size() )
224 MakePrevStringFromVal(*aCurrencyFormatList[nFmtLbPos],
225 rPreviewStr,rpFontColor,nValNum);
230 // -----------------------------------------------------------------------
232 bool SvxNumberFormatShell::AddFormat( String& rFormat, xub_StrLen& rErrPos,
233 sal_uInt16& rCatLbSelPos, short& rFmtSelPos,
234 std::vector<String*>& rFmtEntries )
236 bool bInserted = false;
237 sal_uInt32 nAddKey = pFormatter->GetEntryKey( rFormat, eCurLanguage );
239 if ( nAddKey != NUMBERFORMAT_ENTRY_NOT_FOUND ) // bereits vorhanden?
241 ::std::vector<sal_uInt32>::iterator nAt = GetRemoved_Impl( nAddKey );
242 if ( nAt != aDelList.end() )
244 aDelList.erase( nAt );
245 bInserted = true;
247 else
249 OSL_FAIL( "Doppeltes Format!" );
252 else // neues Format
254 OUString sTemp(rFormat);
255 sal_Int32 nPos;
256 bInserted = pFormatter->PutEntry( sTemp, nPos,
257 nCurCategory, nAddKey,
258 eCurLanguage );
259 rErrPos = (nPos >= 0) ? (xub_StrLen)nPos : 0xFFFF;
260 rFormat = sTemp;
262 if (bInserted)
264 // May be sorted under a different locale if LCID was parsed.
265 const SvNumberformat* pEntry = pFormatter->GetEntry( nAddKey);
266 if (pEntry)
268 LanguageType nLang = pEntry->GetLanguage();
269 if (eCurLanguage != nLang)
271 // Current language's list would not show entry, adapt.
272 eCurLanguage = nLang;
278 if ( bInserted ) // eingefuegt
280 nCurFormatKey = nAddKey;
281 DBG_ASSERT( !IsAdded_Impl( nCurFormatKey ), "Doppeltes Format!" );
282 aAddList.push_back( nCurFormatKey );
284 // aktuelle Tabelle holen
285 pCurFmtTable = &(pFormatter->GetEntryTable( nCurCategory,
286 nCurFormatKey,
287 eCurLanguage ));
288 nCurCategory=pFormatter->GetType(nAddKey); //@@ ???
289 CategoryToPos_Impl( nCurCategory, rCatLbSelPos );
290 rFmtSelPos = FillEntryList_Impl( rFmtEntries );
292 else if ( rErrPos != 0 ) // Syntaxfehler
296 else // Doppelt einfuegen nicht moeglich
298 OSL_FAIL( "Doppeltes Format!" ); // oder doch?
301 return bInserted;
304 // -----------------------------------------------------------------------
306 bool SvxNumberFormatShell::RemoveFormat( const String& rFormat,
307 sal_uInt16& rCatLbSelPos,
308 short& rFmtSelPos,
309 std::vector<String*>& rFmtEntries )
311 sal_uInt32 nDelKey = pFormatter->GetEntryKey( rFormat, eCurLanguage );
313 DBG_ASSERT( nDelKey != NUMBERFORMAT_ENTRY_NOT_FOUND, "Eintrag nicht gefunden!" );
314 DBG_ASSERT( !IsRemoved_Impl( nDelKey ), "Eintrag bereits geloescht!" );
316 if ( (nDelKey != NUMBERFORMAT_ENTRY_NOT_FOUND) && !IsRemoved_Impl( nDelKey ) )
318 aDelList.push_back( nDelKey );
320 ::std::vector<sal_uInt32>::iterator nAt = GetAdded_Impl( nDelKey );
321 if( nAt != aAddList.end() )
323 aAddList.erase( nAt );
326 nCurCategory=pFormatter->GetType(nDelKey);
327 pCurFmtTable = &(pFormatter->GetEntryTable( nCurCategory,
328 nCurFormatKey,
329 eCurLanguage ));
331 nCurFormatKey=pFormatter->GetStandardFormat(nCurCategory,
332 eCurLanguage );
334 CategoryToPos_Impl( nCurCategory, rCatLbSelPos );
335 rFmtSelPos = FillEntryList_Impl( rFmtEntries );
337 return true;
340 // -----------------------------------------------------------------------
342 void SvxNumberFormatShell::MakeFormat( String& rFormat,
343 bool bThousand, bool bNegRed,
344 sal_uInt16 nPrecision, sal_uInt16 nLeadingZeroes,
345 sal_uInt16 nCurrencyPos)
347 if( aCurrencyFormatList.size() > static_cast<size_t>(nCurrencyPos) )
349 xub_StrLen rErrPos=0;
350 std::vector<String*> aFmtEList;
352 sal_uInt32 nFound = pFormatter->TestNewString( *aCurrencyFormatList[nCurrencyPos], eCurLanguage );
354 if ( nFound == NUMBERFORMAT_ENTRY_NOT_FOUND )
356 sal_uInt16 rCatLbSelPos=0;
357 short rFmtSelPos=0;
358 AddFormat( *aCurrencyFormatList[nCurrencyPos],rErrPos,rCatLbSelPos,
359 rFmtSelPos,aFmtEList);
362 if(rErrPos==0)
364 rFormat = pFormatter->GenerateFormat(nCurFormatKey,
365 eCurLanguage,
366 bThousand, bNegRed,
367 nPrecision, nLeadingZeroes);
369 for ( std::vector<String*>::const_iterator it(aFmtEList.begin()); it != aFmtEList.end(); ++it )
370 delete *it;
372 else
374 rFormat = pFormatter->GenerateFormat(nCurFormatKey,
375 eCurLanguage,
376 bThousand, bNegRed,
377 nPrecision, nLeadingZeroes);
381 // -----------------------------------------------------------------------
383 void SvxNumberFormatShell::GetOptions( const String& rFormat,
384 bool& rThousand,
385 bool& rNegRed,
386 sal_uInt16& rPrecision,
387 sal_uInt16& rLeadingZeroes,
388 sal_uInt16& rCatLbPos )
391 sal_uInt32 nFmtKey = pFormatter->GetEntryKey( rFormat, eCurLanguage );
393 if(nFmtKey != NUMBERFORMAT_ENTRY_NOT_FOUND)
395 if ( nFmtKey != NUMBERFORMAT_ENTRY_NOT_FOUND )
397 pFormatter->GetFormatSpecialInfo( nFmtKey,
398 rThousand, rNegRed,
399 rPrecision, rLeadingZeroes );
401 CategoryToPos_Impl( pFormatter->GetType( nFmtKey ), rCatLbPos );
403 else
404 rCatLbPos = CAT_USERDEFINED;
406 else
408 bool bTestBanking = false;
409 sal_uInt16 nPos=FindCurrencyTableEntry(rFormat, bTestBanking );
411 if(IsInTable(nPos,bTestBanking,rFormat) &&
412 pFormatter->GetFormatSpecialInfo( rFormat,rThousand, rNegRed,
413 rPrecision, rLeadingZeroes,eCurLanguage)==0)
415 rCatLbPos = CAT_CURRENCY;
417 else
418 rCatLbPos = CAT_USERDEFINED;
423 // -----------------------------------------------------------------------
425 void SvxNumberFormatShell::MakePreviewString( const String& rFormatStr,
426 String& rPreviewStr,
427 Color*& rpFontColor )
429 rpFontColor = NULL;
431 sal_uIntPtr nExistingFormat = pFormatter->GetEntryKey( rFormatStr, eCurLanguage );
432 if ( nExistingFormat == NUMBERFORMAT_ENTRY_NOT_FOUND )
434 // real preview - not implemented in NumberFormatter for text formats
435 OUString sTempOut(rPreviewStr);
437 pFormatter->GetPreviewString( rFormatStr, nValNum, sTempOut,
438 &rpFontColor, eCurLanguage, bUseStarFormat );
439 rPreviewStr = sTempOut;
441 else
443 // format exists
445 // #50441# if a string was set in addition to the value, use it for text formats
446 bool bUseText = ( eValType == SVX_VALUE_TYPE_STRING ||
447 ( aValStr.Len() && ( pFormatter->GetType(nExistingFormat) & NUMBERFORMAT_TEXT ) ) );
448 if ( bUseText )
450 OUString sTempIn(aValStr);
451 OUString sTempOut(rPreviewStr);
452 pFormatter->GetOutputString( sTempIn, nExistingFormat,
453 sTempOut, &rpFontColor );
454 aValStr = sTempIn;
455 rPreviewStr = sTempOut;
457 else
459 pFormatter->GetOutputString( nValNum, nExistingFormat,
460 rPreviewStr, &rpFontColor, bUseStarFormat );
465 // -----------------------------------------------------------------------
467 bool SvxNumberFormatShell::IsUserDefined( const String& rFmtString )
469 sal_uInt32 nFound = pFormatter->GetEntryKey( rFmtString, eCurLanguage );
471 bool bFlag=false;
472 if ( nFound != NUMBERFORMAT_ENTRY_NOT_FOUND )
474 bFlag=pFormatter->IsUserDefined( rFmtString, eCurLanguage );
476 if(bFlag)
478 const SvNumberformat* pNumEntry = pFormatter->GetEntry(nFound);
480 if(pNumEntry!=NULL && pNumEntry->HasNewCurrency())
482 bool bTestBanking;
483 sal_uInt16 nPos=FindCurrencyTableEntry(rFmtString,bTestBanking);
484 bFlag=!IsInTable(nPos,bTestBanking,rFmtString);
488 return bFlag;
491 // -----------------------------------------------------------------------
493 bool SvxNumberFormatShell::FindEntry( const String& rFmtString, sal_uInt32* pAt /* = NULL */ )
495 bool bRes=false;
496 sal_uInt32 nFound = pFormatter->TestNewString( rFmtString, eCurLanguage );
498 if ( nFound == NUMBERFORMAT_ENTRY_NOT_FOUND )
500 bool bTestBanking=false;
501 sal_uInt16 nPos=FindCurrencyTableEntry(rFmtString, bTestBanking );
503 if(IsInTable(nPos,bTestBanking,rFmtString))
505 nFound=NUMBERFORMAT_ENTRY_NEW_CURRENCY;
506 bRes=true;
509 else
511 bRes=!IsRemoved_Impl( nFound );
514 if ( pAt )
515 *pAt = nFound;
517 return bRes;
521 // -----------------------------------------------------------------------
523 void SvxNumberFormatShell::GetInitSettings( sal_uInt16& nCatLbPos,
524 LanguageType& rLangType,
525 sal_uInt16& nFmtLbSelPos,
526 std::vector<String*>& rFmtEntries,
527 String& rPrevString,
528 Color*& rpPrevColor )
530 // -------------------------------------------------------------------
531 // Vorbedingung: Zahlenformatierer gefunden
532 DBG_ASSERT( pFormatter != NULL, "Zahlenformatierer nicht gefunden!" );
534 // sal_uInt16 nCount = 0;
535 short nSelPos = SELPOS_NONE;
536 // SvNumberFormatTable* pFmtTable = NULL;
538 // Sonderbehandlung fuer undefiniertes Zahlenformat:
539 if ( (eValType == SVX_VALUE_TYPE_UNDEFINED) && (nCurFormatKey == 0) )
540 PosToCategory_Impl( CAT_ALL, nCurCategory ); // Kategorie = Alle
541 else
542 nCurCategory = NUMBERFORMAT_UNDEFINED; // Kategorie = Undefiniert
544 pCurFmtTable = &(pFormatter->GetFirstEntryTable( nCurCategory,
545 nCurFormatKey,
546 eCurLanguage ));
550 CategoryToPos_Impl( nCurCategory, nCatLbPos );
551 rLangType = eCurLanguage;
553 nSelPos = FillEntryList_Impl( rFmtEntries );
555 DBG_ASSERT( nSelPos != SELPOS_NONE, "Leere Formatliste!" );
557 nFmtLbSelPos = (nSelPos != SELPOS_NONE) ? (sal_uInt16)nSelPos : 0;
558 GetPreviewString_Impl( rPrevString, rpPrevColor );
561 // -----------------------------------------------------------------------
563 short SvxNumberFormatShell::FillEntryList_Impl( std::vector<String*>& rList )
565 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
566 * Rueckgabewert ist die Listenposition des aktuellen Formates.
567 * Ist die Liste leer oder gibt es kein aktuelles Format,
568 * so wird SELPOS_NONE geliefert.
570 short nSelPos=0;
571 sal_uInt16 nPrivCat = CAT_CURRENCY;
572 nSelPos=SELPOS_NONE;
574 aCurEntryList.clear();
576 if(nCurCategory==NUMBERFORMAT_ALL)
578 FillEListWithStd_Impl(rList,CAT_NUMBER,nSelPos);
579 FillEListWithStd_Impl(rList,CAT_PERCENT,nSelPos);
580 FillEListWithStd_Impl(rList,CAT_CURRENCY,nSelPos);
581 FillEListWithStd_Impl(rList,CAT_DATE,nSelPos);
582 FillEListWithStd_Impl(rList,CAT_TIME,nSelPos);
583 FillEListWithStd_Impl(rList,CAT_SCIENTIFIC,nSelPos);
584 FillEListWithStd_Impl(rList,CAT_FRACTION,nSelPos);
585 FillEListWithStd_Impl(rList,CAT_BOOLEAN,nSelPos);
586 FillEListWithStd_Impl(rList,CAT_TEXT,nSelPos);
588 else
590 CategoryToPos_Impl(nCurCategory, nPrivCat);
591 FillEListWithStd_Impl(rList,nPrivCat,nSelPos);
594 if( nPrivCat!=CAT_CURRENCY)
595 nSelPos=FillEListWithUsD_Impl(rList,nPrivCat,nSelPos);
597 return nSelPos;
600 void SvxNumberFormatShell::FillEListWithStd_Impl( std::vector<String*>& rList,
601 sal_uInt16 nPrivCat,short &nSelPos )
603 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
604 * Rueckgabewert ist die Listenposition des aktuellen Formates.
605 * Ist die Liste leer oder gibt es kein aktuelles Format,
606 * so wird SELPOS_NONE geliefert.
608 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
610 for ( std::vector<String*>::const_iterator it(aCurrencyFormatList.begin());
611 it != aCurrencyFormatList.end(); ++it )
612 delete *it;
613 aCurrencyFormatList.clear();
615 if(nPrivCat==CAT_CURRENCY)
617 nSelPos=FillEListWithCurrency_Impl(rList,nSelPos);
619 else
621 NfIndexTableOffset eOffsetStart;
622 NfIndexTableOffset eOffsetEnd;
624 switch(nPrivCat)
626 case CAT_NUMBER :eOffsetStart=NF_NUMBER_START;
627 eOffsetEnd=NF_NUMBER_END;
628 break;
629 case CAT_PERCENT :eOffsetStart=NF_PERCENT_START;
630 eOffsetEnd=NF_PERCENT_END;
631 break;
632 case CAT_CURRENCY :eOffsetStart=NF_CURRENCY_START;
633 eOffsetEnd=NF_CURRENCY_END;
634 break;
635 case CAT_DATE :eOffsetStart=NF_DATE_START;
636 eOffsetEnd=NF_DATE_END;
637 break;
638 case CAT_TIME :eOffsetStart=NF_TIME_START;
639 eOffsetEnd=NF_TIME_END;
640 break;
641 case CAT_SCIENTIFIC :eOffsetStart=NF_SCIENTIFIC_START;
642 eOffsetEnd=NF_SCIENTIFIC_END;
643 break;
644 case CAT_FRACTION :eOffsetStart=NF_FRACTION_START;
645 eOffsetEnd=NF_FRACTION_END;
646 break;
647 case CAT_BOOLEAN :eOffsetStart=NF_BOOLEAN;
648 eOffsetEnd=NF_BOOLEAN;
649 break;
650 case CAT_TEXT :eOffsetStart=NF_TEXT;
651 eOffsetEnd=NF_TEXT;
652 break;
653 default :return;
656 nSelPos=FillEListWithFormats_Impl(rList,nSelPos,eOffsetStart,eOffsetEnd);
658 if(nPrivCat==CAT_DATE || nPrivCat==CAT_TIME)
660 nSelPos=FillEListWithDateTime_Impl(rList,nSelPos);
661 //if(nSelPos!=SELPOS_NONE) nSelPos=nTmpPos;
666 short SvxNumberFormatShell::FillEListWithFormats_Impl( std::vector<String*>& rList,
667 short nSelPos,
668 NfIndexTableOffset eOffsetStart,
669 NfIndexTableOffset eOffsetEnd)
671 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
672 * Rueckgabewert ist die Listenposition des aktuellen Formates.
673 * Ist die Liste leer oder gibt es kein aktuelles Format,
674 * so wird SELPOS_NONE geliefert.
676 sal_uInt16 nMyType;
678 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
680 const SvNumberformat* pNumEntry = pCurFmtTable->empty() ? 0 : pCurFmtTable->begin()->second;
681 sal_uInt32 nNFEntry;
682 String aStrComment;
683 String aNewFormNInfo;
685 short nMyCat = SELPOS_NONE;
687 long nIndex;
689 for(nIndex=eOffsetStart;nIndex<=eOffsetEnd;nIndex++)
691 nNFEntry=pFormatter->GetFormatIndex((NfIndexTableOffset)nIndex,eCurLanguage);
693 pNumEntry = pFormatter->GetEntry(nNFEntry);
695 if(pNumEntry==NULL) continue;
697 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
698 aStrComment=pNumEntry->GetComment();
699 CategoryToPos_Impl(nMyCat,nMyType);
700 aNewFormNInfo= pNumEntry->GetFormatstring();
702 String *const pStr = new String(aNewFormNInfo);
704 if ( nNFEntry == nCurFormatKey )
706 nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.size() : SELPOS_NONE;
709 rList.push_back( pStr );
710 aCurEntryList.push_back( nNFEntry );
713 return nSelPos;
716 short SvxNumberFormatShell::FillEListWithDateTime_Impl( std::vector<String*>& rList,
717 short nSelPos)
719 sal_uInt16 nMyType;
721 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
723 const SvNumberformat* pNumEntry = pCurFmtTable->empty() ? 0 : pCurFmtTable->begin()->second;
724 sal_uInt32 nNFEntry;
725 String aStrComment;
726 String aNewFormNInfo;
728 short nMyCat = SELPOS_NONE;
730 long nIndex;
732 for(nIndex=NF_DATETIME_START;nIndex<=NF_DATETIME_END;nIndex++)
734 nNFEntry=pFormatter->GetFormatIndex((NfIndexTableOffset)nIndex,eCurLanguage);
736 pNumEntry = pFormatter->GetEntry(nNFEntry);
737 if(pNumEntry!=NULL)
739 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
740 aStrComment=pNumEntry->GetComment();
741 CategoryToPos_Impl(nMyCat,nMyType);
742 aNewFormNInfo= pNumEntry->GetFormatstring();
744 String *const pStr = new String(aNewFormNInfo);
746 if ( nNFEntry == nCurFormatKey )
748 nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.size() : SELPOS_NONE;
751 rList.push_back( pStr );
752 aCurEntryList.push_back( nNFEntry );
756 return nSelPos;
759 short SvxNumberFormatShell::FillEListWithCurrency_Impl( std::vector<String*>& rList,
760 short nSelPos)
762 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
763 * Rueckgabewert ist die Listenposition des aktuellen Formates.
764 * Ist die Liste leer oder gibt es kein aktuelles Format,
765 * so wird SELPOS_NONE geliefert.
767 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
769 const NfCurrencyEntry* pTmpCurrencyEntry;
770 bool bTmpBanking;
771 XubString rSymbol;
773 bool bFlag=pFormatter->GetNewCurrencySymbolString(nCurFormatKey,rSymbol,
774 &pTmpCurrencyEntry,&bTmpBanking);
776 if((!bFlag && pCurCurrencyEntry==NULL) ||
777 (bFlag && pTmpCurrencyEntry==NULL && !rSymbol.Len()) ||
778 nCurCategory==NUMBERFORMAT_ALL)
780 if ( nCurCategory == NUMBERFORMAT_ALL )
781 FillEListWithUserCurrencys(rList,nSelPos);
782 nSelPos=FillEListWithSysCurrencys(rList,nSelPos);
784 else
786 nSelPos=FillEListWithUserCurrencys(rList,nSelPos);
789 return nSelPos;
793 short SvxNumberFormatShell::FillEListWithSysCurrencys( std::vector<String*>& rList,
794 short nSelPos)
796 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
797 * Rueckgabewert ist die Listenposition des aktuellen Formates.
798 * Ist die Liste leer oder gibt es kein aktuelles Format,
799 * so wird SELPOS_NONE geliefert.
801 sal_uInt16 nMyType;
803 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
805 const SvNumberformat* pNumEntry = pCurFmtTable->empty() ? 0 : pCurFmtTable->begin()->second;
806 sal_uInt32 nNFEntry;
807 String aStrComment;
808 String aNewFormNInfo;
810 nCurCurrencyEntryPos=0;
812 short nMyCat = SELPOS_NONE;
814 NfIndexTableOffset eOffsetStart=NF_CURRENCY_START;
815 NfIndexTableOffset eOffsetEnd=NF_CURRENCY_END;
816 long nIndex;
818 for(nIndex=eOffsetStart;nIndex<=eOffsetEnd;nIndex++)
820 nNFEntry=pFormatter->GetFormatIndex((NfIndexTableOffset)nIndex,eCurLanguage);
822 pNumEntry = pFormatter->GetEntry(nNFEntry);
824 if(pNumEntry==NULL) continue;
826 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
827 aStrComment=pNumEntry->GetComment();
828 CategoryToPos_Impl(nMyCat,nMyType);
829 aNewFormNInfo= pNumEntry->GetFormatstring();
831 String *const pStr = new String(aNewFormNInfo);
833 if ( nNFEntry == nCurFormatKey )
835 nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.size() : SELPOS_NONE;
838 rList.push_back( pStr );
839 aCurEntryList.push_back( nNFEntry );
842 if(nCurCategory!=NUMBERFORMAT_ALL)
844 SvNumberFormatTable::iterator it = pCurFmtTable->begin();
846 while ( it != pCurFmtTable->end() )
848 sal_uInt32 nKey = it->first;
849 pNumEntry = it->second;
851 if ( !IsRemoved_Impl( nKey ))
853 bool bUserNewCurrency=false;
854 if(pNumEntry->HasNewCurrency())
856 const NfCurrencyEntry* pTmpCurrencyEntry;
857 bool bTmpBanking;
858 XubString rSymbol;
860 pFormatter->GetNewCurrencySymbolString(nKey,rSymbol,
861 &pTmpCurrencyEntry,&bTmpBanking);
863 bUserNewCurrency=(pTmpCurrencyEntry!=NULL);
866 if(!bUserNewCurrency &&(pNumEntry->GetType() & NUMBERFORMAT_DEFINED))
868 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
869 aStrComment=pNumEntry->GetComment();
870 CategoryToPos_Impl(nMyCat,nMyType);
871 aNewFormNInfo= pNumEntry->GetFormatstring();
873 String *const pStr = new String(aNewFormNInfo);
875 if ( nKey == nCurFormatKey ) nSelPos =aCurEntryList.size();
876 rList.push_back( pStr );
877 aCurEntryList.push_back( nKey );
880 ++it;
883 return nSelPos;
886 short SvxNumberFormatShell::FillEListWithUserCurrencys( std::vector<String*>& rList,
887 short nSelPos)
889 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
890 * Rueckgabewert ist die Listenposition des aktuellen Formates.
891 * Ist die Liste leer oder gibt es kein aktuelles Format,
892 * so wird SELPOS_NONE geliefert.
894 sal_uInt16 nMyType;
896 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
898 String aStrComment;
899 String aNewFormNInfo;
900 short nMyCat = SELPOS_NONE;
902 const NfCurrencyEntry* pTmpCurrencyEntry;
903 bool bTmpBanking, bAdaptSelPos;
904 XubString rSymbol;
905 XubString rBankSymbol;
907 std::vector<String*> aList;
908 std::vector<sal_uInt32> aKeyList;
910 pFormatter->GetNewCurrencySymbolString(nCurFormatKey,rSymbol,
911 &pTmpCurrencyEntry,&bTmpBanking);
913 XubString rShortSymbol;
915 if(pCurCurrencyEntry==NULL)
917 // #110398# If no currency format was previously selected (we're not
918 // about to add another currency), try to select the initial currency
919 // format (nCurFormatKey) that was set in FormatChanged() after
920 // matching the format string entered in the dialog.
921 bAdaptSelPos = true;
922 pCurCurrencyEntry=(NfCurrencyEntry*)pTmpCurrencyEntry;
923 bBankingSymbol=bTmpBanking;
924 nCurCurrencyEntryPos=FindCurrencyFormat(pTmpCurrencyEntry,bTmpBanking);
926 else
928 if (pTmpCurrencyEntry == pCurCurrencyEntry)
929 bAdaptSelPos = true;
930 else
932 bAdaptSelPos = false;
933 pTmpCurrencyEntry = pCurCurrencyEntry;
935 bTmpBanking=bBankingSymbol;
938 if(pTmpCurrencyEntry!=NULL)
940 rSymbol = pTmpCurrencyEntry->BuildSymbolString(false);
941 rBankSymbol = pTmpCurrencyEntry->BuildSymbolString(true);
942 rShortSymbol = pTmpCurrencyEntry->BuildSymbolString(bTmpBanking,true);
945 SvNumberFormatTable::iterator it = pCurFmtTable->begin();
946 while ( it != pCurFmtTable->end() )
948 sal_uInt32 nKey = it->first;
949 const SvNumberformat* pNumEntry = it->second;
951 if ( !IsRemoved_Impl( nKey ) )
953 if( pNumEntry->GetType() & NUMBERFORMAT_DEFINED ||
954 pNumEntry->IsAdditionalStandardDefined() )
956 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
957 aStrComment=pNumEntry->GetComment();
958 CategoryToPos_Impl(nMyCat,nMyType);
959 aNewFormNInfo= pNumEntry->GetFormatstring();
961 bool bInsFlag = false;
962 if ( pNumEntry->HasNewCurrency() )
964 bInsFlag = true; // merge locale formats into currency selection
966 else if( (!bTmpBanking && aNewFormNInfo.Search(rSymbol)!=STRING_NOTFOUND) ||
967 (bTmpBanking && aNewFormNInfo.Search(rBankSymbol)!=STRING_NOTFOUND) )
969 bInsFlag = true;
971 else if(aNewFormNInfo.Search(rShortSymbol)!=STRING_NOTFOUND)
973 XubString rTstSymbol;
974 const NfCurrencyEntry* pTstCurrencyEntry;
975 bool bTstBanking;
977 pFormatter->GetNewCurrencySymbolString(nKey,rTstSymbol,
978 &pTstCurrencyEntry,&bTstBanking);
980 if(pTmpCurrencyEntry==pTstCurrencyEntry && bTstBanking==bTmpBanking)
982 bInsFlag = true;
987 if(bInsFlag)
989 aList.push_back( new String(aNewFormNInfo) );
990 aKeyList.push_back( nKey );
994 ++it;
997 NfWSStringsDtor aWSStringsDtor;
998 sal_uInt16 nDefault;
999 if ( pTmpCurrencyEntry && nCurCategory != NUMBERFORMAT_ALL )
1001 nDefault = pFormatter->GetCurrencyFormatStrings(
1002 aWSStringsDtor, *pTmpCurrencyEntry, bTmpBanking );
1003 if ( !bTmpBanking )
1004 pFormatter->GetCurrencyFormatStrings(
1005 aWSStringsDtor, *pTmpCurrencyEntry, true );
1007 else
1008 nDefault = 0;
1009 if ( !bTmpBanking && nCurCategory != NUMBERFORMAT_ALL )
1010 { // append formats for all currencies defined in the current I18N locale
1011 const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable();
1012 sal_uInt16 nCurrCount = rCurrencyTable.size();
1013 LanguageType eLang = MsLangId::getRealLanguage( eCurLanguage );
1014 for ( sal_uInt16 i=0; i < nCurrCount; ++i )
1016 const NfCurrencyEntry* pCurr = &rCurrencyTable[i];
1017 if ( pCurr->GetLanguage() == eLang && pTmpCurrencyEntry != pCurr )
1019 pFormatter->GetCurrencyFormatStrings( aWSStringsDtor, *pCurr, false );
1020 pFormatter->GetCurrencyFormatStrings( aWSStringsDtor, *pCurr, true );
1025 size_t nOldListCount = rList.size();
1026 for( size_t i = 0, nPos = nOldListCount; i < aWSStringsDtor.size(); ++i )
1028 bool bFlag = true;
1029 String aInsStr(aWSStringsDtor[i]);
1030 size_t j;
1031 for( j=0; j < aList.size(); ++j )
1033 const String * pTestStr=aList[j];
1035 if(*pTestStr==aInsStr)
1037 bFlag = false;
1038 break;
1041 if(bFlag)
1043 rList.push_back( new String(aInsStr) );
1044 aCurEntryList.insert( aCurEntryList.begin() + (nPos++), NUMBERFORMAT_ENTRY_NOT_FOUND);
1046 else
1048 rList.push_back( aList[j] );
1049 aList.erase( aList.begin()+j );
1050 aCurEntryList.insert( aCurEntryList.begin() + (nPos++), aKeyList[j]);
1051 aKeyList.erase( aKeyList.begin()+j );
1055 for( size_t i = 0; i < aKeyList.size(); ++i )
1057 if( aKeyList[i] != NUMBERFORMAT_ENTRY_NOT_FOUND )
1059 rList.push_back( aList[i] );
1060 aCurEntryList.push_back( aKeyList[i] );
1064 for( size_t i = nOldListCount; i < rList.size(); ++i )
1066 aCurrencyFormatList.push_back( new String(*rList[i]) );
1068 if ( nSelPos == SELPOS_NONE && bAdaptSelPos && aCurEntryList[i] == nCurFormatKey )
1069 nSelPos = i;
1072 if ( nSelPos == SELPOS_NONE && nCurCategory != NUMBERFORMAT_ALL )
1073 nSelPos = nDefault;
1075 return nSelPos;
1079 short SvxNumberFormatShell::FillEListWithUsD_Impl( std::vector<String*>& rList,
1080 sal_uInt16 nPrivCat, short nSelPos )
1082 /* Erstellen einer aktuellen Liste von Format-Eintraegen.
1083 * Rueckgabewert ist die Listenposition des aktuellen Formates.
1084 * Ist die Liste leer oder gibt es kein aktuelles Format,
1085 * so wird SELPOS_NONE geliefert.
1087 sal_uInt16 nMyType;
1089 DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
1091 String aStrComment;
1092 String aNewFormNInfo;
1094 short nMyCat = SELPOS_NONE;
1095 bool bAdditional = (nPrivCat != CAT_USERDEFINED &&
1096 nCurCategory != NUMBERFORMAT_ALL);
1098 SvNumberFormatTable::iterator it = pCurFmtTable->begin();
1099 while ( it != pCurFmtTable->end() )
1101 sal_uInt32 nKey = it->first;
1102 const SvNumberformat* pNumEntry = it->second;
1104 if ( !IsRemoved_Impl( nKey ) )
1106 if( (pNumEntry->GetType() & NUMBERFORMAT_DEFINED) ||
1107 (bAdditional && pNumEntry->IsAdditionalStandardDefined()) )
1109 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
1110 aStrComment=pNumEntry->GetComment();
1111 CategoryToPos_Impl(nMyCat,nMyType);
1112 aNewFormNInfo= pNumEntry->GetFormatstring();
1114 bool bFlag=true;
1115 if(pNumEntry->HasNewCurrency())
1117 bool bTestBanking;
1118 sal_uInt16 nPos=FindCurrencyTableEntry(aNewFormNInfo,bTestBanking);
1119 bFlag=!IsInTable(nPos,bTestBanking,aNewFormNInfo);
1121 if(bFlag)
1123 String *const pStr = new String(aNewFormNInfo);
1125 if ( nKey == nCurFormatKey ) nSelPos = aCurEntryList.size();
1126 rList.push_back( pStr );
1127 aCurEntryList.push_back( nKey );
1131 ++it;
1133 return nSelPos;
1137 // -----------------------------------------------------------------------
1139 void SvxNumberFormatShell::GetPreviewString_Impl( String& rString, Color*& rpColor )
1141 rpColor = NULL;
1143 // #50441# if a string was set in addition to the value, use it for text formats
1144 bool bUseText = ( eValType == SVX_VALUE_TYPE_STRING ||
1145 ( aValStr.Len() && ( pFormatter->GetType(nCurFormatKey) & NUMBERFORMAT_TEXT ) ) );
1147 if ( bUseText )
1149 OUString sTempIn(aValStr);
1150 OUString sTempOut(rString);
1151 pFormatter->GetOutputString( sTempIn, nCurFormatKey, sTempOut, &rpColor );
1152 aValStr = sTempIn;
1153 rString = sTempOut;
1155 else
1157 pFormatter->GetOutputString( nValNum, nCurFormatKey, rString, &rpColor, bUseStarFormat );
1161 // -----------------------------------------------------------------------
1163 ::std::vector<sal_uInt32>::iterator SvxNumberFormatShell::GetRemoved_Impl( size_t nKey )
1165 return ::std::find(aDelList.begin(), aDelList.end(), nKey);
1168 // -----------------------------------------------------------------------
1170 bool SvxNumberFormatShell::IsRemoved_Impl( size_t nKey )
1172 return GetRemoved_Impl( nKey ) != aDelList.end();
1175 // -----------------------------------------------------------------------
1177 ::std::vector<sal_uInt32>::iterator SvxNumberFormatShell::GetAdded_Impl( size_t nKey )
1179 return ::std::find(aAddList.begin(), aAddList.end(), nKey);
1182 //------------------------------------------------------------------------
1184 bool SvxNumberFormatShell::IsAdded_Impl( size_t nKey )
1186 return GetAdded_Impl( nKey ) != aAddList.end();
1189 // -----------------------------------------------------------------------
1190 // Konvertierungs-Routinen:
1191 // ------------------------
1193 void SvxNumberFormatShell::PosToCategory_Impl( sal_uInt16 nPos, short& rCategory )
1195 // Kategorie ::com::sun::star::form-Positionen abbilden (->Resource)
1196 switch ( nPos )
1198 case CAT_USERDEFINED: rCategory = NUMBERFORMAT_DEFINED; break;
1199 case CAT_NUMBER: rCategory = NUMBERFORMAT_NUMBER; break;
1200 case CAT_PERCENT: rCategory = NUMBERFORMAT_PERCENT; break;
1201 case CAT_CURRENCY: rCategory = NUMBERFORMAT_CURRENCY; break;
1202 case CAT_DATE: rCategory = NUMBERFORMAT_DATE; break;
1203 case CAT_TIME: rCategory = NUMBERFORMAT_TIME; break;
1204 case CAT_SCIENTIFIC: rCategory = NUMBERFORMAT_SCIENTIFIC; break;
1205 case CAT_FRACTION: rCategory = NUMBERFORMAT_FRACTION; break;
1206 case CAT_BOOLEAN: rCategory = NUMBERFORMAT_LOGICAL; break;
1207 case CAT_TEXT: rCategory = NUMBERFORMAT_TEXT; break;
1208 case CAT_ALL:
1209 default: rCategory = NUMBERFORMAT_ALL; break;
1213 // -----------------------------------------------------------------------
1215 void SvxNumberFormatShell::CategoryToPos_Impl( short nCategory, sal_uInt16& rPos )
1217 // Kategorie auf ::com::sun::star::form-Positionen abbilden (->Resource)
1218 switch ( nCategory )
1220 case NUMBERFORMAT_DEFINED: rPos = CAT_USERDEFINED; break;
1221 case NUMBERFORMAT_NUMBER: rPos = CAT_NUMBER; break;
1222 case NUMBERFORMAT_PERCENT: rPos = CAT_PERCENT; break;
1223 case NUMBERFORMAT_CURRENCY: rPos = CAT_CURRENCY; break;
1224 case NUMBERFORMAT_DATETIME:
1225 case NUMBERFORMAT_DATE: rPos = CAT_DATE; break;
1226 case NUMBERFORMAT_TIME: rPos = CAT_TIME; break;
1227 case NUMBERFORMAT_SCIENTIFIC: rPos = CAT_SCIENTIFIC; break;
1228 case NUMBERFORMAT_FRACTION: rPos = CAT_FRACTION; break;
1229 case NUMBERFORMAT_LOGICAL: rPos = CAT_BOOLEAN; break;
1230 case NUMBERFORMAT_TEXT: rPos = CAT_TEXT; break;
1231 case NUMBERFORMAT_ALL:
1232 default: rPos = CAT_ALL;
1237 /*************************************************************************
1238 #* Member: MakePrevStringFromVal Datum:19.09.97
1239 #*------------------------------------------------------------------------
1241 #* Klasse: SvxNumberFormatShell
1243 #* Funktion: Formatiert die Zahl nValue abhaengig von rFormatStr
1244 #* und speichert das Ergebnis in rPreviewStr.
1246 #* Input: FormatString, Farbe, zu formatierende Zahl
1248 #* Output: Ausgabestring rPreviewStr
1250 #************************************************************************/
1252 void SvxNumberFormatShell::MakePrevStringFromVal(
1253 const String& rFormatStr,
1254 String& rPreviewStr,
1255 Color*& rpFontColor,
1256 double nValue)
1258 rpFontColor = NULL;
1259 OUString sTempOut(rPreviewStr);
1260 pFormatter->GetPreviewString( rFormatStr, nValue, sTempOut, &rpFontColor, eCurLanguage );
1261 rPreviewStr = sTempOut;
1264 /*************************************************************************
1265 #* Member: GetComment4Entry Datum:30.10.97
1266 #*------------------------------------------------------------------------
1268 #* Klasse: SvxNumberFormatShell
1270 #* Funktion: Liefert den Kommentar fuer einen gegebenen
1271 #* Eintrag zurueck.
1273 #* Input: Nummer des Eintrags
1275 #* Output: Kommentar-String
1277 #************************************************************************/
1279 void SvxNumberFormatShell::SetComment4Entry(short nEntry,String aEntStr)
1281 SvNumberformat *pNumEntry;
1282 if(nEntry<0) return;
1283 sal_uInt32 nMyNfEntry=aCurEntryList[nEntry];
1284 pNumEntry = (SvNumberformat*)pFormatter->GetEntry(nMyNfEntry);
1285 if(pNumEntry!=NULL) pNumEntry->SetComment(aEntStr);
1288 /*************************************************************************
1289 #* Member: GetComment4Entry Datum:30.10.97
1290 #*------------------------------------------------------------------------
1292 #* Klasse: SvxNumberFormatShell
1294 #* Funktion: Liefert den Kommentar fuer einen gegebenen
1295 #* Eintrag zurueck.
1297 #* Input: Nummer des Eintrags
1299 #* Output: Kommentar-String
1301 #************************************************************************/
1303 String SvxNumberFormatShell::GetComment4Entry(short nEntry)
1305 if(nEntry < 0)
1306 return String();
1308 if( static_cast<size_t>(nEntry) < aCurEntryList.size())
1310 sal_uInt32 nMyNfEntry=aCurEntryList[nEntry];
1311 const SvNumberformat *pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1312 if(pNumEntry!=NULL)
1313 return pNumEntry->GetComment();
1316 return String();
1319 /*************************************************************************
1320 #* Member: GetCategory4Entry Datum:30.10.97
1321 #*------------------------------------------------------------------------
1323 #* Klasse: SvxNumberFormatShell
1325 #* Funktion: Liefert die Kategorie- Nummer fuer einen gegebenen
1326 #* Eintrag zurueck.
1328 #* Input: Nummer des Eintrags
1330 #* Output: Kategorie- Nummer
1332 #************************************************************************/
1334 short SvxNumberFormatShell::GetCategory4Entry(short nEntry)
1336 if(nEntry<0) return 0;
1338 if( static_cast<size_t>(nEntry) < aCurEntryList.size() )
1340 sal_uInt32 nMyNfEntry=aCurEntryList[nEntry];
1342 if(nMyNfEntry!=NUMBERFORMAT_ENTRY_NOT_FOUND)
1344 const SvNumberformat *pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1345 sal_uInt16 nMyCat,nMyType;
1346 if(pNumEntry!=NULL)
1348 nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
1349 CategoryToPos_Impl(nMyCat,nMyType);
1351 return (short) nMyType;
1353 return 0;
1355 else if( !aCurrencyFormatList.empty() )
1357 return CAT_CURRENCY;
1360 return 0;
1364 /*************************************************************************
1365 #* Member: GetUserDefined4Entry Datum:31.10.97
1366 #*------------------------------------------------------------------------
1368 #* Klasse: SvxNumberFormatShell
1370 #* Funktion: Liefert die Information, ob ein Eintrag
1371 #* benutzerspezifisch ist zurueck.
1373 #* Input: Nummer des Eintrags
1375 #* Output: Benutzerspezifisch?
1377 #************************************************************************/
1379 bool SvxNumberFormatShell::GetUserDefined4Entry(short nEntry)
1381 if(nEntry<0) return false;
1383 if( static_cast<size_t>(nEntry) < aCurEntryList.size())
1385 sal_uInt32 nMyNfEntry=aCurEntryList[nEntry];
1386 const SvNumberformat *pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1388 if(pNumEntry!=NULL)
1390 if((pNumEntry->GetType() & NUMBERFORMAT_DEFINED)>0)
1392 return true;
1396 return false;
1400 /*************************************************************************
1401 #* Member: GetFormat4Entry Datum:30.10.97
1402 #*------------------------------------------------------------------------
1404 #* Klasse: SvxNumberFormatShell
1406 #* Funktion: Liefert den Format- String fuer einen gegebenen
1407 #* Eintrag zurueck.
1409 #* Input: Nummer des Eintrags
1411 #* Output: Format- String
1413 #************************************************************************/
1415 String SvxNumberFormatShell::GetFormat4Entry(short nEntry)
1417 if(nEntry < 0)
1418 return String();
1420 if( !aCurrencyFormatList.empty() )
1422 if( aCurrencyFormatList.size() > static_cast<size_t>(nEntry) )
1423 return *aCurrencyFormatList[nEntry];
1425 else
1427 sal_uInt32 nMyNfEntry=aCurEntryList[nEntry];
1428 const SvNumberformat *pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1430 if(pNumEntry!=NULL)
1431 return pNumEntry->GetFormatstring();
1433 return String();
1436 /*************************************************************************
1437 #* Member: GetListPos4Entry Datum:31.10.97
1438 #*------------------------------------------------------------------------
1440 #* Klasse: SvxNumberFormatShell
1442 #* Funktion: Liefert die Listen- Nummer fuer einen gegebenen
1443 #* Formatindex zurueck.
1445 #* Input: Nummer des Eintrags
1447 #* Output: Kategorie- Nummer
1449 #************************************************************************/
1451 short SvxNumberFormatShell::GetListPos4Entry(sal_uInt32 nIdx)
1453 short nSelP=SELPOS_NONE;
1455 // Check list size against return type limit.
1456 if( aCurEntryList.size() <= static_cast<size_t>(::std::numeric_limits< short >::max()) )
1458 for(size_t i=0; i < aCurEntryList.size(); ++i)
1460 if(aCurEntryList[i]==nIdx)
1462 nSelP=i;
1463 break;
1467 else
1469 OSL_FAIL("svx::SvxNumberFormatShell::GetListPos4Entry(), list got too large!" );
1471 return nSelP;
1474 short SvxNumberFormatShell::GetListPos4Entry( const String& rFmtString )
1476 sal_uInt32 nAt=0;
1477 short nSelP=SELPOS_NONE;
1478 if(FindEntry(rFmtString, &nAt))
1480 if(NUMBERFORMAT_ENTRY_NOT_FOUND!=nAt && NUMBERFORMAT_ENTRY_NEW_CURRENCY!=nAt)
1482 nSelP=GetListPos4Entry(nAt);
1484 else
1486 for( size_t i=0; i<aCurrencyFormatList.size(); i++ )
1488 if (rFmtString==*aCurrencyFormatList[i])
1490 nSelP = static_cast<short>(i);
1491 break;
1496 return nSelP;
1499 String SvxNumberFormatShell::GetStandardName() const
1501 return pFormatter->GetStandardName( eCurLanguage);
1504 void SvxNumberFormatShell::GetCurrencySymbols(std::vector<OUString>& rList, sal_uInt16* pPos)
1506 const NfCurrencyEntry* pTmpCurrencyEntry=SvNumberFormatter::MatchSystemCurrency();
1508 bool bFlag=(pTmpCurrencyEntry==NULL);
1510 GetCurrencySymbols(rList, bFlag);
1512 if(pPos!=NULL)
1514 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1515 sal_uInt16 nTableCount=rCurrencyTable.size();
1517 *pPos=0;
1518 size_t nCount=aCurCurrencyList.size();
1520 if(bFlag)
1522 *pPos=1;
1523 nCurCurrencyEntryPos=1;
1525 else
1527 for(size_t i=1;i<nCount;i++)
1529 const sal_uInt16 j = aCurCurrencyList[i];
1530 if (j != (sal_uInt16)-1 && j < nTableCount &&
1531 pTmpCurrencyEntry == &rCurrencyTable[j])
1533 *pPos=static_cast<sal_uInt16>(i);
1534 nCurCurrencyEntryPos=static_cast<sal_uInt16>(i);
1535 break;
1543 void SvxNumberFormatShell::GetCurrencySymbols(std::vector<OUString>& rList, bool bFlag)
1545 aCurCurrencyList.clear();
1547 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1548 sal_uInt16 nCount=rCurrencyTable.size();
1550 SvtLanguageTable* pLanguageTable=new SvtLanguageTable;
1552 sal_uInt16 nStart=1;
1554 XubString aString( ApplyLreOrRleEmbedding( rCurrencyTable[0].GetSymbol()));
1555 aString += sal_Unicode(' ');
1556 aString += ApplyLreOrRleEmbedding( pLanguageTable->GetString( rCurrencyTable[0].GetLanguage()));
1558 rList.push_back(aString);
1559 sal_uInt16 nAuto=(sal_uInt16)-1;
1560 aCurCurrencyList.push_back(nAuto);
1562 if(bFlag)
1564 rList.push_back(aString);
1565 aCurCurrencyList.push_back(0);
1566 ++nStart;
1569 CollatorWrapper aCollator( ::comphelper::getProcessComponentContext());
1570 aCollator.loadDefaultCollator( Application::GetSettings().GetLanguageTag().getLocale(), 0);
1572 const String aTwoSpace( RTL_CONSTASCII_USTRINGPARAM( " "));
1574 for(sal_uInt16 i = 1; i < nCount; ++i)
1576 XubString aStr( ApplyLreOrRleEmbedding( rCurrencyTable[i].GetBankSymbol()));
1577 aStr += aTwoSpace;
1578 aStr += ApplyLreOrRleEmbedding( rCurrencyTable[i].GetSymbol());
1579 aStr += aTwoSpace;
1580 aStr += ApplyLreOrRleEmbedding( pLanguageTable->GetString( rCurrencyTable[i].GetLanguage()));
1582 sal_uInt16 j = nStart;
1583 for(; j < rList.size(); ++j)
1584 if (aCollator.compareString(aStr, rList[j]) < 0)
1585 break; // insert before first greater than
1587 rList.insert(rList.begin() + j, aStr);
1588 aCurCurrencyList.insert(aCurCurrencyList.begin() + j, i);
1591 // Append ISO codes to symbol list.
1592 // XXX If this is to be changed, various other places would had to be
1593 // adapted that assume this order!
1594 sal_uInt16 nCont = rList.size();
1596 for(sal_uInt16 i = 1; i < nCount; ++i)
1598 bool bInsert = true;
1599 OUString aStr(ApplyLreOrRleEmbedding(rCurrencyTable[i].GetBankSymbol()));
1601 sal_uInt16 j = nCont;
1602 for(; j < rList.size() && bInsert; ++j)
1604 if(rList[j] == aStr)
1605 bInsert = false;
1606 else if (aCollator.compareString(aStr, rList[j]) < 0)
1607 break; // insert before first greater than
1609 if(bInsert)
1611 rList.insert(rList.begin() + j, aStr);
1612 aCurCurrencyList.insert(aCurCurrencyList.begin()+j, i);
1616 delete pLanguageTable;
1619 void SvxNumberFormatShell::SetCurrencySymbol(sal_uInt16 nPos)
1621 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1622 sal_uInt16 nCount=rCurrencyTable.size();
1624 bBankingSymbol=(nPos>=nCount);
1626 if(nPos<aCurCurrencyList.size())
1628 sal_uInt16 nCurrencyPos=aCurCurrencyList[nPos];
1629 if(nCurrencyPos!=(sal_uInt16)-1)
1631 pCurCurrencyEntry=(NfCurrencyEntry*)&rCurrencyTable[nCurrencyPos];
1632 nCurCurrencyEntryPos=nPos;
1634 else
1636 pCurCurrencyEntry=NULL;
1637 nCurCurrencyEntryPos=0;
1638 nCurFormatKey=pFormatter->GetFormatIndex(
1639 NF_CURRENCY_1000DEC2_RED, eCurLanguage);
1644 sal_uInt32 SvxNumberFormatShell::GetCurrencySymbol()
1646 return nCurCurrencyEntryPos;
1649 void SvxNumberFormatShell::SetCurCurrencyEntry(NfCurrencyEntry* pCEntry)
1651 pCurCurrencyEntry=pCEntry;
1654 bool SvxNumberFormatShell::IsTmpCurrencyFormat( const String& rFmtString )
1656 sal_uInt32 nFound;
1657 FindEntry(rFmtString, &nFound);
1659 if(nFound==NUMBERFORMAT_ENTRY_NEW_CURRENCY)
1661 return true;
1663 return false;
1666 sal_uInt16 SvxNumberFormatShell::FindCurrencyFormat( const String& rFmtString )
1668 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1669 sal_uInt16 nCount=rCurrencyTable.size();
1671 bool bTestBanking=false;
1673 sal_uInt16 nPos=FindCurrencyTableEntry(rFmtString, bTestBanking);
1675 if(nPos!=(sal_uInt16)-1)
1677 sal_uInt16 nStart=0;
1678 if(bTestBanking && aCurCurrencyList.size()>nPos)
1680 nStart=nCount;
1682 for(sal_uInt16 j=nStart;j<aCurCurrencyList.size();j++)
1684 if(aCurCurrencyList[j]==nPos) return j;
1687 return (sal_uInt16) -1;
1690 sal_uInt16 SvxNumberFormatShell::FindCurrencyTableEntry( const String& rFmtString, bool &bTestBanking )
1692 sal_uInt16 nPos=(sal_uInt16) -1;
1694 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1695 sal_uInt16 nCount=rCurrencyTable.size();
1697 const SvNumberformat* pFormat;
1698 OUString aSymbol, aExtension;
1699 sal_uInt32 nFound = pFormatter->TestNewString( rFmtString, eCurLanguage );
1700 if ( nFound != NUMBERFORMAT_ENTRY_NOT_FOUND &&
1701 ((pFormat = pFormatter->GetEntry( nFound )) != 0) &&
1702 pFormat->GetNewCurrencySymbol( aSymbol, aExtension ) )
1703 { // eventually match with format locale
1704 const NfCurrencyEntry* pTmpCurrencyEntry =
1705 SvNumberFormatter::GetCurrencyEntry( bTestBanking, aSymbol, aExtension,
1706 pFormat->GetLanguage() );
1707 if ( pTmpCurrencyEntry )
1709 for(sal_uInt16 i=0;i<nCount;i++)
1711 if(pTmpCurrencyEntry==&rCurrencyTable[i])
1713 nPos=i;
1714 break;
1719 else
1720 { // search symbol string only
1721 for(sal_uInt16 i=0;i<nCount;i++)
1723 const NfCurrencyEntry* pTmpCurrencyEntry=&rCurrencyTable[i];
1724 OUString _aSymbol = pTmpCurrencyEntry->BuildSymbolString(false);
1725 OUString aBankSymbol = pTmpCurrencyEntry->BuildSymbolString(true);
1727 if(rFmtString.Search(_aSymbol)!=STRING_NOTFOUND)
1729 bTestBanking=false;
1730 nPos=i;
1731 break;
1733 else if(rFmtString.Search(aBankSymbol)!=STRING_NOTFOUND)
1735 bTestBanking=true;
1736 nPos=i;
1737 break;
1742 return nPos;
1745 sal_uInt16 SvxNumberFormatShell::FindCurrencyFormat(const NfCurrencyEntry* pTmpCurrencyEntry,bool bTmpBanking)
1747 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1748 sal_uInt16 nCount=rCurrencyTable.size();
1750 sal_uInt16 nPos=0;
1751 for(sal_uInt16 i=0;i<nCount;i++)
1753 if(pTmpCurrencyEntry==&rCurrencyTable[i])
1755 nPos=i;
1756 break;
1760 sal_uInt16 nStart=0;
1761 if(bTmpBanking && aCurCurrencyList.size()>nPos)
1763 nStart=nCount;
1765 for(sal_uInt16 j=nStart;j<aCurCurrencyList.size();j++)
1767 if(aCurCurrencyList[j]==nPos) return j;
1769 return (sal_uInt16) -1;
1772 bool SvxNumberFormatShell::IsInTable(sal_uInt16 const nPos,
1773 bool const bTmpBanking, OUString const& rFmtString)
1775 bool bFlag=false;
1777 if(nPos!=(sal_uInt16)-1)
1779 const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1780 sal_uInt16 nCount=rCurrencyTable.size();
1782 if(nPos<nCount)
1784 NfWSStringsDtor aWSStringsDtor;
1786 const NfCurrencyEntry* pTmpCurrencyEntry=&rCurrencyTable[nPos];
1788 if ( pTmpCurrencyEntry!=NULL)
1790 pFormatter->GetCurrencyFormatStrings( aWSStringsDtor,
1791 *pTmpCurrencyEntry, bTmpBanking );
1793 for(sal_uInt16 i=0;i<aWSStringsDtor.size();i++)
1795 if (aWSStringsDtor[i] == rFmtString)
1797 bFlag=true;
1798 break;
1805 return bFlag;
1808 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */