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