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 <boost/noncopyable.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/container/ElementExistException.hpp>
27 #include <com/sun/star/container/NoSuchElementException.hpp>
28 #include <com/sun/star/container/XNameAccess.hpp>
29 #include <com/sun/star/container/XNameContainer.hpp>
30 #include <com/sun/star/lang/Locale.hpp>
31 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
32 #include <com/sun/star/uno/Any.hxx>
33 #include <com/sun/star/uno/Reference.hxx>
34 #include <com/sun/star/uno/Sequence.hxx>
35 #include <comphelper/configuration.hxx>
36 #include <comphelper/processfactory.hxx>
37 #include "officecfg/Office/Common.hxx"
38 #include <rtl/ustrbuf.hxx>
39 #include <rtl/ustring.h>
40 #include <rtl/ustring.hxx>
41 #include <sal/log.hxx>
42 #include <sal/types.h>
43 #include <i18nlangtag/languagetag.hxx>
44 #include <svl/asiancfg.hxx>
48 OUString
toString(css::lang::Locale
const & locale
) {
49 SAL_WARN_IF( locale
.Language
.indexOf('-') != -1, "svl",
50 "Locale language \"" << locale
.Language
<< "\" contains \"-\"");
51 SAL_WARN_IF( locale
.Country
.indexOf('-') != -1, "svl",
52 "Locale country \"" << locale
.Country
<< "\" contains \"-\"");
53 return LanguageTag::convertToBcp47( locale
, false);
58 struct SvxAsianConfig::Impl
: private boost::noncopyable
{
60 context(comphelper::getProcessComponentContext()),
61 batch(comphelper::ConfigurationChanges::create(context
))
64 css::uno::Reference
< css::uno::XComponentContext
> context
;
66 std::shared_ptr
< comphelper::ConfigurationChanges
> batch
;
69 SvxAsianConfig::SvxAsianConfig(): impl_(new Impl
) {}
71 SvxAsianConfig::~SvxAsianConfig() {}
73 void SvxAsianConfig::Commit() {
74 impl_
->batch
->commit();
77 bool SvxAsianConfig::IsKerningWesternTextOnly() const {
79 officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::get(
83 void SvxAsianConfig::SetKerningWesternTextOnly(bool value
) {
84 officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::set(
88 sal_Int16
SvxAsianConfig::GetCharDistanceCompression() const {
90 officecfg::Office::Common::AsianLayout::CompressCharacterDistance::get(
94 void SvxAsianConfig::SetCharDistanceCompression(sal_Int16 value
) {
95 officecfg::Office::Common::AsianLayout::CompressCharacterDistance::set(
99 css::uno::Sequence
< css::lang::Locale
> SvxAsianConfig::GetStartEndCharLocales()
102 css::uno::Sequence
< OUString
> ns(
103 officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
106 css::uno::Sequence
< css::lang::Locale
> ls(ns
.getLength());
107 for (sal_Int32 i
= 0; i
< ns
.getLength(); ++i
) {
108 ls
[i
] = LanguageTag::convertToLocale( ns
[i
], false);
113 bool SvxAsianConfig::GetStartEndChars(
114 css::lang::Locale
const & locale
, OUString
& startChars
,
115 OUString
& endChars
) const
117 css::uno::Reference
< css::container::XNameAccess
> set(
118 officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
122 v
= set
->getByName(toString(locale
));
123 } catch (css::container::NoSuchElementException
&) {
126 css::uno::Reference
< css::beans::XPropertySet
> el(
127 v
.get
< css::uno::Reference
< css::beans::XPropertySet
> >(),
128 css::uno::UNO_SET_THROW
);
129 startChars
= el
->getPropertyValue("StartCharacters").get
< OUString
>();
130 endChars
= el
->getPropertyValue("EndCharacters").get
< OUString
>();
134 void SvxAsianConfig::SetStartEndChars(
135 css::lang::Locale
const & locale
, OUString
const * startChars
,
136 OUString
const * endChars
)
138 assert((startChars
== 0) == (endChars
== 0));
139 css::uno::Reference
< css::container::XNameContainer
> set(
140 officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
142 OUString
name(toString(locale
));
143 if (startChars
== 0) {
145 set
->removeByName(name
);
146 } catch (css::container::NoSuchElementException
&) {}
151 v
= set
->getByName(name
);
153 } catch (css::container::NoSuchElementException
&) {
157 css::uno::Reference
< css::beans::XPropertySet
> el(
158 v
.get
< css::uno::Reference
< css::beans::XPropertySet
> >(),
159 css::uno::UNO_SET_THROW
);
160 el
->setPropertyValue("StartCharacters", css::uno::makeAny(*startChars
));
161 el
->setPropertyValue("EndCharacters", css::uno::makeAny(*endChars
));
163 css::uno::Reference
< css::beans::XPropertySet
> el(
164 (css::uno::Reference
< css::lang::XSingleServiceFactory
>(
165 set
, css::uno::UNO_QUERY_THROW
)->
167 css::uno::UNO_QUERY_THROW
);
168 el
->setPropertyValue("StartCharacters", css::uno::makeAny(*startChars
));
169 el
->setPropertyValue("EndCharacters", css::uno::makeAny(*endChars
));
170 css::uno::Any
v2(css::uno::makeAny(el
));
172 set
->insertByName(name
, v2
);
173 } catch (css::container::ElementExistException
&) {
174 SAL_INFO("svl", "Concurrent update race for \"" << name
<< '"');
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */