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