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>
30 #include <com/sun/star/uno/Any.hxx>
31 #include <com/sun/star/uno/Sequence.hxx>
34 #if !defined WIN32_LEAN_AND_MEAN
35 # define WIN32_LEAN_AND_MEAN
40 using namespace ::com::sun::star
;
43 namespace { struct ALMutex
: public rtl::Static
< ::osl::Mutex
, ALMutex
> {}; }
45 SvtLanguageOptions::SvtLanguageOptions( bool _bDontLoad
)
47 // Global access, must be guarded (multithreading)
48 ::osl::MutexGuard
aGuard( ALMutex::get() );
50 m_pCJKOptions
.reset(new SvtCJKOptions( _bDontLoad
));
51 m_pCTLOptions
.reset(new SvtCTLOptions( _bDontLoad
));
52 m_pCTLOptions
->AddListener(this);
53 m_pCJKOptions
->AddListener(this);
55 SvtLanguageOptions::~SvtLanguageOptions()
57 // Global access, must be guarded (multithreading)
58 ::osl::MutexGuard
aGuard( ALMutex::get() );
60 m_pCTLOptions
->RemoveListener(this);
61 m_pCJKOptions
->RemoveListener(this);
63 m_pCJKOptions
.reset();
64 m_pCTLOptions
.reset();
67 bool SvtLanguageOptions::IsCJKFontEnabled() const
69 return m_pCJKOptions
->IsCJKFontEnabled();
71 bool SvtLanguageOptions::IsVerticalTextEnabled() const
73 return m_pCJKOptions
->IsVerticalTextEnabled();
75 bool SvtLanguageOptions::IsAsianTypographyEnabled() const
77 return m_pCJKOptions
->IsAsianTypographyEnabled();
79 bool SvtLanguageOptions::IsJapaneseFindEnabled() const
81 return m_pCJKOptions
->IsJapaneseFindEnabled();
83 void SvtLanguageOptions::SetAll( bool _bSet
)
85 m_pCJKOptions
->SetAll( _bSet
);
87 bool SvtLanguageOptions::IsAnyEnabled() const
89 return m_pCJKOptions
->IsAnyEnabled();
92 void SvtLanguageOptions::SetCTLFontEnabled( bool _bEnabled
)
94 m_pCTLOptions
->SetCTLFontEnabled( _bEnabled
);
96 bool SvtLanguageOptions::IsCTLFontEnabled() const
98 return m_pCTLOptions
->IsCTLFontEnabled();
100 void SvtLanguageOptions::SetCTLSequenceChecking( bool _bEnabled
)
102 m_pCTLOptions
->SetCTLSequenceChecking( _bEnabled
);
105 void SvtLanguageOptions::SetCTLSequenceCheckingRestricted( bool _bEnable
)
107 m_pCTLOptions
->SetCTLSequenceCheckingRestricted( _bEnable
);
110 void SvtLanguageOptions::SetCTLSequenceCheckingTypeAndReplace( bool _bEnable
)
112 m_pCTLOptions
->SetCTLSequenceCheckingTypeAndReplace( _bEnable
);
115 bool SvtLanguageOptions::IsReadOnly(SvtLanguageOptions::EOption eOption
) const
117 bool bReadOnly
= false;
121 case SvtLanguageOptions::E_CJKFONT
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_CJKFONT
); break;
122 case SvtLanguageOptions::E_VERTICALTEXT
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_VERTICALTEXT
); break;
123 case SvtLanguageOptions::E_ASIANTYPOGRAPHY
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_ASIANTYPOGRAPHY
); break;
124 case SvtLanguageOptions::E_JAPANESEFIND
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_JAPANESEFIND
); break;
125 case SvtLanguageOptions::E_RUBY
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_RUBY
); break;
126 case SvtLanguageOptions::E_CHANGECASEMAP
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_CHANGECASEMAP
); break;
127 case SvtLanguageOptions::E_DOUBLELINES
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_DOUBLELINES
); break;
128 case SvtLanguageOptions::E_EMPHASISMARKS
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_EMPHASISMARKS
); break;
129 case SvtLanguageOptions::E_VERTICALCALLOUT
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_VERTICALCALLOUT
); break;
130 case SvtLanguageOptions::E_ALLCJK
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_ALL
); break;
132 case SvtLanguageOptions::E_CTLFONT
: bReadOnly
= m_pCTLOptions
->IsReadOnly(SvtCTLOptions::E_CTLFONT
); break;
133 case SvtLanguageOptions::E_CTLSEQUENCECHECKING
: bReadOnly
= m_pCTLOptions
->IsReadOnly(SvtCTLOptions::E_CTLSEQUENCECHECKING
); break;
134 case SvtLanguageOptions::E_CTLCURSORMOVEMENT
: bReadOnly
= m_pCTLOptions
->IsReadOnly(SvtCTLOptions::E_CTLCURSORMOVEMENT
); break;
135 case SvtLanguageOptions::E_CTLTEXTNUMERALS
: bReadOnly
= m_pCTLOptions
->IsReadOnly(SvtCTLOptions::E_CTLTEXTNUMERALS
); break;
140 // returns for a language the scripttype
141 SvtScriptType
SvtLanguageOptions::GetScriptTypeOfLanguage( LanguageType nLang
)
143 if( LANGUAGE_DONTKNOW
== nLang
)
144 nLang
= LANGUAGE_ENGLISH_US
;
145 else if( LANGUAGE_SYSTEM
== nLang
)
146 nLang
= SvtSysLocale().GetLanguageTag().getLanguageType();
148 sal_Int16 nScriptType
= MsLangId::getScriptType( nLang
);
149 SvtScriptType nScript
;
152 case css::i18n::ScriptType::ASIAN
:
153 nScript
= SvtScriptType::ASIAN
;
155 case css::i18n::ScriptType::COMPLEX
:
156 nScript
= SvtScriptType::COMPLEX
;
159 nScript
= SvtScriptType::LATIN
;
164 SvtScriptType
SvtLanguageOptions::FromI18NToSvtScriptType( sal_Int16 nI18NType
)
168 case i18n::ScriptType::LATIN
: return SvtScriptType::LATIN
;
169 case i18n::ScriptType::ASIAN
: return SvtScriptType::ASIAN
;
170 case i18n::ScriptType::COMPLEX
: return SvtScriptType::COMPLEX
;
171 case i18n::ScriptType::WEAK
: return SvtScriptType::NONE
; // no mapping
172 default: assert(false && nI18NType
&& "Unknown i18n::ScriptType"); break;
174 return SvtScriptType::NONE
;
177 sal_Int16
SvtLanguageOptions::FromSvtScriptTypeToI18N( SvtScriptType nItemType
)
181 case SvtScriptType::NONE
: return 0;
182 case SvtScriptType::LATIN
: return i18n::ScriptType::LATIN
;
183 case SvtScriptType::ASIAN
: return i18n::ScriptType::ASIAN
;
184 case SvtScriptType::COMPLEX
: return i18n::ScriptType::COMPLEX
;
185 case SvtScriptType::UNKNOWN
: return 0; // no mapping
186 default: assert(false && static_cast<int>(nItemType
) && "unknown SvtScriptType"); break;
191 sal_Int16
SvtLanguageOptions::GetI18NScriptTypeOfLanguage( LanguageType nLang
)
193 return FromSvtScriptTypeToI18N( GetScriptTypeOfLanguage( nLang
) );
196 SvtSystemLanguageOptions::SvtSystemLanguageOptions() :
197 utl::ConfigItem( "System/L10N")
199 uno::Sequence
< OUString
> aPropertyNames
{ "SystemLocale" };
200 uno::Sequence
< uno::Any
> aValues
= GetProperties( aPropertyNames
);
202 if ( aValues
.hasElements() )
204 aValues
[0]>>= m_sWin16SystemLocale
;
208 SvtSystemLanguageOptions::~SvtSystemLanguageOptions()
212 void SvtSystemLanguageOptions::ImplCommit()
217 void SvtSystemLanguageOptions::Notify( const css::uno::Sequence
< OUString
>& )
219 // no listeners supported yet
222 LanguageType
SvtSystemLanguageOptions::GetWin16SystemLanguage() const
224 if( m_sWin16SystemLocale
.isEmpty() )
225 return LANGUAGE_NONE
;
226 return LanguageTag::convertToLanguageTypeWithFallback( m_sWin16SystemLocale
);
229 bool SvtSystemLanguageOptions::isKeyboardLayoutTypeInstalled(sal_Int16 scriptType
) const
231 bool isInstalled
= false;
233 int nLayouts
= GetKeyboardLayoutList(0, nullptr);
236 HKL
*lpList
= static_cast<HKL
*>(LocalAlloc(LPTR
, (nLayouts
* sizeof(HKL
))));
239 nLayouts
= GetKeyboardLayoutList(nLayouts
, lpList
);
241 for(int i
= 0; i
< nLayouts
; ++i
)
243 LCID lang
= MAKELCID(LOWORD(lpList
[i
]), SORT_DEFAULT
);
244 if (MsLangId::getScriptType(LanguageType(lang
)) == scriptType
)
260 bool SvtSystemLanguageOptions::isCJKKeyboardLayoutInstalled() const
262 return isKeyboardLayoutTypeInstalled(css::i18n::ScriptType::ASIAN
);
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */