1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accessibilityoptions.cxx,v $
10 * $Revision: 1.15.74.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #ifdef SVL_DLLIMPLEMENTATION
35 #undef SVL_DLLIMPLEMENTATION
37 #define SVT_DLLIMPLEMENTATION
39 #include <svtools/accessibilityoptions.hxx>
40 #include "configitems/accessibilityoptions_const.hxx"
42 #include <unotools/configmgr.hxx>
43 #include <tools/debug.hxx>
44 #include <com/sun/star/uno/Any.hxx>
45 #include <com/sun/star/uno/Sequence.hxx>
47 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
48 #include <com/sun/star/beans/XPropertySet.hpp>
50 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
51 #include <com/sun/star/container/XNameAccess.hpp>
53 #ifndef _COMPHELPER_CONFIGURATIONHELPER_HXX_
54 #include <comphelper/configurationhelper.hxx>
56 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX_
57 #include <unotools/processfactory.hxx>
59 #ifndef _SVT_LOGHELPER_HXX_
60 #include <loghelper.hxx>
63 #include <svtools/smplhint.hxx>
65 #include <vcl/settings.hxx>
66 #include <vcl/svapp.hxx>
67 #include <rtl/instance.hxx>
69 #include <itemholder2.hxx>
73 using namespace com::sun::star::uno
;
74 namespace css
= com::sun::star
;
76 #define HELP_TIP_TIMEOUT 0xffff // max. timeout setting to pretend a non-timeout
79 // class SvtAccessibilityOptions_Impl ---------------------------------------------
81 class SvtAccessibilityOptions_Impl
84 css::uno::Reference
< css::container::XNameAccess
> m_xCfg
;
88 SvtAccessibilityOptions_Impl();
89 ~SvtAccessibilityOptions_Impl();
91 void SetVCLSettings();
92 sal_Bool
GetAutoDetectSystemHC();
93 sal_Bool
GetIsForPagePreviews() const;
94 sal_Bool
GetIsHelpTipsDisappear() const;
95 sal_Bool
GetIsAllowAnimatedGraphics() const;
96 sal_Bool
GetIsAllowAnimatedText() const;
97 sal_Bool
GetIsAutomaticFontColor() const;
98 sal_Bool
GetIsSystemFont() const;
99 sal_Int16
GetHelpTipSeconds() const;
100 sal_Bool
IsSelectionInReadonly() const;
102 void SetAutoDetectSystemHC(sal_Bool bSet
);
103 void SetIsForPagePreviews(sal_Bool bSet
);
104 void SetIsHelpTipsDisappear(sal_Bool bSet
);
105 void SetIsAllowAnimatedGraphics(sal_Bool bSet
);
106 void SetIsAllowAnimatedText(sal_Bool bSet
);
107 void SetIsAutomaticFontColor(sal_Bool bSet
);
108 void SetIsSystemFont(sal_Bool bSet
);
109 void SetHelpTipSeconds(sal_Int16 nSet
);
110 void SetSelectionInReadonly(sal_Bool bSet
);
112 sal_Bool
IsModified() const { return bIsModified
; };
115 // initialization of static members --------------------------------------
117 SvtAccessibilityOptions_Impl
* volatile SvtAccessibilityOptions::sm_pSingleImplConfig
=NULL
;
118 sal_Int32
volatile SvtAccessibilityOptions::sm_nAccessibilityRefCount(0);
122 struct SingletonMutex
123 : public rtl::Static
< ::osl::Mutex
, SingletonMutex
> {};
126 // -----------------------------------------------------------------------
127 // class SvtAccessibilityOptions_Impl ---------------------------------------------
129 SvtAccessibilityOptions_Impl::SvtAccessibilityOptions_Impl()
133 m_xCfg
= css::uno::Reference
< css::container::XNameAccess
>(
134 ::comphelper::ConfigurationHelper::openConfig(
135 utl::getProcessServiceFactory(),
137 ::comphelper::ConfigurationHelper::E_STANDARD
),
138 css::uno::UNO_QUERY
);
140 bIsModified
= sal_False
;
142 catch(const css::uno::Exception
& ex
)
145 LogHelper::logIt(ex
);
149 SvtAccessibilityOptions_Impl::~SvtAccessibilityOptions_Impl()
153 // -----------------------------------------------------------------------
154 sal_Bool
SvtAccessibilityOptions_Impl::GetAutoDetectSystemHC()
156 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
157 sal_Bool bRet
= sal_True
;
162 xNode
->getPropertyValue(s_sAutoDetectSystemHC
) >>= bRet
;
164 catch(const css::uno::Exception
& ex
)
166 LogHelper::logIt(ex
);
172 sal_Bool
SvtAccessibilityOptions_Impl::GetIsForPagePreviews() const
174 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
175 sal_Bool bRet
= sal_True
;
180 xNode
->getPropertyValue(s_sIsForPagePreviews
) >>= bRet
;
182 catch(const css::uno::Exception
& ex
)
184 LogHelper::logIt(ex
);
189 sal_Bool
SvtAccessibilityOptions_Impl::GetIsHelpTipsDisappear() const
191 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
192 sal_Bool bRet
= sal_True
;
197 xNode
->getPropertyValue(s_sIsHelpTipsDisappear
) >>= bRet
;
199 catch(const css::uno::Exception
& ex
)
201 LogHelper::logIt(ex
);
207 sal_Bool
SvtAccessibilityOptions_Impl::GetIsAllowAnimatedGraphics() const
209 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
210 sal_Bool bRet
= sal_True
;
215 xNode
->getPropertyValue(s_sIsAllowAnimatedGraphics
) >>= bRet
;
217 catch(const css::uno::Exception
& ex
)
219 LogHelper::logIt(ex
);
225 sal_Bool
SvtAccessibilityOptions_Impl::GetIsAllowAnimatedText() const
227 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
228 sal_Bool bRet
= sal_True
;
233 xNode
->getPropertyValue(s_sIsAllowAnimatedText
) >>= bRet
;
235 catch(const css::uno::Exception
& ex
)
237 LogHelper::logIt(ex
);
243 sal_Bool
SvtAccessibilityOptions_Impl::GetIsAutomaticFontColor() const
245 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
246 sal_Bool bRet
= sal_False
;
251 xNode
->getPropertyValue(s_sIsAutomaticFontColor
) >>= bRet
;
253 catch(const css::uno::Exception
& ex
)
255 LogHelper::logIt(ex
);
261 sal_Bool
SvtAccessibilityOptions_Impl::GetIsSystemFont() const
263 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
264 sal_Bool bRet
= sal_True
;
269 xNode
->getPropertyValue(s_sIsSystemFont
) >>= bRet
;
271 catch(const css::uno::Exception
& ex
)
273 LogHelper::logIt(ex
);
279 sal_Int16
SvtAccessibilityOptions_Impl::GetHelpTipSeconds() const
281 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
287 xNode
->getPropertyValue(s_sHelpTipSeconds
) >>= nRet
;
289 catch(const css::uno::Exception
& ex
)
291 LogHelper::logIt(ex
);
297 sal_Bool
SvtAccessibilityOptions_Impl::IsSelectionInReadonly() const
299 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
300 sal_Bool bRet
= sal_False
;
305 xNode
->getPropertyValue(s_sIsSelectionInReadonly
) >>= bRet
;
307 catch(const css::uno::Exception
& ex
)
309 LogHelper::logIt(ex
);
315 void SvtAccessibilityOptions_Impl::SetAutoDetectSystemHC(sal_Bool bSet
)
317 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
321 if(xNode
.is() && xNode
->getPropertyValue(s_sAutoDetectSystemHC
)!=bSet
)
323 xNode
->setPropertyValue(s_sAutoDetectSystemHC
, css::uno::makeAny(bSet
));
324 ::comphelper::ConfigurationHelper::flush(m_xCfg
);
326 bIsModified
= sal_True
;
329 catch(const css::uno::Exception
& ex
)
331 LogHelper::logIt(ex
);
335 void SvtAccessibilityOptions_Impl::SetIsForPagePreviews(sal_Bool bSet
)
337 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
341 if(xNode
.is() && xNode
->getPropertyValue(s_sIsForPagePreviews
)!=bSet
)
343 xNode
->setPropertyValue(s_sIsForPagePreviews
, css::uno::makeAny(bSet
));
344 ::comphelper::ConfigurationHelper::flush(m_xCfg
);
346 bIsModified
= sal_True
;
349 catch(const css::uno::Exception
& ex
)
351 LogHelper::logIt(ex
);
355 void SvtAccessibilityOptions_Impl::SetIsHelpTipsDisappear(sal_Bool bSet
)
357 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
361 if(xNode
.is() && xNode
->getPropertyValue(s_sIsHelpTipsDisappear
)!=bSet
)
363 xNode
->setPropertyValue(s_sIsHelpTipsDisappear
, css::uno::makeAny(bSet
));
364 ::comphelper::ConfigurationHelper::flush(m_xCfg
);
366 bIsModified
= sal_True
;
369 catch(const css::uno::Exception
& ex
)
371 LogHelper::logIt(ex
);
375 void SvtAccessibilityOptions_Impl::SetIsAllowAnimatedGraphics(sal_Bool bSet
)
377 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
381 if(xNode
.is() && xNode
->getPropertyValue(s_sIsAllowAnimatedGraphics
)!=bSet
)
383 xNode
->setPropertyValue(s_sIsAllowAnimatedGraphics
, css::uno::makeAny(bSet
));
384 ::comphelper::ConfigurationHelper::flush(m_xCfg
);
386 bIsModified
= sal_True
;
389 catch(const css::uno::Exception
& ex
)
391 LogHelper::logIt(ex
);
395 void SvtAccessibilityOptions_Impl::SetIsAllowAnimatedText(sal_Bool bSet
)
397 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
401 if(xNode
.is() && xNode
->getPropertyValue(s_sIsAllowAnimatedText
)!=bSet
)
403 xNode
->setPropertyValue(s_sIsAllowAnimatedText
, css::uno::makeAny(bSet
));
404 ::comphelper::ConfigurationHelper::flush(m_xCfg
);
406 bIsModified
= sal_True
;
409 catch(const css::uno::Exception
& ex
)
411 LogHelper::logIt(ex
);
415 void SvtAccessibilityOptions_Impl::SetIsAutomaticFontColor(sal_Bool bSet
)
417 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
421 if(xNode
.is() && xNode
->getPropertyValue(s_sIsAutomaticFontColor
)!=bSet
)
423 xNode
->setPropertyValue(s_sIsAutomaticFontColor
, css::uno::makeAny(bSet
));
424 ::comphelper::ConfigurationHelper::flush(m_xCfg
);
426 bIsModified
= sal_True
;
429 catch(const css::uno::Exception
& ex
)
431 LogHelper::logIt(ex
);
435 void SvtAccessibilityOptions_Impl::SetIsSystemFont(sal_Bool bSet
)
437 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
441 if(xNode
.is() && xNode
->getPropertyValue(s_sIsSystemFont
)!=bSet
)
443 xNode
->setPropertyValue(s_sIsSystemFont
, css::uno::makeAny(bSet
));
444 ::comphelper::ConfigurationHelper::flush(m_xCfg
);
446 bIsModified
= sal_True
;
449 catch(const css::uno::Exception
& ex
)
451 LogHelper::logIt(ex
);
455 void SvtAccessibilityOptions_Impl::SetHelpTipSeconds(sal_Int16 nSet
)
457 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
461 if(xNode
.is() && xNode
->getPropertyValue(s_sHelpTipSeconds
)!=nSet
)
463 xNode
->setPropertyValue(s_sHelpTipSeconds
, css::uno::makeAny(nSet
));
464 ::comphelper::ConfigurationHelper::flush(m_xCfg
);
466 bIsModified
= sal_True
;
469 catch(const css::uno::Exception
& ex
)
471 LogHelper::logIt(ex
);
475 void SvtAccessibilityOptions_Impl::SetSelectionInReadonly(sal_Bool bSet
)
477 css::uno::Reference
< css::beans::XPropertySet
> xNode(m_xCfg
, css::uno::UNO_QUERY
);
481 if(xNode
.is() && xNode
->getPropertyValue(s_sIsSelectionInReadonly
)!=bSet
)
483 xNode
->setPropertyValue(s_sIsSelectionInReadonly
, css::uno::makeAny(bSet
));
484 ::comphelper::ConfigurationHelper::flush(m_xCfg
);
486 bIsModified
= sal_True
;
489 catch(const css::uno::Exception
& ex
)
491 LogHelper::logIt(ex
);
495 void SvtAccessibilityOptions_Impl::SetVCLSettings()
497 AllSettings aAllSettings
= Application::GetSettings();
498 HelpSettings aHelpSettings
= aAllSettings
.GetHelpSettings();
499 aHelpSettings
.SetTipTimeout( GetIsHelpTipsDisappear() ? GetHelpTipSeconds() * 1000 : HELP_TIP_TIMEOUT
);
500 aAllSettings
.SetHelpSettings(aHelpSettings
);
501 if(aAllSettings
.GetStyleSettings().GetUseSystemUIFonts() != GetIsSystemFont() )
503 StyleSettings aStyleSettings
= aAllSettings
.GetStyleSettings();
504 aStyleSettings
.SetUseSystemUIFonts( GetIsSystemFont() );
505 aAllSettings
.SetStyleSettings(aStyleSettings
);
506 Application::MergeSystemSettings( aAllSettings
);
509 Application::SetSettings(aAllSettings
);
512 // -----------------------------------------------------------------------
513 // class SvtAccessibilityOptions --------------------------------------------------
515 SvtAccessibilityOptions::SvtAccessibilityOptions()
518 ::osl::MutexGuard
aGuard( SingletonMutex::get() );
519 if(!sm_pSingleImplConfig
)
521 sm_pSingleImplConfig
= new SvtAccessibilityOptions_Impl
;
522 ItemHolder2::holdConfigItem(E_ACCESSIBILITYOPTIONS
);
524 ++sm_nAccessibilityRefCount
;
526 //StartListening( *sm_pSingleImplConfig, TRUE );
529 // -----------------------------------------------------------------------
531 SvtAccessibilityOptions::~SvtAccessibilityOptions()
533 //EndListening( *sm_pSingleImplConfig, TRUE );
534 ::osl::MutexGuard
aGuard( SingletonMutex::get() );
535 if( !--sm_nAccessibilityRefCount
)
537 //if( sm_pSingleImplConfig->IsModified() )
538 // sm_pSingleImplConfig->Commit();
539 DELETEZ( sm_pSingleImplConfig
);
543 // -----------------------------------------------------------------------
545 void SvtAccessibilityOptions::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
548 if ( rHint
.IsA(TYPE(SfxSimpleHint
)) )
550 if ( ((SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_ACCESSIBILITY_CHANGED
)
555 // -----------------------------------------------------------------------
557 sal_Bool
SvtAccessibilityOptions::IsModified() const
559 return sm_pSingleImplConfig
->IsModified();
561 void SvtAccessibilityOptions::Commit()
563 //sm_pSingleImplConfig->Commit();
566 // -----------------------------------------------------------------------
568 sal_Bool
SvtAccessibilityOptions::GetIsForDrawings() const
570 DBG_ERROR( "SvtAccessibilityOptions::GetIsForDrawings: is obsolete!" );
573 sal_Bool
SvtAccessibilityOptions::GetIsForBorders() const
575 DBG_ERROR( "SvtAccessibilityOptions::GetIsForBorders: is obsolete!" );
578 sal_Bool
SvtAccessibilityOptions::GetAutoDetectSystemHC() const
580 return sm_pSingleImplConfig
->GetAutoDetectSystemHC();
582 sal_Bool
SvtAccessibilityOptions::GetIsForPagePreviews() const
584 return sm_pSingleImplConfig
->GetIsForPagePreviews();
586 sal_Bool
SvtAccessibilityOptions::GetIsHelpTipsDisappear() const
588 return sm_pSingleImplConfig
->GetIsHelpTipsDisappear();
590 sal_Bool
SvtAccessibilityOptions::GetIsAllowAnimatedGraphics() const
592 return sm_pSingleImplConfig
->GetIsAllowAnimatedGraphics();
594 sal_Bool
SvtAccessibilityOptions::GetIsAllowAnimatedText() const
596 return sm_pSingleImplConfig
->GetIsAllowAnimatedText();
598 sal_Bool
SvtAccessibilityOptions::GetIsAutomaticFontColor() const
600 return sm_pSingleImplConfig
->GetIsAutomaticFontColor();
602 sal_Bool
SvtAccessibilityOptions::GetIsSystemFont() const
604 return sm_pSingleImplConfig
->GetIsSystemFont();
606 sal_Int16
SvtAccessibilityOptions::GetHelpTipSeconds() const
608 return sm_pSingleImplConfig
->GetHelpTipSeconds();
610 sal_Bool
SvtAccessibilityOptions::IsSelectionInReadonly() const
612 return sm_pSingleImplConfig
->IsSelectionInReadonly();
615 // -----------------------------------------------------------------------
616 void SvtAccessibilityOptions::SetAutoDetectSystemHC(sal_Bool bSet
)
618 sm_pSingleImplConfig
->SetAutoDetectSystemHC(bSet
);
620 void SvtAccessibilityOptions::SetIsForPagePreviews(sal_Bool bSet
)
622 sm_pSingleImplConfig
->SetIsForPagePreviews(bSet
);
624 void SvtAccessibilityOptions::SetIsHelpTipsDisappear(sal_Bool bSet
)
626 sm_pSingleImplConfig
->SetIsHelpTipsDisappear(bSet
);
628 void SvtAccessibilityOptions::SetIsAllowAnimatedGraphics(sal_Bool bSet
)
630 sm_pSingleImplConfig
->SetIsAllowAnimatedGraphics(bSet
);
632 void SvtAccessibilityOptions::SetIsAllowAnimatedText(sal_Bool bSet
)
634 sm_pSingleImplConfig
->SetIsAllowAnimatedText(bSet
);
636 void SvtAccessibilityOptions::SetIsAutomaticFontColor(sal_Bool bSet
)
638 sm_pSingleImplConfig
->SetIsAutomaticFontColor(bSet
);
640 void SvtAccessibilityOptions::SetIsSystemFont(sal_Bool bSet
)
642 sm_pSingleImplConfig
->SetIsSystemFont(bSet
);
644 void SvtAccessibilityOptions::SetHelpTipSeconds(sal_Int16 nSet
)
646 sm_pSingleImplConfig
->SetHelpTipSeconds(nSet
);
648 void SvtAccessibilityOptions::SetSelectionInReadonly(sal_Bool bSet
)
650 sm_pSingleImplConfig
->SetSelectionInReadonly(bSet
);
653 void SvtAccessibilityOptions::SetVCLSettings()
655 sm_pSingleImplConfig
->SetVCLSettings();
657 // -----------------------------------------------------------------------