Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / sidebar / Theme.cxx
blobdf469123cb1def22fc7b5aeeec4b5f5bb95a6e17
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 .
19 #include <sfx2/sidebar/Theme.hxx>
20 #include "Paint.hxx"
21 #include "SidebarResource.hxx"
22 #include <sfx2/sidebar/Tools.hxx>
23 #include <sfx2/app.hxx>
25 #include <tools/svborder.hxx>
26 #include <tools/rc.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/settings.hxx>
30 using namespace css;
31 using namespace css::uno;
33 namespace sfx2 { namespace sidebar {
35 Theme& Theme::GetCurrentTheme()
37 return SfxGetpApp()->GetSidebarTheme();
40 Theme::Theme()
41 : ThemeInterfaceBase(m_aMutex),
42 maImages(),
43 maColors(),
44 maPaints(),
45 maIntegers(),
46 maBooleans(),
47 mbIsHighContrastMode(Application::GetSettings().GetStyleSettings().GetHighContrastMode()),
48 mbIsHighContrastModeSetManually(false),
49 maPropertyNameToIdMap(),
50 maPropertyIdToNameMap(),
51 maRawValues(),
52 maChangeListeners(),
53 maVetoableListeners()
56 SetupPropertyMaps();
59 Theme::~Theme()
63 Image Theme::GetImage (const ThemeItem eItem)
65 const PropertyType eType (GetPropertyType(eItem));
66 OSL_ASSERT(eType==PT_Image);
67 const sal_Int32 nIndex (GetIndex(eItem, eType));
68 const Theme& rTheme (GetCurrentTheme());
69 return rTheme.maImages[nIndex];
72 Color Theme::GetColor (const ThemeItem eItem)
74 const PropertyType eType (GetPropertyType(eItem));
75 OSL_ASSERT(eType==PT_Color || eType==PT_Paint);
76 const sal_Int32 nIndex (GetIndex(eItem, eType));
77 const Theme& rTheme (GetCurrentTheme());
78 if (eType == PT_Color)
79 return rTheme.maColors[nIndex];
80 else if (eType == PT_Paint)
81 return rTheme.maPaints[nIndex].GetColor();
82 else
83 return COL_WHITE;
86 const Paint& Theme::GetPaint (const ThemeItem eItem)
88 const PropertyType eType (GetPropertyType(eItem));
89 OSL_ASSERT(eType==PT_Paint);
90 const sal_Int32 nIndex (GetIndex(eItem, eType));
91 const Theme& rTheme (GetCurrentTheme());
92 return rTheme.maPaints[nIndex];
95 const Wallpaper Theme::GetWallpaper (const ThemeItem eItem)
97 return GetPaint(eItem).GetWallpaper();
100 sal_Int32 Theme::GetInteger (const ThemeItem eItem)
102 const PropertyType eType (GetPropertyType(eItem));
103 OSL_ASSERT(eType==PT_Integer);
104 const sal_Int32 nIndex (GetIndex(eItem, eType));
105 const Theme& rTheme (GetCurrentTheme());
106 return rTheme.maIntegers[nIndex];
109 bool Theme::GetBoolean (const ThemeItem eItem)
111 const PropertyType eType (GetPropertyType(eItem));
112 OSL_ASSERT(eType==PT_Boolean);
113 const sal_Int32 nIndex (GetIndex(eItem, eType));
114 const Theme& rTheme (GetCurrentTheme());
115 return rTheme.maBooleans[nIndex];
118 bool Theme::IsHighContrastMode()
120 const Theme& rTheme (GetCurrentTheme());
121 return rTheme.mbIsHighContrastMode;
124 void Theme::HandleDataChange()
126 Theme& rTheme (GetCurrentTheme());
128 if ( ! rTheme.mbIsHighContrastModeSetManually)
130 // Do not modify mbIsHighContrastMode when it was manually set.
131 GetCurrentTheme().mbIsHighContrastMode = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
132 rTheme.maRawValues[Bool_IsHighContrastModeActive] = Any(GetCurrentTheme().mbIsHighContrastMode);
135 GetCurrentTheme().UpdateTheme();
138 void Theme::InitializeTheme()
140 setPropertyValue(
141 maPropertyIdToNameMap[Bool_UseSymphonyIcons],
142 Any(false));
143 setPropertyValue(
144 maPropertyIdToNameMap[Bool_UseSystemColors],
145 Any(false));
148 void Theme::UpdateTheme()
150 SidebarResource aLocalResource;
154 const StyleSettings& rStyle (Application::GetSettings().GetStyleSettings());
155 const bool bUseSystemColors (GetBoolean(Bool_UseSystemColors));
157 #define Alternatives(n,hc,sys) (mbIsHighContrastMode ? hc : (bUseSystemColors ? sys : n))
159 Color aBaseBackgroundColor (rStyle.GetDialogColor());
160 // UX says this should be a little brighter, but that looks off when compared to the other windows.
161 //aBaseBackgroundColor.IncreaseLuminance(7);
162 Color aBorderColor (aBaseBackgroundColor);
163 aBorderColor.DecreaseLuminance(15);
164 Color aSecondColor (aBaseBackgroundColor);
165 aSecondColor.DecreaseLuminance(15);
167 setPropertyValue(
168 maPropertyIdToNameMap[Paint_DeckBackground],
169 Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
171 setPropertyValue(
172 maPropertyIdToNameMap[Paint_DeckTitleBarBackground],
173 Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
174 setPropertyValue(
175 maPropertyIdToNameMap[Int_DeckLeftPadding],
176 Any(sal_Int32(2)));
177 setPropertyValue(
178 maPropertyIdToNameMap[Int_DeckTopPadding],
179 Any(sal_Int32(2)));
180 setPropertyValue(
181 maPropertyIdToNameMap[Int_DeckRightPadding],
182 Any(sal_Int32(2)));
183 setPropertyValue(
184 maPropertyIdToNameMap[Int_DeckBottomPadding],
185 Any(sal_Int32(2)));
186 setPropertyValue(
187 maPropertyIdToNameMap[Int_DeckBorderSize],
188 Any(sal_Int32(1)));
189 setPropertyValue(
190 maPropertyIdToNameMap[Int_DeckSeparatorHeight],
191 Any(sal_Int32(1)));
192 setPropertyValue(
193 maPropertyIdToNameMap[Int_ButtonCornerRadius],
194 Any(sal_Int32(3)));
195 setPropertyValue(
196 maPropertyIdToNameMap[Color_DeckTitleFont],
197 Any(sal_Int32(rStyle.GetFontColor().GetRGBColor())));
198 setPropertyValue(
199 maPropertyIdToNameMap[Int_DeckTitleBarHeight],
200 Any(sal_Int32(Alternatives(
203 rStyle.GetFloatTitleHeight()))));
204 setPropertyValue(
205 maPropertyIdToNameMap[Paint_PanelBackground],
206 Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
208 setPropertyValue(
209 maPropertyIdToNameMap[Paint_PanelTitleBarBackground],
210 Any(Tools::VclToAwtGradient(Gradient(
211 GradientStyle_LINEAR,
212 aSecondColor.GetRGBColor(),
213 aBaseBackgroundColor.GetRGBColor()
214 ))));
215 setPropertyValue(
216 maPropertyIdToNameMap[Color_PanelTitleFont],
217 Any(sal_Int32(mbIsHighContrastMode ? 0x00ff00 : 0x262626)));
218 setPropertyValue(
219 maPropertyIdToNameMap[Int_PanelTitleBarHeight],
220 Any(sal_Int32(Alternatives(
223 rStyle.GetTitleHeight()))));
224 setPropertyValue(
225 maPropertyIdToNameMap[Paint_TabBarBackground],
226 Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
227 setPropertyValue(
228 maPropertyIdToNameMap[Int_TabBarLeftPadding],
229 Any(sal_Int32(2)));
230 setPropertyValue(
231 maPropertyIdToNameMap[Int_TabBarTopPadding],
232 Any(sal_Int32(2)));
233 setPropertyValue(
234 maPropertyIdToNameMap[Int_TabBarRightPadding],
235 Any(sal_Int32(2)));
236 setPropertyValue(
237 maPropertyIdToNameMap[Int_TabBarBottomPadding],
238 Any(sal_Int32(2)));
240 setPropertyValue(
241 maPropertyIdToNameMap[Int_TabMenuPadding],
242 Any(sal_Int32(6)));
243 setPropertyValue(
244 maPropertyIdToNameMap[Color_TabMenuSeparator],
245 Any(sal_Int32(aBorderColor.GetRGBColor())));
246 setPropertyValue(
247 maPropertyIdToNameMap[Int_TabMenuSeparatorPadding],
248 Any(sal_Int32(7)));
250 setPropertyValue(
251 maPropertyIdToNameMap[Int_TabItemWidth],
252 Any(sal_Int32(32)));
253 setPropertyValue(
254 maPropertyIdToNameMap[Int_TabItemHeight],
255 Any(sal_Int32(32)));
256 setPropertyValue(
257 maPropertyIdToNameMap[Color_TabItemBorder],
258 Any(sal_Int32(rStyle.GetActiveBorderColor().GetRGBColor())));
259 // mbIsHighContrastMode ? 0x00ff00 : 0xbfbfbf)));
261 setPropertyValue(
262 maPropertyIdToNameMap[Paint_DropDownBackground],
263 Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
264 setPropertyValue(
265 maPropertyIdToNameMap[Color_DropDownBorder],
266 Any(sal_Int32(rStyle.GetActiveBorderColor().GetRGBColor())));
268 setPropertyValue(
269 maPropertyIdToNameMap[Color_Highlight],
270 Any(sal_Int32(rStyle.GetHighlightColor().GetRGBColor())));
271 setPropertyValue(
272 maPropertyIdToNameMap[Color_HighlightText],
273 Any(sal_Int32(rStyle.GetHighlightTextColor().GetRGBColor())));
275 setPropertyValue(
276 maPropertyIdToNameMap[Paint_TabItemBackgroundNormal],
277 Any());
278 setPropertyValue(
279 maPropertyIdToNameMap[Paint_TabItemBackgroundHighlight],
280 Any(sal_Int32(rStyle.GetActiveTabColor().GetRGBColor())));
281 // mbIsHighContrastMode ? 0x000000 : 0x00ffffff)));
283 setPropertyValue(
284 maPropertyIdToNameMap[Paint_HorizontalBorder],
285 Any(sal_Int32(aBorderColor.GetRGBColor())));
286 // mbIsHighContrastMode ? 0x00ff00 : 0xe4e4e4)));
287 setPropertyValue(
288 maPropertyIdToNameMap[Paint_VerticalBorder],
289 Any(sal_Int32(aBorderColor.GetRGBColor())));
290 setPropertyValue(
291 maPropertyIdToNameMap[Image_Grip],
292 Any(OUString("private:graphicrepository/sfx2/res/grip.png")));
293 setPropertyValue(
294 maPropertyIdToNameMap[Image_Expand],
295 Any(OUString("private:graphicrepository/res/plus.png")));
296 setPropertyValue(
297 maPropertyIdToNameMap[Image_Collapse],
298 Any(OUString("private:graphicrepository/res/minus.png")));
299 setPropertyValue(
300 maPropertyIdToNameMap[Image_TabBarMenu],
301 Any(OUString("private:graphicrepository/sfx2/res/symphony/open_more.png")));
302 setPropertyValue(
303 maPropertyIdToNameMap[Image_PanelMenu],
304 Any(OUString("private:graphicrepository/sfx2/res/symphony/morebutton.png")));
305 setPropertyValue(
306 maPropertyIdToNameMap[Image_Closer],
307 Any(OUString("private:graphicrepository/sfx2/res/closedoc.png")));
308 setPropertyValue(
309 maPropertyIdToNameMap[Image_CloseIndicator],
310 Any(OUString("private:graphicrepository/cmd/lc_decrementlevel.png")));
311 setPropertyValue(
312 maPropertyIdToNameMap[Image_ToolBoxItemSeparator],
313 Any(
314 OUString("private:graphicrepository/sfx2/res/separator.png")));
316 // ToolBox
319 // Separator style
320 setPropertyValue(
321 maPropertyIdToNameMap[Paint_ToolBoxBackground],
322 Any(sal_Int32(rStyle.GetMenuColor().GetRGBColor())));
323 setPropertyValue(
324 maPropertyIdToNameMap[Paint_ToolBoxBorderTopLeft],
325 Any());
326 setPropertyValue(
327 maPropertyIdToNameMap[Paint_ToolBoxBorderCenterCorners],
328 Any());
329 setPropertyValue(
330 maPropertyIdToNameMap[Paint_ToolBoxBorderBottomRight],
331 Any());
332 setPropertyValue(
333 maPropertyIdToNameMap[Rect_ToolBoxPadding],
334 Any(awt::Rectangle(2,2,2,2)));
335 setPropertyValue(
336 maPropertyIdToNameMap[Rect_ToolBoxBorder],
337 Any(awt::Rectangle(0,0,0,0)));
338 setPropertyValue(
339 maPropertyIdToNameMap[Bool_UseToolBoxItemSeparator],
340 Any(true));
343 // Gradient style
344 Color aGradientStop2 (aBaseBackgroundColor);
345 aGradientStop2.IncreaseLuminance(17);
346 Color aToolBoxBorderColor (aBaseBackgroundColor);
347 aToolBoxBorderColor.DecreaseLuminance(12);
348 setPropertyValue(
349 maPropertyIdToNameMap[Paint_ToolBoxBackground],
350 Any(Tools::VclToAwtGradient(Gradient(
351 GradientStyle_LINEAR,
352 aBaseBackgroundColor.GetRGBColor(),
353 aGradientStop2.GetRGBColor()
354 ))));
355 setPropertyValue(
356 maPropertyIdToNameMap[Paint_ToolBoxBorderTopLeft],
357 mbIsHighContrastMode
358 ? Any(util::Color(sal_uInt32(0x00ff00)))
359 : Any(util::Color(aToolBoxBorderColor.GetRGBColor())));
360 setPropertyValue(
361 maPropertyIdToNameMap[Paint_ToolBoxBorderCenterCorners],
362 mbIsHighContrastMode
363 ? Any(util::Color(sal_uInt32(0x00ff00)))
364 : Any(util::Color(aToolBoxBorderColor.GetRGBColor())));
365 setPropertyValue(
366 maPropertyIdToNameMap[Paint_ToolBoxBorderBottomRight],
367 mbIsHighContrastMode
368 ? Any(util::Color(sal_uInt32(0x00ff00)))
369 : Any(util::Color(aToolBoxBorderColor.GetRGBColor())));
370 setPropertyValue(
371 maPropertyIdToNameMap[Rect_ToolBoxPadding],
372 Any(awt::Rectangle(2,2,2,2)));
373 setPropertyValue(
374 maPropertyIdToNameMap[Rect_ToolBoxBorder],
375 Any(awt::Rectangle(1,1,1,1)));
376 setPropertyValue(
377 maPropertyIdToNameMap[Bool_UseToolBoxItemSeparator],
378 Any(false));
380 catch(beans::UnknownPropertyException& rException)
382 OSL_TRACE("unknown property: %s",
383 OUStringToOString(
384 rException.Message,
385 RTL_TEXTENCODING_ASCII_US).getStr());
386 OSL_ASSERT(false);
390 void SAL_CALL Theme::disposing()
392 ChangeListeners aListeners;
393 aListeners.swap(maChangeListeners);
395 const lang::EventObject aEvent (static_cast<XWeak*>(this));
397 for (ChangeListeners::const_iterator
398 iContainer(aListeners.begin()),
399 iContainerEnd(aListeners.end());
400 iContainer != iContainerEnd;
401 ++iContainer)
403 for (ChangeListenerContainer::const_iterator
404 iListener(iContainer->second.begin()),
405 iEnd(iContainer->second.end());
406 iListener!=iEnd;
407 ++iListener)
411 (*iListener)->disposing(aEvent);
413 catch(const Exception&)
420 Reference<beans::XPropertySet> Theme::GetPropertySet()
422 return Reference<beans::XPropertySet>(static_cast<XWeak*>(&GetCurrentTheme()), UNO_QUERY);
425 Reference<beans::XPropertySetInfo> SAL_CALL Theme::getPropertySetInfo()
426 throw(css::uno::RuntimeException, std::exception)
428 return Reference<beans::XPropertySetInfo>(this);
431 void SAL_CALL Theme::setPropertyValue (
432 const ::rtl::OUString& rsPropertyName,
433 const css::uno::Any& rValue)
434 throw (css::beans::UnknownPropertyException,
435 css::uno::RuntimeException,
436 std::exception)
438 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
439 if (iId == maPropertyNameToIdMap.end())
440 throw beans::UnknownPropertyException(rsPropertyName);
442 const PropertyType eType (GetPropertyType(iId->second));
443 if (eType == PT_Invalid)
444 throw beans::UnknownPropertyException(rsPropertyName);
446 const ThemeItem eItem (iId->second);
448 if (rValue == maRawValues[eItem])
450 // Value is not different from the one in the property
451 // set => nothing to do.
452 return;
455 const Any aOldValue (maRawValues[eItem]);
457 const beans::PropertyChangeEvent aEvent(
458 static_cast<XWeak*>(this),
459 rsPropertyName,
460 sal_False,
461 eItem,
462 aOldValue,
463 rValue);
465 if (DoVetoableListenersVeto(GetVetoableListeners(__AnyItem, false), aEvent))
466 return;
467 if (DoVetoableListenersVeto(GetVetoableListeners(eItem, false), aEvent))
468 return;
470 maRawValues[eItem] = rValue;
471 ProcessNewValue(rValue, eItem, eType);
473 BroadcastPropertyChange(GetChangeListeners(__AnyItem, false), aEvent);
474 BroadcastPropertyChange(GetChangeListeners(eItem, false), aEvent);
477 Any SAL_CALL Theme::getPropertyValue (
478 const ::rtl::OUString& rsPropertyName)
479 throw(css::beans::UnknownPropertyException,
480 css::lang::WrappedTargetException,
481 css::uno::RuntimeException, std::exception)
483 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
484 if (iId == maPropertyNameToIdMap.end())
485 throw beans::UnknownPropertyException();
487 const PropertyType eType (GetPropertyType(iId->second));
488 if (eType == PT_Invalid)
489 throw beans::UnknownPropertyException();
491 const ThemeItem eItem (iId->second);
493 return maRawValues[eItem];
496 void SAL_CALL Theme::addPropertyChangeListener(
497 const ::rtl::OUString& rsPropertyName,
498 const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
499 throw(css::beans::UnknownPropertyException,
500 css::lang::WrappedTargetException,
501 css::uno::RuntimeException, std::exception)
503 ThemeItem eItem (__AnyItem);
504 if (rsPropertyName.getLength() > 0)
506 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
507 if (iId == maPropertyNameToIdMap.end())
508 throw beans::UnknownPropertyException();
510 const PropertyType eType (GetPropertyType(iId->second));
511 if (eType == PT_Invalid)
512 throw beans::UnknownPropertyException();
514 eItem = iId->second;
516 ChangeListenerContainer* pListeners = GetChangeListeners(eItem, true);
517 if (pListeners != NULL)
518 pListeners->push_back(rxListener);
521 void SAL_CALL Theme::removePropertyChangeListener(
522 const ::rtl::OUString& rsPropertyName,
523 const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
524 throw(css::beans::UnknownPropertyException,
525 css::lang::WrappedTargetException,
526 css::uno::RuntimeException, std::exception)
528 ThemeItem eItem (__AnyItem);
529 if (rsPropertyName.getLength() > 0)
531 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
532 if (iId == maPropertyNameToIdMap.end())
533 throw beans::UnknownPropertyException();
535 const PropertyType eType (GetPropertyType(iId->second));
536 if (eType == PT_Invalid)
537 throw beans::UnknownPropertyException();
539 eItem = iId->second;
541 ChangeListenerContainer* pContainer = GetChangeListeners(eItem, false);
542 if (pContainer != NULL)
544 ChangeListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener));
545 if (iListener != pContainer->end())
547 pContainer->erase(iListener);
549 // Remove the listener container when empty.
550 if (pContainer->empty())
551 maChangeListeners.erase(eItem);
556 void SAL_CALL Theme::addVetoableChangeListener(
557 const ::rtl::OUString& rsPropertyName,
558 const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
559 throw(css::beans::UnknownPropertyException,
560 css::lang::WrappedTargetException,
561 css::uno::RuntimeException, std::exception)
563 ThemeItem eItem (__AnyItem);
564 if (rsPropertyName.getLength() > 0)
566 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
567 if (iId == maPropertyNameToIdMap.end())
568 throw beans::UnknownPropertyException();
570 const PropertyType eType (GetPropertyType(iId->second));
571 if (eType == PT_Invalid)
572 throw beans::UnknownPropertyException();
574 eItem = iId->second;
576 VetoableListenerContainer* pListeners = GetVetoableListeners(eItem, true);
577 if (pListeners != NULL)
578 pListeners->push_back(rxListener);
581 void SAL_CALL Theme::removeVetoableChangeListener(
582 const ::rtl::OUString& rsPropertyName,
583 const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
584 throw(css::beans::UnknownPropertyException,
585 css::lang::WrappedTargetException,
586 css::uno::RuntimeException, std::exception)
588 ThemeItem eItem (__AnyItem);
589 if (rsPropertyName.getLength() > 0)
591 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
592 if (iId == maPropertyNameToIdMap.end())
593 throw beans::UnknownPropertyException();
595 const PropertyType eType (GetPropertyType(iId->second));
596 if (eType == PT_Invalid)
597 throw beans::UnknownPropertyException();
599 eItem = iId->second;
601 VetoableListenerContainer* pContainer = GetVetoableListeners(eItem, false);
602 if (pContainer != NULL)
604 VetoableListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener));
605 if (iListener != pContainer->end())
607 pContainer->erase(iListener);
608 // Remove container when empty.
609 if (pContainer->empty())
610 maVetoableListeners.erase(eItem);
615 css::uno::Sequence<css::beans::Property> SAL_CALL Theme::getProperties()
616 throw(css::uno::RuntimeException, std::exception)
618 ::std::vector<beans::Property> aProperties;
620 for (sal_Int32 nItem(__Begin),nEnd(__End); nItem!=nEnd; ++nItem)
622 const ThemeItem eItem (static_cast<ThemeItem>(nItem));
623 const PropertyType eType (GetPropertyType(eItem));
624 if (eType == PT_Invalid)
625 continue;
627 const beans::Property aProperty(
628 maPropertyIdToNameMap[eItem],
629 eItem,
630 GetCppuType(eType),
632 aProperties.push_back(aProperty);
635 return css::uno::Sequence<css::beans::Property>(
636 &aProperties.front(),
637 aProperties.size());
640 beans::Property SAL_CALL Theme::getPropertyByName (const ::rtl::OUString& rsPropertyName)
641 throw(css::beans::UnknownPropertyException,
642 css::uno::RuntimeException, std::exception)
644 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
645 if (iId == maPropertyNameToIdMap.end())
646 throw beans::UnknownPropertyException();
648 const PropertyType eType (GetPropertyType(iId->second));
649 if (eType == PT_Invalid)
650 throw beans::UnknownPropertyException();
652 const ThemeItem eItem (iId->second);
654 return beans::Property(
655 rsPropertyName,
656 eItem,
657 GetCppuType(eType),
661 sal_Bool SAL_CALL Theme::hasPropertyByName (const ::rtl::OUString& rsPropertyName)
662 throw(css::uno::RuntimeException, std::exception)
664 PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
665 if (iId == maPropertyNameToIdMap.end())
666 return sal_False;
668 const PropertyType eType (GetPropertyType(iId->second));
669 if (eType == PT_Invalid)
670 return sal_False;
672 return sal_True;
675 void Theme::SetupPropertyMaps()
677 maPropertyIdToNameMap.resize(__Post_Rect);
678 maImages.resize(__Image_Color - __Pre_Image - 1);
679 maColors.resize(__Color_Paint - __Image_Color - 1);
680 maPaints.resize(__Paint_Int - __Color_Paint - 1);
681 maIntegers.resize(__Int_Bool - __Paint_Int - 1);
682 maBooleans.resize(__Bool_Rect - __Int_Bool - 1);
683 maRectangles.resize(__Post_Rect - __Bool_Rect - 1);
685 #define AddEntry(e) maPropertyNameToIdMap[OUString(#e)]=e; maPropertyIdToNameMap[e]=#e
687 AddEntry(Image_Grip);
688 AddEntry(Image_Expand);
689 AddEntry(Image_Collapse);
690 AddEntry(Image_TabBarMenu);
691 AddEntry(Image_PanelMenu);
692 AddEntry(Image_ToolBoxItemSeparator);
693 AddEntry(Image_Closer);
694 AddEntry(Image_CloseIndicator);
696 AddEntry(Color_DeckTitleFont);
697 AddEntry(Color_PanelTitleFont);
698 AddEntry(Color_TabMenuSeparator);
699 AddEntry(Color_TabItemBorder);
700 AddEntry(Color_DropDownBorder);
701 AddEntry(Color_Highlight);
702 AddEntry(Color_HighlightText);
704 AddEntry(Paint_DeckBackground);
705 AddEntry(Paint_DeckTitleBarBackground);
706 AddEntry(Paint_PanelBackground);
707 AddEntry(Paint_PanelTitleBarBackground);
708 AddEntry(Paint_TabBarBackground);
709 AddEntry(Paint_TabItemBackgroundNormal);
710 AddEntry(Paint_TabItemBackgroundHighlight);
711 AddEntry(Paint_HorizontalBorder);
712 AddEntry(Paint_VerticalBorder);
713 AddEntry(Paint_ToolBoxBackground);
714 AddEntry(Paint_ToolBoxBorderTopLeft);
715 AddEntry(Paint_ToolBoxBorderCenterCorners);
716 AddEntry(Paint_ToolBoxBorderBottomRight);
717 AddEntry(Paint_DropDownBackground);
719 AddEntry(Int_DeckTitleBarHeight);
720 AddEntry(Int_DeckBorderSize);
721 AddEntry(Int_DeckSeparatorHeight);
722 AddEntry(Int_PanelTitleBarHeight);
723 AddEntry(Int_TabMenuPadding);
724 AddEntry(Int_TabMenuSeparatorPadding);
725 AddEntry(Int_TabItemWidth);
726 AddEntry(Int_TabItemHeight);
727 AddEntry(Int_DeckLeftPadding);
728 AddEntry(Int_DeckTopPadding);
729 AddEntry(Int_DeckRightPadding);
730 AddEntry(Int_DeckBottomPadding);
731 AddEntry(Int_TabBarLeftPadding);
732 AddEntry(Int_TabBarTopPadding);
733 AddEntry(Int_TabBarRightPadding);
734 AddEntry(Int_TabBarBottomPadding);
735 AddEntry(Int_ButtonCornerRadius);
737 AddEntry(Bool_UseSymphonyIcons);
738 AddEntry(Bool_UseSystemColors);
739 AddEntry(Bool_UseToolBoxItemSeparator);
740 AddEntry(Bool_IsHighContrastModeActive);
742 AddEntry(Rect_ToolBoxPadding);
743 AddEntry(Rect_ToolBoxBorder);
745 #undef AddEntry
747 maRawValues.resize(maPropertyIdToNameMap.size());
750 Theme::PropertyType Theme::GetPropertyType (const ThemeItem eItem)
752 switch(eItem)
754 case Image_Grip:
755 case Image_Expand:
756 case Image_Collapse:
757 case Image_TabBarMenu:
758 case Image_PanelMenu:
759 case Image_ToolBoxItemSeparator:
760 case Image_Closer:
761 case Image_CloseIndicator:
762 return PT_Image;
764 case Color_DeckTitleFont:
765 case Color_PanelTitleFont:
766 case Color_TabMenuSeparator:
767 case Color_TabItemBorder:
768 case Color_DropDownBorder:
769 case Color_Highlight:
770 case Color_HighlightText:
771 return PT_Color;
773 case Paint_DeckBackground:
774 case Paint_DeckTitleBarBackground:
775 case Paint_PanelBackground:
776 case Paint_PanelTitleBarBackground:
777 case Paint_TabBarBackground:
778 case Paint_TabItemBackgroundNormal:
779 case Paint_TabItemBackgroundHighlight:
780 case Paint_HorizontalBorder:
781 case Paint_VerticalBorder:
782 case Paint_ToolBoxBackground:
783 case Paint_ToolBoxBorderTopLeft:
784 case Paint_ToolBoxBorderCenterCorners:
785 case Paint_ToolBoxBorderBottomRight:
786 case Paint_DropDownBackground:
787 return PT_Paint;
789 case Int_DeckTitleBarHeight:
790 case Int_DeckBorderSize:
791 case Int_DeckSeparatorHeight:
792 case Int_PanelTitleBarHeight:
793 case Int_TabMenuPadding:
794 case Int_TabMenuSeparatorPadding:
795 case Int_TabItemWidth:
796 case Int_TabItemHeight:
797 case Int_DeckLeftPadding:
798 case Int_DeckTopPadding:
799 case Int_DeckRightPadding:
800 case Int_DeckBottomPadding:
801 case Int_TabBarLeftPadding:
802 case Int_TabBarTopPadding:
803 case Int_TabBarRightPadding:
804 case Int_TabBarBottomPadding:
805 case Int_ButtonCornerRadius:
806 return PT_Integer;
808 case Bool_UseSymphonyIcons:
809 case Bool_UseSystemColors:
810 case Bool_UseToolBoxItemSeparator:
811 case Bool_IsHighContrastModeActive:
812 return PT_Boolean;
814 case Rect_ToolBoxBorder:
815 case Rect_ToolBoxPadding:
816 return PT_Rectangle;
818 default:
819 return PT_Invalid;
823 css::uno::Type Theme::GetCppuType (const PropertyType eType)
825 switch(eType)
827 case PT_Image:
828 return cppu::UnoType<rtl::OUString>::get();
830 case PT_Color:
831 return cppu::UnoType<sal_uInt32>::get();
833 case PT_Paint:
834 return cppu::UnoType<void>::get();
836 case PT_Integer:
837 return cppu::UnoType<sal_Int32>::get();
839 case PT_Boolean:
840 return cppu::UnoType<sal_Bool>::get();
842 case PT_Rectangle:
843 return cppu::UnoType<awt::Rectangle>::get();
845 case PT_Invalid:
846 default:
847 return cppu::UnoType<void>::get();
851 sal_Int32 Theme::GetIndex (const ThemeItem eItem, const PropertyType eType)
853 switch(eType)
855 case PT_Image:
856 return eItem - __Pre_Image-1;
857 case PT_Color:
858 return eItem - __Image_Color-1;
859 case PT_Paint:
860 return eItem - __Color_Paint-1;
861 case PT_Integer:
862 return eItem - __Paint_Int-1;
863 case PT_Boolean:
864 return eItem - __Int_Bool-1;
865 case PT_Rectangle:
866 return eItem - __Bool_Rect-1;
868 default:
869 OSL_ASSERT(false);
870 return 0;
874 Theme::VetoableListenerContainer* Theme::GetVetoableListeners (
875 const ThemeItem eItem,
876 const bool bCreate)
878 VetoableListeners::iterator iContainer (maVetoableListeners.find(eItem));
879 if (iContainer != maVetoableListeners.end())
880 return &iContainer->second;
881 else if (bCreate)
883 maVetoableListeners[eItem] = VetoableListenerContainer();
884 return &maVetoableListeners[eItem];
886 else
887 return NULL;
890 Theme::ChangeListenerContainer* Theme::GetChangeListeners (
891 const ThemeItem eItem,
892 const bool bCreate)
894 ChangeListeners::iterator iContainer (maChangeListeners.find(eItem));
895 if (iContainer != maChangeListeners.end())
896 return &iContainer->second;
897 else if (bCreate)
899 maChangeListeners[eItem] = ChangeListenerContainer();
900 return &maChangeListeners[eItem];
902 else
903 return NULL;
906 bool Theme::DoVetoableListenersVeto (
907 const VetoableListenerContainer* pListeners,
908 const beans::PropertyChangeEvent& rEvent)
910 if (pListeners == NULL)
911 return false;
913 VetoableListenerContainer aListeners (*pListeners);
916 for (VetoableListenerContainer::const_iterator
917 iListener(aListeners.begin()),
918 iEnd(aListeners.end());
919 iListener!=iEnd;
920 ++iListener)
922 (*iListener)->vetoableChange(rEvent);
925 catch(const beans::PropertyVetoException&)
927 return true;
929 catch(const Exception&)
931 // Ignore any other errors (such as disposed listeners).
933 return false;
936 void Theme::BroadcastPropertyChange (
937 const ChangeListenerContainer* pListeners,
938 const beans::PropertyChangeEvent& rEvent)
940 if (pListeners == NULL)
941 return;
943 const ChangeListenerContainer aListeners (*pListeners);
946 for (ChangeListenerContainer::const_iterator
947 iListener(aListeners.begin()),
948 iEnd(aListeners.end());
949 iListener!=iEnd;
950 ++iListener)
952 (*iListener)->propertyChange(rEvent);
955 catch(const Exception&)
957 // Ignore any errors (such as disposed listeners).
961 void Theme::ProcessNewValue (
962 const Any& rValue,
963 const ThemeItem eItem,
964 const PropertyType eType)
966 const sal_Int32 nIndex (GetIndex (eItem, eType));
967 switch (eType)
969 case PT_Image:
971 ::rtl::OUString sURL;
972 if (rValue >>= sURL)
974 maImages[nIndex] = Tools::GetImage(sURL, NULL);
976 break;
978 case PT_Color:
980 sal_Int32 nColorValue (0);
981 if (rValue >>= nColorValue)
983 maColors[nIndex] = Color(nColorValue);
985 break;
987 case PT_Paint:
989 maPaints[nIndex] = Paint::Create(rValue);
990 break;
992 case PT_Integer:
994 sal_Int32 nValue (0);
995 if (rValue >>= nValue)
997 maIntegers[nIndex] = nValue;
999 break;
1001 case PT_Boolean:
1003 bool nValue (false);
1004 if (rValue >>= nValue)
1006 maBooleans[nIndex] = nValue;
1007 if (eItem == Bool_IsHighContrastModeActive)
1009 mbIsHighContrastModeSetManually = true;
1010 mbIsHighContrastMode = maBooleans[nIndex];
1011 HandleDataChange();
1013 else if (eItem == Bool_UseSystemColors)
1015 HandleDataChange();
1018 break;
1020 case PT_Rectangle:
1022 awt::Rectangle aBox;
1023 if (rValue >>= aBox)
1025 maRectangles[nIndex] = Rectangle(
1026 aBox.X,
1027 aBox.Y,
1028 aBox.Width,
1029 aBox.Height);
1031 break;
1033 case PT_Invalid:
1034 OSL_ASSERT(eType != PT_Invalid);
1035 throw RuntimeException();
1039 } } // end of namespace sfx2::sidebar
1041 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */