LibreOffice Module svl (master) 1
ctloptions.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
20
21#include <svl/ctloptions.hxx>
22
25#include <com/sun/star/uno/Any.h>
26#include <com/sun/star/uno/Sequence.hxx>
27#include <osl/mutex.hxx>
28#include "itemholder2.hxx"
29#include <officecfg/Office/Common.hxx>
30
31using namespace ::com::sun::star;
32using namespace ::com::sun::star::uno;
33
34#define CFG_READONLY_DEFAULT false
35
37{
38private:
46
53
54 virtual void ImplCommit() override;
55
56public:
58 virtual ~SvtCTLOptions_Impl() override;
59
60 virtual void Notify( const Sequence< OUString >& _aPropertyNames ) override;
61 void Load();
62
63 bool IsLoaded() const { return m_bIsLoaded; }
64 void SetCTLFontEnabled( bool _bEnabled );
65
66 void SetCTLSequenceChecking( bool _bEnabled );
67
68 void SetCTLSequenceCheckingRestricted( bool _bEnable );
69
70 void SetCTLSequenceCheckingTypeAndReplace( bool _bEnable );
71
73
75
76 bool IsReadOnly(SvtCTLOptions::EOption eOption) const;
77};
78namespace
79{
80 Sequence<OUString> & PropertyNames()
81 {
82 static Sequence<OUString> SINGLETON;
83 return SINGLETON;
84 }
85}
87{
89 switch(eOption)
90 {
97 default: assert(false);
98 }
99 return bReadOnly;
100}
102
103 utl::ConfigItem("Office.Common/I18N/CTL"),
104
105 m_bIsLoaded ( false ),
106 m_bCTLFontEnabled ( true ),
107 m_bCTLSequenceChecking ( false ),
108 m_bCTLRestricted ( false ),
109 m_bCTLTypeAndReplace ( false ),
110 m_eCTLCursorMovement ( SvtCTLOptions::MOVEMENT_LOGICAL ),
111 m_eCTLTextNumerals ( SvtCTLOptions::NUMERALS_ARABIC ),
112
113 m_bROCTLFontEnabled ( CFG_READONLY_DEFAULT ),
114 m_bROCTLSequenceChecking( CFG_READONLY_DEFAULT ),
115 m_bROCTLRestricted ( CFG_READONLY_DEFAULT ),
116 m_bROCTLTypeAndReplace ( CFG_READONLY_DEFAULT ),
117 m_bROCTLCursorMovement ( CFG_READONLY_DEFAULT ),
118 m_bROCTLTextNumerals ( CFG_READONLY_DEFAULT )
119{
120}
122{
123 assert(!IsModified()); // should have been committed
124}
125
126void SvtCTLOptions_Impl::Notify( const Sequence< OUString >& )
127{
128 Load();
129 NotifyListeners(ConfigurationHints::CtlSettingsChanged);
130}
131
133{
134 Sequence< OUString > &rPropertyNames = PropertyNames();
135 OUString* pOrgNames = rPropertyNames.getArray();
136 sal_Int32 nOrgCount = rPropertyNames.getLength();
137
138 Sequence< OUString > aNames( nOrgCount );
139 Sequence< Any > aValues( nOrgCount );
140
141 OUString* pNames = aNames.getArray();
142 Any* pValues = aValues.getArray();
143 sal_Int32 nRealCount = 0;
144
145 for ( int nProp = 0; nProp < nOrgCount; nProp++ )
146 {
147 switch ( nProp )
148 {
149 case 0:
150 {
152 {
153 pNames[nRealCount] = pOrgNames[nProp];
154 pValues[nRealCount] <<= m_bCTLFontEnabled;
155 ++nRealCount;
156 }
157 }
158 break;
159
160 case 1:
161 {
163 {
164 pNames[nRealCount] = pOrgNames[nProp];
165 pValues[nRealCount] <<= m_bCTLSequenceChecking;
166 ++nRealCount;
167 }
168 }
169 break;
170
171 case 2:
172 {
174 {
175 pNames[nRealCount] = pOrgNames[nProp];
176 pValues[nRealCount] <<= static_cast<sal_Int32>(m_eCTLCursorMovement);
177 ++nRealCount;
178 }
179 }
180 break;
181
182 case 3:
183 {
185 {
186 pNames[nRealCount] = pOrgNames[nProp];
187 pValues[nRealCount] <<= static_cast<sal_Int32>(m_eCTLTextNumerals);
188 ++nRealCount;
189 }
190 }
191 break;
192
193 case 4:
194 {
196 {
197 pNames[nRealCount] = pOrgNames[nProp];
198 pValues[nRealCount] <<= m_bCTLRestricted;
199 ++nRealCount;
200 }
201 }
202 break;
203 case 5:
204 {
206 {
207 pNames[nRealCount] = pOrgNames[nProp];
208 pValues[nRealCount] <<= m_bCTLTypeAndReplace;
209 ++nRealCount;
210 }
211 }
212 break;
213 }
214 }
215 aNames.realloc(nRealCount);
216 aValues.realloc(nRealCount);
217 PutProperties( aNames, aValues );
218 //broadcast changes
219 NotifyListeners(ConfigurationHints::CtlSettingsChanged);
220}
221
223{
224 Sequence< OUString >& rPropertyNames = PropertyNames();
225 if ( !rPropertyNames.hasElements() )
226 {
227 rPropertyNames = {
228 "CTLFont",
229 "CTLSequenceChecking",
230 "CTLCursorMovement",
231 "CTLTextNumerals",
232 "CTLSequenceCheckingRestricted",
233 "CTLSequenceCheckingTypeAndReplace" };
234 EnableNotification( rPropertyNames );
235 }
236 Sequence< Any > aValues = GetProperties( rPropertyNames );
237 Sequence< sal_Bool > aROStates = GetReadOnlyStates( rPropertyNames );
238 const Any* pValues = aValues.getConstArray();
239 const sal_Bool* pROStates = aROStates.getConstArray();
240 assert(aValues.getLength() == rPropertyNames.getLength() && "GetProperties failed");
241 assert(aROStates.getLength() == rPropertyNames.getLength() && "GetReadOnlyStates failed");
242 if ( aValues.getLength() == rPropertyNames.getLength() && aROStates.getLength() == rPropertyNames.getLength() )
243 {
244 bool bValue = false;
245 sal_Int32 nValue = 0;
246
247 for ( int nProp = 0; nProp < rPropertyNames.getLength(); nProp++ )
248 {
249 if ( pValues[nProp].hasValue() )
250 {
251 if ( pValues[nProp] >>= bValue )
252 {
253 switch ( nProp )
254 {
255 case 0: { m_bCTLFontEnabled = bValue; m_bROCTLFontEnabled = pROStates[nProp]; } break;
256 case 1: { m_bCTLSequenceChecking = bValue; m_bROCTLSequenceChecking = pROStates[nProp]; } break;
257 case 4: { m_bCTLRestricted = bValue; m_bROCTLRestricted = pROStates[nProp]; } break;
258 case 5: { m_bCTLTypeAndReplace = bValue; m_bROCTLTypeAndReplace = pROStates[nProp]; } break;
259 }
260 }
261 else if ( pValues[nProp] >>= nValue )
262 {
263 switch ( nProp )
264 {
265 case 2: { m_eCTLCursorMovement = static_cast<SvtCTLOptions::CursorMovement>(nValue); m_bROCTLCursorMovement = pROStates[nProp]; } break;
266 case 3: { m_eCTLTextNumerals = static_cast<SvtCTLOptions::TextNumerals>(nValue); m_bROCTLTextNumerals = pROStates[nProp]; } break;
267 }
268 }
269 }
270 }
271 }
272
273 m_bIsLoaded = true;
274}
276{
277 if(!m_bROCTLFontEnabled && m_bCTLFontEnabled != _bEnabled)
278 {
279 m_bCTLFontEnabled = _bEnabled;
280 SetModified();
281 NotifyListeners(ConfigurationHints::NONE);
282 }
283}
285{
287 {
288 SetModified();
289 m_bCTLSequenceChecking = _bEnabled;
290 NotifyListeners(ConfigurationHints::NONE);
291 }
292}
294{
295 if(!m_bROCTLRestricted && m_bCTLRestricted != _bEnabled)
296 {
297 SetModified();
298 m_bCTLRestricted = _bEnabled;
299 NotifyListeners(ConfigurationHints::NONE);
300 }
301}
303{
305 {
306 SetModified();
307 m_bCTLTypeAndReplace = _bEnabled;
308 NotifyListeners(ConfigurationHints::NONE);
309 }
310}
312{
313 if (!m_bROCTLCursorMovement && m_eCTLCursorMovement != _eMovement )
314 {
315 SetModified();
316 m_eCTLCursorMovement = _eMovement;
317 NotifyListeners(ConfigurationHints::NONE);
318 }
319}
321{
322 if (!m_bROCTLTextNumerals && m_eCTLTextNumerals != _eNumerals )
323 {
324 SetModified();
325 m_eCTLTextNumerals = _eNumerals;
326 NotifyListeners(ConfigurationHints::NONE);
327 }
328}
329
330namespace {
331
332 // global
333 std::weak_ptr<SvtCTLOptions_Impl> g_pCTLOptions;
334
335 osl::Mutex& CTLMutex()
336 {
337 static osl::Mutex aMutex;
338 return aMutex;
339 }
340}
341
343{
344 // Global access, must be guarded (multithreading)
345 ::osl::MutexGuard aGuard( CTLMutex() );
346
347 m_pImpl = g_pCTLOptions.lock();
348 if ( !m_pImpl )
349 {
350 m_pImpl = std::make_shared<SvtCTLOptions_Impl>();
351 g_pCTLOptions = m_pImpl;
352 ItemHolder2::holdConfigItem(EItem::CTLOptions);
353 }
354
355 if( !bDontLoad && !m_pImpl->IsLoaded() )
356 m_pImpl->Load();
357
358 m_pImpl->AddListener(this);
359}
360
361
363{
364 // Global access, must be guarded (multithreading)
365 ::osl::MutexGuard aGuard( CTLMutex() );
366
367 m_pImpl->RemoveListener(this);
368 m_pImpl.reset();
369}
370
372{
373 assert(m_pImpl->IsLoaded());
374 m_pImpl->SetCTLFontEnabled( _bEnabled );
375}
376
378{
379 return officecfg::Office::Common::I18N::CTL::CTLFont::get();
380}
381
383{
384 assert(m_pImpl->IsLoaded());
385 m_pImpl->SetCTLSequenceChecking(_bEnabled);
386}
387
389{
390 return officecfg::Office::Common::I18N::CTL::CTLSequenceChecking::get();
391}
392
394{
395 assert(m_pImpl->IsLoaded());
396 m_pImpl->SetCTLSequenceCheckingRestricted(_bEnable);
397}
398
400{
401 return officecfg::Office::Common::I18N::CTL::CTLSequenceCheckingRestricted::get();
402}
403
405{
406 assert(m_pImpl->IsLoaded());
407 m_pImpl->SetCTLSequenceCheckingTypeAndReplace(_bEnable);
408}
409
411{
412 return officecfg::Office::Common::I18N::CTL::CTLSequenceCheckingTypeAndReplace::get();
413}
414
416{
417 assert(m_pImpl->IsLoaded());
418 m_pImpl->SetCTLCursorMovement( _eMovement );
419}
420
422{
423 return static_cast<SvtCTLOptions::CursorMovement>(officecfg::Office::Common::I18N::CTL::CTLCursorMovement::get());
424}
425
427{
428 assert(m_pImpl->IsLoaded());
429 m_pImpl->SetCTLTextNumerals( _eNumerals );
430}
431
433{
436 return static_cast<SvtCTLOptions::TextNumerals>(officecfg::Office::Common::I18N::CTL::CTLTextNumerals::get());
437}
438
440{
441 assert(m_pImpl->IsLoaded());
442 return m_pImpl->IsReadOnly(eOption);
443}
444
445
446/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
static void holdConfigItem(EItem eItem)
Definition: itemholder2.cxx:64
void SetCTLSequenceChecking(bool _bEnabled)
Definition: ctloptions.cxx:284
bool m_bROCTLSequenceChecking
Definition: ctloptions.cxx:48
virtual void ImplCommit() override
Definition: ctloptions.cxx:132
void SetCTLSequenceCheckingRestricted(bool _bEnable)
Definition: ctloptions.cxx:293
void SetCTLSequenceCheckingTypeAndReplace(bool _bEnable)
Definition: ctloptions.cxx:302
bool IsReadOnly(SvtCTLOptions::EOption eOption) const
Definition: ctloptions.cxx:86
SvtCTLOptions::CursorMovement m_eCTLCursorMovement
Definition: ctloptions.cxx:44
void SetCTLCursorMovement(SvtCTLOptions::CursorMovement _eMovement)
Definition: ctloptions.cxx:311
bool IsLoaded() const
Definition: ctloptions.cxx:63
SvtCTLOptions::TextNumerals m_eCTLTextNumerals
Definition: ctloptions.cxx:45
void SetCTLFontEnabled(bool _bEnabled)
Definition: ctloptions.cxx:275
virtual ~SvtCTLOptions_Impl() override
Definition: ctloptions.cxx:121
virtual void Notify(const Sequence< OUString > &_aPropertyNames) override
Definition: ctloptions.cxx:126
void SetCTLTextNumerals(SvtCTLOptions::TextNumerals _eNumerals)
Definition: ctloptions.cxx:320
void SetCTLTextNumerals(TextNumerals _eNumerals)
Definition: ctloptions.cxx:426
void SetCTLSequenceCheckingTypeAndReplace(bool _bEnable)
Definition: ctloptions.cxx:404
static bool IsCTLFontEnabled()
Definition: ctloptions.cxx:377
static bool IsCTLSequenceCheckingTypeAndReplace()
Definition: ctloptions.cxx:410
void SetCTLCursorMovement(CursorMovement _eMovement)
Definition: ctloptions.cxx:415
SvtCTLOptions(bool bDontLoad=false)
Definition: ctloptions.cxx:342
static CursorMovement GetCTLCursorMovement()
Definition: ctloptions.cxx:421
static TextNumerals GetCTLTextNumerals()
Definition: ctloptions.cxx:432
std::shared_ptr< SvtCTLOptions_Impl > m_pImpl
Definition: ctloptions.hxx:33
bool IsReadOnly(EOption eOption) const
Definition: ctloptions.cxx:439
static bool IsCTLSequenceChecking()
Definition: ctloptions.cxx:388
@ E_CTLSEQUENCECHECKINGTYPEANDREPLACE
Definition: ctloptions.hxx:78
@ E_CTLSEQUENCECHECKINGRESTRICTED
Definition: ctloptions.hxx:77
static bool IsCTLSequenceCheckingRestricted()
Definition: ctloptions.cxx:399
void SetCTLSequenceChecking(bool _bEnabled)
Definition: ctloptions.cxx:382
void SetCTLFontEnabled(bool _bEnabled)
Definition: ctloptions.cxx:371
virtual ~SvtCTLOptions() override
Definition: ctloptions.cxx:362
void SetCTLSequenceCheckingRestricted(bool _bEnable)
Definition: ctloptions.cxx:393
static bool PutProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, const css::uno::Sequence< css::uno::Any > &rValues, bool bAllLocales)
bool EnableNotification(const css::uno::Sequence< OUString > &rNames, bool bEnableInternalNotification=false)
bool IsModified() const
static css::uno::Sequence< css::uno::Any > GetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, bool bAllLocales)
css::uno::Sequence< sal_Bool > GetReadOnlyStates(const css::uno::Sequence< OUString > &rNames)
static bool IsFuzzing()
void NotifyListeners(ConfigurationHints nHint)
#define CFG_READONLY_DEFAULT
Definition: ctloptions.cxx:34
sal_Int16 nValue
bool bReadOnly
std::mutex aMutex
unsigned char sal_Bool