1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_unotools.hxx"
30 
31 #include "unotools/intlwrapper.hxx"
32 #include <com/sun/star/i18n/CollatorOptions.hpp>
33 #include <i18npool/mslangid.hxx>
34 
35 IntlWrapper::IntlWrapper(
36             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF,
37             const ::com::sun::star::lang::Locale& rLocale )
38         :
39         aLocale( rLocale ),
40         xSMgr( xSF ),
41         pCharClass( NULL ),
42         pLocaleData( NULL ),
43         pCalendar( NULL ),
44         pCollator( NULL ),
45         pCaseCollator( NULL )
46 {
47     eLanguage = MsLangId::convertLocaleToLanguage( aLocale );
48 }
49 
50 
51 IntlWrapper::IntlWrapper(
52             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF,
53             LanguageType eLang )
54         :
55         xSMgr( xSF ),
56         pCharClass( NULL ),
57         pLocaleData( NULL ),
58         pCalendar( NULL ),
59         pCollator( NULL ),
60         pCaseCollator( NULL ),
61         eLanguage( eLang )
62 {
63     MsLangId::convertLanguageToLocale( eLanguage, aLocale );
64 }
65 
66 
67 IntlWrapper::~IntlWrapper()
68 {
69     delete pCharClass;
70     delete pLocaleData;
71     delete pCalendar;
72     delete pCollator;
73     delete pCaseCollator;
74 }
75 
76 
77 void IntlWrapper::ImplNewCharClass() const
78 {
79     ((IntlWrapper*)this)->pCharClass = new CharClass( xSMgr, aLocale );
80 }
81 
82 
83 void IntlWrapper::ImplNewLocaleData() const
84 {
85     ((IntlWrapper*)this)->pLocaleData = new LocaleDataWrapper( xSMgr, aLocale );
86 }
87 
88 
89 void IntlWrapper::ImplNewCalendar() const
90 {
91     CalendarWrapper* p = new CalendarWrapper( xSMgr );
92     p->loadDefaultCalendar( aLocale );
93     ((IntlWrapper*)this)->pCalendar = p;
94 }
95 
96 
97 void IntlWrapper::ImplNewCollator( sal_Bool bCaseSensitive ) const
98 {
99     CollatorWrapper* p = new CollatorWrapper( xSMgr );
100     if ( bCaseSensitive )
101     {
102         p->loadDefaultCollator( aLocale, 0 );
103         ((IntlWrapper*)this)->pCaseCollator = p;
104     }
105     else
106     {
107         p->loadDefaultCollator( aLocale, ::com::sun::star::i18n::CollatorOptions::CollatorOptions_IGNORE_CASE );
108         ((IntlWrapper*)this)->pCollator = p;
109     }
110 }
111