update credits
[LibreOffice.git] / editeng / source / uno / UnoForbiddenCharsTable.cxx
blob12dcee9be9a07b6a08604cccca61fd0ca46b9d6d
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 <editeng/UnoForbiddenCharsTable.hxx>
21 #include <editeng/forbiddencharacterstable.hxx>
22 #include <osl/mutex.hxx>
23 #include <vcl/svapp.hxx>
24 #include <editeng/unolingu.hxx> // LocalToLanguage, LanguageToLocale
26 using namespace ::com::sun::star;
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::container;
29 using namespace ::com::sun::star::lang;
30 using namespace ::com::sun::star::i18n;
31 using namespace ::rtl;
32 using namespace ::cppu;
34 SvxUnoForbiddenCharsTable::SvxUnoForbiddenCharsTable(::rtl::Reference<SvxForbiddenCharactersTable> xForbiddenChars) :
35 mxForbiddenChars( xForbiddenChars )
39 SvxUnoForbiddenCharsTable::~SvxUnoForbiddenCharsTable()
43 void SvxUnoForbiddenCharsTable::onChange()
47 ForbiddenCharacters SvxUnoForbiddenCharsTable::getForbiddenCharacters( const Locale& rLocale )
48 throw(NoSuchElementException, RuntimeException)
50 SolarMutexGuard aGuard;
52 if(!mxForbiddenChars.is())
53 throw RuntimeException();
55 const LanguageType eLang = LanguageTag( rLocale ).getLanguageType();
56 const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, sal_False );
57 if(!pForbidden)
58 throw NoSuchElementException();
60 return *pForbidden;
63 sal_Bool SvxUnoForbiddenCharsTable::hasForbiddenCharacters( const Locale& rLocale )
64 throw(RuntimeException)
66 SolarMutexGuard aGuard;
68 if(!mxForbiddenChars.is())
69 return sal_False;
71 const LanguageType eLang = LanguageTag( rLocale ).getLanguageType();
72 const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, sal_False );
74 return NULL != pForbidden;
77 void SvxUnoForbiddenCharsTable::setForbiddenCharacters(const Locale& rLocale, const ForbiddenCharacters& rForbiddenCharacters )
78 throw(RuntimeException)
80 SolarMutexGuard aGuard;
82 if(!mxForbiddenChars.is())
83 throw RuntimeException();
85 const LanguageType eLang = LanguageTag( rLocale ).getLanguageType();
86 mxForbiddenChars->SetForbiddenCharacters( eLang, rForbiddenCharacters );
88 onChange();
91 void SvxUnoForbiddenCharsTable::removeForbiddenCharacters( const Locale& rLocale )
92 throw(RuntimeException)
94 SolarMutexGuard aGuard;
96 if(!mxForbiddenChars.is())
97 throw RuntimeException();
99 const LanguageType eLang = LanguageTag( rLocale ).getLanguageType();
100 mxForbiddenChars->ClearForbiddenCharacters( eLang );
102 onChange();
105 // XSupportedLocales
106 Sequence< Locale > SAL_CALL SvxUnoForbiddenCharsTable::getLocales()
107 throw(RuntimeException)
109 SolarMutexGuard aGuard;
111 const sal_Int32 nCount = mxForbiddenChars.is() ? mxForbiddenChars->GetMap().size() : 0;
113 Sequence< Locale > aLocales( nCount );
114 if( nCount )
116 Locale* pLocales = aLocales.getArray();
118 for( SvxForbiddenCharactersTable::Map::iterator it = mxForbiddenChars->GetMap().begin();
119 it != mxForbiddenChars->GetMap().end(); ++it )
121 const sal_uLong nLanguage = it->first;
122 *pLocales++ = LanguageTag( static_cast < LanguageType > (nLanguage) ).getLocale();
126 return aLocales;
129 sal_Bool SAL_CALL SvxUnoForbiddenCharsTable::hasLocale( const Locale& aLocale )
130 throw(RuntimeException)
132 SolarMutexGuard aGuard;
134 return hasForbiddenCharacters( aLocale );
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */