bump product version to 4.1.6.2
[LibreOffice.git] / sfx2 / source / sidebar / Theme.cxx
blob967adc76b1bb68f9d6e63db0f0880bdcc1c13375
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 #include "sfx2/sidebar/Theme.hxx"
19 #include "Paint.hxx"
20 #include "SidebarResource.hxx"
21 #include "sfx2/sidebar/Tools.hxx"
23 #include <tools/svborder.hxx>
24 #include <tools/rc.hxx>
25 #include <vcl/svapp.hxx>
27 using namespace css;
28 using namespace cssu;
31 namespace sfx2 { namespace sidebar {
33 ::rtl::Reference<Theme> Theme::mpInstance;
38 Theme& Theme::GetCurrentTheme (void)
40 if ( ! mpInstance.is())
42 mpInstance.set(new Theme());
43 mpInstance->InitializeTheme();
45 return *mpInstance;
51 Theme::Theme (void)
52 : ThemeInterfaceBase(m_aMutex),
53 maImages(),
54 maColors(),
55 maPaints(),
56 maIntegers(),
57 maBooleans(),
58 mbIsHighContrastMode(Application::GetSettings().GetStyleSettings().GetHighContrastMode()),
59 mbIsHighContrastModeSetManually(false),
60 maPropertyNameToIdMap(),
61 maPropertyIdToNameMap(),
62 maRawValues(),
63 maChangeListeners(),
64 maVetoableListeners()
67 SetupPropertyMaps();
73 Theme::~Theme (void)
80 Image Theme::GetImage (const ThemeItem eItem)
82 const PropertyType eType (GetPropertyType(eItem));
83 OSL_ASSERT(eType==PT_Image);
84 const sal_Int32 nIndex (GetIndex(eItem, eType));
85 const Theme& rTheme (GetCurrentTheme());
86 return rTheme.maImages[nIndex];
92 Color Theme::GetColor (const ThemeItem eItem)
94 const PropertyType eType (GetPropertyType(eItem));
95 OSL_ASSERT(eType==PT_Color || eType==PT_Paint);
96 const sal_Int32 nIndex (GetIndex(eItem, eType));
97 const Theme& rTheme (GetCurrentTheme());
98 if (eType == PT_Color)
99 return rTheme.maColors[nIndex];
100 else if (eType == PT_Paint)
101 return rTheme.maPaints[nIndex].GetColor();
102 else
103 return COL_WHITE;
109 const Paint& Theme::GetPaint (const ThemeItem eItem)
111 const PropertyType eType (GetPropertyType(eItem));
112 OSL_ASSERT(eType==PT_Paint);
113 const sal_Int32 nIndex (GetIndex(eItem, eType));
114 const Theme& rTheme (GetCurrentTheme());
115 return rTheme.maPaints[nIndex];
121 const Wallpaper Theme::GetWallpaper (const ThemeItem eItem)
123 return GetPaint(eItem).GetWallpaper();
129 sal_Int32 Theme::GetInteger (const ThemeItem eItem)
131 const PropertyType eType (GetPropertyType(eItem));
132 OSL_ASSERT(eType==PT_Integer);
133 const sal_Int32 nIndex (GetIndex(eItem, eType));
134 const Theme& rTheme (GetCurrentTheme());
135 return rTheme.maIntegers[nIndex];
141 bool Theme::GetBoolean (const ThemeItem eItem)
143 const PropertyType eType (GetPropertyType(eItem));
144 OSL_ASSERT(eType==PT_Boolean);
145 const sal_Int32 nIndex (GetIndex(eItem, eType));
146 const Theme& rTheme (GetCurrentTheme());
147 return rTheme.maBooleans[nIndex];
153 Rectangle Theme::GetRectangle (const ThemeItem eItem)
155 const PropertyType eType (GetPropertyType(eItem));
156 OSL_ASSERT(eType==PT_Rectangle);
157 const sal_Int32 nIndex (GetIndex(eItem, eType));
158 const Theme& rTheme (GetCurrentTheme());
159 return rTheme.maRectangles[nIndex];
165 bool Theme::IsHighContrastMode (void)
167 const Theme& rTheme (GetCurrentTheme());
168 return rTheme.mbIsHighContrastMode;
174 void Theme::HandleDataChange (void)
176 Theme& rTheme (GetCurrentTheme());
178 if ( ! rTheme.mbIsHighContrastModeSetManually)
180 // Do not modify mbIsHighContrastMode when it was manually set.
181 GetCurrentTheme().mbIsHighContrastMode = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
182 rTheme.maRawValues[Bool_IsHighContrastModeActive] = Any(GetCurrentTheme().mbIsHighContrastMode);
185 GetCurrentTheme().UpdateTheme();
191 void Theme::InitializeTheme (void)
193 setPropertyValue(
194 maPropertyIdToNameMap[Bool_UseSymphonyIcons],
195 Any(false));
196 setPropertyValue(
197 maPropertyIdToNameMap[Bool_UseSystemColors],
198 Any(false));
204 void Theme::UpdateTheme (void)
206 SidebarResource aLocalResource;
210 const StyleSettings& rStyle (Application::GetSettings().GetStyleSettings());
211 const bool bUseSystemColors (GetBoolean(Bool_UseSystemColors));
213 #define Alternatives(n,hc,sys) (mbIsHighContrastMode ? hc : (bUseSystemColors ? sys : n))
215 Color aBaseBackgroundColor (rStyle.GetDialogColor());
216 // UX says this should be a little brighter, but that looks off when compared to the other windows.
217 //aBaseBackgroundColor.IncreaseLuminance(7);
218 Color aBorderColor (aBaseBackgroundColor);
219 aBorderColor.DecreaseLuminance(15);
220 Color aSecondColor (aBaseBackgroundColor);
221 aSecondColor.DecreaseLuminance(15);
223 setPropertyValue(
224 maPropertyIdToNameMap[Paint_DeckBackground],
225 Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
227 setPropertyValue(
228 maPropertyIdToNameMap[Paint_DeckTitleBarBackground],
229 Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
230 setPropertyValue(
231 maPropertyIdToNameMap[Int_DeckLeftPadding],
232 Any(sal_Int32(2)));
233 setPropertyValue(
234 maPropertyIdToNameMap[Int_DeckTopPadding],
235 Any(sal_Int32(2)));
236 setPropertyValue(
237 maPropertyIdToNameMap[Int_DeckRightPadding],
238 Any(sal_Int32(2)));
239 setPropertyValue(
240 maPropertyIdToNameMap[Int_DeckBottomPadding],
241 Any(sal_Int32(2)));
242 setPropertyValue(
243 maPropertyIdToNameMap[Int_DeckBorderSize],
244 Any(sal_Int32(1)));
245 setPropertyValue(
246 maPropertyIdToNameMap[Int_DeckSeparatorHeight],
247 Any(sal_Int32(1)));
248 setPropertyValue(
249 maPropertyIdToNameMap[Int_ButtonCornerRadius],
250 Any(sal_Int32(3)));
251 setPropertyValue(
252 maPropertyIdToNameMap[Color_DeckTitleFont],
253 Any(sal_Int32(rStyle.GetFontColor().GetRGBColor())));
254 setPropertyValue(
255 maPropertyIdToNameMap[Int_DeckTitleBarHeight],
256 Any(sal_Int32(Alternatives(
259 rStyle.GetFloatTitleHeight()))));
260 setPropertyValue(
261 maPropertyIdToNameMap[Paint_PanelBackground],
262 Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
264 setPropertyValue(
265 maPropertyIdToNameMap[Paint_PanelTitleBarBackground],
266 Any(Tools::VclToAwtGradient(Gradient(
267 GradientStyle_LINEAR,
268 aSecondColor.GetRGBColor(),
269 aBaseBackgroundColor.GetRGBColor()
270 ))));
271 setPropertyValue(
272 maPropertyIdToNameMap[Color_PanelTitleFont],
273 Any(sal_Int32(mbIsHighContrastMode ? 0x00ff00 : 0x262626)));
274 setPropertyValue(
275 maPropertyIdToNameMap[Int_PanelTitleBarHeight],
276 Any(sal_Int32(Alternatives(
279 rStyle.GetTitleHeight()))));
280 setPropertyValue(
281 maPropertyIdToNameMap[Paint_TabBarBackground],
282 Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
283 setPropertyValue(
284 maPropertyIdToNameMap[Int_TabBarLeftPadding],
285 Any(sal_Int32(2)));
286 setPropertyValue(
287 maPropertyIdToNameMap[Int_TabBarTopPadding],
288 Any(sal_Int32(2)));
289 setPropertyValue(
290 maPropertyIdToNameMap[Int_TabBarRightPadding],
291 Any(sal_Int32(2)));
292 setPropertyValue(
293 maPropertyIdToNameMap[Int_TabBarBottomPadding],
294 Any(sal_Int32(2)));
296 setPropertyValue(
297 maPropertyIdToNameMap[Int_TabMenuPadding],
298 Any(sal_Int32(6)));
299 setPropertyValue(
300 maPropertyIdToNameMap[Color_TabMenuSeparator],
301 Any(sal_Int32(aBorderColor.GetRGBColor())));
302 setPropertyValue(
303 maPropertyIdToNameMap[Int_TabMenuSeparatorPadding],
304 Any(sal_Int32(7)));
306 setPropertyValue(
307 maPropertyIdToNameMap[Int_TabItemWidth],
308 Any(sal_Int32(32)));
309 setPropertyValue(
310 maPropertyIdToNameMap[Int_TabItemHeight],
311 Any(sal_Int32(32)));
312 setPropertyValue(
313 maPropertyIdToNameMap[Color_TabItemBorder],
314 Any(sal_Int32(rStyle.GetActiveBorderColor().GetRGBColor())));
315 // mbIsHighContrastMode ? 0x00ff00 : 0xbfbfbf)));
317 setPropertyValue(
318 maPropertyIdToNameMap[Paint_DropDownBackground],
319 Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
320 setPropertyValue(
321 maPropertyIdToNameMap[Color_DropDownBorder],
322 Any(sal_Int32(rStyle.GetActiveBorderColor().GetRGBColor())));
324 setPropertyValue(
325 maPropertyIdToNameMap[Color_Highlight],
326 Any(sal_Int32(rStyle.GetHighlightColor().GetRGBColor())));
327 setPropertyValue(
328 maPropertyIdToNameMap[Color_HighlightText],
329 Any(sal_Int32(rStyle.GetHighlightTextColor().GetRGBColor())));
331 setPropertyValue(
332 maPropertyIdToNameMap[Paint_TabItemBackgroundNormal],
333 Any());
334 setPropertyValue(
335 maPropertyIdToNameMap[Paint_TabItemBackgroundHighlight],
336 Any(sal_Int32(rStyle.GetActiveTabColor().GetRGBColor())));
337 // mbIsHighContrastMode ? 0x000000 : 0x00ffffff)));
339 setPropertyValue(
340 maPropertyIdToNameMap[Paint_HorizontalBorder],
341 Any(sal_Int32(aBorderColor.GetRGBColor())));
342 // mbIsHighContrastMode ? 0x00ff00 : 0xe4e4e4)));
343 setPropertyValue(
344 maPropertyIdToNameMap[Paint_VerticalBorder],
345 Any(sal_Int32(aBorderColor.GetRGBColor())));
346 setPropertyValue(
347 maPropertyIdToNameMap[Image_Grip],
348 Any(A2S("private:graphicrepository/sfx2/res/grip.png")));
349 setPropertyValue(
350 maPropertyIdToNameMap[Image_Expand],
351 Any(A2S("private:graphicrepository/res/plus.png")));
352 setPropertyValue(
353 maPropertyIdToNameMap[Image_Collapse],
354 Any(A2S("private:graphicrepository/res/minus.png")));
355 setPropertyValue(
356 maPropertyIdToNameMap[Image_TabBarMenu],
357 Any(A2S("private:graphicrepository/sfx2/res/symphony/open_more.png")));
358 setPropertyValue(
359 maPropertyIdToNameMap[Image_PanelMenu],
360 Any(A2S("private:graphicrepository/sfx2/res/symphony/morebutton.png")));
361 setPropertyValue(
362 maPropertyIdToNameMap[Image_Closer],
363 Any(A2S("private:graphicrepository/sfx2/res/closedoc.png")));
364 setPropertyValue(
365 maPropertyIdToNameMap[Image_CloseIndicator],
366 Any(A2S("private:graphicrepository/cmd/lc_decrementlevel.png")));
367 setPropertyValue(
368 maPropertyIdToNameMap[Image_ToolBoxItemSeparator],
369 Any(
370 A2S("private:graphicrepository/sfx2/res/separator.png")));
372 // ToolBox
375 // Separator style
376 setPropertyValue(
377 maPropertyIdToNameMap[Paint_ToolBoxBackground],
378 Any(sal_Int32(rStyle.GetMenuColor().GetRGBColor())));
379 setPropertyValue(
380 maPropertyIdToNameMap[Paint_ToolBoxBorderTopLeft],
381 Any());
382 setPropertyValue(
383 maPropertyIdToNameMap[Paint_ToolBoxBorderCenterCorners],
384 Any());
385 setPropertyValue(
386 maPropertyIdToNameMap[Paint_ToolBoxBorderBottomRight],
387 Any());
388 setPropertyValue(
389 maPropertyIdToNameMap[Rect_ToolBoxPadding],
390 Any(awt::Rectangle(2,2,2,2)));
391 setPropertyValue(
392 maPropertyIdToNameMap[Rect_ToolBoxBorder],
393 Any(awt::Rectangle(0,0,0,0)));
394 setPropertyValue(
395 maPropertyIdToNameMap[Bool_UseToolBoxItemSeparator],
396 Any(true));
400 // Gradient style
401 setPropertyValue(
402 maPropertyIdToNameMap[Paint_ToolBoxBackground],
403 Any(Tools::VclToAwtGradient(Gradient(
404 GradientStyle_LINEAR,
405 Color(0xf2f2f2),
406 Color(0xfefefe)
407 ))));
408 setPropertyValue(
409 maPropertyIdToNameMap[Paint_ToolBoxBorderTopLeft],
410 mbIsHighContrastMode
411 ? Any(util::Color(sal_uInt32(0x00ff00)))
412 : Any(util::Color(sal_uInt32(0xf2f2f2))));
413 setPropertyValue(
414 maPropertyIdToNameMap[Paint_ToolBoxBorderCenterCorners],
415 mbIsHighContrastMode
416 ? Any(util::Color(sal_uInt32(0x00ff00)))
417 : Any(util::Color(sal_uInt32(0xf2f2f2))));
418 setPropertyValue(
419 maPropertyIdToNameMap[Paint_ToolBoxBorderBottomRight],
420 mbIsHighContrastMode
421 ? Any(util::Color(sal_uInt32(0x00ff00)))
422 : Any(util::Color(sal_uInt32(0xf2f2f2))));
423 setPropertyValue(
424 maPropertyIdToNameMap[Rect_ToolBoxPadding],
425 Any(awt::Rectangle(2,2,2,2)));
426 setPropertyValue(
427 maPropertyIdToNameMap[Rect_ToolBoxBorder],
428 Any(awt::Rectangle(1,1,1,1)));
429 setPropertyValue(
430 maPropertyIdToNameMap[Bool_UseToolBoxItemSeparator],
431 Any(false));
433 catch(beans::UnknownPropertyException& rException)
435 OSL_TRACE("unknown property: %s",
436 OUStringToOString(
437 rException.Message,
438 RTL_TEXTENCODING_ASCII_US).getStr());
439 OSL_ASSERT(false);
446 void SAL_CALL Theme::disposing (void)
448 ChangeListeners aListeners;
449 maChangeListeners.swap(aListeners);
451 const lang::EventObject aEvent (static_cast<XWeak*>(this));
453 for (ChangeListeners::const_iterator
454 iContainer(maChangeListeners.begin()),
455 iContainerEnd(maChangeListeners.end());
456 iContainerEnd!=iContainerEnd;
457 ++iContainerEnd)
459 for (ChangeListenerContainer::const_iterator
460 iListener(iContainer->second.begin()),
461 iEnd(iContainer->second.end());
462 iListener!=iEnd;
463 ++iListener)
467 (*iListener)->disposing(aEvent);
469 catch(const Exception&)
479 Reference<beans::XPropertySet> Theme::GetPropertySet (void)
481 return Reference<beans::XPropertySet>(static_cast<XWeak*>(&GetCurrentTheme()), UNO_QUERY);
487 Reference<beans::XPropertySetInfo> SAL_CALL Theme::getPropertySetInfo (void)
488 throw(cssu::RuntimeException)
490 return Reference<beans::XPropertySetInfo>(this);
496 void SAL_CALL Theme::setPropertyValue (
497 const ::rtl::OUString& rsPropertyName,
498 const cssu::Any& rValue)
499 throw(cssu::RuntimeException)
501 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
502 if (iId == maPropertyNameToIdMap.end())
503 throw beans::UnknownPropertyException(rsPropertyName, NULL);
505 const PropertyType eType (GetPropertyType(iId->second));
506 if (eType == PT_Invalid)
507 throw beans::UnknownPropertyException(rsPropertyName, NULL);
509 const ThemeItem eItem (iId->second);
511 if (rValue == maRawValues[eItem])
513 // Value is not different from the one in the property
514 // set => nothing to do.
515 return;
518 const Any aOldValue (maRawValues[eItem]);
520 const beans::PropertyChangeEvent aEvent(
521 static_cast<XWeak*>(this),
522 rsPropertyName,
523 sal_False,
524 eItem,
525 aOldValue,
526 rValue);
528 if (DoVetoableListenersVeto(GetVetoableListeners(__AnyItem, false), aEvent))
529 return;
530 if (DoVetoableListenersVeto(GetVetoableListeners(eItem, false), aEvent))
531 return;
533 maRawValues[eItem] = rValue;
534 ProcessNewValue(rValue, eItem, eType);
536 BroadcastPropertyChange(GetChangeListeners(__AnyItem, false), aEvent);
537 BroadcastPropertyChange(GetChangeListeners(eItem, false), aEvent);
543 Any SAL_CALL Theme::getPropertyValue (
544 const ::rtl::OUString& rsPropertyName)
545 throw(css::beans::UnknownPropertyException,
546 css::lang::WrappedTargetException,
547 cssu::RuntimeException)
549 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
550 if (iId == maPropertyNameToIdMap.end())
551 throw beans::UnknownPropertyException();
553 const PropertyType eType (GetPropertyType(iId->second));
554 if (eType == PT_Invalid)
555 throw beans::UnknownPropertyException();
557 const ThemeItem eItem (iId->second);
559 return maRawValues[eItem];
565 void SAL_CALL Theme::addPropertyChangeListener(
566 const ::rtl::OUString& rsPropertyName,
567 const cssu::Reference<css::beans::XPropertyChangeListener>& rxListener)
568 throw(css::beans::UnknownPropertyException,
569 css::lang::WrappedTargetException,
570 cssu::RuntimeException)
572 ThemeItem eItem (__AnyItem);
573 if (rsPropertyName.getLength() > 0)
575 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
576 if (iId == maPropertyNameToIdMap.end())
577 throw beans::UnknownPropertyException();
579 const PropertyType eType (GetPropertyType(iId->second));
580 if (eType == PT_Invalid)
581 throw beans::UnknownPropertyException();
583 eItem = iId->second;
585 ChangeListenerContainer* pListeners = GetChangeListeners(eItem, true);
586 if (pListeners != NULL)
587 pListeners->push_back(rxListener);
593 void SAL_CALL Theme::removePropertyChangeListener(
594 const ::rtl::OUString& rsPropertyName,
595 const cssu::Reference<css::beans::XPropertyChangeListener>& rxListener)
596 throw(css::beans::UnknownPropertyException,
597 css::lang::WrappedTargetException,
598 cssu::RuntimeException)
600 ThemeItem eItem (__AnyItem);
601 if (rsPropertyName.getLength() > 0)
603 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
604 if (iId == maPropertyNameToIdMap.end())
605 throw beans::UnknownPropertyException();
607 const PropertyType eType (GetPropertyType(iId->second));
608 if (eType == PT_Invalid)
609 throw beans::UnknownPropertyException();
611 eItem = iId->second;
613 ChangeListenerContainer* pContainer = GetChangeListeners(eItem, false);
614 if (pContainer != NULL)
616 ChangeListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener));
617 if (iListener != pContainer->end())
619 pContainer->erase(iListener);
621 // Remove the listener container when empty.
622 if (pContainer->empty())
623 maChangeListeners.erase(eItem);
631 void SAL_CALL Theme::addVetoableChangeListener(
632 const ::rtl::OUString& rsPropertyName,
633 const cssu::Reference<css::beans::XVetoableChangeListener>& rxListener)
634 throw(css::beans::UnknownPropertyException,
635 css::lang::WrappedTargetException,
636 cssu::RuntimeException)
638 ThemeItem eItem (__AnyItem);
639 if (rsPropertyName.getLength() > 0)
641 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
642 if (iId == maPropertyNameToIdMap.end())
643 throw beans::UnknownPropertyException();
645 const PropertyType eType (GetPropertyType(iId->second));
646 if (eType == PT_Invalid)
647 throw beans::UnknownPropertyException();
649 eItem = iId->second;
651 VetoableListenerContainer* pListeners = GetVetoableListeners(eItem, true);
652 if (pListeners != NULL)
653 pListeners->push_back(rxListener);
659 void SAL_CALL Theme::removeVetoableChangeListener(
660 const ::rtl::OUString& rsPropertyName,
661 const cssu::Reference<css::beans::XVetoableChangeListener>& rxListener)
662 throw(css::beans::UnknownPropertyException,
663 css::lang::WrappedTargetException,
664 cssu::RuntimeException)
666 ThemeItem eItem (__AnyItem);
667 if (rsPropertyName.getLength() > 0)
669 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
670 if (iId == maPropertyNameToIdMap.end())
671 throw beans::UnknownPropertyException();
673 const PropertyType eType (GetPropertyType(iId->second));
674 if (eType == PT_Invalid)
675 throw beans::UnknownPropertyException();
677 eItem = iId->second;
679 VetoableListenerContainer* pContainer = GetVetoableListeners(eItem, false);
680 if (pContainer != NULL)
682 VetoableListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener));
683 if (iListener != pContainer->end())
685 pContainer->erase(iListener);
686 // Remove container when empty.
687 if (pContainer->empty())
688 maVetoableListeners.erase(eItem);
696 cssu::Sequence<css::beans::Property> SAL_CALL Theme::getProperties (void)
697 throw(cssu::RuntimeException)
699 ::std::vector<beans::Property> aProperties;
701 for (sal_Int32 nItem(__Begin),nEnd(__End); nItem!=nEnd; ++nItem)
703 const ThemeItem eItem (static_cast<ThemeItem>(nItem));
704 const PropertyType eType (GetPropertyType(eItem));
705 if (eType == PT_Invalid)
706 continue;
708 const beans::Property aProperty(
709 maPropertyIdToNameMap[eItem],
710 eItem,
711 GetCppuType(eType),
713 aProperties.push_back(aProperty);
716 return cssu::Sequence<css::beans::Property>(
717 &aProperties.front(),
718 aProperties.size());
724 beans::Property SAL_CALL Theme::getPropertyByName (const ::rtl::OUString& rsPropertyName)
725 throw(css::beans::UnknownPropertyException,
726 cssu::RuntimeException)
728 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
729 if (iId == maPropertyNameToIdMap.end())
730 throw beans::UnknownPropertyException();
732 const PropertyType eType (GetPropertyType(iId->second));
733 if (eType == PT_Invalid)
734 throw beans::UnknownPropertyException();
736 const ThemeItem eItem (iId->second);
738 return beans::Property(
739 rsPropertyName,
740 eItem,
741 GetCppuType(eType),
748 sal_Bool SAL_CALL Theme::hasPropertyByName (const ::rtl::OUString& rsPropertyName)
749 throw(cssu::RuntimeException)
751 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
752 if (iId == maPropertyNameToIdMap.end())
753 return sal_False;
755 const PropertyType eType (GetPropertyType(iId->second));
756 if (eType == PT_Invalid)
757 return sal_False;
759 return sal_True;
765 void Theme::SetupPropertyMaps (void)
767 maPropertyIdToNameMap.resize(__Post_Rect);
768 maImages.resize(__Image_Color - __Pre_Image - 1);
769 maColors.resize(__Color_Paint - __Image_Color - 1);
770 maPaints.resize(__Paint_Int - __Color_Paint - 1);
771 maIntegers.resize(__Int_Bool - __Paint_Int - 1);
772 maBooleans.resize(__Bool_Rect - __Int_Bool - 1);
773 maRectangles.resize(__Post_Rect - __Bool_Rect - 1);
775 #define AddEntry(e) maPropertyNameToIdMap[A2S(#e)]=e; maPropertyIdToNameMap[e]=A2S(#e)
777 AddEntry(Image_Grip);
778 AddEntry(Image_Expand);
779 AddEntry(Image_Collapse);
780 AddEntry(Image_TabBarMenu);
781 AddEntry(Image_PanelMenu);
782 AddEntry(Image_ToolBoxItemSeparator);
783 AddEntry(Image_Closer);
784 AddEntry(Image_CloseIndicator);
786 AddEntry(Color_DeckTitleFont);
787 AddEntry(Color_PanelTitleFont);
788 AddEntry(Color_TabMenuSeparator);
789 AddEntry(Color_TabItemBorder);
790 AddEntry(Color_DropDownBorder);
791 AddEntry(Color_Highlight);
792 AddEntry(Color_HighlightText);
794 AddEntry(Paint_DeckBackground);
795 AddEntry(Paint_DeckTitleBarBackground);
796 AddEntry(Paint_PanelBackground);
797 AddEntry(Paint_PanelTitleBarBackground);
798 AddEntry(Paint_TabBarBackground);
799 AddEntry(Paint_TabItemBackgroundNormal);
800 AddEntry(Paint_TabItemBackgroundHighlight);
801 AddEntry(Paint_HorizontalBorder);
802 AddEntry(Paint_VerticalBorder);
803 AddEntry(Paint_ToolBoxBackground);
804 AddEntry(Paint_ToolBoxBorderTopLeft);
805 AddEntry(Paint_ToolBoxBorderCenterCorners);
806 AddEntry(Paint_ToolBoxBorderBottomRight);
807 AddEntry(Paint_DropDownBackground);
809 AddEntry(Int_DeckTitleBarHeight);
810 AddEntry(Int_DeckBorderSize);
811 AddEntry(Int_DeckSeparatorHeight);
812 AddEntry(Int_PanelTitleBarHeight);
813 AddEntry(Int_TabMenuPadding);
814 AddEntry(Int_TabMenuSeparatorPadding);
815 AddEntry(Int_TabItemWidth);
816 AddEntry(Int_TabItemHeight);
817 AddEntry(Int_DeckLeftPadding);
818 AddEntry(Int_DeckTopPadding);
819 AddEntry(Int_DeckRightPadding);
820 AddEntry(Int_DeckBottomPadding);
821 AddEntry(Int_TabBarLeftPadding);
822 AddEntry(Int_TabBarTopPadding);
823 AddEntry(Int_TabBarRightPadding);
824 AddEntry(Int_TabBarBottomPadding);
825 AddEntry(Int_ButtonCornerRadius);
827 AddEntry(Bool_UseSymphonyIcons);
828 AddEntry(Bool_UseSystemColors);
829 AddEntry(Bool_UseToolBoxItemSeparator);
830 AddEntry(Bool_IsHighContrastModeActive);
832 AddEntry(Rect_ToolBoxPadding);
833 AddEntry(Rect_ToolBoxBorder);
835 #undef AddEntry
837 maRawValues.resize(maPropertyIdToNameMap.size());
843 Theme::PropertyType Theme::GetPropertyType (const ThemeItem eItem)
845 switch(eItem)
847 case Image_Grip:
848 case Image_Expand:
849 case Image_Collapse:
850 case Image_TabBarMenu:
851 case Image_PanelMenu:
852 case Image_ToolBoxItemSeparator:
853 case Image_Closer:
854 case Image_CloseIndicator:
855 return PT_Image;
857 case Color_DeckTitleFont:
858 case Color_PanelTitleFont:
859 case Color_TabMenuSeparator:
860 case Color_TabItemBorder:
861 case Color_DropDownBorder:
862 case Color_Highlight:
863 case Color_HighlightText:
864 return PT_Color;
866 case Paint_DeckBackground:
867 case Paint_DeckTitleBarBackground:
868 case Paint_PanelBackground:
869 case Paint_PanelTitleBarBackground:
870 case Paint_TabBarBackground:
871 case Paint_TabItemBackgroundNormal:
872 case Paint_TabItemBackgroundHighlight:
873 case Paint_HorizontalBorder:
874 case Paint_VerticalBorder:
875 case Paint_ToolBoxBackground:
876 case Paint_ToolBoxBorderTopLeft:
877 case Paint_ToolBoxBorderCenterCorners:
878 case Paint_ToolBoxBorderBottomRight:
879 case Paint_DropDownBackground:
880 return PT_Paint;
882 case Int_DeckTitleBarHeight:
883 case Int_DeckBorderSize:
884 case Int_DeckSeparatorHeight:
885 case Int_PanelTitleBarHeight:
886 case Int_TabMenuPadding:
887 case Int_TabMenuSeparatorPadding:
888 case Int_TabItemWidth:
889 case Int_TabItemHeight:
890 case Int_DeckLeftPadding:
891 case Int_DeckTopPadding:
892 case Int_DeckRightPadding:
893 case Int_DeckBottomPadding:
894 case Int_TabBarLeftPadding:
895 case Int_TabBarTopPadding:
896 case Int_TabBarRightPadding:
897 case Int_TabBarBottomPadding:
898 case Int_ButtonCornerRadius:
899 return PT_Integer;
901 case Bool_UseSymphonyIcons:
902 case Bool_UseSystemColors:
903 case Bool_UseToolBoxItemSeparator:
904 case Bool_IsHighContrastModeActive:
905 return PT_Boolean;
907 case Rect_ToolBoxBorder:
908 case Rect_ToolBoxPadding:
909 return PT_Rectangle;
911 default:
912 return PT_Invalid;
919 cssu::Type Theme::GetCppuType (const PropertyType eType)
921 switch(eType)
923 case PT_Image:
924 return getCppuType((rtl::OUString*)NULL);
926 case PT_Color:
927 return getCppuType((sal_uInt32*)NULL);
929 case PT_Paint:
930 return getCppuVoidType();
932 case PT_Integer:
933 return getCppuType((sal_Int32*)NULL);
935 case PT_Boolean:
936 return getCppuType((sal_Bool*)NULL);
938 case PT_Rectangle:
939 return getCppuType((awt::Rectangle*)NULL);
941 case PT_Invalid:
942 default:
943 return getCppuVoidType();
950 sal_Int32 Theme::GetIndex (const ThemeItem eItem, const PropertyType eType)
952 switch(eType)
954 case PT_Image:
955 return eItem - __Pre_Image-1;
956 case PT_Color:
957 return eItem - __Image_Color-1;
958 case PT_Paint:
959 return eItem - __Color_Paint-1;
960 case PT_Integer:
961 return eItem - __Paint_Int-1;
962 case PT_Boolean:
963 return eItem - __Int_Bool-1;
964 case PT_Rectangle:
965 return eItem - __Bool_Rect-1;
967 default:
968 OSL_ASSERT(false);
969 return 0;
976 Theme::VetoableListenerContainer* Theme::GetVetoableListeners (
977 const ThemeItem eItem,
978 const bool bCreate)
980 VetoableListeners::iterator iContainer (maVetoableListeners.find(eItem));
981 if (iContainer != maVetoableListeners.end())
982 return &iContainer->second;
983 else if (bCreate)
985 maVetoableListeners[eItem] = VetoableListenerContainer();
986 return &maVetoableListeners[eItem];
988 else
989 return NULL;
995 Theme::ChangeListenerContainer* Theme::GetChangeListeners (
996 const ThemeItem eItem,
997 const bool bCreate)
999 ChangeListeners::iterator iContainer (maChangeListeners.find(eItem));
1000 if (iContainer != maChangeListeners.end())
1001 return &iContainer->second;
1002 else if (bCreate)
1004 maChangeListeners[eItem] = ChangeListenerContainer();
1005 return &maChangeListeners[eItem];
1007 else
1008 return NULL;
1014 bool Theme::DoVetoableListenersVeto (
1015 const VetoableListenerContainer* pListeners,
1016 const beans::PropertyChangeEvent& rEvent) const
1018 if (pListeners == NULL)
1019 return false;
1021 VetoableListenerContainer aListeners (*pListeners);
1024 for (VetoableListenerContainer::const_iterator
1025 iListener(aListeners.begin()),
1026 iEnd(aListeners.end());
1027 iListener!=iEnd;
1028 ++iListener)
1030 (*iListener)->vetoableChange(rEvent);
1033 catch(const beans::PropertyVetoException&)
1035 return true;
1037 catch(const Exception&)
1039 // Ignore any other errors (such as disposed listeners).
1041 return false;
1047 void Theme::BroadcastPropertyChange (
1048 const ChangeListenerContainer* pListeners,
1049 const beans::PropertyChangeEvent& rEvent) const
1051 if (pListeners == NULL)
1052 return;
1054 const ChangeListenerContainer aListeners (*pListeners);
1057 for (ChangeListenerContainer::const_iterator
1058 iListener(aListeners.begin()),
1059 iEnd(aListeners.end());
1060 iListener!=iEnd;
1061 ++iListener)
1063 (*iListener)->propertyChange(rEvent);
1066 catch(const Exception&)
1068 // Ignore any errors (such as disposed listeners).
1075 void Theme::ProcessNewValue (
1076 const Any& rValue,
1077 const ThemeItem eItem,
1078 const PropertyType eType)
1080 const sal_Int32 nIndex (GetIndex (eItem, eType));
1081 switch (eType)
1083 case PT_Image:
1085 ::rtl::OUString sURL;
1086 if (rValue >>= sURL)
1088 maImages[nIndex] = Tools::GetImage(sURL, NULL);
1090 break;
1092 case PT_Color:
1094 sal_Int32 nColorValue (0);
1095 if (rValue >>= nColorValue)
1097 maColors[nIndex] = Color(nColorValue);
1099 break;
1101 case PT_Paint:
1103 maPaints[nIndex] = Paint::Create(rValue);
1104 break;
1106 case PT_Integer:
1108 sal_Int32 nValue (0);
1109 if (rValue >>= nValue)
1111 maIntegers[nIndex] = nValue;
1113 break;
1115 case PT_Boolean:
1117 sal_Bool nValue (0);
1118 if (rValue >>= nValue)
1120 maBooleans[nIndex] = (nValue==sal_True);
1121 if (eItem == Bool_IsHighContrastModeActive)
1123 mbIsHighContrastModeSetManually = true;
1124 mbIsHighContrastMode = maBooleans[nIndex];
1125 HandleDataChange();
1127 else if (eItem == Bool_UseSystemColors)
1129 HandleDataChange();
1132 break;
1134 case PT_Rectangle:
1136 awt::Rectangle aBox;
1137 if (rValue >>= aBox)
1139 maRectangles[nIndex] = Rectangle(
1140 aBox.X,
1141 aBox.Y,
1142 aBox.Width,
1143 aBox.Height);
1145 break;
1147 case PT_Invalid:
1148 OSL_ASSERT(eType != PT_Invalid);
1149 throw RuntimeException();
1153 } } // end of namespace sfx2::sidebar