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