tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / svl / source / config / asiancfg.cxx
bloba5ccfd74c00129c8e5fef153f30ea1fadc2ba9c5
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 <sal/config.h>
22 #include <cassert>
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>
43 namespace {
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 {
56 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 // static
75 bool SvxAsianConfig::IsKerningWesternTextOnly() {
76 return
77 officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::get();
80 void SvxAsianConfig::SetKerningWesternTextOnly(bool value) {
81 officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::set(
82 value, impl_->batch);
85 // static
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);
95 // static
96 css::uno::Sequence< css::lang::Locale > SvxAsianConfig::GetStartEndCharLocales()
98 const css::uno::Sequence< OUString > ns(
99 officecfg::Office::Common::AsianLayout::StartEndCharacters::get()->
100 getElementNames());
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); });
105 return ls;
108 // static
109 bool SvxAsianConfig::GetStartEndChars(
110 css::lang::Locale const & locale, OUString & startChars,
111 OUString & endChars)
113 css::uno::Reference< css::container::XNameAccess > set(
114 officecfg::Office::Common::AsianLayout::StartEndCharacters::get());
115 css::uno::Any v;
116 try {
117 v = set->getByName(toString(locale));
118 } catch (css::container::NoSuchElementException &) {
119 return false;
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 >();
126 return true;
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(
136 impl_->batch));
137 OUString name(toString(locale));
138 if (startChars == nullptr) {
139 try {
140 set->removeByName(name);
141 } catch (css::container::NoSuchElementException &) {}
142 } else {
143 bool found;
144 css::uno::Any v;
145 try {
146 v = set->getByName(name);
147 found = true;
148 } catch (css::container::NoSuchElementException &) {
149 found = false;
151 if (found) {
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));
157 } else {
158 css::uno::Reference< css::beans::XPropertySet > el(
159 (css::uno::Reference< css::lang::XSingleServiceFactory >(
160 set, css::uno::UNO_QUERY_THROW)->
161 createInstance()),
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);
166 try {
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: */