/src/libreoffice/vcl/source/weld/DoubleNumericFormatter.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
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 | | |
10 | | #include <svl/numformat.hxx> |
11 | | #include <svl/zformat.hxx> |
12 | | #include <unotools/localedatawrapper.hxx> |
13 | | #include <vcl/weld/DoubleNumericFormatter.hxx> |
14 | | |
15 | | namespace weld |
16 | | { |
17 | | DoubleNumericFormatter::DoubleNumericFormatter(weld::Entry& rEntry) |
18 | 0 | : EntryFormatter(rEntry) |
19 | 0 | { |
20 | 0 | ResetConformanceTester(); |
21 | 0 | } |
22 | | |
23 | | DoubleNumericFormatter::DoubleNumericFormatter(weld::FormattedSpinButton& rSpinButton) |
24 | 0 | : EntryFormatter(rSpinButton) |
25 | 0 | { |
26 | 0 | ResetConformanceTester(); |
27 | 0 | } |
28 | | |
29 | 0 | DoubleNumericFormatter::~DoubleNumericFormatter() = default; |
30 | | |
31 | | void DoubleNumericFormatter::FormatChanged(FORMAT_CHANGE_TYPE nWhat) |
32 | 0 | { |
33 | 0 | ResetConformanceTester(); |
34 | 0 | EntryFormatter::FormatChanged(nWhat); |
35 | 0 | } |
36 | | |
37 | | bool DoubleNumericFormatter::CheckText(const OUString& sText) const |
38 | 0 | { |
39 | | // We'd like to implement this using the NumberFormatter::IsNumberFormat, but unfortunately, this doesn't |
40 | | // recognize fragments of numbers (like, for instance "1e", which happens during entering e.g. "1e10") |
41 | | // Thus, the roundabout way via a regular expression |
42 | 0 | return m_pNumberValidator->isValidNumericFragment(sText); |
43 | 0 | } |
44 | | |
45 | | void DoubleNumericFormatter::ResetConformanceTester() |
46 | 0 | { |
47 | | // the thousands and the decimal separator are language dependent |
48 | 0 | const SvNumberformat* pFormatEntry = GetOrCreateFormatter().GetEntry(m_nFormatKey); |
49 | |
|
50 | 0 | sal_Unicode cSeparatorThousand = ','; |
51 | 0 | sal_Unicode cSeparatorDecimal = '.'; |
52 | 0 | if (pFormatEntry) |
53 | 0 | { |
54 | 0 | LocaleDataWrapper aLocaleInfo(LanguageTag(pFormatEntry->GetLanguage())); |
55 | |
|
56 | 0 | OUString sSeparator = aLocaleInfo.getNumThousandSep(); |
57 | 0 | if (!sSeparator.isEmpty()) |
58 | 0 | cSeparatorThousand = sSeparator[0]; |
59 | |
|
60 | 0 | sSeparator = aLocaleInfo.getNumDecimalSep(); |
61 | 0 | if (!sSeparator.isEmpty()) |
62 | 0 | cSeparatorDecimal = sSeparator[0]; |
63 | 0 | } |
64 | |
|
65 | 0 | m_pNumberValidator.reset( |
66 | 0 | new validation::NumberValidator(cSeparatorThousand, cSeparatorDecimal)); |
67 | 0 | } |
68 | | } |
69 | | |
70 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |