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 <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"
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
48 css::uno::Reference
< css::container::XNameAccess
> m_xCfg
;
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);
75 : public rtl::Static
< ::osl::Mutex
, SingletonMutex
> {};
79 // class SvtAccessibilityOptions_Impl ---------------------------------------------
81 SvtAccessibilityOptions_Impl::SvtAccessibilityOptions_Impl()
86 ::comphelper::ConfigurationHelper::openConfig(
87 comphelper::getProcessComponentContext(),
88 "org.openoffice.Office.Common/Accessibility",
89 ::comphelper::EConfigurationModes::Standard
),
92 catch(const css::uno::Exception
&)
94 DBG_UNHANDLED_EXCEPTION("svtools.config");
99 bool SvtAccessibilityOptions_Impl::GetIsForPagePreviews() const
101 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
107 xNode
->getPropertyValue("IsForPagePreviews") >>= bRet
;
109 catch(const css::uno::Exception
&)
111 DBG_UNHANDLED_EXCEPTION("svtools.config");
116 bool SvtAccessibilityOptions_Impl::GetIsHelpTipsDisappear() const
118 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
124 xNode
->getPropertyValue("IsHelpTipsDisappear") >>= bRet
;
126 catch(const css::uno::Exception
&)
128 DBG_UNHANDLED_EXCEPTION("svtools.config");
134 bool SvtAccessibilityOptions_Impl::GetIsAllowAnimatedGraphics() const
136 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
142 xNode
->getPropertyValue("IsAllowAnimatedGraphics") >>= bRet
;
144 catch(const css::uno::Exception
&)
146 DBG_UNHANDLED_EXCEPTION("svtools.config");
152 bool SvtAccessibilityOptions_Impl::GetIsAllowAnimatedText() const
154 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
160 xNode
->getPropertyValue("IsAllowAnimatedText") >>= bRet
;
162 catch(const css::uno::Exception
&)
164 DBG_UNHANDLED_EXCEPTION("svtools.config");
170 bool SvtAccessibilityOptions_Impl::GetIsAutomaticFontColor() const
172 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
178 xNode
->getPropertyValue("IsAutomaticFontColor") >>= bRet
;
180 catch(const css::uno::Exception
&)
182 DBG_UNHANDLED_EXCEPTION("svtools.config");
188 sal_Int16
SvtAccessibilityOptions_Impl::GetHelpTipSeconds() const
190 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
196 xNode
->getPropertyValue("HelpTipSeconds") >>= nRet
;
198 catch(const css::uno::Exception
&)
200 DBG_UNHANDLED_EXCEPTION("svtools.config");
206 bool SvtAccessibilityOptions_Impl::IsSelectionInReadonly() const
208 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
214 xNode
->getPropertyValue("IsSelectionInReadonly") >>= bRet
;
216 catch(const css::uno::Exception
&)
218 DBG_UNHANDLED_EXCEPTION("svtools.config");
224 sal_Int16
SvtAccessibilityOptions_Impl::GetEdgeBlending() const
226 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
232 xNode
->getPropertyValue("EdgeBlending") >>= nRet
;
234 catch(const css::uno::Exception
&)
236 DBG_UNHANDLED_EXCEPTION("svtools.config");
242 sal_Int16
SvtAccessibilityOptions_Impl::GetListBoxMaximumLineCount() const
244 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
250 xNode
->getPropertyValue("ListBoxMaximumLineCount") >>= nRet
;
252 catch(const css::uno::Exception
&)
254 DBG_UNHANDLED_EXCEPTION("svtools.config");
260 sal_Int16
SvtAccessibilityOptions_Impl::GetColorValueSetColumnCount() const
265 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
271 xNode
->getPropertyValue("ColorValueSetColumnCount") >>= nRet
;
273 catch(const css::uno::Exception
&)
275 DBG_UNHANDLED_EXCEPTION("svtools.config");
282 bool SvtAccessibilityOptions_Impl::GetPreviewUsesCheckeredBackground() const
284 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
290 xNode
->getPropertyValue("PreviewUsesCheckeredBackground") >>= bRet
;
292 catch(const css::uno::Exception
&)
294 DBG_UNHANDLED_EXCEPTION("svtools.config");
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: */