Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / source / sidebar / Theme.cxx
blobbd64a87b79078a30072f295a463bb580484f8633
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sfx2/sidebar/Theme.hxx>
21 #include <sidebar/Tools.hxx>
22 #include <sfx2/app.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/settings.hxx>
26 #include <tools/diagnose_ex.h>
28 #include <com/sun/star/awt/Rectangle.hpp>
30 using namespace css;
31 using namespace css::uno;
33 namespace sfx2::sidebar {
35 Theme& Theme::GetCurrentTheme()
37 return SfxGetpApp()->GetSidebarTheme();
40 Theme::Theme()
41 : ThemeInterfaceBase(m_aMutex),
42 maImages(),
43 maColors(),
44 maIntegers(),
45 maBooleans(),
46 mbIsHighContrastMode(Application::GetSettings().GetStyleSettings().GetHighContrastMode()),
47 mbIsHighContrastModeSetManually(false),
48 maPropertyNameToIdMap(),
49 maPropertyIdToNameMap(),
50 maRawValues(),
51 maChangeListeners(),
52 maVetoableListeners()
55 SetupPropertyMaps();
58 Theme::~Theme()
62 Image Theme::GetImage (const ThemeItem eItem)
64 const PropertyType eType (GetPropertyType(eItem));
65 OSL_ASSERT(eType==PT_Image);
66 const sal_Int32 nIndex (GetIndex(eItem, eType));
67 const Theme& rTheme (GetCurrentTheme());
68 return rTheme.maImages[nIndex];
71 Color Theme::GetColor (const ThemeItem eItem)
73 const PropertyType eType (GetPropertyType(eItem));
74 OSL_ASSERT(eType==PT_Color);
75 const sal_Int32 nIndex (GetIndex(eItem, eType));
76 const Theme& rTheme (GetCurrentTheme());
77 if (eType == PT_Color)
78 return rTheme.maColors[nIndex];
79 else
80 return COL_WHITE;
83 sal_Int32 Theme::GetInteger (const ThemeItem eItem)
85 const PropertyType eType (GetPropertyType(eItem));
86 OSL_ASSERT(eType==PT_Integer);
87 const sal_Int32 nIndex (GetIndex(eItem, eType));
88 const Theme& rTheme (GetCurrentTheme());
89 return rTheme.maIntegers[nIndex];
92 bool Theme::GetBoolean (const ThemeItem eItem)
94 const PropertyType eType (GetPropertyType(eItem));
95 OSL_ASSERT(eType==PT_Boolean);
96 const sal_Int32 nIndex (GetIndex(eItem, eType));
97 const Theme& rTheme (GetCurrentTheme());
98 return rTheme.maBooleans[nIndex];
101 bool Theme::IsHighContrastMode()
103 const Theme& rTheme (GetCurrentTheme());
104 return rTheme.mbIsHighContrastMode;
107 void Theme::HandleDataChange()
109 Theme& rTheme (GetCurrentTheme());
111 if ( ! rTheme.mbIsHighContrastModeSetManually)
113 // Do not modify mbIsHighContrastMode when it was manually set.
114 GetCurrentTheme().mbIsHighContrastMode = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
115 rTheme.maRawValues[Bool_IsHighContrastModeActive] <<= GetCurrentTheme().mbIsHighContrastMode;
118 GetCurrentTheme().UpdateTheme();
121 void Theme::InitializeTheme()
123 setPropertyValue(
124 maPropertyIdToNameMap[Bool_UseSystemColors],
125 Any(false));
128 void Theme::UpdateTheme()
132 const StyleSettings& rStyle (Application::GetSettings().GetStyleSettings());
133 const bool bUseSystemColors (GetBoolean(Bool_UseSystemColors));
135 #define Alternatives(n,hc,sys) (mbIsHighContrastMode ? hc : (bUseSystemColors ? sys : n))
137 Color aBaseBackgroundColor (rStyle.GetDialogColor());
138 // UX says this should be a little brighter, but that looks off when compared to the other windows.
139 //aBaseBackgroundColor.IncreaseLuminance(7);
140 Color aBorderColor (aBaseBackgroundColor);
141 Color aSecondColor (aBaseBackgroundColor);
142 aSecondColor.DecreaseLuminance(15);
144 setPropertyValue(
145 maPropertyIdToNameMap[Color_DeckBackground],
146 Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
148 setPropertyValue(
149 maPropertyIdToNameMap[Color_DeckTitleBarBackground],
150 Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
151 setPropertyValue(
152 maPropertyIdToNameMap[Int_DeckSeparatorHeight],
153 Any(sal_Int32(1)));
154 setPropertyValue(
155 maPropertyIdToNameMap[Color_DeckTitleFont],
156 Any(sal_Int32(rStyle.GetFontColor().GetRGBColor())));
157 setPropertyValue(
158 maPropertyIdToNameMap[Int_DeckTitleBarHeight],
159 Any(sal_Int32(Alternatives(
162 rStyle.GetFloatTitleHeight()))));
163 setPropertyValue(
164 maPropertyIdToNameMap[Color_PanelBackground],
165 Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
167 setPropertyValue(
168 maPropertyIdToNameMap[Color_PanelTitleBarBackground],
169 Any(sal_Int32(aSecondColor.GetRGBColor())));
170 setPropertyValue(
171 maPropertyIdToNameMap[Color_PanelTitleFont],
172 Any(sal_Int32(mbIsHighContrastMode ? 0x00ff00 : 0x262626)));
173 setPropertyValue(
174 maPropertyIdToNameMap[Int_PanelTitleBarHeight],
175 Any(sal_Int32(Alternatives(
178 rStyle.GetTitleHeight()))));
179 setPropertyValue(
180 maPropertyIdToNameMap[Color_TabBarBackground],
181 Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
183 setPropertyValue(
184 maPropertyIdToNameMap[Color_DropDownBackground],
185 Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
187 setPropertyValue(
188 maPropertyIdToNameMap[Color_Highlight],
189 Any(sal_Int32(rStyle.GetHighlightColor().GetRGBColor())));
190 setPropertyValue(
191 maPropertyIdToNameMap[Color_HighlightText],
192 Any(sal_Int32(rStyle.GetHighlightTextColor().GetRGBColor())));
194 setPropertyValue(
195 maPropertyIdToNameMap[Color_HorizontalBorder],
196 Any(sal_Int32(aBorderColor.GetRGBColor())));
198 setPropertyValue(
199 maPropertyIdToNameMap[Color_VerticalBorder],
200 Any(sal_Int32(aBorderColor.GetRGBColor())));
201 setPropertyValue(
202 maPropertyIdToNameMap[Image_CloseIndicator],
203 Any(OUString("private:graphicrepository/cmd/lc_decrementlevel.png")));
205 catch(beans::UnknownPropertyException const &)
207 DBG_UNHANDLED_EXCEPTION("sfx", "unknown property");
208 OSL_ASSERT(false);
212 void SAL_CALL Theme::disposing()
214 SolarMutexGuard aGuard;
216 ChangeListeners aListeners;
217 aListeners.swap(maChangeListeners);
219 const lang::EventObject aEvent (static_cast<XWeak*>(this));
221 for (const auto& rContainer : aListeners)
223 for (const auto& rxListener : rContainer.second)
227 rxListener->disposing(aEvent);
229 catch(const Exception&)
236 Reference<beans::XPropertySet> Theme::GetPropertySet()
238 return Reference<beans::XPropertySet>(static_cast<XWeak*>(&GetCurrentTheme()), UNO_QUERY);
241 Reference<beans::XPropertySetInfo> SAL_CALL Theme::getPropertySetInfo()
243 return Reference<beans::XPropertySetInfo>(this);
246 void SAL_CALL Theme::setPropertyValue (
247 const OUString& rsPropertyName,
248 const css::uno::Any& rValue)
250 SolarMutexGuard aGuard;
252 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
253 if (iId == maPropertyNameToIdMap.end())
254 throw beans::UnknownPropertyException(rsPropertyName);
256 const PropertyType eType (GetPropertyType(iId->second));
257 if (eType == PT_Invalid)
258 throw beans::UnknownPropertyException(rsPropertyName);
260 const ThemeItem eItem (iId->second);
262 if (rValue == maRawValues[eItem])
264 // Value is not different from the one in the property
265 // set => nothing to do.
266 return;
269 const Any aOldValue (maRawValues[eItem]);
271 const beans::PropertyChangeEvent aEvent(
272 static_cast<XWeak*>(this),
273 rsPropertyName,
274 false,
275 eItem,
276 aOldValue,
277 rValue);
279 if (DoVetoableListenersVeto(GetVetoableListeners(AnyItem_, false), aEvent))
280 return;
281 if (DoVetoableListenersVeto(GetVetoableListeners(eItem, false), aEvent))
282 return;
284 maRawValues[eItem] = rValue;
285 ProcessNewValue(rValue, eItem, eType);
287 BroadcastPropertyChange(GetChangeListeners(AnyItem_, false), aEvent);
288 BroadcastPropertyChange(GetChangeListeners(eItem, false), aEvent);
291 Any SAL_CALL Theme::getPropertyValue (
292 const OUString& rsPropertyName)
294 SolarMutexGuard aGuard;
296 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
297 if (iId == maPropertyNameToIdMap.end())
298 throw beans::UnknownPropertyException(rsPropertyName);
300 const PropertyType eType (GetPropertyType(iId->second));
301 if (eType == PT_Invalid)
302 throw beans::UnknownPropertyException(rsPropertyName);
304 const ThemeItem eItem (iId->second);
306 return maRawValues[eItem];
309 void SAL_CALL Theme::addPropertyChangeListener(
310 const OUString& rsPropertyName,
311 const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
313 SolarMutexGuard aGuard;
315 ThemeItem eItem (AnyItem_);
316 if (rsPropertyName.getLength() > 0)
318 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
319 if (iId == maPropertyNameToIdMap.end())
320 throw beans::UnknownPropertyException(rsPropertyName);
322 const PropertyType eType (GetPropertyType(iId->second));
323 if (eType == PT_Invalid)
324 throw beans::UnknownPropertyException(rsPropertyName);
326 eItem = iId->second;
328 ChangeListenerContainer* pListeners = GetChangeListeners(eItem, true);
329 if (pListeners != nullptr)
330 pListeners->push_back(rxListener);
333 void SAL_CALL Theme::removePropertyChangeListener(
334 const OUString& rsPropertyName,
335 const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
337 SolarMutexGuard aGuard;
339 ThemeItem eItem (AnyItem_);
340 if (rsPropertyName.getLength() > 0)
342 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
343 if (iId == maPropertyNameToIdMap.end())
344 throw beans::UnknownPropertyException(rsPropertyName);
346 const PropertyType eType (GetPropertyType(iId->second));
347 if (eType == PT_Invalid)
348 throw beans::UnknownPropertyException(rsPropertyName);
350 eItem = iId->second;
352 ChangeListenerContainer* pContainer = GetChangeListeners(eItem, false);
353 if (pContainer != nullptr)
355 ChangeListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener));
356 if (iListener != pContainer->end())
358 pContainer->erase(iListener);
360 // Remove the listener container when empty.
361 if (pContainer->empty())
362 maChangeListeners.erase(eItem);
367 void SAL_CALL Theme::addVetoableChangeListener(
368 const OUString& rsPropertyName,
369 const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
371 SolarMutexGuard aGuard;
373 ThemeItem eItem (AnyItem_);
374 if (rsPropertyName.getLength() > 0)
376 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
377 if (iId == maPropertyNameToIdMap.end())
378 throw beans::UnknownPropertyException(rsPropertyName);
380 const PropertyType eType (GetPropertyType(iId->second));
381 if (eType == PT_Invalid)
382 throw beans::UnknownPropertyException(rsPropertyName);
384 eItem = iId->second;
386 VetoableListenerContainer* pListeners = GetVetoableListeners(eItem, true);
387 if (pListeners != nullptr)
388 pListeners->push_back(rxListener);
391 void SAL_CALL Theme::removeVetoableChangeListener(
392 const OUString& rsPropertyName,
393 const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
395 SolarMutexGuard aGuard;
397 ThemeItem eItem (AnyItem_);
398 if (rsPropertyName.getLength() > 0)
400 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
401 if (iId == maPropertyNameToIdMap.end())
402 throw beans::UnknownPropertyException(rsPropertyName);
404 const PropertyType eType (GetPropertyType(iId->second));
405 if (eType == PT_Invalid)
406 throw beans::UnknownPropertyException(rsPropertyName);
408 eItem = iId->second;
410 VetoableListenerContainer* pContainer = GetVetoableListeners(eItem, false);
411 if (pContainer != nullptr)
413 VetoableListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener));
414 if (iListener != pContainer->end())
416 pContainer->erase(iListener);
417 // Remove container when empty.
418 if (pContainer->empty())
419 maVetoableListeners.erase(eItem);
424 css::uno::Sequence<css::beans::Property> SAL_CALL Theme::getProperties()
426 SolarMutexGuard aGuard;
428 ::std::vector<beans::Property> aProperties;
430 sal_Int32 const nEnd(End_);
431 for (sal_Int32 nItem(Begin_); nItem!=nEnd; ++nItem)
433 const ThemeItem eItem (static_cast<ThemeItem>(nItem));
434 const PropertyType eType (GetPropertyType(eItem));
435 if (eType == PT_Invalid)
436 continue;
438 const beans::Property aProperty(
439 maPropertyIdToNameMap[eItem],
440 eItem,
441 GetCppuType(eType),
443 aProperties.push_back(aProperty);
446 return css::uno::Sequence<css::beans::Property>(
447 aProperties.data(),
448 aProperties.size());
451 beans::Property SAL_CALL Theme::getPropertyByName (const OUString& rsPropertyName)
453 SolarMutexGuard aGuard;
455 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
456 if (iId == maPropertyNameToIdMap.end())
457 throw beans::UnknownPropertyException(rsPropertyName);
459 const PropertyType eType (GetPropertyType(iId->second));
460 if (eType == PT_Invalid)
461 throw beans::UnknownPropertyException(rsPropertyName);
463 const ThemeItem eItem (iId->second);
465 return beans::Property(
466 rsPropertyName,
467 eItem,
468 GetCppuType(eType),
472 sal_Bool SAL_CALL Theme::hasPropertyByName (const OUString& rsPropertyName)
474 SolarMutexGuard aGuard;
476 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
477 if (iId == maPropertyNameToIdMap.end())
478 return false;
480 const PropertyType eType (GetPropertyType(iId->second));
481 if (eType == PT_Invalid)
482 return false;
484 return true;
487 void Theme::SetupPropertyMaps()
489 maPropertyIdToNameMap.resize(Post_Bool_);
490 maImages.resize(Image_Color_ - Pre_Image_ - 1);
491 maColors.resize(Color_Int_ - Image_Color_ - 1);
492 maIntegers.resize(Int_Bool_ - Color_Int_ - 1);
493 maBooleans.resize(Post_Bool_ - Int_Bool_ - 1);
495 maPropertyNameToIdMap["Image_CloseIndicator"]=Image_CloseIndicator;
496 maPropertyIdToNameMap[Image_CloseIndicator]="Image_CloseIndicator";
499 maPropertyNameToIdMap["Color_DeckTitleFont"]=Color_DeckTitleFont;
500 maPropertyIdToNameMap[Color_DeckTitleFont]="Color_DeckTitleFont";
502 maPropertyNameToIdMap["Color_PanelTitleFont"]=Color_PanelTitleFont;
503 maPropertyIdToNameMap[Color_PanelTitleFont]="Color_PanelTitleFont";
505 maPropertyNameToIdMap["Color_Highlight"]=Color_Highlight;
506 maPropertyIdToNameMap[Color_Highlight]="Color_Highlight";
508 maPropertyNameToIdMap["Color_HighlightText"]=Color_HighlightText;
509 maPropertyIdToNameMap[Color_HighlightText]="Color_HighlightText";
512 maPropertyNameToIdMap["Color_DeckBackground"]=Color_DeckBackground;
513 maPropertyIdToNameMap[Color_DeckBackground]="Color_DeckBackground";
515 maPropertyNameToIdMap["Color_DeckTitleBarBackground"]=Color_DeckTitleBarBackground;
516 maPropertyIdToNameMap[Color_DeckTitleBarBackground]="Color_DeckTitleBarBackground";
518 maPropertyNameToIdMap["Color_PanelBackground"]=Color_PanelBackground;
519 maPropertyIdToNameMap[Color_PanelBackground]="Color_PanelBackground";
521 maPropertyNameToIdMap["Color_PanelTitleBarBackground"]=Color_PanelTitleBarBackground;
522 maPropertyIdToNameMap[Color_PanelTitleBarBackground]="Color_PanelTitleBarBackground";
524 maPropertyNameToIdMap["Color_TabBarBackground"]=Color_TabBarBackground;
525 maPropertyIdToNameMap[Color_TabBarBackground]="Color_TabBarBackground";
527 maPropertyNameToIdMap["Color_HorizontalBorder"]=Color_HorizontalBorder;
528 maPropertyIdToNameMap[Color_HorizontalBorder]="Color_HorizontalBorder";
530 maPropertyNameToIdMap["Color_VerticalBorder"]=Color_VerticalBorder;
531 maPropertyIdToNameMap[Color_VerticalBorder]="Color_VerticalBorder";
533 maPropertyNameToIdMap["Color_DropDownBackground"]=Color_DropDownBackground;
534 maPropertyIdToNameMap[Color_DropDownBackground]="Color_DropDownBackground";
537 maPropertyNameToIdMap["Int_DeckTitleBarHeight"]=Int_DeckTitleBarHeight;
538 maPropertyIdToNameMap[Int_DeckTitleBarHeight]="Int_DeckTitleBarHeight";
540 maPropertyNameToIdMap["Int_DeckBorderSize"]=Int_DeckBorderSize;
541 maPropertyIdToNameMap[Int_DeckBorderSize]="Int_DeckBorderSize";
543 maPropertyNameToIdMap["Int_DeckSeparatorHeight"]=Int_DeckSeparatorHeight;
544 maPropertyIdToNameMap[Int_DeckSeparatorHeight]="Int_DeckSeparatorHeight";
546 maPropertyNameToIdMap["Int_PanelTitleBarHeight"]=Int_PanelTitleBarHeight;
547 maPropertyIdToNameMap[Int_PanelTitleBarHeight]="Int_PanelTitleBarHeight";
549 maPropertyNameToIdMap["Int_DeckLeftPadding"]=Int_DeckLeftPadding;
550 maPropertyIdToNameMap[Int_DeckLeftPadding]="Int_DeckLeftPadding";
552 maPropertyNameToIdMap["Int_DeckTopPadding"]=Int_DeckTopPadding;
553 maPropertyIdToNameMap[Int_DeckTopPadding]="Int_DeckTopPadding";
555 maPropertyNameToIdMap["Int_DeckRightPadding"]=Int_DeckRightPadding;
556 maPropertyIdToNameMap[Int_DeckRightPadding]="Int_DeckRightPadding";
558 maPropertyNameToIdMap["Int_DeckBottomPadding"]=Int_DeckBottomPadding;
559 maPropertyIdToNameMap[Int_DeckBottomPadding]="Int_DeckBottomPadding";
562 maPropertyNameToIdMap["Bool_UseSystemColors"]=Bool_UseSystemColors;
563 maPropertyIdToNameMap[Bool_UseSystemColors]="Bool_UseSystemColors";
565 maPropertyNameToIdMap["Bool_IsHighContrastModeActive"]=Bool_IsHighContrastModeActive;
566 maPropertyIdToNameMap[Bool_IsHighContrastModeActive]="Bool_IsHighContrastModeActive";
568 maRawValues.resize(maPropertyIdToNameMap.size());
571 Theme::PropertyType Theme::GetPropertyType (const ThemeItem eItem)
573 switch(eItem)
575 case Image_CloseIndicator:
576 return PT_Image;
578 case Color_DeckTitleFont:
579 case Color_PanelTitleFont:
580 case Color_Highlight:
581 case Color_HighlightText:
582 case Color_DeckBackground:
583 case Color_DeckTitleBarBackground:
584 case Color_PanelBackground:
585 case Color_PanelTitleBarBackground:
586 case Color_TabBarBackground:
587 case Color_HorizontalBorder:
588 case Color_VerticalBorder:
589 case Color_DropDownBackground:
590 return PT_Color;
592 case Int_DeckTitleBarHeight:
593 case Int_DeckBorderSize:
594 case Int_DeckSeparatorHeight:
595 case Int_PanelTitleBarHeight:
596 case Int_DeckLeftPadding:
597 case Int_DeckTopPadding:
598 case Int_DeckRightPadding:
599 case Int_DeckBottomPadding:
600 return PT_Integer;
602 case Bool_UseSystemColors:
603 case Bool_IsHighContrastModeActive:
604 return PT_Boolean;
606 default:
607 return PT_Invalid;
611 css::uno::Type const & Theme::GetCppuType (const PropertyType eType)
613 switch(eType)
615 case PT_Image:
616 return cppu::UnoType<OUString>::get();
618 case PT_Color:
619 return cppu::UnoType<sal_uInt32>::get();
621 case PT_Integer:
622 return cppu::UnoType<sal_Int32>::get();
624 case PT_Boolean:
625 return cppu::UnoType<sal_Bool>::get();
627 case PT_Invalid:
628 default:
629 return cppu::UnoType<void>::get();
633 sal_Int32 Theme::GetIndex (const ThemeItem eItem, const PropertyType eType)
635 switch(eType)
637 case PT_Image:
638 return eItem - Pre_Image_-1;
639 case PT_Color:
640 return eItem - Image_Color_-1;
641 case PT_Integer:
642 return eItem - Color_Int_-1;
643 case PT_Boolean:
644 return eItem - Int_Bool_-1;
645 default:
646 OSL_ASSERT(false);
647 return 0;
651 Theme::VetoableListenerContainer* Theme::GetVetoableListeners (
652 const ThemeItem eItem,
653 const bool bCreate)
655 VetoableListeners::iterator iContainer (maVetoableListeners.find(eItem));
656 if (iContainer != maVetoableListeners.end())
657 return &iContainer->second;
658 else if (bCreate)
660 maVetoableListeners[eItem] = VetoableListenerContainer();
661 return &maVetoableListeners[eItem];
663 else
664 return nullptr;
667 Theme::ChangeListenerContainer* Theme::GetChangeListeners (
668 const ThemeItem eItem,
669 const bool bCreate)
671 ChangeListeners::iterator iContainer (maChangeListeners.find(eItem));
672 if (iContainer != maChangeListeners.end())
673 return &iContainer->second;
674 else if (bCreate)
676 maChangeListeners[eItem] = ChangeListenerContainer();
677 return &maChangeListeners[eItem];
679 else
680 return nullptr;
683 bool Theme::DoVetoableListenersVeto (
684 const VetoableListenerContainer* pListeners,
685 const beans::PropertyChangeEvent& rEvent)
687 if (pListeners == nullptr)
688 return false;
690 VetoableListenerContainer aListeners (*pListeners);
693 for (const auto& rxListener : aListeners)
695 rxListener->vetoableChange(rEvent);
698 catch(const beans::PropertyVetoException&)
700 return true;
702 catch(const Exception&)
704 // Ignore any other errors (such as disposed listeners).
706 return false;
709 void Theme::BroadcastPropertyChange (
710 const ChangeListenerContainer* pListeners,
711 const beans::PropertyChangeEvent& rEvent)
713 if (pListeners == nullptr)
714 return;
716 const ChangeListenerContainer aListeners (*pListeners);
719 for (const auto& rxListener : aListeners)
721 rxListener->propertyChange(rEvent);
724 catch(const Exception&)
726 // Ignore any errors (such as disposed listeners).
730 void Theme::ProcessNewValue (
731 const Any& rValue,
732 const ThemeItem eItem,
733 const PropertyType eType)
735 const sal_Int32 nIndex (GetIndex (eItem, eType));
736 switch (eType)
738 case PT_Image:
740 OUString sURL;
741 if (rValue >>= sURL)
743 maImages[nIndex] = Image(Tools::GetImage(sURL, nullptr));
745 break;
747 case PT_Color:
749 sal_Int32 nColorValue (0);
750 if (rValue >>= nColorValue)
752 maColors[nIndex] = Color(nColorValue);
754 break;
756 case PT_Integer:
758 sal_Int32 nValue (0);
759 if (rValue >>= nValue)
761 maIntegers[nIndex] = nValue;
763 break;
765 case PT_Boolean:
767 bool bValue (false);
768 if (rValue >>= bValue)
770 maBooleans[nIndex] = bValue;
771 if (eItem == Bool_IsHighContrastModeActive)
773 mbIsHighContrastModeSetManually = true;
774 mbIsHighContrastMode = maBooleans[nIndex];
775 HandleDataChange();
777 else if (eItem == Bool_UseSystemColors)
779 HandleDataChange();
782 break;
784 case PT_Invalid:
785 OSL_ASSERT(eType != PT_Invalid);
786 throw RuntimeException();
790 } // end of namespace sfx2::sidebar
792 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */