xref: /AOO41X/main/svl/source/config/languageoptions.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svl.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <svl/languageoptions.hxx>
32*cdf0e10cSrcweir #include <svl/cjkoptions.hxx>
33*cdf0e10cSrcweir #include <svl/ctloptions.hxx>
34*cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
35*cdf0e10cSrcweir #include <vos/mutex.hxx>
36*cdf0e10cSrcweir #include <osl/mutex.hxx>
37*cdf0e10cSrcweir #include <rtl/instance.hxx>
38*cdf0e10cSrcweir #include <com/sun/star/i18n/ScriptType.hpp>
39*cdf0e10cSrcweir #include <unotools/syslocale.hxx>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir using namespace ::com::sun::star;
42*cdf0e10cSrcweir // global ----------------------------------------------------------------------
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir namespace { struct ALMutex : public rtl::Static< ::osl::Mutex, ALMutex > {}; }
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir // class SvtLanguageOptions ----------------------------------------------------
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir SvtLanguageOptions::SvtLanguageOptions( sal_Bool _bDontLoad )
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir     // Global access, must be guarded (multithreading)
51*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( ALMutex::get() );
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 	m_pCJKOptions = new SvtCJKOptions( _bDontLoad );
54*cdf0e10cSrcweir     m_pCTLOptions = new SvtCTLOptions( _bDontLoad );
55*cdf0e10cSrcweir     m_pCTLOptions->AddListener(this);
56*cdf0e10cSrcweir     m_pCJKOptions->AddListener(this);
57*cdf0e10cSrcweir }
58*cdf0e10cSrcweir //------------------------------------------------------------------------------
59*cdf0e10cSrcweir SvtLanguageOptions::~SvtLanguageOptions()
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir     // Global access, must be guarded (multithreading)
62*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( ALMutex::get() );
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir     m_pCTLOptions->RemoveListener(this);
65*cdf0e10cSrcweir     m_pCJKOptions->RemoveListener(this);
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir 	delete m_pCJKOptions;
68*cdf0e10cSrcweir 	delete m_pCTLOptions;
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir //------------------------------------------------------------------------------
71*cdf0e10cSrcweir // CJK options -----------------------------------------------------------------
72*cdf0e10cSrcweir //------------------------------------------------------------------------------
73*cdf0e10cSrcweir sal_Bool SvtLanguageOptions::IsCJKFontEnabled() const
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir 	return m_pCJKOptions->IsCJKFontEnabled();
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir //------------------------------------------------------------------------------
78*cdf0e10cSrcweir sal_Bool SvtLanguageOptions::IsVerticalTextEnabled() const
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir 	return m_pCJKOptions->IsVerticalTextEnabled();
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir //------------------------------------------------------------------------------
83*cdf0e10cSrcweir sal_Bool SvtLanguageOptions::IsAsianTypographyEnabled() const
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir 	return m_pCJKOptions->IsAsianTypographyEnabled();
86*cdf0e10cSrcweir }
87*cdf0e10cSrcweir //------------------------------------------------------------------------------
88*cdf0e10cSrcweir sal_Bool SvtLanguageOptions::IsJapaneseFindEnabled() const
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir 	return m_pCJKOptions->IsJapaneseFindEnabled();
91*cdf0e10cSrcweir }
92*cdf0e10cSrcweir //------------------------------------------------------------------------------
93*cdf0e10cSrcweir sal_Bool SvtLanguageOptions::IsRubyEnabled() const
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir 	return m_pCJKOptions->IsRubyEnabled();
96*cdf0e10cSrcweir }
97*cdf0e10cSrcweir //------------------------------------------------------------------------------
98*cdf0e10cSrcweir sal_Bool SvtLanguageOptions::IsChangeCaseMapEnabled() const
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir 	return m_pCJKOptions->IsChangeCaseMapEnabled();
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir //------------------------------------------------------------------------------
103*cdf0e10cSrcweir sal_Bool SvtLanguageOptions::IsDoubleLinesEnabled() const
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir 	return m_pCJKOptions->IsDoubleLinesEnabled();
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir //------------------------------------------------------------------------------
108*cdf0e10cSrcweir sal_Bool SvtLanguageOptions::IsEmphasisMarksEnabled() const
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir 	return m_pCJKOptions->IsEmphasisMarksEnabled();
111*cdf0e10cSrcweir }
112*cdf0e10cSrcweir //------------------------------------------------------------------------------
113*cdf0e10cSrcweir sal_Bool SvtLanguageOptions::IsVerticalCallOutEnabled() const
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir 	return m_pCJKOptions->IsVerticalCallOutEnabled();
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir //------------------------------------------------------------------------------
118*cdf0e10cSrcweir void SvtLanguageOptions::SetAll( sal_Bool _bSet )
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir 	m_pCJKOptions->SetAll( _bSet );
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir //------------------------------------------------------------------------------
123*cdf0e10cSrcweir sal_Bool SvtLanguageOptions::IsAnyEnabled() const
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir 	return m_pCJKOptions->IsAnyEnabled();
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir //------------------------------------------------------------------------------
128*cdf0e10cSrcweir // CTL options -----------------------------------------------------------------
129*cdf0e10cSrcweir //------------------------------------------------------------------------------
130*cdf0e10cSrcweir void SvtLanguageOptions::SetCTLFontEnabled( sal_Bool _bEnabled )
131*cdf0e10cSrcweir {
132*cdf0e10cSrcweir 	m_pCTLOptions->SetCTLFontEnabled( _bEnabled );
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir //------------------------------------------------------------------------------
135*cdf0e10cSrcweir sal_Bool SvtLanguageOptions::IsCTLFontEnabled() const
136*cdf0e10cSrcweir {
137*cdf0e10cSrcweir 	return m_pCTLOptions->IsCTLFontEnabled();
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir //------------------------------------------------------------------------------
140*cdf0e10cSrcweir void SvtLanguageOptions::SetCTLSequenceChecking( sal_Bool _bEnabled )
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir     m_pCTLOptions->SetCTLSequenceChecking( _bEnabled );
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir //------------------------------------------------------------------------------
145*cdf0e10cSrcweir sal_Bool SvtLanguageOptions::IsCTLSequenceChecking() const
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir     return m_pCTLOptions->IsCTLSequenceChecking();
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir /*-- 26.09.2005 15:48:23---------------------------------------------------
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
152*cdf0e10cSrcweir void SvtLanguageOptions::SetCTLSequenceCheckingRestricted( sal_Bool _bEnable )
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir     m_pCTLOptions->SetCTLSequenceCheckingRestricted( _bEnable );
155*cdf0e10cSrcweir }
156*cdf0e10cSrcweir /*-- 26.09.2005 15:48:23---------------------------------------------------
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
159*cdf0e10cSrcweir sal_Bool SvtLanguageOptions::IsCTLSequenceCheckingRestricted( void ) const
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir     return m_pCTLOptions->IsCTLSequenceCheckingRestricted();
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir /*-- 26.09.2005 15:48:23---------------------------------------------------
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
166*cdf0e10cSrcweir void SvtLanguageOptions::SetCTLSequenceCheckingTypeAndReplace( sal_Bool _bEnable )
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir     m_pCTLOptions->SetCTLSequenceCheckingTypeAndReplace( _bEnable );
169*cdf0e10cSrcweir }
170*cdf0e10cSrcweir /*-- 26.09.2005 15:48:24---------------------------------------------------
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
173*cdf0e10cSrcweir sal_Bool SvtLanguageOptions::IsCTLSequenceCheckingTypeAndReplace() const
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir     return m_pCTLOptions->IsCTLSequenceCheckingTypeAndReplace();
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir //------------------------------------------------------------------------------
179*cdf0e10cSrcweir sal_Bool SvtLanguageOptions::IsReadOnly(SvtLanguageOptions::EOption eOption) const
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir     sal_Bool bReadOnly = sal_False;
182*cdf0e10cSrcweir     switch(eOption)
183*cdf0e10cSrcweir     {
184*cdf0e10cSrcweir         // cjk options
185*cdf0e10cSrcweir         case SvtLanguageOptions::E_CJKFONT          : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_CJKFONT        ); break;
186*cdf0e10cSrcweir         case SvtLanguageOptions::E_VERTICALTEXT     : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_VERTICALTEXT   ); break;
187*cdf0e10cSrcweir         case SvtLanguageOptions::E_ASIANTYPOGRAPHY  : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_ASIANTYPOGRAPHY); break;
188*cdf0e10cSrcweir         case SvtLanguageOptions::E_JAPANESEFIND     : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_JAPANESEFIND   ); break;
189*cdf0e10cSrcweir         case SvtLanguageOptions::E_RUBY             : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_RUBY           ); break;
190*cdf0e10cSrcweir         case SvtLanguageOptions::E_CHANGECASEMAP    : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_CHANGECASEMAP  ); break;
191*cdf0e10cSrcweir         case SvtLanguageOptions::E_DOUBLELINES      : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_DOUBLELINES    ); break;
192*cdf0e10cSrcweir         case SvtLanguageOptions::E_EMPHASISMARKS    : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_EMPHASISMARKS  ); break;
193*cdf0e10cSrcweir         case SvtLanguageOptions::E_VERTICALCALLOUT  : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_VERTICALCALLOUT); break;
194*cdf0e10cSrcweir         case SvtLanguageOptions::E_ALLCJK           : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_ALL            ); break;
195*cdf0e10cSrcweir         // ctl options
196*cdf0e10cSrcweir         case SvtLanguageOptions::E_CTLFONT              : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLFONT            ); break;
197*cdf0e10cSrcweir         case SvtLanguageOptions::E_CTLSEQUENCECHECKING  : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLSEQUENCECHECKING); break;
198*cdf0e10cSrcweir         case SvtLanguageOptions::E_CTLCURSORMOVEMENT    : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLCURSORMOVEMENT  ); break;
199*cdf0e10cSrcweir         case SvtLanguageOptions::E_CTLTEXTNUMERALS      : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLTEXTNUMERALS    ); break;
200*cdf0e10cSrcweir     }
201*cdf0e10cSrcweir     return bReadOnly;
202*cdf0e10cSrcweir }
203*cdf0e10cSrcweir /* -----------------30.04.2003 11:03-----------------*/
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir // returns for a language the scripttype
206*cdf0e10cSrcweir sal_uInt16 SvtLanguageOptions::GetScriptTypeOfLanguage( sal_uInt16 nLang )
207*cdf0e10cSrcweir {
208*cdf0e10cSrcweir 	if( LANGUAGE_DONTKNOW == nLang )
209*cdf0e10cSrcweir     	nLang = LANGUAGE_ENGLISH_US;
210*cdf0e10cSrcweir 	else if( LANGUAGE_SYSTEM == nLang  )
211*cdf0e10cSrcweir 		nLang = SvtSysLocale().GetLanguage();
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir     sal_Int16 nScriptType = MsLangId::getScriptType( nLang );
214*cdf0e10cSrcweir 	sal_uInt16 nScript;
215*cdf0e10cSrcweir     switch (nScriptType)
216*cdf0e10cSrcweir     {
217*cdf0e10cSrcweir         case ::com::sun::star::i18n::ScriptType::ASIAN:
218*cdf0e10cSrcweir             nScript = SCRIPTTYPE_ASIAN;
219*cdf0e10cSrcweir             break;
220*cdf0e10cSrcweir         case ::com::sun::star::i18n::ScriptType::COMPLEX:
221*cdf0e10cSrcweir             nScript = SCRIPTTYPE_COMPLEX;
222*cdf0e10cSrcweir             break;
223*cdf0e10cSrcweir         default:
224*cdf0e10cSrcweir             nScript = SCRIPTTYPE_LATIN;
225*cdf0e10cSrcweir     }
226*cdf0e10cSrcweir 	return nScript;
227*cdf0e10cSrcweir }
228*cdf0e10cSrcweir // -----------------------------------------------------------------------------
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir /*-- 27.10.2005 08:18:01---------------------------------------------------
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
234*cdf0e10cSrcweir SvtSystemLanguageOptions::SvtSystemLanguageOptions() :
235*cdf0e10cSrcweir     utl::ConfigItem( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("System/L10N") ))
236*cdf0e10cSrcweir {
237*cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aPropertyNames(1);
238*cdf0e10cSrcweir     rtl::OUString* pNames = aPropertyNames.getArray();
239*cdf0e10cSrcweir     pNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SystemLocale"));
240*cdf0e10cSrcweir     uno::Sequence< uno::Any > aValues = GetProperties( aPropertyNames );
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir     if ( aValues.getLength() )
243*cdf0e10cSrcweir     {
244*cdf0e10cSrcweir         aValues[0]>>= m_sWin16SystemLocale;
245*cdf0e10cSrcweir     }
246*cdf0e10cSrcweir }
247*cdf0e10cSrcweir /*-- 27.10.2005 08:18:01---------------------------------------------------
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
250*cdf0e10cSrcweir SvtSystemLanguageOptions::~SvtSystemLanguageOptions()
251*cdf0e10cSrcweir {
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir /*-- 27.10.2005 08:18:02---------------------------------------------------
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
256*cdf0e10cSrcweir void    SvtSystemLanguageOptions::Commit()
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir     //does nothing
259*cdf0e10cSrcweir }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir void    SvtSystemLanguageOptions::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
262*cdf0e10cSrcweir {
263*cdf0e10cSrcweir     // no listeners supported yet
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir /*-- 27.10.2005 08:36:14---------------------------------------------------
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
269*cdf0e10cSrcweir LanguageType SvtSystemLanguageOptions::GetWin16SystemLanguage()
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir     if( m_sWin16SystemLocale.getLength() == 0 )
272*cdf0e10cSrcweir         return LANGUAGE_NONE;
273*cdf0e10cSrcweir     return MsLangId::convertIsoStringToLanguage( m_sWin16SystemLocale );
274*cdf0e10cSrcweir }
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir 
277