Bump version to 5.0-14
[LibreOffice.git] / svtools / source / config / accessibilityoptions.cxx
blobde2eb97a2e0ba1e7ad3b61856a382196c74ef1df
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 .
21 #include <svtools/accessibilityoptions.hxx>
23 #include <unotools/configmgr.hxx>
24 #include <com/sun/star/uno/Any.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/container/XNameAccess.hpp>
29 #include <comphelper/configurationhelper.hxx>
30 #include <comphelper/processfactory.hxx>
32 #include <svl/smplhint.hxx>
34 #include <svtools/colorcfg.hxx>
36 #include <vcl/settings.hxx>
37 #include <vcl/svapp.hxx>
38 #include <rtl/instance.hxx>
40 #include "itemholder2.hxx"
42 using namespace utl;
43 using namespace com::sun::star::uno;
45 #define HELP_TIP_TIMEOUT 0xffff // max. timeout setting to pretend a non-timeout
47 namespace
49 const char s_sAccessibility[] = "org.openoffice.Office.Common/Accessibility";
50 const char s_sAutoDetectSystemHC[] = "AutoDetectSystemHC";
51 const char s_sIsForPagePreviews[] = "IsForPagePreviews";
52 const char s_sIsHelpTipsDisappear[] = "IsHelpTipsDisappear";
53 const char s_sHelpTipSeconds[] = "HelpTipSeconds";
54 const char s_sIsAllowAnimatedGraphics[] = "IsAllowAnimatedGraphics";
55 const char s_sIsAllowAnimatedText[] = "IsAllowAnimatedText";
56 const char s_sIsAutomaticFontColor[] = "IsAutomaticFontColor";
57 const char s_sIsSelectionInReadonly[] = "IsSelectionInReadonly";
58 const char s_sColorValueSetColumnCount[] = "ColorValueSetColumnCount";
59 const char s_sEdgeBlending[] = "EdgeBlending";
60 const char s_sListBoxMaximumLineCount[] = "ListBoxMaximumLineCount";
61 const char s_sPreviewUsesCheckeredBackground[] = "PreviewUsesCheckeredBackground";
64 // class SvtAccessibilityOptions_Impl ---------------------------------------------
66 class SvtAccessibilityOptions_Impl
68 private:
69 css::uno::Reference< css::container::XNameAccess > m_xCfg;
70 bool bIsModified;
72 public:
73 SvtAccessibilityOptions_Impl();
74 ~SvtAccessibilityOptions_Impl();
76 void SetVCLSettings();
77 bool GetAutoDetectSystemHC();
78 bool GetIsForPagePreviews() const;
79 bool GetIsHelpTipsDisappear() const;
80 bool GetIsAllowAnimatedGraphics() const;
81 bool GetIsAllowAnimatedText() const;
82 bool GetIsAutomaticFontColor() const;
83 sal_Int16 GetHelpTipSeconds() const;
84 bool IsSelectionInReadonly() const;
85 sal_Int16 GetEdgeBlending() const;
86 sal_Int16 GetListBoxMaximumLineCount() const;
87 sal_Int16 GetColorValueSetColumnCount() const;
88 bool GetPreviewUsesCheckeredBackground() const;
90 void SetAutoDetectSystemHC(bool bSet);
91 void SetIsForPagePreviews(bool bSet);
92 void SetIsHelpTipsDisappear(bool bSet);
93 void SetIsAllowAnimatedGraphics(bool bSet);
94 void SetIsAllowAnimatedText(bool bSet);
95 void SetIsAutomaticFontColor(bool bSet);
96 void SetHelpTipSeconds(sal_Int16 nSet);
97 void SetSelectionInReadonly(bool bSet);
99 bool IsModified() const { return bIsModified; };
102 // initialization of static members --------------------------------------
104 SvtAccessibilityOptions_Impl* SvtAccessibilityOptions::sm_pSingleImplConfig =NULL;
105 sal_Int32 SvtAccessibilityOptions::sm_nAccessibilityRefCount(0);
107 namespace
109 struct SingletonMutex
110 : public rtl::Static< ::osl::Mutex, SingletonMutex > {};
114 // class SvtAccessibilityOptions_Impl ---------------------------------------------
116 SvtAccessibilityOptions_Impl::SvtAccessibilityOptions_Impl()
120 m_xCfg = css::uno::Reference< css::container::XNameAccess >(
121 ::comphelper::ConfigurationHelper::openConfig(
122 comphelper::getProcessComponentContext(),
123 s_sAccessibility,
124 ::comphelper::ConfigurationHelper::E_STANDARD),
125 css::uno::UNO_QUERY);
127 bIsModified = false;
129 catch(const css::uno::Exception& ex)
131 m_xCfg.clear();
132 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
136 SvtAccessibilityOptions_Impl::~SvtAccessibilityOptions_Impl()
141 bool SvtAccessibilityOptions_Impl::GetAutoDetectSystemHC()
143 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
144 bool bRet = true;
148 if(xNode.is())
149 xNode->getPropertyValue(s_sAutoDetectSystemHC) >>= bRet;
151 catch(const css::uno::Exception& ex)
153 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
156 return bRet;
159 bool SvtAccessibilityOptions_Impl::GetIsForPagePreviews() const
161 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
162 bool bRet = true;
166 if(xNode.is())
167 xNode->getPropertyValue(s_sIsForPagePreviews) >>= bRet;
169 catch(const css::uno::Exception& ex)
171 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
173 return bRet;
176 bool SvtAccessibilityOptions_Impl::GetIsHelpTipsDisappear() const
178 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
179 bool bRet = true;
183 if(xNode.is())
184 xNode->getPropertyValue(s_sIsHelpTipsDisappear) >>= bRet;
186 catch(const css::uno::Exception& ex)
188 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
191 return bRet;
194 bool SvtAccessibilityOptions_Impl::GetIsAllowAnimatedGraphics() const
196 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
197 bool bRet = true;
201 if(xNode.is())
202 xNode->getPropertyValue(s_sIsAllowAnimatedGraphics) >>= bRet;
204 catch(const css::uno::Exception& ex)
206 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
209 return bRet;
212 bool SvtAccessibilityOptions_Impl::GetIsAllowAnimatedText() const
214 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
215 bool bRet = true;
219 if(xNode.is())
220 xNode->getPropertyValue(s_sIsAllowAnimatedText) >>= bRet;
222 catch(const css::uno::Exception& ex)
224 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
227 return bRet;
230 bool SvtAccessibilityOptions_Impl::GetIsAutomaticFontColor() const
232 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
233 bool bRet = false;
237 if(xNode.is())
238 xNode->getPropertyValue(s_sIsAutomaticFontColor) >>= bRet;
240 catch(const css::uno::Exception& ex)
242 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
245 return bRet;
248 sal_Int16 SvtAccessibilityOptions_Impl::GetHelpTipSeconds() const
250 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
251 sal_Int16 nRet = 4;
255 if(xNode.is())
256 xNode->getPropertyValue(s_sHelpTipSeconds) >>= nRet;
258 catch(const css::uno::Exception& ex)
260 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
263 return nRet;
266 bool SvtAccessibilityOptions_Impl::IsSelectionInReadonly() const
268 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
269 bool bRet = false;
273 if(xNode.is())
274 xNode->getPropertyValue(s_sIsSelectionInReadonly) >>= bRet;
276 catch(const css::uno::Exception& ex)
278 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
281 return bRet;
284 sal_Int16 SvtAccessibilityOptions_Impl::GetEdgeBlending() const
286 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
287 sal_Int16 nRet = 35;
291 if(xNode.is())
292 xNode->getPropertyValue(s_sEdgeBlending) >>= nRet;
294 catch(const css::uno::Exception& ex)
296 SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
299 return nRet;
302 sal_Int16 SvtAccessibilityOptions_Impl::GetListBoxMaximumLineCount() const
304 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
305 sal_Int16 nRet = 25;
309 if(xNode.is())
310 xNode->getPropertyValue(s_sListBoxMaximumLineCount) >>= nRet;
312 catch(const css::uno::Exception& ex)
314 SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
317 return nRet;
320 sal_Int16 SvtAccessibilityOptions_Impl::GetColorValueSetColumnCount() const
322 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
323 sal_Int16 nRet = 12;
327 if(xNode.is())
328 xNode->getPropertyValue(s_sColorValueSetColumnCount) >>= nRet;
330 catch(const css::uno::Exception& ex)
332 SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
335 return nRet;
338 bool SvtAccessibilityOptions_Impl::GetPreviewUsesCheckeredBackground() const
340 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
341 bool bRet = false;
345 if(xNode.is())
346 xNode->getPropertyValue(s_sPreviewUsesCheckeredBackground) >>= bRet;
348 catch(const css::uno::Exception& ex)
350 SAL_WARN("svtools", "Caught unexpected: " << ex.Message);
353 return bRet;
356 void SvtAccessibilityOptions_Impl::SetAutoDetectSystemHC(bool bSet)
358 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
362 if(xNode.is() && xNode->getPropertyValue(s_sAutoDetectSystemHC)!=bSet)
364 xNode->setPropertyValue(s_sAutoDetectSystemHC, css::uno::makeAny(bSet));
365 ::comphelper::ConfigurationHelper::flush(m_xCfg);
366 svtools::ColorConfig().Reload();
367 bIsModified = true;
370 catch(const css::uno::Exception& ex)
372 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
376 void SvtAccessibilityOptions_Impl::SetIsForPagePreviews(bool bSet)
378 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
382 if(xNode.is() && xNode->getPropertyValue(s_sIsForPagePreviews)!=bSet)
384 xNode->setPropertyValue(s_sIsForPagePreviews, css::uno::makeAny(bSet));
385 ::comphelper::ConfigurationHelper::flush(m_xCfg);
387 bIsModified = true;
390 catch(const css::uno::Exception& ex)
392 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
396 void SvtAccessibilityOptions_Impl::SetIsHelpTipsDisappear(bool bSet)
398 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
402 if(xNode.is() && xNode->getPropertyValue(s_sIsHelpTipsDisappear)!=bSet)
404 xNode->setPropertyValue(s_sIsHelpTipsDisappear, css::uno::makeAny(bSet));
405 ::comphelper::ConfigurationHelper::flush(m_xCfg);
407 bIsModified = true;
410 catch(const css::uno::Exception& ex)
412 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
416 void SvtAccessibilityOptions_Impl::SetIsAllowAnimatedGraphics(bool bSet)
418 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
422 if(xNode.is() && xNode->getPropertyValue(s_sIsAllowAnimatedGraphics)!=bSet)
424 xNode->setPropertyValue(s_sIsAllowAnimatedGraphics, css::uno::makeAny(bSet));
425 ::comphelper::ConfigurationHelper::flush(m_xCfg);
427 bIsModified = true;
430 catch(const css::uno::Exception& ex)
432 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
436 void SvtAccessibilityOptions_Impl::SetIsAllowAnimatedText(bool bSet)
438 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
442 if(xNode.is() && xNode->getPropertyValue(s_sIsAllowAnimatedText)!=bSet)
444 xNode->setPropertyValue(s_sIsAllowAnimatedText, css::uno::makeAny(bSet));
445 ::comphelper::ConfigurationHelper::flush(m_xCfg);
447 bIsModified = true;
450 catch(const css::uno::Exception& ex)
452 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
456 void SvtAccessibilityOptions_Impl::SetIsAutomaticFontColor(bool bSet)
458 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
462 if(xNode.is() && xNode->getPropertyValue(s_sIsAutomaticFontColor)!=bSet)
464 xNode->setPropertyValue(s_sIsAutomaticFontColor, css::uno::makeAny(bSet));
465 ::comphelper::ConfigurationHelper::flush(m_xCfg);
467 bIsModified = true;
470 catch(const css::uno::Exception& ex)
472 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
476 void SvtAccessibilityOptions_Impl::SetHelpTipSeconds(sal_Int16 nSet)
478 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
482 if(xNode.is() && xNode->getPropertyValue(s_sHelpTipSeconds)!=nSet)
484 xNode->setPropertyValue(s_sHelpTipSeconds, css::uno::makeAny(nSet));
485 ::comphelper::ConfigurationHelper::flush(m_xCfg);
487 bIsModified = true;
490 catch(const css::uno::Exception& ex)
492 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
496 void SvtAccessibilityOptions_Impl::SetSelectionInReadonly(bool bSet)
498 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
502 if(xNode.is() && xNode->getPropertyValue(s_sIsSelectionInReadonly)!=bSet)
504 xNode->setPropertyValue(s_sIsSelectionInReadonly, css::uno::makeAny(bSet));
505 ::comphelper::ConfigurationHelper::flush(m_xCfg);
507 bIsModified = true;
510 catch(const css::uno::Exception& ex)
512 SAL_WARN("svtools.config", "Caught unexpected: " << ex.Message);
516 void SvtAccessibilityOptions_Impl::SetVCLSettings()
518 AllSettings aAllSettings(Application::GetSettings());
519 StyleSettings aStyleSettings(aAllSettings.GetStyleSettings());
520 HelpSettings aHelpSettings(aAllSettings.GetHelpSettings());
521 bool StyleSettingsChanged(false);
523 aHelpSettings.SetTipTimeout( GetIsHelpTipsDisappear() ? GetHelpTipSeconds() * 1000 : HELP_TIP_TIMEOUT);
524 aAllSettings.SetHelpSettings(aHelpSettings);
526 const sal_Int16 nEdgeBlendingCountA(GetEdgeBlending());
527 OSL_ENSURE(nEdgeBlendingCountA >= 0, "OOps, negative values for EdgeBlending are not allowed (!)");
528 const sal_uInt16 nEdgeBlendingCountB(static_cast< sal_uInt16 >(nEdgeBlendingCountA >= 0 ? nEdgeBlendingCountA : 0));
530 if(aStyleSettings.GetEdgeBlending() != nEdgeBlendingCountB)
532 aStyleSettings.SetEdgeBlending(nEdgeBlendingCountB);
533 StyleSettingsChanged = true;
536 const sal_Int16 nMaxLineCountA(GetListBoxMaximumLineCount());
537 OSL_ENSURE(nMaxLineCountA >= 0, "OOps, negative values for ListBoxMaximumLineCount are not allowed (!)");
538 const sal_uInt16 nMaxLineCountB(static_cast< sal_uInt16 >(nMaxLineCountA >= 0 ? nMaxLineCountA : 0));
540 if(aStyleSettings.GetListBoxMaximumLineCount() != nMaxLineCountB)
542 aStyleSettings.SetListBoxMaximumLineCount(nMaxLineCountB);
543 StyleSettingsChanged = true;
546 const sal_Int16 nMaxColumnCountA(GetColorValueSetColumnCount());
547 OSL_ENSURE(nMaxColumnCountA >= 0, "OOps, negative values for ColorValueSetColumnCount are not allowed (!)");
548 const sal_uInt16 nMaxColumnCountB(static_cast< sal_uInt16 >(nMaxColumnCountA >= 0 ? nMaxColumnCountA : 0));
550 if(aStyleSettings.GetColorValueSetColumnCount() != nMaxColumnCountB)
552 aStyleSettings.SetColorValueSetColumnCount(nMaxColumnCountB);
553 StyleSettingsChanged = true;
556 const bool bPreviewUsesCheckeredBackground(GetPreviewUsesCheckeredBackground());
558 if(aStyleSettings.GetPreviewUsesCheckeredBackground() != bPreviewUsesCheckeredBackground)
560 aStyleSettings.SetPreviewUsesCheckeredBackground(bPreviewUsesCheckeredBackground);
561 StyleSettingsChanged = true;
564 if(StyleSettingsChanged)
566 aAllSettings.SetStyleSettings(aStyleSettings);
567 Application::MergeSystemSettings(aAllSettings);
570 Application::SetSettings(aAllSettings);
573 // class SvtAccessibilityOptions --------------------------------------------------
575 SvtAccessibilityOptions::SvtAccessibilityOptions()
578 ::osl::MutexGuard aGuard( SingletonMutex::get() );
579 if(!sm_pSingleImplConfig)
581 sm_pSingleImplConfig = new SvtAccessibilityOptions_Impl;
582 svtools::ItemHolder2::holdConfigItem(E_ACCESSIBILITYOPTIONS);
584 ++sm_nAccessibilityRefCount;
586 //StartListening( *sm_pSingleImplConfig, sal_True );
591 SvtAccessibilityOptions::~SvtAccessibilityOptions()
593 //EndListening( *sm_pSingleImplConfig, sal_True );
594 ::osl::MutexGuard aGuard( SingletonMutex::get() );
595 if( !--sm_nAccessibilityRefCount )
597 //if( sm_pSingleImplConfig->IsModified() )
598 // sm_pSingleImplConfig->Commit();
599 DELETEZ( sm_pSingleImplConfig );
605 void SvtAccessibilityOptions::Notify( SfxBroadcaster&, const SfxHint& rHint )
607 NotifyListeners(0);
608 const SfxSimpleHint* pSfxSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
609 if ( pSfxSimpleHint )
611 if ( pSfxSimpleHint->GetId() == SFX_HINT_ACCESSIBILITY_CHANGED )
612 SetVCLSettings();
618 bool SvtAccessibilityOptions::IsModified() const
620 return sm_pSingleImplConfig->IsModified();
623 bool SvtAccessibilityOptions::GetAutoDetectSystemHC() const
625 return sm_pSingleImplConfig->GetAutoDetectSystemHC();
627 bool SvtAccessibilityOptions::GetIsForPagePreviews() const
629 return sm_pSingleImplConfig->GetIsForPagePreviews();
631 bool SvtAccessibilityOptions::GetIsHelpTipsDisappear() const
633 return sm_pSingleImplConfig->GetIsHelpTipsDisappear();
635 bool SvtAccessibilityOptions::GetIsAllowAnimatedGraphics() const
637 return sm_pSingleImplConfig->GetIsAllowAnimatedGraphics();
639 bool SvtAccessibilityOptions::GetIsAllowAnimatedText() const
641 return sm_pSingleImplConfig->GetIsAllowAnimatedText();
643 bool SvtAccessibilityOptions::GetIsAutomaticFontColor() const
645 return sm_pSingleImplConfig->GetIsAutomaticFontColor();
647 sal_Int16 SvtAccessibilityOptions::GetHelpTipSeconds() const
649 return sm_pSingleImplConfig->GetHelpTipSeconds();
651 bool SvtAccessibilityOptions::IsSelectionInReadonly() const
653 return sm_pSingleImplConfig->IsSelectionInReadonly();
657 void SvtAccessibilityOptions::SetAutoDetectSystemHC(bool bSet)
659 sm_pSingleImplConfig->SetAutoDetectSystemHC(bSet);
661 void SvtAccessibilityOptions::SetIsForPagePreviews(bool bSet)
663 sm_pSingleImplConfig->SetIsForPagePreviews(bSet);
665 void SvtAccessibilityOptions::SetIsHelpTipsDisappear(bool bSet)
667 sm_pSingleImplConfig->SetIsHelpTipsDisappear(bSet);
669 void SvtAccessibilityOptions::SetIsAllowAnimatedGraphics(bool bSet)
671 sm_pSingleImplConfig->SetIsAllowAnimatedGraphics(bSet);
673 void SvtAccessibilityOptions::SetIsAllowAnimatedText(bool bSet)
675 sm_pSingleImplConfig->SetIsAllowAnimatedText(bSet);
677 void SvtAccessibilityOptions::SetIsAutomaticFontColor(bool bSet)
679 sm_pSingleImplConfig->SetIsAutomaticFontColor(bSet);
681 void SvtAccessibilityOptions::SetHelpTipSeconds(sal_Int16 nSet)
683 sm_pSingleImplConfig->SetHelpTipSeconds(nSet);
685 void SvtAccessibilityOptions::SetSelectionInReadonly(bool bSet)
687 sm_pSingleImplConfig->SetSelectionInReadonly(bSet);
689 void SvtAccessibilityOptions::SetVCLSettings()
691 sm_pSingleImplConfig->SetVCLSettings();
696 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */