Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "sal/config.h"
21 :
22 : #include <cassert>
23 :
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 "svl/asiancfg.hxx"
44 :
45 : namespace {
46 :
47 0 : rtl::OUString toString(css::lang::Locale const & locale) {
48 : SAL_WARN_IF(
49 : locale.Language.indexOf('-') != -1, "svl",
50 : "Locale language \"" << locale.Language << "\" contains \"-\"");
51 0 : rtl::OUStringBuffer buf(locale.Language);
52 : SAL_WARN_IF(
53 : locale.Country.isEmpty() && !locale.Variant.isEmpty(), "svl",
54 : "Locale has empty country but non-empty variant \"" << locale.Variant
55 : << '"');
56 0 : if (!locale.Country.isEmpty()) {
57 0 : buf.append('-');
58 : SAL_WARN_IF(
59 : locale.Country.indexOf('-') != -1, "svl",
60 : "Locale country \"" << locale.Country << "\" contains \"-\"");
61 0 : buf.append(locale.Country);
62 0 : if (!locale.Variant.isEmpty()) {
63 0 : buf.append('-');
64 0 : buf.append(locale.Variant);
65 : }
66 : }
67 0 : return buf.makeStringAndClear();
68 : }
69 :
70 : }
71 :
72 395 : struct SvxAsianConfig::Impl: private boost::noncopyable {
73 395 : Impl():
74 : context(comphelper::getProcessComponentContext()),
75 395 : batch(comphelper::ConfigurationChanges::create(context))
76 395 : {}
77 :
78 : css::uno::Reference< css::uno::XComponentContext > context;
79 :
80 : boost::shared_ptr< comphelper::ConfigurationChanges > batch;
81 : };
82 :
83 395 : SvxAsianConfig::SvxAsianConfig(): impl_(new Impl) {}
84 :
85 395 : SvxAsianConfig::~SvxAsianConfig() {}
86 :
87 0 : void SvxAsianConfig::Commit() {
88 0 : impl_->batch->commit();
89 0 : }
90 :
91 306 : bool SvxAsianConfig::IsKerningWesternTextOnly() const {
92 : return
93 : officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::get(
94 306 : impl_->context);
95 : }
96 :
97 0 : void SvxAsianConfig::SetKerningWesternTextOnly(bool value) {
98 : officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::set(
99 0 : value, impl_->batch, impl_->context);
100 0 : }
101 :
102 306 : sal_Int16 SvxAsianConfig::GetCharDistanceCompression() const {
103 : return
104 : officecfg::Office::Common::AsianLayout::CompressCharacterDistance::get(
105 306 : impl_->context);
106 : }
107 :
108 0 : void SvxAsianConfig::SetCharDistanceCompression(sal_Int16 value) {
109 : officecfg::Office::Common::AsianLayout::CompressCharacterDistance::set(
110 0 : value, impl_->batch, impl_->context);
111 0 : }
112 :
113 395 : css::uno::Sequence< css::lang::Locale > SvxAsianConfig::GetStartEndCharLocales()
114 : const
115 : {
116 : css::uno::Sequence< rtl::OUString > ns(
117 : officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
118 790 : impl_->context)->
119 395 : getElementNames());
120 395 : css::uno::Sequence< css::lang::Locale > ls(ns.getLength());
121 395 : for (sal_Int32 i = 0; i < ns.getLength(); ++i) {
122 0 : sal_Int32 n = 0;
123 0 : ls[i].Language = ns[i].getToken(0, '-', n);
124 0 : ls[i].Country = ns[i].getToken(0, '-', n);
125 0 : ls[i].Variant = ns[i].getToken(0, '-', n);
126 : }
127 395 : return ls;
128 : }
129 :
130 0 : bool SvxAsianConfig::GetStartEndChars(
131 : css::lang::Locale const & locale, rtl::OUString & startChars,
132 : rtl::OUString & endChars) const
133 : {
134 : css::uno::Reference< css::container::XNameAccess > set(
135 : officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
136 0 : impl_->context));
137 0 : css::uno::Any v;
138 : try {
139 0 : v = set->getByName(toString(locale));
140 0 : } catch (css::container::NoSuchElementException &) {
141 0 : return false;
142 : }
143 : css::uno::Reference< css::beans::XPropertySet > el(
144 : v.get< css::uno::Reference< css::beans::XPropertySet > >(),
145 0 : css::uno::UNO_SET_THROW);
146 0 : startChars = el->getPropertyValue("StartCharacters").get< rtl::OUString >();
147 0 : endChars = el->getPropertyValue("EndCharacters").get< rtl::OUString >();
148 0 : return true;
149 : }
150 :
151 0 : void SvxAsianConfig::SetStartEndChars(
152 : css::lang::Locale const & locale, rtl::OUString const * startChars,
153 : rtl::OUString const * endChars)
154 : {
155 : assert((startChars == 0) == (endChars == 0));
156 : css::uno::Reference< css::container::XNameContainer > set(
157 : officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
158 0 : impl_->batch, impl_->context));
159 0 : rtl::OUString name(toString(locale));
160 0 : if (startChars == 0) {
161 : try {
162 0 : set->removeByName(name);
163 0 : } catch (css::container::NoSuchElementException &) {}
164 : } else {
165 : bool found;
166 0 : css::uno::Any v;
167 : try {
168 0 : v = set->getByName(name);
169 0 : found = true;
170 0 : } catch (css::container::NoSuchElementException &) {
171 0 : found = false;
172 : }
173 0 : if (found) {
174 : css::uno::Reference< css::beans::XPropertySet > el(
175 : v.get< css::uno::Reference< css::beans::XPropertySet > >(),
176 0 : css::uno::UNO_SET_THROW);
177 0 : el->setPropertyValue("StartCharacters", css::uno::makeAny(*startChars));
178 0 : el->setPropertyValue("EndCharacters", css::uno::makeAny(*endChars));
179 : } else {
180 : css::uno::Reference< css::beans::XPropertySet > el(
181 : (css::uno::Reference< css::lang::XSingleServiceFactory >(
182 0 : set, css::uno::UNO_QUERY_THROW)->
183 0 : createInstance()),
184 0 : css::uno::UNO_QUERY_THROW);
185 0 : el->setPropertyValue("StartCharacters", css::uno::makeAny(*startChars));
186 0 : el->setPropertyValue("EndCharacters", css::uno::makeAny(*endChars));
187 0 : css::uno::Any v2(css::uno::makeAny(el));
188 : try {
189 0 : set->insertByName(name, v2);
190 0 : } catch (css::container::ElementExistException &) {
191 : SAL_INFO("svl", "Concurrent update race for \"" << name << '"');
192 0 : }
193 0 : }
194 0 : }
195 0 : }
196 :
197 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|