Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_SVTOOLS_SYSLOCALEOPTIONS_HXX
21 : #define INCLUDED_SVTOOLS_SYSLOCALEOPTIONS_HXX
22 :
23 : #include "unotools/unotoolsdllapi.h"
24 : #include <sal/types.h>
25 : #include <rtl/ustring.hxx>
26 : #include <tools/solar.h>
27 : #include <tools/link.hxx>
28 : #include <i18npool/lang.h>
29 : #include <i18npool/languagetag.hxx>
30 : #include <tools/string.hxx>
31 : #include <unotools/options.hxx>
32 :
33 : // bits for broadcasting hints of changes in a SfxSimpleHint, may be combined
34 : const sal_uLong SYSLOCALEOPTIONS_HINT_LOCALE = 0x00000001;
35 : const sal_uLong SYSLOCALEOPTIONS_HINT_CURRENCY = 0x00000002;
36 : const sal_uLong SYSLOCALEOPTIONS_HINT_UILOCALE = 0x00000004;
37 : const sal_uLong SYSLOCALEOPTIONS_HINT_DECSEP = 0x00000008;
38 : const sal_uLong SYSLOCALEOPTIONS_HINT_DATEPATTERNS = 0x00000010;
39 : const sal_uLong SYSLOCALEOPTIONS_HINT_IGNORELANG = 0x00000020;
40 :
41 : class SvtSysLocaleOptions_Impl;
42 : class SvtListener;
43 : namespace osl { class Mutex; }
44 :
45 : class UNOTOOLS_DLLPUBLIC SAL_WARN_UNUSED SvtSysLocaleOptions : public utl::detail::Options
46 : {
47 : static SvtSysLocaleOptions_Impl* pOptions;
48 : static sal_Int32 nRefCount;
49 :
50 : UNOTOOLS_DLLPRIVATE static ::osl::Mutex& GetMutex();
51 : virtual void ConfigurationChanged( utl::ConfigurationBroadcaster* p, sal_uInt32 nHint );
52 :
53 : public:
54 :
55 : enum EOption
56 : {
57 : E_LOCALE,
58 : E_UILOCALE,
59 : E_CURRENCY,
60 : E_DATEPATTERNS
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 : /** Get locale set, if empty denotes SYSTEM locale, not resolved
103 : to the real locale. */
104 : LanguageTag GetLanguageTag() const;
105 : /** Get locale set, always resolved to the real locale. */
106 : const LanguageTag& GetRealLanguageTag() const;
107 :
108 : /// The config string may be empty to denote the SYSTEM locale
109 : void SetUILocaleConfigString( const ::rtl::OUString& rStr );
110 : /** Get UI locale set, always resolved to the real locale. */
111 : const LanguageTag& GetRealUILanguageTag() 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 :
117 : /** The config string may be empty to denote the default
118 : DateAcceptancePatterns of the locale */
119 : const ::rtl::OUString& GetDatePatternsConfigString() const;
120 : void SetDatePatternsConfigString( const ::rtl::OUString& rStr );
121 :
122 : // determine whether the decimal separator defined in the keyboard layout is used
123 : // or the one approriate to the locale
124 : sal_Bool IsDecimalSeparatorAsLocale() const;
125 : void SetDecimalSeparatorAsLocale( sal_Bool bSet);
126 :
127 : // determine whether to ignore changes to the system keyboard/locale/language when
128 : // determining the language for newly entered text
129 : sal_Bool IsIgnoreLanguageChange() const;
130 : void SetIgnoreLanguageChange( sal_Bool bSet);
131 :
132 : // convenience methods
133 :
134 : /// Get currency abbreviation and locale from an USD-en-US or EUR-de-DE string
135 : static void GetCurrencyAbbrevAndLanguage(
136 : String& rAbbrev,
137 : LanguageType& eLang,
138 : const ::rtl::OUString& rConfigString );
139 :
140 : /// Create an USD-en-US or EUR-de-DE string
141 : static ::rtl::OUString CreateCurrencyConfigString(
142 : const String& rAbbrev,
143 : LanguageType eLang );
144 :
145 4 : void GetCurrencyAbbrevAndLanguage(
146 : String& rAbbrev,
147 : LanguageType& eLang ) const
148 : {
149 : GetCurrencyAbbrevAndLanguage( rAbbrev,
150 4 : eLang, GetCurrencyConfigString() );
151 4 : }
152 :
153 : void SetCurrencyAbbrevAndLanguage(
154 : const String& rAbbrev,
155 : LanguageType eLang )
156 : {
157 : SetCurrencyConfigString(
158 : CreateCurrencyConfigString(
159 : rAbbrev, eLang ) );
160 : }
161 :
162 : /** Set a link to a method to be called whenever the default currency
163 : changes. This can be only one method, and normally it is the static
164 : link method which calls SvNumberFormatter::SetDefaultSystemCurrency().
165 : This is needed because the number formatter isn't part of the svl light
166 : library, otherwise we could call SetDefaultSystemCurrency() directly.
167 : */
168 : static void SetCurrencyChangeLink( const Link& rLink );
169 : static const Link& GetCurrencyChangeLink();
170 :
171 : /** return the readonly state of the queried option. */
172 : sal_Bool IsReadOnly( EOption eOption ) const;
173 : };
174 :
175 : #endif // INCLUDED_SVTOOLS_SYSLOCALEOPTIONS_HXX
176 :
177 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|