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 .
20 #include <sal/config.h>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/container/ElementExistException.hpp>
26 #include <com/sun/star/container/NoSuchElementException.hpp>
27 #include <com/sun/star/container/XNameAccess.hpp>
28 #include <com/sun/star/container/XNameContainer.hpp>
29 #include <com/sun/star/lang/Locale.hpp>
30 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
31 #include <com/sun/star/uno/Any.hxx>
32 #include <com/sun/star/uno/Reference.hxx>
33 #include <com/sun/star/uno/Sequence.hxx>
34 #include <comphelper/configuration.hxx>
35 #include <comphelper/processfactory.hxx>
36 #include <officecfg/Office/Common.hxx>
37 #include <rtl/ustring.hxx>
38 #include <sal/log.hxx>
39 #include <sal/types.h>
40 #include <i18nlangtag/languagetag.hxx>
41 #include <svl/asiancfg.hxx>
45 OUString
toString(css::lang::Locale
const & locale
) {
46 SAL_WARN_IF( locale
.Language
.indexOf('-') != -1, "svl",
47 "Locale language \"" << locale
.Language
<< "\" contains \"-\"");
48 SAL_WARN_IF( locale
.Country
.indexOf('-') != -1, "svl",
49 "Locale country \"" << locale
.Country
<< "\" contains \"-\"");
50 return LanguageTag::convertToBcp47( locale
, false);
55 struct SvxAsianConfig::Impl
{
57 batch(comphelper::ConfigurationChanges::create())
60 Impl(const Impl
&) = delete;
61 Impl
& operator=(const Impl
&) = delete;
63 std::shared_ptr
< comphelper::ConfigurationChanges
> batch
;
66 SvxAsianConfig::SvxAsianConfig(): impl_(new Impl
) {}
68 SvxAsianConfig::~SvxAsianConfig() {}
70 void SvxAsianConfig::Commit() {
71 impl_
->batch
->commit();
75 bool SvxAsianConfig::IsKerningWesternTextOnly() {
77 officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::get();
80 void SvxAsianConfig::SetKerningWesternTextOnly(bool value
) {
81 officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::set(
86 CharCompressType
SvxAsianConfig::GetCharDistanceCompression() {
87 return static_cast<CharCompressType
>(officecfg::Office::Common::AsianLayout::CompressCharacterDistance::get());
90 void SvxAsianConfig::SetCharDistanceCompression(CharCompressType value
) {
91 officecfg::Office::Common::AsianLayout::CompressCharacterDistance::set(
92 static_cast<sal_uInt16
>(value
), impl_
->batch
);
96 css::uno::Sequence
< css::lang::Locale
> SvxAsianConfig::GetStartEndCharLocales()
98 const css::uno::Sequence
< OUString
> ns(
99 officecfg::Office::Common::AsianLayout::StartEndCharacters::get()->
101 css::uno::Sequence
< css::lang::Locale
> ls(ns
.getLength());
102 std::transform(ns
.begin(), ns
.end(), ls
.getArray(),
103 [](const OUString
& rName
) -> css::lang::Locale
{
104 return LanguageTag::convertToLocale( rName
, false); });
109 bool SvxAsianConfig::GetStartEndChars(
110 css::lang::Locale
const & locale
, OUString
& startChars
,
113 css::uno::Reference
< css::container::XNameAccess
> set(
114 officecfg::Office::Common::AsianLayout::StartEndCharacters::get());
117 v
= set
->getByName(toString(locale
));
118 } catch (css::container::NoSuchElementException
&) {
121 css::uno::Reference
< css::beans::XPropertySet
> el(
122 v
.get
< css::uno::Reference
< css::beans::XPropertySet
> >(),
123 css::uno::UNO_SET_THROW
);
124 startChars
= el
->getPropertyValue(u
"StartCharacters"_ustr
).get
< OUString
>();
125 endChars
= el
->getPropertyValue(u
"EndCharacters"_ustr
).get
< OUString
>();
129 void SvxAsianConfig::SetStartEndChars(
130 css::lang::Locale
const & locale
, OUString
const * startChars
,
131 OUString
const * endChars
)
133 assert((startChars
== nullptr) == (endChars
== nullptr));
134 css::uno::Reference
< css::container::XNameContainer
> set(
135 officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
137 OUString
name(toString(locale
));
138 if (startChars
== nullptr) {
140 set
->removeByName(name
);
141 } catch (css::container::NoSuchElementException
&) {}
146 v
= set
->getByName(name
);
148 } catch (css::container::NoSuchElementException
&) {
152 css::uno::Reference
< css::beans::XPropertySet
> el(
153 v
.get
< css::uno::Reference
< css::beans::XPropertySet
> >(),
154 css::uno::UNO_SET_THROW
);
155 el
->setPropertyValue(u
"StartCharacters"_ustr
, css::uno::Any(*startChars
));
156 el
->setPropertyValue(u
"EndCharacters"_ustr
, css::uno::Any(*endChars
));
158 css::uno::Reference
< css::beans::XPropertySet
> el(
159 (css::uno::Reference
< css::lang::XSingleServiceFactory
>(
160 set
, css::uno::UNO_QUERY_THROW
)->
162 css::uno::UNO_QUERY_THROW
);
163 el
->setPropertyValue(u
"StartCharacters"_ustr
, css::uno::Any(*startChars
));
164 el
->setPropertyValue(u
"EndCharacters"_ustr
, css::uno::Any(*endChars
));
165 css::uno::Any
v2(el
);
167 set
->insertByName(name
, v2
);
168 } catch (css::container::ElementExistException
&) {
169 SAL_INFO("svl", "Concurrent update race for \"" << name
<< '"');
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */