xref: /AOO41X/main/svtools/source/config/accessibilityoptions.cxx (revision ff0525f24f03981d56b7579b645949f111420994)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26 
27 #include <svtools/accessibilityoptions.hxx>
28 #include "configitems/accessibilityoptions_const.hxx"
29 
30 #include <unotools/configmgr.hxx>
31 #include <tools/debug.hxx>
32 #include <com/sun/star/uno/Any.hxx>
33 #include <com/sun/star/uno/Sequence.hxx>
34 
35 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #endif
38 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
39 #include <com/sun/star/container/XNameAccess.hpp>
40 #endif
41 #ifndef _COMPHELPER_CONFIGURATIONHELPER_HXX_
42 #include <comphelper/configurationhelper.hxx>
43 #endif
44 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX_
45 #include <unotools/processfactory.hxx>
46 #endif
47 #ifndef _SVT_LOGHELPER_HXX_
48 #include <unotools/loghelper.hxx>
49 #endif
50 
51 #include <svl/smplhint.hxx>
52 
53 #include <vcl/settings.hxx>
54 #include <vcl/svapp.hxx>
55 #include <rtl/instance.hxx>
56 
57 #include <itemholder2.hxx>
58 
59 using namespace utl;
60 using namespace rtl;
61 using namespace com::sun::star::uno;
62 namespace css = com::sun::star;
63 
64 #define HELP_TIP_TIMEOUT 0xffff     // max. timeout setting to pretend a non-timeout
65 
66 
67 // class SvtAccessibilityOptions_Impl ---------------------------------------------
68 
69 class SvtAccessibilityOptions_Impl
70 {
71 private:
72     css::uno::Reference< css::container::XNameAccess > m_xCfg;
73     sal_Bool                                           bIsModified;
74 
75 public:
76     SvtAccessibilityOptions_Impl();
77     ~SvtAccessibilityOptions_Impl();
78 
79     void        SetVCLSettings();
80     sal_Bool    GetAutoDetectSystemHC();
81     sal_Bool    GetIsForPagePreviews() const;
82     sal_Bool    GetIsHelpTipsDisappear() const;
83     sal_Bool    GetIsAllowAnimatedGraphics() const;
84     sal_Bool    GetIsAllowAnimatedText() const;
85     sal_Bool    GetIsAutomaticFontColor() const;
86     sal_Bool    GetIsSystemFont() const;
87     sal_Int16   GetHelpTipSeconds() const;
88     sal_Bool    IsSelectionInReadonly() const;
89 
90     void        SetAutoDetectSystemHC(sal_Bool bSet);
91     void        SetIsForPagePreviews(sal_Bool bSet);
92     void        SetIsHelpTipsDisappear(sal_Bool bSet);
93     void        SetIsAllowAnimatedGraphics(sal_Bool bSet);
94     void        SetIsAllowAnimatedText(sal_Bool bSet);
95     void        SetIsAutomaticFontColor(sal_Bool bSet);
96     void        SetIsSystemFont(sal_Bool bSet);
97     void        SetHelpTipSeconds(sal_Int16 nSet);
98     void        SetSelectionInReadonly(sal_Bool bSet);
99 
100     sal_Bool    IsModified() const { return bIsModified; };
101 };
102 
103 // initialization of static members --------------------------------------
104 
105 SvtAccessibilityOptions_Impl* volatile  SvtAccessibilityOptions::sm_pSingleImplConfig =NULL;
106 sal_Int32                     volatile  SvtAccessibilityOptions::sm_nAccessibilityRefCount(0);
107 
108 namespace
109 {
110     struct SingletonMutex
111         : public rtl::Static< ::osl::Mutex, SingletonMutex > {};
112 }
113 
114 // -----------------------------------------------------------------------
115 // class SvtAccessibilityOptions_Impl ---------------------------------------------
116 
117 SvtAccessibilityOptions_Impl::SvtAccessibilityOptions_Impl()
118 {
119     try
120     {
121         m_xCfg = css::uno::Reference< css::container::XNameAccess >(
122             ::comphelper::ConfigurationHelper::openConfig(
123             utl::getProcessServiceFactory(),
124             s_sAccessibility,
125             ::comphelper::ConfigurationHelper::E_STANDARD),
126             css::uno::UNO_QUERY);
127 
128         bIsModified = sal_False;
129     }
130     catch(const css::uno::Exception& ex)
131     {
132         m_xCfg.clear();
133         LogHelper::logIt(ex);
134     }
135 }
136 
137 SvtAccessibilityOptions_Impl::~SvtAccessibilityOptions_Impl()
138 {
139 }
140 
141 // -----------------------------------------------------------------------
142 sal_Bool SvtAccessibilityOptions_Impl::GetAutoDetectSystemHC()
143 {
144     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
145     sal_Bool                                        bRet = sal_True;
146 
147     try
148     {
149         if(xNode.is())
150             xNode->getPropertyValue(s_sAutoDetectSystemHC) >>= bRet;
151     }
152     catch(const css::uno::Exception& ex)
153     {
154         LogHelper::logIt(ex);
155     }
156 
157     return bRet;
158 }
159 
160 sal_Bool SvtAccessibilityOptions_Impl::GetIsForPagePreviews() const
161 {
162     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
163     sal_Bool                                        bRet = sal_True;
164 
165     try
166     {
167         if(xNode.is())
168             xNode->getPropertyValue(s_sIsForPagePreviews) >>= bRet;
169     }
170     catch(const css::uno::Exception& ex)
171     {
172         LogHelper::logIt(ex);
173     }
174     return bRet;
175 }
176 
177 sal_Bool SvtAccessibilityOptions_Impl::GetIsHelpTipsDisappear() const
178 {
179     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
180     sal_Bool                                        bRet = sal_True;
181 
182     try
183     {
184         if(xNode.is())
185             xNode->getPropertyValue(s_sIsHelpTipsDisappear) >>= bRet;
186     }
187     catch(const css::uno::Exception& ex)
188     {
189         LogHelper::logIt(ex);
190     }
191 
192     return bRet;
193 }
194 
195 sal_Bool SvtAccessibilityOptions_Impl::GetIsAllowAnimatedGraphics() const
196 {
197     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
198     sal_Bool                                        bRet = sal_True;
199 
200     try
201     {
202         if(xNode.is())
203             xNode->getPropertyValue(s_sIsAllowAnimatedGraphics) >>= bRet;
204     }
205     catch(const css::uno::Exception& ex)
206     {
207         LogHelper::logIt(ex);
208     }
209 
210     return bRet;
211 }
212 
213 sal_Bool SvtAccessibilityOptions_Impl::GetIsAllowAnimatedText() const
214 {
215     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
216     sal_Bool                                        bRet = sal_True;
217 
218     try
219     {
220         if(xNode.is())
221             xNode->getPropertyValue(s_sIsAllowAnimatedText) >>= bRet;
222     }
223     catch(const css::uno::Exception& ex)
224     {
225         LogHelper::logIt(ex);
226     }
227 
228     return bRet;
229 }
230 
231 sal_Bool SvtAccessibilityOptions_Impl::GetIsAutomaticFontColor() const
232 {
233     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
234     sal_Bool                                        bRet = sal_False;
235 
236     try
237     {
238         if(xNode.is())
239             xNode->getPropertyValue(s_sIsAutomaticFontColor) >>= bRet;
240     }
241     catch(const css::uno::Exception& ex)
242     {
243         LogHelper::logIt(ex);
244     }
245 
246     return bRet;
247 }
248 
249 sal_Bool SvtAccessibilityOptions_Impl::GetIsSystemFont() const
250 {
251     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
252     sal_Bool                                        bRet = sal_True;
253 
254     try
255     {
256         if(xNode.is())
257             xNode->getPropertyValue(s_sIsSystemFont) >>= bRet;
258     }
259     catch(const css::uno::Exception& ex)
260     {
261         LogHelper::logIt(ex);
262     }
263 
264     return bRet;
265 }
266 
267 sal_Int16 SvtAccessibilityOptions_Impl::GetHelpTipSeconds() const
268 {
269     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
270     sal_Int16                                       nRet = 4;
271 
272     try
273     {
274         if(xNode.is())
275             xNode->getPropertyValue(s_sHelpTipSeconds) >>= nRet;
276     }
277     catch(const css::uno::Exception& ex)
278     {
279         LogHelper::logIt(ex);
280     }
281 
282     return nRet;
283 }
284 
285 sal_Bool SvtAccessibilityOptions_Impl::IsSelectionInReadonly() const
286 {
287     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
288     sal_Bool                                        bRet = sal_False;
289 
290     try
291     {
292         if(xNode.is())
293             xNode->getPropertyValue(s_sIsSelectionInReadonly) >>= bRet;
294     }
295     catch(const css::uno::Exception& ex)
296     {
297         LogHelper::logIt(ex);
298     }
299 
300     return bRet;
301 }
302 
303 void SvtAccessibilityOptions_Impl::SetAutoDetectSystemHC(sal_Bool bSet)
304 {
305     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
306 
307     try
308     {
309         if(xNode.is() && xNode->getPropertyValue(s_sAutoDetectSystemHC)!=bSet)
310         {
311             xNode->setPropertyValue(s_sAutoDetectSystemHC, css::uno::makeAny(bSet));
312             ::comphelper::ConfigurationHelper::flush(m_xCfg);
313 
314             bIsModified = sal_True;
315         }
316     }
317     catch(const css::uno::Exception& ex)
318     {
319         LogHelper::logIt(ex);
320     }
321 }
322 
323 void SvtAccessibilityOptions_Impl::SetIsForPagePreviews(sal_Bool bSet)
324 {
325     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
326 
327     try
328     {
329         if(xNode.is() && xNode->getPropertyValue(s_sIsForPagePreviews)!=bSet)
330         {
331             xNode->setPropertyValue(s_sIsForPagePreviews, css::uno::makeAny(bSet));
332             ::comphelper::ConfigurationHelper::flush(m_xCfg);
333 
334             bIsModified = sal_True;
335         }
336     }
337     catch(const css::uno::Exception& ex)
338     {
339         LogHelper::logIt(ex);
340     }
341 }
342 
343 void SvtAccessibilityOptions_Impl::SetIsHelpTipsDisappear(sal_Bool bSet)
344 {
345     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
346 
347     try
348     {
349         if(xNode.is() && xNode->getPropertyValue(s_sIsHelpTipsDisappear)!=bSet)
350         {
351             xNode->setPropertyValue(s_sIsHelpTipsDisappear, css::uno::makeAny(bSet));
352             ::comphelper::ConfigurationHelper::flush(m_xCfg);
353 
354             bIsModified = sal_True;
355         }
356     }
357     catch(const css::uno::Exception& ex)
358     {
359         LogHelper::logIt(ex);
360     }
361 }
362 
363 void SvtAccessibilityOptions_Impl::SetIsAllowAnimatedGraphics(sal_Bool bSet)
364 {
365     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
366 
367     try
368     {
369         if(xNode.is() && xNode->getPropertyValue(s_sIsAllowAnimatedGraphics)!=bSet)
370         {
371             xNode->setPropertyValue(s_sIsAllowAnimatedGraphics, css::uno::makeAny(bSet));
372             ::comphelper::ConfigurationHelper::flush(m_xCfg);
373 
374             bIsModified = sal_True;
375         }
376     }
377     catch(const css::uno::Exception& ex)
378     {
379         LogHelper::logIt(ex);
380     }
381 }
382 
383 void SvtAccessibilityOptions_Impl::SetIsAllowAnimatedText(sal_Bool bSet)
384 {
385     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
386 
387     try
388     {
389         if(xNode.is() && xNode->getPropertyValue(s_sIsAllowAnimatedText)!=bSet)
390         {
391             xNode->setPropertyValue(s_sIsAllowAnimatedText, css::uno::makeAny(bSet));
392             ::comphelper::ConfigurationHelper::flush(m_xCfg);
393 
394             bIsModified = sal_True;
395         }
396     }
397     catch(const css::uno::Exception& ex)
398     {
399         LogHelper::logIt(ex);
400     }
401 }
402 
403 void SvtAccessibilityOptions_Impl::SetIsAutomaticFontColor(sal_Bool bSet)
404 {
405     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
406 
407     try
408     {
409         if(xNode.is() && xNode->getPropertyValue(s_sIsAutomaticFontColor)!=bSet)
410         {
411             xNode->setPropertyValue(s_sIsAutomaticFontColor, css::uno::makeAny(bSet));
412             ::comphelper::ConfigurationHelper::flush(m_xCfg);
413 
414             bIsModified = sal_True;
415         }
416     }
417     catch(const css::uno::Exception& ex)
418     {
419         LogHelper::logIt(ex);
420     }
421 }
422 
423 void SvtAccessibilityOptions_Impl::SetIsSystemFont(sal_Bool bSet)
424 {
425     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
426 
427     try
428     {
429         if(xNode.is() && xNode->getPropertyValue(s_sIsSystemFont)!=bSet)
430         {
431             xNode->setPropertyValue(s_sIsSystemFont, css::uno::makeAny(bSet));
432             ::comphelper::ConfigurationHelper::flush(m_xCfg);
433 
434             bIsModified = sal_True;
435         }
436     }
437     catch(const css::uno::Exception& ex)
438     {
439         LogHelper::logIt(ex);
440     }
441 }
442 
443 void SvtAccessibilityOptions_Impl::SetHelpTipSeconds(sal_Int16 nSet)
444 {
445     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
446 
447     try
448     {
449         if(xNode.is() && xNode->getPropertyValue(s_sHelpTipSeconds)!=nSet)
450         {
451             xNode->setPropertyValue(s_sHelpTipSeconds, css::uno::makeAny(nSet));
452             ::comphelper::ConfigurationHelper::flush(m_xCfg);
453 
454             bIsModified = sal_True;
455         }
456     }
457     catch(const css::uno::Exception& ex)
458     {
459         LogHelper::logIt(ex);
460     }
461 }
462 
463 void SvtAccessibilityOptions_Impl::SetSelectionInReadonly(sal_Bool bSet)
464 {
465     css::uno::Reference< css::beans::XPropertySet > xNode(m_xCfg, css::uno::UNO_QUERY);
466 
467     try
468     {
469         if(xNode.is() && xNode->getPropertyValue(s_sIsSelectionInReadonly)!=bSet)
470         {
471             xNode->setPropertyValue(s_sIsSelectionInReadonly, css::uno::makeAny(bSet));
472             ::comphelper::ConfigurationHelper::flush(m_xCfg);
473 
474             bIsModified = sal_True;
475         }
476     }
477     catch(const css::uno::Exception& ex)
478     {
479         LogHelper::logIt(ex);
480     }
481 }
482 
483 void SvtAccessibilityOptions_Impl::SetVCLSettings()
484 {
485     AllSettings aAllSettings = Application::GetSettings();
486     HelpSettings aHelpSettings = aAllSettings.GetHelpSettings();
487     aHelpSettings.SetTipTimeout( GetIsHelpTipsDisappear() ? GetHelpTipSeconds() * 1000 : HELP_TIP_TIMEOUT);
488     aAllSettings.SetHelpSettings(aHelpSettings);
489     if(aAllSettings.GetStyleSettings().GetUseSystemUIFonts() != GetIsSystemFont() )
490     {
491         StyleSettings aStyleSettings = aAllSettings.GetStyleSettings();
492         aStyleSettings.SetUseSystemUIFonts( GetIsSystemFont()  );
493         aAllSettings.SetStyleSettings(aStyleSettings);
494         Application::MergeSystemSettings( aAllSettings );
495     }
496 
497     Application::SetSettings(aAllSettings);
498 }
499 
500 // -----------------------------------------------------------------------
501 // class SvtAccessibilityOptions --------------------------------------------------
502 
503 SvtAccessibilityOptions::SvtAccessibilityOptions()
504 {
505     {
506         ::osl::MutexGuard aGuard( SingletonMutex::get() );
507         if(!sm_pSingleImplConfig)
508         {
509             sm_pSingleImplConfig = new SvtAccessibilityOptions_Impl;
510             ItemHolder2::holdConfigItem(E_ACCESSIBILITYOPTIONS);
511         }
512         ++sm_nAccessibilityRefCount;
513     }
514     //StartListening( *sm_pSingleImplConfig, sal_True );
515 }
516 
517 // -----------------------------------------------------------------------
518 
519 SvtAccessibilityOptions::~SvtAccessibilityOptions()
520 {
521     //EndListening( *sm_pSingleImplConfig, sal_True );
522     ::osl::MutexGuard aGuard( SingletonMutex::get() );
523     if( !--sm_nAccessibilityRefCount )
524     {
525         //if( sm_pSingleImplConfig->IsModified() )
526         //  sm_pSingleImplConfig->Commit();
527         DELETEZ( sm_pSingleImplConfig );
528     }
529 }
530 
531 // -----------------------------------------------------------------------
532 
533 void SvtAccessibilityOptions::Notify( SfxBroadcaster&, const SfxHint& rHint )
534 {
535     NotifyListeners(0);
536     if ( rHint.IsA(TYPE(SfxSimpleHint)) )
537     {
538         if ( ((SfxSimpleHint&)rHint).GetId()  == SFX_HINT_ACCESSIBILITY_CHANGED )
539             SetVCLSettings();
540     }
541 }
542 
543 // -----------------------------------------------------------------------
544 
545 sal_Bool SvtAccessibilityOptions::IsModified() const
546 {
547     return sm_pSingleImplConfig->IsModified();
548 }
549 void SvtAccessibilityOptions::Commit()
550 {
551     //sm_pSingleImplConfig->Commit();
552 }
553 
554 // -----------------------------------------------------------------------
555 
556 sal_Bool SvtAccessibilityOptions::GetIsForDrawings() const
557 {
558     DBG_ERROR( "SvtAccessibilityOptions::GetIsForDrawings: is obsolete!" );
559     return sal_False;
560 }
561 sal_Bool SvtAccessibilityOptions::GetIsForBorders() const
562 {
563     DBG_ERROR( "SvtAccessibilityOptions::GetIsForBorders: is obsolete!" );
564     return sal_False;
565 }
566 sal_Bool SvtAccessibilityOptions::GetAutoDetectSystemHC() const
567 {
568     return sm_pSingleImplConfig->GetAutoDetectSystemHC();
569 }
570 sal_Bool SvtAccessibilityOptions::GetIsForPagePreviews() const
571 {
572     return sm_pSingleImplConfig->GetIsForPagePreviews();
573 }
574 sal_Bool SvtAccessibilityOptions::GetIsHelpTipsDisappear() const
575 {
576     return sm_pSingleImplConfig->GetIsHelpTipsDisappear();
577 }
578 sal_Bool SvtAccessibilityOptions::GetIsAllowAnimatedGraphics() const
579 {
580     return sm_pSingleImplConfig->GetIsAllowAnimatedGraphics();
581 }
582 sal_Bool SvtAccessibilityOptions::GetIsAllowAnimatedText() const
583 {
584     return sm_pSingleImplConfig->GetIsAllowAnimatedText();
585 }
586 sal_Bool SvtAccessibilityOptions::GetIsAutomaticFontColor() const
587 {
588     return sm_pSingleImplConfig->GetIsAutomaticFontColor();
589 }
590 sal_Bool SvtAccessibilityOptions::GetIsSystemFont() const
591 {
592     return sm_pSingleImplConfig->GetIsSystemFont();
593 }
594 sal_Int16 SvtAccessibilityOptions::GetHelpTipSeconds() const
595 {
596     return sm_pSingleImplConfig->GetHelpTipSeconds();
597 }
598 sal_Bool SvtAccessibilityOptions::IsSelectionInReadonly() const
599 {
600     return sm_pSingleImplConfig->IsSelectionInReadonly();
601 }
602 
603 // -----------------------------------------------------------------------
604 void SvtAccessibilityOptions::SetAutoDetectSystemHC(sal_Bool bSet)
605 {
606     sm_pSingleImplConfig->SetAutoDetectSystemHC(bSet);
607 }
608 void SvtAccessibilityOptions::SetIsForPagePreviews(sal_Bool bSet)
609 {
610     sm_pSingleImplConfig->SetIsForPagePreviews(bSet);
611 }
612 void SvtAccessibilityOptions::SetIsHelpTipsDisappear(sal_Bool bSet)
613 {
614     sm_pSingleImplConfig->SetIsHelpTipsDisappear(bSet);
615 }
616 void SvtAccessibilityOptions::SetIsAllowAnimatedGraphics(sal_Bool bSet)
617 {
618     sm_pSingleImplConfig->SetIsAllowAnimatedGraphics(bSet);
619 }
620 void SvtAccessibilityOptions::SetIsAllowAnimatedText(sal_Bool bSet)
621 {
622     sm_pSingleImplConfig->SetIsAllowAnimatedText(bSet);
623 }
624 void SvtAccessibilityOptions::SetIsAutomaticFontColor(sal_Bool bSet)
625 {
626     sm_pSingleImplConfig->SetIsAutomaticFontColor(bSet);
627 }
628 void SvtAccessibilityOptions::SetIsSystemFont(sal_Bool bSet)
629 {
630     sm_pSingleImplConfig->SetIsSystemFont(bSet);
631 }
632 void SvtAccessibilityOptions::SetHelpTipSeconds(sal_Int16 nSet)
633 {
634     sm_pSingleImplConfig->SetHelpTipSeconds(nSet);
635 }
636 void SvtAccessibilityOptions::SetSelectionInReadonly(sal_Bool bSet)
637 {
638     sm_pSingleImplConfig->SetSelectionInReadonly(bSet);
639 }
640 
641 void SvtAccessibilityOptions::SetVCLSettings()
642 {
643     sm_pSingleImplConfig->SetVCLSettings();
644 }
645 // -----------------------------------------------------------------------
646