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_svl.hxx"
26 
27 #include <svl/languageoptions.hxx>
28 #include <svl/cjkoptions.hxx>
29 #include <svl/ctloptions.hxx>
30 #include <i18npool/mslangid.hxx>
31 #include <vos/mutex.hxx>
32 #include <osl/mutex.hxx>
33 #include <rtl/instance.hxx>
34 #include <com/sun/star/i18n/ScriptType.hpp>
35 #include <unotools/syslocale.hxx>
36 
37 using namespace ::com::sun::star;
38 // global ----------------------------------------------------------------------
39 
40 namespace { struct ALMutex : public rtl::Static< ::osl::Mutex, ALMutex > {}; }
41 
42 // class SvtLanguageOptions ----------------------------------------------------
43 
SvtLanguageOptions(sal_Bool _bDontLoad)44 SvtLanguageOptions::SvtLanguageOptions( sal_Bool _bDontLoad )
45 {
46     // Global access, must be guarded (multithreading)
47     ::osl::MutexGuard aGuard( ALMutex::get() );
48 
49 	m_pCJKOptions = new SvtCJKOptions( _bDontLoad );
50     m_pCTLOptions = new SvtCTLOptions( _bDontLoad );
51     m_pCTLOptions->AddListener(this);
52     m_pCJKOptions->AddListener(this);
53 }
54 //------------------------------------------------------------------------------
~SvtLanguageOptions()55 SvtLanguageOptions::~SvtLanguageOptions()
56 {
57     // Global access, must be guarded (multithreading)
58     ::osl::MutexGuard aGuard( ALMutex::get() );
59 
60     m_pCTLOptions->RemoveListener(this);
61     m_pCJKOptions->RemoveListener(this);
62 
63 	delete m_pCJKOptions;
64 	delete m_pCTLOptions;
65 }
66 //------------------------------------------------------------------------------
67 // CJK options -----------------------------------------------------------------
68 //------------------------------------------------------------------------------
IsCJKFontEnabled() const69 sal_Bool SvtLanguageOptions::IsCJKFontEnabled() const
70 {
71 	return m_pCJKOptions->IsCJKFontEnabled();
72 }
73 //------------------------------------------------------------------------------
IsVerticalTextEnabled() const74 sal_Bool SvtLanguageOptions::IsVerticalTextEnabled() const
75 {
76 	return m_pCJKOptions->IsVerticalTextEnabled();
77 }
78 //------------------------------------------------------------------------------
IsAsianTypographyEnabled() const79 sal_Bool SvtLanguageOptions::IsAsianTypographyEnabled() const
80 {
81 	return m_pCJKOptions->IsAsianTypographyEnabled();
82 }
83 //------------------------------------------------------------------------------
IsJapaneseFindEnabled() const84 sal_Bool SvtLanguageOptions::IsJapaneseFindEnabled() const
85 {
86 	return m_pCJKOptions->IsJapaneseFindEnabled();
87 }
88 //------------------------------------------------------------------------------
IsRubyEnabled() const89 sal_Bool SvtLanguageOptions::IsRubyEnabled() const
90 {
91 	return m_pCJKOptions->IsRubyEnabled();
92 }
93 //------------------------------------------------------------------------------
IsChangeCaseMapEnabled() const94 sal_Bool SvtLanguageOptions::IsChangeCaseMapEnabled() const
95 {
96 	return m_pCJKOptions->IsChangeCaseMapEnabled();
97 }
98 //------------------------------------------------------------------------------
IsDoubleLinesEnabled() const99 sal_Bool SvtLanguageOptions::IsDoubleLinesEnabled() const
100 {
101 	return m_pCJKOptions->IsDoubleLinesEnabled();
102 }
103 //------------------------------------------------------------------------------
IsEmphasisMarksEnabled() const104 sal_Bool SvtLanguageOptions::IsEmphasisMarksEnabled() const
105 {
106 	return m_pCJKOptions->IsEmphasisMarksEnabled();
107 }
108 //------------------------------------------------------------------------------
IsVerticalCallOutEnabled() const109 sal_Bool SvtLanguageOptions::IsVerticalCallOutEnabled() const
110 {
111 	return m_pCJKOptions->IsVerticalCallOutEnabled();
112 }
113 //------------------------------------------------------------------------------
SetAll(sal_Bool _bSet)114 void SvtLanguageOptions::SetAll( sal_Bool _bSet )
115 {
116 	m_pCJKOptions->SetAll( _bSet );
117 }
118 //------------------------------------------------------------------------------
IsAnyEnabled() const119 sal_Bool SvtLanguageOptions::IsAnyEnabled() const
120 {
121 	return m_pCJKOptions->IsAnyEnabled();
122 }
123 //------------------------------------------------------------------------------
124 // CTL options -----------------------------------------------------------------
125 //------------------------------------------------------------------------------
SetCTLFontEnabled(sal_Bool _bEnabled)126 void SvtLanguageOptions::SetCTLFontEnabled( sal_Bool _bEnabled )
127 {
128 	m_pCTLOptions->SetCTLFontEnabled( _bEnabled );
129 }
130 //------------------------------------------------------------------------------
IsCTLFontEnabled() const131 sal_Bool SvtLanguageOptions::IsCTLFontEnabled() const
132 {
133 	return m_pCTLOptions->IsCTLFontEnabled();
134 }
135 //------------------------------------------------------------------------------
SetCTLSequenceChecking(sal_Bool _bEnabled)136 void SvtLanguageOptions::SetCTLSequenceChecking( sal_Bool _bEnabled )
137 {
138     m_pCTLOptions->SetCTLSequenceChecking( _bEnabled );
139 }
140 //------------------------------------------------------------------------------
IsCTLSequenceChecking() const141 sal_Bool SvtLanguageOptions::IsCTLSequenceChecking() const
142 {
143     return m_pCTLOptions->IsCTLSequenceChecking();
144 }
145 /*-- 26.09.2005 15:48:23---------------------------------------------------
146 
147   -----------------------------------------------------------------------*/
SetCTLSequenceCheckingRestricted(sal_Bool _bEnable)148 void SvtLanguageOptions::SetCTLSequenceCheckingRestricted( sal_Bool _bEnable )
149 {
150     m_pCTLOptions->SetCTLSequenceCheckingRestricted( _bEnable );
151 }
152 /*-- 26.09.2005 15:48:23---------------------------------------------------
153 
154   -----------------------------------------------------------------------*/
IsCTLSequenceCheckingRestricted(void) const155 sal_Bool SvtLanguageOptions::IsCTLSequenceCheckingRestricted( void ) const
156 {
157     return m_pCTLOptions->IsCTLSequenceCheckingRestricted();
158 }
159 /*-- 26.09.2005 15:48:23---------------------------------------------------
160 
161   -----------------------------------------------------------------------*/
SetCTLSequenceCheckingTypeAndReplace(sal_Bool _bEnable)162 void SvtLanguageOptions::SetCTLSequenceCheckingTypeAndReplace( sal_Bool _bEnable )
163 {
164     m_pCTLOptions->SetCTLSequenceCheckingTypeAndReplace( _bEnable );
165 }
166 /*-- 26.09.2005 15:48:24---------------------------------------------------
167 
168   -----------------------------------------------------------------------*/
IsCTLSequenceCheckingTypeAndReplace() const169 sal_Bool SvtLanguageOptions::IsCTLSequenceCheckingTypeAndReplace() const
170 {
171     return m_pCTLOptions->IsCTLSequenceCheckingTypeAndReplace();
172 }
173 
174 //------------------------------------------------------------------------------
IsReadOnly(SvtLanguageOptions::EOption eOption) const175 sal_Bool SvtLanguageOptions::IsReadOnly(SvtLanguageOptions::EOption eOption) const
176 {
177     sal_Bool bReadOnly = sal_False;
178     switch(eOption)
179     {
180         // cjk options
181         case SvtLanguageOptions::E_CJKFONT          : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_CJKFONT        ); break;
182         case SvtLanguageOptions::E_VERTICALTEXT     : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_VERTICALTEXT   ); break;
183         case SvtLanguageOptions::E_ASIANTYPOGRAPHY  : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_ASIANTYPOGRAPHY); break;
184         case SvtLanguageOptions::E_JAPANESEFIND     : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_JAPANESEFIND   ); break;
185         case SvtLanguageOptions::E_RUBY             : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_RUBY           ); break;
186         case SvtLanguageOptions::E_CHANGECASEMAP    : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_CHANGECASEMAP  ); break;
187         case SvtLanguageOptions::E_DOUBLELINES      : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_DOUBLELINES    ); break;
188         case SvtLanguageOptions::E_EMPHASISMARKS    : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_EMPHASISMARKS  ); break;
189         case SvtLanguageOptions::E_VERTICALCALLOUT  : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_VERTICALCALLOUT); break;
190         case SvtLanguageOptions::E_ALLCJK           : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_ALL            ); break;
191         // ctl options
192         case SvtLanguageOptions::E_CTLFONT              : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLFONT            ); break;
193         case SvtLanguageOptions::E_CTLSEQUENCECHECKING  : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLSEQUENCECHECKING); break;
194         case SvtLanguageOptions::E_CTLCURSORMOVEMENT    : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLCURSORMOVEMENT  ); break;
195         case SvtLanguageOptions::E_CTLTEXTNUMERALS      : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLTEXTNUMERALS    ); break;
196     }
197     return bReadOnly;
198 }
199 /* -----------------30.04.2003 11:03-----------------*/
200 
201 // returns for a language the scripttype
GetScriptTypeOfLanguage(sal_uInt16 nLang)202 sal_uInt16 SvtLanguageOptions::GetScriptTypeOfLanguage( sal_uInt16 nLang )
203 {
204 	if( LANGUAGE_DONTKNOW == nLang )
205     	nLang = LANGUAGE_ENGLISH_US;
206 	else if( LANGUAGE_SYSTEM == nLang  )
207 		nLang = SvtSysLocale().GetLanguage();
208 
209     sal_Int16 nScriptType = MsLangId::getScriptType( nLang );
210 	sal_uInt16 nScript;
211     switch (nScriptType)
212     {
213         case ::com::sun::star::i18n::ScriptType::ASIAN:
214             nScript = SCRIPTTYPE_ASIAN;
215             break;
216         case ::com::sun::star::i18n::ScriptType::COMPLEX:
217             nScript = SCRIPTTYPE_COMPLEX;
218             break;
219         default:
220             nScript = SCRIPTTYPE_LATIN;
221     }
222 	return nScript;
223 }
224 // -----------------------------------------------------------------------------
225 
226 
227 /*-- 27.10.2005 08:18:01---------------------------------------------------
228 
229   -----------------------------------------------------------------------*/
SvtSystemLanguageOptions()230 SvtSystemLanguageOptions::SvtSystemLanguageOptions() :
231     utl::ConfigItem( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("System/L10N") ))
232 {
233     uno::Sequence< rtl::OUString > aPropertyNames(1);
234     rtl::OUString* pNames = aPropertyNames.getArray();
235     pNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SystemLocale"));
236     uno::Sequence< uno::Any > aValues = GetProperties( aPropertyNames );
237 
238     if ( aValues.getLength() )
239     {
240         aValues[0]>>= m_sWin16SystemLocale;
241     }
242 }
243 /*-- 27.10.2005 08:18:01---------------------------------------------------
244 
245   -----------------------------------------------------------------------*/
~SvtSystemLanguageOptions()246 SvtSystemLanguageOptions::~SvtSystemLanguageOptions()
247 {
248 }
249 /*-- 27.10.2005 08:18:02---------------------------------------------------
250 
251   -----------------------------------------------------------------------*/
Commit()252 void    SvtSystemLanguageOptions::Commit()
253 {
254     //does nothing
255 }
256 
Notify(const com::sun::star::uno::Sequence<rtl::OUString> &)257 void    SvtSystemLanguageOptions::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
258 {
259     // no listeners supported yet
260 }
261 
262 /*-- 27.10.2005 08:36:14---------------------------------------------------
263 
264   -----------------------------------------------------------------------*/
GetWin16SystemLanguage()265 LanguageType SvtSystemLanguageOptions::GetWin16SystemLanguage()
266 {
267     if( m_sWin16SystemLocale.getLength() == 0 )
268         return LANGUAGE_NONE;
269     return MsLangId::convertIsoStringToLanguage( m_sWin16SystemLocale );
270 }
271 
272 
273