1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_editeng.hxx"
26 
27 #include <editeng/forbiddencharacterstable.hxx>
28 
29 #include <unotools/localedatawrapper.hxx>
30 #include <editeng/unolingu.hxx>
31 
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 
SvxForbiddenCharactersTable(::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> xMSF,sal_uInt16 nISize,sal_uInt16 nGrow)34 SvxForbiddenCharactersTable::SvxForbiddenCharactersTable( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMSF, sal_uInt16 nISize, sal_uInt16 nGrow )
35  : SvxForbiddenCharactersTableImpl( nISize, nGrow )
36 {
37 	mxMSF = xMSF;
38 }
39 
40 
~SvxForbiddenCharactersTable()41 SvxForbiddenCharactersTable::~SvxForbiddenCharactersTable()
42 {
43 	for ( sal_uLong n = Count(); n; )
44 		delete GetObject( --n );
45 }
46 
47 
48 
GetForbiddenCharacters(sal_uInt16 nLanguage,sal_Bool bGetDefault) const49 const com::sun::star::i18n::ForbiddenCharacters* SvxForbiddenCharactersTable::GetForbiddenCharacters( sal_uInt16 nLanguage, sal_Bool bGetDefault ) const
50 {
51 	ForbiddenCharactersInfo* pInf = Get( nLanguage );
52 	if ( !pInf && bGetDefault && mxMSF.is() )
53 	{
54 		const SvxForbiddenCharactersTableImpl *pConstImpl = dynamic_cast<const SvxForbiddenCharactersTableImpl*>(this);
55 		SvxForbiddenCharactersTableImpl* pImpl = const_cast<SvxForbiddenCharactersTableImpl*>(pConstImpl);
56  		pInf = new ForbiddenCharactersInfo;
57 		pImpl->Insert( nLanguage, pInf );
58 
59 		pInf->bTemporary = sal_True;
60 		LocaleDataWrapper aWrapper( mxMSF, SvxCreateLocale( nLanguage ) );
61 		pInf->aForbiddenChars = aWrapper.getForbiddenCharacters();
62 	}
63 	return pInf ? &pInf->aForbiddenChars : NULL;
64 }
65 
66 
67 
SetForbiddenCharacters(sal_uInt16 nLanguage,const com::sun::star::i18n::ForbiddenCharacters & rForbiddenChars)68 void SvxForbiddenCharactersTable::SetForbiddenCharacters( sal_uInt16 nLanguage, const com::sun::star::i18n::ForbiddenCharacters& rForbiddenChars )
69 {
70 	ForbiddenCharactersInfo* pInf = Get( nLanguage );
71 	if ( !pInf )
72 	{
73 		pInf = new ForbiddenCharactersInfo;
74 		Insert( nLanguage, pInf );
75 	}
76 	pInf->bTemporary = sal_False;
77 	pInf->aForbiddenChars = rForbiddenChars;
78 }
79 
ClearForbiddenCharacters(sal_uInt16 nLanguage)80 void SvxForbiddenCharactersTable::ClearForbiddenCharacters( sal_uInt16 nLanguage )
81 {
82 	ForbiddenCharactersInfo* pInf = Get( nLanguage );
83 	if ( pInf )
84 	{
85 		Remove( nLanguage );
86 		delete pInf;
87 	}
88 }
89