/src/libreoffice/editeng/source/uno/UnoForbiddenCharsTable.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 | | * 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 | | #include <sal/config.h> |
21 | | |
22 | | #include <com/sun/star/container/NoSuchElementException.hpp> |
23 | | #include <editeng/UnoForbiddenCharsTable.hxx> |
24 | | #include <editeng/forbiddencharacterstable.hxx> |
25 | | #include <i18nlangtag/languagetag.hxx> |
26 | | #include <utility> |
27 | | #include <vcl/svapp.hxx> |
28 | | |
29 | | using namespace ::com::sun::star; |
30 | | using namespace ::com::sun::star::uno; |
31 | | using namespace ::com::sun::star::container; |
32 | | using namespace ::com::sun::star::lang; |
33 | | using namespace ::com::sun::star::i18n; |
34 | | using namespace ::cppu; |
35 | | |
36 | | SvxUnoForbiddenCharsTable::SvxUnoForbiddenCharsTable(std::shared_ptr<SvxForbiddenCharactersTable> xForbiddenChars) |
37 | 2.92k | : mxForbiddenChars(std::move(xForbiddenChars)) |
38 | 2.92k | { |
39 | 2.92k | } |
40 | | |
41 | | SvxUnoForbiddenCharsTable::~SvxUnoForbiddenCharsTable() |
42 | 2.92k | { |
43 | 2.92k | } |
44 | | |
45 | | void SvxUnoForbiddenCharsTable::onChange() |
46 | 0 | { |
47 | 0 | } |
48 | | |
49 | | ForbiddenCharacters SvxUnoForbiddenCharsTable::getForbiddenCharacters( const lang::Locale& rLocale ) |
50 | 0 | { |
51 | 0 | SolarMutexGuard aGuard; |
52 | |
|
53 | 0 | if (!mxForbiddenChars) |
54 | 0 | throw RuntimeException(u"No Forbidden Characters present"_ustr); |
55 | | |
56 | 0 | const LanguageType eLang = LanguageTag::convertToLanguageType( rLocale ); |
57 | 0 | const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, false ); |
58 | 0 | if(!pForbidden) |
59 | 0 | throw NoSuchElementException(); |
60 | | |
61 | 0 | return *pForbidden; |
62 | 0 | } |
63 | | |
64 | | sal_Bool SvxUnoForbiddenCharsTable::hasForbiddenCharacters( const lang::Locale& rLocale ) |
65 | 0 | { |
66 | 0 | SolarMutexGuard aGuard; |
67 | |
|
68 | 0 | if (!mxForbiddenChars) |
69 | 0 | return false; |
70 | | |
71 | 0 | const LanguageType eLang = LanguageTag::convertToLanguageType( rLocale ); |
72 | 0 | const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, false ); |
73 | |
|
74 | 0 | return nullptr != pForbidden; |
75 | 0 | } |
76 | | |
77 | | void SvxUnoForbiddenCharsTable::setForbiddenCharacters(const lang::Locale& rLocale, const ForbiddenCharacters& rForbiddenCharacters ) |
78 | 1.12k | { |
79 | 1.12k | SolarMutexGuard aGuard; |
80 | | |
81 | 1.12k | if (!mxForbiddenChars) |
82 | 0 | throw RuntimeException(u"No Forbidden Characters present"_ustr); |
83 | | |
84 | 1.12k | const LanguageType eLang = LanguageTag::convertToLanguageType( rLocale ); |
85 | 1.12k | mxForbiddenChars->SetForbiddenCharacters( eLang, rForbiddenCharacters ); |
86 | | |
87 | 1.12k | onChange(); |
88 | 1.12k | } |
89 | | |
90 | | void SvxUnoForbiddenCharsTable::removeForbiddenCharacters( const lang::Locale& rLocale ) |
91 | 0 | { |
92 | 0 | SolarMutexGuard aGuard; |
93 | |
|
94 | 0 | if (!mxForbiddenChars) |
95 | 0 | throw RuntimeException(u"No Forbidden Characters present"_ustr); |
96 | | |
97 | 0 | const LanguageType eLang = LanguageTag::convertToLanguageType( rLocale ); |
98 | 0 | mxForbiddenChars->ClearForbiddenCharacters( eLang ); |
99 | |
|
100 | 0 | onChange(); |
101 | 0 | } |
102 | | |
103 | | // XSupportedLocales |
104 | | Sequence< lang::Locale > SAL_CALL SvxUnoForbiddenCharsTable::getLocales() |
105 | 8 | { |
106 | 8 | SolarMutexGuard aGuard; |
107 | | |
108 | 8 | const sal_Int32 nCount = mxForbiddenChars ? mxForbiddenChars->GetMap().size() : 0; |
109 | | |
110 | 8 | Sequence< lang::Locale > aLocales( nCount ); |
111 | 8 | if( nCount ) |
112 | 0 | { |
113 | 0 | lang::Locale* pLocales = aLocales.getArray(); |
114 | |
|
115 | 0 | for (auto const& elem : mxForbiddenChars->GetMap()) |
116 | 0 | { |
117 | 0 | const LanguageType nLanguage = elem.first; |
118 | 0 | *pLocales++ = LanguageTag( nLanguage ).getLocale(); |
119 | 0 | } |
120 | 0 | } |
121 | | |
122 | 8 | return aLocales; |
123 | 8 | } |
124 | | |
125 | | sal_Bool SAL_CALL SvxUnoForbiddenCharsTable::hasLocale( const lang::Locale& aLocale ) |
126 | 0 | { |
127 | 0 | SolarMutexGuard aGuard; |
128 | |
|
129 | 0 | return hasForbiddenCharacters( aLocale ); |
130 | 0 | } |
131 | | |
132 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |