merge the formfield patch from ooo-build
[ooovba.git] / i18npool / source / localedata / localedata.cxx
blobfe4de6e554859e35e9fa954f9777e4fa57900551
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: localedata.cxx,v $
10 * $Revision: 1.59.24.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_i18npool.hxx"
34 #include <localedata.hxx>
35 #include <i18npool/mslangid.hxx>
36 #include <rtl/ustrbuf.hxx>
37 #include <string.h>
38 #include <stdio.h>
39 #include "rtl/instance.hxx"
41 #if OSL_DEBUG_LEVEL == 0
42 # ifndef NDEBUG
43 # define NDEBUG
44 # endif
45 #endif
46 #include <assert.h>
48 using namespace com::sun::star::i18n;
49 using namespace com::sun::star::uno;
50 using namespace com::sun::star::lang;
51 using namespace com::sun::star;
52 using namespace rtl;
54 static const sal_Char clocaledata[] = "com.sun.star.i18n.LocaleData";
56 typedef sal_Unicode** (SAL_CALL * MyFunc_Type)( sal_Int16&);
57 typedef sal_Unicode*** (SAL_CALL * MyFunc_Type2)( sal_Int16&, sal_Int16& );
58 typedef sal_Unicode**** (SAL_CALL * MyFunc_Type3)( sal_Int16&, sal_Int16&, sal_Int16& );
59 typedef sal_Unicode const * const * (SAL_CALL * MyFunc_FormatCode)( sal_Int16&, sal_Unicode const *&, sal_Unicode const *& );
61 #ifdef OS2 // YD 8.3!!
62 static const char *lcl_DATA_EN = "ld_en";
63 static const char *lcl_DATA_ES = "ld_es";
64 static const char *lcl_DATA_EURO = "ld_eur";
65 static const char *lcl_DATA_OTHERS = "ld_oth";
66 #else
67 static const char *lcl_DATA_EN = "localedata_en";
68 static const char *lcl_DATA_ES = "localedata_es";
69 static const char *lcl_DATA_EURO = "localedata_euro";
70 static const char *lcl_DATA_OTHERS = "localedata_others";
71 #endif
73 static const struct {
74 const char* pLocale;
75 const char* pLib;
76 } aLibTable[] = {
77 { "en_US", lcl_DATA_EN },
78 { "en_AU", lcl_DATA_EN },
79 { "en_BZ", lcl_DATA_EN },
80 { "en_CA", lcl_DATA_EN },
81 { "en_GB", lcl_DATA_EN },
82 { "en_IE", lcl_DATA_EN },
83 { "en_JM", lcl_DATA_EN },
84 { "en_NZ", lcl_DATA_EN },
85 { "en_PH", lcl_DATA_EN },
86 { "en_TT", lcl_DATA_EN },
87 { "en_ZA", lcl_DATA_EN },
88 { "en_ZW", lcl_DATA_EN },
89 { "en_NA", lcl_DATA_EN },
90 { "en_GH", lcl_DATA_EN },
92 { "es_ES", lcl_DATA_ES },
93 { "es_AR", lcl_DATA_ES },
94 { "es_BO", lcl_DATA_ES },
95 { "es_CL", lcl_DATA_ES },
96 { "es_CO", lcl_DATA_ES },
97 { "es_CR", lcl_DATA_ES },
98 { "es_DO", lcl_DATA_ES },
99 { "es_EC", lcl_DATA_ES },
100 { "es_GT", lcl_DATA_ES },
101 { "es_HN", lcl_DATA_ES },
102 { "es_MX", lcl_DATA_ES },
103 { "es_NI", lcl_DATA_ES },
104 { "es_PA", lcl_DATA_ES },
105 { "es_PE", lcl_DATA_ES },
106 { "es_PR", lcl_DATA_ES },
107 { "es_PY", lcl_DATA_ES },
108 { "es_SV", lcl_DATA_ES },
109 { "es_UY", lcl_DATA_ES },
110 { "es_VE", lcl_DATA_ES },
111 { "gl_ES", lcl_DATA_ES },
113 { "de_DE", lcl_DATA_EURO },
114 { "de_AT", lcl_DATA_EURO },
115 { "de_CH", lcl_DATA_EURO },
116 { "de_LI", lcl_DATA_EURO },
117 { "de_LU", lcl_DATA_EURO },
118 { "fr_FR", lcl_DATA_EURO },
119 { "fr_BE", lcl_DATA_EURO },
120 { "fr_CA", lcl_DATA_EURO },
121 { "fr_CH", lcl_DATA_EURO },
122 { "fr_LU", lcl_DATA_EURO },
123 { "fr_MC", lcl_DATA_EURO },
124 { "it_IT", lcl_DATA_EURO },
125 { "it_CH", lcl_DATA_EURO },
126 { "sl_SI", lcl_DATA_EURO },
127 { "sv_SE", lcl_DATA_EURO },
128 { "sv_FI", lcl_DATA_EURO },
129 { "ca_ES", lcl_DATA_EURO },
130 { "cs_CZ", lcl_DATA_EURO },
131 { "sk_SK", lcl_DATA_EURO },
132 { "da_DK", lcl_DATA_EURO },
133 { "el_GR", lcl_DATA_EURO },
134 { "fi_FI", lcl_DATA_EURO },
135 { "is_IS", lcl_DATA_EURO },
136 { "nl_BE", lcl_DATA_EURO },
137 { "nl_NL", lcl_DATA_EURO },
138 { "no_NO", lcl_DATA_EURO },
139 { "nn_NO", lcl_DATA_EURO },
140 { "nb_NO", lcl_DATA_EURO },
141 { "pl_PL", lcl_DATA_EURO },
142 { "pt_BR", lcl_DATA_EURO },
143 { "pt_PT", lcl_DATA_EURO },
144 { "ru_RU", lcl_DATA_EURO },
145 { "tr_TR", lcl_DATA_EURO },
146 { "et_EE", lcl_DATA_EURO },
147 { "lb_LU", lcl_DATA_EURO },
148 { "lt_LT", lcl_DATA_EURO },
149 { "lv_LV", lcl_DATA_EURO },
150 { "uk_UA", lcl_DATA_EURO },
151 { "ro_RO", lcl_DATA_EURO },
152 { "cy_GB", lcl_DATA_EURO },
153 { "bg_BG", lcl_DATA_EURO },
154 { "sh_ME", lcl_DATA_EURO },
155 { "sh_RS", lcl_DATA_EURO },
156 { "sh_YU", lcl_DATA_EURO },
157 { "sr_ME", lcl_DATA_EURO },
158 { "sr_RS", lcl_DATA_EURO },
159 { "sr_YU", lcl_DATA_EURO },
160 { "hr_HR", lcl_DATA_EURO },
161 { "bs_BA", lcl_DATA_EURO },
162 { "eu", lcl_DATA_EURO },
163 { "fo_FO", lcl_DATA_EURO },
164 { "ga_IE", lcl_DATA_EURO },
165 { "ka_GE", lcl_DATA_EURO },
166 { "be_BY", lcl_DATA_EURO },
167 { "kl_GL", lcl_DATA_EURO },
168 { "mk_MK", lcl_DATA_EURO },
169 { "br_FR", lcl_DATA_EURO },
170 { "la_VA", lcl_DATA_EURO },
171 { "cv_RU", lcl_DATA_EURO },
172 { "wa_BE", lcl_DATA_EURO },
173 { "fur_IT", lcl_DATA_EURO },
174 { "gsc_FR", lcl_DATA_EURO },
175 { "fy_NL", lcl_DATA_EURO },
176 { "oc_FR", lcl_DATA_EURO },
177 { "mt_MT", lcl_DATA_EURO },
178 { "sc_IT", lcl_DATA_EURO },
179 { "ast_ES", lcl_DATA_EURO },
181 { "ja_JP", lcl_DATA_OTHERS },
182 { "ko_KR", lcl_DATA_OTHERS },
183 { "zh_CN", lcl_DATA_OTHERS },
184 { "zh_HK", lcl_DATA_OTHERS },
185 { "zh_SG", lcl_DATA_OTHERS },
186 { "zh_TW", lcl_DATA_OTHERS },
187 { "zh_MO", lcl_DATA_OTHERS },
189 { "ar_EG", lcl_DATA_OTHERS },
190 { "ar_LB", lcl_DATA_OTHERS },
191 { "ar_SA", lcl_DATA_OTHERS },
192 { "ar_TN", lcl_DATA_OTHERS },
193 { "he_IL", lcl_DATA_OTHERS },
194 { "hi_IN", lcl_DATA_OTHERS },
195 { "kn_IN", lcl_DATA_OTHERS },
196 { "ta_IN", lcl_DATA_OTHERS },
197 { "te_IN", lcl_DATA_OTHERS },
198 { "gu_IN", lcl_DATA_OTHERS },
199 { "mr_IN", lcl_DATA_OTHERS },
200 { "pa_IN", lcl_DATA_OTHERS },
201 { "bn_IN", lcl_DATA_OTHERS },
202 { "or_IN", lcl_DATA_OTHERS },
203 { "en_IN", lcl_DATA_OTHERS },
204 { "ml_IN", lcl_DATA_OTHERS },
205 { "bn_BD", lcl_DATA_OTHERS },
206 { "th_TH", lcl_DATA_OTHERS },
208 { "af_ZA", lcl_DATA_OTHERS },
209 { "hu_HU", lcl_DATA_OTHERS },
210 { "id_ID", lcl_DATA_OTHERS },
211 { "ms_MY", lcl_DATA_OTHERS },
212 { "ia", lcl_DATA_OTHERS },
213 { "mn_MN", lcl_DATA_OTHERS },
214 { "az_AZ", lcl_DATA_OTHERS },
215 { "sw_TZ", lcl_DATA_OTHERS },
216 { "km_KH", lcl_DATA_OTHERS },
217 { "lo_LA", lcl_DATA_OTHERS },
218 { "rw_RW", lcl_DATA_OTHERS },
219 { "eo", lcl_DATA_OTHERS },
220 { "dz_BT", lcl_DATA_OTHERS },
221 { "ne_NP", lcl_DATA_OTHERS },
222 { "zu_ZA", lcl_DATA_OTHERS },
223 { "nso_ZA", lcl_DATA_OTHERS },
224 { "vi_VN", lcl_DATA_OTHERS },
225 { "tn_ZA", lcl_DATA_OTHERS },
226 { "xh_ZA", lcl_DATA_OTHERS },
227 { "st_ZA", lcl_DATA_OTHERS },
228 { "ss_ZA", lcl_DATA_OTHERS },
229 { "ve_ZA", lcl_DATA_OTHERS },
230 { "nr_ZA", lcl_DATA_OTHERS },
231 { "ts_ZA", lcl_DATA_OTHERS },
232 { "ku_TR", lcl_DATA_OTHERS },
233 { "ak_GH", lcl_DATA_OTHERS },
234 { "af_NA", lcl_DATA_OTHERS },
235 { "am_ET", lcl_DATA_OTHERS },
236 { "ti_ER", lcl_DATA_OTHERS },
237 { "tg_TJ", lcl_DATA_OTHERS },
238 { "ky_KG", lcl_DATA_OTHERS },
239 { "kk_KZ", lcl_DATA_OTHERS },
240 { "fa_IR", lcl_DATA_OTHERS },
241 { "ha_GH", lcl_DATA_OTHERS },
242 { "ee_GH", lcl_DATA_OTHERS },
243 { "sg_CF", lcl_DATA_OTHERS },
244 { "lg_UG", lcl_DATA_OTHERS },
245 { "uz_UZ", lcl_DATA_OTHERS },
246 { "ln_CD", lcl_DATA_OTHERS },
247 { "hy_AM", lcl_DATA_OTHERS },
248 { "hil_PH", lcl_DATA_OTHERS },
249 { "so_SO", lcl_DATA_OTHERS },
250 { "gug_PY", lcl_DATA_OTHERS },
251 { "tk_TM", lcl_DATA_OTHERS },
252 { "my_MM", lcl_DATA_OTHERS },
253 { "shs_CA", lcl_DATA_OTHERS },
254 { "tpi_PG", lcl_DATA_OTHERS },
255 { "ar_OM", lcl_DATA_OTHERS },
256 { "ug_CN", lcl_DATA_OTHERS },
257 { "om_ET", lcl_DATA_OTHERS },
260 static const sal_Unicode under = sal_Unicode('_');
262 static const sal_Int16 nbOfLocales = sizeof(aLibTable) / sizeof(aLibTable[0]);
264 struct LocaleDataLookupTableItem
266 LocaleDataLookupTableItem(const sal_Char *name, osl::Module* m, const sal_Char* lname) : dllName(name), module(m), localeName(lname)
269 const sal_Char* dllName;
270 osl::Module *module;
271 const sal_Char* localeName;
273 com::sun::star::lang::Locale aLocale;
274 sal_Bool equals(const com::sun::star::lang::Locale& rLocale)
276 return (rLocale == aLocale);
280 LocaleData::LocaleData()
283 LocaleData::~LocaleData()
288 LocaleDataItem SAL_CALL
289 LocaleData::getLocaleItem( const Locale& rLocale ) throw(RuntimeException)
291 sal_Int16 dataItemCount = 0;
292 sal_Unicode **dataItem = NULL;
294 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getLocaleItem" );
296 if ( func ) {
297 dataItem = func(dataItemCount);
299 LocaleDataItem item(
300 dataItem[0],
301 dataItem[1],
302 dataItem[2],
303 dataItem[3],
304 dataItem[4],
305 dataItem[5],
306 dataItem[6],
307 dataItem[7],
308 dataItem[8],
309 dataItem[9],
310 dataItem[10],
311 dataItem[11],
312 dataItem[12],
313 dataItem[13],
314 dataItem[14],
315 dataItem[15],
316 dataItem[16],
317 dataItem[17]
319 return item;
321 else {
322 LocaleDataItem item1;
323 return item1;
327 extern "C" { static void SAL_CALL thisModule() {} }
329 namespace
332 // implement the lookup table as a safe static object
333 class lcl_LookupTableHelper
335 public:
336 lcl_LookupTableHelper();
337 ~lcl_LookupTableHelper();
339 oslGenericFunction SAL_CALL getFunctionSymbolByName(
340 const OUString& localeName, const sal_Char* pFunction,
341 LocaleDataLookupTableItem** pOutCachedItem );
343 private:
344 ::osl::Mutex maMutex;
345 ::std::vector< LocaleDataLookupTableItem* > maLookupTable;
348 // from instance.hxx: Helper base class for a late-initialized
349 // (default-constructed) static variable, implementing the double-checked
350 // locking pattern correctly.
351 // usage: lcl_LookupTableHelper & rLookupTable = lcl_LookupTableStatic::get();
352 // retrieves the singleton lookup table instance
353 struct lcl_LookupTableStatic : public ::rtl::Static< lcl_LookupTableHelper, lcl_LookupTableStatic >
356 lcl_LookupTableHelper::lcl_LookupTableHelper()
360 lcl_LookupTableHelper::~lcl_LookupTableHelper()
362 LocaleDataLookupTableItem* pItem = 0;
364 std::vector<LocaleDataLookupTableItem*>::const_iterator aEnd(maLookupTable.end());
365 std::vector<LocaleDataLookupTableItem*>::iterator aIter(maLookupTable.begin());
367 for ( ; aIter != aEnd; ++aIter ) {
368 pItem = *aIter;
369 delete pItem->module;
370 delete pItem;
372 maLookupTable.clear();
375 oslGenericFunction SAL_CALL lcl_LookupTableHelper::getFunctionSymbolByName(
376 const OUString& localeName, const sal_Char* pFunction,
377 LocaleDataLookupTableItem** pOutCachedItem )
379 OUString aFallback;
380 bool bFallback = (localeName.indexOf( under) < 0);
381 if (bFallback)
383 Locale aLocale;
384 aLocale.Language = localeName;
385 Locale aFbLocale = MsLangId::getFallbackLocale( aLocale);
386 if (aFbLocale == aLocale)
387 bFallback = false; // may be a "language-only-locale" like Interlingua (ia)
388 else if (aFbLocale.Country.getLength()) {
389 OUStringBuffer aBuf(5);
390 aFallback = aBuf.append(aFbLocale.Language).append( under).append(aFbLocale.Country).makeStringAndClear();
392 else
393 aFallback = aFbLocale.Language;
396 for ( sal_Int16 i = 0; i < nbOfLocales; i++)
398 if (localeName.equalsAscii(aLibTable[i].pLocale) ||
399 (bFallback && localeName == aFallback))
401 LocaleDataLookupTableItem* pCurrent = 0;
402 OUStringBuffer aBuf(strlen(aLibTable[i].pLocale) + 1 + strlen(pFunction));
404 ::osl::MutexGuard aGuard( maMutex );
405 for (size_t l = 0; l < maLookupTable.size(); l++)
407 pCurrent = maLookupTable[l];
408 if (pCurrent->dllName == aLibTable[i].pLib)
410 OSL_ASSERT( pOutCachedItem );
411 if( pOutCachedItem )
413 (*pOutCachedItem) = new LocaleDataLookupTableItem( *pCurrent );
414 (*pOutCachedItem)->localeName = aLibTable[i].pLocale;
415 return (*pOutCachedItem)->module->getFunctionSymbol(
416 aBuf.appendAscii( pFunction).append( under).
417 appendAscii( (*pOutCachedItem)->localeName).makeStringAndClear());
419 else
420 return NULL;
424 // Library not loaded, load it and add it to the list.
425 #ifdef SAL_DLLPREFIX
426 aBuf.ensureCapacity(strlen(aLibTable[i].pLib) + 6); // mostly "lib*.so"
427 aBuf.appendAscii( SAL_DLLPREFIX ).appendAscii(aLibTable[i].pLib).appendAscii( SAL_DLLEXTENSION );
428 #else
429 aBuf.ensureCapacity(strlen(aLibTable[i].pLib) + 4); // mostly "*.dll"
430 aBuf.appendAscii(aLibTable[i].pLib).appendAscii( SAL_DLLEXTENSION );
431 #endif
432 osl::Module *module = new osl::Module();
433 if ( module->loadRelative(&thisModule, aBuf.makeStringAndClear()) )
435 ::osl::MutexGuard aGuard( maMutex );
436 LocaleDataLookupTableItem* pNewItem = 0;
437 maLookupTable.push_back(pNewItem = new LocaleDataLookupTableItem(aLibTable[i].pLib, module, aLibTable[i].pLocale ));
438 OSL_ASSERT( pOutCachedItem );
439 if( pOutCachedItem )
441 (*pOutCachedItem) = new LocaleDataLookupTableItem( *pNewItem );
442 return module->getFunctionSymbol(
443 aBuf.appendAscii(pFunction).append(under).
444 appendAscii((*pOutCachedItem)->localeName).makeStringAndClear());
446 else
447 return NULL;
449 else
450 delete module;
453 return NULL;
456 } // anonymous namespace
458 #define REF_DAYS 0
459 #define REF_MONTHS 1
460 #define REF_ERAS 2
462 Sequence< CalendarItem > &LocaleData::getCalendarItemByName(const OUString& name,
463 const Locale& rLocale, const Sequence< Calendar >& calendarsSeq, sal_Int16 len, sal_Int16 item)
464 throw(RuntimeException)
466 if (!ref_name.equals(name)) {
467 sal_Int32 index = 0;
468 OUString language = name.getToken(0, under, index);
469 OUString country = name.getToken(0, under, index);
470 Locale loc(language, country, OUString());
471 Sequence < Calendar > cals;
472 if (loc == rLocale) {
473 cals = calendarsSeq;
474 } else {
475 cals = getAllCalendars(loc);
476 len = sal::static_int_cast<sal_Int16>( cals.getLength() );
478 const OUString& id = name.getToken(0, under, index);
479 for (index = 0; index < cals.getLength(); index++) {
480 if (id.equals(cals[index].Name)) {
481 ref_cal = cals[index];
482 break;
485 // Refered locale does not found, return name for en_US locale.
486 if (index == cals.getLength()) {
487 cals = getAllCalendars(
488 Locale(OUString::createFromAscii("en"), OUString::createFromAscii("US"), OUString()));
489 if (cals.getLength() > 0)
490 ref_cal = cals[0];
491 else
492 throw RuntimeException();
494 ref_name = name;
496 return item == REF_DAYS ? ref_cal.Days : item == REF_MONTHS ? ref_cal.Months : ref_cal.Eras;
500 Sequence< Calendar > SAL_CALL
501 LocaleData::getAllCalendars( const Locale& rLocale ) throw(RuntimeException)
504 sal_Int16 calendarsCount = 0;
505 sal_Unicode **allCalendars = NULL;
507 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getAllCalendars" );
509 if ( func ) {
510 allCalendars = func(calendarsCount);
512 Sequence< Calendar > calendarsSeq(calendarsCount);
513 sal_Int16 offset = 3;
514 sal_Int16 i, j;
515 for(i = 0; i < calendarsCount; i++) {
516 Sequence< CalendarItem > days(allCalendars[0][i]);
517 Sequence< CalendarItem > months(allCalendars[1][i]);
518 Sequence< CalendarItem > eras(allCalendars[2][i]);
519 OUString calendarID(allCalendars[offset]);
520 offset++;
521 sal_Bool defaultCalendar = sal::static_int_cast<sal_Bool>( allCalendars[offset][0] );
522 offset++;
523 if (OUString(allCalendars[offset]).equalsAscii("ref")) {
524 days = getCalendarItemByName(OUString(allCalendars[offset+1]), rLocale, calendarsSeq, i, REF_DAYS);
525 offset += 2;
526 } else {
527 for(j = 0; j < allCalendars[0][i]; j++) {
528 CalendarItem day(allCalendars[offset],
529 allCalendars[offset+1], allCalendars[offset+2]);
530 days[j] = day;
531 offset += 3;
534 if (OUString(allCalendars[offset]).equalsAscii("ref")) {
535 months = getCalendarItemByName(OUString(allCalendars[offset+1]), rLocale, calendarsSeq, i, REF_MONTHS);
536 offset += 2;
537 } else {
538 for(j = 0; j < allCalendars[1][i]; j++) {
539 CalendarItem month(allCalendars[offset],
540 allCalendars[offset+1], allCalendars[offset+2]);
541 months[j] = month;
542 offset += 3;
545 if (OUString(allCalendars[offset]).equalsAscii("ref")) {
546 eras = getCalendarItemByName(OUString(allCalendars[offset+1]), rLocale, calendarsSeq, i, REF_ERAS);
547 offset += 2;
548 } else {
549 for(j = 0; j < allCalendars[2][i]; j++) {
550 CalendarItem era(allCalendars[offset],
551 allCalendars[offset+1], allCalendars[offset+2]);
552 eras[j] = era;
553 offset += 3;
556 OUString startOfWeekDay(allCalendars[offset]);
557 offset++;
558 sal_Int16 minimalDaysInFirstWeek = allCalendars[offset][0];
559 offset++;
560 Calendar aCalendar(days, months, eras, startOfWeekDay,
561 minimalDaysInFirstWeek, defaultCalendar, calendarID);
562 calendarsSeq[i] = aCalendar;
564 return calendarsSeq;
566 else {
567 Sequence< Calendar > seq1(0);
568 return seq1;
573 Sequence< Currency2 > SAL_CALL
574 LocaleData::getAllCurrencies2( const Locale& rLocale ) throw(RuntimeException)
577 sal_Int16 currencyCount = 0;
578 sal_Unicode **allCurrencies = NULL;
580 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getAllCurrencies" );
582 if ( func ) {
583 allCurrencies = func(currencyCount);
585 Sequence< Currency2 > seq(currencyCount);
586 for(int i = 0, nOff = 0; i < currencyCount; i++, nOff += 8 ) {
587 Currency2 cur(
588 allCurrencies[nOff], // string ID
589 allCurrencies[nOff+1], // string Symbol
590 allCurrencies[nOff+2], // string BankSymbol
591 allCurrencies[nOff+3], // string Name
592 allCurrencies[nOff+4][0] != 0, // boolean Default
593 allCurrencies[nOff+5][0] != 0, // boolean UsedInCompatibleFormatCodes
594 allCurrencies[nOff+6][0], // short DecimalPlaces
595 allCurrencies[nOff+7][0] != 0 // boolean LegacyOnly
597 seq[i] = cur;
599 return seq;
601 else {
602 Sequence< Currency2 > seq1(0);
603 return seq1;
608 Sequence< Currency > SAL_CALL
609 LocaleData::getAllCurrencies( const Locale& rLocale ) throw(RuntimeException)
611 Sequence< Currency2 > aCur2( getAllCurrencies2( rLocale));
612 sal_Int32 nLen = aCur2.getLength();
613 Sequence< Currency > aCur1( nLen);
614 const Currency2* p2 = aCur2.getArray();
615 Currency* p1 = aCur1.getArray();
616 for (sal_Int32 i=0; i < nLen; ++i, ++p1, ++p2)
618 *p1 = *p2;
620 return aCur1;
624 // return a static (!) string resulting from replacing all occurrences of
625 // 'oldStr' string in 'formatCode' string with 'newStr' string
626 static const sal_Unicode * replace( sal_Unicode const * const formatCode, sal_Unicode const * const oldStr, sal_Unicode const * const newStr)
628 // make reasonable assumption of maximum length of formatCode.
629 #define MAX_FORMATCODE_LENTH 512
630 static sal_Unicode str[MAX_FORMATCODE_LENTH];
632 if (oldStr[0] == 0) // no replacement requires
633 return formatCode;
635 sal_Int32 i = 0, k = 0;
636 while (formatCode[i] > 0 && k < MAX_FORMATCODE_LENTH) {
637 sal_Int32 j = 0, last = k;
638 // search oldStr in formatCode
639 while (formatCode[i] > 0 && oldStr[j] > 0 && k < MAX_FORMATCODE_LENTH) {
640 str[k++] = formatCode[i];
641 if (formatCode[i++] != oldStr[j++])
642 break;
644 if (oldStr[j] == 0) {
645 // matched string found, do replacement
646 k = last; j = 0;
647 while (newStr[j] > 0 && k < MAX_FORMATCODE_LENTH)
648 str[k++] = newStr[j++];
651 if (k >= MAX_FORMATCODE_LENTH) // could not complete replacement, return original formatCode
652 return formatCode;
654 str[k] = 0;
655 return str;
658 Sequence< FormatElement > SAL_CALL
659 LocaleData::getAllFormats( const Locale& rLocale ) throw(RuntimeException)
661 const int SECTIONS = 2;
662 struct FormatSection
664 MyFunc_FormatCode func;
665 sal_Unicode const *from;
666 sal_Unicode const *to;
667 sal_Unicode const *const *formatArray;
668 sal_Int16 formatCount;
670 FormatSection() : func(0), from(0), to(0), formatArray(0), formatCount(0) {}
671 sal_Int16 getFunc( LocaleData& rLocaleData, const Locale& rL, const char* pName )
673 func = reinterpret_cast<MyFunc_FormatCode>( rLocaleData.getFunctionSymbol( rL, pName));
674 if (func)
675 formatArray = func( formatCount, from, to);
676 return formatCount;
678 } section[SECTIONS];
680 #if 0
681 // #i79398# wntmsci10 MSVC doesn't get this right with optimization.
682 const sal_Int32 formatCount = section[0].getFunc( *this, rLocale, "getAllFormats0")
683 + section[1].getFunc( *this, rLocale, "getAllFormats1");
684 #else
685 sal_Int32 formatCount = section[0].getFunc( *this, rLocale, "getAllFormats0");
686 formatCount += section[1].getFunc( *this, rLocale, "getAllFormats1");
687 #endif
688 Sequence< FormatElement > seq(formatCount);
689 sal_Int32 f = 0;
690 for (int s = 0; s < SECTIONS; ++s)
692 sal_Unicode const * const * const formatArray = section[s].formatArray;
693 if ( formatArray )
695 for (int i = 0, nOff = 0; i < section[s].formatCount; ++i, nOff += 7, ++f)
697 FormatElement elem(
698 replace( formatArray[nOff], section[s].from, section[s].to),
699 formatArray[nOff + 1],
700 formatArray[nOff + 2],
701 formatArray[nOff + 3],
702 formatArray[nOff + 4],
703 formatArray[nOff + 5][0],
704 sal::static_int_cast<sal_Bool>(formatArray[nOff + 6][0]));
705 seq[f] = elem;
709 return seq;
712 #define COLLATOR_OFFSET_ALGO 0
713 #define COLLATOR_OFFSET_DEFAULT 1
714 #define COLLATOR_OFFSET_RULE 2
715 #define COLLATOR_ELEMENTS 3
717 OUString SAL_CALL
718 LocaleData::getCollatorRuleByAlgorithm( const Locale& rLocale, const OUString& algorithm ) throw(RuntimeException)
720 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getCollatorImplementation" );
721 if ( func ) {
722 sal_Int16 collatorCount = 0;
723 sal_Unicode **collatorArray = func(collatorCount);
724 for(sal_Int16 i = 0; i < collatorCount; i++)
725 if (algorithm.equals(collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_ALGO]))
726 return OUString(collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_RULE]);
728 return OUString();
732 Sequence< Implementation > SAL_CALL
733 LocaleData::getCollatorImplementations( const Locale& rLocale ) throw(RuntimeException)
735 sal_Int16 collatorCount = 0;
736 sal_Unicode **collatorArray = NULL;
738 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getCollatorImplementation" );
740 if ( func ) {
741 collatorArray = func(collatorCount);
742 Sequence< Implementation > seq(collatorCount);
743 for(sal_Int16 i = 0; i < collatorCount; i++) {
744 Implementation impl(collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_ALGO],
745 sal::static_int_cast<sal_Bool>(
746 collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_DEFAULT][0]));
747 seq[i] = impl;
749 return seq;
751 else {
752 Sequence< Implementation > seq1(0);
753 return seq1;
757 Sequence< OUString > SAL_CALL
758 LocaleData::getCollationOptions( const Locale& rLocale ) throw(RuntimeException)
760 sal_Int16 optionsCount = 0;
761 sal_Unicode **optionsArray = NULL;
763 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getCollationOptions" );
765 if ( func ) {
766 optionsArray = func(optionsCount);
767 Sequence< OUString > seq(optionsCount);
768 for(sal_Int16 i = 0; i < optionsCount; i++) {
769 seq[i] = OUString( optionsArray[i] );
771 return seq;
773 else {
774 Sequence< OUString > seq1(0);
775 return seq1;
779 Sequence< OUString > SAL_CALL
780 LocaleData::getSearchOptions( const Locale& rLocale ) throw(RuntimeException)
782 sal_Int16 optionsCount = 0;
783 sal_Unicode **optionsArray = NULL;
785 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getSearchOptions" );
787 if ( func ) {
788 optionsArray = func(optionsCount);
789 Sequence< OUString > seq(optionsCount);
790 for(sal_Int16 i = 0; i < optionsCount; i++) {
791 seq[i] = OUString( optionsArray[i] );
793 return seq;
795 else {
796 Sequence< OUString > seq1(0);
797 return seq1;
801 sal_Unicode ** SAL_CALL
802 LocaleData::getIndexArray(const Locale& rLocale, sal_Int16& indexCount)
804 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getIndexAlgorithm" );
806 if (func)
807 return func(indexCount);
808 return NULL;
811 Sequence< OUString > SAL_CALL
812 LocaleData::getIndexAlgorithm( const Locale& rLocale ) throw(RuntimeException)
814 sal_Int16 indexCount = 0;
815 sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
817 if ( indexArray ) {
818 Sequence< OUString > seq(indexCount);
819 for(sal_Int16 i = 0; i < indexCount; i++) {
820 seq[i] = indexArray[i*5];
822 return seq;
824 else {
825 Sequence< OUString > seq1(0);
826 return seq1;
830 OUString SAL_CALL
831 LocaleData::getDefaultIndexAlgorithm( const Locale& rLocale ) throw(RuntimeException)
833 sal_Int16 indexCount = 0;
834 sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
836 if ( indexArray ) {
837 for(sal_Int16 i = 0; i < indexCount; i++) {
838 if (indexArray[i*5 + 3][0])
839 return OUString(indexArray[i*5]);
842 return OUString();
845 sal_Bool SAL_CALL
846 LocaleData::hasPhonetic( const Locale& rLocale ) throw(RuntimeException)
848 sal_Int16 indexCount = 0;
849 sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
851 if ( indexArray ) {
852 for(sal_Int16 i = 0; i < indexCount; i++) {
853 if (indexArray[i*5 + 4][0])
854 return sal_True;
857 return sal_False;
860 sal_Unicode ** SAL_CALL
861 LocaleData::getIndexArrayForAlgorithm(const Locale& rLocale, const OUString& algorithm)
863 sal_Int16 indexCount = 0;
864 sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
865 if ( indexArray ) {
866 for(sal_Int16 i = 0; i < indexCount; i++) {
867 if (algorithm.equals(indexArray[i*5]))
868 return indexArray+i*5;
871 return NULL;
874 sal_Bool SAL_CALL
875 LocaleData::isPhonetic( const Locale& rLocale, const OUString& algorithm ) throw(RuntimeException)
877 sal_Unicode **indexArray = getIndexArrayForAlgorithm(rLocale, algorithm);
878 return (indexArray && indexArray[4][0]) ? sal_True : sal_False;
881 OUString SAL_CALL
882 LocaleData::getIndexKeysByAlgorithm( const Locale& rLocale, const OUString& algorithm ) throw(RuntimeException)
884 sal_Unicode **indexArray = getIndexArrayForAlgorithm(rLocale, algorithm);
885 return indexArray ? OUString::createFromAscii("0-9")+OUString(indexArray[2]) : OUString();
888 OUString SAL_CALL
889 LocaleData::getIndexModuleByAlgorithm( const Locale& rLocale, const OUString& algorithm ) throw(RuntimeException)
891 sal_Unicode **indexArray = getIndexArrayForAlgorithm(rLocale, algorithm);
892 return indexArray ? OUString(indexArray[1]) : OUString();
895 Sequence< UnicodeScript > SAL_CALL
896 LocaleData::getUnicodeScripts( const Locale& rLocale ) throw(RuntimeException)
898 sal_Int16 scriptCount = 0;
899 sal_Unicode **scriptArray = NULL;
901 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getUnicodeScripts" );
903 if ( func ) {
904 scriptArray = func(scriptCount);
905 Sequence< UnicodeScript > seq(scriptCount);
906 for(sal_Int16 i = 0; i < scriptCount; i++) {
907 seq[i] = UnicodeScript( OUString(scriptArray[i]).toInt32() );
909 return seq;
911 else {
912 Sequence< UnicodeScript > seq1(0);
913 return seq1;
917 Sequence< OUString > SAL_CALL
918 LocaleData::getFollowPageWords( const Locale& rLocale ) throw(RuntimeException)
920 sal_Int16 wordCount = 0;
921 sal_Unicode **wordArray = NULL;
923 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getFollowPageWords" );
925 if ( func ) {
926 wordArray = func(wordCount);
927 Sequence< OUString > seq(wordCount);
928 for(sal_Int16 i = 0; i < wordCount; i++) {
929 seq[i] = OUString(wordArray[i]);
931 return seq;
933 else {
934 Sequence< OUString > seq1(0);
935 return seq1;
939 Sequence< OUString > SAL_CALL
940 LocaleData::getTransliterations( const Locale& rLocale ) throw(RuntimeException)
943 sal_Int16 transliterationsCount = 0;
944 sal_Unicode **transliterationsArray = NULL;
946 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getTransliterations" );
948 if ( func ) {
949 transliterationsArray = func(transliterationsCount);
951 Sequence< OUString > seq(transliterationsCount);
952 for(int i = 0; i < transliterationsCount; i++) {
953 OUString elem(transliterationsArray[i]);
954 seq[i] = elem;
956 return seq;
958 else {
959 Sequence< OUString > seq1(0);
960 return seq1;
967 LanguageCountryInfo SAL_CALL
968 LocaleData::getLanguageCountryInfo( const Locale& rLocale ) throw(RuntimeException)
970 sal_Int16 LCInfoCount = 0;
971 sal_Unicode **LCInfoArray = NULL;
973 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getLCInfo" );
975 if ( func ) {
976 LCInfoArray = func(LCInfoCount);
977 LanguageCountryInfo info(LCInfoArray[0],
978 LCInfoArray[1],
979 LCInfoArray[2],
980 LCInfoArray[3],
981 LCInfoArray[4]);
982 return info;
984 else {
985 LanguageCountryInfo info1;
986 return info1;
992 ForbiddenCharacters SAL_CALL
993 LocaleData::getForbiddenCharacters( const Locale& rLocale ) throw(RuntimeException)
995 sal_Int16 LCForbiddenCharactersCount = 0;
996 sal_Unicode **LCForbiddenCharactersArray = NULL;
998 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getForbiddenCharacters" );
1000 if ( func ) {
1001 LCForbiddenCharactersArray = func(LCForbiddenCharactersCount);
1002 ForbiddenCharacters chars(LCForbiddenCharactersArray[0], LCForbiddenCharactersArray[1]);
1003 return chars;
1005 else {
1006 ForbiddenCharacters chars1;
1007 return chars1;
1011 OUString SAL_CALL
1012 LocaleData::getHangingCharacters( const Locale& rLocale ) throw(RuntimeException)
1014 sal_Int16 LCForbiddenCharactersCount = 0;
1015 sal_Unicode **LCForbiddenCharactersArray = NULL;
1017 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getForbiddenCharacters" );
1019 if ( func ) {
1020 LCForbiddenCharactersArray = func(LCForbiddenCharactersCount);
1021 return OUString(LCForbiddenCharactersArray[2]);
1024 return OUString();
1027 Sequence< OUString > SAL_CALL
1028 LocaleData::getBreakIteratorRules( const Locale& rLocale ) throw(RuntimeException)
1030 sal_Int16 LCBreakIteratorRuleCount = 0;
1031 sal_Unicode **LCBreakIteratorRulesArray = NULL;
1033 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getBreakIteratorRules" );
1035 if ( func ) {
1036 LCBreakIteratorRulesArray = func(LCBreakIteratorRuleCount);
1037 Sequence< OUString > seq(LCBreakIteratorRuleCount);
1038 for(int i = 0; i < (LCBreakIteratorRuleCount); i++) {
1039 OUString elem(LCBreakIteratorRulesArray[i]);
1040 seq[i] = elem;
1042 return seq;
1044 else {
1045 Sequence< OUString > seq1(0);
1046 return seq1;
1051 Sequence< OUString > SAL_CALL
1052 LocaleData::getReservedWord( const Locale& rLocale ) throw(RuntimeException)
1054 sal_Int16 LCReservedWordsCount = 0;
1055 sal_Unicode **LCReservedWordsArray = NULL;
1057 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getReservedWords" );
1059 if ( func ) {
1060 LCReservedWordsArray = func(LCReservedWordsCount);
1061 Sequence< OUString > seq(LCReservedWordsCount);
1062 for(int i = 0; i < (LCReservedWordsCount); i++) {
1063 OUString elem(LCReservedWordsArray[i]);
1064 seq[i] = elem;
1066 return seq;
1068 else {
1069 Sequence< OUString > seq1(0);
1070 return seq1;
1075 inline
1076 OUString C2U( const char* s )
1078 return OUString::createFromAscii( s );
1081 Sequence< Sequence<beans::PropertyValue> > SAL_CALL
1082 LocaleData::getContinuousNumberingLevels( const lang::Locale& rLocale ) throw(RuntimeException)
1084 int i;
1086 // load symbol
1087 MyFunc_Type2 func = (MyFunc_Type2) getFunctionSymbol( rLocale, "getContinuousNumberingLevels" );
1089 if ( func )
1091 // invoke function
1092 sal_Int16 nStyles;
1093 sal_Int16 nAttributes;
1094 sal_Unicode*** p0 = func( nStyles, nAttributes );
1096 // allocate memory for nAttributes attributes for each of the nStyles styles.
1097 Sequence< Sequence<beans::PropertyValue> > pv( nStyles );
1098 for( i=0; i<pv.getLength(); i++ ) {
1099 pv[i] = Sequence<beans::PropertyValue>( nAttributes );
1102 sal_Unicode*** pStyle = p0;
1103 for( i=0; i<nStyles; i++ ) {
1104 sal_Unicode** pAttribute = pStyle[i];
1105 for( int j=0; j<nAttributes; j++ ) { // prefix, numberingtype, ...
1106 sal_Unicode* pString = pAttribute[j];
1107 beans::PropertyValue& rVal = pv[i][j];
1108 OUString sVal;
1109 if( pString ) {
1110 if( 0 != j && 2 != j )
1111 sVal = pString;
1112 else if( *pString )
1113 sVal = OUString( pString, 1 );
1116 switch( j )
1118 case 0:
1119 rVal.Name = C2U("Prefix");
1120 rVal.Value <<= sVal;
1121 break;
1122 case 1:
1123 rVal.Name = C2U("NumberingType");
1124 rVal.Value <<= (sal_Int16) sVal.toInt32();
1125 break;
1126 case 2:
1127 rVal.Name = C2U("Suffix");
1128 rVal.Value <<= sVal;
1129 break;
1130 case 3:
1131 rVal.Name = C2U("Transliteration");
1132 rVal.Value <<= sVal;
1133 break;
1134 case 4:
1135 rVal.Name = C2U("NatNum");
1136 rVal.Value <<= (sal_Int16) sVal.toInt32();
1137 break;
1138 default:
1139 assert(0);
1143 return pv;
1146 Sequence< Sequence<beans::PropertyValue> > seq1(0);
1147 return seq1;
1150 // ============================================================================
1151 // \/ OutlineNumbering helper class \/
1153 #include <com/sun/star/container/XIndexAccess.hpp>
1154 #include <cppuhelper/implbase1.hxx>
1156 namespace com{ namespace sun{ namespace star{ namespace lang {
1157 struct Locale;
1158 }}}}
1159 //-----------------------------------------------------------------------------
1160 struct OutlineNumberingLevel_Impl
1162 OUString sPrefix;
1163 sal_Int16 nNumType; //com::sun::star::style::NumberingType
1164 OUString sSuffix;
1165 sal_Unicode cBulletChar;
1166 const sal_Char* sBulletFontName;
1167 sal_Int16 nParentNumbering;
1168 sal_Int32 nLeftMargin;
1169 sal_Int32 nSymbolTextDistance;
1170 sal_Int32 nFirstLineOffset;
1171 OUString sTransliteration;
1172 sal_Int32 nNatNum;
1174 //-----------------------------------------------------------------------------
1175 class OutlineNumbering : public cppu::WeakImplHelper1 < container::XIndexAccess >
1177 const OutlineNumberingLevel_Impl* m_pOutlineLevels;
1178 sal_Int16 m_nCount;
1179 public:
1180 // OutlineNumbering(const OutlineNumberingLevel_Impl* pOutlineLevels);
1181 OutlineNumbering(const OutlineNumberingLevel_Impl* pOutlineLevels, int nLevels);
1182 ~OutlineNumbering();
1184 //XIndexAccess
1185 virtual sal_Int32 SAL_CALL getCount( ) throw(RuntimeException);
1186 virtual Any SAL_CALL getByIndex( sal_Int32 Index )
1187 throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException);
1189 //XElementAccess
1190 virtual Type SAL_CALL getElementType( ) throw(RuntimeException);
1191 virtual sal_Bool SAL_CALL hasElements( ) throw(RuntimeException);
1195 // OutlineNumbering helper class
1196 // ============================================================================
1198 static
1199 sal_Char* U2C( OUString str )
1201 sal_Char* s = new sal_Char[ str.getLength()+1 ];
1202 int i;
1203 for( i = 0; i < str.getLength(); i++)
1204 s[i] = sal::static_int_cast<sal_Char>( str[i] );
1205 s[i]='\0';
1206 return s;
1210 Sequence< Reference<container::XIndexAccess> > SAL_CALL
1211 LocaleData::getOutlineNumberingLevels( const lang::Locale& rLocale ) throw(RuntimeException)
1213 int i;
1215 // load symbol
1216 MyFunc_Type3 func = (MyFunc_Type3) getFunctionSymbol( rLocale, "getOutlineNumberingLevels" );
1218 if ( func )
1220 // invoke function
1221 sal_Int16 nStyles;
1222 sal_Int16 nLevels;
1223 sal_Int16 nAttributes;
1224 sal_Unicode**** p0 = func( nStyles, nLevels, nAttributes );
1226 Sequence< Reference<container::XIndexAccess> > aRet( nStyles );
1228 OUString aEmptyStr;
1230 sal_Unicode**** pStyle = p0;
1231 for( i=0; i<nStyles; i++ )
1233 int j;
1235 OutlineNumberingLevel_Impl* level = new OutlineNumberingLevel_Impl[ nLevels+1 ];
1236 sal_Unicode*** pLevel = pStyle[i];
1237 for( j = 0; j < nLevels; j++ )
1239 sal_Unicode** pAttribute = pLevel[j];
1240 for( int k=0; k<nAttributes; k++ )
1242 OUString tmp( pAttribute[k] );
1243 switch( k )
1245 case 0: level[j].sPrefix = tmp; break;
1246 case 1: level[j].nNumType = sal::static_int_cast<sal_Int16>(tmp.toInt32()); break;
1247 case 2: level[j].sSuffix = tmp; break;
1248 //case 3: level[j].cBulletChar = tmp.toChar(); break;
1249 case 3: level[j].cBulletChar = sal::static_int_cast<sal_Unicode>(tmp.toInt32(16)); break; // base 16
1250 case 4: level[j].sBulletFontName = U2C( tmp ); break;
1251 case 5: level[j].nParentNumbering = sal::static_int_cast<sal_Int16>(tmp.toInt32()); break;
1252 case 6: level[j].nLeftMargin = tmp.toInt32(); break;
1253 case 7: level[j].nSymbolTextDistance = tmp.toInt32(); break;
1254 case 8: level[j].nFirstLineOffset = tmp.toInt32(); break;
1255 case 9: // Adjust
1256 // these values seem to be hard-coded elsewhere:
1257 // level[j].Value <<= (sal_Int16) text::HoriOrientation::LEFT;
1258 // level[j].Value <<= (sal_Int16) style::HorizontalAlignment::LEFT;
1259 break;
1260 case 10: level[j].sTransliteration = tmp; break;
1261 case 11: level[j].nNatNum = tmp.toInt32(); break;
1262 default:
1263 assert(0);
1267 level[j].sPrefix = aEmptyStr;
1268 level[j].nNumType = 0;
1269 level[j].sSuffix = aEmptyStr;
1270 level[j].cBulletChar = 0;
1271 level[j].sBulletFontName = 0;
1272 level[j].nParentNumbering = 0;
1273 level[j].nLeftMargin = 0;
1274 level[j].nSymbolTextDistance = 0;
1275 level[j].nFirstLineOffset = 0;
1276 level[j].sTransliteration = aEmptyStr;
1277 level[j].nNatNum = 0;
1278 aRet[i] = new OutlineNumbering( level, nLevels );
1280 return aRet;
1282 else {
1283 Sequence< Reference<container::XIndexAccess> > seq1(0);
1284 return seq1;
1288 /////////////////////////////////////////////////////////////////////////////////////////////
1289 //////////////////////////////////helper functions///////////////////////////////////////////
1290 /////////////////////////////////////////////////////////////////////////////////////////////
1292 oslGenericFunction SAL_CALL LocaleData::getFunctionSymbol( const Locale& rLocale, const sal_Char* pFunction )
1293 throw(RuntimeException)
1295 lcl_LookupTableHelper & rLookupTable = lcl_LookupTableStatic::get();
1297 OUStringBuffer aBuf(1);
1298 if (cachedItem.get() && cachedItem->equals(rLocale)) {
1299 aBuf.ensureCapacity(strlen(pFunction) + 1 + strlen(cachedItem->localeName));
1300 return cachedItem->module->getFunctionSymbol(aBuf.appendAscii(pFunction).append(under).
1301 appendAscii(cachedItem->localeName).makeStringAndClear());
1304 oslGenericFunction pSymbol = 0;
1305 static OUString tw(OUString::createFromAscii("TW"));
1306 static OUString en_US(OUString::createFromAscii("en_US"));
1308 sal_Int32 l = rLocale.Language.getLength();
1309 sal_Int32 c = rLocale.Country.getLength();
1310 sal_Int32 v = rLocale.Variant.getLength();
1311 aBuf.ensureCapacity(l+c+v+3);
1313 LocaleDataLookupTableItem *pCachedItem = 0;
1315 if ((l > 0 && c > 0 && v > 0 &&
1316 // load function with name <func>_<lang>_<country>_<varian>
1317 (pSymbol = rLookupTable.getFunctionSymbolByName(aBuf.append(rLocale.Language).append(under).append(
1318 rLocale.Country).append(under).append(rLocale.Variant).makeStringAndClear(), pFunction, &pCachedItem)) != 0) ||
1319 (l > 0 && c > 0 &&
1320 // load function with name <ase>_<lang>_<country>
1321 (pSymbol = rLookupTable.getFunctionSymbolByName(aBuf.append(rLocale.Language).append(under).append(
1322 rLocale.Country).makeStringAndClear(), pFunction, &pCachedItem)) != 0) ||
1323 (l > 0 && c > 0 && rLocale.Language.equalsAscii("zh") &&
1324 (rLocale.Country.equalsAscii("HK") ||
1325 rLocale.Country.equalsAscii("MO")) &&
1326 // if the country code is HK or MO, one more step to try TW.
1327 (pSymbol = rLookupTable.getFunctionSymbolByName(aBuf.append(rLocale.Language).append(under).append(tw).makeStringAndClear(),
1328 pFunction, &pCachedItem)) != 0) ||
1329 (l > 0 &&
1330 // load function with name <func>_<lang>
1331 (pSymbol = rLookupTable.getFunctionSymbolByName(rLocale.Language, pFunction, &pCachedItem)) != 0) ||
1332 // load default function with name <func>_en_US
1333 (pSymbol = rLookupTable.getFunctionSymbolByName(en_US, pFunction, &pCachedItem)) != 0)
1335 if( pCachedItem )
1336 cachedItem.reset( pCachedItem );
1337 if( cachedItem.get())
1338 cachedItem->aLocale = rLocale;
1339 return pSymbol;
1341 throw RuntimeException();
1344 Sequence< Locale > SAL_CALL
1345 LocaleData::getAllInstalledLocaleNames() throw(RuntimeException)
1347 Sequence< lang::Locale > seq( nbOfLocales );
1348 OUString empStr;
1349 sal_Int16 nInstalled = 0;
1351 for( sal_Int16 i=0; i<nbOfLocales; i++ ) {
1352 OUString name = OUString::createFromAscii( aLibTable[i].pLocale );
1354 // Check if the locale is really available and not just in the table,
1355 // don't allow fall backs.
1356 LocaleDataLookupTableItem *pCachedItem = 0;
1357 if (lcl_LookupTableStatic::get().getFunctionSymbolByName( name, "getLocaleItem", &pCachedItem )) {
1358 if( pCachedItem )
1359 cachedItem.reset( pCachedItem );
1360 sal_Int32 index = 0;
1361 lang::Locale tmpLocale(name.getToken(0, under, index), empStr, empStr);
1362 if (index >= 0) {
1363 tmpLocale.Country = name.getToken(0, under, index);
1364 if (index >= 0)
1365 tmpLocale.Variant = name.getToken(0, under, index);
1367 seq[nInstalled++] = tmpLocale;
1370 if ( nInstalled < nbOfLocales )
1371 seq.realloc( nInstalled ); // reflect reality
1373 return seq;
1376 // ============================================================================
1378 using namespace ::com::sun::star::container;
1379 using namespace ::com::sun::star::beans;
1380 using namespace ::com::sun::star::style;
1381 using namespace ::com::sun::star::text;
1383 // // bad: can't have empty prefix ...
1384 // OutlineNumbering::OutlineNumbering(const OutlineNumberingLevel_Impl* pOutlnLevels) :
1385 // m_pOutlineLevels(pOutlnLevels),
1386 // m_nCount(0)
1387 // {
1388 // const OutlineNumberingLevel_Impl* pTemp = m_pOutlineLevels;
1389 // while((pTemp++)->sPrefix)
1390 // m_nCount++;
1391 // }
1393 OutlineNumbering::OutlineNumbering(const OutlineNumberingLevel_Impl* pOutlnLevels, int nLevels) :
1394 m_pOutlineLevels(pOutlnLevels),
1395 m_nCount(sal::static_int_cast<sal_Int16>(nLevels))
1399 OutlineNumbering::~OutlineNumbering()
1401 delete [] m_pOutlineLevels;
1404 sal_Int32 OutlineNumbering::getCount( ) throw(RuntimeException)
1406 return m_nCount;
1409 Any OutlineNumbering::getByIndex( sal_Int32 nIndex )
1410 throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
1412 if(nIndex < 0 || nIndex >= m_nCount)
1413 throw IndexOutOfBoundsException();
1414 const OutlineNumberingLevel_Impl* pTemp = m_pOutlineLevels;
1415 pTemp += nIndex;
1416 Any aRet;
1418 Sequence<PropertyValue> aOutlineNumbering(12);
1419 PropertyValue* pValues = aOutlineNumbering.getArray();
1420 pValues[0].Name = C2U( "Prefix");
1421 pValues[0].Value <<= pTemp->sPrefix;
1422 pValues[1].Name = C2U("NumberingType");
1423 pValues[1].Value <<= pTemp->nNumType;
1424 pValues[2].Name = C2U("Suffix");
1425 pValues[2].Value <<= pTemp->sSuffix;
1426 pValues[3].Name = C2U("BulletChar");
1427 pValues[3].Value <<= OUString(&pTemp->cBulletChar, 1);
1428 pValues[4].Name = C2U("BulletFontName");
1429 pValues[4].Value <<= C2U(pTemp->sBulletFontName);
1430 pValues[5].Name = C2U("ParentNumbering");
1431 pValues[5].Value <<= pTemp->nParentNumbering;
1432 pValues[6].Name = C2U("LeftMargin");
1433 pValues[6].Value <<= pTemp->nLeftMargin;
1434 pValues[7].Name = C2U("SymbolTextDistance");
1435 pValues[7].Value <<= pTemp->nSymbolTextDistance;
1436 pValues[8].Name = C2U("FirstLineOffset");
1437 pValues[8].Value <<= pTemp->nFirstLineOffset;
1438 pValues[9].Name = C2U("Adjust");
1439 pValues[9].Value <<= (sal_Int16)HoriOrientation::LEFT;
1440 pValues[10].Name = C2U("Transliteration");
1441 pValues[10].Value <<= pTemp->sTransliteration;
1442 pValues[11].Name = C2U("NatNum");
1443 pValues[11].Value <<= pTemp->nNatNum;
1444 aRet <<= aOutlineNumbering;
1445 return aRet;
1448 Type OutlineNumbering::getElementType( ) throw(RuntimeException)
1450 return ::getCppuType((Sequence<PropertyValue>*)0);
1453 sal_Bool OutlineNumbering::hasElements( ) throw(RuntimeException)
1455 return m_nCount > 0;
1458 OUString SAL_CALL
1459 LocaleData::getImplementationName() throw( RuntimeException )
1461 return OUString::createFromAscii(clocaledata);
1464 sal_Bool SAL_CALL
1465 LocaleData::supportsService(const OUString& rServiceName)
1466 throw( RuntimeException )
1468 return !rServiceName.compareToAscii(clocaledata);
1471 Sequence< OUString > SAL_CALL
1472 LocaleData::getSupportedServiceNames() throw( RuntimeException )
1474 Sequence< OUString > aRet(1);
1475 aRet[0] = OUString::createFromAscii(clocaledata);
1476 return aRet;