1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <svl/languageoptions.hxx>
22 #include <svl/cjkoptions.hxx>
23 #include <svl/ctloptions.hxx>
24 #include <i18nlangtag/mslangid.hxx>
25 #include <i18nlangtag/languagetag.hxx>
26 #include <osl/mutex.hxx>
27 #include <rtl/instance.hxx>
28 #include <com/sun/star/i18n/ScriptType.hpp>
29 #include <unotools/syslocale.hxx>
35 using namespace ::com::sun::star
;
38 namespace { struct ALMutex
: public rtl::Static
< ::osl::Mutex
, ALMutex
> {}; }
40 SvtLanguageOptions::SvtLanguageOptions( bool _bDontLoad
)
42 // Global access, must be guarded (multithreading)
43 ::osl::MutexGuard
aGuard( ALMutex::get() );
45 m_pCJKOptions
= new SvtCJKOptions( _bDontLoad
);
46 m_pCTLOptions
= new SvtCTLOptions( _bDontLoad
);
47 m_pCTLOptions
->AddListener(this);
48 m_pCJKOptions
->AddListener(this);
50 SvtLanguageOptions::~SvtLanguageOptions()
52 // Global access, must be guarded (multithreading)
53 ::osl::MutexGuard
aGuard( ALMutex::get() );
55 m_pCTLOptions
->RemoveListener(this);
56 m_pCJKOptions
->RemoveListener(this);
62 bool SvtLanguageOptions::IsCJKFontEnabled() const
64 return m_pCJKOptions
->IsCJKFontEnabled();
66 bool SvtLanguageOptions::IsVerticalTextEnabled() const
68 return m_pCJKOptions
->IsVerticalTextEnabled();
70 bool SvtLanguageOptions::IsAsianTypographyEnabled() const
72 return m_pCJKOptions
->IsAsianTypographyEnabled();
74 bool SvtLanguageOptions::IsJapaneseFindEnabled() const
76 return m_pCJKOptions
->IsJapaneseFindEnabled();
78 void SvtLanguageOptions::SetAll( bool _bSet
)
80 m_pCJKOptions
->SetAll( _bSet
);
82 bool SvtLanguageOptions::IsAnyEnabled() const
84 return m_pCJKOptions
->IsAnyEnabled();
87 void SvtLanguageOptions::SetCTLFontEnabled( bool _bEnabled
)
89 m_pCTLOptions
->SetCTLFontEnabled( _bEnabled
);
91 bool SvtLanguageOptions::IsCTLFontEnabled() const
93 return m_pCTLOptions
->IsCTLFontEnabled();
95 void SvtLanguageOptions::SetCTLSequenceChecking( bool _bEnabled
)
97 m_pCTLOptions
->SetCTLSequenceChecking( _bEnabled
);
100 void SvtLanguageOptions::SetCTLSequenceCheckingRestricted( bool _bEnable
)
102 m_pCTLOptions
->SetCTLSequenceCheckingRestricted( _bEnable
);
105 void SvtLanguageOptions::SetCTLSequenceCheckingTypeAndReplace( bool _bEnable
)
107 m_pCTLOptions
->SetCTLSequenceCheckingTypeAndReplace( _bEnable
);
110 bool SvtLanguageOptions::IsReadOnly(SvtLanguageOptions::EOption eOption
) const
112 bool bReadOnly
= false;
116 case SvtLanguageOptions::E_CJKFONT
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_CJKFONT
); break;
117 case SvtLanguageOptions::E_VERTICALTEXT
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_VERTICALTEXT
); break;
118 case SvtLanguageOptions::E_ASIANTYPOGRAPHY
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_ASIANTYPOGRAPHY
); break;
119 case SvtLanguageOptions::E_JAPANESEFIND
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_JAPANESEFIND
); break;
120 case SvtLanguageOptions::E_RUBY
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_RUBY
); break;
121 case SvtLanguageOptions::E_CHANGECASEMAP
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_CHANGECASEMAP
); break;
122 case SvtLanguageOptions::E_DOUBLELINES
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_DOUBLELINES
); break;
123 case SvtLanguageOptions::E_EMPHASISMARKS
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_EMPHASISMARKS
); break;
124 case SvtLanguageOptions::E_VERTICALCALLOUT
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_VERTICALCALLOUT
); break;
125 case SvtLanguageOptions::E_ALLCJK
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_ALL
); break;
127 case SvtLanguageOptions::E_CTLFONT
: bReadOnly
= m_pCTLOptions
->IsReadOnly(SvtCTLOptions::E_CTLFONT
); break;
128 case SvtLanguageOptions::E_CTLSEQUENCECHECKING
: bReadOnly
= m_pCTLOptions
->IsReadOnly(SvtCTLOptions::E_CTLSEQUENCECHECKING
); break;
129 case SvtLanguageOptions::E_CTLCURSORMOVEMENT
: bReadOnly
= m_pCTLOptions
->IsReadOnly(SvtCTLOptions::E_CTLCURSORMOVEMENT
); break;
130 case SvtLanguageOptions::E_CTLTEXTNUMERALS
: bReadOnly
= m_pCTLOptions
->IsReadOnly(SvtCTLOptions::E_CTLTEXTNUMERALS
); break;
135 // returns for a language the scripttype
136 SvtScriptType
SvtLanguageOptions::GetScriptTypeOfLanguage( sal_uInt16 nLang
)
138 if( LANGUAGE_DONTKNOW
== nLang
)
139 nLang
= LANGUAGE_ENGLISH_US
;
140 else if( LANGUAGE_SYSTEM
== nLang
)
141 nLang
= SvtSysLocale().GetLanguageTag().getLanguageType();
143 sal_Int16 nScriptType
= MsLangId::getScriptType( nLang
);
144 SvtScriptType nScript
;
147 case ::com::sun::star::i18n::ScriptType::ASIAN
:
148 nScript
= SvtScriptType::ASIAN
;
150 case ::com::sun::star::i18n::ScriptType::COMPLEX
:
151 nScript
= SvtScriptType::COMPLEX
;
154 nScript
= SvtScriptType::LATIN
;
159 SvtScriptType
SvtLanguageOptions::FromI18NToSvtScriptType( sal_Int16 nI18NType
)
163 case i18n::ScriptType::LATIN
: return SvtScriptType::LATIN
;
164 case i18n::ScriptType::ASIAN
: return SvtScriptType::ASIAN
;
165 case i18n::ScriptType::COMPLEX
: return SvtScriptType::COMPLEX
;
166 case i18n::ScriptType::WEAK
: return SvtScriptType::NONE
; // no mapping
167 default: assert(false && nI18NType
&& "Unknown i18n::ScriptType"); break;
169 return SvtScriptType::NONE
;
172 sal_Int16
SvtLanguageOptions::FromSvtScriptTypeToI18N( SvtScriptType nItemType
)
176 case SvtScriptType::NONE
: return 0;
177 case SvtScriptType::LATIN
: return i18n::ScriptType::LATIN
;
178 case SvtScriptType::ASIAN
: return i18n::ScriptType::ASIAN
;
179 case SvtScriptType::COMPLEX
: return i18n::ScriptType::COMPLEX
;
180 case SvtScriptType::UNKNOWN
: return 0; // no mapping
181 default: assert(false && static_cast<int>(nItemType
) && "unknown SvtScriptType"); break;
186 sal_Int16
SvtLanguageOptions::GetI18NScriptTypeOfLanguage( sal_uInt16 nLang
)
188 return FromSvtScriptTypeToI18N( GetScriptTypeOfLanguage( nLang
) );
191 SvtSystemLanguageOptions::SvtSystemLanguageOptions() :
192 utl::ConfigItem( "System/L10N")
194 uno::Sequence
< OUString
> aPropertyNames(1);
195 OUString
* pNames
= aPropertyNames
.getArray();
196 pNames
[0] = "SystemLocale";
197 uno::Sequence
< uno::Any
> aValues
= GetProperties( aPropertyNames
);
199 if ( aValues
.getLength() )
201 aValues
[0]>>= m_sWin16SystemLocale
;
205 SvtSystemLanguageOptions::~SvtSystemLanguageOptions()
209 void SvtSystemLanguageOptions::ImplCommit()
214 void SvtSystemLanguageOptions::Notify( const com::sun::star::uno::Sequence
< OUString
>& )
216 // no listeners supported yet
219 LanguageType
SvtSystemLanguageOptions::GetWin16SystemLanguage() const
221 if( m_sWin16SystemLocale
.isEmpty() )
222 return LANGUAGE_NONE
;
223 return LanguageTag::convertToLanguageTypeWithFallback( m_sWin16SystemLocale
);
226 bool SvtSystemLanguageOptions::isKeyboardLayoutTypeInstalled(sal_Int16 scriptType
) const
228 bool isInstalled
= false;
230 int nLayouts
= GetKeyboardLayoutList(0, NULL
);
233 HKL
*lpList
= (HKL
*)LocalAlloc(LPTR
, (nLayouts
* sizeof(HKL
)));
236 nLayouts
= GetKeyboardLayoutList(nLayouts
, lpList
);
238 for(int i
= 0; i
< nLayouts
; ++i
)
240 LCID lang
= MAKELCID((WORD
)((DWORD_PTR
)lpList
[i
] & 0xffff), SORT_DEFAULT
);
241 if (MsLangId::getScriptType(lang
) == scriptType
)
258 bool SvtSystemLanguageOptions::isCTLKeyboardLayoutInstalled() const
260 return isKeyboardLayoutTypeInstalled(::com::sun::star::i18n::ScriptType::COMPLEX
);
264 bool SvtSystemLanguageOptions::isCJKKeyboardLayoutInstalled() const
266 return isKeyboardLayoutTypeInstalled(::com::sun::star::i18n::ScriptType::ASIAN
);
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */