nss: upgrade to release 3.73
[LibreOffice.git] / svtools / source / config / accessibilityoptions.cxx
blob2790296c424d0bcafc581e69f52ba213379a9786
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>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/container/XNameAccess.hpp>
28 #include <comphelper/configurationhelper.hxx>
29 #include <comphelper/processfactory.hxx>
31 #include <vcl/settings.hxx>
32 #include <vcl/svapp.hxx>
33 #include <rtl/instance.hxx>
34 #include <tools/diagnose_ex.h>
36 #include "itemholder2.hxx"
38 using namespace utl;
39 using namespace com::sun::star::uno;
41 #define HELP_TIP_TIMEOUT 0xffff // max. timeout setting to pretend a non-timeout
43 // class SvtAccessibilityOptions_Impl ---------------------------------------------
45 class SvtAccessibilityOptions_Impl
47 private:
48 css::uno::Reference< css::container::XNameAccess > m_xCfg;
50 public:
51 SvtAccessibilityOptions_Impl();
53 void SetVCLSettings();
54 bool GetIsForPagePreviews() const;
55 bool GetIsHelpTipsDisappear() const;
56 bool GetIsAllowAnimatedGraphics() const;
57 bool GetIsAllowAnimatedText() const;
58 bool GetIsAutomaticFontColor() const;
59 sal_Int16 GetHelpTipSeconds() const;
60 bool IsSelectionInReadonly() const;
61 sal_Int16 GetEdgeBlending() const;
62 sal_Int16 GetListBoxMaximumLineCount() const;
63 sal_Int16 GetColorValueSetColumnCount() const;
64 bool GetPreviewUsesCheckeredBackground() const;
67 // initialization of static members --------------------------------------
69 SvtAccessibilityOptions_Impl* SvtAccessibilityOptions::sm_pSingleImplConfig =nullptr;
70 sal_Int32 SvtAccessibilityOptions::sm_nAccessibilityRefCount(0);
72 namespace
74 struct SingletonMutex
75 : public rtl::Static< ::osl::Mutex, SingletonMutex > {};
79 // class SvtAccessibilityOptions_Impl ---------------------------------------------
81 SvtAccessibilityOptions_Impl::SvtAccessibilityOptions_Impl()
83 try
85 m_xCfg.set(
86 ::comphelper::ConfigurationHelper::openConfig(
87 comphelper::getProcessComponentContext(),
88 "org.openoffice.Office.Common/Accessibility",
89 ::comphelper::EConfigurationModes::Standard ),
90 css::uno::UNO_QUERY);
92 catch(const css::uno::Exception&)
94 DBG_UNHANDLED_EXCEPTION("svtools.config");
95 m_xCfg.clear();
99 bool SvtAccessibilityOptions_Impl::GetIsForPagePreviews() const
101 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
102 bool bRet = true;
106 if(xNode.is())
107 xNode->getPropertyValue("IsForPagePreviews") >>= bRet;
109 catch(const css::uno::Exception&)
111 DBG_UNHANDLED_EXCEPTION("svtools.config");
113 return bRet;
116 bool SvtAccessibilityOptions_Impl::GetIsHelpTipsDisappear() const
118 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
119 bool bRet = true;
123 if(xNode.is())
124 xNode->getPropertyValue("IsHelpTipsDisappear") >>= bRet;
126 catch(const css::uno::Exception&)
128 DBG_UNHANDLED_EXCEPTION("svtools.config");
131 return bRet;
134 bool SvtAccessibilityOptions_Impl::GetIsAllowAnimatedGraphics() const
136 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
137 bool bRet = true;
141 if(xNode.is())
142 xNode->getPropertyValue("IsAllowAnimatedGraphics") >>= bRet;
144 catch(const css::uno::Exception&)
146 DBG_UNHANDLED_EXCEPTION("svtools.config");
149 return bRet;
152 bool SvtAccessibilityOptions_Impl::GetIsAllowAnimatedText() const
154 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
155 bool bRet = true;
159 if(xNode.is())
160 xNode->getPropertyValue("IsAllowAnimatedText") >>= bRet;
162 catch(const css::uno::Exception&)
164 DBG_UNHANDLED_EXCEPTION("svtools.config");
167 return bRet;
170 bool SvtAccessibilityOptions_Impl::GetIsAutomaticFontColor() const
172 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
173 bool bRet = false;
177 if(xNode.is())
178 xNode->getPropertyValue("IsAutomaticFontColor") >>= bRet;
180 catch(const css::uno::Exception&)
182 DBG_UNHANDLED_EXCEPTION("svtools.config");
185 return bRet;
188 sal_Int16 SvtAccessibilityOptions_Impl::GetHelpTipSeconds() const
190 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
191 sal_Int16 nRet = 4;
195 if(xNode.is())
196 xNode->getPropertyValue("HelpTipSeconds") >>= nRet;
198 catch(const css::uno::Exception&)
200 DBG_UNHANDLED_EXCEPTION("svtools.config");
203 return nRet;
206 bool SvtAccessibilityOptions_Impl::IsSelectionInReadonly() const
208 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
209 bool bRet = false;
213 if(xNode.is())
214 xNode->getPropertyValue("IsSelectionInReadonly") >>= bRet;
216 catch(const css::uno::Exception&)
218 DBG_UNHANDLED_EXCEPTION("svtools.config");
221 return bRet;
224 sal_Int16 SvtAccessibilityOptions_Impl::GetEdgeBlending() const
226 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
227 sal_Int16 nRet = 35;
231 if(xNode.is())
232 xNode->getPropertyValue("EdgeBlending") >>= nRet;
234 catch(const css::uno::Exception&)
236 DBG_UNHANDLED_EXCEPTION("svtools.config");
239 return nRet;
242 sal_Int16 SvtAccessibilityOptions_Impl::GetListBoxMaximumLineCount() const
244 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
245 sal_Int16 nRet = 25;
249 if(xNode.is())
250 xNode->getPropertyValue("ListBoxMaximumLineCount") >>= nRet;
252 catch(const css::uno::Exception&)
254 DBG_UNHANDLED_EXCEPTION("svtools.config");
257 return nRet;
260 sal_Int16 SvtAccessibilityOptions_Impl::GetColorValueSetColumnCount() const
262 #ifdef IOS
263 return 4;
264 #else
265 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
266 sal_Int16 nRet = 12;
270 if(xNode.is())
271 xNode->getPropertyValue("ColorValueSetColumnCount") >>= nRet;
273 catch(const css::uno::Exception&)
275 DBG_UNHANDLED_EXCEPTION("svtools.config");
278 return nRet;
279 #endif
282 bool SvtAccessibilityOptions_Impl::GetPreviewUsesCheckeredBackground() const
284 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
285 bool bRet = false;
289 if(xNode.is())
290 xNode->getPropertyValue("PreviewUsesCheckeredBackground") >>= bRet;
292 catch(const css::uno::Exception&)
294 DBG_UNHANDLED_EXCEPTION("svtools.config");
297 return bRet;
300 void SvtAccessibilityOptions_Impl::SetVCLSettings()
302 AllSettings aAllSettings(Application::GetSettings());
303 StyleSettings aStyleSettings(aAllSettings.GetStyleSettings());
304 HelpSettings aHelpSettings(aAllSettings.GetHelpSettings());
305 bool StyleSettingsChanged(false);
307 aHelpSettings.SetTipTimeout( GetIsHelpTipsDisappear() ? GetHelpTipSeconds() * 1000 : HELP_TIP_TIMEOUT);
308 aAllSettings.SetHelpSettings(aHelpSettings);
310 const sal_Int16 nEdgeBlendingCountA(GetEdgeBlending());
311 OSL_ENSURE(nEdgeBlendingCountA >= 0, "OOps, negative values for EdgeBlending are not allowed (!)");
312 const sal_uInt16 nEdgeBlendingCountB(static_cast< sal_uInt16 >(nEdgeBlendingCountA >= 0 ? nEdgeBlendingCountA : 0));
314 if(aStyleSettings.GetEdgeBlending() != nEdgeBlendingCountB)
316 aStyleSettings.SetEdgeBlending(nEdgeBlendingCountB);
317 StyleSettingsChanged = true;
320 const sal_Int16 nMaxLineCountA(GetListBoxMaximumLineCount());
321 OSL_ENSURE(nMaxLineCountA >= 0, "OOps, negative values for ListBoxMaximumLineCount are not allowed (!)");
322 const sal_uInt16 nMaxLineCountB(static_cast< sal_uInt16 >(nMaxLineCountA >= 0 ? nMaxLineCountA : 0));
324 if(aStyleSettings.GetListBoxMaximumLineCount() != nMaxLineCountB)
326 aStyleSettings.SetListBoxMaximumLineCount(nMaxLineCountB);
327 StyleSettingsChanged = true;
330 const sal_Int16 nMaxColumnCountA(GetColorValueSetColumnCount());
331 OSL_ENSURE(nMaxColumnCountA >= 0, "OOps, negative values for ColorValueSetColumnCount are not allowed (!)");
332 const sal_uInt16 nMaxColumnCountB(static_cast< sal_uInt16 >(nMaxColumnCountA >= 0 ? nMaxColumnCountA : 0));
334 if(aStyleSettings.GetColorValueSetColumnCount() != nMaxColumnCountB)
336 aStyleSettings.SetColorValueSetColumnCount(nMaxColumnCountB);
337 StyleSettingsChanged = true;
340 const bool bPreviewUsesCheckeredBackground(GetPreviewUsesCheckeredBackground());
342 if(aStyleSettings.GetPreviewUsesCheckeredBackground() != bPreviewUsesCheckeredBackground)
344 aStyleSettings.SetPreviewUsesCheckeredBackground(bPreviewUsesCheckeredBackground);
345 StyleSettingsChanged = true;
348 if(StyleSettingsChanged)
350 aAllSettings.SetStyleSettings(aStyleSettings);
351 Application::MergeSystemSettings(aAllSettings);
354 Application::SetSettings(aAllSettings);
357 // class SvtAccessibilityOptions --------------------------------------------------
359 SvtAccessibilityOptions::SvtAccessibilityOptions()
361 if (!utl::ConfigManager::IsFuzzing())
363 ::osl::MutexGuard aGuard( SingletonMutex::get() );
364 if(!sm_pSingleImplConfig)
366 sm_pSingleImplConfig = new SvtAccessibilityOptions_Impl;
367 svtools::ItemHolder2::holdConfigItem(EItem::AccessibilityOptions);
369 ++sm_nAccessibilityRefCount;
371 //StartListening( *sm_pSingleImplConfig, sal_True );
374 SvtAccessibilityOptions::~SvtAccessibilityOptions()
376 //EndListening( *sm_pSingleImplConfig, sal_True );
377 ::osl::MutexGuard aGuard( SingletonMutex::get() );
378 if( !--sm_nAccessibilityRefCount )
380 //if( sm_pSingleImplConfig->IsModified() )
381 // sm_pSingleImplConfig->Commit();
382 delete sm_pSingleImplConfig;
383 sm_pSingleImplConfig = nullptr;
387 bool SvtAccessibilityOptions::GetIsForPagePreviews() const
389 return sm_pSingleImplConfig->GetIsForPagePreviews();
391 bool SvtAccessibilityOptions::GetIsAllowAnimatedGraphics() const
393 return sm_pSingleImplConfig->GetIsAllowAnimatedGraphics();
395 bool SvtAccessibilityOptions::GetIsAllowAnimatedText() const
397 return sm_pSingleImplConfig->GetIsAllowAnimatedText();
399 bool SvtAccessibilityOptions::GetIsAutomaticFontColor() const
401 return sm_pSingleImplConfig->GetIsAutomaticFontColor();
403 bool SvtAccessibilityOptions::IsSelectionInReadonly() const
405 return sm_pSingleImplConfig->IsSelectionInReadonly();
409 void SvtAccessibilityOptions::SetVCLSettings()
411 sm_pSingleImplConfig->SetVCLSettings();
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */