/src/libreoffice/sc/source/ui/docshell/DocumentModelAccessor.cxx
Line | Count | Source |
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 | | |
10 | | #include <DocumentModelAccessor.hxx> |
11 | | |
12 | | #include <document.hxx> |
13 | | #include <docpool.hxx> |
14 | | #include <svl/intitem.hxx> |
15 | | #include <svl/zformat.hxx> |
16 | | #include <svl/zforlist.hxx> |
17 | | #include <svl/numformat.hxx> |
18 | | #include <svl/itempool.hxx> |
19 | | |
20 | | namespace |
21 | | { |
22 | | struct CurrencyIDLess |
23 | | { |
24 | | bool operator()(const sfx::CurrencyID& lhs, const sfx::CurrencyID& rhs) const |
25 | 0 | { |
26 | 0 | return std::tie(lhs.aSymbol, lhs.aExtension, lhs.eLanguage) |
27 | 0 | < std::tie(rhs.aSymbol, rhs.aExtension, rhs.eLanguage); |
28 | 0 | } |
29 | | }; |
30 | | struct CurrencyIDEquals |
31 | | { |
32 | | bool operator()(const sfx::CurrencyID& lhs, const sfx::CurrencyID& rhs) const |
33 | 0 | { |
34 | 0 | return std::tie(lhs.aSymbol, lhs.aExtension, lhs.eLanguage) |
35 | 0 | == std::tie(rhs.aSymbol, rhs.aExtension, rhs.eLanguage); |
36 | 0 | } |
37 | | }; |
38 | | |
39 | | } // anonymous |
40 | | |
41 | | namespace sc |
42 | | { |
43 | | std::vector<sfx::CurrencyID> DocumentModelAccessor::getDocumentCurrencies() const |
44 | 0 | { |
45 | 0 | SvNumberFormatter* pFormatter = m_pDocument->GetFormatTable(); |
46 | 0 | if (!pFormatter) |
47 | 0 | return {}; |
48 | | |
49 | 0 | std::vector<sfx::CurrencyID> aCurrencyIDs; |
50 | |
|
51 | 0 | const SvNFFormatData& rFormatData = pFormatter->GetROFormatData(); |
52 | 0 | const SvNFFormatData::FormatEntryMap& rEntryMap = rFormatData.GetFormatEntryMap(); |
53 | 0 | for (const auto& rPair : rEntryMap) |
54 | 0 | { |
55 | 0 | SvNumberformat const* pEntry = rPair.second.get(); |
56 | 0 | if (pEntry && pEntry->GetMaskedType() == SvNumFormatType::CURRENCY |
57 | 0 | && pEntry->HasNewCurrency() && pEntry->GetLanguage() != LANGUAGE_SYSTEM |
58 | 0 | && !pEntry->IsAdditionalBuiltin()) |
59 | 0 | { |
60 | 0 | OUString aSymbol; |
61 | 0 | OUString aExtension; |
62 | 0 | pEntry->GetNewCurrencySymbol(aSymbol, aExtension); |
63 | 0 | aCurrencyIDs.push_back({ aSymbol, aExtension, pEntry->GetLanguage() }); |
64 | 0 | } |
65 | 0 | } |
66 | | |
67 | | // remove duplicates |
68 | 0 | std::sort(aCurrencyIDs.begin(), aCurrencyIDs.end(), CurrencyIDLess()); |
69 | 0 | aCurrencyIDs.erase(std::unique(aCurrencyIDs.begin(), aCurrencyIDs.end(), CurrencyIDEquals()), |
70 | 0 | aCurrencyIDs.end()); |
71 | 0 | return aCurrencyIDs; |
72 | 0 | } |
73 | | |
74 | | } // end sc |
75 | | |
76 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |