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 <comphelper/diagnose_ex.hxx>
34 #include <officecfg/Office/Common.hxx>
38 #include "itemholder2.hxx"
41 using namespace com::sun::star::uno
;
43 #define HELP_TIP_TIMEOUT 0xffff // max. timeout setting to pretend a non-timeout
45 // class SvtAccessibilityOptions_Impl ---------------------------------------------
47 class SvtAccessibilityOptions_Impl
50 css::uno::Reference
< css::container::XNameAccess
> m_xCfg
;
51 css::uno::Reference
< css::beans::XPropertySet
> m_xNode
;
54 SvtAccessibilityOptions_Impl();
57 // initialization of static members --------------------------------------
59 SvtAccessibilityOptions_Impl
* SvtAccessibilityOptions::sm_pSingleImplConfig
=nullptr;
60 sal_Int32
SvtAccessibilityOptions::sm_nAccessibilityRefCount(0);
64 std::mutex
& SingletonMutex()
66 static std::mutex SINGLETON
;
72 // class SvtAccessibilityOptions_Impl ---------------------------------------------
74 SvtAccessibilityOptions_Impl::SvtAccessibilityOptions_Impl()
79 ::comphelper::ConfigurationHelper::openConfig(
80 comphelper::getProcessComponentContext(),
81 "org.openoffice.Office.Common/Accessibility",
82 ::comphelper::EConfigurationModes::Standard
),
84 m_xNode
.set(m_xCfg
, css::uno::UNO_QUERY
);
86 catch(const css::uno::Exception
&)
88 DBG_UNHANDLED_EXCEPTION("svtools.config");
93 void SvtAccessibilityOptions::SetVCLSettings()
95 AllSettings
aAllSettings(Application::GetSettings());
96 StyleSettings
aStyleSettings(aAllSettings
.GetStyleSettings());
97 HelpSettings
aHelpSettings(aAllSettings
.GetHelpSettings());
98 bool StyleSettingsChanged(false);
100 bool bHelpTipsDisappear
= officecfg::Office::Common::Accessibility::IsHelpTipsDisappear::get();
101 sal_Int16 nHelpTipSeconds
= officecfg::Office::Common::Accessibility::HelpTipSeconds::get();
102 aHelpSettings
.SetTipTimeout( bHelpTipsDisappear
? nHelpTipSeconds
* 1000 : HELP_TIP_TIMEOUT
);
103 aAllSettings
.SetHelpSettings(aHelpSettings
);
105 std::optional
<sal_Int16
> nEdgeBlendingCount(officecfg::Office::Common::Accessibility::EdgeBlending::get());
106 if (!nEdgeBlendingCount
)
107 nEdgeBlendingCount
= 35;
108 OSL_ENSURE(*nEdgeBlendingCount
>= 0, "OOps, negative values for EdgeBlending are not allowed (!)");
109 if (*nEdgeBlendingCount
< 0)
110 nEdgeBlendingCount
= 0;
112 if(aStyleSettings
.GetEdgeBlending() != *nEdgeBlendingCount
)
114 aStyleSettings
.SetEdgeBlending(*nEdgeBlendingCount
);
115 StyleSettingsChanged
= true;
118 std::optional
<sal_Int16
> nMaxLineCount(officecfg::Office::Common::Accessibility::ListBoxMaximumLineCount::get());
121 OSL_ENSURE(*nMaxLineCount
>= 0, "OOps, negative values for ListBoxMaximumLineCount are not allowed (!)");
122 if (*nMaxLineCount
< 0)
125 if(aStyleSettings
.GetListBoxMaximumLineCount() != *nMaxLineCount
)
127 aStyleSettings
.SetListBoxMaximumLineCount(*nMaxLineCount
);
128 StyleSettingsChanged
= true;
132 std::optional
<sal_Int16
> nMaxColumnCount
= 4;
134 std::optional
<sal_Int16
> nMaxColumnCount(officecfg::Office::Common::Accessibility::ColorValueSetColumnCount::get());
135 if (!nMaxColumnCount
)
136 nMaxColumnCount
= 12;
139 OSL_ENSURE(*nMaxColumnCount
>= 0, "OOps, negative values for ColorValueSetColumnCount are not allowed (!)");
140 if (*nMaxColumnCount
< 0)
143 if(aStyleSettings
.GetColorValueSetColumnCount() != *nMaxColumnCount
)
145 aStyleSettings
.SetColorValueSetColumnCount(*nMaxColumnCount
);
146 StyleSettingsChanged
= true;
149 std::optional
<bool> bTmp
= officecfg::Office::Common::Accessibility::PreviewUsesCheckeredBackground::get();
150 const bool bPreviewUsesCheckeredBackground
= bTmp
.value_or(false);
152 if(aStyleSettings
.GetPreviewUsesCheckeredBackground() != bPreviewUsesCheckeredBackground
)
154 aStyleSettings
.SetPreviewUsesCheckeredBackground(bPreviewUsesCheckeredBackground
);
155 StyleSettingsChanged
= true;
158 if(StyleSettingsChanged
)
160 aAllSettings
.SetStyleSettings(aStyleSettings
);
161 Application::MergeSystemSettings(aAllSettings
);
164 Application::SetSettings(aAllSettings
);
167 // class SvtAccessibilityOptions --------------------------------------------------
169 SvtAccessibilityOptions::SvtAccessibilityOptions()
171 if (!utl::ConfigManager::IsFuzzing())
173 std::unique_lock
aGuard( SingletonMutex() );
174 if(!sm_pSingleImplConfig
)
176 sm_pSingleImplConfig
= new SvtAccessibilityOptions_Impl
;
177 aGuard
.unlock(); // because holdConfigItem will call this constructor
178 svtools::ItemHolder2::holdConfigItem(EItem::AccessibilityOptions
);
180 ++sm_nAccessibilityRefCount
;
182 //StartListening( *sm_pSingleImplConfig, sal_True );
185 SvtAccessibilityOptions::~SvtAccessibilityOptions()
187 //EndListening( *sm_pSingleImplConfig, sal_True );
188 std::unique_lock
aGuard( SingletonMutex() );
189 if( !--sm_nAccessibilityRefCount
)
191 //if( sm_pSingleImplConfig->IsModified() )
192 // sm_pSingleImplConfig->Commit();
193 delete sm_pSingleImplConfig
;
194 sm_pSingleImplConfig
= nullptr;
197 bool SvtAccessibilityOptions::GetIsAllowAnimatedGraphics()
199 return officecfg::Office::Common::Accessibility::IsAllowAnimatedGraphics::get();
201 bool SvtAccessibilityOptions::GetIsAllowAnimatedText()
203 return officecfg::Office::Common::Accessibility::IsAllowAnimatedText::get();
205 bool SvtAccessibilityOptions::GetIsAutomaticFontColor()
207 return officecfg::Office::Common::Accessibility::IsAutomaticFontColor::get();
209 bool SvtAccessibilityOptions::IsSelectionInReadonly()
211 return officecfg::Office::Common::Accessibility::IsSelectionInReadonly::get();
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */