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