merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / config / languageoptions.cxx
blob204c06621c07efdd8470704f3999439a1db1f1f7
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: languageoptions.cxx,v $
10 * $Revision: 1.21 $
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_svtools.hxx"
34 #ifdef SVL_DLLIMPLEMENTATION
35 #undef SVL_DLLIMPLEMENTATION
36 #endif
37 #define SVT_DLLIMPLEMENTATION
39 #include <svtools/languageoptions.hxx>
40 #include <svtools/cjkoptions.hxx>
41 #include <svtools/ctloptions.hxx>
42 #include <vcl/svapp.hxx>
43 #include <i18npool/mslangid.hxx>
44 #include <vos/mutex.hxx>
45 #include <vcl/svapp.hxx>
46 #include <osl/mutex.hxx>
47 #include <rtl/instance.hxx>
48 #include <com/sun/star/i18n/ScriptType.hpp>
50 using namespace ::com::sun::star;
51 // global ----------------------------------------------------------------------
53 namespace { struct ALMutex : public rtl::Static< ::osl::Mutex, ALMutex > {}; }
55 // class SvtLanguageOptions ----------------------------------------------------
57 SvtLanguageOptions::SvtLanguageOptions( sal_Bool _bDontLoad )
59 // Global access, must be guarded (multithreading)
60 ::osl::MutexGuard aGuard( ALMutex::get() );
62 m_pCJKOptions = new SvtCJKOptions( _bDontLoad );
63 m_pCTLOptions = new SvtCTLOptions( _bDontLoad );
64 StartListening(*m_pCTLOptions);
66 //------------------------------------------------------------------------------
67 SvtLanguageOptions::~SvtLanguageOptions()
69 // Global access, must be guarded (multithreading)
70 ::osl::MutexGuard aGuard( ALMutex::get() );
72 delete m_pCJKOptions;
73 delete m_pCTLOptions;
75 //------------------------------------------------------------------------------
76 // CJK options -----------------------------------------------------------------
77 //------------------------------------------------------------------------------
78 sal_Bool SvtLanguageOptions::IsCJKFontEnabled() const
80 return m_pCJKOptions->IsCJKFontEnabled();
82 //------------------------------------------------------------------------------
83 sal_Bool SvtLanguageOptions::IsVerticalTextEnabled() const
85 return m_pCJKOptions->IsVerticalTextEnabled();
87 //------------------------------------------------------------------------------
88 sal_Bool SvtLanguageOptions::IsAsianTypographyEnabled() const
90 return m_pCJKOptions->IsAsianTypographyEnabled();
92 //------------------------------------------------------------------------------
93 sal_Bool SvtLanguageOptions::IsJapaneseFindEnabled() const
95 return m_pCJKOptions->IsJapaneseFindEnabled();
97 //------------------------------------------------------------------------------
98 sal_Bool SvtLanguageOptions::IsRubyEnabled() const
100 return m_pCJKOptions->IsRubyEnabled();
102 //------------------------------------------------------------------------------
103 sal_Bool SvtLanguageOptions::IsChangeCaseMapEnabled() const
105 return m_pCJKOptions->IsChangeCaseMapEnabled();
107 //------------------------------------------------------------------------------
108 sal_Bool SvtLanguageOptions::IsDoubleLinesEnabled() const
110 return m_pCJKOptions->IsDoubleLinesEnabled();
112 //------------------------------------------------------------------------------
113 sal_Bool SvtLanguageOptions::IsEmphasisMarksEnabled() const
115 return m_pCJKOptions->IsEmphasisMarksEnabled();
117 //------------------------------------------------------------------------------
118 sal_Bool SvtLanguageOptions::IsVerticalCallOutEnabled() const
120 return m_pCJKOptions->IsVerticalCallOutEnabled();
122 //------------------------------------------------------------------------------
123 void SvtLanguageOptions::SetAll( sal_Bool _bSet )
125 m_pCJKOptions->SetAll( _bSet );
127 //------------------------------------------------------------------------------
128 sal_Bool SvtLanguageOptions::IsAnyEnabled() const
130 return m_pCJKOptions->IsAnyEnabled();
132 //------------------------------------------------------------------------------
133 // CTL options -----------------------------------------------------------------
134 //------------------------------------------------------------------------------
135 void SvtLanguageOptions::SetCTLFontEnabled( sal_Bool _bEnabled )
137 m_pCTLOptions->SetCTLFontEnabled( _bEnabled );
139 //------------------------------------------------------------------------------
140 sal_Bool SvtLanguageOptions::IsCTLFontEnabled() const
142 return m_pCTLOptions->IsCTLFontEnabled();
144 //------------------------------------------------------------------------------
145 void SvtLanguageOptions::SetCTLSequenceChecking( sal_Bool _bEnabled )
147 m_pCTLOptions->SetCTLSequenceChecking( _bEnabled );
149 //------------------------------------------------------------------------------
150 sal_Bool SvtLanguageOptions::IsCTLSequenceChecking() const
152 return m_pCTLOptions->IsCTLSequenceChecking();
154 /*-- 26.09.2005 15:48:23---------------------------------------------------
156 -----------------------------------------------------------------------*/
157 void SvtLanguageOptions::SetCTLSequenceCheckingRestricted( sal_Bool _bEnable )
159 m_pCTLOptions->SetCTLSequenceCheckingRestricted( _bEnable );
161 /*-- 26.09.2005 15:48:23---------------------------------------------------
163 -----------------------------------------------------------------------*/
164 sal_Bool SvtLanguageOptions::IsCTLSequenceCheckingRestricted( void ) const
166 return m_pCTLOptions->IsCTLSequenceCheckingRestricted();
168 /*-- 26.09.2005 15:48:23---------------------------------------------------
170 -----------------------------------------------------------------------*/
171 void SvtLanguageOptions::SetCTLSequenceCheckingTypeAndReplace( sal_Bool _bEnable )
173 m_pCTLOptions->SetCTLSequenceCheckingTypeAndReplace( _bEnable );
175 /*-- 26.09.2005 15:48:24---------------------------------------------------
177 -----------------------------------------------------------------------*/
178 sal_Bool SvtLanguageOptions::IsCTLSequenceCheckingTypeAndReplace() const
180 return m_pCTLOptions->IsCTLSequenceCheckingTypeAndReplace();
183 //------------------------------------------------------------------------------
184 sal_Bool SvtLanguageOptions::IsReadOnly(SvtLanguageOptions::EOption eOption) const
186 sal_Bool bReadOnly = sal_False;
187 switch(eOption)
189 // cjk options
190 case SvtLanguageOptions::E_CJKFONT : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_CJKFONT ); break;
191 case SvtLanguageOptions::E_VERTICALTEXT : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_VERTICALTEXT ); break;
192 case SvtLanguageOptions::E_ASIANTYPOGRAPHY : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_ASIANTYPOGRAPHY); break;
193 case SvtLanguageOptions::E_JAPANESEFIND : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_JAPANESEFIND ); break;
194 case SvtLanguageOptions::E_RUBY : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_RUBY ); break;
195 case SvtLanguageOptions::E_CHANGECASEMAP : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_CHANGECASEMAP ); break;
196 case SvtLanguageOptions::E_DOUBLELINES : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_DOUBLELINES ); break;
197 case SvtLanguageOptions::E_EMPHASISMARKS : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_EMPHASISMARKS ); break;
198 case SvtLanguageOptions::E_VERTICALCALLOUT : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_VERTICALCALLOUT); break;
199 case SvtLanguageOptions::E_ALLCJK : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_ALL ); break;
200 // ctl options
201 case SvtLanguageOptions::E_CTLFONT : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLFONT ); break;
202 case SvtLanguageOptions::E_CTLSEQUENCECHECKING : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLSEQUENCECHECKING); break;
203 case SvtLanguageOptions::E_CTLCURSORMOVEMENT : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLCURSORMOVEMENT ); break;
204 case SvtLanguageOptions::E_CTLTEXTNUMERALS : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLTEXTNUMERALS ); break;
206 return bReadOnly;
208 /* -----------------30.04.2003 11:03-----------------
210 --------------------------------------------------*/
211 void SvtLanguageOptions::Notify( SfxBroadcaster&, const SfxHint& rHint )
213 vos::OGuard aVclGuard( Application::GetSolarMutex() );
214 Broadcast( rHint );
217 // -----------------------------------------------------------------------------
218 // returns for a language the scripttype
219 sal_uInt16 SvtLanguageOptions::GetScriptTypeOfLanguage( sal_uInt16 nLang )
221 if( LANGUAGE_DONTKNOW == nLang )
222 nLang = LANGUAGE_ENGLISH_US;
223 else if( LANGUAGE_SYSTEM == nLang )
224 nLang = Application::GetSettings().GetLanguage();
226 sal_Int16 nScriptType = MsLangId::getScriptType( nLang );
227 USHORT nScript;
228 switch (nScriptType)
230 case ::com::sun::star::i18n::ScriptType::ASIAN:
231 nScript = SCRIPTTYPE_ASIAN;
232 break;
233 case ::com::sun::star::i18n::ScriptType::COMPLEX:
234 nScript = SCRIPTTYPE_COMPLEX;
235 break;
236 default:
237 nScript = SCRIPTTYPE_LATIN;
239 return nScript;
241 // -----------------------------------------------------------------------------
244 /*-- 27.10.2005 08:18:01---------------------------------------------------
246 -----------------------------------------------------------------------*/
247 SvtSystemLanguageOptions::SvtSystemLanguageOptions() :
248 utl::ConfigItem( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("System/L10N") ))
250 uno::Sequence< rtl::OUString > aPropertyNames(1);
251 rtl::OUString* pNames = aPropertyNames.getArray();
252 pNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SystemLocale"));
253 uno::Sequence< uno::Any > aValues = GetProperties( aPropertyNames );
255 if ( aValues.getLength() )
257 aValues[0]>>= m_sWin16SystemLocale;
260 /*-- 27.10.2005 08:18:01---------------------------------------------------
262 -----------------------------------------------------------------------*/
263 SvtSystemLanguageOptions::~SvtSystemLanguageOptions()
266 /*-- 27.10.2005 08:18:02---------------------------------------------------
268 -----------------------------------------------------------------------*/
269 void SvtSystemLanguageOptions::Commit()
271 //does nothing
273 /*-- 27.10.2005 08:36:14---------------------------------------------------
275 -----------------------------------------------------------------------*/
276 LanguageType SvtSystemLanguageOptions::GetWin16SystemLanguage()
278 if( m_sWin16SystemLocale.getLength() == 0 )
279 return LANGUAGE_NONE;
280 return MsLangId::convertIsoStringToLanguage( m_sWin16SystemLocale );