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 #include "precompiled_sfx2.hxx" 23 24 #include "sfx2/sidebar/Theme.hxx" 25 #include "Paint.hxx" 26 #include "SidebarResource.hxx" 27 #include "Tools.hxx" 28 29 #include <tools/svborder.hxx> 30 #include <tools/rc.hxx> 31 #include <vcl/svapp.hxx> 32 33 using namespace css; 34 using namespace cssu; 35 36 37 namespace sfx2 { namespace sidebar { 38 39 ::rtl::Reference<Theme> Theme::mpInstance; 40 41 42 43 44 Theme& Theme::GetCurrentTheme (void) 45 { 46 if ( ! mpInstance.is()) 47 { 48 mpInstance.set(new Theme()); 49 mpInstance->InitializeTheme(); 50 } 51 return *mpInstance; 52 } 53 54 55 56 57 Theme::Theme (void) 58 : ThemeInterfaceBase(m_aMutex), 59 maImages(), 60 maColors(), 61 maPaints(), 62 maIntegers(), 63 maBooleans(), 64 mbIsHighContrastMode(Application::GetSettings().GetStyleSettings().GetHighContrastMode()), 65 mbIsHighContrastModeSetManually(false), 66 maPropertyNameToIdMap(), 67 maPropertyIdToNameMap(), 68 maRawValues(), 69 maChangeListeners(), 70 maVetoableListeners() 71 72 { 73 SetupPropertyMaps(); 74 } 75 76 77 78 79 Theme::~Theme (void) 80 { 81 } 82 83 84 85 86 Image Theme::GetImage (const ThemeItem eItem) 87 { 88 const PropertyType eType (GetPropertyType(eItem)); 89 OSL_ASSERT(eType==PT_Image); 90 const sal_Int32 nIndex (GetIndex(eItem, eType)); 91 const Theme& rTheme (GetCurrentTheme()); 92 return rTheme.maImages[nIndex]; 93 } 94 95 96 97 98 Color Theme::GetColor (const ThemeItem eItem) 99 { 100 const PropertyType eType (GetPropertyType(eItem)); 101 OSL_ASSERT(eType==PT_Color); 102 const sal_Int32 nIndex (GetIndex(eItem, eType)); 103 const Theme& rTheme (GetCurrentTheme()); 104 return rTheme.maColors[nIndex]; 105 } 106 107 108 109 110 const Paint& Theme::GetPaint (const ThemeItem eItem) 111 { 112 const PropertyType eType (GetPropertyType(eItem)); 113 OSL_ASSERT(eType==PT_Paint); 114 const sal_Int32 nIndex (GetIndex(eItem, eType)); 115 const Theme& rTheme (GetCurrentTheme()); 116 return rTheme.maPaints[nIndex]; 117 } 118 119 120 121 122 const Wallpaper Theme::GetWallpaper (const ThemeItem eItem) 123 { 124 return GetPaint(eItem).GetWallpaper(); 125 } 126 127 128 129 130 sal_Int32 Theme::GetInteger (const ThemeItem eItem) 131 { 132 const PropertyType eType (GetPropertyType(eItem)); 133 OSL_ASSERT(eType==PT_Integer); 134 const sal_Int32 nIndex (GetIndex(eItem, eType)); 135 const Theme& rTheme (GetCurrentTheme()); 136 return rTheme.maIntegers[nIndex]; 137 } 138 139 140 141 142 bool Theme::GetBoolean (const ThemeItem eItem) 143 { 144 const PropertyType eType (GetPropertyType(eItem)); 145 OSL_ASSERT(eType==PT_Boolean); 146 const sal_Int32 nIndex (GetIndex(eItem, eType)); 147 const Theme& rTheme (GetCurrentTheme()); 148 return rTheme.maBooleans[nIndex]; 149 } 150 151 152 153 154 Rectangle Theme::GetRectangle (const ThemeItem eItem) 155 { 156 const PropertyType eType (GetPropertyType(eItem)); 157 OSL_ASSERT(eType==PT_Rectangle); 158 const sal_Int32 nIndex (GetIndex(eItem, eType)); 159 const Theme& rTheme (GetCurrentTheme()); 160 return rTheme.maRectangles[nIndex]; 161 } 162 163 164 165 166 bool Theme::IsHighContrastMode (void) 167 { 168 const Theme& rTheme (GetCurrentTheme()); 169 return rTheme.mbIsHighContrastMode; 170 } 171 172 173 174 175 void Theme::HandleDataChange (void) 176 { 177 Theme& rTheme (GetCurrentTheme()); 178 179 if ( ! rTheme.mbIsHighContrastModeSetManually) 180 { 181 // Do not modify mbIsHighContrastMode when it was manually set. 182 GetCurrentTheme().mbIsHighContrastMode = Application::GetSettings().GetStyleSettings().GetHighContrastMode(); 183 rTheme.maRawValues[Bool_IsHighContrastModeActive] = Any(GetCurrentTheme().mbIsHighContrastMode); 184 } 185 186 GetCurrentTheme().UpdateTheme(); 187 } 188 189 190 191 192 void Theme::InitializeTheme (void) 193 { 194 setPropertyValue( 195 maPropertyIdToNameMap[Bool_UseSymphonyIcons], 196 Any(true)); 197 setPropertyValue( 198 maPropertyIdToNameMap[Bool_UseSystemColors], 199 Any(false)); 200 } 201 202 203 204 205 void Theme::UpdateTheme (void) 206 { 207 SidebarResource aLocalResource; 208 209 try 210 { 211 const StyleSettings& rStyle (Application::GetSettings().GetStyleSettings()); 212 const bool bUseSystemColors (GetBoolean(Bool_UseSystemColors)); 213 214 #define Alternatives(n,hc,sys) (mbIsHighContrastMode ? hc : (bUseSystemColors ? sys : n)) 215 216 setPropertyValue( 217 maPropertyIdToNameMap[Paint_DeckBackground], 218 Any(sal_Int32(Alternatives( 219 0xf0f0f0, 220 0x000000, 221 rStyle.GetDialogColor().GetRGBColor())))); 222 223 setPropertyValue( 224 maPropertyIdToNameMap[Paint_DeckTitleBarBackground], 225 Any(sal_Int32(Alternatives( 226 0xf0f0f0, 227 0x000000, 228 rStyle.GetDialogColor().GetRGBColor())))); 229 setPropertyValue( 230 maPropertyIdToNameMap[Int_DeckLeftPadding], 231 Any(sal_Int32(2))); 232 setPropertyValue( 233 maPropertyIdToNameMap[Int_DeckTopPadding], 234 Any(sal_Int32(2))); 235 setPropertyValue( 236 maPropertyIdToNameMap[Int_DeckRightPadding], 237 Any(sal_Int32(2))); 238 setPropertyValue( 239 maPropertyIdToNameMap[Int_DeckBottomPadding], 240 Any(sal_Int32(2))); 241 setPropertyValue( 242 maPropertyIdToNameMap[Int_DeckBorderSize], 243 Any(sal_Int32(1))); 244 setPropertyValue( 245 maPropertyIdToNameMap[Int_DeckSeparatorHeight], 246 Any(sal_Int32(1))); 247 setPropertyValue( 248 maPropertyIdToNameMap[Color_DeckTitleFont], 249 Any(sal_Int32(Alternatives( 250 0x262626, 251 0x00ff00, 252 rStyle.GetDialogTextColor().GetRGBColor())))); 253 setPropertyValue( 254 maPropertyIdToNameMap[Int_DeckTitleBarHeight], 255 Any(sal_Int32(Alternatives( 256 26, 257 26, 258 rStyle.GetFloatTitleHeight())))); 259 setPropertyValue( 260 maPropertyIdToNameMap[Paint_PanelBackground], 261 Any(sal_Int32(mbIsHighContrastMode ? 0x000000 : 0xffffff))); 262 setPropertyValue( 263 maPropertyIdToNameMap[Paint_PanelTitleBarBackground], 264 Any(sal_Int32(mbIsHighContrastMode ? 0x000000 : 0xb2b2b2))); 265 setPropertyValue( 266 maPropertyIdToNameMap[Color_PanelTitleFont], 267 Any(sal_Int32(mbIsHighContrastMode ? 0x00ff00 : 0x262626))); 268 setPropertyValue( 269 maPropertyIdToNameMap[Int_PanelTitleBarHeight], 270 Any(sal_Int32(Alternatives( 271 26, 272 26, 273 rStyle.GetTitleHeight())))); 274 setPropertyValue( 275 maPropertyIdToNameMap[Paint_TabBarBackground], 276 Any(sal_Int32(mbIsHighContrastMode ? 0x000000 : 0xf0f0f0))); 277 setPropertyValue( 278 maPropertyIdToNameMap[Int_TabBarLeftPadding], 279 Any(sal_Int32(2))); 280 setPropertyValue( 281 maPropertyIdToNameMap[Int_TabBarTopPadding], 282 Any(sal_Int32(2))); 283 setPropertyValue( 284 maPropertyIdToNameMap[Int_TabBarRightPadding], 285 Any(sal_Int32(2))); 286 setPropertyValue( 287 maPropertyIdToNameMap[Int_TabBarBottomPadding], 288 Any(sal_Int32(2))); 289 290 setPropertyValue( 291 maPropertyIdToNameMap[Int_TabMenuPadding], 292 Any(sal_Int32(6))); 293 setPropertyValue( 294 maPropertyIdToNameMap[Color_TabMenuSeparator], 295 Any(sal_Int32(mbIsHighContrastMode ? 0x00ff00 : 0xbfbfbf))); 296 setPropertyValue( 297 maPropertyIdToNameMap[Int_TabMenuSeparatorPadding], 298 Any(sal_Int32(7))); 299 300 setPropertyValue( 301 maPropertyIdToNameMap[Int_TabItemWidth], 302 Any(sal_Int32(32))); 303 setPropertyValue( 304 maPropertyIdToNameMap[Int_TabItemHeight], 305 Any(sal_Int32(32))); 306 setPropertyValue( 307 maPropertyIdToNameMap[Color_TabItemBorder], 308 Any(sal_Int32(mbIsHighContrastMode ? 0x00ff00 : 0xbfbfbf))); 309 setPropertyValue( 310 maPropertyIdToNameMap[Paint_TabItemBackgroundNormal], 311 Any()); 312 setPropertyValue( 313 maPropertyIdToNameMap[Paint_TabItemBackgroundHighlight], 314 Any(sal_Int32(mbIsHighContrastMode ? 0x000000 : 0x00ffffff))); 315 316 setPropertyValue( 317 maPropertyIdToNameMap[Paint_HorizontalBorder], 318 Any(sal_Int32(mbIsHighContrastMode ? 0xff00ff00 : 0xd9d9d9))); 319 setPropertyValue( 320 maPropertyIdToNameMap[Paint_VerticalBorder], 321 Any(sal_Int32(mbIsHighContrastMode ? 0xff00ff00 : 0xd9d9d9))); 322 323 setPropertyValue( 324 maPropertyIdToNameMap[Image_Grip], 325 Any( 326 mbIsHighContrastMode 327 ? A2S("private:graphicrepository/sfx2/res/grip_hc.png") 328 : A2S("private:graphicrepository/sfx2/res/grip.png"))); 329 setPropertyValue( 330 maPropertyIdToNameMap[Image_Expand], 331 Any( 332 mbIsHighContrastMode 333 ? A2S("private:graphicrepository/svtools/res/triangle_right_hc.png") 334 : A2S("private:graphicrepository/svtools/res/triangle_right.png"))); 335 // ? A2S("private:graphicrepository/res/plus_sch.png") 336 // : A2S("private:graphicrepository/res/plus.png"))); 337 setPropertyValue( 338 maPropertyIdToNameMap[Image_Collapse], 339 Any( 340 mbIsHighContrastMode 341 ? A2S("private:graphicrepository/svtools/res/triangle_down_hc.png") 342 : A2S("private:graphicrepository/svtools/res/triangle_down.png"))); 343 // ? A2S("private:graphicrepository/res/minus_sch.png") 344 // : A2S("private:graphicrepository/res/minus.png"))); 345 setPropertyValue( 346 maPropertyIdToNameMap[Image_TabBarMenu], 347 Any( 348 mbIsHighContrastMode 349 ? A2S("private:graphicrepository/sfx2/res/menu_hc.png") 350 : A2S("private:graphicrepository/sfx2/res/menu.png"))); 351 setPropertyValue( 352 maPropertyIdToNameMap[Image_PanelMenu], 353 Any( 354 mbIsHighContrastMode 355 ? A2S("private:graphicrepository/res/imh30823.png") 356 : A2S("private:graphicrepository/res/im30823.png"))); 357 setPropertyValue( 358 maPropertyIdToNameMap[Image_Closer], 359 Any(A2S("private:graphicrepository/sfx2/res/closedoc.png"))); 360 setPropertyValue( 361 maPropertyIdToNameMap[Image_ToolBoxItemSeparator], 362 Any( 363 A2S("private:graphicrepository/sfx2/res/separator.png"))); 364 365 // ToolBox 366 setPropertyValue( 367 maPropertyIdToNameMap[Paint_ToolBoxBackground], 368 Any(Tools::VclToAwtGradient(Gradient( 369 GRADIENT_LINEAR, 370 Color(0xf2f2f2), 371 Color(0xfefefe) 372 )))); 373 setPropertyValue( 374 maPropertyIdToNameMap[Paint_ToolBoxBorderTopLeft], 375 mbIsHighContrastMode 376 ? Any(util::Color(sal_uInt32(0x00ff00))) 377 : Any(util::Color(sal_uInt32(0xf2f2f2)))); 378 setPropertyValue( 379 maPropertyIdToNameMap[Paint_ToolBoxBorderCenterCorners], 380 mbIsHighContrastMode 381 ? Any(util::Color(sal_uInt32(0x00ff00))) 382 : Any(util::Color(sal_uInt32(0xf2f2f2)))); 383 setPropertyValue( 384 maPropertyIdToNameMap[Paint_ToolBoxBorderBottomRight], 385 mbIsHighContrastMode 386 ? Any(util::Color(sal_uInt32(0x00ff00))) 387 : Any(util::Color(sal_uInt32(0xf2f2f2)))); 388 setPropertyValue( 389 maPropertyIdToNameMap[Rect_ToolBoxPadding], 390 Any(awt::Rectangle(2,2,2,2))); 391 setPropertyValue( 392 maPropertyIdToNameMap[Rect_ToolBoxBorder], 393 Any(awt::Rectangle(1,1,1,1))); 394 setPropertyValue( 395 maPropertyIdToNameMap[Bool_UseToolBoxItemSeparator], 396 Any(false)); 397 } 398 catch(beans::UnknownPropertyException& rException) 399 { 400 OSL_TRACE("unknown property: %s", 401 OUStringToOString( 402 rException.Message, 403 RTL_TEXTENCODING_ASCII_US).getStr()); 404 OSL_ASSERT(false); 405 } 406 } 407 408 409 410 411 void SAL_CALL Theme::disposing (void) 412 { 413 ChangeListeners aListeners; 414 maChangeListeners.swap(aListeners); 415 416 const lang::EventObject aEvent (static_cast<XWeak*>(this)); 417 418 for (ChangeListeners::const_iterator 419 iContainer(maChangeListeners.begin()), 420 iContainerEnd(maChangeListeners.end()); 421 iContainerEnd!=iContainerEnd; 422 ++iContainerEnd) 423 { 424 for (ChangeListenerContainer::const_iterator 425 iListener(iContainer->second.begin()), 426 iEnd(iContainer->second.end()); 427 iListener!=iEnd; 428 ++iListener) 429 { 430 try 431 { 432 (*iListener)->disposing(aEvent); 433 } 434 catch(const Exception&) 435 { 436 } 437 } 438 } 439 } 440 441 442 443 444 Reference<beans::XPropertySet> Theme::GetPropertySet (void) 445 { 446 return Reference<beans::XPropertySet>(static_cast<XWeak*>(&GetCurrentTheme()), UNO_QUERY); 447 } 448 449 450 451 452 Reference<beans::XPropertySetInfo> SAL_CALL Theme::getPropertySetInfo (void) 453 throw(cssu::RuntimeException) 454 { 455 return Reference<beans::XPropertySetInfo>(this); 456 } 457 458 459 460 461 void SAL_CALL Theme::setPropertyValue ( 462 const ::rtl::OUString& rsPropertyName, 463 const cssu::Any& rValue) 464 throw(cssu::RuntimeException) 465 { 466 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName)); 467 if (iId == maPropertyNameToIdMap.end()) 468 throw beans::UnknownPropertyException(rsPropertyName, NULL); 469 470 const PropertyType eType (GetPropertyType(iId->second)); 471 if (eType == PT_Invalid) 472 throw beans::UnknownPropertyException(rsPropertyName, NULL); 473 474 const ThemeItem eItem (iId->second); 475 476 if (rValue == maRawValues[eItem]) 477 { 478 // Value is not different from the one in the property 479 // set => nothing to do. 480 return; 481 } 482 483 const Any aOldValue (maRawValues[eItem]); 484 485 const beans::PropertyChangeEvent aEvent( 486 static_cast<XWeak*>(this), 487 rsPropertyName, 488 sal_False, 489 eItem, 490 aOldValue, 491 rValue); 492 493 if (DoVetoableListenersVeto(GetVetoableListeners(__AnyItem, false), aEvent)) 494 return; 495 if (DoVetoableListenersVeto(GetVetoableListeners(eItem, false), aEvent)) 496 return; 497 498 maRawValues[eItem] = rValue; 499 ProcessNewValue(rValue, eItem, eType); 500 501 BroadcastPropertyChange(GetChangeListeners(__AnyItem, false), aEvent); 502 BroadcastPropertyChange(GetChangeListeners(eItem, false), aEvent); 503 } 504 505 506 507 508 Any SAL_CALL Theme::getPropertyValue ( 509 const ::rtl::OUString& rsPropertyName) 510 throw(css::beans::UnknownPropertyException, 511 css::lang::WrappedTargetException, 512 cssu::RuntimeException) 513 { 514 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName)); 515 if (iId == maPropertyNameToIdMap.end()) 516 throw beans::UnknownPropertyException(); 517 518 const PropertyType eType (GetPropertyType(iId->second)); 519 if (eType == PT_Invalid) 520 throw beans::UnknownPropertyException(); 521 522 const ThemeItem eItem (iId->second); 523 524 return maRawValues[eItem]; 525 } 526 527 528 529 530 void SAL_CALL Theme::addPropertyChangeListener( 531 const ::rtl::OUString& rsPropertyName, 532 const cssu::Reference<css::beans::XPropertyChangeListener>& rxListener) 533 throw(css::beans::UnknownPropertyException, 534 css::lang::WrappedTargetException, 535 cssu::RuntimeException) 536 { 537 ThemeItem eItem (__AnyItem); 538 if (rsPropertyName.getLength() > 0) 539 { 540 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName)); 541 if (iId == maPropertyNameToIdMap.end()) 542 throw beans::UnknownPropertyException(); 543 544 const PropertyType eType (GetPropertyType(iId->second)); 545 if (eType == PT_Invalid) 546 throw beans::UnknownPropertyException(); 547 548 eItem = iId->second; 549 } 550 ChangeListenerContainer* pListeners = GetChangeListeners(eItem, true); 551 if (pListeners != NULL) 552 pListeners->push_back(rxListener); 553 } 554 555 556 557 558 void SAL_CALL Theme::removePropertyChangeListener( 559 const ::rtl::OUString& rsPropertyName, 560 const cssu::Reference<css::beans::XPropertyChangeListener>& rxListener) 561 throw(css::beans::UnknownPropertyException, 562 css::lang::WrappedTargetException, 563 cssu::RuntimeException) 564 { 565 ThemeItem eItem (__AnyItem); 566 if (rsPropertyName.getLength() > 0) 567 { 568 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName)); 569 if (iId == maPropertyNameToIdMap.end()) 570 throw beans::UnknownPropertyException(); 571 572 const PropertyType eType (GetPropertyType(iId->second)); 573 if (eType == PT_Invalid) 574 throw beans::UnknownPropertyException(); 575 576 eItem = iId->second; 577 } 578 ChangeListenerContainer* pContainer = GetChangeListeners(eItem, false); 579 if (pContainer != NULL) 580 { 581 ChangeListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener)); 582 if (iListener != pContainer->end()) 583 { 584 pContainer->erase(iListener); 585 586 // Remove the listener container when empty. 587 if (pContainer->empty()) 588 maChangeListeners.erase(eItem); 589 } 590 } 591 } 592 593 594 595 596 void SAL_CALL Theme::addVetoableChangeListener( 597 const ::rtl::OUString& rsPropertyName, 598 const cssu::Reference<css::beans::XVetoableChangeListener>& rxListener) 599 throw(css::beans::UnknownPropertyException, 600 css::lang::WrappedTargetException, 601 cssu::RuntimeException) 602 { 603 ThemeItem eItem (__AnyItem); 604 if (rsPropertyName.getLength() > 0) 605 { 606 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName)); 607 if (iId == maPropertyNameToIdMap.end()) 608 throw beans::UnknownPropertyException(); 609 610 const PropertyType eType (GetPropertyType(iId->second)); 611 if (eType == PT_Invalid) 612 throw beans::UnknownPropertyException(); 613 614 eItem = iId->second; 615 } 616 VetoableListenerContainer* pListeners = GetVetoableListeners(eItem, true); 617 if (pListeners != NULL) 618 pListeners->push_back(rxListener); 619 } 620 621 622 623 624 void SAL_CALL Theme::removeVetoableChangeListener( 625 const ::rtl::OUString& rsPropertyName, 626 const cssu::Reference<css::beans::XVetoableChangeListener>& rxListener) 627 throw(css::beans::UnknownPropertyException, 628 css::lang::WrappedTargetException, 629 cssu::RuntimeException) 630 { 631 ThemeItem eItem (__AnyItem); 632 if (rsPropertyName.getLength() > 0) 633 { 634 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName)); 635 if (iId == maPropertyNameToIdMap.end()) 636 throw beans::UnknownPropertyException(); 637 638 const PropertyType eType (GetPropertyType(iId->second)); 639 if (eType == PT_Invalid) 640 throw beans::UnknownPropertyException(); 641 642 eItem = iId->second; 643 } 644 VetoableListenerContainer* pContainer = GetVetoableListeners(eItem, false); 645 if (pContainer != NULL) 646 { 647 VetoableListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener)); 648 if (iListener != pContainer->end()) 649 { 650 pContainer->erase(iListener); 651 // Remove container when empty. 652 if (pContainer->empty()) 653 maVetoableListeners.erase(eItem); 654 } 655 } 656 } 657 658 659 660 661 cssu::Sequence<css::beans::Property> SAL_CALL Theme::getProperties (void) 662 throw(cssu::RuntimeException) 663 { 664 ::std::vector<beans::Property> aProperties; 665 666 for (sal_Int32 nItem(__Begin),nEnd(__End); nItem!=nEnd; ++nItem) 667 { 668 const ThemeItem eItem (static_cast<ThemeItem>(nItem)); 669 const PropertyType eType (GetPropertyType(eItem)); 670 if (eType == PT_Invalid) 671 continue; 672 673 const beans::Property aProperty( 674 maPropertyIdToNameMap[eItem], 675 eItem, 676 GetCppuType(eType), 677 0); 678 aProperties.push_back(aProperty); 679 } 680 681 return cssu::Sequence<css::beans::Property>( 682 &aProperties.front(), 683 aProperties.size()); 684 } 685 686 687 688 689 beans::Property SAL_CALL Theme::getPropertyByName (const ::rtl::OUString& rsPropertyName) 690 throw(css::beans::UnknownPropertyException, 691 cssu::RuntimeException) 692 { 693 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName)); 694 if (iId == maPropertyNameToIdMap.end()) 695 throw beans::UnknownPropertyException(); 696 697 const PropertyType eType (GetPropertyType(iId->second)); 698 if (eType == PT_Invalid) 699 throw beans::UnknownPropertyException(); 700 701 const ThemeItem eItem (iId->second); 702 703 return beans::Property( 704 rsPropertyName, 705 eItem, 706 GetCppuType(eType), 707 0); 708 } 709 710 711 712 713 sal_Bool SAL_CALL Theme::hasPropertyByName (const ::rtl::OUString& rsPropertyName) 714 throw(cssu::RuntimeException) 715 { 716 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName)); 717 if (iId == maPropertyNameToIdMap.end()) 718 return sal_False; 719 720 const PropertyType eType (GetPropertyType(iId->second)); 721 if (eType == PT_Invalid) 722 return sal_False; 723 724 return sal_True; 725 } 726 727 728 729 730 void Theme::SetupPropertyMaps (void) 731 { 732 maPropertyIdToNameMap.resize(__Post_Rect); 733 maImages.resize(__Image_Color - __Pre_Image - 1); 734 maColors.resize(__Color_Paint - __Image_Color - 1); 735 maPaints.resize(__Paint_Int - __Color_Paint - 1); 736 maIntegers.resize(__Int_Bool - __Paint_Int - 1); 737 maBooleans.resize(__Bool_Rect - __Int_Bool - 1); 738 maRectangles.resize(__Post_Rect - __Bool_Rect - 1); 739 740 #define AddEntry(e) maPropertyNameToIdMap[A2S(#e)]=e; maPropertyIdToNameMap[e]=A2S(#e) 741 742 AddEntry(Image_Grip); 743 AddEntry(Image_Expand); 744 AddEntry(Image_Collapse); 745 AddEntry(Image_TabBarMenu); 746 AddEntry(Image_PanelMenu); 747 AddEntry(Image_ToolBoxItemSeparator); 748 AddEntry(Image_Closer); 749 750 AddEntry(Color_DeckTitleFont); 751 AddEntry(Color_PanelTitleFont); 752 AddEntry(Color_TabMenuSeparator); 753 AddEntry(Color_TabItemBorder); 754 755 AddEntry(Paint_DeckBackground); 756 AddEntry(Paint_DeckTitleBarBackground); 757 AddEntry(Paint_PanelBackground); 758 AddEntry(Paint_PanelTitleBarBackground); 759 AddEntry(Paint_TabBarBackground); 760 AddEntry(Paint_TabItemBackgroundNormal); 761 AddEntry(Paint_TabItemBackgroundHighlight); 762 AddEntry(Paint_HorizontalBorder); 763 AddEntry(Paint_VerticalBorder); 764 AddEntry(Paint_ToolBoxBackground); 765 AddEntry(Paint_ToolBoxBorderTopLeft); 766 AddEntry(Paint_ToolBoxBorderCenterCorners); 767 AddEntry(Paint_ToolBoxBorderBottomRight); 768 769 AddEntry(Int_DeckTitleBarHeight); 770 AddEntry(Int_DeckBorderSize); 771 AddEntry(Int_DeckSeparatorHeight); 772 AddEntry(Int_PanelTitleBarHeight); 773 AddEntry(Int_TabMenuPadding); 774 AddEntry(Int_TabMenuSeparatorPadding); 775 AddEntry(Int_TabItemWidth); 776 AddEntry(Int_TabItemHeight); 777 AddEntry(Int_DeckLeftPadding); 778 AddEntry(Int_DeckTopPadding); 779 AddEntry(Int_DeckRightPadding); 780 AddEntry(Int_DeckBottomPadding); 781 AddEntry(Int_TabBarLeftPadding); 782 AddEntry(Int_TabBarTopPadding); 783 AddEntry(Int_TabBarRightPadding); 784 AddEntry(Int_TabBarBottomPadding); 785 786 AddEntry(Bool_UseSymphonyIcons); 787 AddEntry(Bool_UseSystemColors); 788 AddEntry(Bool_UseToolBoxItemSeparator); 789 AddEntry(Bool_IsHighContrastModeActive); 790 791 AddEntry(Rect_ToolBoxPadding); 792 AddEntry(Rect_ToolBoxBorder); 793 794 #undef AddEntry 795 796 maRawValues.resize(maPropertyIdToNameMap.size()); 797 } 798 799 800 801 802 Theme::PropertyType Theme::GetPropertyType (const ThemeItem eItem) 803 { 804 switch(eItem) 805 { 806 case Image_Grip: 807 case Image_Expand: 808 case Image_Collapse: 809 case Image_TabBarMenu: 810 case Image_PanelMenu: 811 case Image_ToolBoxItemSeparator: 812 case Image_Closer: 813 return PT_Image; 814 815 case Color_DeckTitleFont: 816 case Color_PanelTitleFont: 817 case Color_TabMenuSeparator: 818 case Color_TabItemBorder: 819 return PT_Color; 820 821 case Paint_DeckBackground: 822 case Paint_DeckTitleBarBackground: 823 case Paint_PanelBackground: 824 case Paint_PanelTitleBarBackground: 825 case Paint_TabBarBackground: 826 case Paint_TabItemBackgroundNormal: 827 case Paint_TabItemBackgroundHighlight: 828 case Paint_HorizontalBorder: 829 case Paint_VerticalBorder: 830 case Paint_ToolBoxBackground: 831 case Paint_ToolBoxBorderTopLeft: 832 case Paint_ToolBoxBorderCenterCorners: 833 case Paint_ToolBoxBorderBottomRight: 834 return PT_Paint; 835 836 case Int_DeckTitleBarHeight: 837 case Int_DeckBorderSize: 838 case Int_DeckSeparatorHeight: 839 case Int_PanelTitleBarHeight: 840 case Int_TabMenuPadding: 841 case Int_TabMenuSeparatorPadding: 842 case Int_TabItemWidth: 843 case Int_TabItemHeight: 844 case Int_DeckLeftPadding: 845 case Int_DeckTopPadding: 846 case Int_DeckRightPadding: 847 case Int_DeckBottomPadding: 848 case Int_TabBarLeftPadding: 849 case Int_TabBarTopPadding: 850 case Int_TabBarRightPadding: 851 case Int_TabBarBottomPadding: 852 return PT_Integer; 853 854 case Bool_UseSymphonyIcons: 855 case Bool_UseSystemColors: 856 case Bool_UseToolBoxItemSeparator: 857 case Bool_IsHighContrastModeActive: 858 return PT_Boolean; 859 860 case Rect_ToolBoxBorder: 861 case Rect_ToolBoxPadding: 862 return PT_Rectangle; 863 864 default: 865 return PT_Invalid; 866 } 867 } 868 869 870 871 872 cssu::Type Theme::GetCppuType (const PropertyType eType) 873 { 874 switch(eType) 875 { 876 case PT_Image: 877 return getCppuType((rtl::OUString*)NULL); 878 879 case PT_Color: 880 return getCppuType((sal_uInt32*)NULL); 881 882 case PT_Paint: 883 return getCppuVoidType(); 884 885 case PT_Integer: 886 return getCppuType((sal_Int32*)NULL); 887 888 case PT_Boolean: 889 return getCppuType((sal_Bool*)NULL); 890 891 case PT_Rectangle: 892 return getCppuType((awt::Rectangle*)NULL); 893 894 case PT_Invalid: 895 default: 896 return getCppuVoidType(); 897 } 898 } 899 900 901 902 903 sal_Int32 Theme::GetIndex (const ThemeItem eItem, const PropertyType eType) 904 { 905 switch(eType) 906 { 907 case PT_Image: 908 return eItem - __Pre_Image-1; 909 case PT_Color: 910 return eItem - __Image_Color-1; 911 case PT_Paint: 912 return eItem - __Color_Paint-1; 913 case PT_Integer: 914 return eItem - __Paint_Int-1; 915 case PT_Boolean: 916 return eItem - __Int_Bool-1; 917 case PT_Rectangle: 918 return eItem - __Bool_Rect-1; 919 920 default: 921 OSL_ASSERT(false); 922 return 0; 923 } 924 } 925 926 927 928 929 Theme::VetoableListenerContainer* Theme::GetVetoableListeners ( 930 const ThemeItem eItem, 931 const bool bCreate) 932 { 933 VetoableListeners::iterator iContainer (maVetoableListeners.find(eItem)); 934 if (iContainer != maVetoableListeners.end()) 935 return &iContainer->second; 936 else if (bCreate) 937 { 938 maVetoableListeners[eItem] = VetoableListenerContainer(); 939 return &maVetoableListeners[eItem]; 940 } 941 else 942 return NULL; 943 } 944 945 946 947 948 Theme::ChangeListenerContainer* Theme::GetChangeListeners ( 949 const ThemeItem eItem, 950 const bool bCreate) 951 { 952 ChangeListeners::iterator iContainer (maChangeListeners.find(eItem)); 953 if (iContainer != maChangeListeners.end()) 954 return &iContainer->second; 955 else if (bCreate) 956 { 957 maChangeListeners[eItem] = ChangeListenerContainer(); 958 return &maChangeListeners[eItem]; 959 } 960 else 961 return NULL; 962 } 963 964 965 966 967 bool Theme::DoVetoableListenersVeto ( 968 const VetoableListenerContainer* pListeners, 969 const beans::PropertyChangeEvent& rEvent) const 970 { 971 if (pListeners == NULL) 972 return false; 973 974 VetoableListenerContainer aListeners (*pListeners); 975 try 976 { 977 for (VetoableListenerContainer::const_iterator 978 iListener(aListeners.begin()), 979 iEnd(aListeners.end()); 980 iListener!=iEnd; 981 ++iListener) 982 { 983 (*iListener)->vetoableChange(rEvent); 984 } 985 } 986 catch(const beans::PropertyVetoException&) 987 { 988 return true; 989 } 990 catch(const Exception&) 991 { 992 // Ignore any other errors (such as disposed listeners). 993 } 994 return false; 995 } 996 997 998 999 1000 void Theme::BroadcastPropertyChange ( 1001 const ChangeListenerContainer* pListeners, 1002 const beans::PropertyChangeEvent& rEvent) const 1003 { 1004 if (pListeners == NULL) 1005 return; 1006 1007 const ChangeListenerContainer aListeners (*pListeners); 1008 try 1009 { 1010 for (ChangeListenerContainer::const_iterator 1011 iListener(aListeners.begin()), 1012 iEnd(aListeners.end()); 1013 iListener!=iEnd; 1014 ++iListener) 1015 { 1016 (*iListener)->propertyChange(rEvent); 1017 } 1018 } 1019 catch(const Exception&) 1020 { 1021 // Ignore any errors (such as disposed listeners). 1022 } 1023 } 1024 1025 1026 1027 1028 void Theme::ProcessNewValue ( 1029 const Any& rValue, 1030 const ThemeItem eItem, 1031 const PropertyType eType) 1032 { 1033 const sal_Int32 nIndex (GetIndex (eItem, eType)); 1034 switch (eType) 1035 { 1036 case PT_Image: 1037 { 1038 ::rtl::OUString sURL; 1039 if (rValue >>= sURL) 1040 { 1041 maImages[nIndex] = Tools::GetImage(sURL, NULL); 1042 } 1043 break; 1044 } 1045 case PT_Color: 1046 { 1047 sal_Int32 nColorValue (0); 1048 if (rValue >>= nColorValue) 1049 { 1050 maColors[nIndex] = Color(nColorValue); 1051 } 1052 break; 1053 } 1054 case PT_Paint: 1055 { 1056 maPaints[nIndex] = Paint::Create(rValue); 1057 break; 1058 } 1059 case PT_Integer: 1060 { 1061 sal_Int32 nValue (0); 1062 if (rValue >>= nValue) 1063 { 1064 maIntegers[nIndex] = nValue; 1065 } 1066 break; 1067 } 1068 case PT_Boolean: 1069 { 1070 sal_Bool nValue (0); 1071 if (rValue >>= nValue) 1072 { 1073 maBooleans[nIndex] = (nValue==sal_True); 1074 if (eItem == Bool_IsHighContrastModeActive) 1075 { 1076 mbIsHighContrastModeSetManually = true; 1077 mbIsHighContrastMode = maBooleans[nIndex]; 1078 HandleDataChange(); 1079 } 1080 else if (eItem == Bool_UseSystemColors) 1081 { 1082 HandleDataChange(); 1083 } 1084 } 1085 break; 1086 } 1087 case PT_Rectangle: 1088 { 1089 awt::Rectangle aBox; 1090 if (rValue >>= aBox) 1091 { 1092 maRectangles[nIndex] = Rectangle( 1093 aBox.X, 1094 aBox.Y, 1095 aBox.Width, 1096 aBox.Height); 1097 } 1098 break; 1099 } 1100 case PT_Invalid: 1101 OSL_ASSERT(eType != PT_Invalid); 1102 throw RuntimeException(); 1103 } 1104 } 1105 1106 1107 1108 1109 } } // end of namespace sfx2::sidebar 1110