1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_editeng.hxx" 30 #include <editeng/UnoForbiddenCharsTable.hxx> 31 #include <editeng/forbiddencharacterstable.hxx> 32 #include <vos/mutex.hxx> 33 #include <vcl/svapp.hxx> 34 #include <editeng/unolingu.hxx> // LocalToLanguage, LanguageToLocale 35 36 using namespace ::com::sun::star; 37 using namespace ::com::sun::star::uno; 38 using namespace ::com::sun::star::container; 39 using namespace ::com::sun::star::lang; 40 using namespace ::com::sun::star::i18n; 41 using namespace ::rtl; 42 using namespace ::vos; 43 using namespace ::cppu; 44 45 SvxUnoForbiddenCharsTable::SvxUnoForbiddenCharsTable(ORef<SvxForbiddenCharactersTable> xForbiddenChars) : 46 mxForbiddenChars( xForbiddenChars ) 47 { 48 } 49 50 SvxUnoForbiddenCharsTable::~SvxUnoForbiddenCharsTable() 51 { 52 } 53 54 void SvxUnoForbiddenCharsTable::onChange() 55 { 56 } 57 58 ForbiddenCharacters SvxUnoForbiddenCharsTable::getForbiddenCharacters( const Locale& rLocale ) 59 throw(NoSuchElementException, RuntimeException) 60 { 61 OGuard aGuard( Application::GetSolarMutex() ); 62 63 if(!mxForbiddenChars.isValid()) 64 throw RuntimeException(); 65 66 const LanguageType eLang = SvxLocaleToLanguage( rLocale ); 67 const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, sal_False ); 68 if(!pForbidden) 69 throw NoSuchElementException(); 70 71 return *pForbidden; 72 } 73 74 sal_Bool SvxUnoForbiddenCharsTable::hasForbiddenCharacters( const Locale& rLocale ) 75 throw(RuntimeException) 76 { 77 OGuard aGuard( Application::GetSolarMutex() ); 78 79 if(!mxForbiddenChars.isValid()) 80 return sal_False; 81 82 const LanguageType eLang = SvxLocaleToLanguage( rLocale ); 83 const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, sal_False ); 84 85 return NULL != pForbidden; 86 } 87 88 void SvxUnoForbiddenCharsTable::setForbiddenCharacters(const Locale& rLocale, const ForbiddenCharacters& rForbiddenCharacters ) 89 throw(RuntimeException) 90 { 91 OGuard aGuard( Application::GetSolarMutex() ); 92 93 if(!mxForbiddenChars.isValid()) 94 throw RuntimeException(); 95 96 const LanguageType eLang = SvxLocaleToLanguage( rLocale ); 97 mxForbiddenChars->SetForbiddenCharacters( eLang, rForbiddenCharacters ); 98 99 onChange(); 100 } 101 102 void SvxUnoForbiddenCharsTable::removeForbiddenCharacters( const Locale& rLocale ) 103 throw(RuntimeException) 104 { 105 OGuard aGuard( Application::GetSolarMutex() ); 106 107 if(!mxForbiddenChars.isValid()) 108 throw RuntimeException(); 109 110 const LanguageType eLang = SvxLocaleToLanguage( rLocale ); 111 mxForbiddenChars->ClearForbiddenCharacters( eLang ); 112 113 onChange(); 114 } 115 116 // XSupportedLocales 117 Sequence< Locale > SAL_CALL SvxUnoForbiddenCharsTable::getLocales() 118 throw(RuntimeException) 119 { 120 OGuard aGuard( Application::GetSolarMutex() ); 121 122 const sal_Int32 nCount = mxForbiddenChars.isValid() ? mxForbiddenChars->Count() : 0; 123 124 Sequence< Locale > aLocales( nCount ); 125 if( nCount ) 126 { 127 Locale* pLocales = aLocales.getArray(); 128 129 for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ ) 130 { 131 const sal_uLong nLanguage = mxForbiddenChars->GetObjectKey( nIndex ); 132 SvxLanguageToLocale ( *pLocales++, static_cast < LanguageType > (nLanguage) ); 133 } 134 } 135 136 return aLocales; 137 } 138 139 sal_Bool SAL_CALL SvxUnoForbiddenCharsTable::hasLocale( const Locale& aLocale ) 140 throw(RuntimeException) 141 { 142 OGuard aGuard( Application::GetSolarMutex() ); 143 144 return hasForbiddenCharacters( aLocale ); 145 } 146