tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / core / tool / numformat.cxx
blobc69da6de4e3b4f50c1418b25e8d2f98b95dc2245
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <numformat.hxx>
21 #include <patattr.hxx>
22 #include <document.hxx>
24 #include <comphelper/processfactory.hxx>
25 #include <svl/numformat.hxx>
26 #include <svl/zformat.hxx>
27 #include <svl/languageoptions.hxx>
28 #include <optional>
30 namespace
32 const OUString& getNumDecimalSep(const SvNumberformat& rFormat)
34 LanguageType nFormatLang = rFormat.GetLanguage();
35 if (nFormatLang == LANGUAGE_SYSTEM)
36 return ScGlobal::getLocaleData().getNumDecimalSep();
37 // LocaleDataWrapper can be expensive to construct, so cache the result for
38 // repeated calls
39 static std::optional<LocaleDataWrapper> localeCache;
40 if (!localeCache || localeCache->getLanguageTag().getLanguageType() != nFormatLang)
41 localeCache.emplace(
42 comphelper::getProcessComponentContext(), LanguageTag(nFormatLang));
43 return localeCache->getNumDecimalSep();
47 namespace sc {
49 bool NumFmtUtil::isLatinScript( const ScPatternAttr& rPat, ScDocument& rDoc )
51 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
52 sal_uInt32 nKey = rPat.GetNumberFormat(pFormatter);
53 return isLatinScript(nKey, rDoc);
56 bool NumFmtUtil::isLatinScript( sal_uLong nFormat, ScDocument& rDoc )
58 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
59 const SvNumberformat* pFormat = pFormatter->GetEntry(nFormat);
60 if (!pFormat || !pFormat->IsStandard())
61 return false;
63 // The standard format is all-latin if the decimal separator doesn't
64 // have a different script type
65 SvtScriptType nScript = rDoc.GetStringScriptType(getNumDecimalSep(*pFormat));
66 return (nScript == SvtScriptType::NONE || nScript == SvtScriptType::LATIN);
71 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */