1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/config.h>
22 #include <com/sun/star/container/NoSuchElementException.hpp>
23 #include <editeng/UnoForbiddenCharsTable.hxx>
24 #include <editeng/forbiddencharacterstable.hxx>
25 #include <i18nlangtag/languagetag.hxx>
27 #include <vcl/svapp.hxx>
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
;
36 SvxUnoForbiddenCharsTable::SvxUnoForbiddenCharsTable(std::shared_ptr
<SvxForbiddenCharactersTable
> xForbiddenChars
)
37 : mxForbiddenChars(std::move(xForbiddenChars
))
41 SvxUnoForbiddenCharsTable::~SvxUnoForbiddenCharsTable()
45 void SvxUnoForbiddenCharsTable::onChange()
49 ForbiddenCharacters
SvxUnoForbiddenCharsTable::getForbiddenCharacters( const lang::Locale
& rLocale
)
51 SolarMutexGuard aGuard
;
53 if (!mxForbiddenChars
)
54 throw RuntimeException("No Forbidden Characters present");
56 const LanguageType eLang
= LanguageTag::convertToLanguageType( rLocale
);
57 const ForbiddenCharacters
* pForbidden
= mxForbiddenChars
->GetForbiddenCharacters( eLang
, false );
59 throw NoSuchElementException();
64 sal_Bool
SvxUnoForbiddenCharsTable::hasForbiddenCharacters( const lang::Locale
& rLocale
)
66 SolarMutexGuard aGuard
;
68 if (!mxForbiddenChars
)
71 const LanguageType eLang
= LanguageTag::convertToLanguageType( rLocale
);
72 const ForbiddenCharacters
* pForbidden
= mxForbiddenChars
->GetForbiddenCharacters( eLang
, false );
74 return nullptr != pForbidden
;
77 void SvxUnoForbiddenCharsTable::setForbiddenCharacters(const lang::Locale
& rLocale
, const ForbiddenCharacters
& rForbiddenCharacters
)
79 SolarMutexGuard aGuard
;
81 if (!mxForbiddenChars
)
82 throw RuntimeException("No Forbidden Characters present");
84 const LanguageType eLang
= LanguageTag::convertToLanguageType( rLocale
);
85 mxForbiddenChars
->SetForbiddenCharacters( eLang
, rForbiddenCharacters
);
90 void SvxUnoForbiddenCharsTable::removeForbiddenCharacters( const lang::Locale
& rLocale
)
92 SolarMutexGuard aGuard
;
94 if (!mxForbiddenChars
)
95 throw RuntimeException("No Forbidden Characters present");
97 const LanguageType eLang
= LanguageTag::convertToLanguageType( rLocale
);
98 mxForbiddenChars
->ClearForbiddenCharacters( eLang
);
104 Sequence
< lang::Locale
> SAL_CALL
SvxUnoForbiddenCharsTable::getLocales()
106 SolarMutexGuard aGuard
;
108 const sal_Int32 nCount
= mxForbiddenChars
? mxForbiddenChars
->GetMap().size() : 0;
110 Sequence
< lang::Locale
> aLocales( nCount
);
113 lang::Locale
* pLocales
= aLocales
.getArray();
115 for (auto const& elem
: mxForbiddenChars
->GetMap())
117 const LanguageType nLanguage
= elem
.first
;
118 *pLocales
++ = LanguageTag( nLanguage
).getLocale();
125 sal_Bool SAL_CALL
SvxUnoForbiddenCharsTable::hasLocale( const lang::Locale
& aLocale
)
127 SolarMutexGuard aGuard
;
129 return hasForbiddenCharacters( aLocale
);
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */