xref: /trunk/main/editeng/source/misc/forbiddencharacterstable.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 
31 #include <editeng/forbiddencharacterstable.hxx>
32 
33 #include <unotools/localedatawrapper.hxx>
34 #include <editeng/unolingu.hxx>
35 
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 
38 SvxForbiddenCharactersTable::SvxForbiddenCharactersTable( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMSF, sal_uInt16 nISize, sal_uInt16 nGrow )
39  : SvxForbiddenCharactersTableImpl( nISize, nGrow )
40 {
41     mxMSF = xMSF;
42 }
43 
44 
45 SvxForbiddenCharactersTable::~SvxForbiddenCharactersTable()
46 {
47     for ( sal_uLong n = Count(); n; )
48         delete GetObject( --n );
49 }
50 
51 
52 
53 const com::sun::star::i18n::ForbiddenCharacters* SvxForbiddenCharactersTable::GetForbiddenCharacters( sal_uInt16 nLanguage, sal_Bool bGetDefault ) const
54 {
55     ForbiddenCharactersInfo* pInf = Get( nLanguage );
56     if ( !pInf && bGetDefault && mxMSF.is() )
57     {
58         const SvxForbiddenCharactersTableImpl *pConstImpl = dynamic_cast<const SvxForbiddenCharactersTableImpl*>(this);
59         SvxForbiddenCharactersTableImpl* pImpl = const_cast<SvxForbiddenCharactersTableImpl*>(pConstImpl);
60         pInf = new ForbiddenCharactersInfo;
61         pImpl->Insert( nLanguage, pInf );
62 
63         pInf->bTemporary = sal_True;
64         LocaleDataWrapper aWrapper( mxMSF, SvxCreateLocale( nLanguage ) );
65         pInf->aForbiddenChars = aWrapper.getForbiddenCharacters();
66     }
67     return pInf ? &pInf->aForbiddenChars : NULL;
68 }
69 
70 
71 
72 void SvxForbiddenCharactersTable::SetForbiddenCharacters( sal_uInt16 nLanguage, const com::sun::star::i18n::ForbiddenCharacters& rForbiddenChars )
73 {
74     ForbiddenCharactersInfo* pInf = Get( nLanguage );
75     if ( !pInf )
76     {
77         pInf = new ForbiddenCharactersInfo;
78         Insert( nLanguage, pInf );
79     }
80     pInf->bTemporary = sal_False;
81     pInf->aForbiddenChars = rForbiddenChars;
82 }
83 
84 void SvxForbiddenCharactersTable::ClearForbiddenCharacters( sal_uInt16 nLanguage )
85 {
86     ForbiddenCharactersInfo* pInf = Get( nLanguage );
87     if ( pInf )
88     {
89         Remove( nLanguage );
90         delete pInf;
91     }
92 }
93