1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <editeng/UnoForbiddenCharsTable.hxx>
30 #include <editeng/forbiddencharacterstable.hxx>
31 #include <osl/mutex.hxx>
32 #include <vcl/svapp.hxx>
33 #include <editeng/unolingu.hxx> // LocalToLanguage, LanguageToLocale
35 using namespace ::com::sun::star
;
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::container
;
38 using namespace ::com::sun::star::lang
;
39 using namespace ::com::sun::star::i18n
;
40 using namespace ::rtl
;
41 using namespace ::cppu
;
43 SvxUnoForbiddenCharsTable::SvxUnoForbiddenCharsTable(::rtl::Reference
<SvxForbiddenCharactersTable
> xForbiddenChars
) :
44 mxForbiddenChars( xForbiddenChars
)
48 SvxUnoForbiddenCharsTable::~SvxUnoForbiddenCharsTable()
52 void SvxUnoForbiddenCharsTable::onChange()
56 ForbiddenCharacters
SvxUnoForbiddenCharsTable::getForbiddenCharacters( const Locale
& rLocale
)
57 throw(NoSuchElementException
, RuntimeException
)
59 SolarMutexGuard aGuard
;
61 if(!mxForbiddenChars
.is())
62 throw RuntimeException();
64 const LanguageType eLang
= SvxLocaleToLanguage( rLocale
);
65 const ForbiddenCharacters
* pForbidden
= mxForbiddenChars
->GetForbiddenCharacters( eLang
, sal_False
);
67 throw NoSuchElementException();
72 sal_Bool
SvxUnoForbiddenCharsTable::hasForbiddenCharacters( const Locale
& rLocale
)
73 throw(RuntimeException
)
75 SolarMutexGuard aGuard
;
77 if(!mxForbiddenChars
.is())
80 const LanguageType eLang
= SvxLocaleToLanguage( rLocale
);
81 const ForbiddenCharacters
* pForbidden
= mxForbiddenChars
->GetForbiddenCharacters( eLang
, sal_False
);
83 return NULL
!= pForbidden
;
86 void SvxUnoForbiddenCharsTable::setForbiddenCharacters(const Locale
& rLocale
, const ForbiddenCharacters
& rForbiddenCharacters
)
87 throw(RuntimeException
)
89 SolarMutexGuard aGuard
;
91 if(!mxForbiddenChars
.is())
92 throw RuntimeException();
94 const LanguageType eLang
= SvxLocaleToLanguage( rLocale
);
95 mxForbiddenChars
->SetForbiddenCharacters( eLang
, rForbiddenCharacters
);
100 void SvxUnoForbiddenCharsTable::removeForbiddenCharacters( const Locale
& rLocale
)
101 throw(RuntimeException
)
103 SolarMutexGuard aGuard
;
105 if(!mxForbiddenChars
.is())
106 throw RuntimeException();
108 const LanguageType eLang
= SvxLocaleToLanguage( rLocale
);
109 mxForbiddenChars
->ClearForbiddenCharacters( eLang
);
115 Sequence
< Locale
> SAL_CALL
SvxUnoForbiddenCharsTable::getLocales()
116 throw(RuntimeException
)
118 SolarMutexGuard aGuard
;
120 const sal_Int32 nCount
= mxForbiddenChars
.is() ? mxForbiddenChars
->GetMap().size() : 0;
122 Sequence
< Locale
> aLocales( nCount
);
125 Locale
* pLocales
= aLocales
.getArray();
127 for( SvxForbiddenCharactersTable::Map::iterator it
= mxForbiddenChars
->GetMap().begin();
128 it
!= mxForbiddenChars
->GetMap().end(); ++it
)
130 const sal_uLong nLanguage
= it
->first
;
131 SvxLanguageToLocale ( *pLocales
++, static_cast < LanguageType
> (nLanguage
) );
138 sal_Bool SAL_CALL
SvxUnoForbiddenCharsTable::hasLocale( const Locale
& aLocale
)
139 throw(RuntimeException
)
141 SolarMutexGuard aGuard
;
143 return hasForbiddenCharacters( aLocale
);
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */