1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21 #include <svtools/accessibilityoptions.hxx>
22
23 #include <unotools/configmgr.hxx>
24 #include <com/sun/star/uno/Any.hxx>
25
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>
30
31 #include <svl/hint.hxx>
32
33 #include <vcl/settings.hxx>
34 #include <vcl/svapp.hxx>
35 #include <rtl/instance.hxx>
36 #include <tools/diagnose_ex.h>
37
38 #include "itemholder2.hxx"
39
40 using namespace utl;
41 using namespace com::sun::star::uno;
42
43 #define HELP_TIP_TIMEOUT 0xffff // max. timeout setting to pretend a non-timeout
44
45 // class SvtAccessibilityOptions_Impl ---------------------------------------------
46
47 class SvtAccessibilityOptions_Impl
48 {
49 private:
50 css::uno::Reference< css::container::XNameAccess > m_xCfg;
51
52 public:
53 SvtAccessibilityOptions_Impl();
54
55 void SetVCLSettings();
56 bool GetIsForPagePreviews() const;
57 bool GetIsHelpTipsDisappear() const;
58 bool GetIsAllowAnimatedGraphics() const;
59 bool GetIsAllowAnimatedText() const;
60 bool GetIsAutomaticFontColor() const;
61 sal_Int16 GetHelpTipSeconds() const;
62 bool IsSelectionInReadonly() const;
63 sal_Int16 GetEdgeBlending() const;
64 sal_Int16 GetListBoxMaximumLineCount() const;
65 sal_Int16 GetColorValueSetColumnCount() const;
66 bool GetPreviewUsesCheckeredBackground() const;
67 };
68
69 // initialization of static members --------------------------------------
70
71 SvtAccessibilityOptions_Impl* SvtAccessibilityOptions::sm_pSingleImplConfig =nullptr;
72 sal_Int32 SvtAccessibilityOptions::sm_nAccessibilityRefCount(0);
73
74 namespace
75 {
76 struct SingletonMutex
77 : public rtl::Static< ::osl::Mutex, SingletonMutex > {};
78 }
79
80
81 // class SvtAccessibilityOptions_Impl ---------------------------------------------
82
SvtAccessibilityOptions_Impl()83 SvtAccessibilityOptions_Impl::SvtAccessibilityOptions_Impl()
84 {
85 try
86 {
87 m_xCfg.set(
88 ::comphelper::ConfigurationHelper::openConfig(
89 comphelper::getProcessComponentContext(),
90 "org.openoffice.Office.Common/Accessibility",
91 ::comphelper::EConfigurationModes::Standard ),
92 css::uno::UNO_QUERY);
93 }
94 catch(const css::uno::Exception&)
95 {
96 DBG_UNHANDLED_EXCEPTION("svtools.config");
97 m_xCfg.clear();
98 }
99 }
100
GetIsForPagePreviews() const101 bool SvtAccessibilityOptions_Impl::GetIsForPagePreviews() const
102 {
103 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
104 bool bRet = true;
105
106 try
107 {
108 if(xNode.is())
109 xNode->getPropertyValue("IsForPagePreviews") >>= bRet;
110 }
111 catch(const css::uno::Exception&)
112 {
113 DBG_UNHANDLED_EXCEPTION("svtools.config");
114 }
115 return bRet;
116 }
117
GetIsHelpTipsDisappear() const118 bool SvtAccessibilityOptions_Impl::GetIsHelpTipsDisappear() const
119 {
120 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
121 bool bRet = true;
122
123 try
124 {
125 if(xNode.is())
126 xNode->getPropertyValue("IsHelpTipsDisappear") >>= bRet;
127 }
128 catch(const css::uno::Exception&)
129 {
130 DBG_UNHANDLED_EXCEPTION("svtools.config");
131 }
132
133 return bRet;
134 }
135
GetIsAllowAnimatedGraphics() const136 bool SvtAccessibilityOptions_Impl::GetIsAllowAnimatedGraphics() const
137 {
138 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
139 bool bRet = true;
140
141 try
142 {
143 if(xNode.is())
144 xNode->getPropertyValue("IsAllowAnimatedGraphics") >>= bRet;
145 }
146 catch(const css::uno::Exception&)
147 {
148 DBG_UNHANDLED_EXCEPTION("svtools.config");
149 }
150
151 return bRet;
152 }
153
GetIsAllowAnimatedText() const154 bool SvtAccessibilityOptions_Impl::GetIsAllowAnimatedText() const
155 {
156 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
157 bool bRet = true;
158
159 try
160 {
161 if(xNode.is())
162 xNode->getPropertyValue("IsAllowAnimatedText") >>= bRet;
163 }
164 catch(const css::uno::Exception&)
165 {
166 DBG_UNHANDLED_EXCEPTION("svtools.config");
167 }
168
169 return bRet;
170 }
171
GetIsAutomaticFontColor() const172 bool SvtAccessibilityOptions_Impl::GetIsAutomaticFontColor() const
173 {
174 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
175 bool bRet = false;
176
177 try
178 {
179 if(xNode.is())
180 xNode->getPropertyValue("IsAutomaticFontColor") >>= bRet;
181 }
182 catch(const css::uno::Exception&)
183 {
184 DBG_UNHANDLED_EXCEPTION("svtools.config");
185 }
186
187 return bRet;
188 }
189
GetHelpTipSeconds() const190 sal_Int16 SvtAccessibilityOptions_Impl::GetHelpTipSeconds() const
191 {
192 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
193 sal_Int16 nRet = 4;
194
195 try
196 {
197 if(xNode.is())
198 xNode->getPropertyValue("HelpTipSeconds") >>= nRet;
199 }
200 catch(const css::uno::Exception&)
201 {
202 DBG_UNHANDLED_EXCEPTION("svtools.config");
203 }
204
205 return nRet;
206 }
207
IsSelectionInReadonly() const208 bool SvtAccessibilityOptions_Impl::IsSelectionInReadonly() const
209 {
210 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
211 bool bRet = false;
212
213 try
214 {
215 if(xNode.is())
216 xNode->getPropertyValue("IsSelectionInReadonly") >>= bRet;
217 }
218 catch(const css::uno::Exception&)
219 {
220 DBG_UNHANDLED_EXCEPTION("svtools.config");
221 }
222
223 return bRet;
224 }
225
GetEdgeBlending() const226 sal_Int16 SvtAccessibilityOptions_Impl::GetEdgeBlending() const
227 {
228 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
229 sal_Int16 nRet = 35;
230
231 try
232 {
233 if(xNode.is())
234 xNode->getPropertyValue("EdgeBlending") >>= nRet;
235 }
236 catch(const css::uno::Exception&)
237 {
238 DBG_UNHANDLED_EXCEPTION("svtools.config");
239 }
240
241 return nRet;
242 }
243
GetListBoxMaximumLineCount() const244 sal_Int16 SvtAccessibilityOptions_Impl::GetListBoxMaximumLineCount() const
245 {
246 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
247 sal_Int16 nRet = 25;
248
249 try
250 {
251 if(xNode.is())
252 xNode->getPropertyValue("ListBoxMaximumLineCount") >>= nRet;
253 }
254 catch(const css::uno::Exception&)
255 {
256 DBG_UNHANDLED_EXCEPTION("svtools.config");
257 }
258
259 return nRet;
260 }
261
GetColorValueSetColumnCount() const262 sal_Int16 SvtAccessibilityOptions_Impl::GetColorValueSetColumnCount() const
263 {
264 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
265 sal_Int16 nRet = 12;
266
267 try
268 {
269 if(xNode.is())
270 xNode->getPropertyValue("ColorValueSetColumnCount") >>= nRet;
271 }
272 catch(const css::uno::Exception&)
273 {
274 DBG_UNHANDLED_EXCEPTION("svtools.config");
275 }
276
277 return nRet;
278 }
279
GetPreviewUsesCheckeredBackground() const280 bool SvtAccessibilityOptions_Impl::GetPreviewUsesCheckeredBackground() const
281 {
282 css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
283 bool bRet = false;
284
285 try
286 {
287 if(xNode.is())
288 xNode->getPropertyValue("PreviewUsesCheckeredBackground") >>= bRet;
289 }
290 catch(const css::uno::Exception&)
291 {
292 DBG_UNHANDLED_EXCEPTION("svtools.config");
293 }
294
295 return bRet;
296 }
297
SetVCLSettings()298 void SvtAccessibilityOptions_Impl::SetVCLSettings()
299 {
300 AllSettings aAllSettings(Application::GetSettings());
301 StyleSettings aStyleSettings(aAllSettings.GetStyleSettings());
302 HelpSettings aHelpSettings(aAllSettings.GetHelpSettings());
303 bool StyleSettingsChanged(false);
304
305 aHelpSettings.SetTipTimeout( GetIsHelpTipsDisappear() ? GetHelpTipSeconds() * 1000 : HELP_TIP_TIMEOUT);
306 aAllSettings.SetHelpSettings(aHelpSettings);
307
308 const sal_Int16 nEdgeBlendingCountA(GetEdgeBlending());
309 OSL_ENSURE(nEdgeBlendingCountA >= 0, "OOps, negative values for EdgeBlending are not allowed (!)");
310 const sal_uInt16 nEdgeBlendingCountB(static_cast< sal_uInt16 >(nEdgeBlendingCountA >= 0 ? nEdgeBlendingCountA : 0));
311
312 if(aStyleSettings.GetEdgeBlending() != nEdgeBlendingCountB)
313 {
314 aStyleSettings.SetEdgeBlending(nEdgeBlendingCountB);
315 StyleSettingsChanged = true;
316 }
317
318 const sal_Int16 nMaxLineCountA(GetListBoxMaximumLineCount());
319 OSL_ENSURE(nMaxLineCountA >= 0, "OOps, negative values for ListBoxMaximumLineCount are not allowed (!)");
320 const sal_uInt16 nMaxLineCountB(static_cast< sal_uInt16 >(nMaxLineCountA >= 0 ? nMaxLineCountA : 0));
321
322 if(aStyleSettings.GetListBoxMaximumLineCount() != nMaxLineCountB)
323 {
324 aStyleSettings.SetListBoxMaximumLineCount(nMaxLineCountB);
325 StyleSettingsChanged = true;
326 }
327
328 const sal_Int16 nMaxColumnCountA(GetColorValueSetColumnCount());
329 OSL_ENSURE(nMaxColumnCountA >= 0, "OOps, negative values for ColorValueSetColumnCount are not allowed (!)");
330 const sal_uInt16 nMaxColumnCountB(static_cast< sal_uInt16 >(nMaxColumnCountA >= 0 ? nMaxColumnCountA : 0));
331
332 if(aStyleSettings.GetColorValueSetColumnCount() != nMaxColumnCountB)
333 {
334 aStyleSettings.SetColorValueSetColumnCount(nMaxColumnCountB);
335 StyleSettingsChanged = true;
336 }
337
338 const bool bPreviewUsesCheckeredBackground(GetPreviewUsesCheckeredBackground());
339
340 if(aStyleSettings.GetPreviewUsesCheckeredBackground() != bPreviewUsesCheckeredBackground)
341 {
342 aStyleSettings.SetPreviewUsesCheckeredBackground(bPreviewUsesCheckeredBackground);
343 StyleSettingsChanged = true;
344 }
345
346 if(StyleSettingsChanged)
347 {
348 aAllSettings.SetStyleSettings(aStyleSettings);
349 Application::MergeSystemSettings(aAllSettings);
350 }
351
352 Application::SetSettings(aAllSettings);
353 }
354
355 // class SvtAccessibilityOptions --------------------------------------------------
356
SvtAccessibilityOptions()357 SvtAccessibilityOptions::SvtAccessibilityOptions()
358 {
359 if (!utl::ConfigManager::IsFuzzing())
360 {
361 ::osl::MutexGuard aGuard( SingletonMutex::get() );
362 if(!sm_pSingleImplConfig)
363 {
364 sm_pSingleImplConfig = new SvtAccessibilityOptions_Impl;
365 svtools::ItemHolder2::holdConfigItem(EItem::AccessibilityOptions);
366 }
367 ++sm_nAccessibilityRefCount;
368 }
369 //StartListening( *sm_pSingleImplConfig, sal_True );
370 }
371
~SvtAccessibilityOptions()372 SvtAccessibilityOptions::~SvtAccessibilityOptions()
373 {
374 //EndListening( *sm_pSingleImplConfig, sal_True );
375 ::osl::MutexGuard aGuard( SingletonMutex::get() );
376 if( !--sm_nAccessibilityRefCount )
377 {
378 //if( sm_pSingleImplConfig->IsModified() )
379 // sm_pSingleImplConfig->Commit();
380 DELETEZ( sm_pSingleImplConfig );
381 }
382 }
383
Notify(SfxBroadcaster &,const SfxHint &)384 void SvtAccessibilityOptions::Notify( SfxBroadcaster&, const SfxHint& )
385 {
386 NotifyListeners(ConfigurationHints::NONE);
387 }
388
389
GetIsForPagePreviews() const390 bool SvtAccessibilityOptions::GetIsForPagePreviews() const
391 {
392 return sm_pSingleImplConfig->GetIsForPagePreviews();
393 }
GetIsAllowAnimatedGraphics() const394 bool SvtAccessibilityOptions::GetIsAllowAnimatedGraphics() const
395 {
396 return sm_pSingleImplConfig->GetIsAllowAnimatedGraphics();
397 }
GetIsAllowAnimatedText() const398 bool SvtAccessibilityOptions::GetIsAllowAnimatedText() const
399 {
400 return sm_pSingleImplConfig->GetIsAllowAnimatedText();
401 }
GetIsAutomaticFontColor() const402 bool SvtAccessibilityOptions::GetIsAutomaticFontColor() const
403 {
404 return sm_pSingleImplConfig->GetIsAutomaticFontColor();
405 }
IsSelectionInReadonly() const406 bool SvtAccessibilityOptions::IsSelectionInReadonly() const
407 {
408 return sm_pSingleImplConfig->IsSelectionInReadonly();
409 }
410
411
SetVCLSettings()412 void SvtAccessibilityOptions::SetVCLSettings()
413 {
414 sm_pSingleImplConfig->SetVCLSettings();
415 }
416
417
418 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
419