xref: /aoo42x/main/sfx2/source/sidebar/Theme.cxx (revision 0d805bdd)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include "precompiled_sfx2.hxx"
23 
24 #include "sfx2/sidebar/Theme.hxx"
25 #include "Paint.hxx"
26 #include "SidebarResource.hxx"
27 #include "Tools.hxx"
28 
29 #include <tools/svborder.hxx>
30 #include <tools/rc.hxx>
31 #include <vcl/svapp.hxx>
32 
33 using namespace css;
34 using namespace cssu;
35 
36 
37 namespace sfx2 { namespace sidebar {
38 
39 ::rtl::Reference<Theme> Theme::mpInstance;
40 
41 
42 
43 
44 Theme& Theme::GetCurrentTheme (void)
45 {
46     if ( ! mpInstance.is())
47     {
48         mpInstance.set(new Theme());
49         mpInstance->InitializeTheme();
50     }
51     return *mpInstance;
52 }
53 
54 
55 
56 
57 Theme::Theme (void)
58     : ThemeInterfaceBase(m_aMutex),
59       maImages(),
60       maColors(),
61       maPaints(),
62       maIntegers(),
63       maBooleans(),
64       mbIsHighContrastMode(Application::GetSettings().GetStyleSettings().GetHighContrastMode()),
65       mbIsHighContrastModeSetManually(false),
66       maPropertyNameToIdMap(),
67       maPropertyIdToNameMap(),
68       maRawValues(),
69       maChangeListeners(),
70       maVetoableListeners()
71 
72 {
73     SetupPropertyMaps();
74 }
75 
76 
77 
78 
79 Theme::~Theme (void)
80 {
81 }
82 
83 
84 
85 
86 Image Theme::GetImage (const ThemeItem eItem)
87 {
88     const PropertyType eType (GetPropertyType(eItem));
89     OSL_ASSERT(eType==PT_Image);
90     const sal_Int32 nIndex (GetIndex(eItem, eType));
91     const Theme& rTheme (GetCurrentTheme());
92     return rTheme.maImages[nIndex];
93 }
94 
95 
96 
97 
98 Color Theme::GetColor (const ThemeItem eItem)
99 {
100     const PropertyType eType (GetPropertyType(eItem));
101     OSL_ASSERT(eType==PT_Color || eType==PT_Paint);
102     const sal_Int32 nIndex (GetIndex(eItem, eType));
103     const Theme& rTheme (GetCurrentTheme());
104     if (eType == PT_Color)
105         return rTheme.maColors[nIndex];
106     else if (eType == PT_Paint)
107         return rTheme.maPaints[nIndex].GetColor();
108     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         const Color aBaseBackgroundColor (rStyle.GetDialogColor());
222         Color aBorderColor (aBaseBackgroundColor);
223         aBorderColor.DecreaseLuminance(15);
224         Color aSecondColor (aBaseBackgroundColor);
225         aSecondColor.DecreaseLuminance(15);
226 
227         setPropertyValue(
228             maPropertyIdToNameMap[Paint_DeckBackground],
229             Any(sal_Int32(rStyle.GetMenuColor().GetRGBColor())));
230 
231         setPropertyValue(
232             maPropertyIdToNameMap[Paint_DeckTitleBarBackground],
233             Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
234         setPropertyValue(
235             maPropertyIdToNameMap[Int_DeckLeftPadding],
236             Any(sal_Int32(2)));
237         setPropertyValue(
238             maPropertyIdToNameMap[Int_DeckTopPadding],
239             Any(sal_Int32(2)));
240         setPropertyValue(
241             maPropertyIdToNameMap[Int_DeckRightPadding],
242             Any(sal_Int32(2)));
243         setPropertyValue(
244             maPropertyIdToNameMap[Int_DeckBottomPadding],
245             Any(sal_Int32(2)));
246         setPropertyValue(
247             maPropertyIdToNameMap[Int_DeckBorderSize],
248             Any(sal_Int32(1)));
249         setPropertyValue(
250             maPropertyIdToNameMap[Int_DeckSeparatorHeight],
251             Any(sal_Int32(1)));
252         setPropertyValue(
253             maPropertyIdToNameMap[Color_DeckTitleFont],
254             Any(sal_Int32(rStyle.GetFontColor().GetRGBColor())));
255         setPropertyValue(
256             maPropertyIdToNameMap[Int_DeckTitleBarHeight],
257             Any(sal_Int32(Alternatives(
258                         26,
259                         26,
260                         rStyle.GetFloatTitleHeight()))));
261         setPropertyValue(
262             maPropertyIdToNameMap[Paint_PanelBackground],
263             Any(sal_Int32(rStyle.GetDialogColor().GetRGBColor())));
264         //            Any(sal_Int32(mbIsHighContrastMode ? 0x000000 :
265         //            0xffffff)));
266 
267         setPropertyValue(
268             maPropertyIdToNameMap[Paint_PanelTitleBarBackground],
269             Any(Tools::VclToAwtGradient(Gradient(
270                         GRADIENT_LINEAR,
271                         aSecondColor.GetRGBColor(),
272                         aBaseBackgroundColor.GetRGBColor()
273                         ))));
274         setPropertyValue(
275             maPropertyIdToNameMap[Color_PanelTitleFont],
276             Any(sal_Int32(mbIsHighContrastMode ? 0x00ff00 : 0x262626)));
277         setPropertyValue(
278             maPropertyIdToNameMap[Int_PanelTitleBarHeight],
279             Any(sal_Int32(Alternatives(
280                         26,
281                         26,
282                         rStyle.GetTitleHeight()))));
283         setPropertyValue(
284             maPropertyIdToNameMap[Paint_TabBarBackground],
285             Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
286         setPropertyValue(
287             maPropertyIdToNameMap[Int_TabBarLeftPadding],
288             Any(sal_Int32(2)));
289         setPropertyValue(
290             maPropertyIdToNameMap[Int_TabBarTopPadding],
291             Any(sal_Int32(2)));
292         setPropertyValue(
293             maPropertyIdToNameMap[Int_TabBarRightPadding],
294             Any(sal_Int32(2)));
295         setPropertyValue(
296             maPropertyIdToNameMap[Int_TabBarBottomPadding],
297             Any(sal_Int32(2)));
298 
299         setPropertyValue(
300             maPropertyIdToNameMap[Int_TabMenuPadding],
301             Any(sal_Int32(6)));
302         setPropertyValue(
303             maPropertyIdToNameMap[Color_TabMenuSeparator],
304             Any(sal_Int32(aBorderColor.GetRGBColor())));
305         setPropertyValue(
306             maPropertyIdToNameMap[Int_TabMenuSeparatorPadding],
307             Any(sal_Int32(7)));
308 
309         setPropertyValue(
310             maPropertyIdToNameMap[Int_TabItemWidth],
311             Any(sal_Int32(32)));
312         setPropertyValue(
313             maPropertyIdToNameMap[Int_TabItemHeight],
314             Any(sal_Int32(32)));
315         setPropertyValue(
316             maPropertyIdToNameMap[Color_TabItemBorder],
317             Any(sal_Int32(rStyle.GetActiveBorderColor().GetRGBColor())));
318         //                    mbIsHighContrastMode ? 0x00ff00 : 0xbfbfbf)));
319 
320         setPropertyValue(
321             maPropertyIdToNameMap[Paint_DropDownBackground],
322             Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
323         setPropertyValue(
324             maPropertyIdToNameMap[Color_DropDownBorder],
325             Any(sal_Int32(rStyle.GetActiveBorderColor().GetRGBColor())));
326 
327         setPropertyValue(
328             maPropertyIdToNameMap[Color_Highlight],
329             Any(sal_Int32(rStyle.GetHighlightColor().GetRGBColor())));
330         setPropertyValue(
331             maPropertyIdToNameMap[Color_HighlightText],
332             Any(sal_Int32(rStyle.GetHighlightTextColor().GetRGBColor())));
333 
334         setPropertyValue(
335             maPropertyIdToNameMap[Paint_TabItemBackgroundNormal],
336             Any());
337         setPropertyValue(
338             maPropertyIdToNameMap[Paint_TabItemBackgroundHighlight],
339             Any(sal_Int32(rStyle.GetActiveTabColor().GetRGBColor())));
340         //                    mbIsHighContrastMode ? 0x000000 : 0x00ffffff)));
341 
342         setPropertyValue(
343             maPropertyIdToNameMap[Paint_HorizontalBorder],
344             Any(sal_Int32(aBorderColor.GetRGBColor())));
345         //                    mbIsHighContrastMode ? 0x00ff00 :  0xe4e4e4)));
346         setPropertyValue(
347             maPropertyIdToNameMap[Paint_VerticalBorder],
348             Any(sal_Int32(aBorderColor.GetRGBColor())));
349         //                    mbIsHighContrastMode ? 0x00ff00 : 0xe4e4e4)));
350 
351         setPropertyValue(
352             maPropertyIdToNameMap[Image_Grip],
353             Any(
354                 mbIsHighContrastMode
355                     ? A2S("private:graphicrepository/sfx2/res/grip_hc.png")
356                     : A2S("private:graphicrepository/sfx2/res/grip.png")));
357         setPropertyValue(
358             maPropertyIdToNameMap[Image_Expand],
359             Any(
360                 mbIsHighContrastMode
361                     ? A2S("private:graphicrepository/res/plus_sch.png")
362                     : A2S("private:graphicrepository/res/plus.png")));
363         setPropertyValue(
364             maPropertyIdToNameMap[Image_Collapse],
365             Any(
366                 mbIsHighContrastMode
367                     ? A2S("private:graphicrepository/res/minus_sch.png")
368                     : A2S("private:graphicrepository/res/minus.png")));
369         setPropertyValue(
370             maPropertyIdToNameMap[Image_TabBarMenu],
371             Any(
372                 mbIsHighContrastMode
373                     ? A2S("private:graphicrepository/sfx2/res/menu_hc.png")
374                     : A2S("private:graphicrepository/sfx2/res/symphony/open_more.png")));
375         setPropertyValue(
376             maPropertyIdToNameMap[Image_PanelMenu],
377             Any(
378                 mbIsHighContrastMode
379                     ? A2S("private:graphicrepository/sfx2/res/symphony/morebutton.png")
380                     : A2S("private:graphicrepository/sfx2/res/symphony/morebutton_h.png")));
381         setPropertyValue(
382             maPropertyIdToNameMap[Image_Closer],
383             Any(A2S("private:graphicrepository/sfx2/res/closedoc.png")));
384         setPropertyValue(
385             maPropertyIdToNameMap[Image_ToolBoxItemSeparator],
386             Any(
387                 A2S("private:graphicrepository/sfx2/res/separator.png")));
388 
389         // ToolBox
390 
391         /*
392         // Separator style
393         setPropertyValue(
394             maPropertyIdToNameMap[Paint_ToolBoxBackground],
395             Any(sal_Int32(rStyle.GetMenuColor().GetRGBColor())));
396         setPropertyValue(
397             maPropertyIdToNameMap[Paint_ToolBoxBorderTopLeft],
398             Any());
399         setPropertyValue(
400             maPropertyIdToNameMap[Paint_ToolBoxBorderCenterCorners],
401             Any());
402         setPropertyValue(
403             maPropertyIdToNameMap[Paint_ToolBoxBorderBottomRight],
404             Any());
405         setPropertyValue(
406             maPropertyIdToNameMap[Rect_ToolBoxPadding],
407             Any(awt::Rectangle(2,2,2,2)));
408         setPropertyValue(
409             maPropertyIdToNameMap[Rect_ToolBoxBorder],
410             Any(awt::Rectangle(0,0,0,0)));
411         setPropertyValue(
412             maPropertyIdToNameMap[Bool_UseToolBoxItemSeparator],
413             Any(true));
414 
415         */
416 
417         // Gradient style
418         setPropertyValue(
419             maPropertyIdToNameMap[Paint_ToolBoxBackground],
420             Any(Tools::VclToAwtGradient(Gradient(
421                         GRADIENT_LINEAR,
422                         Color(0xf2f2f2),
423                         Color(0xfefefe)
424                         ))));
425         setPropertyValue(
426             maPropertyIdToNameMap[Paint_ToolBoxBorderTopLeft],
427             mbIsHighContrastMode
428                 ? Any(util::Color(sal_uInt32(0x00ff00)))
429                 : Any(util::Color(sal_uInt32(0xf2f2f2))));
430         setPropertyValue(
431             maPropertyIdToNameMap[Paint_ToolBoxBorderCenterCorners],
432             mbIsHighContrastMode
433                 ? Any(util::Color(sal_uInt32(0x00ff00)))
434                 : Any(util::Color(sal_uInt32(0xf2f2f2))));
435         setPropertyValue(
436             maPropertyIdToNameMap[Paint_ToolBoxBorderBottomRight],
437             mbIsHighContrastMode
438                 ? Any(util::Color(sal_uInt32(0x00ff00)))
439                 : Any(util::Color(sal_uInt32(0xf2f2f2))));
440         setPropertyValue(
441             maPropertyIdToNameMap[Rect_ToolBoxPadding],
442             Any(awt::Rectangle(2,2,2,2)));
443         setPropertyValue(
444             maPropertyIdToNameMap[Rect_ToolBoxBorder],
445             Any(awt::Rectangle(1,1,1,1)));
446         setPropertyValue(
447             maPropertyIdToNameMap[Bool_UseToolBoxItemSeparator],
448             Any(false));
449     }
450     catch(beans::UnknownPropertyException& rException)
451     {
452         OSL_TRACE("unknown property: %s",
453             OUStringToOString(
454                 rException.Message,
455                 RTL_TEXTENCODING_ASCII_US).getStr());
456         OSL_ASSERT(false);
457     }
458 }
459 
460 
461 
462 
463 void SAL_CALL Theme::disposing (void)
464 {
465     ChangeListeners aListeners;
466     maChangeListeners.swap(aListeners);
467 
468     const lang::EventObject aEvent (static_cast<XWeak*>(this));
469 
470     for (ChangeListeners::const_iterator
471              iContainer(maChangeListeners.begin()),
472              iContainerEnd(maChangeListeners.end());
473          iContainerEnd!=iContainerEnd;
474          ++iContainerEnd)
475     {
476         for (ChangeListenerContainer::const_iterator
477                  iListener(iContainer->second.begin()),
478                  iEnd(iContainer->second.end());
479              iListener!=iEnd;
480              ++iListener)
481         {
482             try
483             {
484                 (*iListener)->disposing(aEvent);
485             }
486             catch(const Exception&)
487             {
488             }
489         }
490     }
491 }
492 
493 
494 
495 
496 Reference<beans::XPropertySet> Theme::GetPropertySet (void)
497 {
498     return Reference<beans::XPropertySet>(static_cast<XWeak*>(&GetCurrentTheme()), UNO_QUERY);
499 }
500 
501 
502 
503 
504 Reference<beans::XPropertySetInfo> SAL_CALL Theme::getPropertySetInfo (void)
505     throw(cssu::RuntimeException)
506 {
507     return Reference<beans::XPropertySetInfo>(this);
508 }
509 
510 
511 
512 
513 void SAL_CALL Theme::setPropertyValue (
514     const ::rtl::OUString& rsPropertyName,
515     const cssu::Any& rValue)
516     throw(cssu::RuntimeException)
517 {
518     PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
519     if (iId == maPropertyNameToIdMap.end())
520         throw beans::UnknownPropertyException(rsPropertyName, NULL);
521 
522     const PropertyType eType (GetPropertyType(iId->second));
523     if (eType == PT_Invalid)
524         throw beans::UnknownPropertyException(rsPropertyName, NULL);
525 
526     const ThemeItem eItem (iId->second);
527 
528     if (rValue == maRawValues[eItem])
529     {
530         // Value is not different from the one in the property
531         // set => nothing to do.
532         return;
533     }
534 
535     const Any aOldValue (maRawValues[eItem]);
536 
537     const beans::PropertyChangeEvent aEvent(
538         static_cast<XWeak*>(this),
539         rsPropertyName,
540         sal_False,
541         eItem,
542         aOldValue,
543         rValue);
544 
545     if (DoVetoableListenersVeto(GetVetoableListeners(__AnyItem, false), aEvent))
546         return;
547     if (DoVetoableListenersVeto(GetVetoableListeners(eItem, false), aEvent))
548         return;
549 
550     maRawValues[eItem] = rValue;
551     ProcessNewValue(rValue, eItem, eType);
552 
553     BroadcastPropertyChange(GetChangeListeners(__AnyItem, false), aEvent);
554     BroadcastPropertyChange(GetChangeListeners(eItem, false), aEvent);
555 }
556 
557 
558 
559 
560 Any SAL_CALL Theme::getPropertyValue (
561     const ::rtl::OUString& rsPropertyName)
562     throw(css::beans::UnknownPropertyException,
563         css::lang::WrappedTargetException,
564         cssu::RuntimeException)
565 {
566     PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
567     if (iId == maPropertyNameToIdMap.end())
568         throw beans::UnknownPropertyException();
569 
570     const PropertyType eType (GetPropertyType(iId->second));
571     if (eType == PT_Invalid)
572         throw beans::UnknownPropertyException();
573 
574     const ThemeItem eItem (iId->second);
575 
576     return maRawValues[eItem];
577 }
578 
579 
580 
581 
582 void SAL_CALL Theme::addPropertyChangeListener(
583     const ::rtl::OUString& rsPropertyName,
584     const cssu::Reference<css::beans::XPropertyChangeListener>& rxListener)
585     throw(css::beans::UnknownPropertyException,
586         css::lang::WrappedTargetException,
587         cssu::RuntimeException)
588 {
589     ThemeItem eItem (__AnyItem);
590     if (rsPropertyName.getLength() > 0)
591     {
592         PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
593         if (iId == maPropertyNameToIdMap.end())
594             throw beans::UnknownPropertyException();
595 
596         const PropertyType eType (GetPropertyType(iId->second));
597         if (eType == PT_Invalid)
598             throw beans::UnknownPropertyException();
599 
600         eItem = iId->second;
601     }
602     ChangeListenerContainer* pListeners = GetChangeListeners(eItem, true);
603     if (pListeners != NULL)
604         pListeners->push_back(rxListener);
605 }
606 
607 
608 
609 
610 void SAL_CALL Theme::removePropertyChangeListener(
611     const ::rtl::OUString& rsPropertyName,
612     const cssu::Reference<css::beans::XPropertyChangeListener>& rxListener)
613     throw(css::beans::UnknownPropertyException,
614         css::lang::WrappedTargetException,
615         cssu::RuntimeException)
616 {
617     ThemeItem eItem (__AnyItem);
618     if (rsPropertyName.getLength() > 0)
619     {
620         PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
621         if (iId == maPropertyNameToIdMap.end())
622             throw beans::UnknownPropertyException();
623 
624         const PropertyType eType (GetPropertyType(iId->second));
625         if (eType == PT_Invalid)
626             throw beans::UnknownPropertyException();
627 
628         eItem = iId->second;
629     }
630     ChangeListenerContainer* pContainer = GetChangeListeners(eItem, false);
631     if (pContainer != NULL)
632     {
633         ChangeListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener));
634         if (iListener != pContainer->end())
635         {
636             pContainer->erase(iListener);
637 
638             // Remove the listener container when empty.
639             if (pContainer->empty())
640                 maChangeListeners.erase(eItem);
641         }
642     }
643 }
644 
645 
646 
647 
648 void SAL_CALL Theme::addVetoableChangeListener(
649     const ::rtl::OUString& rsPropertyName,
650     const cssu::Reference<css::beans::XVetoableChangeListener>& rxListener)
651     throw(css::beans::UnknownPropertyException,
652         css::lang::WrappedTargetException,
653         cssu::RuntimeException)
654 {
655     ThemeItem eItem (__AnyItem);
656     if (rsPropertyName.getLength() > 0)
657     {
658         PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
659         if (iId == maPropertyNameToIdMap.end())
660             throw beans::UnknownPropertyException();
661 
662         const PropertyType eType (GetPropertyType(iId->second));
663         if (eType == PT_Invalid)
664             throw beans::UnknownPropertyException();
665 
666         eItem = iId->second;
667     }
668     VetoableListenerContainer* pListeners = GetVetoableListeners(eItem, true);
669     if (pListeners != NULL)
670         pListeners->push_back(rxListener);
671 }
672 
673 
674 
675 
676 void SAL_CALL Theme::removeVetoableChangeListener(
677     const ::rtl::OUString& rsPropertyName,
678     const cssu::Reference<css::beans::XVetoableChangeListener>& rxListener)
679     throw(css::beans::UnknownPropertyException,
680         css::lang::WrappedTargetException,
681         cssu::RuntimeException)
682 {
683     ThemeItem eItem (__AnyItem);
684     if (rsPropertyName.getLength() > 0)
685     {
686         PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
687         if (iId == maPropertyNameToIdMap.end())
688             throw beans::UnknownPropertyException();
689 
690         const PropertyType eType (GetPropertyType(iId->second));
691         if (eType == PT_Invalid)
692             throw beans::UnknownPropertyException();
693 
694         eItem = iId->second;
695     }
696     VetoableListenerContainer* pContainer = GetVetoableListeners(eItem, false);
697     if (pContainer != NULL)
698     {
699         VetoableListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener));
700         if (iListener != pContainer->end())
701         {
702             pContainer->erase(iListener);
703             // Remove container when empty.
704             if (pContainer->empty())
705                 maVetoableListeners.erase(eItem);
706         }
707     }
708 }
709 
710 
711 
712 
713 cssu::Sequence<css::beans::Property> SAL_CALL Theme::getProperties (void)
714     throw(cssu::RuntimeException)
715 {
716     ::std::vector<beans::Property> aProperties;
717 
718     for (sal_Int32 nItem(__Begin),nEnd(__End); nItem!=nEnd; ++nItem)
719     {
720         const ThemeItem eItem (static_cast<ThemeItem>(nItem));
721         const PropertyType eType (GetPropertyType(eItem));
722         if (eType == PT_Invalid)
723             continue;
724 
725         const beans::Property aProperty(
726             maPropertyIdToNameMap[eItem],
727             eItem,
728             GetCppuType(eType),
729             0);
730         aProperties.push_back(aProperty);
731     }
732 
733     return cssu::Sequence<css::beans::Property>(
734         &aProperties.front(),
735         aProperties.size());
736 }
737 
738 
739 
740 
741 beans::Property SAL_CALL Theme::getPropertyByName (const ::rtl::OUString& rsPropertyName)
742     throw(css::beans::UnknownPropertyException,
743         cssu::RuntimeException)
744 {
745     PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
746     if (iId == maPropertyNameToIdMap.end())
747         throw beans::UnknownPropertyException();
748 
749     const PropertyType eType (GetPropertyType(iId->second));
750     if (eType == PT_Invalid)
751         throw beans::UnknownPropertyException();
752 
753     const ThemeItem eItem (iId->second);
754 
755     return beans::Property(
756         rsPropertyName,
757         eItem,
758         GetCppuType(eType),
759         0);
760 }
761 
762 
763 
764 
765 sal_Bool SAL_CALL Theme::hasPropertyByName (const ::rtl::OUString& rsPropertyName)
766     throw(cssu::RuntimeException)
767 {
768     PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
769     if (iId == maPropertyNameToIdMap.end())
770         return sal_False;
771 
772     const PropertyType eType (GetPropertyType(iId->second));
773     if (eType == PT_Invalid)
774         return sal_False;
775 
776     return sal_True;
777 }
778 
779 
780 
781 
782 void Theme::SetupPropertyMaps (void)
783 {
784     maPropertyIdToNameMap.resize(__Post_Rect);
785     maImages.resize(__Image_Color - __Pre_Image - 1);
786     maColors.resize(__Color_Paint - __Image_Color - 1);
787     maPaints.resize(__Paint_Int - __Color_Paint - 1);
788     maIntegers.resize(__Int_Bool - __Paint_Int - 1);
789     maBooleans.resize(__Bool_Rect - __Int_Bool - 1);
790     maRectangles.resize(__Post_Rect - __Bool_Rect - 1);
791 
792     #define AddEntry(e) maPropertyNameToIdMap[A2S(#e)]=e; maPropertyIdToNameMap[e]=A2S(#e)
793 
794     AddEntry(Image_Grip);
795     AddEntry(Image_Expand);
796     AddEntry(Image_Collapse);
797     AddEntry(Image_TabBarMenu);
798     AddEntry(Image_PanelMenu);
799     AddEntry(Image_ToolBoxItemSeparator);
800     AddEntry(Image_Closer);
801 
802     AddEntry(Color_DeckTitleFont);
803     AddEntry(Color_PanelTitleFont);
804     AddEntry(Color_TabMenuSeparator);
805     AddEntry(Color_TabItemBorder);
806     AddEntry(Color_DropDownBorder);
807     AddEntry(Color_Highlight);
808     AddEntry(Color_HighlightText);
809 
810     AddEntry(Paint_DeckBackground);
811     AddEntry(Paint_DeckTitleBarBackground);
812     AddEntry(Paint_PanelBackground);
813     AddEntry(Paint_PanelTitleBarBackground);
814     AddEntry(Paint_TabBarBackground);
815     AddEntry(Paint_TabItemBackgroundNormal);
816     AddEntry(Paint_TabItemBackgroundHighlight);
817     AddEntry(Paint_HorizontalBorder);
818     AddEntry(Paint_VerticalBorder);
819     AddEntry(Paint_ToolBoxBackground);
820     AddEntry(Paint_ToolBoxBorderTopLeft);
821     AddEntry(Paint_ToolBoxBorderCenterCorners);
822     AddEntry(Paint_ToolBoxBorderBottomRight);
823     AddEntry(Paint_DropDownBackground);
824 
825     AddEntry(Int_DeckTitleBarHeight);
826     AddEntry(Int_DeckBorderSize);
827     AddEntry(Int_DeckSeparatorHeight);
828     AddEntry(Int_PanelTitleBarHeight);
829     AddEntry(Int_TabMenuPadding);
830     AddEntry(Int_TabMenuSeparatorPadding);
831     AddEntry(Int_TabItemWidth);
832     AddEntry(Int_TabItemHeight);
833     AddEntry(Int_DeckLeftPadding);
834     AddEntry(Int_DeckTopPadding);
835     AddEntry(Int_DeckRightPadding);
836     AddEntry(Int_DeckBottomPadding);
837     AddEntry(Int_TabBarLeftPadding);
838     AddEntry(Int_TabBarTopPadding);
839     AddEntry(Int_TabBarRightPadding);
840     AddEntry(Int_TabBarBottomPadding);
841 
842     AddEntry(Bool_UseSymphonyIcons);
843     AddEntry(Bool_UseSystemColors);
844     AddEntry(Bool_UseToolBoxItemSeparator);
845     AddEntry(Bool_IsHighContrastModeActive);
846 
847     AddEntry(Rect_ToolBoxPadding);
848     AddEntry(Rect_ToolBoxBorder);
849 
850     #undef AddEntry
851 
852     maRawValues.resize(maPropertyIdToNameMap.size());
853 }
854 
855 
856 
857 
858 Theme::PropertyType Theme::GetPropertyType (const ThemeItem eItem)
859 {
860     switch(eItem)
861     {
862         case Image_Grip:
863         case Image_Expand:
864         case Image_Collapse:
865         case Image_TabBarMenu:
866         case Image_PanelMenu:
867         case Image_ToolBoxItemSeparator:
868         case Image_Closer:
869             return PT_Image;
870 
871         case Color_DeckTitleFont:
872         case Color_PanelTitleFont:
873         case Color_TabMenuSeparator:
874         case Color_TabItemBorder:
875         case Color_DropDownBorder:
876         case Color_Highlight:
877         case Color_HighlightText:
878             return PT_Color;
879 
880         case Paint_DeckBackground:
881         case Paint_DeckTitleBarBackground:
882         case Paint_PanelBackground:
883         case Paint_PanelTitleBarBackground:
884         case Paint_TabBarBackground:
885         case Paint_TabItemBackgroundNormal:
886         case Paint_TabItemBackgroundHighlight:
887         case Paint_HorizontalBorder:
888         case Paint_VerticalBorder:
889         case Paint_ToolBoxBackground:
890         case Paint_ToolBoxBorderTopLeft:
891         case Paint_ToolBoxBorderCenterCorners:
892         case Paint_ToolBoxBorderBottomRight:
893         case Paint_DropDownBackground:
894             return PT_Paint;
895 
896         case Int_DeckTitleBarHeight:
897         case Int_DeckBorderSize:
898         case Int_DeckSeparatorHeight:
899         case Int_PanelTitleBarHeight:
900         case Int_TabMenuPadding:
901         case Int_TabMenuSeparatorPadding:
902         case Int_TabItemWidth:
903         case Int_TabItemHeight:
904         case Int_DeckLeftPadding:
905         case Int_DeckTopPadding:
906         case Int_DeckRightPadding:
907         case Int_DeckBottomPadding:
908         case Int_TabBarLeftPadding:
909         case Int_TabBarTopPadding:
910         case Int_TabBarRightPadding:
911         case Int_TabBarBottomPadding:
912             return PT_Integer;
913 
914         case Bool_UseSymphonyIcons:
915         case Bool_UseSystemColors:
916         case Bool_UseToolBoxItemSeparator:
917         case Bool_IsHighContrastModeActive:
918             return PT_Boolean;
919 
920         case Rect_ToolBoxBorder:
921         case Rect_ToolBoxPadding:
922             return PT_Rectangle;
923 
924         default:
925             return PT_Invalid;
926     }
927 }
928 
929 
930 
931 
932 cssu::Type Theme::GetCppuType (const PropertyType eType)
933 {
934     switch(eType)
935     {
936         case PT_Image:
937             return getCppuType((rtl::OUString*)NULL);
938 
939         case PT_Color:
940             return getCppuType((sal_uInt32*)NULL);
941 
942         case PT_Paint:
943             return getCppuVoidType();
944 
945         case PT_Integer:
946             return getCppuType((sal_Int32*)NULL);
947 
948         case PT_Boolean:
949             return getCppuType((sal_Bool*)NULL);
950 
951         case PT_Rectangle:
952             return getCppuType((awt::Rectangle*)NULL);
953 
954         case PT_Invalid:
955         default:
956             return getCppuVoidType();
957     }
958 }
959 
960 
961 
962 
963 sal_Int32 Theme::GetIndex (const ThemeItem eItem, const PropertyType eType)
964 {
965     switch(eType)
966     {
967         case PT_Image:
968             return eItem - __Pre_Image-1;
969         case PT_Color:
970             return eItem - __Image_Color-1;
971         case PT_Paint:
972             return eItem - __Color_Paint-1;
973         case PT_Integer:
974             return eItem - __Paint_Int-1;
975         case PT_Boolean:
976             return eItem - __Int_Bool-1;
977         case PT_Rectangle:
978             return eItem - __Bool_Rect-1;
979 
980         default:
981             OSL_ASSERT(false);
982             return 0;
983     }
984 }
985 
986 
987 
988 
989 Theme::VetoableListenerContainer* Theme::GetVetoableListeners (
990     const ThemeItem eItem,
991     const bool bCreate)
992 {
993     VetoableListeners::iterator iContainer (maVetoableListeners.find(eItem));
994     if (iContainer != maVetoableListeners.end())
995         return &iContainer->second;
996     else if (bCreate)
997     {
998         maVetoableListeners[eItem] = VetoableListenerContainer();
999         return &maVetoableListeners[eItem];
1000     }
1001     else
1002         return NULL;
1003 }
1004 
1005 
1006 
1007 
1008 Theme::ChangeListenerContainer* Theme::GetChangeListeners (
1009     const ThemeItem eItem,
1010     const bool bCreate)
1011 {
1012     ChangeListeners::iterator iContainer (maChangeListeners.find(eItem));
1013     if (iContainer != maChangeListeners.end())
1014         return &iContainer->second;
1015     else if (bCreate)
1016     {
1017         maChangeListeners[eItem] = ChangeListenerContainer();
1018         return &maChangeListeners[eItem];
1019     }
1020     else
1021         return NULL;
1022 }
1023 
1024 
1025 
1026 
1027 bool Theme::DoVetoableListenersVeto (
1028     const VetoableListenerContainer* pListeners,
1029     const beans::PropertyChangeEvent& rEvent) const
1030 {
1031     if (pListeners == NULL)
1032         return false;
1033 
1034     VetoableListenerContainer aListeners (*pListeners);
1035     try
1036     {
1037         for (VetoableListenerContainer::const_iterator
1038                  iListener(aListeners.begin()),
1039                  iEnd(aListeners.end());
1040              iListener!=iEnd;
1041              ++iListener)
1042         {
1043             (*iListener)->vetoableChange(rEvent);
1044         }
1045     }
1046     catch(const beans::PropertyVetoException&)
1047     {
1048         return true;
1049     }
1050     catch(const Exception&)
1051     {
1052         // Ignore any other errors (such as disposed listeners).
1053     }
1054     return false;
1055 }
1056 
1057 
1058 
1059 
1060 void Theme::BroadcastPropertyChange (
1061     const ChangeListenerContainer* pListeners,
1062     const beans::PropertyChangeEvent& rEvent) const
1063 {
1064     if (pListeners == NULL)
1065         return;
1066 
1067     const ChangeListenerContainer aListeners (*pListeners);
1068     try
1069     {
1070         for (ChangeListenerContainer::const_iterator
1071                  iListener(aListeners.begin()),
1072                  iEnd(aListeners.end());
1073              iListener!=iEnd;
1074              ++iListener)
1075         {
1076             (*iListener)->propertyChange(rEvent);
1077         }
1078     }
1079     catch(const Exception&)
1080     {
1081         // Ignore any errors (such as disposed listeners).
1082     }
1083 }
1084 
1085 
1086 
1087 
1088 void Theme::ProcessNewValue (
1089     const Any& rValue,
1090     const ThemeItem eItem,
1091     const PropertyType eType)
1092 {
1093     const sal_Int32 nIndex (GetIndex (eItem, eType));
1094     switch (eType)
1095     {
1096         case PT_Image:
1097         {
1098             ::rtl::OUString sURL;
1099             if (rValue >>= sURL)
1100             {
1101                 maImages[nIndex] = Tools::GetImage(sURL, NULL);
1102             }
1103             break;
1104         }
1105         case PT_Color:
1106         {
1107             sal_Int32 nColorValue (0);
1108             if (rValue >>= nColorValue)
1109             {
1110                 maColors[nIndex] = Color(nColorValue);
1111             }
1112             break;
1113         }
1114         case PT_Paint:
1115         {
1116             maPaints[nIndex] = Paint::Create(rValue);
1117             break;
1118         }
1119         case PT_Integer:
1120         {
1121             sal_Int32 nValue (0);
1122             if (rValue >>= nValue)
1123             {
1124                 maIntegers[nIndex] = nValue;
1125             }
1126             break;
1127         }
1128         case PT_Boolean:
1129         {
1130             sal_Bool nValue (0);
1131             if (rValue >>= nValue)
1132             {
1133                 maBooleans[nIndex] = (nValue==sal_True);
1134                 if (eItem == Bool_IsHighContrastModeActive)
1135                 {
1136                     mbIsHighContrastModeSetManually = true;
1137                     mbIsHighContrastMode = maBooleans[nIndex];
1138                     HandleDataChange();
1139                 }
1140                 else if (eItem == Bool_UseSystemColors)
1141                 {
1142                     HandleDataChange();
1143                 }
1144             }
1145             break;
1146         }
1147         case PT_Rectangle:
1148         {
1149             awt::Rectangle aBox;
1150             if (rValue >>= aBox)
1151             {
1152                 maRectangles[nIndex] = Rectangle(
1153                     aBox.X,
1154                     aBox.Y,
1155                     aBox.Width,
1156                     aBox.Height);
1157             }
1158             break;
1159         }
1160         case PT_Invalid:
1161             OSL_ASSERT(eType != PT_Invalid);
1162             throw RuntimeException();
1163     }
1164 }
1165 
1166 
1167 
1168 
1169 } } // end of namespace sfx2::sidebar
1170