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_unotools.hxx"
26 
27 #include "unotools/intlwrapper.hxx"
28 #include <com/sun/star/i18n/CollatorOptions.hpp>
29 #include <i18npool/mslangid.hxx>
30 
IntlWrapper(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xSF,const::com::sun::star::lang::Locale & rLocale)31 IntlWrapper::IntlWrapper(
32             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF,
33             const ::com::sun::star::lang::Locale& rLocale )
34         :
35         aLocale( rLocale ),
36         xSMgr( xSF ),
37         pCharClass( NULL ),
38         pLocaleData( NULL ),
39         pCalendar( NULL ),
40         pCollator( NULL ),
41         pCaseCollator( NULL )
42 {
43     eLanguage = MsLangId::convertLocaleToLanguage( aLocale );
44 }
45 
46 
IntlWrapper(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xSF,LanguageType eLang)47 IntlWrapper::IntlWrapper(
48             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF,
49             LanguageType eLang )
50         :
51         xSMgr( xSF ),
52         pCharClass( NULL ),
53         pLocaleData( NULL ),
54         pCalendar( NULL ),
55         pCollator( NULL ),
56         pCaseCollator( NULL ),
57         eLanguage( eLang )
58 {
59     MsLangId::convertLanguageToLocale( eLanguage, aLocale );
60 }
61 
62 
~IntlWrapper()63 IntlWrapper::~IntlWrapper()
64 {
65     delete pCharClass;
66     delete pLocaleData;
67     delete pCalendar;
68     delete pCollator;
69     delete pCaseCollator;
70 }
71 
72 
ImplNewCharClass() const73 void IntlWrapper::ImplNewCharClass() const
74 {
75     ((IntlWrapper*)this)->pCharClass = new CharClass( xSMgr, aLocale );
76 }
77 
78 
ImplNewLocaleData() const79 void IntlWrapper::ImplNewLocaleData() const
80 {
81     ((IntlWrapper*)this)->pLocaleData = new LocaleDataWrapper( xSMgr, aLocale );
82 }
83 
84 
ImplNewCalendar() const85 void IntlWrapper::ImplNewCalendar() const
86 {
87     CalendarWrapper* p = new CalendarWrapper( xSMgr );
88     p->loadDefaultCalendar( aLocale );
89     ((IntlWrapper*)this)->pCalendar = p;
90 }
91 
92 
ImplNewCollator(sal_Bool bCaseSensitive) const93 void IntlWrapper::ImplNewCollator( sal_Bool bCaseSensitive ) const
94 {
95     CollatorWrapper* p = new CollatorWrapper( xSMgr );
96     if ( bCaseSensitive )
97     {
98         p->loadDefaultCollator( aLocale, 0 );
99         ((IntlWrapper*)this)->pCaseCollator = p;
100     }
101     else
102     {
103         p->loadDefaultCollator( aLocale, ::com::sun::star::i18n::CollatorOptions::CollatorOptions_IGNORE_CASE );
104         ((IntlWrapper*)this)->pCollator = p;
105     }
106 }
107