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_i18npool.hxx"
26
27 #include <localedata.hxx>
28 #include <i18npool/mslangid.hxx>
29 #include <rtl/ustrbuf.hxx>
30 #include <string.h>
31 #include <stdio.h>
32 #include "rtl/instance.hxx"
33
34 using namespace com::sun::star::i18n;
35 using namespace com::sun::star::uno;
36 using namespace com::sun::star::lang;
37 using namespace com::sun::star;
38 using namespace rtl;
39
40 static const sal_Char clocaledata[] = "com.sun.star.i18n.LocaleData";
41
42 typedef sal_Unicode** (SAL_CALL * MyFunc_Type)( sal_Int16&);
43 typedef sal_Unicode*** (SAL_CALL * MyFunc_Type2)( sal_Int16&, sal_Int16& );
44 typedef sal_Unicode**** (SAL_CALL * MyFunc_Type3)( sal_Int16&, sal_Int16&, sal_Int16& );
45 typedef sal_Unicode const * const * (SAL_CALL * MyFunc_FormatCode)( sal_Int16&, sal_Unicode const *&, sal_Unicode const *& );
46
47 #ifdef OS2 // YD 8.3!!
48 static const char *lcl_DATA_EN = "ld_en";
49 static const char *lcl_DATA_ES = "ld_es";
50 static const char *lcl_DATA_EURO = "ld_eur";
51 static const char *lcl_DATA_OTHERS = "ld_oth";
52 #else
53 static const char *lcl_DATA_EN = "localedata_en";
54 static const char *lcl_DATA_ES = "localedata_es";
55 static const char *lcl_DATA_EURO = "localedata_euro";
56 static const char *lcl_DATA_OTHERS = "localedata_others";
57 #endif
58
59 static const struct {
60 const char* pLocale;
61 const char* pLib;
62 } aLibTable[] = {
63 { "en_US", lcl_DATA_EN },
64 { "en_AU", lcl_DATA_EN },
65 { "en_BZ", lcl_DATA_EN },
66 { "en_CA", lcl_DATA_EN },
67 { "en_GB", lcl_DATA_EN },
68 { "en_IE", lcl_DATA_EN },
69 { "en_JM", lcl_DATA_EN },
70 { "en_NZ", lcl_DATA_EN },
71 { "en_PH", lcl_DATA_EN },
72 { "en_TT", lcl_DATA_EN },
73 { "en_ZA", lcl_DATA_EN },
74 { "en_ZW", lcl_DATA_EN },
75 { "en_NA", lcl_DATA_EN },
76 { "en_GH", lcl_DATA_EN },
77
78 { "es_ES", lcl_DATA_ES },
79 { "es_AR", lcl_DATA_ES },
80 { "es_BO", lcl_DATA_ES },
81 { "es_CL", lcl_DATA_ES },
82 { "es_CO", lcl_DATA_ES },
83 { "es_CR", lcl_DATA_ES },
84 { "es_DO", lcl_DATA_ES },
85 { "es_EC", lcl_DATA_ES },
86 { "es_GT", lcl_DATA_ES },
87 { "es_HN", lcl_DATA_ES },
88 { "es_MX", lcl_DATA_ES },
89 { "es_NI", lcl_DATA_ES },
90 { "es_PA", lcl_DATA_ES },
91 { "es_PE", lcl_DATA_ES },
92 { "es_PR", lcl_DATA_ES },
93 { "es_PY", lcl_DATA_ES },
94 { "es_SV", lcl_DATA_ES },
95 { "es_UY", lcl_DATA_ES },
96 { "es_VE", lcl_DATA_ES },
97 { "gl_ES", lcl_DATA_ES },
98
99 { "de_DE", lcl_DATA_EURO },
100 { "de_AT", lcl_DATA_EURO },
101 { "de_CH", lcl_DATA_EURO },
102 { "de_LI", lcl_DATA_EURO },
103 { "de_LU", lcl_DATA_EURO },
104 { "fr_FR", lcl_DATA_EURO },
105 { "fr_BE", lcl_DATA_EURO },
106 { "fr_CA", lcl_DATA_EURO },
107 { "fr_CH", lcl_DATA_EURO },
108 { "fr_LU", lcl_DATA_EURO },
109 { "fr_MC", lcl_DATA_EURO },
110 { "it_IT", lcl_DATA_EURO },
111 { "it_CH", lcl_DATA_EURO },
112 { "sl_SI", lcl_DATA_EURO },
113 { "sv_SE", lcl_DATA_EURO },
114 { "sv_FI", lcl_DATA_EURO },
115 { "ca_ES", lcl_DATA_EURO },
116 { "cs_CZ", lcl_DATA_EURO },
117 { "sk_SK", lcl_DATA_EURO },
118 { "da_DK", lcl_DATA_EURO },
119 { "el_GR", lcl_DATA_EURO },
120 { "fi_FI", lcl_DATA_EURO },
121 { "is_IS", lcl_DATA_EURO },
122 { "nl_BE", lcl_DATA_EURO },
123 { "nl_NL", lcl_DATA_EURO },
124 { "no_NO", lcl_DATA_EURO },
125 { "nn_NO", lcl_DATA_EURO },
126 { "nb_NO", lcl_DATA_EURO },
127 { "nds_DE", lcl_DATA_EURO },
128 { "pl_PL", lcl_DATA_EURO },
129 { "pt_BR", lcl_DATA_EURO },
130 { "pt_PT", lcl_DATA_EURO },
131 { "ru_RU", lcl_DATA_EURO },
132 { "tr_TR", lcl_DATA_EURO },
133 { "tt_RU", lcl_DATA_EURO },
134 { "et_EE", lcl_DATA_EURO },
135 { "lb_LU", lcl_DATA_EURO },
136 { "lt_LT", lcl_DATA_EURO },
137 { "lv_LV", lcl_DATA_EURO },
138 { "uk_UA", lcl_DATA_EURO },
139 { "ro_RO", lcl_DATA_EURO },
140 { "cy_GB", lcl_DATA_EURO },
141 { "bg_BG", lcl_DATA_EURO },
142 { "sh_ME", lcl_DATA_EURO },
143 { "sh_RS", lcl_DATA_EURO },
144 { "sh_YU", lcl_DATA_EURO },
145 { "sr_ME", lcl_DATA_EURO },
146 { "sr_RS", lcl_DATA_EURO },
147 { "sr_YU", lcl_DATA_EURO },
148 { "hr_HR", lcl_DATA_EURO },
149 { "bs_BA", lcl_DATA_EURO },
150 { "eu", lcl_DATA_EURO },
151 { "fo_FO", lcl_DATA_EURO },
152 { "ga_IE", lcl_DATA_EURO },
153 { "gd_GB", lcl_DATA_EURO },
154 { "ka_GE", lcl_DATA_EURO },
155 { "be_BY", lcl_DATA_EURO },
156 { "kl_GL", lcl_DATA_EURO },
157 { "mk_MK", lcl_DATA_EURO },
158 { "br_FR", lcl_DATA_EURO },
159 { "la_VA", lcl_DATA_EURO },
160 { "cv_RU", lcl_DATA_EURO },
161 { "wa_BE", lcl_DATA_EURO },
162 { "fur_IT", lcl_DATA_EURO },
163 { "gsc_FR", lcl_DATA_EURO },
164 { "fy_NL", lcl_DATA_EURO },
165 { "oc_FR", lcl_DATA_EURO },
166 { "mt_MT", lcl_DATA_EURO },
167 { "sc_IT", lcl_DATA_EURO },
168 { "ast_ES", lcl_DATA_EURO },
169 { "ltg_LV", lcl_DATA_EURO },
170 { "hsb_DE", lcl_DATA_EURO },
171 { "dsb_DE", lcl_DATA_EURO },
172 { "rue_SK", lcl_DATA_EURO },
173
174 { "ja_JP", lcl_DATA_OTHERS },
175 { "ko_KR", lcl_DATA_OTHERS },
176 { "zh_CN", lcl_DATA_OTHERS },
177 { "zh_HK", lcl_DATA_OTHERS },
178 { "zh_SG", lcl_DATA_OTHERS },
179 { "zh_TW", lcl_DATA_OTHERS },
180 { "zh_MO", lcl_DATA_OTHERS },
181
182 { "ar_EG", lcl_DATA_OTHERS },
183 { "ar_DZ", lcl_DATA_OTHERS },
184 { "ar_LB", lcl_DATA_OTHERS },
185 { "ar_SA", lcl_DATA_OTHERS },
186 { "ar_TN", lcl_DATA_OTHERS },
187 { "he_IL", lcl_DATA_OTHERS },
188 { "hi_IN", lcl_DATA_OTHERS },
189 { "kn_IN", lcl_DATA_OTHERS },
190 { "ta_IN", lcl_DATA_OTHERS },
191 { "te_IN", lcl_DATA_OTHERS },
192 { "gu_IN", lcl_DATA_OTHERS },
193 { "mr_IN", lcl_DATA_OTHERS },
194 { "pa_IN", lcl_DATA_OTHERS },
195 { "bn_IN", lcl_DATA_OTHERS },
196 { "or_IN", lcl_DATA_OTHERS },
197 { "en_IN", lcl_DATA_OTHERS },
198 { "ml_IN", lcl_DATA_OTHERS },
199 { "bn_BD", lcl_DATA_OTHERS },
200 { "th_TH", lcl_DATA_OTHERS },
201
202 { "af_ZA", lcl_DATA_OTHERS },
203 { "hu_HU", lcl_DATA_OTHERS },
204 { "id_ID", lcl_DATA_OTHERS },
205 { "ms_MY", lcl_DATA_OTHERS },
206 { "ia", lcl_DATA_OTHERS },
207 { "mn_MN", lcl_DATA_OTHERS },
208 { "az_AZ", lcl_DATA_OTHERS },
209 { "sw_TZ", lcl_DATA_OTHERS },
210 { "km_KH", lcl_DATA_OTHERS },
211 { "lo_LA", lcl_DATA_OTHERS },
212 { "rw_RW", lcl_DATA_OTHERS },
213 { "eo", lcl_DATA_OTHERS },
214 { "dz_BT", lcl_DATA_OTHERS },
215 { "ne_NP", lcl_DATA_OTHERS },
216 { "zu_ZA", lcl_DATA_OTHERS },
217 { "nso_ZA", lcl_DATA_OTHERS },
218 { "vi_VN", lcl_DATA_OTHERS },
219 { "tn_ZA", lcl_DATA_OTHERS },
220 { "xh_ZA", lcl_DATA_OTHERS },
221 { "st_ZA", lcl_DATA_OTHERS },
222 { "ss_ZA", lcl_DATA_OTHERS },
223 { "ve_ZA", lcl_DATA_OTHERS },
224 { "nr_ZA", lcl_DATA_OTHERS },
225 { "ts_ZA", lcl_DATA_OTHERS },
226 { "ku_TR", lcl_DATA_OTHERS },
227 { "ak_GH", lcl_DATA_OTHERS },
228 { "af_NA", lcl_DATA_OTHERS },
229 { "am_ET", lcl_DATA_OTHERS },
230 { "ti_ER", lcl_DATA_OTHERS },
231 { "tg_TJ", lcl_DATA_OTHERS },
232 { "kab_DZ", lcl_DATA_OTHERS },
233 { "kk_KZ", lcl_DATA_OTHERS },
234 { "ky_KG", lcl_DATA_OTHERS },
235 { "fa_IR", lcl_DATA_OTHERS },
236 { "ha_GH", lcl_DATA_OTHERS },
237 { "ee_GH", lcl_DATA_OTHERS },
238 { "sg_CF", lcl_DATA_OTHERS },
239 { "lg_UG", lcl_DATA_OTHERS },
240 { "uz_UZ", lcl_DATA_OTHERS },
241 { "ln_CD", lcl_DATA_OTHERS },
242 { "hy_AM", lcl_DATA_OTHERS },
243 { "hil_PH", lcl_DATA_OTHERS },
244 { "so_SO", lcl_DATA_OTHERS },
245 { "gug_PY", lcl_DATA_OTHERS },
246 { "tk_TM", lcl_DATA_OTHERS },
247 { "my_MM", lcl_DATA_OTHERS },
248 { "shs_CA", lcl_DATA_OTHERS },
249 { "tpi_PG", lcl_DATA_OTHERS },
250 { "ar_OM", lcl_DATA_OTHERS },
251 { "ug_CN", lcl_DATA_OTHERS },
252 { "om_ET", lcl_DATA_OTHERS },
253 { "plt_MG", lcl_DATA_OTHERS },
254 { "mai_IN", lcl_DATA_OTHERS },
255 { "yi_US", lcl_DATA_OTHERS },
256 { "haw_US", lcl_DATA_OTHERS },
257 { "lif_NP", lcl_DATA_OTHERS },
258 { "ur_PK", lcl_DATA_OTHERS },
259 { "ht_HT", lcl_DATA_OTHERS },
260 { "jbo", lcl_DATA_OTHERS }
261 };
262
263 static const sal_Unicode under = sal_Unicode('_');
264
265 static const sal_Int16 nbOfLocales = sizeof(aLibTable) / sizeof(aLibTable[0]);
266
267 struct LocaleDataLookupTableItem
268 {
LocaleDataLookupTableItemLocaleDataLookupTableItem269 LocaleDataLookupTableItem(const sal_Char *name, osl::Module* m, const sal_Char* lname) : dllName(name), module(m), localeName(lname)
270 {
271 }
272 const sal_Char* dllName;
273 osl::Module *module;
274 const sal_Char* localeName;
275
276 com::sun::star::lang::Locale aLocale;
equalsLocaleDataLookupTableItem277 sal_Bool equals(const com::sun::star::lang::Locale& rLocale)
278 {
279 return (rLocale == aLocale);
280 }
281 };
282
LocaleData()283 LocaleData::LocaleData()
284 {
285 }
~LocaleData()286 LocaleData::~LocaleData()
287 {
288 }
289
290
291 LocaleDataItem SAL_CALL
getLocaleItem(const Locale & rLocale)292 LocaleData::getLocaleItem( const Locale& rLocale ) throw(RuntimeException)
293 {
294 sal_Int16 dataItemCount = 0;
295 sal_Unicode **dataItem = NULL;
296
297 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getLocaleItem" );
298
299 if ( func ) {
300 dataItem = func(dataItemCount);
301
302 LocaleDataItem item(
303 dataItem[0],
304 dataItem[1],
305 dataItem[2],
306 dataItem[3],
307 dataItem[4],
308 dataItem[5],
309 dataItem[6],
310 dataItem[7],
311 dataItem[8],
312 dataItem[9],
313 dataItem[10],
314 dataItem[11],
315 dataItem[12],
316 dataItem[13],
317 dataItem[14],
318 dataItem[15],
319 dataItem[16],
320 dataItem[17]
321 );
322 return item;
323 }
324 else {
325 LocaleDataItem item1;
326 return item1;
327 }
328 }
329
thisModule()330 extern "C" { static void SAL_CALL thisModule() {} }
331
332 namespace
333 {
334
335 // implement the lookup table as a safe static object
336 class lcl_LookupTableHelper
337 {
338 public:
339 lcl_LookupTableHelper();
340 ~lcl_LookupTableHelper();
341
342 oslGenericFunction SAL_CALL getFunctionSymbolByName(
343 const OUString& localeName, const sal_Char* pFunction,
344 LocaleDataLookupTableItem** pOutCachedItem );
345
346 private:
347 ::osl::Mutex maMutex;
348 ::std::vector< LocaleDataLookupTableItem* > maLookupTable;
349 };
350
351 // from instance.hxx: Helper base class for a late-initialized
352 // (default-constructed) static variable, implementing the double-checked
353 // locking pattern correctly.
354 // usage: lcl_LookupTableHelper & rLookupTable = lcl_LookupTableStatic::get();
355 // retrieves the singleton lookup table instance
356 struct lcl_LookupTableStatic : public ::rtl::Static< lcl_LookupTableHelper, lcl_LookupTableStatic >
357 {};
358
lcl_LookupTableHelper()359 lcl_LookupTableHelper::lcl_LookupTableHelper()
360 {
361 }
362
~lcl_LookupTableHelper()363 lcl_LookupTableHelper::~lcl_LookupTableHelper()
364 {
365 LocaleDataLookupTableItem* pItem = 0;
366
367 std::vector<LocaleDataLookupTableItem*>::const_iterator aEnd(maLookupTable.end());
368 std::vector<LocaleDataLookupTableItem*>::iterator aIter(maLookupTable.begin());
369
370 for ( ; aIter != aEnd; ++aIter ) {
371 pItem = *aIter;
372 delete pItem->module;
373 delete pItem;
374 }
375 maLookupTable.clear();
376 }
377
getFunctionSymbolByName(const OUString & localeName,const sal_Char * pFunction,LocaleDataLookupTableItem ** pOutCachedItem)378 oslGenericFunction SAL_CALL lcl_LookupTableHelper::getFunctionSymbolByName(
379 const OUString& localeName, const sal_Char* pFunction,
380 LocaleDataLookupTableItem** pOutCachedItem )
381 {
382 OUString aFallback;
383 bool bFallback = (localeName.indexOf( under) < 0);
384 if (bFallback)
385 {
386 Locale aLocale;
387 aLocale.Language = localeName;
388 Locale aFbLocale = MsLangId::getFallbackLocale( aLocale);
389 if (aFbLocale == aLocale)
390 bFallback = false; // may be a "language-only-locale" like Interlingua (ia)
391 else if (aFbLocale.Country.getLength()) {
392 OUStringBuffer aBuf(5);
393 aFallback = aBuf.append(aFbLocale.Language).append( under).append(aFbLocale.Country).makeStringAndClear();
394 }
395 else
396 aFallback = aFbLocale.Language;
397 }
398
399 for ( sal_Int16 i = 0; i < nbOfLocales; i++)
400 {
401 if (localeName.equalsAscii(aLibTable[i].pLocale) ||
402 (bFallback && localeName == aFallback))
403 {
404 LocaleDataLookupTableItem* pCurrent = 0;
405 OUStringBuffer aBuf(strlen(aLibTable[i].pLocale) + 1 + strlen(pFunction));
406 {
407 ::osl::MutexGuard aGuard( maMutex );
408 for (size_t l = 0; l < maLookupTable.size(); l++)
409 {
410 pCurrent = maLookupTable[l];
411 if (pCurrent->dllName == aLibTable[i].pLib)
412 {
413 OSL_ASSERT( pOutCachedItem );
414 if( pOutCachedItem )
415 {
416 (*pOutCachedItem) = new LocaleDataLookupTableItem( *pCurrent );
417 (*pOutCachedItem)->localeName = aLibTable[i].pLocale;
418 return (*pOutCachedItem)->module->getFunctionSymbol(
419 aBuf.appendAscii( pFunction).append( under).
420 appendAscii( (*pOutCachedItem)->localeName).makeStringAndClear());
421 }
422 else
423 return NULL;
424 }
425 }
426 }
427 // Library not loaded, load it and add it to the list.
428 #ifdef SAL_DLLPREFIX
429 aBuf.ensureCapacity(strlen(aLibTable[i].pLib) + 6); // mostly "lib*.so"
430 aBuf.appendAscii( SAL_DLLPREFIX ).appendAscii(aLibTable[i].pLib).appendAscii( SAL_DLLEXTENSION );
431 #else
432 aBuf.ensureCapacity(strlen(aLibTable[i].pLib) + 4); // mostly "*.dll"
433 aBuf.appendAscii(aLibTable[i].pLib).appendAscii( SAL_DLLEXTENSION );
434 #endif
435 osl::Module *module = new osl::Module();
436 if ( module->loadRelative(&thisModule, aBuf.makeStringAndClear()) )
437 {
438 ::osl::MutexGuard aGuard( maMutex );
439 LocaleDataLookupTableItem* pNewItem = 0;
440 maLookupTable.push_back(pNewItem = new LocaleDataLookupTableItem(aLibTable[i].pLib, module, aLibTable[i].pLocale ));
441 OSL_ASSERT( pOutCachedItem );
442 if( pOutCachedItem )
443 {
444 (*pOutCachedItem) = new LocaleDataLookupTableItem( *pNewItem );
445 return module->getFunctionSymbol(
446 aBuf.appendAscii(pFunction).append(under).
447 appendAscii((*pOutCachedItem)->localeName).makeStringAndClear());
448 }
449 else
450 return NULL;
451 }
452 else
453 delete module;
454 }
455 }
456 return NULL;
457 }
458
459 } // anonymous namespace
460
461 #define REF_DAYS 0
462 #define REF_MONTHS 1
463 #define REF_ERAS 2
464
getCalendarItemByName(const OUString & name,const Locale & rLocale,const Sequence<Calendar> & calendarsSeq,sal_Int16 len,sal_Int16 item)465 Sequence< CalendarItem > &LocaleData::getCalendarItemByName(const OUString& name,
466 const Locale& rLocale, const Sequence< Calendar >& calendarsSeq, sal_Int16 len, sal_Int16 item)
467 throw(RuntimeException)
468 {
469 if (!ref_name.equals(name)) {
470 sal_Int32 index = 0;
471 OUString language = name.getToken(0, under, index);
472 OUString country = name.getToken(0, under, index);
473 Locale loc(language, country, OUString());
474 Sequence < Calendar > cals;
475 if (loc == rLocale) {
476 cals = calendarsSeq;
477 } else {
478 cals = getAllCalendars(loc);
479 len = sal::static_int_cast<sal_Int16>( cals.getLength() );
480 }
481 const OUString& id = name.getToken(0, under, index);
482 for (index = 0; index < cals.getLength(); index++) {
483 if (id.equals(cals[index].Name)) {
484 ref_cal = cals[index];
485 break;
486 }
487 }
488 // Referred locale does not found, return name for en_US locale.
489 if (index == cals.getLength()) {
490 cals = getAllCalendars(
491 Locale(OUString::createFromAscii("en"), OUString::createFromAscii("US"), OUString()));
492 if (cals.getLength() > 0)
493 ref_cal = cals[0];
494 else
495 throw RuntimeException();
496 }
497 ref_name = name;
498 }
499 return item == REF_DAYS ? ref_cal.Days : item == REF_MONTHS ? ref_cal.Months : ref_cal.Eras;
500 }
501
502
503 Sequence< Calendar > SAL_CALL
getAllCalendars(const Locale & rLocale)504 LocaleData::getAllCalendars( const Locale& rLocale ) throw(RuntimeException)
505 {
506
507 sal_Int16 calendarsCount = 0;
508 sal_Unicode **allCalendars = NULL;
509
510 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getAllCalendars" );
511
512 if ( func ) {
513 allCalendars = func(calendarsCount);
514
515 Sequence< Calendar > calendarsSeq(calendarsCount);
516 sal_Int16 offset = 3;
517 sal_Int16 i, j;
518 for(i = 0; i < calendarsCount; i++) {
519 Sequence< CalendarItem > days(allCalendars[0][i]);
520 Sequence< CalendarItem > months(allCalendars[1][i]);
521 Sequence< CalendarItem > eras(allCalendars[2][i]);
522 OUString calendarID(allCalendars[offset]);
523 offset++;
524 sal_Bool defaultCalendar = sal::static_int_cast<sal_Bool>( allCalendars[offset][0] );
525 offset++;
526 if (OUString(allCalendars[offset]).equalsAscii("ref")) {
527 days = getCalendarItemByName(OUString(allCalendars[offset+1]), rLocale, calendarsSeq, i, REF_DAYS);
528 offset += 2;
529 } else {
530 for(j = 0; j < allCalendars[0][i]; j++) {
531 CalendarItem day(allCalendars[offset],
532 allCalendars[offset+1], allCalendars[offset+2]);
533 days[j] = day;
534 offset += 3;
535 }
536 }
537 if (OUString(allCalendars[offset]).equalsAscii("ref")) {
538 months = getCalendarItemByName(OUString(allCalendars[offset+1]), rLocale, calendarsSeq, i, REF_MONTHS);
539 offset += 2;
540 } else {
541 for(j = 0; j < allCalendars[1][i]; j++) {
542 CalendarItem month(allCalendars[offset],
543 allCalendars[offset+1], allCalendars[offset+2]);
544 months[j] = month;
545 offset += 3;
546 }
547 }
548 if (OUString(allCalendars[offset]).equalsAscii("ref")) {
549 eras = getCalendarItemByName(OUString(allCalendars[offset+1]), rLocale, calendarsSeq, i, REF_ERAS);
550 offset += 2;
551 } else {
552 for(j = 0; j < allCalendars[2][i]; j++) {
553 CalendarItem era(allCalendars[offset],
554 allCalendars[offset+1], allCalendars[offset+2]);
555 eras[j] = era;
556 offset += 3;
557 }
558 }
559 OUString startOfWeekDay(allCalendars[offset]);
560 offset++;
561 sal_Int16 minimalDaysInFirstWeek = allCalendars[offset][0];
562 offset++;
563 Calendar aCalendar(days, months, eras, startOfWeekDay,
564 minimalDaysInFirstWeek, defaultCalendar, calendarID);
565 calendarsSeq[i] = aCalendar;
566 }
567 return calendarsSeq;
568 }
569 else {
570 Sequence< Calendar > seq1(0);
571 return seq1;
572 }
573 }
574
575
576 Sequence< Currency2 > SAL_CALL
getAllCurrencies2(const Locale & rLocale)577 LocaleData::getAllCurrencies2( const Locale& rLocale ) throw(RuntimeException)
578 {
579
580 sal_Int16 currencyCount = 0;
581 sal_Unicode **allCurrencies = NULL;
582
583 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getAllCurrencies" );
584
585 if ( func ) {
586 allCurrencies = func(currencyCount);
587
588 Sequence< Currency2 > seq(currencyCount);
589 for(int i = 0, nOff = 0; i < currencyCount; i++, nOff += 8 ) {
590 Currency2 cur(
591 allCurrencies[nOff], // string ID
592 allCurrencies[nOff+1], // string Symbol
593 allCurrencies[nOff+2], // string BankSymbol
594 allCurrencies[nOff+3], // string Name
595 allCurrencies[nOff+4][0] != 0, // boolean Default
596 allCurrencies[nOff+5][0] != 0, // boolean UsedInCompatibleFormatCodes
597 allCurrencies[nOff+6][0], // short DecimalPlaces
598 allCurrencies[nOff+7][0] != 0 // boolean LegacyOnly
599 );
600 seq[i] = cur;
601 }
602 return seq;
603 }
604 else {
605 Sequence< Currency2 > seq1(0);
606 return seq1;
607 }
608 }
609
610
611 Sequence< Currency > SAL_CALL
getAllCurrencies(const Locale & rLocale)612 LocaleData::getAllCurrencies( const Locale& rLocale ) throw(RuntimeException)
613 {
614 Sequence< Currency2 > aCur2( getAllCurrencies2( rLocale));
615 sal_Int32 nLen = aCur2.getLength();
616 Sequence< Currency > aCur1( nLen);
617 const Currency2* p2 = aCur2.getArray();
618 Currency* p1 = aCur1.getArray();
619 for (sal_Int32 i=0; i < nLen; ++i, ++p1, ++p2)
620 {
621 *p1 = *p2;
622 }
623 return aCur1;
624 }
625
626
627 // return a static (!) string resulting from replacing all occurrences of
628 // 'oldStr' string in 'formatCode' string with 'newStr' string
replace(sal_Unicode const * const formatCode,sal_Unicode const * const oldStr,sal_Unicode const * const newStr)629 static const sal_Unicode * replace( sal_Unicode const * const formatCode, sal_Unicode const * const oldStr, sal_Unicode const * const newStr)
630 {
631 // make reasonable assumption of maximum length of formatCode.
632 #define MAX_FORMATCODE_LENTH 512
633 static sal_Unicode str[MAX_FORMATCODE_LENTH];
634
635 if (oldStr[0] == 0) // no replacement requires
636 return formatCode;
637
638 sal_Int32 i = 0, k = 0;
639 while (formatCode[i] > 0 && k < MAX_FORMATCODE_LENTH) {
640 sal_Int32 j = 0, last = k;
641 // search oldStr in formatCode
642 while (formatCode[i] > 0 && oldStr[j] > 0 && k < MAX_FORMATCODE_LENTH) {
643 str[k++] = formatCode[i];
644 if (formatCode[i++] != oldStr[j++])
645 break;
646 }
647 if (oldStr[j] == 0) {
648 // matched string found, do replacement
649 k = last; j = 0;
650 while (newStr[j] > 0 && k < MAX_FORMATCODE_LENTH)
651 str[k++] = newStr[j++];
652 }
653 }
654 if (k >= MAX_FORMATCODE_LENTH) // could not complete replacement, return original formatCode
655 return formatCode;
656
657 str[k] = 0;
658 return str;
659 }
660
661 Sequence< FormatElement > SAL_CALL
getAllFormats(const Locale & rLocale)662 LocaleData::getAllFormats( const Locale& rLocale ) throw(RuntimeException)
663 {
664 const int SECTIONS = 2;
665 struct FormatSection
666 {
667 MyFunc_FormatCode func;
668 sal_Unicode const *from;
669 sal_Unicode const *to;
670 sal_Unicode const *const *formatArray;
671 sal_Int16 formatCount;
672
673 FormatSection() : func(0), from(0), to(0), formatArray(0), formatCount(0) {}
674 sal_Int16 getFunc( LocaleData& rLocaleData, const Locale& rL, const char* pName )
675 {
676 func = reinterpret_cast<MyFunc_FormatCode>( rLocaleData.getFunctionSymbol( rL, pName));
677 if (func)
678 formatArray = func( formatCount, from, to);
679 return formatCount;
680 }
681 } section[SECTIONS];
682
683 #if 0
684 // #i79398# wntmsci10 MSVC doesn't get this right with optimization.
685 const sal_Int32 formatCount = section[0].getFunc( *this, rLocale, "getAllFormats0")
686 + section[1].getFunc( *this, rLocale, "getAllFormats1");
687 #else
688 sal_Int32 formatCount = section[0].getFunc( *this, rLocale, "getAllFormats0");
689 formatCount += section[1].getFunc( *this, rLocale, "getAllFormats1");
690 #endif
691 Sequence< FormatElement > seq(formatCount);
692 sal_Int32 f = 0;
693 for (int s = 0; s < SECTIONS; ++s)
694 {
695 sal_Unicode const * const * const formatArray = section[s].formatArray;
696 if ( formatArray )
697 {
698 for (int i = 0, nOff = 0; i < section[s].formatCount; ++i, nOff += 7, ++f)
699 {
700 FormatElement elem(
701 replace( formatArray[nOff], section[s].from, section[s].to),
702 formatArray[nOff + 1],
703 formatArray[nOff + 2],
704 formatArray[nOff + 3],
705 formatArray[nOff + 4],
706 formatArray[nOff + 5][0],
707 sal::static_int_cast<sal_Bool>(formatArray[nOff + 6][0]));
708 seq[f] = elem;
709 }
710 }
711 }
712 return seq;
713 }
714
715 #define COLLATOR_OFFSET_ALGO 0
716 #define COLLATOR_OFFSET_DEFAULT 1
717 #define COLLATOR_OFFSET_RULE 2
718 #define COLLATOR_ELEMENTS 3
719
720 OUString SAL_CALL
getCollatorRuleByAlgorithm(const Locale & rLocale,const OUString & algorithm)721 LocaleData::getCollatorRuleByAlgorithm( const Locale& rLocale, const OUString& algorithm ) throw(RuntimeException)
722 {
723 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getCollatorImplementation" );
724 if ( func ) {
725 sal_Int16 collatorCount = 0;
726 sal_Unicode **collatorArray = func(collatorCount);
727 for(sal_Int16 i = 0; i < collatorCount; i++)
728 if (algorithm.equals(collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_ALGO]))
729 return OUString(collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_RULE]);
730 }
731 return OUString();
732 }
733
734
735 Sequence< Implementation > SAL_CALL
getCollatorImplementations(const Locale & rLocale)736 LocaleData::getCollatorImplementations( const Locale& rLocale ) throw(RuntimeException)
737 {
738 sal_Int16 collatorCount = 0;
739 sal_Unicode **collatorArray = NULL;
740
741 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getCollatorImplementation" );
742
743 if ( func ) {
744 collatorArray = func(collatorCount);
745 Sequence< Implementation > seq(collatorCount);
746 for(sal_Int16 i = 0; i < collatorCount; i++) {
747 Implementation impl(collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_ALGO],
748 sal::static_int_cast<sal_Bool>(
749 collatorArray[i * COLLATOR_ELEMENTS + COLLATOR_OFFSET_DEFAULT][0]));
750 seq[i] = impl;
751 }
752 return seq;
753 }
754 else {
755 Sequence< Implementation > seq1(0);
756 return seq1;
757 }
758 }
759
760 Sequence< OUString > SAL_CALL
getCollationOptions(const Locale & rLocale)761 LocaleData::getCollationOptions( const Locale& rLocale ) throw(RuntimeException)
762 {
763 sal_Int16 optionsCount = 0;
764 sal_Unicode **optionsArray = NULL;
765
766 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getCollationOptions" );
767
768 if ( func ) {
769 optionsArray = func(optionsCount);
770 Sequence< OUString > seq(optionsCount);
771 for(sal_Int16 i = 0; i < optionsCount; i++) {
772 seq[i] = OUString( optionsArray[i] );
773 }
774 return seq;
775 }
776 else {
777 Sequence< OUString > seq1(0);
778 return seq1;
779 }
780 }
781
782 Sequence< OUString > SAL_CALL
getSearchOptions(const Locale & rLocale)783 LocaleData::getSearchOptions( const Locale& rLocale ) throw(RuntimeException)
784 {
785 sal_Int16 optionsCount = 0;
786 sal_Unicode **optionsArray = NULL;
787
788 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getSearchOptions" );
789
790 if ( func ) {
791 optionsArray = func(optionsCount);
792 Sequence< OUString > seq(optionsCount);
793 for(sal_Int16 i = 0; i < optionsCount; i++) {
794 seq[i] = OUString( optionsArray[i] );
795 }
796 return seq;
797 }
798 else {
799 Sequence< OUString > seq1(0);
800 return seq1;
801 }
802 }
803
804 sal_Unicode ** SAL_CALL
getIndexArray(const Locale & rLocale,sal_Int16 & indexCount)805 LocaleData::getIndexArray(const Locale& rLocale, sal_Int16& indexCount)
806 {
807 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getIndexAlgorithm" );
808
809 if (func)
810 return func(indexCount);
811 return NULL;
812 }
813
814 Sequence< OUString > SAL_CALL
getIndexAlgorithm(const Locale & rLocale)815 LocaleData::getIndexAlgorithm( const Locale& rLocale ) throw(RuntimeException)
816 {
817 sal_Int16 indexCount = 0;
818 sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
819
820 if ( indexArray ) {
821 Sequence< OUString > seq(indexCount);
822 for(sal_Int16 i = 0; i < indexCount; i++) {
823 seq[i] = indexArray[i*5];
824 }
825 return seq;
826 }
827 else {
828 Sequence< OUString > seq1(0);
829 return seq1;
830 }
831 }
832
833 OUString SAL_CALL
getDefaultIndexAlgorithm(const Locale & rLocale)834 LocaleData::getDefaultIndexAlgorithm( const Locale& rLocale ) throw(RuntimeException)
835 {
836 sal_Int16 indexCount = 0;
837 sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
838
839 if ( indexArray ) {
840 for(sal_Int16 i = 0; i < indexCount; i++) {
841 if (indexArray[i*5 + 3][0])
842 return OUString(indexArray[i*5]);
843 }
844 }
845 return OUString();
846 }
847
848 sal_Bool SAL_CALL
hasPhonetic(const Locale & rLocale)849 LocaleData::hasPhonetic( const Locale& rLocale ) throw(RuntimeException)
850 {
851 sal_Int16 indexCount = 0;
852 sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
853
854 if ( indexArray ) {
855 for(sal_Int16 i = 0; i < indexCount; i++) {
856 if (indexArray[i*5 + 4][0])
857 return sal_True;
858 }
859 }
860 return sal_False;
861 }
862
863 sal_Unicode ** SAL_CALL
getIndexArrayForAlgorithm(const Locale & rLocale,const OUString & algorithm)864 LocaleData::getIndexArrayForAlgorithm(const Locale& rLocale, const OUString& algorithm)
865 {
866 sal_Int16 indexCount = 0;
867 sal_Unicode **indexArray = getIndexArray(rLocale, indexCount);
868 if ( indexArray ) {
869 for(sal_Int16 i = 0; i < indexCount; i++) {
870 if (algorithm.equals(indexArray[i*5]))
871 return indexArray+i*5;
872 }
873 }
874 return NULL;
875 }
876
877 sal_Bool SAL_CALL
isPhonetic(const Locale & rLocale,const OUString & algorithm)878 LocaleData::isPhonetic( const Locale& rLocale, const OUString& algorithm ) throw(RuntimeException)
879 {
880 sal_Unicode **indexArray = getIndexArrayForAlgorithm(rLocale, algorithm);
881 return (indexArray && indexArray[4][0]) ? sal_True : sal_False;
882 }
883
884 OUString SAL_CALL
getIndexKeysByAlgorithm(const Locale & rLocale,const OUString & algorithm)885 LocaleData::getIndexKeysByAlgorithm( const Locale& rLocale, const OUString& algorithm ) throw(RuntimeException)
886 {
887 sal_Unicode **indexArray = getIndexArrayForAlgorithm(rLocale, algorithm);
888 return indexArray ? OUString::createFromAscii("0-9")+OUString(indexArray[2]) : OUString();
889 }
890
891 OUString SAL_CALL
getIndexModuleByAlgorithm(const Locale & rLocale,const OUString & algorithm)892 LocaleData::getIndexModuleByAlgorithm( const Locale& rLocale, const OUString& algorithm ) throw(RuntimeException)
893 {
894 sal_Unicode **indexArray = getIndexArrayForAlgorithm(rLocale, algorithm);
895 return indexArray ? OUString(indexArray[1]) : OUString();
896 }
897
898 Sequence< UnicodeScript > SAL_CALL
getUnicodeScripts(const Locale & rLocale)899 LocaleData::getUnicodeScripts( const Locale& rLocale ) throw(RuntimeException)
900 {
901 sal_Int16 scriptCount = 0;
902 sal_Unicode **scriptArray = NULL;
903
904 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getUnicodeScripts" );
905
906 if ( func ) {
907 scriptArray = func(scriptCount);
908 Sequence< UnicodeScript > seq(scriptCount);
909 for(sal_Int16 i = 0; i < scriptCount; i++) {
910 seq[i] = UnicodeScript( OUString(scriptArray[i]).toInt32() );
911 }
912 return seq;
913 }
914 else {
915 Sequence< UnicodeScript > seq1(0);
916 return seq1;
917 }
918 }
919
920 Sequence< OUString > SAL_CALL
getFollowPageWords(const Locale & rLocale)921 LocaleData::getFollowPageWords( const Locale& rLocale ) throw(RuntimeException)
922 {
923 sal_Int16 wordCount = 0;
924 sal_Unicode **wordArray = NULL;
925
926 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getFollowPageWords" );
927
928 if ( func ) {
929 wordArray = func(wordCount);
930 Sequence< OUString > seq(wordCount);
931 for(sal_Int16 i = 0; i < wordCount; i++) {
932 seq[i] = OUString(wordArray[i]);
933 }
934 return seq;
935 }
936 else {
937 Sequence< OUString > seq1(0);
938 return seq1;
939 }
940 }
941
942 Sequence< OUString > SAL_CALL
getTransliterations(const Locale & rLocale)943 LocaleData::getTransliterations( const Locale& rLocale ) throw(RuntimeException)
944 {
945
946 sal_Int16 transliterationsCount = 0;
947 sal_Unicode **transliterationsArray = NULL;
948
949 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getTransliterations" );
950
951 if ( func ) {
952 transliterationsArray = func(transliterationsCount);
953
954 Sequence< OUString > seq(transliterationsCount);
955 for(int i = 0; i < transliterationsCount; i++) {
956 OUString elem(transliterationsArray[i]);
957 seq[i] = elem;
958 }
959 return seq;
960 }
961 else {
962 Sequence< OUString > seq1(0);
963 return seq1;
964 }
965
966
967 }
968
969
970 LanguageCountryInfo SAL_CALL
getLanguageCountryInfo(const Locale & rLocale)971 LocaleData::getLanguageCountryInfo( const Locale& rLocale ) throw(RuntimeException)
972 {
973 sal_Int16 LCInfoCount = 0;
974 sal_Unicode **LCInfoArray = NULL;
975
976 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getLCInfo" );
977
978 if ( func ) {
979 LCInfoArray = func(LCInfoCount);
980 LanguageCountryInfo info(LCInfoArray[0],
981 LCInfoArray[1],
982 LCInfoArray[2],
983 LCInfoArray[3],
984 LCInfoArray[4]);
985 return info;
986 }
987 else {
988 LanguageCountryInfo info1;
989 return info1;
990 }
991
992 }
993
994
995 ForbiddenCharacters SAL_CALL
getForbiddenCharacters(const Locale & rLocale)996 LocaleData::getForbiddenCharacters( const Locale& rLocale ) throw(RuntimeException)
997 {
998 sal_Int16 LCForbiddenCharactersCount = 0;
999 sal_Unicode **LCForbiddenCharactersArray = NULL;
1000
1001 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getForbiddenCharacters" );
1002
1003 if ( func ) {
1004 LCForbiddenCharactersArray = func(LCForbiddenCharactersCount);
1005 ForbiddenCharacters chars(LCForbiddenCharactersArray[0], LCForbiddenCharactersArray[1]);
1006 return chars;
1007 }
1008 else {
1009 ForbiddenCharacters chars1;
1010 return chars1;
1011 }
1012 }
1013
1014 OUString SAL_CALL
getHangingCharacters(const Locale & rLocale)1015 LocaleData::getHangingCharacters( const Locale& rLocale ) throw(RuntimeException)
1016 {
1017 sal_Int16 LCForbiddenCharactersCount = 0;
1018 sal_Unicode **LCForbiddenCharactersArray = NULL;
1019
1020 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getForbiddenCharacters" );
1021
1022 if ( func ) {
1023 LCForbiddenCharactersArray = func(LCForbiddenCharactersCount);
1024 return OUString(LCForbiddenCharactersArray[2]);
1025 }
1026
1027 return OUString();
1028 }
1029
1030 Sequence< OUString > SAL_CALL
getBreakIteratorRules(const Locale & rLocale)1031 LocaleData::getBreakIteratorRules( const Locale& rLocale ) throw(RuntimeException)
1032 {
1033 sal_Int16 LCBreakIteratorRuleCount = 0;
1034 sal_Unicode **LCBreakIteratorRulesArray = NULL;
1035
1036 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getBreakIteratorRules" );
1037
1038 if ( func ) {
1039 LCBreakIteratorRulesArray = func(LCBreakIteratorRuleCount);
1040 Sequence< OUString > seq(LCBreakIteratorRuleCount);
1041 for(int i = 0; i < (LCBreakIteratorRuleCount); i++) {
1042 OUString elem(LCBreakIteratorRulesArray[i]);
1043 seq[i] = elem;
1044 }
1045 return seq;
1046 }
1047 else {
1048 Sequence< OUString > seq1(0);
1049 return seq1;
1050 }
1051 }
1052
1053
1054 Sequence< OUString > SAL_CALL
getReservedWord(const Locale & rLocale)1055 LocaleData::getReservedWord( const Locale& rLocale ) throw(RuntimeException)
1056 {
1057 sal_Int16 LCReservedWordsCount = 0;
1058 sal_Unicode **LCReservedWordsArray = NULL;
1059
1060 MyFunc_Type func = (MyFunc_Type) getFunctionSymbol( rLocale, "getReservedWords" );
1061
1062 if ( func ) {
1063 LCReservedWordsArray = func(LCReservedWordsCount);
1064 Sequence< OUString > seq(LCReservedWordsCount);
1065 for(int i = 0; i < (LCReservedWordsCount); i++) {
1066 OUString elem(LCReservedWordsArray[i]);
1067 seq[i] = elem;
1068 }
1069 return seq;
1070 }
1071 else {
1072 Sequence< OUString > seq1(0);
1073 return seq1;
1074 }
1075 }
1076
1077
1078 inline
C2U(const char * s)1079 OUString C2U( const char* s )
1080 {
1081 return OUString::createFromAscii( s );
1082 }
1083
1084 Sequence< Sequence<beans::PropertyValue> > SAL_CALL
getContinuousNumberingLevels(const lang::Locale & rLocale)1085 LocaleData::getContinuousNumberingLevels( const lang::Locale& rLocale ) throw(RuntimeException)
1086 {
1087 int i;
1088
1089 // load symbol
1090 MyFunc_Type2 func = (MyFunc_Type2) getFunctionSymbol( rLocale, "getContinuousNumberingLevels" );
1091
1092 if ( func )
1093 {
1094 // invoke function
1095 sal_Int16 nStyles;
1096 sal_Int16 nAttributes;
1097 sal_Unicode*** p0 = func( nStyles, nAttributes );
1098
1099 // allocate memory for nAttributes attributes for each of the nStyles styles.
1100 Sequence< Sequence<beans::PropertyValue> > pv( nStyles );
1101 for( i=0; i<pv.getLength(); i++ ) {
1102 pv[i] = Sequence<beans::PropertyValue>( nAttributes );
1103 }
1104
1105 sal_Unicode*** pStyle = p0;
1106 for( i=0; i<nStyles; i++ ) {
1107 sal_Unicode** pAttribute = pStyle[i];
1108 for( int j=0; j<nAttributes; j++ ) { // prefix, numberingtype, ...
1109 sal_Unicode* pString = pAttribute[j];
1110 beans::PropertyValue& rVal = pv[i][j];
1111 OUString sVal;
1112 if( pString ) {
1113 if( 0 != j && 2 != j )
1114 sVal = pString;
1115 else if( *pString )
1116 sVal = OUString( pString, 1 );
1117 }
1118
1119 switch( j )
1120 {
1121 case 0:
1122 rVal.Name = C2U("Prefix");
1123 rVal.Value <<= sVal;
1124 break;
1125 case 1:
1126 rVal.Name = C2U("NumberingType");
1127 rVal.Value <<= (sal_Int16) sVal.toInt32();
1128 break;
1129 case 2:
1130 rVal.Name = C2U("Suffix");
1131 rVal.Value <<= sVal;
1132 break;
1133 case 3:
1134 rVal.Name = C2U("Transliteration");
1135 rVal.Value <<= sVal;
1136 break;
1137 case 4:
1138 rVal.Name = C2U("NatNum");
1139 rVal.Value <<= (sal_Int16) sVal.toInt32();
1140 break;
1141 default:
1142 OSL_ASSERT(0);
1143 }
1144 }
1145 }
1146 return pv;
1147 }
1148
1149 Sequence< Sequence<beans::PropertyValue> > seq1(0);
1150 return seq1;
1151 }
1152
1153 // ============================================================================
1154 // \/ OutlineNumbering helper class \/
1155 //
1156 #include <com/sun/star/container/XIndexAccess.hpp>
1157 #include <cppuhelper/implbase1.hxx>
1158
1159 namespace com{ namespace sun{ namespace star{ namespace lang {
1160 struct Locale;
1161 }}}}
1162 //-----------------------------------------------------------------------------
1163 struct OutlineNumberingLevel_Impl
1164 {
1165 OUString sPrefix;
1166 sal_Int16 nNumType; //com::sun::star::style::NumberingType
1167 OUString sSuffix;
1168 sal_Unicode cBulletChar;
1169 const sal_Char* sBulletFontName;
1170 sal_Int16 nParentNumbering;
1171 sal_Int32 nLeftMargin;
1172 sal_Int32 nSymbolTextDistance;
1173 sal_Int32 nFirstLineOffset;
1174 OUString sTransliteration;
1175 sal_Int32 nNatNum;
1176 };
1177 //-----------------------------------------------------------------------------
1178 class OutlineNumbering : public cppu::WeakImplHelper1 < container::XIndexAccess >
1179 {
1180 const OutlineNumberingLevel_Impl* m_pOutlineLevels;
1181 sal_Int16 m_nCount;
1182 public:
1183 // OutlineNumbering(const OutlineNumberingLevel_Impl* pOutlineLevels);
1184 OutlineNumbering(const OutlineNumberingLevel_Impl* pOutlineLevels, int nLevels);
1185 ~OutlineNumbering();
1186
1187 //XIndexAccess
1188 virtual sal_Int32 SAL_CALL getCount( ) throw(RuntimeException);
1189 virtual Any SAL_CALL getByIndex( sal_Int32 Index )
1190 throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException);
1191
1192 //XElementAccess
1193 virtual Type SAL_CALL getElementType( ) throw(RuntimeException);
1194 virtual sal_Bool SAL_CALL hasElements( ) throw(RuntimeException);
1195 };
1196
1197 //
1198 // OutlineNumbering helper class
1199 // ============================================================================
1200
1201 static
U2C(OUString str)1202 sal_Char* U2C( OUString str )
1203 {
1204 sal_Char* s = new sal_Char[ str.getLength()+1 ];
1205 int i;
1206 for( i = 0; i < str.getLength(); i++)
1207 s[i] = sal::static_int_cast<sal_Char>( str[i] );
1208 s[i]='\0';
1209 return s;
1210 }
1211
1212
1213 Sequence< Reference<container::XIndexAccess> > SAL_CALL
getOutlineNumberingLevels(const lang::Locale & rLocale)1214 LocaleData::getOutlineNumberingLevels( const lang::Locale& rLocale ) throw(RuntimeException)
1215 {
1216 int i;
1217
1218 // load symbol
1219 MyFunc_Type3 func = (MyFunc_Type3) getFunctionSymbol( rLocale, "getOutlineNumberingLevels" );
1220
1221 if ( func )
1222 {
1223 // invoke function
1224 sal_Int16 nStyles;
1225 sal_Int16 nLevels;
1226 sal_Int16 nAttributes;
1227 sal_Unicode**** p0 = func( nStyles, nLevels, nAttributes );
1228
1229 Sequence< Reference<container::XIndexAccess> > aRet( nStyles );
1230
1231 OUString aEmptyStr;
1232
1233 sal_Unicode**** pStyle = p0;
1234 for( i=0; i<nStyles; i++ )
1235 {
1236 int j;
1237
1238 OutlineNumberingLevel_Impl* level = new OutlineNumberingLevel_Impl[ nLevels+1 ];
1239 sal_Unicode*** pLevel = pStyle[i];
1240 for( j = 0; j < nLevels; j++ )
1241 {
1242 sal_Unicode** pAttribute = pLevel[j];
1243 for( int k=0; k<nAttributes; k++ )
1244 {
1245 OUString tmp( pAttribute[k] );
1246 switch( k )
1247 {
1248 case 0: level[j].sPrefix = tmp; break;
1249 case 1: level[j].nNumType = sal::static_int_cast<sal_Int16>(tmp.toInt32()); break;
1250 case 2: level[j].sSuffix = tmp; break;
1251 //case 3: level[j].cBulletChar = tmp.toChar(); break;
1252 case 3: level[j].cBulletChar = sal::static_int_cast<sal_Unicode>(tmp.toInt32(16)); break; // base 16
1253 case 4: level[j].sBulletFontName = U2C( tmp ); break;
1254 case 5: level[j].nParentNumbering = sal::static_int_cast<sal_Int16>(tmp.toInt32()); break;
1255 case 6: level[j].nLeftMargin = tmp.toInt32(); break;
1256 case 7: level[j].nSymbolTextDistance = tmp.toInt32(); break;
1257 case 8: level[j].nFirstLineOffset = tmp.toInt32(); break;
1258 case 9: // Adjust
1259 // these values seem to be hard-coded elsewhere:
1260 // level[j].Value <<= (sal_Int16) text::HoriOrientation::LEFT;
1261 // level[j].Value <<= (sal_Int16) style::HorizontalAlignment::LEFT;
1262 break;
1263 case 10: level[j].sTransliteration = tmp; break;
1264 case 11: level[j].nNatNum = tmp.toInt32(); break;
1265 default:
1266 OSL_ASSERT(0);
1267 }
1268 }
1269 }
1270 level[j].sPrefix = aEmptyStr;
1271 level[j].nNumType = 0;
1272 level[j].sSuffix = aEmptyStr;
1273 level[j].cBulletChar = 0;
1274 level[j].sBulletFontName = 0;
1275 level[j].nParentNumbering = 0;
1276 level[j].nLeftMargin = 0;
1277 level[j].nSymbolTextDistance = 0;
1278 level[j].nFirstLineOffset = 0;
1279 level[j].sTransliteration = aEmptyStr;
1280 level[j].nNatNum = 0;
1281 aRet[i] = new OutlineNumbering( level, nLevels );
1282 }
1283 return aRet;
1284 }
1285 else {
1286 Sequence< Reference<container::XIndexAccess> > seq1(0);
1287 return seq1;
1288 }
1289 }
1290
1291 /////////////////////////////////////////////////////////////////////////////////////////////
1292 //////////////////////////////////helper functions///////////////////////////////////////////
1293 /////////////////////////////////////////////////////////////////////////////////////////////
1294
getFunctionSymbol(const Locale & rLocale,const sal_Char * pFunction)1295 oslGenericFunction SAL_CALL LocaleData::getFunctionSymbol( const Locale& rLocale, const sal_Char* pFunction )
1296 throw(RuntimeException)
1297 {
1298 lcl_LookupTableHelper & rLookupTable = lcl_LookupTableStatic::get();
1299
1300 OUStringBuffer aBuf(1);
1301 if (cachedItem.get() && cachedItem->equals(rLocale)) {
1302 aBuf.ensureCapacity(strlen(pFunction) + 1 + strlen(cachedItem->localeName));
1303 return cachedItem->module->getFunctionSymbol(aBuf.appendAscii(pFunction).append(under).
1304 appendAscii(cachedItem->localeName).makeStringAndClear());
1305 }
1306
1307 oslGenericFunction pSymbol = 0;
1308 static OUString tw(OUString::createFromAscii("TW"));
1309 static OUString en_US(OUString::createFromAscii("en_US"));
1310
1311 sal_Int32 l = rLocale.Language.getLength();
1312 sal_Int32 c = rLocale.Country.getLength();
1313 sal_Int32 v = rLocale.Variant.getLength();
1314 aBuf.ensureCapacity(l+c+v+3);
1315
1316 LocaleDataLookupTableItem *pCachedItem = 0;
1317
1318 if ((l > 0 && c > 0 && v > 0 &&
1319 // load function with name <func>_<lang>_<country>_<varian>
1320 (pSymbol = rLookupTable.getFunctionSymbolByName(aBuf.append(rLocale.Language).append(under).append(
1321 rLocale.Country).append(under).append(rLocale.Variant).makeStringAndClear(), pFunction, &pCachedItem)) != 0) ||
1322 (l > 0 && c > 0 &&
1323 // load function with name <ase>_<lang>_<country>
1324 (pSymbol = rLookupTable.getFunctionSymbolByName(aBuf.append(rLocale.Language).append(under).append(
1325 rLocale.Country).makeStringAndClear(), pFunction, &pCachedItem)) != 0) ||
1326 (l > 0 && c > 0 && rLocale.Language.equalsAscii("zh") &&
1327 (rLocale.Country.equalsAscii("HK") ||
1328 rLocale.Country.equalsAscii("MO")) &&
1329 // if the country code is HK or MO, one more step to try TW.
1330 (pSymbol = rLookupTable.getFunctionSymbolByName(aBuf.append(rLocale.Language).append(under).append(tw).makeStringAndClear(),
1331 pFunction, &pCachedItem)) != 0) ||
1332 (l > 0 &&
1333 // load function with name <func>_<lang>
1334 (pSymbol = rLookupTable.getFunctionSymbolByName(rLocale.Language, pFunction, &pCachedItem)) != 0) ||
1335 // load default function with name <func>_en_US
1336 (pSymbol = rLookupTable.getFunctionSymbolByName(en_US, pFunction, &pCachedItem)) != 0)
1337 {
1338 if( pCachedItem )
1339 cachedItem.reset( pCachedItem );
1340 if( cachedItem.get())
1341 cachedItem->aLocale = rLocale;
1342 return pSymbol;
1343 }
1344 throw RuntimeException();
1345 }
1346
1347 Sequence< Locale > SAL_CALL
getAllInstalledLocaleNames()1348 LocaleData::getAllInstalledLocaleNames() throw(RuntimeException)
1349 {
1350 Sequence< lang::Locale > seq( nbOfLocales );
1351 OUString empStr;
1352 sal_Int16 nInstalled = 0;
1353
1354 for( sal_Int16 i=0; i<nbOfLocales; i++ ) {
1355 OUString name = OUString::createFromAscii( aLibTable[i].pLocale );
1356
1357 // Check if the locale is really available and not just in the table,
1358 // don't allow fall backs.
1359 LocaleDataLookupTableItem *pCachedItem = 0;
1360 if (lcl_LookupTableStatic::get().getFunctionSymbolByName( name, "getLocaleItem", &pCachedItem )) {
1361 if( pCachedItem )
1362 cachedItem.reset( pCachedItem );
1363 sal_Int32 index = 0;
1364 lang::Locale tmpLocale(name.getToken(0, under, index), empStr, empStr);
1365 if (index >= 0) {
1366 tmpLocale.Country = name.getToken(0, under, index);
1367 if (index >= 0)
1368 tmpLocale.Variant = name.getToken(0, under, index);
1369 }
1370 seq[nInstalled++] = tmpLocale;
1371 }
1372 }
1373 if ( nInstalled < nbOfLocales )
1374 seq.realloc( nInstalled ); // reflect reality
1375
1376 return seq;
1377 }
1378
1379 // ============================================================================
1380
1381 using namespace ::com::sun::star::container;
1382 using namespace ::com::sun::star::beans;
1383 using namespace ::com::sun::star::style;
1384 using namespace ::com::sun::star::text;
1385
1386 // // bad: can't have empty prefix ...
1387 // OutlineNumbering::OutlineNumbering(const OutlineNumberingLevel_Impl* pOutlnLevels) :
1388 // m_pOutlineLevels(pOutlnLevels),
1389 // m_nCount(0)
1390 // {
1391 // const OutlineNumberingLevel_Impl* pTemp = m_pOutlineLevels;
1392 // while((pTemp++)->sPrefix)
1393 // m_nCount++;
1394 // }
1395
OutlineNumbering(const OutlineNumberingLevel_Impl * pOutlnLevels,int nLevels)1396 OutlineNumbering::OutlineNumbering(const OutlineNumberingLevel_Impl* pOutlnLevels, int nLevels) :
1397 m_pOutlineLevels(pOutlnLevels),
1398 m_nCount(sal::static_int_cast<sal_Int16>(nLevels))
1399 {
1400 }
1401
~OutlineNumbering()1402 OutlineNumbering::~OutlineNumbering()
1403 {
1404 delete [] m_pOutlineLevels;
1405 }
1406
getCount()1407 sal_Int32 OutlineNumbering::getCount( ) throw(RuntimeException)
1408 {
1409 return m_nCount;
1410 }
1411
getByIndex(sal_Int32 nIndex)1412 Any OutlineNumbering::getByIndex( sal_Int32 nIndex )
1413 throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
1414 {
1415 if(nIndex < 0 || nIndex >= m_nCount)
1416 throw IndexOutOfBoundsException();
1417 const OutlineNumberingLevel_Impl* pTemp = m_pOutlineLevels;
1418 pTemp += nIndex;
1419 Any aRet;
1420
1421 Sequence<PropertyValue> aOutlineNumbering(12);
1422 PropertyValue* pValues = aOutlineNumbering.getArray();
1423 pValues[0].Name = C2U( "Prefix");
1424 pValues[0].Value <<= pTemp->sPrefix;
1425 pValues[1].Name = C2U("NumberingType");
1426 pValues[1].Value <<= pTemp->nNumType;
1427 pValues[2].Name = C2U("Suffix");
1428 pValues[2].Value <<= pTemp->sSuffix;
1429 pValues[3].Name = C2U("BulletChar");
1430 pValues[3].Value <<= OUString(&pTemp->cBulletChar, 1);
1431 pValues[4].Name = C2U("BulletFontName");
1432 pValues[4].Value <<= C2U(pTemp->sBulletFontName);
1433 pValues[5].Name = C2U("ParentNumbering");
1434 pValues[5].Value <<= pTemp->nParentNumbering;
1435 pValues[6].Name = C2U("LeftMargin");
1436 pValues[6].Value <<= pTemp->nLeftMargin;
1437 pValues[7].Name = C2U("SymbolTextDistance");
1438 pValues[7].Value <<= pTemp->nSymbolTextDistance;
1439 pValues[8].Name = C2U("FirstLineOffset");
1440 pValues[8].Value <<= pTemp->nFirstLineOffset;
1441 pValues[9].Name = C2U("Adjust");
1442 pValues[9].Value <<= (sal_Int16)HoriOrientation::LEFT;
1443 pValues[10].Name = C2U("Transliteration");
1444 pValues[10].Value <<= pTemp->sTransliteration;
1445 pValues[11].Name = C2U("NatNum");
1446 pValues[11].Value <<= pTemp->nNatNum;
1447 aRet <<= aOutlineNumbering;
1448 return aRet;
1449 }
1450
getElementType()1451 Type OutlineNumbering::getElementType( ) throw(RuntimeException)
1452 {
1453 return ::getCppuType((Sequence<PropertyValue>*)0);
1454 }
1455
hasElements()1456 sal_Bool OutlineNumbering::hasElements( ) throw(RuntimeException)
1457 {
1458 return m_nCount > 0;
1459 }
1460
1461 OUString SAL_CALL
getImplementationName()1462 LocaleData::getImplementationName() throw( RuntimeException )
1463 {
1464 return OUString::createFromAscii(clocaledata);
1465 }
1466
1467 sal_Bool SAL_CALL
supportsService(const OUString & rServiceName)1468 LocaleData::supportsService(const OUString& rServiceName)
1469 throw( RuntimeException )
1470 {
1471 return !rServiceName.compareToAscii(clocaledata);
1472 }
1473
1474 Sequence< OUString > SAL_CALL
getSupportedServiceNames()1475 LocaleData::getSupportedServiceNames() throw( RuntimeException )
1476 {
1477 Sequence< OUString > aRet(1);
1478 aRet[0] = OUString::createFromAscii(clocaledata);
1479 return aRet;
1480 }
1481