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();
74 bool SvxAsianConfig::IsKerningWesternTextOnly() const {
76 officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::get();
79 void SvxAsianConfig::SetKerningWesternTextOnly(bool value
) {
80 officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::set(
84 CharCompressType
SvxAsianConfig::GetCharDistanceCompression() const {
85 return static_cast<CharCompressType
>(officecfg::Office::Common::AsianLayout::CompressCharacterDistance::get());
88 void SvxAsianConfig::SetCharDistanceCompression(CharCompressType value
) {
89 officecfg::Office::Common::AsianLayout::CompressCharacterDistance::set(
90 static_cast<sal_uInt16
>(value
), impl_
->batch
);
93 css::uno::Sequence
< css::lang::Locale
> SvxAsianConfig::GetStartEndCharLocales()
96 const css::uno::Sequence
< OUString
> ns(
97 officecfg::Office::Common::AsianLayout::StartEndCharacters::get()->
99 css::uno::Sequence
< css::lang::Locale
> ls(ns
.getLength());
100 std::transform(ns
.begin(), ns
.end(), ls
.getArray(),
101 [](const OUString
& rName
) -> css::lang::Locale
{
102 return LanguageTag::convertToLocale( rName
, false); });
106 bool SvxAsianConfig::GetStartEndChars(
107 css::lang::Locale
const & locale
, OUString
& startChars
,
108 OUString
& endChars
) const
110 css::uno::Reference
< css::container::XNameAccess
> set(
111 officecfg::Office::Common::AsianLayout::StartEndCharacters::get());
114 v
= set
->getByName(toString(locale
));
115 } catch (css::container::NoSuchElementException
&) {
118 css::uno::Reference
< css::beans::XPropertySet
> el(
119 v
.get
< css::uno::Reference
< css::beans::XPropertySet
> >(),
120 css::uno::UNO_SET_THROW
);
121 startChars
= el
->getPropertyValue("StartCharacters").get
< OUString
>();
122 endChars
= el
->getPropertyValue("EndCharacters").get
< OUString
>();
126 void SvxAsianConfig::SetStartEndChars(
127 css::lang::Locale
const & locale
, OUString
const * startChars
,
128 OUString
const * endChars
)
130 assert((startChars
== nullptr) == (endChars
== nullptr));
131 css::uno::Reference
< css::container::XNameContainer
> set(
132 officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
134 OUString
name(toString(locale
));
135 if (startChars
== nullptr) {
137 set
->removeByName(name
);
138 } catch (css::container::NoSuchElementException
&) {}
143 v
= set
->getByName(name
);
145 } catch (css::container::NoSuchElementException
&) {
149 css::uno::Reference
< css::beans::XPropertySet
> el(
150 v
.get
< css::uno::Reference
< css::beans::XPropertySet
> >(),
151 css::uno::UNO_SET_THROW
);
152 el
->setPropertyValue("StartCharacters", css::uno::Any(*startChars
));
153 el
->setPropertyValue("EndCharacters", css::uno::Any(*endChars
));
155 css::uno::Reference
< css::beans::XPropertySet
> el(
156 (css::uno::Reference
< css::lang::XSingleServiceFactory
>(
157 set
, css::uno::UNO_QUERY_THROW
)->
159 css::uno::UNO_QUERY_THROW
);
160 el
->setPropertyValue("StartCharacters", css::uno::Any(*startChars
));
161 el
->setPropertyValue("EndCharacters", css::uno::Any(*endChars
));
162 css::uno::Any
v2(el
);
164 set
->insertByName(name
, v2
);
165 } catch (css::container::ElementExistException
&) {
166 SAL_INFO("svl", "Concurrent update race for \"" << name
<< '"');
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */