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 <i18nlangtag/mslangid.hxx>
23 #include <i18nlangtag/languagetag.hxx>
24 #include <com/sun/star/i18n/ScriptType.hpp>
25 #include <unotools/syslocale.hxx>
28 #if !defined WIN32_LEAN_AND_MEAN
29 # define WIN32_LEAN_AND_MEAN
34 using namespace ::com::sun::star
;
37 namespace SvtLanguageOptions
40 // returns for a language the scripttype
41 SvtScriptType
GetScriptTypeOfLanguage( LanguageType nLang
)
43 if( LANGUAGE_DONTKNOW
== nLang
)
44 nLang
= LANGUAGE_ENGLISH_US
;
45 else if (LANGUAGE_SYSTEM
== nLang
|| LANGUAGE_PROCESS_OR_USER_DEFAULT
== nLang
)
46 nLang
= SvtSysLocale().GetLanguageTag().getLanguageType();
48 sal_Int16 nScriptType
= MsLangId::getScriptType( nLang
);
49 SvtScriptType nScript
;
52 case css::i18n::ScriptType::ASIAN
:
53 nScript
= SvtScriptType::ASIAN
;
55 case css::i18n::ScriptType::COMPLEX
:
56 nScript
= SvtScriptType::COMPLEX
;
59 nScript
= SvtScriptType::LATIN
;
64 SvtScriptType
FromI18NToSvtScriptType( sal_Int16 nI18NType
)
68 case i18n::ScriptType::LATIN
: return SvtScriptType::LATIN
;
69 case i18n::ScriptType::ASIAN
: return SvtScriptType::ASIAN
;
70 case i18n::ScriptType::COMPLEX
: return SvtScriptType::COMPLEX
;
71 case i18n::ScriptType::WEAK
: return SvtScriptType::NONE
; // no mapping
72 default: assert(false && nI18NType
&& "Unknown i18n::ScriptType"); break;
74 return SvtScriptType::NONE
;
77 sal_Int16
FromSvtScriptTypeToI18N( SvtScriptType nItemType
)
81 case SvtScriptType::NONE
: return 0;
82 case SvtScriptType::LATIN
: return i18n::ScriptType::LATIN
;
83 case SvtScriptType::ASIAN
: return i18n::ScriptType::ASIAN
;
84 case SvtScriptType::COMPLEX
: return i18n::ScriptType::COMPLEX
;
85 case SvtScriptType::UNKNOWN
: return 0; // no mapping
86 default: assert(false && static_cast<int>(nItemType
) && "unknown SvtScriptType"); break;
91 sal_Int16
GetI18NScriptTypeOfLanguage( LanguageType nLang
)
93 return FromSvtScriptTypeToI18N( GetScriptTypeOfLanguage( nLang
) );
96 } // namespace SvtLanguageOptions
98 static bool isKeyboardLayoutTypeInstalled(sal_Int16 scriptType
)
100 bool isInstalled
= false;
102 int nLayouts
= GetKeyboardLayoutList(0, nullptr);
105 HKL
*lpList
= static_cast<HKL
*>(LocalAlloc(LPTR
, (nLayouts
* sizeof(HKL
))));
108 nLayouts
= GetKeyboardLayoutList(nLayouts
, lpList
);
110 for(int i
= 0; i
< nLayouts
; ++i
)
112 LCID lang
= MAKELCID(LOWORD(lpList
[i
]), SORT_DEFAULT
);
113 if (MsLangId::getScriptType(LanguageType(lang
)) == scriptType
)
129 namespace SvtSystemLanguageOptions
131 bool isCJKKeyboardLayoutInstalled()
133 return isKeyboardLayoutTypeInstalled(css::i18n::ScriptType::ASIAN
);
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */