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
;
36 // global ----------------------------------------------------------------------
38 namespace { struct ALMutex
: public rtl::Static
< ::osl::Mutex
, ALMutex
> {}; }
40 // class SvtLanguageOptions ----------------------------------------------------
42 SvtLanguageOptions::SvtLanguageOptions( sal_Bool _bDontLoad
)
44 // Global access, must be guarded (multithreading)
45 ::osl::MutexGuard
aGuard( ALMutex::get() );
47 m_pCJKOptions
= new SvtCJKOptions( _bDontLoad
);
48 m_pCTLOptions
= new SvtCTLOptions( _bDontLoad
);
49 m_pCTLOptions
->AddListener(this);
50 m_pCJKOptions
->AddListener(this);
52 SvtLanguageOptions::~SvtLanguageOptions()
54 // Global access, must be guarded (multithreading)
55 ::osl::MutexGuard
aGuard( ALMutex::get() );
57 m_pCTLOptions
->RemoveListener(this);
58 m_pCJKOptions
->RemoveListener(this);
63 // CJK options -----------------------------------------------------------------
64 sal_Bool
SvtLanguageOptions::IsCJKFontEnabled() const
66 return m_pCJKOptions
->IsCJKFontEnabled();
68 sal_Bool
SvtLanguageOptions::IsVerticalTextEnabled() const
70 return m_pCJKOptions
->IsVerticalTextEnabled();
72 sal_Bool
SvtLanguageOptions::IsAsianTypographyEnabled() const
74 return m_pCJKOptions
->IsAsianTypographyEnabled();
76 sal_Bool
SvtLanguageOptions::IsJapaneseFindEnabled() const
78 return m_pCJKOptions
->IsJapaneseFindEnabled();
80 void SvtLanguageOptions::SetAll( sal_Bool _bSet
)
82 m_pCJKOptions
->SetAll( _bSet
);
84 sal_Bool
SvtLanguageOptions::IsAnyEnabled() const
86 return m_pCJKOptions
->IsAnyEnabled();
88 // CTL options -----------------------------------------------------------------
89 void SvtLanguageOptions::SetCTLFontEnabled( sal_Bool _bEnabled
)
91 m_pCTLOptions
->SetCTLFontEnabled( _bEnabled
);
93 sal_Bool
SvtLanguageOptions::IsCTLFontEnabled() const
95 return m_pCTLOptions
->IsCTLFontEnabled();
97 void SvtLanguageOptions::SetCTLSequenceChecking( sal_Bool _bEnabled
)
99 m_pCTLOptions
->SetCTLSequenceChecking( _bEnabled
);
102 void SvtLanguageOptions::SetCTLSequenceCheckingRestricted( sal_Bool _bEnable
)
104 m_pCTLOptions
->SetCTLSequenceCheckingRestricted( _bEnable
);
107 void SvtLanguageOptions::SetCTLSequenceCheckingTypeAndReplace( sal_Bool _bEnable
)
109 m_pCTLOptions
->SetCTLSequenceCheckingTypeAndReplace( _bEnable
);
112 sal_Bool
SvtLanguageOptions::IsReadOnly(SvtLanguageOptions::EOption eOption
) const
114 sal_Bool bReadOnly
= sal_False
;
118 case SvtLanguageOptions::E_CJKFONT
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_CJKFONT
); break;
119 case SvtLanguageOptions::E_VERTICALTEXT
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_VERTICALTEXT
); break;
120 case SvtLanguageOptions::E_ASIANTYPOGRAPHY
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_ASIANTYPOGRAPHY
); break;
121 case SvtLanguageOptions::E_JAPANESEFIND
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_JAPANESEFIND
); break;
122 case SvtLanguageOptions::E_RUBY
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_RUBY
); break;
123 case SvtLanguageOptions::E_CHANGECASEMAP
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_CHANGECASEMAP
); break;
124 case SvtLanguageOptions::E_DOUBLELINES
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_DOUBLELINES
); break;
125 case SvtLanguageOptions::E_EMPHASISMARKS
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_EMPHASISMARKS
); break;
126 case SvtLanguageOptions::E_VERTICALCALLOUT
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_VERTICALCALLOUT
); break;
127 case SvtLanguageOptions::E_ALLCJK
: bReadOnly
= m_pCJKOptions
->IsReadOnly(SvtCJKOptions::E_ALL
); break;
129 case SvtLanguageOptions::E_CTLFONT
: bReadOnly
= m_pCTLOptions
->IsReadOnly(SvtCTLOptions::E_CTLFONT
); break;
130 case SvtLanguageOptions::E_CTLSEQUENCECHECKING
: bReadOnly
= m_pCTLOptions
->IsReadOnly(SvtCTLOptions::E_CTLSEQUENCECHECKING
); break;
131 case SvtLanguageOptions::E_CTLCURSORMOVEMENT
: bReadOnly
= m_pCTLOptions
->IsReadOnly(SvtCTLOptions::E_CTLCURSORMOVEMENT
); break;
132 case SvtLanguageOptions::E_CTLTEXTNUMERALS
: bReadOnly
= m_pCTLOptions
->IsReadOnly(SvtCTLOptions::E_CTLTEXTNUMERALS
); break;
137 // returns for a language the scripttype
138 sal_uInt16
SvtLanguageOptions::GetScriptTypeOfLanguage( sal_uInt16 nLang
)
140 if( LANGUAGE_DONTKNOW
== nLang
)
141 nLang
= LANGUAGE_ENGLISH_US
;
142 else if( LANGUAGE_SYSTEM
== nLang
)
143 nLang
= SvtSysLocale().GetLanguageTag().getLanguageType();
145 sal_Int16 nScriptType
= MsLangId::getScriptType( nLang
);
149 case ::com::sun::star::i18n::ScriptType::ASIAN
:
150 nScript
= SCRIPTTYPE_ASIAN
;
152 case ::com::sun::star::i18n::ScriptType::COMPLEX
:
153 nScript
= SCRIPTTYPE_COMPLEX
;
156 nScript
= SCRIPTTYPE_LATIN
;
160 // -----------------------------------------------------------------------------
162 SvtSystemLanguageOptions::SvtSystemLanguageOptions() :
163 utl::ConfigItem( "System/L10N")
165 uno::Sequence
< OUString
> aPropertyNames(1);
166 OUString
* pNames
= aPropertyNames
.getArray();
167 pNames
[0] = "SystemLocale";
168 uno::Sequence
< uno::Any
> aValues
= GetProperties( aPropertyNames
);
170 if ( aValues
.getLength() )
172 aValues
[0]>>= m_sWin16SystemLocale
;
176 SvtSystemLanguageOptions::~SvtSystemLanguageOptions()
180 void SvtSystemLanguageOptions::Commit()
185 void SvtSystemLanguageOptions::Notify( const com::sun::star::uno::Sequence
< OUString
>& )
187 // no listeners supported yet
190 LanguageType
SvtSystemLanguageOptions::GetWin16SystemLanguage() const
192 if( m_sWin16SystemLocale
.isEmpty() )
193 return LANGUAGE_NONE
;
194 return LanguageTag::convertToLanguageTypeWithFallback( m_sWin16SystemLocale
);
197 bool SvtSystemLanguageOptions::isKeyboardLayoutTypeInstalled(sal_Int16 scriptType
) const
199 bool isInstalled
= false;
201 int nLayouts
= GetKeyboardLayoutList(0, NULL
);
204 HKL
*lpList
= (HKL
*)LocalAlloc(LPTR
, (nLayouts
* sizeof(HKL
)));
207 nLayouts
= GetKeyboardLayoutList(nLayouts
, lpList
);
209 for(int i
= 0; i
< nLayouts
; ++i
)
211 LCID lang
= MAKELCID((WORD
)((DWORD_PTR
)lpList
[i
] & 0xffff), SORT_DEFAULT
);
212 if (MsLangId::getScriptType(lang
) == scriptType
)
229 bool SvtSystemLanguageOptions::isCTLKeyboardLayoutInstalled() const
231 return isKeyboardLayoutTypeInstalled(::com::sun::star::i18n::ScriptType::COMPLEX
);
235 bool SvtSystemLanguageOptions::isCJKKeyboardLayoutInstalled() const
237 return isKeyboardLayoutTypeInstalled(::com::sun::star::i18n::ScriptType::ASIAN
);
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */