LibreOffice Module unotools (master) 1
compatibility.cxx
Go to the documentation of this file.
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
23#include <tools/debug.hxx>
24#include <sal/log.hxx>
25#include <com/sun/star/uno/Any.hxx>
26#include <com/sun/star/uno/Sequence.hxx>
27#include <com/sun/star/beans/PropertyValue.hpp>
28#include <com/sun/star/lang/Locale.hpp>
30
31#include "itemholder1.hxx"
32
33#include <algorithm>
34
35using namespace ::utl;
36using namespace ::osl;
37using namespace ::com::sun::star::uno;
38using namespace ::com::sun::star::beans;
39
40constexpr OUStringLiteral ROOTNODE_OPTIONS = u"Office.Compatibility";
41#define PATHDELIMITER "/"
42#define SETNODE_ALLFILEFORMATS "AllFileFormats"
43
45 : m_aPropertyValue( SvtCompatibilityEntry::getElementCount() )
46{
47 /* Should be in the start. Do not remove it. */
48 setValue<OUString>( Index::Name, OUString() );
49 setValue<OUString>( Index::Module, OUString() );
50
51 /* Editable list of default values. Sync it with the SvtCompatibilityEntry::Index enum class. */
52 setValue<bool>( Index::AddSpacing, false );
53 setValue<bool>( Index::AddSpacingAtPages, false );
54 setValue<bool>( Index::UseOurTabStops, false );
55 setValue<bool>( Index::NoExtLeading, false );
56 setValue<bool>( Index::UseLineSpacing, false );
57 setValue<bool>( Index::AddTableSpacing, false );
58 setValue<bool>( Index::UseObjectPositioning, false );
59 setValue<bool>( Index::UseOurTextWrapping, false );
60 setValue<bool>( Index::ConsiderWrappingStyle, false );
61 setValue<bool>( Index::ExpandWordSpace, true );
62 setValue<bool>( Index::ProtectForm, false );
63 setValue<bool>( Index::MsWordTrailingBlanks, false );
64 setValue<bool>( Index::SubtractFlysAnchoredAtFlys, false );
65 setValue<bool>( Index::EmptyDbFieldHidesPara, true );
66 setValue<bool>( Index::AddTableLineSpacing, false );
67 setValue<bool>( Index::UseVariableWidthNBSP, false );
68}
69
71{
72 static const char* sPropertyName[] =
73 {
74 /* Should be in the start. Do not remove it. */
75 "Name",
76 "Module",
77
78 /* Editable list of compatibility option names. Sync it with the SvtCompatibilityEntry::Index enum class. */
79 "AddSpacing",
80 "AddSpacingAtPages",
81 "UseOurTabStopFormat",
82 "NoExternalLeading",
83 "UseLineSpacing",
84 "AddTableSpacing",
85 "UseObjectPositioning",
86 "UseOurTextWrapping",
87 "ConsiderWrappingStyle",
88 "ExpandWordSpace",
89 "ProtectForm",
90 "MsWordCompTrailingBlanks",
91 "SubtractFlysAnchoredAtFlys",
92 "EmptyDbFieldHidesPara",
93 "UseVariableWidthNBSP",
94
95 "AddTableLineSpacing" // Must be the last one
96 };
97
98 /* Size of sPropertyName array not equal size of the SvtCompatibilityEntry::Index enum class */
99 assert( std::size(sPropertyName) == SvtCompatibilityEntry::getElementCount() );
100
101 return OUString::createFromAscii( sPropertyName[ static_cast<int>(rIdx) ] );
102}
103
104/*-****************************************************************************************************************
105 @descr support simple menu structures and operations on it
106****************************************************************************************************************-*/
107
108/*-****************************************************************************************************
109 @short base implementation of public interface for "SvtCompatibilityOptions"!
110 @descr These class is used as static member of "SvtCompatibilityOptions" ...
111 => The code exist only for one time and isn't duplicated for every instance!
112*//*-*****************************************************************************************************/
113class SvtCompatibilityOptions_Impl : public ConfigItem
114{
115 public:
117 virtual ~SvtCompatibilityOptions_Impl() override;
118
119 void AppendItem( const SvtCompatibilityEntry& aItem );
120 void Clear();
121
122 void SetDefault( SvtCompatibilityEntry::Index rIdx, bool rValue );
123 bool GetDefault( SvtCompatibilityEntry::Index rIdx ) const;
124
125 const std::vector< SvtCompatibilityEntry > & GetOptions() const { return m_aOptions; }
126
127 /*-****************************************************************************************************
128 @short called for notify of configmanager
129 @descr This method is called from the ConfigManager before the application ends or from the
130 PropertyChangeListener if the sub tree broadcasts changes. You must update your
131 internal values.
132
133 @seealso baseclass ConfigItem
134
135 @param "lPropertyNames" is the list of properties which should be updated.
136 *//*-*****************************************************************************************************/
137 virtual void Notify( const Sequence< OUString >& lPropertyNames ) override;
138
139 private:
140 virtual void ImplCommit() override;
141
142 /*-****************************************************************************************************
143 @short return list of key names of our configuration management which represent one module tree
144 @descr These methods return the current list of key names! We need it to get needed values from our
145 configuration management and support dynamical menu item lists!
146 @return A list of configuration key names is returned.
147 *//*-*****************************************************************************************************/
149
150 private:
151 std::vector< SvtCompatibilityEntry > m_aOptions;
153};
154
156{
157 // Get names and values of all accessible menu entries and fill internal structures.
158 // See impl_GetPropertyNames() for further information.
161 Sequence< Any > lValues = GetProperties( lNames );
162
163 // Safe impossible cases.
164 // We need values from ALL configuration keys.
165 // Follow assignment use order of values in relation to our list of key names!
166 DBG_ASSERT( !( lNames.getLength()!=lValues.getLength() ), "SvtCompatibilityOptions_Impl::SvtCompatibilityOptions_Impl()\nI miss some values of configuration keys!\n" );
167
168 // Get names/values for new menu.
169 // 4 subkeys for every item!
170 bool bDefaultFound = false;
171 sal_Int32 nDestStep = 0;
172 for ( const auto& rNode : std::as_const(lNodes) )
173 {
175
176 aItem.setValue<OUString>( SvtCompatibilityEntry::Index::Name, rNode );
177
178 for ( int i = static_cast<int>(SvtCompatibilityEntry::Index::Module); i < static_cast<int>(SvtCompatibilityEntry::Index::INVALID); ++i )
179 {
180 aItem.setValue( SvtCompatibilityEntry::Index(i), lValues[ nDestStep ] );
181 nDestStep++;
182 }
183
184 m_aOptions.push_back( aItem );
185
187 {
188 SvtSysLocale aSysLocale;
189 css::lang::Locale aLocale = aSysLocale.GetLanguageTag().getLocale();
190 if ( aLocale.Language == "zh" || aLocale.Language == "ja" || aLocale.Language == "ko" )
192
193 m_aDefOptions = aItem;
194 bDefaultFound = true;
195 }
196 }
197}
198
200{
201 assert( !IsModified() ); // should have been committed
202}
203
205{
206 m_aOptions.push_back( aItem );
207
208 // default item reset?
210 m_aDefOptions = aItem;
211
212 SetModified();
213}
214
216{
217 m_aOptions.clear();
218
219 SetModified();
220}
221
223{
224 /* Are not set Name and Module */
226
227 m_aDefOptions.setValue<bool>( rIdx, rValue );
228}
229
231{
232 /* Are not set Name and Module */
234
235 return m_aDefOptions.getValue<bool>( rIdx );
236}
237
239{
240 SAL_WARN( "unotools.config", "SvtCompatibilityOptions_Impl::Notify() Not implemented yet! I don't know how I can handle a dynamical list of unknown properties ..." );
241}
242
244{
245 // Write all properties!
246 // Delete complete set first.
247 ClearNodeSet( SETNODE_ALLFILEFORMATS );
248
249 Sequence< PropertyValue > lPropertyValues( SvtCompatibilityEntry::getElementCount() - 1 );
250 auto lPropertyValuesRange = asNonConstRange(lPropertyValues);
251 sal_uInt32 nNewCount = m_aOptions.size();
252 for ( sal_uInt32 nItem = 0; nItem < nNewCount; ++nItem )
253 {
254 SvtCompatibilityEntry aItem = m_aOptions[ nItem ];
256
257 for ( int i = static_cast<int>(SvtCompatibilityEntry::Index::Module); i < static_cast<int>(SvtCompatibilityEntry::Index::INVALID); ++i )
258 {
259 lPropertyValuesRange[ i - 1 ].Name = sNode + SvtCompatibilityEntry::getName( SvtCompatibilityEntry::Index(i) );
260 lPropertyValuesRange[ i - 1 ].Value = aItem.getValue( SvtCompatibilityEntry::Index(i) );
261 }
262
263 SetSetProperties( SETNODE_ALLFILEFORMATS, lPropertyValues );
264 }
265}
266
268{
269 // First get ALL names of current existing list items in configuration!
270 rItems = GetNodeNames( SETNODE_ALLFILEFORMATS );
271
272 // expand list to result list ...
273 Sequence< OUString > lProperties( rItems.getLength() * ( SvtCompatibilityEntry::getElementCount() - 1 ) );
274 auto lPropertiesRange = asNonConstRange(lProperties);
275
276 sal_Int32 nDestStep = 0;
277 // Copy entries to destination and expand every item with 2 supported sub properties.
278 for ( const auto& rItem : std::as_const(rItems) )
279 {
280 OUString sFixPath = SETNODE_ALLFILEFORMATS PATHDELIMITER + rItem + PATHDELIMITER;
281 for ( int i = static_cast<int>(SvtCompatibilityEntry::Index::Module); i < static_cast<int>(SvtCompatibilityEntry::Index::INVALID); ++i )
282 {
283 lPropertiesRange[ nDestStep ] = sFixPath + SvtCompatibilityEntry::getName( SvtCompatibilityEntry::Index(i) );
284 nDestStep++;
285 }
286 }
287
288 // Return result.
289 return lProperties;
290}
291
292namespace
293{
294 std::weak_ptr<SvtCompatibilityOptions_Impl> theOptions;
295}
296
298{
299 // Global access, must be guarded (multithreading!).
300 MutexGuard aGuard( GetOwnStaticMutex() );
301
302 m_pImpl = theOptions.lock();
303 if ( !m_pImpl )
304 {
305 m_pImpl = std::make_shared<SvtCompatibilityOptions_Impl>();
306 theOptions = m_pImpl;
308 }
309}
310
312{
313 // Global access, must be guarded (multithreading!)
314 MutexGuard aGuard( GetOwnStaticMutex() );
315 m_pImpl.reset();
316}
317
319{
320 MutexGuard aGuard( GetOwnStaticMutex() );
321 m_pImpl->AppendItem( aItem );
322}
323
325{
326 MutexGuard aGuard( GetOwnStaticMutex() );
327 m_pImpl->Clear();
328}
329
331{
332 MutexGuard aGuard( GetOwnStaticMutex() );
333 m_pImpl->SetDefault( rIdx, rValue );
334}
335
337{
338 MutexGuard aGuard( GetOwnStaticMutex() );
339 return m_pImpl->GetDefault( rIdx );
340}
341
342std::vector< SvtCompatibilityEntry > SvtCompatibilityOptions::GetList() const
343{
344 MutexGuard aGuard( GetOwnStaticMutex() );
345
346 return m_pImpl->GetOptions();
347}
348
350{
351 static osl::Mutex aMutex;
352 return aMutex;
353}
354
355/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void holdConfigItem(EItem eItem)
Definition: itemholder1.cxx:68
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
@ AddTableLineSpacing
special entry: optcomp.cxx converts the other values to integers but not this one because it doesn't ...
static constexpr OUStringLiteral DEFAULT_ENTRY_NAME
static OUString getName(const Index rIdx)
css::uno::Any getValue(const Index rIdx) const
static size_t getElementCount()
void setValue(const Index rIdx, css::uno::Any const &rValue)
const std::vector< SvtCompatibilityEntry > & GetOptions() const
Sequence< OUString > impl_GetPropertyNames(Sequence< OUString > &rItems)
virtual void Notify(const Sequence< OUString > &lPropertyNames) override
void SetDefault(SvtCompatibilityEntry::Index rIdx, bool rValue)
std::vector< SvtCompatibilityEntry > m_aOptions
virtual ~SvtCompatibilityOptions_Impl() override
virtual void ImplCommit() override
SvtCompatibilityEntry m_aDefOptions
bool GetDefault(SvtCompatibilityEntry::Index rIdx) const
void AppendItem(const SvtCompatibilityEntry &aItem)
virtual ~SvtCompatibilityOptions() override
bool GetDefault(SvtCompatibilityEntry::Index rIdx) const
std::shared_ptr< SvtCompatibilityOptions_Impl > m_pImpl
void SetDefault(SvtCompatibilityEntry::Index rIdx, bool rValue)
std::vector< SvtCompatibilityEntry > GetList() const
void AppendItem(const SvtCompatibilityEntry &aItem)
static UNOTOOLS_DLLPRIVATE osl::Mutex & GetOwnStaticMutex()
SvtSysLocale provides a refcounted single instance of an application wide LocaleDataWrapper and <type...
Definition: syslocale.hxx:44
const LanguageTag & GetLanguageTag() const
Definition: syslocale.cxx:161
constexpr OUStringLiteral ROOTNODE_OPTIONS
#define SETNODE_ALLFILEFORMATS
#define PATHDELIMITER
#define DBG_ASSERT(sCon, aError)
float u
@ Compatibility
#define SAL_WARN(area, stream)
int i
std::mutex aMutex