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 #include "unotools/unotoolsdllapi.h"
24 
25 #ifndef _UNOTOOLS_INTLWRAPPER_HXX
26 #define _UNOTOOLS_INTLWRAPPER_HXX
27 #include <unotools/charclass.hxx>
28 #include <unotools/localedatawrapper.hxx>
29 #include <unotools/calendarwrapper.hxx>
30 #include <unotools/collatorwrapper.hxx>
31 #include <i18npool/lang.h>
32 
33 
34 /**
35     A wrapper of I18N wrappers. Using this is more expensive than using some
36     single wrapper classes so use it only if you must pass a single pointer
37     without knowing in advance what is needed, e.g. for
38     SfxPoolItem::GetPresentation(). Remember that this wrapper was only created
39     for convenience to bypass some oddities, if possible don't use it. <p>
40 
41     Implemented are only the const get...() methods of the wrappers, which are
42     loaded on demand, for consistency reasons no change of locale is possible.
43     Only default calendar and default collator are supported. <p>
44 
45     One exception though is the calendar wrapper: to be able to set a value and
46     retrieve calendar values it is not const, so methods using this should
47     reset the calendar to the previous value if it isn't sure where the
48     IntlWrapper did come from. <p>
49  */
50 class UNOTOOLS_DLLPUBLIC IntlWrapper
51 {
52 private:
53 
54 	::com::sun::star::lang::Locale	aLocale;
55 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMgr;
56 
57             CharClass*          pCharClass;
58             LocaleDataWrapper*  pLocaleData;
59             CalendarWrapper*    pCalendar;
60             CollatorWrapper*    pCollator;
61             CollatorWrapper*    pCaseCollator;
62 
63             LanguageType        eLanguage;
64 
65             void                ImplNewCharClass() const;
66             void                ImplNewLocaleData() const;
67             void                ImplNewCalendar() const;
68             void                ImplNewCollator( sal_Bool bCaseSensitive ) const;
69 
70 
71 public:
72                                 IntlWrapper(
73 									const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF,
74 									const ::com::sun::star::lang::Locale& rLocale
75                                     );
76                                 IntlWrapper(
77 									const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF,
78                                     LanguageType eLang
79                                     );
80                                 ~IntlWrapper();
81 
getLanguage() const82     LanguageType                getLanguage() const { return eLanguage; }
getLocale() const83     const ::com::sun::star::lang::Locale&   getLocale() const { return aLocale; }
84 
getCharClass() const85     const CharClass*            getCharClass() const
86                                     {
87                                         if ( !pCharClass )
88                                             ImplNewCharClass();
89                                         return pCharClass;
90                                     }
getLocaleData() const91     const LocaleDataWrapper*    getLocaleData() const
92                                     {
93                                         if ( !pLocaleData )
94                                             ImplNewLocaleData();
95                                         return pLocaleData;
96                                     }
getCalendar() const97     CalendarWrapper*            getCalendar() const
98                                     {
99                                         if ( !pCalendar )
100                                             ImplNewCalendar();
101                                         return pCalendar;
102                                     }
103     /// case insensitive collator, simple IGNORE_CASE
getCollator() const104     const CollatorWrapper*      getCollator() const
105                                     {
106                                         if ( !pCollator )
107                                             ImplNewCollator( sal_False );
108                                         return pCollator;
109                                     }
110     /// case sensitive collator
getCaseCollator() const111     const CollatorWrapper*      getCaseCollator() const
112                                     {
113                                         if ( !pCaseCollator )
114                                             ImplNewCollator( sal_True );
115                                         return pCaseCollator;
116                                     }
117 };
118 
119 #endif // _UNOTOOLS_INTLWRAPPER_HXX
120