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 #ifndef INCLUDED_SVTOOLS_SYSLOCALEOPTIONS_HXX
25 #define INCLUDED_SVTOOLS_SYSLOCALEOPTIONS_HXX
26 
27 #include "unotools/unotoolsdllapi.h"
28 #include <sal/types.h>
29 #include <rtl/ustring.hxx>
30 #include <tools/solar.h>
31 #include <tools/link.hxx>
32 #include <i18npool/lang.h>
33 #include <tools/string.hxx>
34 #include <unotools/options.hxx>
35 
36 // bits for broadcasting hints of changes in a SfxSimpleHint, may be combined
37 const sal_uLong SYSLOCALEOPTIONS_HINT_LOCALE    = 0x00000001;
38 const sal_uLong SYSLOCALEOPTIONS_HINT_CURRENCY  = 0x00000002;
39 const sal_uLong SYSLOCALEOPTIONS_HINT_UILOCALE  = 0x00000004;
40 const sal_uLong SYSLOCALEOPTIONS_HINT_DECSEP    = 0x00000008;
41 
42 class SvtSysLocaleOptions_Impl;
43 class SvtListener;
44 namespace osl { class Mutex; }
45 
46 class UNOTOOLS_DLLPUBLIC SvtSysLocaleOptions: public utl::detail::Options
47 {
48     static  SvtSysLocaleOptions_Impl*   pOptions;
49     static  sal_Int32                   nRefCount;
50 
51     UNOTOOLS_DLLPRIVATE static  ::osl::Mutex&       GetMutex();
52     virtual void ConfigurationChanged( utl::ConfigurationBroadcaster* p, sal_uInt32 nHint );
53 
54 public:
55 
56     enum EOption
57     {
58         E_LOCALE,
59 		E_UILOCALE,
60         E_CURRENCY
61     };
62                                 SvtSysLocaleOptions();
63                                 virtual ~SvtSysLocaleOptions();
64 
65     // ConfigItem methods
66 
67             sal_Bool            IsModified();
68             void                Commit();
69 
70                                 /** Add a listener to react on config changes
71                                     which are broadcasted in a SfxSimpleHint
72                                     @return
73                                         <TRUE/> if added
74                                         <FALSE/> if not added
75                                  */
76 
77     /** Block broadcasts and accumulate hints. This may be useful if, for
78         example, the locale and currency are changed and the currency was
79         empty before, since changing the locale with an empty currency does
80         also broadcast a change hint for the currency which would result in
81         two currency changes broadcasted.
82 
83         @param bBlock
84             <TRUE/>: broadcasts are blocked until reversed.
85             <FALSE/>: broadcasts are not blocked anymore. Pending hints are
86             broadcasted if no other instance blocks the broadcast.
87 
88         @ATTENTION
89         All SvtSysLocaleOptions instances point to exactly one refcounted
90         internal representation instance and broadcast blocks are counted.
91         Thus if you issue a BlockBroadcasts(sal_True) you MUST issue a matching
92         BlockBroadcasts(sal_False) or otherwise pending hints would never be
93         broadcasted again.
94      */
95        virtual void                BlockBroadcasts( bool bBlock );
96 
97     // config value access methods
98 
99     /// The config string may be empty to denote the SYSTEM locale
100             const ::rtl::OUString&  GetLocaleConfigString() const;
101             void                SetLocaleConfigString( const ::rtl::OUString& rStr );
102 			com::sun::star::lang::Locale GetLocale() const;
103 			com::sun::star::lang::Locale GetRealLocale() const;
104 			LanguageType		GetRealLanguage() const;
105 
106     /// The config string may be empty to denote the SYSTEM locale
107             const ::rtl::OUString&  GetUILocaleConfigString() const;
108             void                SetUILocaleConfigString( const ::rtl::OUString& rStr );
109 			com::sun::star::lang::Locale GetUILocale() const;
110 			com::sun::star::lang::Locale GetRealUILocale() const;
111 			LanguageType		GetRealUILanguage() const;
112 
113     /// The config string may be empty to denote the default currency of the locale
114             const ::rtl::OUString&  GetCurrencyConfigString() const;
115             void                SetCurrencyConfigString( const ::rtl::OUString& rStr );
116     // determine whether the decimal separator defined in the keyboard layout is used
117     // or the one approriate to the locale
118             sal_Bool            IsDecimalSeparatorAsLocale() const;
119             void                SetDecimalSeparatorAsLocale( sal_Bool bSet);
120 
121     // convenience methods
122 
123     /// Get currency abbreviation and locale from an USD-en-US or EUR-de-DE string
124     static  void                GetCurrencyAbbrevAndLanguage(
125                                     String& rAbbrev,
126                                     LanguageType& eLang,
127                                     const ::rtl::OUString& rConfigString );
128 
129     /// Create an USD-en-US or EUR-de-DE string
130     static  ::rtl::OUString     CreateCurrencyConfigString(
131                                     const String& rAbbrev,
132                                     LanguageType eLang );
133 
GetCurrencyAbbrevAndLanguage(String & rAbbrev,LanguageType & eLang) const134             void                GetCurrencyAbbrevAndLanguage(
135                                         String& rAbbrev,
136                                         LanguageType& eLang ) const
137                                     {
138                                         GetCurrencyAbbrevAndLanguage( rAbbrev,
139                                             eLang, GetCurrencyConfigString() );
140                                     }
141 
SetCurrencyAbbrevAndLanguage(const String & rAbbrev,LanguageType eLang)142             void                SetCurrencyAbbrevAndLanguage(
143                                         const String& rAbbrev,
144                                         LanguageType eLang )
145                                     {
146                                         SetCurrencyConfigString(
147                                             CreateCurrencyConfigString(
148                                             rAbbrev, eLang ) );
149                                     }
150 
151     /** Set a link to a method to be called whenever the default currency
152         changes. This can be only one method, and normally it is the static
153         link method which calls SvNumberFormatter::SetDefaultSystemCurrency().
154         This is needed because the number formatter isn't part of the svl light
155         library, otherwise we could call SetDefaultSystemCurrency() directly.
156      */
157     static  void                SetCurrencyChangeLink( const Link& rLink );
158     static  const Link&         GetCurrencyChangeLink();
159 
160     /** return the readonly state of the queried option. */
161             sal_Bool            IsReadOnly( EOption eOption ) const;
162 };
163 
164 #endif  // INCLUDED_SVTOOLS_SYSLOCALEOPTIONS_HXX
165