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