1*190118d0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*190118d0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*190118d0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*190118d0SAndrew Rist  * distributed with this work for additional information
6*190118d0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*190118d0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*190118d0SAndrew Rist  * "License"); you may not use this file except in compliance
9*190118d0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*190118d0SAndrew Rist  *
11*190118d0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*190118d0SAndrew Rist  *
13*190118d0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*190118d0SAndrew Rist  * software distributed under the License is distributed on an
15*190118d0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*190118d0SAndrew Rist  * KIND, either express or implied.  See the License for the
17*190118d0SAndrew Rist  * specific language governing permissions and limitations
18*190118d0SAndrew Rist  * under the License.
19*190118d0SAndrew Rist  *
20*190118d0SAndrew Rist  *************************************************************/
21*190118d0SAndrew Rist 
22*190118d0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_editeng.hxx"
26cdf0e10cSrcweir #include <editeng/UnoForbiddenCharsTable.hxx>
27cdf0e10cSrcweir #include <editeng/forbiddencharacterstable.hxx>
28cdf0e10cSrcweir #include <vos/mutex.hxx>
29cdf0e10cSrcweir #include <vcl/svapp.hxx>
30cdf0e10cSrcweir #include <editeng/unolingu.hxx> // LocalToLanguage, LanguageToLocale
31cdf0e10cSrcweir 
32cdf0e10cSrcweir using namespace ::com::sun::star;
33cdf0e10cSrcweir using namespace ::com::sun::star::uno;
34cdf0e10cSrcweir using namespace ::com::sun::star::container;
35cdf0e10cSrcweir using namespace ::com::sun::star::lang;
36cdf0e10cSrcweir using namespace ::com::sun::star::i18n;
37cdf0e10cSrcweir using namespace ::rtl;
38cdf0e10cSrcweir using namespace ::vos;
39cdf0e10cSrcweir using namespace ::cppu;
40cdf0e10cSrcweir 
SvxUnoForbiddenCharsTable(ORef<SvxForbiddenCharactersTable> xForbiddenChars)41cdf0e10cSrcweir SvxUnoForbiddenCharsTable::SvxUnoForbiddenCharsTable(ORef<SvxForbiddenCharactersTable> xForbiddenChars) :
42cdf0e10cSrcweir 	mxForbiddenChars( xForbiddenChars )
43cdf0e10cSrcweir {
44cdf0e10cSrcweir }
45cdf0e10cSrcweir 
~SvxUnoForbiddenCharsTable()46cdf0e10cSrcweir SvxUnoForbiddenCharsTable::~SvxUnoForbiddenCharsTable()
47cdf0e10cSrcweir {
48cdf0e10cSrcweir }
49cdf0e10cSrcweir 
onChange()50cdf0e10cSrcweir void SvxUnoForbiddenCharsTable::onChange()
51cdf0e10cSrcweir {
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
getForbiddenCharacters(const Locale & rLocale)54cdf0e10cSrcweir ForbiddenCharacters SvxUnoForbiddenCharsTable::getForbiddenCharacters( const Locale& rLocale )
55cdf0e10cSrcweir 	throw(NoSuchElementException, RuntimeException)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	if(!mxForbiddenChars.isValid())
60cdf0e10cSrcweir 		throw RuntimeException();
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	const LanguageType eLang = SvxLocaleToLanguage( rLocale );
63cdf0e10cSrcweir 	const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, sal_False );
64cdf0e10cSrcweir 	if(!pForbidden)
65cdf0e10cSrcweir 		throw NoSuchElementException();
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	return *pForbidden;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
hasForbiddenCharacters(const Locale & rLocale)70cdf0e10cSrcweir sal_Bool SvxUnoForbiddenCharsTable::hasForbiddenCharacters( const Locale& rLocale )
71cdf0e10cSrcweir 	throw(RuntimeException)
72cdf0e10cSrcweir {
73cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	if(!mxForbiddenChars.isValid())
76cdf0e10cSrcweir 		return sal_False;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	const LanguageType eLang = SvxLocaleToLanguage( rLocale );
79cdf0e10cSrcweir 	const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, sal_False );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	return NULL != pForbidden;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
setForbiddenCharacters(const Locale & rLocale,const ForbiddenCharacters & rForbiddenCharacters)84cdf0e10cSrcweir void SvxUnoForbiddenCharsTable::setForbiddenCharacters(const Locale& rLocale, const ForbiddenCharacters& rForbiddenCharacters )
85cdf0e10cSrcweir 	throw(RuntimeException)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	if(!mxForbiddenChars.isValid())
90cdf0e10cSrcweir 		throw RuntimeException();
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	const LanguageType eLang = SvxLocaleToLanguage( rLocale );
93cdf0e10cSrcweir 	mxForbiddenChars->SetForbiddenCharacters( eLang, rForbiddenCharacters );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	onChange();
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
removeForbiddenCharacters(const Locale & rLocale)98cdf0e10cSrcweir void SvxUnoForbiddenCharsTable::removeForbiddenCharacters( const Locale& rLocale )
99cdf0e10cSrcweir 	throw(RuntimeException)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	if(!mxForbiddenChars.isValid())
104cdf0e10cSrcweir 		throw RuntimeException();
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	const LanguageType eLang = SvxLocaleToLanguage( rLocale );
107cdf0e10cSrcweir 	mxForbiddenChars->ClearForbiddenCharacters( eLang );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	onChange();
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir // XSupportedLocales
getLocales()113cdf0e10cSrcweir Sequence< Locale > SAL_CALL SvxUnoForbiddenCharsTable::getLocales()
114cdf0e10cSrcweir 	throw(RuntimeException)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	const sal_Int32 nCount = mxForbiddenChars.isValid() ? mxForbiddenChars->Count() : 0;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	Sequence< Locale > aLocales( nCount );
121cdf0e10cSrcweir 	if( nCount )
122cdf0e10cSrcweir 	{
123cdf0e10cSrcweir 		Locale* pLocales = aLocales.getArray();
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 		for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
126cdf0e10cSrcweir 		{
127cdf0e10cSrcweir 			const sal_uLong nLanguage = mxForbiddenChars->GetObjectKey( nIndex );
128cdf0e10cSrcweir 			SvxLanguageToLocale ( *pLocales++, static_cast < LanguageType > (nLanguage) );
129cdf0e10cSrcweir 		}
130cdf0e10cSrcweir 	}
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	return aLocales;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
hasLocale(const Locale & aLocale)135cdf0e10cSrcweir sal_Bool SAL_CALL SvxUnoForbiddenCharsTable::hasLocale( const Locale& aLocale )
136cdf0e10cSrcweir 	throw(RuntimeException)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	return hasForbiddenCharacters( aLocale );
141cdf0e10cSrcweir }
142