1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
,
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
;
83 case SVX_VALUE_TYPE_STRING
:
86 case SVX_VALUE_TYPE_NUMBER
:
87 case SVX_VALUE_TYPE_UNDEFINED
:
93 // -----------------------------------------------------------------------
95 SvxNumberFormatShell::SvxNumberFormatShell( SvNumberFormatter
* pNumFormatter
,
96 sal_uInt32 nFormatKey
,
97 SvxNumberValueType eNumValType
,
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
118 case SVX_VALUE_TYPE_NUMBER
:
121 case SVX_VALUE_TYPE_STRING
:
122 case SVX_VALUE_TYPE_UNDEFINED
:
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.
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
)
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
)
176 // -----------------------------------------------------------------------
178 void SvxNumberFormatShell::CategoryChanged( sal_uInt16 nCatLbPos
,
180 std::vector
<String
*>& rFmtEntries
)
182 short nOldCategory
= nCurCategory
;
183 PosToCategory_Impl( nCatLbPos
, nCurCategory
);
184 pCurFmtTable
= &( pFormatter
->GetEntryTable( nCurCategory
,
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
,
197 std::vector
<String
*>& rFmtEntries
)
199 eCurLanguage
= eLangType
;
200 pCurFmtTable
= &(pFormatter
->ChangeCL( nCurCategory
,
203 rFmtSelPos
= FillEntryList_Impl( rFmtEntries
);
206 // -----------------------------------------------------------------------
208 void SvxNumberFormatShell::FormatChanged( sal_uInt16 nFmtLbPos
,
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
);
249 OSL_FAIL( "Doppeltes Format!" );
254 OUString
sTemp(rFormat
);
256 bInserted
= pFormatter
->PutEntry( sTemp
, nPos
,
257 nCurCategory
, nAddKey
,
259 rErrPos
= (nPos
>= 0) ? (xub_StrLen
)nPos
: 0xFFFF;
264 // May be sorted under a different locale if LCID was parsed.
265 const SvNumberformat
* pEntry
= pFormatter
->GetEntry( nAddKey
);
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
,
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?
304 // -----------------------------------------------------------------------
306 bool SvxNumberFormatShell::RemoveFormat( const String
& rFormat
,
307 sal_uInt16
& rCatLbSelPos
,
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
,
331 nCurFormatKey
=pFormatter
->GetStandardFormat(nCurCategory
,
334 CategoryToPos_Impl( nCurCategory
, rCatLbSelPos
);
335 rFmtSelPos
= FillEntryList_Impl( rFmtEntries
);
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;
358 AddFormat( *aCurrencyFormatList
[nCurrencyPos
],rErrPos
,rCatLbSelPos
,
359 rFmtSelPos
,aFmtEList
);
364 rFormat
= pFormatter
->GenerateFormat(nCurFormatKey
,
367 nPrecision
, nLeadingZeroes
);
369 for ( std::vector
<String
*>::const_iterator
it(aFmtEList
.begin()); it
!= aFmtEList
.end(); ++it
)
374 rFormat
= pFormatter
->GenerateFormat(nCurFormatKey
,
377 nPrecision
, nLeadingZeroes
);
381 // -----------------------------------------------------------------------
383 void SvxNumberFormatShell::GetOptions( const String
& rFormat
,
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
,
399 rPrecision
, rLeadingZeroes
);
401 CategoryToPos_Impl( pFormatter
->GetType( nFmtKey
), rCatLbPos
);
404 rCatLbPos
= CAT_USERDEFINED
;
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
;
418 rCatLbPos
= CAT_USERDEFINED
;
423 // -----------------------------------------------------------------------
425 void SvxNumberFormatShell::MakePreviewString( const String
& rFormatStr
,
427 Color
*& rpFontColor
)
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
;
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
) ) );
450 OUString
sTempIn(aValStr
);
451 OUString
sTempOut(rPreviewStr
);
452 pFormatter
->GetOutputString( sTempIn
, nExistingFormat
,
453 sTempOut
, &rpFontColor
);
455 rPreviewStr
= sTempOut
;
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
);
472 if ( nFound
!= NUMBERFORMAT_ENTRY_NOT_FOUND
)
474 bFlag
=pFormatter
->IsUserDefined( rFmtString
, eCurLanguage
);
478 const SvNumberformat
* pNumEntry
= pFormatter
->GetEntry(nFound
);
480 if(pNumEntry
!=NULL
&& pNumEntry
->HasNewCurrency())
483 sal_uInt16 nPos
=FindCurrencyTableEntry(rFmtString
,bTestBanking
);
484 bFlag
=!IsInTable(nPos
,bTestBanking
,rFmtString
);
491 // -----------------------------------------------------------------------
493 bool SvxNumberFormatShell::FindEntry( const String
& rFmtString
, sal_uInt32
* pAt
/* = NULL */ )
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
;
511 bRes
=!IsRemoved_Impl( nFound
);
521 // -----------------------------------------------------------------------
523 void SvxNumberFormatShell::GetInitSettings( sal_uInt16
& nCatLbPos
,
524 LanguageType
& rLangType
,
525 sal_uInt16
& nFmtLbSelPos
,
526 std::vector
<String
*>& rFmtEntries
,
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
542 nCurCategory
= NUMBERFORMAT_UNDEFINED
; // Kategorie = Undefiniert
544 pCurFmtTable
= &(pFormatter
->GetFirstEntryTable( nCurCategory
,
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.
571 sal_uInt16 nPrivCat
= CAT_CURRENCY
;
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
);
590 CategoryToPos_Impl(nCurCategory
, nPrivCat
);
591 FillEListWithStd_Impl(rList
,nPrivCat
,nSelPos
);
594 if( nPrivCat
!=CAT_CURRENCY
)
595 nSelPos
=FillEListWithUsD_Impl(rList
,nPrivCat
,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
)
613 aCurrencyFormatList
.clear();
615 if(nPrivCat
==CAT_CURRENCY
)
617 nSelPos
=FillEListWithCurrency_Impl(rList
,nSelPos
);
621 NfIndexTableOffset eOffsetStart
;
622 NfIndexTableOffset eOffsetEnd
;
626 case CAT_NUMBER
:eOffsetStart
=NF_NUMBER_START
;
627 eOffsetEnd
=NF_NUMBER_END
;
629 case CAT_PERCENT
:eOffsetStart
=NF_PERCENT_START
;
630 eOffsetEnd
=NF_PERCENT_END
;
632 case CAT_CURRENCY
:eOffsetStart
=NF_CURRENCY_START
;
633 eOffsetEnd
=NF_CURRENCY_END
;
635 case CAT_DATE
:eOffsetStart
=NF_DATE_START
;
636 eOffsetEnd
=NF_DATE_END
;
638 case CAT_TIME
:eOffsetStart
=NF_TIME_START
;
639 eOffsetEnd
=NF_TIME_END
;
641 case CAT_SCIENTIFIC
:eOffsetStart
=NF_SCIENTIFIC_START
;
642 eOffsetEnd
=NF_SCIENTIFIC_END
;
644 case CAT_FRACTION
:eOffsetStart
=NF_FRACTION_START
;
645 eOffsetEnd
=NF_FRACTION_END
;
647 case CAT_BOOLEAN
:eOffsetStart
=NF_BOOLEAN
;
648 eOffsetEnd
=NF_BOOLEAN
;
650 case CAT_TEXT
:eOffsetStart
=NF_TEXT
;
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
,
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.
678 DBG_ASSERT( pCurFmtTable
!= NULL
, "Unbekanntes Zahlenformat!" );
680 const SvNumberformat
* pNumEntry
= pCurFmtTable
->empty() ? 0 : pCurFmtTable
->begin()->second
;
683 String aNewFormNInfo
;
685 short nMyCat
= SELPOS_NONE
;
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
);
716 short SvxNumberFormatShell::FillEListWithDateTime_Impl( std::vector
<String
*>& rList
,
721 DBG_ASSERT( pCurFmtTable
!= NULL
, "Unbekanntes Zahlenformat!" );
723 const SvNumberformat
* pNumEntry
= pCurFmtTable
->empty() ? 0 : pCurFmtTable
->begin()->second
;
726 String aNewFormNInfo
;
728 short nMyCat
= SELPOS_NONE
;
732 for(nIndex
=NF_DATETIME_START
;nIndex
<=NF_DATETIME_END
;nIndex
++)
734 nNFEntry
=pFormatter
->GetFormatIndex((NfIndexTableOffset
)nIndex
,eCurLanguage
);
736 pNumEntry
= pFormatter
->GetEntry(nNFEntry
);
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
);
759 short SvxNumberFormatShell::FillEListWithCurrency_Impl( std::vector
<String
*>& rList
,
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
;
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
);
786 nSelPos
=FillEListWithUserCurrencys(rList
,nSelPos
);
793 short SvxNumberFormatShell::FillEListWithSysCurrencys( std::vector
<String
*>& rList
,
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.
803 DBG_ASSERT( pCurFmtTable
!= NULL
, "Unbekanntes Zahlenformat!" );
805 const SvNumberformat
* pNumEntry
= pCurFmtTable
->empty() ? 0 : pCurFmtTable
->begin()->second
;
808 String aNewFormNInfo
;
810 nCurCurrencyEntryPos
=0;
812 short nMyCat
= SELPOS_NONE
;
814 NfIndexTableOffset eOffsetStart
=NF_CURRENCY_START
;
815 NfIndexTableOffset eOffsetEnd
=NF_CURRENCY_END
;
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
;
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
);
886 short SvxNumberFormatShell::FillEListWithUserCurrencys( std::vector
<String
*>& rList
,
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.
896 DBG_ASSERT( pCurFmtTable
!= NULL
, "Unbekanntes Zahlenformat!" );
899 String aNewFormNInfo
;
900 short nMyCat
= SELPOS_NONE
;
902 const NfCurrencyEntry
* pTmpCurrencyEntry
;
903 bool bTmpBanking
, bAdaptSelPos
;
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.
922 pCurCurrencyEntry
=(NfCurrencyEntry
*)pTmpCurrencyEntry
;
923 bBankingSymbol
=bTmpBanking
;
924 nCurCurrencyEntryPos
=FindCurrencyFormat(pTmpCurrencyEntry
,bTmpBanking
);
928 if (pTmpCurrencyEntry
== pCurCurrencyEntry
)
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
) )
971 else if(aNewFormNInfo
.Search(rShortSymbol
)!=STRING_NOTFOUND
)
973 XubString rTstSymbol
;
974 const NfCurrencyEntry
* pTstCurrencyEntry
;
977 pFormatter
->GetNewCurrencySymbolString(nKey
,rTstSymbol
,
978 &pTstCurrencyEntry
,&bTstBanking
);
980 if(pTmpCurrencyEntry
==pTstCurrencyEntry
&& bTstBanking
==bTmpBanking
)
989 aList
.push_back( new String(aNewFormNInfo
) );
990 aKeyList
.push_back( nKey
);
997 NfWSStringsDtor aWSStringsDtor
;
999 if ( pTmpCurrencyEntry
&& nCurCategory
!= NUMBERFORMAT_ALL
)
1001 nDefault
= pFormatter
->GetCurrencyFormatStrings(
1002 aWSStringsDtor
, *pTmpCurrencyEntry
, bTmpBanking
);
1004 pFormatter
->GetCurrencyFormatStrings(
1005 aWSStringsDtor
, *pTmpCurrencyEntry
, true );
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
)
1029 String
aInsStr(aWSStringsDtor
[i
]);
1031 for( j
=0; j
< aList
.size(); ++j
)
1033 const String
* pTestStr
=aList
[j
];
1035 if(*pTestStr
==aInsStr
)
1043 rList
.push_back( new String(aInsStr
) );
1044 aCurEntryList
.insert( aCurEntryList
.begin() + (nPos
++), NUMBERFORMAT_ENTRY_NOT_FOUND
);
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
)
1072 if ( nSelPos
== SELPOS_NONE
&& nCurCategory
!= NUMBERFORMAT_ALL
)
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.
1089 DBG_ASSERT( pCurFmtTable
!= NULL
, "Unbekanntes Zahlenformat!" );
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();
1115 if(pNumEntry
->HasNewCurrency())
1118 sal_uInt16 nPos
=FindCurrencyTableEntry(aNewFormNInfo
,bTestBanking
);
1119 bFlag
=!IsInTable(nPos
,bTestBanking
,aNewFormNInfo
);
1123 String
*const pStr
= new String(aNewFormNInfo
);
1125 if ( nKey
== nCurFormatKey
) nSelPos
= aCurEntryList
.size();
1126 rList
.push_back( pStr
);
1127 aCurEntryList
.push_back( nKey
);
1137 // -----------------------------------------------------------------------
1139 void SvxNumberFormatShell::GetPreviewString_Impl( String
& rString
, Color
*& rpColor
)
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
) ) );
1149 OUString
sTempIn(aValStr
);
1150 OUString
sTempOut(rString
);
1151 pFormatter
->GetOutputString( sTempIn
, nCurFormatKey
, sTempOut
, &rpColor
);
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)
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;
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
,
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
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
1297 #* Input: Nummer des Eintrags
1299 #* Output: Kommentar-String
1301 #************************************************************************/
1303 String
SvxNumberFormatShell::GetComment4Entry(short nEntry
)
1308 if( static_cast<size_t>(nEntry
) < aCurEntryList
.size())
1310 sal_uInt32 nMyNfEntry
=aCurEntryList
[nEntry
];
1311 const SvNumberformat
*pNumEntry
= pFormatter
->GetEntry(nMyNfEntry
);
1313 return pNumEntry
->GetComment();
1319 /*************************************************************************
1320 #* Member: GetCategory4Entry Datum:30.10.97
1321 #*------------------------------------------------------------------------
1323 #* Klasse: SvxNumberFormatShell
1325 #* Funktion: Liefert die Kategorie- Nummer fuer einen gegebenen
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
;
1348 nMyCat
=pNumEntry
->GetType() & ~NUMBERFORMAT_DEFINED
;
1349 CategoryToPos_Impl(nMyCat
,nMyType
);
1351 return (short) nMyType
;
1355 else if( !aCurrencyFormatList
.empty() )
1357 return CAT_CURRENCY
;
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
);
1390 if((pNumEntry
->GetType() & NUMBERFORMAT_DEFINED
)>0)
1400 /*************************************************************************
1401 #* Member: GetFormat4Entry Datum:30.10.97
1402 #*------------------------------------------------------------------------
1404 #* Klasse: SvxNumberFormatShell
1406 #* Funktion: Liefert den Format- String fuer einen gegebenen
1409 #* Input: Nummer des Eintrags
1411 #* Output: Format- String
1413 #************************************************************************/
1415 String
SvxNumberFormatShell::GetFormat4Entry(short nEntry
)
1420 if( !aCurrencyFormatList
.empty() )
1422 if( aCurrencyFormatList
.size() > static_cast<size_t>(nEntry
) )
1423 return *aCurrencyFormatList
[nEntry
];
1427 sal_uInt32 nMyNfEntry
=aCurEntryList
[nEntry
];
1428 const SvNumberformat
*pNumEntry
= pFormatter
->GetEntry(nMyNfEntry
);
1431 return pNumEntry
->GetFormatstring();
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
)
1469 OSL_FAIL("svx::SvxNumberFormatShell::GetListPos4Entry(), list got too large!" );
1474 short SvxNumberFormatShell::GetListPos4Entry( const String
& rFmtString
)
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
);
1486 for( size_t i
=0; i
<aCurrencyFormatList
.size(); i
++ )
1488 if (rFmtString
==*aCurrencyFormatList
[i
])
1490 nSelP
= static_cast<short>(i
);
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
);
1514 const NfCurrencyTable
& rCurrencyTable
=SvNumberFormatter::GetTheCurrencyTable();
1515 sal_uInt16 nTableCount
=rCurrencyTable
.size();
1518 size_t nCount
=aCurCurrencyList
.size();
1523 nCurCurrencyEntryPos
=1;
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
);
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
);
1564 rList
.push_back(aString
);
1565 aCurCurrencyList
.push_back(0);
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()));
1578 aStr
+= ApplyLreOrRleEmbedding( rCurrencyTable
[i
].GetSymbol());
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
)
1606 else if (aCollator
.compareString(aStr
, rList
[j
]) < 0)
1607 break; // insert before first greater than
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
;
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
)
1657 FindEntry(rFmtString
, &nFound
);
1659 if(nFound
==NUMBERFORMAT_ENTRY_NEW_CURRENCY
)
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
)
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
])
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
)
1733 else if(rFmtString
.Search(aBankSymbol
)!=STRING_NOTFOUND
)
1745 sal_uInt16
SvxNumberFormatShell::FindCurrencyFormat(const NfCurrencyEntry
* pTmpCurrencyEntry
,bool bTmpBanking
)
1747 const NfCurrencyTable
& rCurrencyTable
=SvNumberFormatter::GetTheCurrencyTable();
1748 sal_uInt16 nCount
=rCurrencyTable
.size();
1751 for(sal_uInt16 i
=0;i
<nCount
;i
++)
1753 if(pTmpCurrencyEntry
==&rCurrencyTable
[i
])
1760 sal_uInt16 nStart
=0;
1761 if(bTmpBanking
&& aCurCurrencyList
.size()>nPos
)
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
)
1777 if(nPos
!=(sal_uInt16
)-1)
1779 const NfCurrencyTable
& rCurrencyTable
=SvNumberFormatter::GetTheCurrencyTable();
1780 sal_uInt16 nCount
=rCurrencyTable
.size();
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
)
1808 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */