bump product version to 7.6.3.2-android
[LibreOffice.git] / svl / source / config / cjkoptions.cxx
blob72e5c8ea2a3d422d00063fa55b5f6aae3c73b0a3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <svl/cjkoptions.hxx>
22 #include <svl/languageoptions.hxx>
23 #include <i18nlangtag/lang.h>
24 #include <i18nlangtag/languagetag.hxx>
25 #include <officecfg/System.hxx>
26 #include <officecfg/Office/Common.hxx>
27 #include <mutex>
29 using namespace ::com::sun::star::uno;
31 static void SvtCJKOptions_Load();
33 namespace SvtCJKOptions
36 bool IsCJKFontEnabled()
38 SvtCJKOptions_Load();
39 return officecfg::Office::Common::I18N::CJK::CJKFont::get();
42 bool IsVerticalTextEnabled()
44 SvtCJKOptions_Load();
45 return officecfg::Office::Common::I18N::CJK::VerticalText::get();
48 bool IsAsianTypographyEnabled()
50 SvtCJKOptions_Load();
51 return officecfg::Office::Common::I18N::CJK::AsianTypography::get();
54 bool IsJapaneseFindEnabled()
56 SvtCJKOptions_Load();
57 return officecfg::Office::Common::I18N::CJK::JapaneseFind::get();
60 bool IsRubyEnabled()
62 SvtCJKOptions_Load();
63 return officecfg::Office::Common::I18N::CJK::Ruby::get();
66 bool IsChangeCaseMapEnabled()
68 SvtCJKOptions_Load();
69 return officecfg::Office::Common::I18N::CJK::ChangeCaseMap::get();
72 bool IsDoubleLinesEnabled()
74 SvtCJKOptions_Load();
75 return officecfg::Office::Common::I18N::CJK::DoubleLines::get();
78 void SetAll(bool bSet)
80 SvtCJKOptions_Load();
81 if ( officecfg::Office::Common::I18N::CJK::CJKFont::isReadOnly()
82 || officecfg::Office::Common::I18N::CJK::VerticalText::isReadOnly()
83 || officecfg::Office::Common::I18N::CJK::AsianTypography::isReadOnly()
84 || officecfg::Office::Common::I18N::CJK::JapaneseFind::isReadOnly()
85 || officecfg::Office::Common::I18N::CJK::Ruby::isReadOnly()
86 || officecfg::Office::Common::I18N::CJK::ChangeCaseMap::isReadOnly()
87 || officecfg::Office::Common::I18N::CJK::DoubleLines::isReadOnly() )
88 return;
90 std::shared_ptr<comphelper::ConfigurationChanges> xChanges(comphelper::ConfigurationChanges::create());
91 officecfg::Office::Common::I18N::CJK::CJKFont::set(bSet, xChanges);
92 officecfg::Office::Common::I18N::CJK::VerticalText::set(bSet, xChanges);
93 officecfg::Office::Common::I18N::CJK::AsianTypography::set(bSet, xChanges);
94 officecfg::Office::Common::I18N::CJK::JapaneseFind::set(bSet, xChanges);
95 officecfg::Office::Common::I18N::CJK::Ruby::set(bSet, xChanges);
96 officecfg::Office::Common::I18N::CJK::ChangeCaseMap::set(bSet, xChanges);
97 officecfg::Office::Common::I18N::CJK::DoubleLines::set(bSet, xChanges);
98 xChanges->commit();
101 bool IsAnyEnabled()
103 SvtCJKOptions_Load();
104 return IsCJKFontEnabled() || IsVerticalTextEnabled() || IsAsianTypographyEnabled() || IsJapaneseFindEnabled() ||
105 IsRubyEnabled() || IsChangeCaseMapEnabled() || IsDoubleLinesEnabled() ;
108 bool IsReadOnly(EOption eOption)
110 SvtCJKOptions_Load();
111 switch (eOption)
113 case E_CJKFONT: return officecfg::Office::Common::I18N::CJK::CJKFont::isReadOnly();
114 case E_VERTICALTEXT: return officecfg::Office::Common::I18N::CJK::VerticalText::isReadOnly();
115 case E_ASIANTYPOGRAPHY: return officecfg::Office::Common::I18N::CJK::AsianTypography::isReadOnly();
116 case E_JAPANESEFIND: return officecfg::Office::Common::I18N::CJK::JapaneseFind::isReadOnly();
117 case E_RUBY: return officecfg::Office::Common::I18N::CJK::Ruby::isReadOnly();
118 case E_CHANGECASEMAP: return officecfg::Office::Common::I18N::CJK::ChangeCaseMap::isReadOnly();
119 case E_DOUBLELINES: return officecfg::Office::Common::I18N::CJK::DoubleLines::isReadOnly();
120 case E_ALL:
121 return officecfg::Office::Common::I18N::CJK::CJKFont::isReadOnly()
122 || officecfg::Office::Common::I18N::CJK::VerticalText::isReadOnly()
123 || officecfg::Office::Common::I18N::CJK::AsianTypography::isReadOnly()
124 || officecfg::Office::Common::I18N::CJK::JapaneseFind::isReadOnly()
125 || officecfg::Office::Common::I18N::CJK::Ruby::isReadOnly()
126 || officecfg::Office::Common::I18N::CJK::ChangeCaseMap::isReadOnly()
127 || officecfg::Office::Common::I18N::CJK::DoubleLines::isReadOnly();
128 default:
129 assert(false);
131 return false;
134 } // namespace SvtCJKOptions
137 static std::once_flag gLoadFlag;
139 static void SvtCJKOptions_Load()
141 std::call_once(gLoadFlag,
142 []()
144 if (officecfg::Office::Common::I18N::CJK::CJKFont::get())
145 return;
147 SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage(LANGUAGE_SYSTEM);
148 //system locale is CJK
149 bool bAutoEnableCJK = bool(nScriptType & SvtScriptType::ASIAN);
151 if (!bAutoEnableCJK)
153 //windows secondary system locale is CJK
154 OUString sWin16SystemLocale = officecfg::System::L10N::SystemLocale::get();
155 LanguageType eSystemLanguage = LANGUAGE_NONE;
156 if( !sWin16SystemLocale.isEmpty() )
157 eSystemLanguage = LanguageTag::convertToLanguageTypeWithFallback( sWin16SystemLocale );
158 if (eSystemLanguage != LANGUAGE_SYSTEM)
160 SvtScriptType nWinScript = SvtLanguageOptions::GetScriptTypeOfLanguage( eSystemLanguage );
161 bAutoEnableCJK = bool(nWinScript & SvtScriptType::ASIAN);
164 //CJK keyboard is installed
165 if (!bAutoEnableCJK)
166 bAutoEnableCJK = SvtSystemLanguageOptions::isCJKKeyboardLayoutInstalled();
169 if (bAutoEnableCJK)
171 std::shared_ptr<comphelper::ConfigurationChanges> xChanges(comphelper::ConfigurationChanges::create());
172 officecfg::Office::Common::I18N::CJK::CJKFont::set(true, xChanges);
173 officecfg::Office::Common::I18N::CJK::VerticalText::set(true, xChanges);
174 officecfg::Office::Common::I18N::CJK::AsianTypography::set(true, xChanges);
175 officecfg::Office::Common::I18N::CJK::JapaneseFind::set(true, xChanges);
176 officecfg::Office::Common::I18N::CJK::Ruby::set(true, xChanges);
177 officecfg::Office::Common::I18N::CJK::ChangeCaseMap::set(true, xChanges);
178 officecfg::Office::Common::I18N::CJK::DoubleLines::set(true, xChanges);
179 xChanges->commit();
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */