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 .
21 #include <svl/ctloptions.hxx>
23 #include <svl/languageoptions.hxx>
24 #include <i18nlangtag/mslangid.hxx>
25 #include <unotools/configitem.hxx>
26 #include <com/sun/star/uno/Any.h>
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <osl/mutex.hxx>
29 #include <rtl/instance.hxx>
30 #include <unotools/syslocale.hxx>
31 #include <svl/hint.hxx>
32 #include "itemholder2.hxx"
34 using namespace ::com::sun::star
;
35 using namespace ::com::sun::star::uno
;
37 #define CFG_READONLY_DEFAULT false
39 class SvtCTLOptions_Impl
: public utl::ConfigItem
43 bool m_bCTLFontEnabled
;
44 bool m_bCTLSequenceChecking
;
45 bool m_bCTLRestricted
;
46 bool m_bCTLTypeAndReplace
;
47 SvtCTLOptions::CursorMovement m_eCTLCursorMovement
;
48 SvtCTLOptions::TextNumerals m_eCTLTextNumerals
;
50 bool m_bROCTLFontEnabled
;
51 bool m_bROCTLSequenceChecking
;
52 bool m_bROCTLRestricted
;
53 bool m_bROCTLTypeAndReplace
;
54 bool m_bROCTLCursorMovement
;
55 bool m_bROCTLTextNumerals
;
57 virtual void ImplCommit() override
;
61 virtual ~SvtCTLOptions_Impl() override
;
63 virtual void Notify( const Sequence
< OUString
>& _aPropertyNames
) override
;
66 bool IsLoaded() const { return m_bIsLoaded
; }
67 void SetCTLFontEnabled( bool _bEnabled
);
68 bool IsCTLFontEnabled() const { return m_bCTLFontEnabled
; }
70 void SetCTLSequenceChecking( bool _bEnabled
);
71 bool IsCTLSequenceChecking() const { return m_bCTLSequenceChecking
;}
73 void SetCTLSequenceCheckingRestricted( bool _bEnable
);
74 bool IsCTLSequenceCheckingRestricted() const { return m_bCTLRestricted
; }
76 void SetCTLSequenceCheckingTypeAndReplace( bool _bEnable
);
77 bool IsCTLSequenceCheckingTypeAndReplace() const { return m_bCTLTypeAndReplace
; }
79 void SetCTLCursorMovement( SvtCTLOptions::CursorMovement _eMovement
);
80 SvtCTLOptions::CursorMovement
81 GetCTLCursorMovement() const { return m_eCTLCursorMovement
; }
83 void SetCTLTextNumerals( SvtCTLOptions::TextNumerals _eNumerals
);
84 SvtCTLOptions::TextNumerals
85 GetCTLTextNumerals() const { return m_eCTLTextNumerals
; }
87 bool IsReadOnly(SvtCTLOptions::EOption eOption
) const;
92 : public rtl::Static
< Sequence
< OUString
>, PropertyNames
> {};
94 bool SvtCTLOptions_Impl::IsReadOnly(SvtCTLOptions::EOption eOption
) const
96 bool bReadOnly
= CFG_READONLY_DEFAULT
;
99 case SvtCTLOptions::E_CTLFONT
: bReadOnly
= m_bROCTLFontEnabled
; break;
100 case SvtCTLOptions::E_CTLSEQUENCECHECKING
: bReadOnly
= m_bROCTLSequenceChecking
; break;
101 case SvtCTLOptions::E_CTLCURSORMOVEMENT
: bReadOnly
= m_bROCTLCursorMovement
; break;
102 case SvtCTLOptions::E_CTLTEXTNUMERALS
: bReadOnly
= m_bROCTLTextNumerals
; break;
103 case SvtCTLOptions::E_CTLSEQUENCECHECKINGRESTRICTED
: bReadOnly
= m_bROCTLRestricted
; break;
104 case SvtCTLOptions::E_CTLSEQUENCECHECKINGTYPEANDREPLACE
: bReadOnly
= m_bROCTLTypeAndReplace
; break;
105 default: assert(false);
109 SvtCTLOptions_Impl::SvtCTLOptions_Impl() :
111 utl::ConfigItem("Office.Common/I18N/CTL"),
113 m_bIsLoaded ( false ),
114 m_bCTLFontEnabled ( true ),
115 m_bCTLSequenceChecking ( false ),
116 m_bCTLRestricted ( false ),
117 m_bCTLTypeAndReplace ( false ),
118 m_eCTLCursorMovement ( SvtCTLOptions::MOVEMENT_LOGICAL
),
119 m_eCTLTextNumerals ( SvtCTLOptions::NUMERALS_ARABIC
),
121 m_bROCTLFontEnabled ( CFG_READONLY_DEFAULT
),
122 m_bROCTLSequenceChecking( CFG_READONLY_DEFAULT
),
123 m_bROCTLRestricted ( CFG_READONLY_DEFAULT
),
124 m_bROCTLTypeAndReplace ( CFG_READONLY_DEFAULT
),
125 m_bROCTLCursorMovement ( CFG_READONLY_DEFAULT
),
126 m_bROCTLTextNumerals ( CFG_READONLY_DEFAULT
)
129 SvtCTLOptions_Impl::~SvtCTLOptions_Impl()
131 assert(!IsModified()); // should have been committed
134 void SvtCTLOptions_Impl::Notify( const Sequence
< OUString
>& )
137 NotifyListeners(ConfigurationHints::CtlSettingsChanged
);
140 void SvtCTLOptions_Impl::ImplCommit()
142 Sequence
< OUString
> &rPropertyNames
= PropertyNames::get();
143 OUString
* pOrgNames
= rPropertyNames
.getArray();
144 sal_Int32 nOrgCount
= rPropertyNames
.getLength();
146 Sequence
< OUString
> aNames( nOrgCount
);
147 Sequence
< Any
> aValues( nOrgCount
);
149 OUString
* pNames
= aNames
.getArray();
150 Any
* pValues
= aValues
.getArray();
151 sal_Int32 nRealCount
= 0;
153 for ( int nProp
= 0; nProp
< nOrgCount
; nProp
++ )
159 if (!m_bROCTLFontEnabled
)
161 pNames
[nRealCount
] = pOrgNames
[nProp
];
162 pValues
[nRealCount
] <<= m_bCTLFontEnabled
;
170 if (!m_bROCTLSequenceChecking
)
172 pNames
[nRealCount
] = pOrgNames
[nProp
];
173 pValues
[nRealCount
] <<= m_bCTLSequenceChecking
;
181 if (!m_bROCTLCursorMovement
)
183 pNames
[nRealCount
] = pOrgNames
[nProp
];
184 pValues
[nRealCount
] <<= static_cast<sal_Int32
>(m_eCTLCursorMovement
);
192 if (!m_bROCTLTextNumerals
)
194 pNames
[nRealCount
] = pOrgNames
[nProp
];
195 pValues
[nRealCount
] <<= static_cast<sal_Int32
>(m_eCTLTextNumerals
);
203 if (!m_bROCTLRestricted
)
205 pNames
[nRealCount
] = pOrgNames
[nProp
];
206 pValues
[nRealCount
] <<= m_bCTLRestricted
;
213 if(!m_bROCTLTypeAndReplace
)
215 pNames
[nRealCount
] = pOrgNames
[nProp
];
216 pValues
[nRealCount
] <<= m_bCTLTypeAndReplace
;
223 aNames
.realloc(nRealCount
);
224 aValues
.realloc(nRealCount
);
225 PutProperties( aNames
, aValues
);
227 NotifyListeners(ConfigurationHints::CtlSettingsChanged
);
230 void SvtCTLOptions_Impl::Load()
232 Sequence
< OUString
>& rPropertyNames
= PropertyNames::get();
233 if ( !rPropertyNames
.hasElements() )
235 rPropertyNames
.realloc(6);
236 OUString
* pNames
= rPropertyNames
.getArray();
237 pNames
[0] = "CTLFont";
238 pNames
[1] = "CTLSequenceChecking";
239 pNames
[2] = "CTLCursorMovement";
240 pNames
[3] = "CTLTextNumerals";
241 pNames
[4] = "CTLSequenceCheckingRestricted";
242 pNames
[5] = "CTLSequenceCheckingTypeAndReplace";
243 EnableNotification( rPropertyNames
);
245 Sequence
< Any
> aValues
= GetProperties( rPropertyNames
);
246 Sequence
< sal_Bool
> aROStates
= GetReadOnlyStates( rPropertyNames
);
247 const Any
* pValues
= aValues
.getConstArray();
248 const sal_Bool
* pROStates
= aROStates
.getConstArray();
249 assert(aValues
.getLength() == rPropertyNames
.getLength() && "GetProperties failed");
250 assert(aROStates
.getLength() == rPropertyNames
.getLength() && "GetReadOnlyStates failed");
251 if ( aValues
.getLength() == rPropertyNames
.getLength() && aROStates
.getLength() == rPropertyNames
.getLength() )
254 sal_Int32 nValue
= 0;
256 for ( int nProp
= 0; nProp
< rPropertyNames
.getLength(); nProp
++ )
258 if ( pValues
[nProp
].hasValue() )
260 if ( pValues
[nProp
] >>= bValue
)
264 case 0: { m_bCTLFontEnabled
= bValue
; m_bROCTLFontEnabled
= pROStates
[nProp
]; } break;
265 case 1: { m_bCTLSequenceChecking
= bValue
; m_bROCTLSequenceChecking
= pROStates
[nProp
]; } break;
266 case 4: { m_bCTLRestricted
= bValue
; m_bROCTLRestricted
= pROStates
[nProp
]; } break;
267 case 5: { m_bCTLTypeAndReplace
= bValue
; m_bROCTLTypeAndReplace
= pROStates
[nProp
]; } break;
270 else if ( pValues
[nProp
] >>= nValue
)
274 case 2: { m_eCTLCursorMovement
= static_cast<SvtCTLOptions::CursorMovement
>(nValue
); m_bROCTLCursorMovement
= pROStates
[nProp
]; } break;
275 case 3: { m_eCTLTextNumerals
= static_cast<SvtCTLOptions::TextNumerals
>(nValue
); m_bROCTLTextNumerals
= pROStates
[nProp
]; } break;
284 void SvtCTLOptions_Impl::SetCTLFontEnabled( bool _bEnabled
)
286 if(!m_bROCTLFontEnabled
&& m_bCTLFontEnabled
!= _bEnabled
)
288 m_bCTLFontEnabled
= _bEnabled
;
290 NotifyListeners(ConfigurationHints::NONE
);
293 void SvtCTLOptions_Impl::SetCTLSequenceChecking( bool _bEnabled
)
295 if(!m_bROCTLSequenceChecking
&& m_bCTLSequenceChecking
!= _bEnabled
)
298 m_bCTLSequenceChecking
= _bEnabled
;
299 NotifyListeners(ConfigurationHints::NONE
);
302 void SvtCTLOptions_Impl::SetCTLSequenceCheckingRestricted( bool _bEnabled
)
304 if(!m_bROCTLRestricted
&& m_bCTLRestricted
!= _bEnabled
)
307 m_bCTLRestricted
= _bEnabled
;
308 NotifyListeners(ConfigurationHints::NONE
);
311 void SvtCTLOptions_Impl::SetCTLSequenceCheckingTypeAndReplace( bool _bEnabled
)
313 if(!m_bROCTLTypeAndReplace
&& m_bCTLTypeAndReplace
!= _bEnabled
)
316 m_bCTLTypeAndReplace
= _bEnabled
;
317 NotifyListeners(ConfigurationHints::NONE
);
320 void SvtCTLOptions_Impl::SetCTLCursorMovement( SvtCTLOptions::CursorMovement _eMovement
)
322 if (!m_bROCTLCursorMovement
&& m_eCTLCursorMovement
!= _eMovement
)
325 m_eCTLCursorMovement
= _eMovement
;
326 NotifyListeners(ConfigurationHints::NONE
);
329 void SvtCTLOptions_Impl::SetCTLTextNumerals( SvtCTLOptions::TextNumerals _eNumerals
)
331 if (!m_bROCTLTextNumerals
&& m_eCTLTextNumerals
!= _eNumerals
)
334 m_eCTLTextNumerals
= _eNumerals
;
335 NotifyListeners(ConfigurationHints::NONE
);
342 std::weak_ptr
<SvtCTLOptions_Impl
> g_pCTLOptions
;
344 struct CTLMutex
: public rtl::Static
< osl::Mutex
, CTLMutex
> {};
347 SvtCTLOptions::SvtCTLOptions( bool bDontLoad
)
349 // Global access, must be guarded (multithreading)
350 ::osl::MutexGuard
aGuard( CTLMutex::get() );
352 m_pImpl
= g_pCTLOptions
.lock();
355 m_pImpl
= std::make_shared
<SvtCTLOptions_Impl
>();
356 g_pCTLOptions
= m_pImpl
;
357 ItemHolder2::holdConfigItem(EItem::CTLOptions
);
360 if( !bDontLoad
&& !m_pImpl
->IsLoaded() )
363 m_pImpl
->AddListener(this);
367 SvtCTLOptions::~SvtCTLOptions()
369 // Global access, must be guarded (multithreading)
370 ::osl::MutexGuard
aGuard( CTLMutex::get() );
372 m_pImpl
->RemoveListener(this);
376 void SvtCTLOptions::SetCTLFontEnabled( bool _bEnabled
)
378 assert(m_pImpl
->IsLoaded());
379 m_pImpl
->SetCTLFontEnabled( _bEnabled
);
382 bool SvtCTLOptions::IsCTLFontEnabled() const
384 assert(m_pImpl
->IsLoaded());
385 return m_pImpl
->IsCTLFontEnabled();
388 void SvtCTLOptions::SetCTLSequenceChecking( bool _bEnabled
)
390 assert(m_pImpl
->IsLoaded());
391 m_pImpl
->SetCTLSequenceChecking(_bEnabled
);
394 bool SvtCTLOptions::IsCTLSequenceChecking() const
396 assert(m_pImpl
->IsLoaded());
397 return m_pImpl
->IsCTLSequenceChecking();
400 void SvtCTLOptions::SetCTLSequenceCheckingRestricted( bool _bEnable
)
402 assert(m_pImpl
->IsLoaded());
403 m_pImpl
->SetCTLSequenceCheckingRestricted(_bEnable
);
406 bool SvtCTLOptions::IsCTLSequenceCheckingRestricted() const
408 assert(m_pImpl
->IsLoaded());
409 return m_pImpl
->IsCTLSequenceCheckingRestricted();
412 void SvtCTLOptions::SetCTLSequenceCheckingTypeAndReplace( bool _bEnable
)
414 assert(m_pImpl
->IsLoaded());
415 m_pImpl
->SetCTLSequenceCheckingTypeAndReplace(_bEnable
);
418 bool SvtCTLOptions::IsCTLSequenceCheckingTypeAndReplace() const
420 assert(m_pImpl
->IsLoaded());
421 return m_pImpl
->IsCTLSequenceCheckingTypeAndReplace();
424 void SvtCTLOptions::SetCTLCursorMovement( SvtCTLOptions::CursorMovement _eMovement
)
426 assert(m_pImpl
->IsLoaded());
427 m_pImpl
->SetCTLCursorMovement( _eMovement
);
430 SvtCTLOptions::CursorMovement
SvtCTLOptions::GetCTLCursorMovement() const
432 assert(m_pImpl
->IsLoaded());
433 return m_pImpl
->GetCTLCursorMovement();
436 void SvtCTLOptions::SetCTLTextNumerals( SvtCTLOptions::TextNumerals _eNumerals
)
438 assert(m_pImpl
->IsLoaded());
439 m_pImpl
->SetCTLTextNumerals( _eNumerals
);
442 SvtCTLOptions::TextNumerals
SvtCTLOptions::GetCTLTextNumerals() const
444 assert(m_pImpl
->IsLoaded());
445 return m_pImpl
->GetCTLTextNumerals();
448 bool SvtCTLOptions::IsReadOnly(EOption eOption
) const
450 assert(m_pImpl
->IsLoaded());
451 return m_pImpl
->IsReadOnly(eOption
);
455 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */