xref: /trunk/main/svx/source/items/numfmtsh.cxx (revision f6e50924)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 // include ---------------------------------------------------------------
28 #include <tools/color.hxx>
29 
30 #define _SVX_NUMFMTSH_CXX
31 #define _SVSTDARR_STRINGSDTOR
32 #include <tools/debug.hxx>
33 #include <i18npool/mslangid.hxx>
34 
35 #define _ZFORLIST_DECLARE_TABLE
36 #include <svl/zforlist.hxx>
37 #include <svl/zformat.hxx>
38 
39 #include <svtools/langtab.hxx>
40 #include <vcl/svapp.hxx>
41 #include <comphelper/processfactory.hxx>
42 
43 #include <svx/numfmtsh.hxx>
44 // class SvxNumberFormatShell --------------------------------------------
45 
46 const double SvxNumberFormatShell::DEFAULT_NUMVALUE = 1234.56789;
47 
48 SV_IMPL_PTRARR( NfShCurrencyEntries, NfCurrencyEntry* );
49 
50 // -----------------------------------------------------------------------
51 
52 
53 
Create(SvNumberFormatter * pNumFormatter,sal_uInt32 nFormatKey,SvxNumberValueType eNumValType,const String & rNumStr)54 SvxNumberFormatShell* SvxNumberFormatShell::Create( SvNumberFormatter* pNumFormatter,
55 											  sal_uInt32              nFormatKey,
56 											  SvxNumberValueType eNumValType,
57 											  const String&		 rNumStr )
58 {
59 	return new SvxNumberFormatShell(pNumFormatter,nFormatKey,
60 									eNumValType,rNumStr );
61 }
62 
Create(SvNumberFormatter * pNumFormatter,sal_uInt32 nFormatKey,SvxNumberValueType eNumValType,double nNumVal,const String * pNumStr)63 SvxNumberFormatShell* SvxNumberFormatShell::Create( SvNumberFormatter* pNumFormatter,
64 											  sal_uInt32				 nFormatKey,
65 											  SvxNumberValueType eNumValType,
66 											  double			 nNumVal,
67 											  const String*		 pNumStr )
68 {
69 	return new SvxNumberFormatShell(pNumFormatter,nFormatKey,
70 									eNumValType,nNumVal,pNumStr );
71 }
72 
73 // -----------------------------------------------------------------------
74 
75 #define _INIT \
76 	pFormatter		( pNumFormatter ), 	\
77 	pCurFmtTable	( NULL ), 			\
78     eValType        ( eNumValType ),    \
79     bUndoAddList    ( sal_True ),       \
80     nInitFormatKey  ( nFormatKey ),     \
81     nCurFormatKey   ( nFormatKey ),     \
82     pCurCurrencyEntry(NULL),            \
83 	bBankingSymbol	(sal_False),			\
84     nCurCurrencyEntryPos((sal_uInt16) SELPOS_NONE)
85 
86 // -----------------------------------------------------------------------
87 
SvxNumberFormatShell(SvNumberFormatter * pNumFormatter,sal_uInt32 nFormatKey,SvxNumberValueType eNumValType,const String & rNumStr)88 SvxNumberFormatShell::SvxNumberFormatShell(	SvNumberFormatter*	pNumFormatter,
89 											sal_uInt32				nFormatKey,
90 											SvxNumberValueType	eNumValType,
91 											const String&		rNumStr )
92 	:	_INIT
93 {
94 	nValNum = DEFAULT_NUMVALUE;
95 
96 	switch ( eValType )
97 	{
98 		case SVX_VALUE_TYPE_STRING:
99 			aValStr = rNumStr;
100 			break;
101 		case SVX_VALUE_TYPE_NUMBER:
102 		case SVX_VALUE_TYPE_UNDEFINED:
103 		default:
104 			aValStr.Erase();
105 	}
106 }
107 
108 // -----------------------------------------------------------------------
109 
110 SvxNumberFormatShell::SvxNumberFormatShell( SvNumberFormatter*	pNumFormatter,
111 											sal_uInt32				nFormatKey,
112 											SvxNumberValueType	eNumValType,
113 											double				nNumVal,
114 											const String*		pNumStr )
115 	:	_INIT
116 {
117 	//	#50441# When used in Writer, the SvxNumberInfoItem contains the
118 	//	original string in addition to the value
119 
120 	if ( pNumStr )
121 		aValStr = *pNumStr;
122 
123 	switch ( eValType )
124 	{
125 		case SVX_VALUE_TYPE_NUMBER:
126 			nValNum = nNumVal;
127 			break;
128 		case SVX_VALUE_TYPE_STRING:
129 		case SVX_VALUE_TYPE_UNDEFINED:
130 		default:
131 			nValNum = DEFAULT_NUMVALUE;
132 	}
133 }
134 
135 // -----------------------------------------------------------------------
136 
137 SvxNumberFormatShell::~SvxNumberFormatShell()
138 {
139 	/*
140 	 * An dieser Stelle wird abhaengig davon, ob die
141 	 * hinzugefuegten, benutzerdefinierten als gueltig
142 	 * erklaert wurden (ValidateNewEntries()), die
143 	 * Add-Liste wieder aus dem Zahlenformatierer entfernt.
144 	 *
145 	 * Loeschen von Formaten aus dem Formatierer passiert
146 	 * aus Undo-Gruenden nur in der aufrufenden Instanz.
147 	 */
148 
149 	if ( bUndoAddList )
150 	{
151 		// Hinzugefuegte Formate sind nicht gueltig:
152 		// => wieder entfernen:
153 
154 		for ( sal_uInt16 i = 0; i < aAddList.Count(); ++i )
155 			pFormatter->DeleteEntry( aAddList[i] );
156 	}
157 
158 	//--------------------------------
159 	// Add-/Remove-Listen leerraeumen:
160 	//--------------------------------
161 	aAddList.Remove( 0, aAddList.Count() );
162 	aDelList.Remove( 0, aAddList.Count() );
163 
164 	if(aCurrencyFormatList.Count()>0)
165 		aCurrencyFormatList.DeleteAndDestroy(0,aCurrencyFormatList.Count());
166 }
167 
168 // -----------------------------------------------------------------------
169 
GetUpdateDataCount() const170 sal_uInt32 SvxNumberFormatShell::GetUpdateDataCount() const
171 {
172 	return aDelList.Count();
173 }
174 
175 // -----------------------------------------------------------------------
176 
GetUpdateData(sal_uInt32 * pDelArray,const sal_uInt32 nSize)177 void SvxNumberFormatShell::GetUpdateData( sal_uInt32* pDelArray, const sal_uInt32 nSize )
178 {
179 	const sal_uInt32 nCount = aDelList.Count();
180 
181 	DBG_ASSERT( pDelArray && ( nSize == nCount ), "Array nicht initialisiert!" );
182 
183 	if ( pDelArray && ( nSize == nCount ) )
184 		for ( sal_uInt16 i = 0; i < aDelList.Count(); ++i )
185 			*pDelArray++ = aDelList[i];
186 }
187 
188 // -----------------------------------------------------------------------
189 
CategoryChanged(sal_uInt16 nCatLbPos,short & rFmtSelPos,SvStrings & rFmtEntries)190 void SvxNumberFormatShell::CategoryChanged( sal_uInt16     nCatLbPos,
191 											short&     rFmtSelPos,
192 											SvStrings& rFmtEntries )
193 {
194 	short nOldCategory = nCurCategory;
195 	PosToCategory_Impl( nCatLbPos, nCurCategory );
196 	pCurFmtTable = &( pFormatter->GetEntryTable( nCurCategory,
197 												 nCurFormatKey,
198 												 eCurLanguage ) );
199 	// reinitialize currency if category newly entered
200 	if ( nCurCategory == NUMBERFORMAT_CURRENCY && nOldCategory != nCurCategory )
201 		pCurCurrencyEntry = NULL;
202 	rFmtSelPos = FillEntryList_Impl( rFmtEntries );
203 }
204 
205 // -----------------------------------------------------------------------
206 
LanguageChanged(LanguageType eLangType,short & rFmtSelPos,SvStrings & rFmtEntries)207 void SvxNumberFormatShell::LanguageChanged( LanguageType eLangType,
208 											short&		 rFmtSelPos,
209 											SvStrings&   rFmtEntries )
210 {
211 	eCurLanguage = eLangType;
212 	pCurFmtTable = &(pFormatter->ChangeCL( nCurCategory,
213 										   nCurFormatKey,
214 										   eCurLanguage ) );
215 	rFmtSelPos = FillEntryList_Impl( rFmtEntries );
216 }
217 
218 // -----------------------------------------------------------------------
219 
FormatChanged(sal_uInt16 nFmtLbPos,String & rPreviewStr,Color * & rpFontColor)220 void SvxNumberFormatShell::FormatChanged( sal_uInt16  nFmtLbPos,
221 										  String& rPreviewStr,
222                                           Color*& rpFontColor )
223 {
224 	//nCurFormatKey = pCurFmtTable->GetKey( pCurFmtTable->GetObject( nFmtLbPos ) );
225 
226 	if(nFmtLbPos<aCurEntryList.Count())
227 	{
228 		nCurFormatKey=aCurEntryList[nFmtLbPos];
229 
230 		if(nCurFormatKey!=NUMBERFORMAT_ENTRY_NOT_FOUND)
231 		{
232             GetPreviewString_Impl( rPreviewStr, rpFontColor );
233 		}
234 		else if(nCurCategory==NUMBERFORMAT_CURRENCY)
235 		{
236 			if(nFmtLbPos<aCurrencyFormatList.Count())
237 			{
238 				//nCurFormatKey=nFmtLbPos;
239 				MakePrevStringFromVal(*aCurrencyFormatList[nFmtLbPos],
240                                     rPreviewStr,rpFontColor,nValNum);
241 			}
242 		}
243 	}
244 }
245 // -----------------------------------------------------------------------
246 
AddFormat(String & rFormat,xub_StrLen & rErrPos,sal_uInt16 & rCatLbSelPos,short & rFmtSelPos,SvStrings & rFmtEntries)247 sal_Bool SvxNumberFormatShell::AddFormat( String& rFormat,  xub_StrLen& rErrPos,
248 									  sal_uInt16& rCatLbSelPos, short& rFmtSelPos,
249 									  SvStrings& rFmtEntries )
250 {
251 	sal_Bool 	bInserted	= sal_False;
252 	sal_uInt32	nAddKey		= pFormatter->GetEntryKey( rFormat, eCurLanguage );
253 
254 	if ( nAddKey != NUMBERFORMAT_ENTRY_NOT_FOUND ) // bereits vorhanden?
255 	{
256 		if ( IsRemoved_Impl( nAddKey ) )
257 		{
258 			// Key suchen und loeschen
259 			sal_Bool	bFound	= sal_False;
260 			sal_uInt16	nAt		= 0;
261 
262 			for ( sal_uInt16 i = 0; !bFound && i < aDelList.Count(); ++i )
263 			{
264 				if ( aDelList[i] == nAddKey )
265 				{
266 					bFound	= sal_True;
267 					nAt		= i;
268 				}
269 			}
270 			DBG_ASSERT( bFound, "Key not found" );
271 			aDelList.Remove( nAt );
272 			bInserted = sal_True;
273 		}
274 		else
275 		{
276 			DBG_ERROR( "Doppeltes Format!" );
277 		}
278 	}
279 	else // neues Format
280 	{
281 		bInserted = pFormatter->PutEntry( rFormat, rErrPos,
282 										  nCurCategory, nAddKey,
283 										  eCurLanguage );
284 	}
285 
286 	if ( bInserted ) // eingefuegt
287 	{
288 		nCurFormatKey = nAddKey;
289 		DBG_ASSERT( !IsAdded_Impl( nCurFormatKey ), "Doppeltes Format!" );
290 		aAddList.Insert( nCurFormatKey, aAddList.Count() );
291 
292 		// aktuelle Tabelle holen
293 		pCurFmtTable = &(pFormatter->GetEntryTable( nCurCategory,
294 													nCurFormatKey,
295 													eCurLanguage ));
296 		nCurCategory=pFormatter->GetType(nAddKey); //@@ ???
297 		CategoryToPos_Impl( nCurCategory, rCatLbSelPos );
298 		rFmtSelPos = FillEntryList_Impl( rFmtEntries );
299 	}
300 	else if ( rErrPos != 0 ) // Syntaxfehler
301 	{
302 		;
303 	}
304 	else // Doppelt einfuegen nicht moeglich
305 	{
306 		DBG_ERROR( "Doppeltes Format!" ); // oder doch?
307 	}
308 
309 	return bInserted;
310 }
311 
312 // -----------------------------------------------------------------------
313 
RemoveFormat(const String & rFormat,sal_uInt16 & rCatLbSelPos,short & rFmtSelPos,SvStrings & rFmtEntries)314 sal_Bool SvxNumberFormatShell::RemoveFormat( const String& 	rFormat,
315 										 sal_uInt16&		rCatLbSelPos,
316 										 short&			rFmtSelPos,
317 										 SvStrings& 	rFmtEntries )
318 {
319 	sal_uInt32 nDelKey = pFormatter->GetEntryKey( rFormat, eCurLanguage );
320 
321 	DBG_ASSERT( nDelKey != NUMBERFORMAT_ENTRY_NOT_FOUND, "Eintrag nicht gefunden!" );
322 	DBG_ASSERT( !IsRemoved_Impl( nDelKey ), "Eintrag bereits geloescht!" );
323 
324 	if ( (nDelKey != NUMBERFORMAT_ENTRY_NOT_FOUND) && !IsRemoved_Impl( nDelKey ) )
325 	{
326 		aDelList.Insert( nDelKey, aDelList.Count() );
327 
328 		if ( IsAdded_Impl( nDelKey ) )
329 		{
330 			// Key suchen und loeschen
331 			sal_Bool	bFound	= sal_False;
332 			sal_uInt16	nAt		= 0;
333 
334 			for ( sal_uInt16 i = 0; !bFound && i < aAddList.Count(); ++i )
335 			{
336 				if ( aAddList[i] == nDelKey )
337 				{
338 					bFound	= sal_True;
339 					nAt		= i;
340 				}
341 			}
342 			DBG_ASSERT( bFound, "Key not found" );
343 			aAddList.Remove( nAt );
344 		}
345 
346 		nCurCategory=pFormatter->GetType(nDelKey); //@@ 01.10.97
347 		pCurFmtTable = &(pFormatter->GetEntryTable( nCurCategory,
348 													nCurFormatKey,
349 													eCurLanguage ));
350 
351 		nCurFormatKey=pFormatter->GetStandardFormat(nCurCategory,
352 											eCurLanguage );
353 
354 		CategoryToPos_Impl( nCurCategory, rCatLbSelPos );
355 		rFmtSelPos = FillEntryList_Impl( rFmtEntries );
356 		//rFmtSelPos = (short) nCurFormatKey; //@@ 01.10.97
357 	}
358 	return sal_True;
359 }
360 
361 // -----------------------------------------------------------------------
362 
MakeFormat(String & rFormat,sal_Bool bThousand,sal_Bool bNegRed,sal_uInt16 nPrecision,sal_uInt16 nLeadingZeroes,sal_uInt16 nCurrencyPos)363 void SvxNumberFormatShell::MakeFormat( String& rFormat,
364 									   sal_Bool bThousand, sal_Bool bNegRed,
365 									   sal_uInt16 nPrecision, sal_uInt16 nLeadingZeroes,
366 									   sal_uInt16 nCurrencyPos)
367 {
368 	if(aCurrencyFormatList.Count()>nCurrencyPos)
369 	{
370 		xub_StrLen rErrPos=0;
371 		sal_uInt16 rCatLbSelPos=0;
372 		short  rFmtSelPos=0;
373 		SvStrings aFmtEList;
374 
375 		sal_uInt32 nFound = pFormatter->TestNewString( *aCurrencyFormatList[nCurrencyPos], eCurLanguage );
376 
377 		if ( nFound == NUMBERFORMAT_ENTRY_NOT_FOUND )
378 		{
379 			AddFormat( *aCurrencyFormatList[nCurrencyPos],rErrPos,rCatLbSelPos,
380 					rFmtSelPos,aFmtEList);
381 		}
382 
383 		if(rErrPos==0)
384 		{
385 			pFormatter->GenerateFormat( rFormat, nCurFormatKey,
386 										eCurLanguage,
387 										bThousand, bNegRed,
388 										nPrecision, nLeadingZeroes );
389 		}
390 		aFmtEList.DeleteAndDestroy(0,aFmtEList.Count());
391 	}
392 	else
393 	{
394 		pFormatter->GenerateFormat( rFormat, nCurFormatKey,
395 									eCurLanguage,
396 									bThousand, bNegRed,
397 									nPrecision, nLeadingZeroes );
398 	}
399 }
400 
401 // -----------------------------------------------------------------------
402 
GetOptions(const String & rFormat,sal_Bool & rThousand,sal_Bool & rNegRed,sal_uInt16 & rPrecision,sal_uInt16 & rLeadingZeroes,sal_uInt16 & rCatLbPos)403 void SvxNumberFormatShell::GetOptions( const String&	rFormat,
404 									   sal_Bool&			rThousand,
405 									   sal_Bool&			rNegRed,
406 									   sal_uInt16&			rPrecision,
407 									   sal_uInt16&			rLeadingZeroes,
408 									   sal_uInt16&			rCatLbPos )
409 {
410 
411 	sal_uInt32 nFmtKey = pFormatter->GetEntryKey( rFormat, eCurLanguage );
412 
413 	if(nFmtKey != NUMBERFORMAT_ENTRY_NOT_FOUND)
414 	{
415 		if ( nFmtKey != NUMBERFORMAT_ENTRY_NOT_FOUND )
416 		{
417 			pFormatter->GetFormatSpecialInfo( nFmtKey,
418 											  rThousand, rNegRed,
419 											  rPrecision, rLeadingZeroes );
420 
421 			CategoryToPos_Impl( pFormatter->GetType( nFmtKey ), rCatLbPos );
422 		}
423 		else
424 			rCatLbPos = CAT_USERDEFINED;
425 	}
426 	else
427 	{
428 		sal_Bool bTestBanking=sal_False;
429 		sal_uInt16 nPos=FindCurrencyTableEntry(rFormat, bTestBanking );
430 
431 		if(IsInTable(nPos,bTestBanking,rFormat) &&
432 			pFormatter->GetFormatSpecialInfo( rFormat,rThousand, rNegRed,
433 								  rPrecision, rLeadingZeroes,eCurLanguage)==0)
434 		{
435 			rCatLbPos = CAT_CURRENCY;
436 		}
437 		else
438 			rCatLbPos = CAT_USERDEFINED;
439 	}
440 
441 }
442 
443 // -----------------------------------------------------------------------
444 
MakePreviewString(const String & rFormatStr,String & rPreviewStr,Color * & rpFontColor)445 void SvxNumberFormatShell::MakePreviewString( const String& rFormatStr,
446 											  String&       rPreviewStr,
447                                               Color*&       rpFontColor )
448 {
449     rpFontColor = NULL;
450 
451 	sal_uIntPtr nExistingFormat = pFormatter->GetEntryKey( rFormatStr, eCurLanguage );
452 	if ( nExistingFormat == NUMBERFORMAT_ENTRY_NOT_FOUND )
453 	{
454 		//	real preview - not implemented in NumberFormatter for text formats
455 
456 		pFormatter->GetPreviewString( rFormatStr, nValNum, rPreviewStr,
457                                       &rpFontColor, eCurLanguage );
458 	}
459 	else
460 	{
461 		//	format exists
462 
463 		//	#50441# if a string was set in addition to the value, use it for text formats
464 		sal_Bool bUseText = ( eValType == SVX_VALUE_TYPE_STRING ||
465 							( aValStr.Len() && ( pFormatter->GetType(nExistingFormat) & NUMBERFORMAT_TEXT ) ) );
466 		if ( bUseText )
467 			pFormatter->GetOutputString( aValStr, nExistingFormat,
468                                          rPreviewStr, &rpFontColor );
469 		else
470 			pFormatter->GetOutputString( nValNum, nExistingFormat,
471                                          rPreviewStr, &rpFontColor );
472 	}
473 }
474 
475 // -----------------------------------------------------------------------
476 
IsUserDefined(const String & rFmtString)477 sal_Bool SvxNumberFormatShell::IsUserDefined( const String& rFmtString )
478 {
479 	sal_uInt32 nFound = pFormatter->GetEntryKey( rFmtString, eCurLanguage );
480 
481 	sal_Bool bFlag=sal_False;
482 	if ( nFound != NUMBERFORMAT_ENTRY_NOT_FOUND )
483 	{
484 		bFlag=pFormatter->IsUserDefined( rFmtString, eCurLanguage );
485 
486 		if(bFlag)
487 		{
488 			const SvNumberformat* pNumEntry	= pFormatter->GetEntry(nFound);
489 
490 			if(pNumEntry!=NULL && pNumEntry->HasNewCurrency())
491 			{
492 				sal_Bool bTestBanking;
493 				sal_uInt16 nPos=FindCurrencyTableEntry(rFmtString,bTestBanking);
494 				bFlag=!IsInTable(nPos,bTestBanking,rFmtString);
495 			}
496 		}
497 	}
498 	return bFlag;
499 }
500 
501 // -----------------------------------------------------------------------
502 
FindEntry(const String & rFmtString,sal_uInt32 * pAt)503 sal_Bool SvxNumberFormatShell::FindEntry( const String& rFmtString, sal_uInt32* pAt /* = NULL */ )
504 {
505 	sal_Bool bRes=sal_False;
506 	sal_uInt32 nFound = pFormatter->TestNewString( rFmtString, eCurLanguage );
507 
508 	if ( nFound == NUMBERFORMAT_ENTRY_NOT_FOUND )
509 	{
510 		sal_Bool bTestBanking=sal_False;
511 		sal_uInt16 nPos=FindCurrencyTableEntry(rFmtString, bTestBanking );
512 
513 		if(IsInTable(nPos,bTestBanking,rFmtString))
514 		{
515 			nFound=NUMBERFORMAT_ENTRY_NEW_CURRENCY;
516 			bRes=sal_True;
517 		}
518 	}
519 	else
520 	{
521 		bRes=!IsRemoved_Impl( nFound );
522 	}
523 
524 	if ( pAt )
525 		*pAt = nFound;
526 
527 	return bRes;
528 }
529 
530 
531 // -----------------------------------------------------------------------
532 
GetInitSettings(sal_uInt16 & nCatLbPos,LanguageType & rLangType,sal_uInt16 & nFmtLbSelPos,SvStrings & rFmtEntries,String & rPrevString,Color * & rpPrevColor)533 void SvxNumberFormatShell::GetInitSettings(
534         sal_uInt16&     nCatLbPos,
535         LanguageType&   rLangType,
536         sal_uInt16&     nFmtLbSelPos,
537         SvStrings&      rFmtEntries,
538         String&         rPrevString,
539         Color*&         rpPrevColor )
540 {
541 	// -------------------------------------------------------------------
542 	// Vorbedingung: Zahlenformatierer gefunden
543 	DBG_ASSERT( pFormatter != NULL, "Zahlenformatierer nicht gefunden!" );
544 
545 //  sal_uInt16                  nCount      = 0;
546 	short					nSelPos		= SELPOS_NONE;
547 //  SvNumberFormatTable*    pFmtTable   = NULL;
548 
549 	// Sonderbehandlung fuer undefiniertes Zahlenformat:
550 	if ( (eValType == SVX_VALUE_TYPE_UNDEFINED) && (nCurFormatKey == 0) )
551 		PosToCategory_Impl( CAT_ALL, nCurCategory );		// Kategorie = Alle
552 	else
553 		nCurCategory = NUMBERFORMAT_UNDEFINED;		// Kategorie = Undefiniert
554 
555 	pCurFmtTable =	&(pFormatter->GetFirstEntryTable( nCurCategory,
556 													  nCurFormatKey,
557 													  eCurLanguage ));
558 
559 
560 
561 	CategoryToPos_Impl( nCurCategory, nCatLbPos );
562 	rLangType = eCurLanguage;
563 
564 	nSelPos = FillEntryList_Impl( rFmtEntries );
565 
566 	DBG_ASSERT( nSelPos != SELPOS_NONE, "Leere Formatliste!" );
567 
568 	nFmtLbSelPos = (nSelPos != SELPOS_NONE) ? (sal_uInt16)nSelPos : 0;
569     GetPreviewString_Impl( rPrevString, rpPrevColor );
570 }
571 
572 // -----------------------------------------------------------------------
573 
FillEntryList_Impl(SvStrings & rList)574 short SvxNumberFormatShell::FillEntryList_Impl( SvStrings& rList )
575 {
576 	/* Erstellen einer aktuellen Liste von Format-Eintraegen.
577 	 * Rueckgabewert ist die Listenposition des aktuellen Formates.
578 	 * Ist die Liste leer oder gibt es kein aktuelles Format,
579 	 * so wird SELPOS_NONE geliefert.
580 	 */
581 	short nSelPos=0;
582 	aCurEntryList.Remove(nSelPos,aCurEntryList.Count());
583 	sal_uInt16			nPrivCat = CAT_CURRENCY;
584 	nSelPos=SELPOS_NONE;
585 
586 	if(nCurCategory==NUMBERFORMAT_ALL)
587 	{
588 		FillEListWithStd_Impl(rList,CAT_NUMBER,nSelPos);
589 		FillEListWithStd_Impl(rList,CAT_PERCENT,nSelPos);
590 		FillEListWithStd_Impl(rList,CAT_CURRENCY,nSelPos);
591 		FillEListWithStd_Impl(rList,CAT_DATE,nSelPos);
592 		FillEListWithStd_Impl(rList,CAT_TIME,nSelPos);
593 		FillEListWithStd_Impl(rList,CAT_SCIENTIFIC,nSelPos);
594 		FillEListWithStd_Impl(rList,CAT_FRACTION,nSelPos);
595 		FillEListWithStd_Impl(rList,CAT_BOOLEAN,nSelPos);
596 		FillEListWithStd_Impl(rList,CAT_TEXT,nSelPos);
597 	}
598 	else
599 	{
600 		CategoryToPos_Impl(nCurCategory, nPrivCat);
601 		FillEListWithStd_Impl(rList,nPrivCat,nSelPos);
602 	}
603 
604 	if(	nPrivCat!=CAT_CURRENCY)
605 		nSelPos=FillEListWithUsD_Impl(rList,nPrivCat,nSelPos);
606 
607 	return nSelPos;
608 }
609 
FillEListWithStd_Impl(SvStrings & rList,sal_uInt16 nPrivCat,short & nSelPos)610 void SvxNumberFormatShell::FillEListWithStd_Impl( SvStrings& rList,sal_uInt16 nPrivCat,short &nSelPos )
611 {
612 	/* Erstellen einer aktuellen Liste von Format-Eintraegen.
613 	 * Rueckgabewert ist die Listenposition des aktuellen Formates.
614 	 * Ist die Liste leer oder gibt es kein aktuelles Format,
615 	 * so wird SELPOS_NONE geliefert.
616 	 */
617 	DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
618 
619 	if(aCurrencyFormatList.Count()>0)
620 		aCurrencyFormatList.DeleteAndDestroy(0,aCurrencyFormatList.Count());
621 
622 	if(nPrivCat==CAT_CURRENCY)
623 	{
624 		nSelPos=FillEListWithCurrency_Impl(rList,nSelPos);
625 	}
626 	else
627 	{
628 		NfIndexTableOffset eOffsetStart;
629 		NfIndexTableOffset eOffsetEnd;
630 
631 		switch(nPrivCat)
632 		{
633 			case CAT_NUMBER			:eOffsetStart=NF_NUMBER_START;
634 								 	eOffsetEnd=NF_NUMBER_END;
635 								 	break;
636 			case CAT_PERCENT		:eOffsetStart=NF_PERCENT_START;
637 								 	eOffsetEnd=NF_PERCENT_END;
638 								 	break;
639 			case CAT_CURRENCY		:eOffsetStart=NF_CURRENCY_START;
640 								 	eOffsetEnd=NF_CURRENCY_END;
641 								 	break;
642 			case CAT_DATE			:eOffsetStart=NF_DATE_START;
643 								 	eOffsetEnd=NF_DATE_END;
644 								 	break;
645 			case CAT_TIME			:eOffsetStart=NF_TIME_START;
646 								 	eOffsetEnd=NF_TIME_END;
647 								 	break;
648 			case CAT_SCIENTIFIC		:eOffsetStart=NF_SCIENTIFIC_START;
649 								 	eOffsetEnd=NF_SCIENTIFIC_END;
650 								 	break;
651 			case CAT_FRACTION		:eOffsetStart=NF_FRACTION_START;
652 								 	eOffsetEnd=NF_FRACTION_END;
653 								 	break;
654 			case CAT_BOOLEAN		:eOffsetStart=NF_BOOLEAN;
655 								 	eOffsetEnd=NF_BOOLEAN;
656 								 	break;
657 			case CAT_TEXT			:eOffsetStart=NF_TEXT;
658 								 	eOffsetEnd=NF_TEXT;
659 								 	break;
660 			default					:return;
661 		}
662 
663 		nSelPos=FillEListWithFormats_Impl(rList,nSelPos,eOffsetStart,eOffsetEnd);
664 
665 		if(nPrivCat==CAT_DATE || nPrivCat==CAT_TIME)
666 		{
667 			nSelPos=FillEListWithDateTime_Impl(rList,nSelPos);
668 			//if(nSelPos!=SELPOS_NONE) nSelPos=nTmpPos;
669 		}
670 	}
671 }
672 
FillEListWithFormats_Impl(SvStrings & rList,short nSelPos,NfIndexTableOffset eOffsetStart,NfIndexTableOffset eOffsetEnd)673 short SvxNumberFormatShell::FillEListWithFormats_Impl( SvStrings& rList,short nSelPos,
674 													   NfIndexTableOffset eOffsetStart,
675 													   NfIndexTableOffset eOffsetEnd)
676 {
677 	/* Erstellen einer aktuellen Liste von Format-Eintraegen.
678 	 * Rueckgabewert ist die Listenposition des aktuellen Formates.
679 	 * Ist die Liste leer oder gibt es kein aktuelles Format,
680 	 * so wird SELPOS_NONE geliefert.
681 	 */
682 	sal_uInt16	nMyType;
683 
684 	DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
685 
686 	const SvNumberformat*	pNumEntry	= pCurFmtTable->First();
687 //  sal_uInt16          nCount      = 0;
688 	sal_uInt32			nNFEntry;
689 	String			aStrComment;
690 	String			aNewFormNInfo;
691 	String			aPrevString;
692 	String			a2PrevString;
693 
694 	short			nMyCat		= SELPOS_NONE;
695 //  short           nIq=0;
696 
697 	long nIndex;
698 
699 	for(nIndex=eOffsetStart;nIndex<=eOffsetEnd;nIndex++)
700 	{
701 		nNFEntry=pFormatter->GetFormatIndex((NfIndexTableOffset)nIndex,eCurLanguage);
702 
703 		pNumEntry	= pFormatter->GetEntry(nNFEntry);
704 
705 		if(pNumEntry==NULL) continue;
706 
707 		nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
708 		aStrComment=pNumEntry->GetComment();
709 		CategoryToPos_Impl(nMyCat,nMyType);
710 		aNewFormNInfo=	pNumEntry->GetFormatstring();
711 
712 		const StringPtr pStr = new String(aNewFormNInfo);
713 
714 		if ( nNFEntry == nCurFormatKey )
715 		{
716 			nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.Count() : SELPOS_NONE;
717 		}
718 
719 		rList.Insert( pStr,rList.Count());
720 		aCurEntryList.Insert( nNFEntry, aCurEntryList.Count() );
721 	}
722 
723 	return nSelPos;
724 }
725 
FillEListWithDateTime_Impl(SvStrings & rList,short nSelPos)726 short SvxNumberFormatShell::FillEListWithDateTime_Impl( SvStrings& rList,short nSelPos)
727 {
728 	sal_uInt16	nMyType;
729 
730 	DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
731 
732 	const SvNumberformat*	pNumEntry	= pCurFmtTable->First();
733 //  sal_uInt16          nCount      = 0;
734 	sal_uInt32			nNFEntry;
735 	String			aStrComment;
736 	String			aNewFormNInfo;
737 	String			aPrevString;
738 	String			a2PrevString;
739 
740 	short			nMyCat		= SELPOS_NONE;
741 //  short           nIq=0;
742 
743 	long nIndex;
744 
745 	for(nIndex=NF_DATETIME_START;nIndex<=NF_DATETIME_END;nIndex++)
746 	{
747 		nNFEntry=pFormatter->GetFormatIndex((NfIndexTableOffset)nIndex,eCurLanguage);
748 
749 		pNumEntry	= pFormatter->GetEntry(nNFEntry);
750 		if(pNumEntry!=NULL)
751 		{
752 			nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
753 			aStrComment=pNumEntry->GetComment();
754 			CategoryToPos_Impl(nMyCat,nMyType);
755 			aNewFormNInfo=	pNumEntry->GetFormatstring();
756 
757 			const StringPtr pStr = new String(aNewFormNInfo);
758 
759 			if ( nNFEntry == nCurFormatKey )
760 			{
761 				nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.Count() : SELPOS_NONE;
762 			}
763 
764 			rList.Insert( pStr,rList.Count());
765 			aCurEntryList.Insert( nNFEntry, aCurEntryList.Count() );
766 		}
767 	}
768 
769 	return nSelPos;
770 }
771 
FillEListWithCurrency_Impl(SvStrings & rList,short nSelPos)772 short SvxNumberFormatShell::FillEListWithCurrency_Impl( SvStrings& rList,short nSelPos)
773 {
774 	/* Erstellen einer aktuellen Liste von Format-Eintraegen.
775 	 * Rueckgabewert ist die Listenposition des aktuellen Formates.
776 	 * Ist die Liste leer oder gibt es kein aktuelles Format,
777 	 * so wird SELPOS_NONE geliefert.
778 	 */
779 	DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
780 
781 	const NfCurrencyEntry* pTmpCurrencyEntry;
782 	sal_Bool			 bTmpBanking;
783 	XubString		 rSymbol;
784 
785 	sal_Bool bFlag=pFormatter->GetNewCurrencySymbolString(nCurFormatKey,rSymbol,
786 				&pTmpCurrencyEntry,&bTmpBanking);
787 
788 	if((!bFlag && pCurCurrencyEntry==NULL)	||
789 		(bFlag && pTmpCurrencyEntry==NULL && !rSymbol.Len())	||
790 		nCurCategory==NUMBERFORMAT_ALL)
791 	{
792 		if ( nCurCategory == NUMBERFORMAT_ALL )
793 			FillEListWithUserCurrencys(rList,nSelPos);
794 		nSelPos=FillEListWithSysCurrencys(rList,nSelPos);
795 	}
796 	else
797 	{
798 		nSelPos=FillEListWithUserCurrencys(rList,nSelPos);
799 	}
800 
801 	return nSelPos;
802 }
803 
804 
FillEListWithSysCurrencys(SvStrings & rList,short nSelPos)805 short SvxNumberFormatShell::FillEListWithSysCurrencys( SvStrings& rList,short nSelPos)
806 {
807 	/* Erstellen einer aktuellen Liste von Format-Eintraegen.
808 	 * Rueckgabewert ist die Listenposition des aktuellen Formates.
809 	 * Ist die Liste leer oder gibt es kein aktuelles Format,
810 	 * so wird SELPOS_NONE geliefert.
811 	 */
812 	sal_uInt16	nMyType;
813 
814 	DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
815 
816 	const SvNumberformat*	pNumEntry	= pCurFmtTable->First();
817 	sal_uInt16 			nCount		= 0;
818 	sal_uInt32			nNFEntry;
819 	String			aStrComment;
820 	String			aNewFormNInfo;
821 	String			aPrevString;
822 	String			a2PrevString;
823 
824 	nCurCurrencyEntryPos=0;
825 
826 	short			nMyCat		= SELPOS_NONE;
827 //  short           nIq=0;
828 
829 	NfIndexTableOffset eOffsetStart=NF_CURRENCY_START;
830 	NfIndexTableOffset eOffsetEnd=NF_CURRENCY_END;;
831 	long nIndex;
832 
833 	for(nIndex=eOffsetStart;nIndex<=eOffsetEnd;nIndex++)
834 	{
835 		nNFEntry=pFormatter->GetFormatIndex((NfIndexTableOffset)nIndex,eCurLanguage);
836 
837 		pNumEntry	= pFormatter->GetEntry(nNFEntry);
838 
839 		if(pNumEntry==NULL) continue;
840 
841 		nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
842 		aStrComment=pNumEntry->GetComment();
843 		CategoryToPos_Impl(nMyCat,nMyType);
844 		aNewFormNInfo=	pNumEntry->GetFormatstring();
845 
846 		const StringPtr pStr = new String(aNewFormNInfo);
847 
848 		if ( nNFEntry == nCurFormatKey )
849 		{
850 			nSelPos = ( !IsRemoved_Impl( nNFEntry ) ) ? aCurEntryList.Count() : SELPOS_NONE;
851 		}
852 
853 		rList.Insert( pStr,rList.Count());
854 		aCurEntryList.Insert( nNFEntry, aCurEntryList.Count() );
855 	}
856 
857 	if(nCurCategory!=NUMBERFORMAT_ALL)
858 	{
859 		pNumEntry	= pCurFmtTable->First();
860 		nCount		= 0;
861 		while ( pNumEntry )
862 		{
863 			sal_uInt32 nKey = pCurFmtTable->GetCurKey();
864 
865 			nCount++;
866 
867 			if ( !IsRemoved_Impl( nKey ))
868 			{
869 				sal_Bool bUserNewCurrency=sal_False;
870 				if(pNumEntry->HasNewCurrency())
871 				{
872 					const NfCurrencyEntry* pTmpCurrencyEntry;
873 					sal_Bool			bTmpBanking;
874 					XubString		rSymbol;
875 
876 					pFormatter->GetNewCurrencySymbolString(nKey,rSymbol,
877 						&pTmpCurrencyEntry,&bTmpBanking);
878 
879 					bUserNewCurrency=(pTmpCurrencyEntry!=NULL);
880 				}
881 
882 				if(!bUserNewCurrency &&(pNumEntry->GetType() & NUMBERFORMAT_DEFINED))
883 				{
884 					nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
885 					aStrComment=pNumEntry->GetComment();
886 					CategoryToPos_Impl(nMyCat,nMyType);
887 					aNewFormNInfo=	pNumEntry->GetFormatstring();
888 
889 					const StringPtr pStr = new String(aNewFormNInfo);
890 
891 					if ( nKey == nCurFormatKey ) nSelPos =aCurEntryList.Count();
892 					rList.Insert( pStr,rList.Count());
893 					aCurEntryList.Insert( nKey, aCurEntryList.Count() );
894 				}
895 			}
896 			pNumEntry = pCurFmtTable->Next();
897 		}
898 	}
899 	return nSelPos;
900 }
901 
FillEListWithUserCurrencys(SvStrings & rList,short nSelPos)902 short SvxNumberFormatShell::FillEListWithUserCurrencys( SvStrings& rList,short nSelPos)
903 {
904 	/* Erstellen einer aktuellen Liste von Format-Eintraegen.
905 	 * Rueckgabewert ist die Listenposition des aktuellen Formates.
906 	 * Ist die Liste leer oder gibt es kein aktuelles Format,
907 	 * so wird SELPOS_NONE geliefert.
908 	 */
909 	sal_uInt16 nMyType;
910 
911 	DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
912 
913 	sal_uInt16 			nCount		= 0;
914 	String			aStrComment;
915 	String			aNewFormNInfo;
916 	String			aPrevString;
917 	String			a2PrevString;
918 	short			nMyCat = SELPOS_NONE;
919 //  short           nIq=0;
920 
921 	const NfCurrencyEntry* pTmpCurrencyEntry;
922 	sal_Bool        bTmpBanking, bAdaptSelPos;
923 	XubString		rSymbol;
924 	XubString		rBankSymbol;
925 
926 	SvStrings		aList;
927 	SvULongs		aKeyList;
928 
929     /*sal_Bool bFlag=*/pFormatter->GetNewCurrencySymbolString(nCurFormatKey,rSymbol,
930 				&pTmpCurrencyEntry,&bTmpBanking);
931 
932 	XubString rShortSymbol;
933 
934 	if(pCurCurrencyEntry==NULL)
935 	{
936         // #110398# If no currency format was previously selected (we're not
937         // about to add another currency), try to select the initial currency
938         // format (nCurFormatKey) that was set in FormatChanged() after
939         // matching the format string entered in the dialog.
940         bAdaptSelPos = sal_True;
941 		pCurCurrencyEntry=(NfCurrencyEntry*)pTmpCurrencyEntry;
942 		bBankingSymbol=bTmpBanking;
943 		nCurCurrencyEntryPos=FindCurrencyFormat(pTmpCurrencyEntry,bTmpBanking);
944 	}
945 	else
946 	{
947         if (pTmpCurrencyEntry == pCurCurrencyEntry)
948             bAdaptSelPos = sal_True;
949         else
950         {
951             bAdaptSelPos = sal_False;
952 		    pTmpCurrencyEntry = pCurCurrencyEntry;
953         }
954 		bTmpBanking=bBankingSymbol;
955 	}
956 
957 	if(pTmpCurrencyEntry!=NULL)
958 	{
959 		pTmpCurrencyEntry->BuildSymbolString(rSymbol,sal_False);
960 		pTmpCurrencyEntry->BuildSymbolString(rBankSymbol,sal_True);
961 		pTmpCurrencyEntry->BuildSymbolString(rShortSymbol,bTmpBanking,sal_True);
962 	}
963 
964 	const SvNumberformat*	pNumEntry	= pCurFmtTable->First();
965 
966 	while ( pNumEntry )
967 	{
968 		sal_uInt32 nKey = pCurFmtTable->GetCurKey();
969 
970 		nCount++;
971 
972 		if ( !IsRemoved_Impl( nKey ) )
973 		{
974 			if( pNumEntry->GetType() & NUMBERFORMAT_DEFINED ||
975 					pNumEntry->IsAdditionalStandardDefined() )
976 			{
977 				nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
978 				aStrComment=pNumEntry->GetComment();
979 				CategoryToPos_Impl(nMyCat,nMyType);
980 				aNewFormNInfo=	pNumEntry->GetFormatstring();
981 
982 				sal_Bool bInsFlag=sal_False;
983 				if ( pNumEntry->HasNewCurrency() )
984 					bInsFlag = sal_True;	// merge locale formats into currency selection
985 				else if( (!bTmpBanking && aNewFormNInfo.Search(rSymbol)!=STRING_NOTFOUND) ||
986 				   (bTmpBanking && aNewFormNInfo.Search(rBankSymbol)!=STRING_NOTFOUND) )
987 				{
988 					bInsFlag=sal_True;
989 				}
990 				else if(aNewFormNInfo.Search(rShortSymbol)!=STRING_NOTFOUND)
991 				{
992 					XubString rTstSymbol;
993 					const NfCurrencyEntry* pTstCurrencyEntry;
994 					sal_Bool bTstBanking;
995 
996                     /*sal_Bool bTstFlag=*/pFormatter->GetNewCurrencySymbolString(nKey,rTstSymbol,
997 								&pTstCurrencyEntry,&bTstBanking);
998 
999 					if(pTmpCurrencyEntry==pTstCurrencyEntry && bTstBanking==bTmpBanking)
1000 					{
1001 						bInsFlag=sal_True;
1002 					}
1003 
1004 				}
1005 
1006 				if(bInsFlag)
1007 				{
1008 					const StringPtr pStr = new String(aNewFormNInfo);
1009 
1010 					aList.Insert( pStr,aList.Count());
1011 					aKeyList.Insert( nKey, aKeyList.Count() );
1012 				}
1013 			}
1014 		}
1015 		pNumEntry = pCurFmtTable->Next();
1016 	}
1017 
1018 	NfWSStringsDtor aWSStringsDtor;
1019 	sal_uInt16 nDefault;
1020 	if ( pTmpCurrencyEntry && nCurCategory != NUMBERFORMAT_ALL )
1021     {
1022         nDefault = pFormatter->GetCurrencyFormatStrings(
1023 			aWSStringsDtor,	*pTmpCurrencyEntry, bTmpBanking );
1024         if ( !bTmpBanking )
1025             pFormatter->GetCurrencyFormatStrings(
1026                 aWSStringsDtor, *pTmpCurrencyEntry, sal_True );
1027     }
1028 	else
1029 		nDefault = 0;
1030     if ( !bTmpBanking && nCurCategory != NUMBERFORMAT_ALL )
1031     {   // append formats for all currencies defined in the current I18N locale
1032         const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable();
1033         sal_uInt16 nCurrCount = rCurrencyTable.Count();
1034         LanguageType eLang = MsLangId::getRealLanguage( eCurLanguage );
1035         for ( sal_uInt16 i=0; i < nCurrCount; ++i )
1036         {
1037             const NfCurrencyEntry* pCurr = rCurrencyTable[i];
1038             if ( pCurr->GetLanguage() == eLang && pTmpCurrencyEntry != pCurr )
1039             {
1040                 pFormatter->GetCurrencyFormatStrings( aWSStringsDtor, *pCurr, sal_False );
1041                 pFormatter->GetCurrencyFormatStrings( aWSStringsDtor, *pCurr, sal_True );
1042             }
1043         }
1044     }
1045 
1046     sal_uInt16 i,nPos;
1047 	sal_uInt16 nOldListCount = rList.Count();
1048 	for( i=0, nPos=nOldListCount; i<aWSStringsDtor.Count(); i++)
1049 	{
1050 		sal_Bool bFlag=sal_True;
1051 		String aInsStr(*aWSStringsDtor[i]);
1052 		sal_uInt16 j;
1053 		for(j=0;j<aList.Count();j++)
1054 		{
1055 			const StringPtr pTestStr=aList[j];
1056 
1057 			if(*pTestStr==aInsStr)
1058 			{
1059 				bFlag=sal_False;
1060 				break;
1061 			}
1062 		}
1063 		if(bFlag)
1064 		{
1065 			rList.Insert(new String(aInsStr),nPos);
1066 			aCurEntryList.Insert( NUMBERFORMAT_ENTRY_NOT_FOUND, nPos++);
1067 		}
1068 		else
1069 		{
1070 			rList.Insert(aList[j],nPos);
1071 			aList.Remove(j);
1072 			aCurEntryList.Insert( aKeyList[j],nPos++);
1073 			aKeyList.Remove(j);
1074 		}
1075 	}
1076 
1077 	for(i=0;i<aKeyList.Count();i++)
1078 	{
1079 		if(aKeyList[i]!=NUMBERFORMAT_ENTRY_NOT_FOUND)
1080 		{
1081 			rList.Insert(aList[i],rList.Count());
1082 			aCurEntryList.Insert( aKeyList[i],aCurEntryList.Count());
1083 		}
1084 	}
1085 
1086 	for(i=nOldListCount;i<rList.Count();i++)
1087 	{
1088 		aCurrencyFormatList.Insert(new String(*rList[i]),aCurrencyFormatList.Count());
1089 
1090 		if ( nSelPos == SELPOS_NONE && bAdaptSelPos && aCurEntryList[i] == nCurFormatKey )
1091 			nSelPos = i;
1092 	}
1093 
1094 	if ( nSelPos == SELPOS_NONE && nCurCategory != NUMBERFORMAT_ALL )
1095 		nSelPos = nDefault;
1096 
1097 	return nSelPos;
1098 }
1099 
1100 
FillEListWithUsD_Impl(SvStrings & rList,sal_uInt16 nPrivCat,short nSelPos)1101 short SvxNumberFormatShell::FillEListWithUsD_Impl( SvStrings& rList, sal_uInt16 nPrivCat, short nSelPos)
1102 {
1103 	/* Erstellen einer aktuellen Liste von Format-Eintraegen.
1104 	 * Rueckgabewert ist die Listenposition des aktuellen Formates.
1105 	 * Ist die Liste leer oder gibt es kein aktuelles Format,
1106 	 * so wird SELPOS_NONE geliefert.
1107 	 */
1108 	sal_uInt16 nMyType;
1109 
1110 	DBG_ASSERT( pCurFmtTable != NULL, "Unbekanntes Zahlenformat!" );
1111 
1112 	const SvNumberformat*	pNumEntry	= pCurFmtTable->First();
1113 	sal_uInt16 			nCount		= 0;
1114 	String			aStrComment;
1115 	String			aNewFormNInfo;
1116 	String			aPrevString;
1117 	String			a2PrevString;
1118 
1119 	short			nMyCat		= SELPOS_NONE;
1120 //  short           nIq=0;
1121 	sal_Bool		bAdditional = (nPrivCat != CAT_USERDEFINED &&
1122 									nCurCategory != NUMBERFORMAT_ALL);
1123 
1124 	while ( pNumEntry )
1125 	{
1126 		sal_uInt32 nKey = pCurFmtTable->GetCurKey();
1127 
1128 		nCount++;
1129 
1130 		if ( !IsRemoved_Impl( nKey ) )
1131 		{
1132 			if( (pNumEntry->GetType() & NUMBERFORMAT_DEFINED) ||
1133 					(bAdditional && pNumEntry->IsAdditionalStandardDefined()) )
1134 			{
1135 				nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
1136 				aStrComment=pNumEntry->GetComment();
1137 				CategoryToPos_Impl(nMyCat,nMyType);
1138 				aNewFormNInfo=	pNumEntry->GetFormatstring();
1139 
1140 				sal_Bool bFlag=sal_True;
1141 				if(pNumEntry->HasNewCurrency())
1142 				{
1143 					sal_Bool bTestBanking;
1144 					sal_uInt16 nPos=FindCurrencyTableEntry(aNewFormNInfo,bTestBanking);
1145 					bFlag=!IsInTable(nPos,bTestBanking,aNewFormNInfo);
1146 				}
1147 				if(bFlag)
1148 				{
1149 					const StringPtr pStr = new String(aNewFormNInfo);
1150 
1151 					if ( nKey == nCurFormatKey ) nSelPos =aCurEntryList.Count();
1152 					rList.Insert( pStr,rList.Count());
1153 					aCurEntryList.Insert( nKey, aCurEntryList.Count() );
1154 				}
1155 			}
1156 		}
1157 		pNumEntry = pCurFmtTable->Next();
1158 	}
1159 	return nSelPos;
1160 }
1161 
1162 
1163 // -----------------------------------------------------------------------
1164 
GetPreviewString_Impl(String & rString,Color * & rpColor)1165 void SvxNumberFormatShell::GetPreviewString_Impl( String& rString, Color*& rpColor )
1166 {
1167     rpColor = NULL;
1168 
1169 	//	#50441# if a string was set in addition to the value, use it for text formats
1170 	sal_Bool bUseText = ( eValType == SVX_VALUE_TYPE_STRING ||
1171 						( aValStr.Len() && ( pFormatter->GetType(nCurFormatKey) & NUMBERFORMAT_TEXT ) ) );
1172 
1173 	if ( bUseText )
1174         pFormatter->GetOutputString( aValStr, nCurFormatKey, rString, &rpColor );
1175 	else
1176         pFormatter->GetOutputString( nValNum, nCurFormatKey, rString, &rpColor );
1177 }
1178 
1179 // -----------------------------------------------------------------------
1180 
IsRemoved_Impl(sal_uInt32 nKey)1181 sal_Bool SvxNumberFormatShell::IsRemoved_Impl( sal_uInt32 nKey )
1182 {
1183 	sal_Bool bFound = sal_False;
1184 	for ( sal_uInt16 i = 0; !bFound && i < aDelList.Count(); ++i )
1185 		if ( aDelList[i] == nKey )
1186 			bFound = sal_True;
1187 	return bFound;
1188 }
1189 
1190 // -----------------------------------------------------------------------
1191 
IsAdded_Impl(sal_uInt32 nKey)1192 sal_Bool SvxNumberFormatShell::IsAdded_Impl( sal_uInt32 nKey )
1193 {
1194 	sal_Bool bFound = sal_False;
1195 	for ( sal_uInt16 i = 0; !bFound && i < aAddList.Count(); ++i )
1196 		if ( aAddList[i] == nKey )
1197 			bFound = sal_True;
1198 	return bFound;
1199 }
1200 
1201 // -----------------------------------------------------------------------
1202 // Konvertierungs-Routinen:
1203 // ------------------------
1204 
PosToCategory_Impl(sal_uInt16 nPos,short & rCategory)1205 void SvxNumberFormatShell::PosToCategory_Impl( sal_uInt16 nPos, short& rCategory )
1206 {
1207 	// Kategorie ::com::sun::star::form-Positionen abbilden (->Resource)
1208 	switch ( nPos )
1209 	{
1210 		case CAT_USERDEFINED:	rCategory = NUMBERFORMAT_DEFINED;		break;
1211 		case CAT_NUMBER:		rCategory = NUMBERFORMAT_NUMBER;		break;
1212 		case CAT_PERCENT:		rCategory = NUMBERFORMAT_PERCENT;		break;
1213 		case CAT_CURRENCY:		rCategory = NUMBERFORMAT_CURRENCY;		break;
1214 		case CAT_DATE:			rCategory = NUMBERFORMAT_DATE;			break;
1215 		case CAT_TIME:			rCategory = NUMBERFORMAT_TIME;			break;
1216 		case CAT_SCIENTIFIC:	rCategory = NUMBERFORMAT_SCIENTIFIC;	break;
1217 		case CAT_FRACTION:		rCategory = NUMBERFORMAT_FRACTION;		break;
1218 		case CAT_BOOLEAN:		rCategory = NUMBERFORMAT_LOGICAL;		break;
1219 		case CAT_TEXT:			rCategory = NUMBERFORMAT_TEXT;			break;
1220 		case CAT_ALL:
1221 		default:	rCategory = NUMBERFORMAT_ALL; break;
1222 	}
1223 }
1224 
1225 // -----------------------------------------------------------------------
1226 
CategoryToPos_Impl(short nCategory,sal_uInt16 & rPos)1227 void SvxNumberFormatShell::CategoryToPos_Impl( short nCategory, sal_uInt16& rPos )
1228 {
1229 	// Kategorie auf ::com::sun::star::form-Positionen abbilden (->Resource)
1230 	switch ( nCategory )
1231 	{
1232 		case NUMBERFORMAT_DEFINED:		rPos = CAT_USERDEFINED;	break;
1233 		case NUMBERFORMAT_NUMBER:		rPos = CAT_NUMBER;		break;
1234 		case NUMBERFORMAT_PERCENT:		rPos = CAT_PERCENT;		break;
1235 		case NUMBERFORMAT_CURRENCY:		rPos = CAT_CURRENCY;	break;
1236 		case NUMBERFORMAT_DATETIME:
1237 		case NUMBERFORMAT_DATE:			rPos = CAT_DATE;		break;
1238 		case NUMBERFORMAT_TIME:			rPos = CAT_TIME;		break;
1239 		case NUMBERFORMAT_SCIENTIFIC:	rPos = CAT_SCIENTIFIC;	break;
1240 		case NUMBERFORMAT_FRACTION:		rPos = CAT_FRACTION;	break;
1241 		case NUMBERFORMAT_LOGICAL:		rPos = CAT_BOOLEAN;		break;
1242 		case NUMBERFORMAT_TEXT:			rPos = CAT_TEXT;		break;
1243 		case NUMBERFORMAT_ALL:
1244 		default:						rPos = CAT_ALL;
1245 	}
1246 }
1247 
1248 
1249 /*************************************************************************
1250 #*	Member:		MakePrevStringFromVal						Datum:19.09.97
1251 #*------------------------------------------------------------------------
1252 #*
1253 #*  Klasse:		SvxNumberFormatShell
1254 #*
1255 #*  Funktion:	Formatiert die Zahl nValue abhaengig von rFormatStr
1256 #*				und speichert das Ergebnis in rPreviewStr.
1257 #*
1258 #*  Input:		FormatString, Farbe, zu formatierende Zahl
1259 #*
1260 #*	Output:		Ausgabestring rPreviewStr
1261 #*
1262 #************************************************************************/
1263 
MakePrevStringFromVal(const String & rFormatStr,String & rPreviewStr,Color * & rpFontColor,double nValue)1264 void SvxNumberFormatShell::MakePrevStringFromVal(
1265         const String& rFormatStr,
1266         String& rPreviewStr,
1267         Color*& rpFontColor,
1268         double  nValue)
1269 {
1270     rpFontColor = NULL;
1271     pFormatter->GetPreviewString( rFormatStr, nValue, rPreviewStr, &rpFontColor, eCurLanguage );
1272 }
1273 
1274 /*************************************************************************
1275 #*	Member:		GetComment4Entry							Datum:30.10.97
1276 #*------------------------------------------------------------------------
1277 #*
1278 #*  Klasse:		SvxNumberFormatShell
1279 #*
1280 #*  Funktion:	Liefert den Kommentar fuer einen gegebenen
1281 #*				Eintrag zurueck.
1282 #*
1283 #*  Input:		Nummer des Eintrags
1284 #*
1285 #*	Output:		Kommentar-String
1286 #*
1287 #************************************************************************/
1288 
SetComment4Entry(short nEntry,String aEntStr)1289 void SvxNumberFormatShell::SetComment4Entry(short nEntry,String aEntStr)
1290 {
1291 	SvNumberformat *pNumEntry;
1292 	if(nEntry<0) return;
1293 	sal_uInt32	nMyNfEntry=aCurEntryList[nEntry];
1294 	pNumEntry = (SvNumberformat*)pFormatter->GetEntry(nMyNfEntry);
1295 	if(pNumEntry!=NULL) pNumEntry->SetComment(aEntStr);
1296 }
1297 
1298 /*************************************************************************
1299 #*	Member:		GetComment4Entry							Datum:30.10.97
1300 #*------------------------------------------------------------------------
1301 #*
1302 #*  Klasse:		SvxNumberFormatShell
1303 #*
1304 #*  Funktion:	Liefert den Kommentar fuer einen gegebenen
1305 #*				Eintrag zurueck.
1306 #*
1307 #*  Input:		Nummer des Eintrags
1308 #*
1309 #*	Output:		Kommentar-String
1310 #*
1311 #************************************************************************/
1312 
GetComment4Entry(short nEntry)1313 String SvxNumberFormatShell::GetComment4Entry(short nEntry)
1314 {
1315 	const SvNumberformat *pNumEntry;
1316 
1317 	if(nEntry < 0)
1318 		return String();
1319 
1320 	if(nEntry<aCurEntryList.Count())
1321 	{
1322 		sal_uInt32	nMyNfEntry=aCurEntryList[nEntry];
1323 		pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1324 		if(pNumEntry!=NULL)
1325 			return pNumEntry->GetComment();
1326 	}
1327 
1328 	return String();
1329 }
1330 
1331 /*************************************************************************
1332 #*	Member:		GetCategory4Entry							Datum:30.10.97
1333 #*------------------------------------------------------------------------
1334 #*
1335 #*  Klasse:		SvxNumberFormatShell
1336 #*
1337 #*  Funktion:	Liefert die Kategorie- Nummer fuer einen gegebenen
1338 #*				Eintrag zurueck.
1339 #*
1340 #*  Input:		Nummer des Eintrags
1341 #*
1342 #*	Output:		Kategorie- Nummer
1343 #*
1344 #************************************************************************/
1345 
GetCategory4Entry(short nEntry)1346 short SvxNumberFormatShell::GetCategory4Entry(short nEntry)
1347 {
1348 	const SvNumberformat *pNumEntry;
1349 	if(nEntry<0) return 0;
1350 
1351 	if(nEntry<aCurEntryList.Count())
1352 	{
1353 		sal_uInt32	nMyNfEntry=aCurEntryList[nEntry];
1354 
1355 		if(nMyNfEntry!=NUMBERFORMAT_ENTRY_NOT_FOUND)
1356 		{
1357 			pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1358 			sal_uInt16 nMyCat,nMyType;
1359 			if(pNumEntry!=NULL)
1360 			{
1361 				nMyCat=pNumEntry->GetType() & ~NUMBERFORMAT_DEFINED;
1362 				CategoryToPos_Impl(nMyCat,nMyType);
1363 
1364 				return (short) nMyType;
1365 			}
1366 			return 0;
1367 		}
1368 		else if(aCurrencyFormatList.Count()>0)
1369 		{
1370 			return CAT_CURRENCY;
1371 		}
1372 	}
1373 	return 0;
1374 
1375 }
1376 
1377 /*************************************************************************
1378 #*	Member:		GetUserDefined4Entry						Datum:31.10.97
1379 #*------------------------------------------------------------------------
1380 #*
1381 #*  Klasse:		SvxNumberFormatShell
1382 #*
1383 #*  Funktion:	Liefert die Information, ob ein Eintrag
1384 #*				benutzerspezifisch ist zurueck.
1385 #*
1386 #*  Input:		Nummer des Eintrags
1387 #*
1388 #*	Output:		Benutzerspezifisch?
1389 #*
1390 #************************************************************************/
1391 
GetUserDefined4Entry(short nEntry)1392 sal_Bool SvxNumberFormatShell::GetUserDefined4Entry(short nEntry)
1393 {
1394 	const SvNumberformat *pNumEntry;
1395 	if(nEntry<0) return 0;
1396 	if(nEntry<aCurEntryList.Count())
1397 	{
1398 		sal_uInt32	nMyNfEntry=aCurEntryList[nEntry];
1399 		pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1400 
1401 		if(pNumEntry!=NULL)
1402 		{
1403 			if((pNumEntry->GetType() & NUMBERFORMAT_DEFINED)>0)
1404 			{
1405 				return sal_True;
1406 			}
1407 		}
1408 	}
1409 	return sal_False;
1410 }
1411 
1412 
1413 /*************************************************************************
1414 #*	Member:		GetFormat4Entry								Datum:30.10.97
1415 #*------------------------------------------------------------------------
1416 #*
1417 #*  Klasse:		SvxNumberFormatShell
1418 #*
1419 #*  Funktion:	Liefert den Format- String fuer einen gegebenen
1420 #*				Eintrag zurueck.
1421 #*
1422 #*  Input:		Nummer des Eintrags
1423 #*
1424 #*	Output:		Format- String
1425 #*
1426 #************************************************************************/
1427 
GetFormat4Entry(short nEntry)1428 String SvxNumberFormatShell::GetFormat4Entry(short nEntry)
1429 {
1430 	const SvNumberformat *pNumEntry;
1431 
1432 	if(nEntry < 0)
1433 		return String();
1434 
1435 	if(aCurrencyFormatList.Count()>0)
1436 	{
1437 		if(aCurrencyFormatList.Count()>nEntry)
1438 			return *aCurrencyFormatList[nEntry];
1439 	}
1440 	else
1441 	{
1442 		sal_uInt32	nMyNfEntry=aCurEntryList[nEntry];
1443 		pNumEntry = pFormatter->GetEntry(nMyNfEntry);
1444 
1445 		if(pNumEntry!=NULL)
1446 			return pNumEntry->GetFormatstring();
1447 	}
1448 	return String();
1449 }
1450 
1451 /*************************************************************************
1452 #*	Member:		GetListPos4Entry							Datum:31.10.97
1453 #*------------------------------------------------------------------------
1454 #*
1455 #*  Klasse:		SvxNumberFormatShell
1456 #*
1457 #*  Funktion:	Liefert die Listen- Nummer fuer einen gegebenen
1458 #*				Formatindex zurueck.
1459 #*
1460 #*  Input:		Nummer des Eintrags
1461 #*
1462 #*	Output:		Kategorie- Nummer
1463 #*
1464 #************************************************************************/
1465 
GetListPos4Entry(sal_uInt32 nIdx)1466 short SvxNumberFormatShell::GetListPos4Entry(sal_uInt32 nIdx)
1467 {
1468 	short nSelP=SELPOS_NONE;
1469 	if( aCurEntryList.Count() <= 0x7fff )
1470 	{
1471 		for(short i=0;i<aCurEntryList.Count();i++)
1472 		{
1473 			if(aCurEntryList[i]==nIdx)
1474 			{
1475 				nSelP=i;
1476 				break;
1477 			}
1478 		}
1479 	}
1480 	else
1481 	{
1482 		DBG_ERROR("svx::SvxNumberFormatShell::GetListPos4Entry(), list got to large!" );
1483 	}
1484 	return nSelP;
1485 }
1486 
GetListPos4Entry(const String & rFmtString)1487 short SvxNumberFormatShell::GetListPos4Entry( const String& rFmtString )
1488 {
1489 	sal_uInt32 nAt=0;
1490 	short nSelP=SELPOS_NONE;
1491 	if(FindEntry(rFmtString, &nAt))
1492 	{
1493 		if(NUMBERFORMAT_ENTRY_NOT_FOUND!=nAt && NUMBERFORMAT_ENTRY_NEW_CURRENCY!=nAt)
1494 		{
1495 			nSelP=GetListPos4Entry(nAt);
1496 		}
1497 		else
1498 		{
1499 			if(aCurrencyFormatList.Count()>0)
1500 			{
1501 				for(sal_uInt16 i=0;i<aCurrencyFormatList.Count();i++)
1502 				{
1503 					if (rFmtString==*aCurrencyFormatList[i])
1504 					{
1505 						nSelP=i;
1506 						break;
1507 					}
1508 				}
1509 			}
1510 		}
1511 	}
1512 	return nSelP;
1513 }
1514 
GetStandardName() const1515 String SvxNumberFormatShell::GetStandardName() const
1516 {
1517     return pFormatter->GetStandardName( eCurLanguage);
1518 }
1519 
GetCurrencySymbols(SvStringsDtor & rList,sal_uInt16 * pPos)1520 void SvxNumberFormatShell::GetCurrencySymbols( SvStringsDtor& rList, sal_uInt16* pPos )
1521 {
1522 
1523     const NfCurrencyEntry* pTmpCurrencyEntry=SvNumberFormatter::MatchSystemCurrency();
1524 
1525 	sal_Bool bFlag=(pTmpCurrencyEntry==NULL);
1526 
1527 	GetCurrencySymbols( rList, bFlag);
1528 
1529 	if(pPos!=NULL)
1530 	{
1531         const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1532 		sal_uInt16 nTableCount=rCurrencyTable.Count();
1533 
1534 		*pPos=0;
1535 		sal_uInt16 nCount=aCurCurrencyList.Count();
1536 
1537 		if(bFlag)
1538 		{
1539 			*pPos=1;
1540 			nCurCurrencyEntryPos=1;
1541 		}
1542 		else
1543 		{
1544 			for(sal_uInt16 i=1;i<nCount;i++)
1545 			{
1546                 const sal_uInt16 j = aCurCurrencyList[i];
1547 				if (j != (sal_uInt16)-1 && j < nTableCount &&
1548                         pTmpCurrencyEntry == rCurrencyTable[j])
1549 				{
1550 					*pPos=i;
1551 					nCurCurrencyEntryPos=i;
1552 					break;
1553 				}
1554 			}
1555 		}
1556 	}
1557 
1558 }
1559 
GetCurrencySymbols(SvStringsDtor & rList,sal_Bool bFlag)1560 void SvxNumberFormatShell::GetCurrencySymbols( SvStringsDtor& rList, sal_Bool bFlag )
1561 {
1562 	aCurCurrencyList.Remove(0,aCurCurrencyList.Count());
1563 
1564     const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1565 	sal_uInt16 nCount=rCurrencyTable.Count();
1566 
1567     SvtLanguageTable* pLanguageTable=new SvtLanguageTable;
1568 
1569     sal_uInt16 nStart=1;
1570 	sal_uInt16 i,j;
1571 
1572 	XubString aString( ApplyLreOrRleEmbedding( rCurrencyTable[0]->GetSymbol()));
1573 	aString += sal_Unicode(' ');
1574 	aString += ApplyLreOrRleEmbedding( pLanguageTable->GetString( rCurrencyTable[0]->GetLanguage()));
1575 
1576 	WSStringPtr pStr = new XubString(aString);
1577 	rList.Insert( pStr,rList.Count());
1578 	sal_uInt16 nAuto=(sal_uInt16)-1;
1579 	aCurCurrencyList.Insert(nAuto,aCurCurrencyList.Count());
1580 
1581 	if(bFlag)
1582 	{
1583 		pStr = new XubString(aString);
1584 		rList.Insert( pStr,rList.Count());
1585 		aCurCurrencyList.Insert((sal_uInt16)0,aCurCurrencyList.Count());
1586         ++nStart;
1587 	}
1588 
1589     CollatorWrapper aCollator( ::comphelper::getProcessServiceFactory());
1590     aCollator.loadDefaultCollator( Application::GetSettings().GetLocale(), 0);
1591 
1592     const String aTwoSpace( RTL_CONSTASCII_USTRINGPARAM( "  "));
1593 
1594     for(i=1;i<nCount;i++)
1595 	{
1596         XubString aStr( ApplyLreOrRleEmbedding( rCurrencyTable[i]->GetBankSymbol()));
1597         aStr += aTwoSpace;
1598         aStr += ApplyLreOrRleEmbedding( rCurrencyTable[i]->GetSymbol());
1599         aStr += aTwoSpace;
1600         aStr += ApplyLreOrRleEmbedding( pLanguageTable->GetString( rCurrencyTable[i]->GetLanguage()));
1601 
1602         pStr = new XubString(aStr);
1603 #if 0
1604         fprintf( stderr, "currency entry: %s\n", ByteString( *pStr, RTL_TEXTENCODING_UTF8).GetBuffer());
1605 #endif
1606 		for(j=nStart;j<rList.Count();j++)
1607 		{
1608 			const StringPtr pTestStr=rList[j];
1609 			if (aCollator.compareString( *pStr, *pTestStr) < 0)
1610                 break;  // insert before first greater than
1611 		}
1612 		rList.Insert( pStr,j);
1613 		aCurCurrencyList.Insert(i,j);
1614 	}
1615 
1616     // Append ISO codes to symbol list.
1617     // XXX If this is to be changed, various other places would had to be
1618     // adapted that assume this order!
1619     sal_uInt16 nCont = rList.Count();
1620 
1621     for(i=1;i<nCount;i++)
1622 	{
1623 		bool bInsert = true;
1624 		pStr = new XubString( ApplyLreOrRleEmbedding( rCurrencyTable[i]->GetBankSymbol()));
1625 
1626 		for (j = nCont; j < rList.Count() && bInsert; ++j)
1627 		{
1628 			const StringPtr pTestStr=rList[j];
1629 
1630 			if(*pTestStr==*pStr)
1631 				bInsert = false;
1632 			else
1633                 if (aCollator.compareString( *pStr, *pTestStr) < 0)
1634                     break;  // insert before first greater than
1635 		}
1636 		if(bInsert)
1637 		{
1638 			rList.Insert( pStr,j);
1639 			aCurCurrencyList.Insert(i,j);
1640 		}
1641 	}
1642 
1643     delete pLanguageTable;
1644 }
1645 
GetCurrencyFormats(SvStrings & aListDtor)1646 void SvxNumberFormatShell::GetCurrencyFormats(SvStrings& aListDtor)
1647 {
1648 	if(pCurCurrencyEntry!=NULL)
1649 	{
1650 		NfWSStringsDtor aWSStringsDtor;
1651         /*sal_uInt16 nDefault = */pFormatter->GetCurrencyFormatStrings( aWSStringsDtor,
1652 			*pCurCurrencyEntry, bBankingSymbol );
1653 
1654 		for(sal_uInt16 i=0;i<aWSStringsDtor.Count();i++)
1655 		{
1656 			aListDtor.Insert(new String(*aWSStringsDtor[i]),aListDtor.Count());
1657 		}
1658 	}
1659 }
1660 
IsBankingSymbol(sal_uInt16 nPos)1661 sal_Bool SvxNumberFormatShell::IsBankingSymbol(sal_uInt16 nPos)
1662 {
1663     const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1664 	sal_uInt16 nCount=rCurrencyTable.Count();
1665 
1666 	return (nPos>nCount);
1667 }
1668 
SetCurrencySymbol(sal_uInt16 nPos)1669 void SvxNumberFormatShell::SetCurrencySymbol(sal_uInt16 nPos)
1670 {
1671     const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1672 	sal_uInt16 nCount=rCurrencyTable.Count();
1673 
1674 	bBankingSymbol=(nPos>=nCount);
1675 
1676 	if(nPos<aCurCurrencyList.Count())
1677 	{
1678 		sal_uInt16 nCurrencyPos=aCurCurrencyList[nPos];
1679 		if(nCurrencyPos!=(sal_uInt16)-1)
1680 		{
1681 			pCurCurrencyEntry=rCurrencyTable[nCurrencyPos];
1682 			nCurCurrencyEntryPos=nPos;
1683 		}
1684 		else
1685 		{
1686 			pCurCurrencyEntry=NULL;
1687 			nCurCurrencyEntryPos=0;
1688 			nCurFormatKey=pFormatter->GetFormatIndex(
1689 						 NF_CURRENCY_1000DEC2_RED, eCurLanguage);
1690 		}
1691 	}
1692 }
1693 
GetCurrencySymbol()1694 sal_uInt32 SvxNumberFormatShell::GetCurrencySymbol()
1695 {
1696 	return nCurCurrencyEntryPos;
1697 }
1698 
GetCurCurrencyEntry()1699 NfCurrencyEntry* SvxNumberFormatShell::GetCurCurrencyEntry()
1700 {
1701 	return pCurCurrencyEntry;
1702 }
1703 
SetCurCurrencyEntry(NfCurrencyEntry * pCEntry)1704 void SvxNumberFormatShell::SetCurCurrencyEntry(NfCurrencyEntry* pCEntry)
1705 {
1706 	pCurCurrencyEntry=pCEntry;
1707 }
1708 
IsTmpCurrencyFormat(const String & rFmtString)1709 sal_Bool SvxNumberFormatShell::IsTmpCurrencyFormat( const String& rFmtString )
1710 {
1711 	sal_uInt32 nFound;
1712     /*sal_Bool bRes=*/FindEntry(rFmtString, &nFound);
1713 
1714 	if(nFound==NUMBERFORMAT_ENTRY_NEW_CURRENCY)
1715 	{
1716 		return sal_True;
1717 	}
1718 	return sal_False;
1719 }
1720 
FindCurrencyFormat(const String & rFmtString)1721 sal_uInt16 SvxNumberFormatShell::FindCurrencyFormat( const String& rFmtString )
1722 {
1723     const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1724 	sal_uInt16 nCount=rCurrencyTable.Count();
1725 
1726 	sal_Bool bTestBanking=sal_False;
1727 
1728 	sal_uInt16 nPos=FindCurrencyTableEntry(rFmtString, bTestBanking);
1729 
1730 	sal_uInt16 nStart=0;
1731 
1732 	if(nPos!=(sal_uInt16)-1)
1733 	{
1734 		if(bTestBanking && aCurCurrencyList.Count()>nPos)
1735 		{
1736 			nStart=nCount;
1737 		}
1738 		for(sal_uInt16 j=nStart;j<aCurCurrencyList.Count();j++)
1739 		{
1740 			if(aCurCurrencyList[j]==nPos) return j;
1741 		}
1742 	}
1743 	return (sal_uInt16) -1;
1744 }
1745 
FindCurrencyTableEntry(const String & rFmtString,sal_Bool & bTestBanking)1746 sal_uInt16 SvxNumberFormatShell::FindCurrencyTableEntry( const String& rFmtString, sal_Bool &bTestBanking )
1747 {
1748 	sal_uInt16 nPos=(sal_uInt16) -1;
1749 
1750     const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1751 	sal_uInt16 nCount=rCurrencyTable.Count();
1752 
1753 	const SvNumberformat* pFormat;
1754 	String aSymbol, aExtension;
1755 	sal_uInt32 nFound = pFormatter->TestNewString( rFmtString, eCurLanguage );
1756 	if ( nFound != NUMBERFORMAT_ENTRY_NOT_FOUND &&
1757 			((pFormat = pFormatter->GetEntry( nFound )) != 0) &&
1758 			pFormat->GetNewCurrencySymbol( aSymbol, aExtension ) )
1759 	{	// eventually match with format locale
1760 		const NfCurrencyEntry* pTmpCurrencyEntry =
1761             SvNumberFormatter::GetCurrencyEntry( bTestBanking, aSymbol, aExtension,
1762 			pFormat->GetLanguage() );
1763 		if ( pTmpCurrencyEntry )
1764 		{
1765 			for(sal_uInt16 i=0;i<nCount;i++)
1766 			{
1767 				if(pTmpCurrencyEntry==rCurrencyTable[i])
1768 				{
1769 					nPos=i;
1770 					break;
1771 				}
1772 			}
1773 		}
1774 	}
1775 	else
1776 	{	// search symbol string only
1777 		for(sal_uInt16 i=0;i<nCount;i++)
1778 		{
1779 			const NfCurrencyEntry* pTmpCurrencyEntry=rCurrencyTable[i];
1780             XubString _aSymbol, aBankSymbol;
1781             pTmpCurrencyEntry->BuildSymbolString(_aSymbol,sal_False);
1782 			pTmpCurrencyEntry->BuildSymbolString(aBankSymbol,sal_True);
1783 
1784             if(rFmtString.Search(_aSymbol)!=STRING_NOTFOUND)
1785 			{
1786 				bTestBanking=sal_False;
1787 				nPos=i;
1788 				break;
1789 			}
1790 			else if(rFmtString.Search(aBankSymbol)!=STRING_NOTFOUND)
1791 			{
1792 				bTestBanking=sal_True;
1793 				nPos=i;
1794 				break;
1795 			}
1796 		}
1797 	}
1798 
1799 	return nPos;
1800 }
1801 
FindCurrencyFormat(const NfCurrencyEntry * pTmpCurrencyEntry,sal_Bool bTmpBanking)1802 sal_uInt16 SvxNumberFormatShell::FindCurrencyFormat(const NfCurrencyEntry* pTmpCurrencyEntry,sal_Bool bTmpBanking)
1803 {
1804     const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1805 	sal_uInt16 nCount=rCurrencyTable.Count();
1806 
1807 //  sal_Bool bTestBanking=sal_False;
1808 	sal_uInt16 nPos=0;
1809 	for(sal_uInt16 i=0;i<nCount;i++)
1810 	{
1811 		if(pTmpCurrencyEntry==rCurrencyTable[i])
1812 		{
1813 			nPos=i;
1814 			break;
1815 		}
1816 	}
1817 
1818 	sal_uInt16 nStart=0;
1819 	if(bTmpBanking && aCurCurrencyList.Count()>nPos)
1820 	{
1821 		nStart=nCount;
1822 	}
1823 	for(sal_uInt16 j=nStart;j<aCurCurrencyList.Count();j++)
1824 	{
1825 		if(aCurCurrencyList[j]==nPos) return j;
1826 	}
1827 	return (sal_uInt16) -1;
1828 }
1829 
IsInTable(sal_uInt16 nPos,sal_Bool bTmpBanking,const String & rFmtString)1830 sal_Bool SvxNumberFormatShell::IsInTable(sal_uInt16 nPos,sal_Bool bTmpBanking,const String &rFmtString)
1831 {
1832 	sal_Bool bFlag=sal_False;
1833 
1834 	if(nPos!=(sal_uInt16)-1)
1835 	{
1836         const NfCurrencyTable& rCurrencyTable=SvNumberFormatter::GetTheCurrencyTable();
1837 		sal_uInt16 nCount=rCurrencyTable.Count();
1838 
1839 		if(nPos<nCount)
1840 		{
1841 			NfWSStringsDtor aWSStringsDtor;
1842 			sal_uInt16 nDefault;
1843 
1844 			const NfCurrencyEntry* pTmpCurrencyEntry=rCurrencyTable[nPos];
1845 
1846 			if ( pTmpCurrencyEntry!=NULL)
1847 			{
1848 				nDefault = pFormatter->GetCurrencyFormatStrings( aWSStringsDtor,
1849 								*pTmpCurrencyEntry, bTmpBanking );
1850 
1851 				for(sal_uInt16 i=0;i<aWSStringsDtor.Count();i++)
1852 				{
1853 					if(*aWSStringsDtor[i]==rFmtString)
1854 					{
1855 						bFlag=sal_True;
1856 						break;
1857 					}
1858 				}
1859 			}
1860 		}
1861 	}
1862 
1863 	return bFlag;
1864 }
1865 
1866