summaryrefslogtreecommitdiffstats
path: root/include/unotools/syslocaleoptions.hxx
blob: c0fab39a76c6ec733c56bc1be3a05ae624556963 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_UNOTOOLS_SYSLOCALEOPTIONS_HXX
#define INCLUDED_UNOTOOLS_SYSLOCALEOPTIONS_HXX

#include <unotools/unotoolsdllapi.h>
#include <sal/types.h>
#include <rtl/ustring.hxx>
#include <i18nlangtag/lang.h>
#include <i18nlangtag/languagetag.hxx>
#include <unotools/options.hxx>

class SvtSysLocaleOptions_Impl;
class LinkParamNone;
template <typename Arg, typename Ret> class Link;

class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtSysLocaleOptions final : public utl::detail::Options
{
    std::shared_ptr<SvtSysLocaleOptions_Impl>  pImpl;

    virtual void ConfigurationChanged( utl::ConfigurationBroadcaster* p, ConfigurationHints nHint ) override;

public:

    enum class EOption
    {
        Locale,
        Currency,
        DatePatterns,
        DecimalSeparator,
        IgnoreLanguageChange
    };
                                SvtSysLocaleOptions();
                                virtual ~SvtSysLocaleOptions() override;

    // ConfigItem methods

            bool                IsModified() const;
            void                Commit();

                                /** Add a listener to react on config changes
                                    which are broadcasted in a SfxSimpleHint
                                    @return
                                        <TRUE/> if added
                                        <FALSE/> if not added
                                 */

    /** Block broadcasts and accumulate hints. This may be useful if, for
        example, the locale and currency are changed and the currency was
        empty before, since changing the locale with an empty currency does
        also broadcast a change hint for the currency which would result in
        two currency changes broadcasted.

        @param bBlock
            <TRUE/>: broadcasts are blocked until reversed.
            <FALSE/>: broadcasts are not blocked anymore. Pending hints are
            broadcasted if no other instance blocks the broadcast.

        @ATTENTION
        All SvtSysLocaleOptions instances point to exactly one refcounted
        internal representation instance and broadcast blocks are counted.
        Thus if you issue a BlockBroadcasts(true) you MUST issue a matching
        BlockBroadcasts(false) or otherwise pending hints would never be
        broadcasted again.
     */
       virtual void             BlockBroadcasts( bool bBlock ) override;

    // config value access methods

    /// The config string may be empty to denote the SYSTEM locale
            void                SetLocaleConfigString( const OUString& rStr );
            /** Get locale set, not resolved to the real locale. */
            LanguageTag         GetLanguageTag() const;
            /** Get locale set, always resolved to the real locale. */
            const LanguageTag&  GetRealLanguageTag() const;

    /// The config string may be empty to denote the SYSTEM locale
            void                SetUILocaleConfigString( const OUString& rStr );
            /** Get UI locale set, always resolved to the real locale. */
            const LanguageTag&  GetRealUILanguageTag() const;

    /// The config string may be empty to denote the default currency of the locale
            const OUString&     GetCurrencyConfigString() const;
            void                SetCurrencyConfigString( const OUString& rStr );

    /** The config string may be empty to denote the default
        DateAcceptancePatterns of the locale */
            const OUString&     GetDatePatternsConfigString() const;
            void                SetDatePatternsConfigString( const OUString& rStr );

    // determine whether the decimal separator defined in the keyboard layout is used
    // or the one appropriate to the locale
            bool                IsDecimalSeparatorAsLocale() const;
            void                SetDecimalSeparatorAsLocale( bool bSet);

    // determine whether to ignore changes to the system keyboard/locale/language when
    // determining the language for newly entered text
            bool                IsIgnoreLanguageChange() const;
            void                SetIgnoreLanguageChange( bool bSet);

    // convenience methods

    /// Get currency abbreviation and locale from an USD-en-US or EUR-de-DE string
    static  void                GetCurrencyAbbrevAndLanguage(
                                    OUString& rAbbrev,
                                    LanguageType& eLang,
                                    const OUString& rConfigString );

    /// Create an USD-en-US or EUR-de-DE string
    static  OUString            CreateCurrencyConfigString(
                                    const OUString& rAbbrev,
                                    LanguageType eLang );

            void                GetCurrencyAbbrevAndLanguage(
                                        OUString& rAbbrev,
                                        LanguageType& eLang ) const
                                    {
                                        GetCurrencyAbbrevAndLanguage( rAbbrev,
                                            eLang, GetCurrencyConfigString() );
                                    }

    /** Set a link to a method to be called whenever the default currency
        changes. This can be only one method, and normally it is the static
        link method which calls SvNumberFormatter::SetDefaultSystemCurrency().
        This is needed because the number formatter isn't part of the svl light
        library, otherwise we could call SetDefaultSystemCurrency() directly.
     */
    static  void                SetCurrencyChangeLink( const Link<LinkParamNone*,void>& rLink );
    static  const Link<LinkParamNone*,void>&       GetCurrencyChangeLink();

    /** return the readonly state of the queried option. */
            bool                IsReadOnly( EOption eOption ) const;
};

#endif // INCLUDED_UNOTOOLS_SYSLOCALEOPTIONS_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */