Update ooo320-m1
[ooovba.git] / svx / source / unoedit / UnoForbiddenCharsTable.cxx
blob53b36fd9773a97c3f1641f9f8d7926c9c8db098d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UnoForbiddenCharsTable.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include "UnoForbiddenCharsTable.hxx"
34 #include "forbiddencharacterstable.hxx"
35 #include <vos/mutex.hxx>
36 #include <vcl/svapp.hxx>
37 #include "unolingu.hxx"
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::container;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::i18n;
44 using namespace ::rtl;
45 using namespace ::vos;
46 using namespace ::cppu;
48 SvxUnoForbiddenCharsTable::SvxUnoForbiddenCharsTable(ORef<SvxForbiddenCharactersTable> xForbiddenChars) :
49 mxForbiddenChars( xForbiddenChars )
53 SvxUnoForbiddenCharsTable::~SvxUnoForbiddenCharsTable()
57 void SvxUnoForbiddenCharsTable::onChange()
61 ForbiddenCharacters SvxUnoForbiddenCharsTable::getForbiddenCharacters( const Locale& rLocale )
62 throw(NoSuchElementException, RuntimeException)
64 OGuard aGuard( Application::GetSolarMutex() );
66 if(!mxForbiddenChars.isValid())
67 throw RuntimeException();
69 const LanguageType eLang = SvxLocaleToLanguage( rLocale );
70 const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, FALSE );
71 if(!pForbidden)
72 throw NoSuchElementException();
74 return *pForbidden;
77 sal_Bool SvxUnoForbiddenCharsTable::hasForbiddenCharacters( const Locale& rLocale )
78 throw(RuntimeException)
80 OGuard aGuard( Application::GetSolarMutex() );
82 if(!mxForbiddenChars.isValid())
83 return sal_False;
85 const LanguageType eLang = SvxLocaleToLanguage( rLocale );
86 const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, FALSE );
88 return NULL != pForbidden;
91 void SvxUnoForbiddenCharsTable::setForbiddenCharacters(const Locale& rLocale, const ForbiddenCharacters& rForbiddenCharacters )
92 throw(RuntimeException)
94 OGuard aGuard( Application::GetSolarMutex() );
96 if(!mxForbiddenChars.isValid())
97 throw RuntimeException();
99 const LanguageType eLang = SvxLocaleToLanguage( rLocale );
100 mxForbiddenChars->SetForbiddenCharacters( eLang, rForbiddenCharacters );
102 onChange();
105 void SvxUnoForbiddenCharsTable::removeForbiddenCharacters( const Locale& rLocale )
106 throw(RuntimeException)
108 OGuard aGuard( Application::GetSolarMutex() );
110 if(!mxForbiddenChars.isValid())
111 throw RuntimeException();
113 const LanguageType eLang = SvxLocaleToLanguage( rLocale );
114 mxForbiddenChars->ClearForbiddenCharacters( eLang );
116 onChange();
119 // XSupportedLocales
120 Sequence< Locale > SAL_CALL SvxUnoForbiddenCharsTable::getLocales()
121 throw(RuntimeException)
123 OGuard aGuard( Application::GetSolarMutex() );
125 const sal_Int32 nCount = mxForbiddenChars.isValid() ? mxForbiddenChars->Count() : 0;
127 Sequence< Locale > aLocales( nCount );
128 if( nCount )
130 Locale* pLocales = aLocales.getArray();
132 for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
134 const ULONG nLanguage = mxForbiddenChars->GetObjectKey( nIndex );
135 SvxLanguageToLocale ( *pLocales++, static_cast < LanguageType > (nLanguage) );
139 return aLocales;
142 sal_Bool SAL_CALL SvxUnoForbiddenCharsTable::hasLocale( const Locale& aLocale )
143 throw(RuntimeException)
145 OGuard aGuard( Application::GetSolarMutex() );
147 return hasForbiddenCharacters( aLocale );