xref: /aoo42x/main/sfx2/source/sidebar/Theme.cxx (revision f120fe41)
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(true));
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/svtools/res/triangle_right_hc.png")
362                     : A2S("private:graphicrepository/svtools/res/triangle_right.png")));
363         //                    ? A2S("private:graphicrepository/res/plus_sch.png")
364         //                    : A2S("private:graphicrepository/res/plus.png")));
365         setPropertyValue(
366             maPropertyIdToNameMap[Image_Collapse],
367             Any(
368                 mbIsHighContrastMode
369                     ? A2S("private:graphicrepository/svtools/res/triangle_down_hc.png")
370                     : A2S("private:graphicrepository/svtools/res/triangle_down.png")));
371         //                    ? A2S("private:graphicrepository/res/minus_sch.png")
372         //                    : A2S("private:graphicrepository/res/minus.png")));
373         setPropertyValue(
374             maPropertyIdToNameMap[Image_TabBarMenu],
375             Any(
376                 mbIsHighContrastMode
377                     ? A2S("private:graphicrepository/sfx2/res/menu_hc.png")
378                     : A2S("private:graphicrepository/sfx2/res/menu.png")));
379         setPropertyValue(
380             maPropertyIdToNameMap[Image_PanelMenu],
381             Any(
382                 mbIsHighContrastMode
383                     ? A2S("private:graphicrepository/res/imh30823.png")
384                     : A2S("private:graphicrepository/res/im30823.png")));
385         setPropertyValue(
386             maPropertyIdToNameMap[Image_Closer],
387             Any(A2S("private:graphicrepository/sfx2/res/closedoc.png")));
388         setPropertyValue(
389             maPropertyIdToNameMap[Image_ToolBoxItemSeparator],
390             Any(
391                 A2S("private:graphicrepository/sfx2/res/separator.png")));
392 
393         // ToolBox
394 
395         /*
396         // Separator style
397         setPropertyValue(
398             maPropertyIdToNameMap[Paint_ToolBoxBackground],
399             Any(sal_Int32(rStyle.GetMenuColor().GetRGBColor())));
400         setPropertyValue(
401             maPropertyIdToNameMap[Paint_ToolBoxBorderTopLeft],
402             Any());
403         setPropertyValue(
404             maPropertyIdToNameMap[Paint_ToolBoxBorderCenterCorners],
405             Any());
406         setPropertyValue(
407             maPropertyIdToNameMap[Paint_ToolBoxBorderBottomRight],
408             Any());
409         setPropertyValue(
410             maPropertyIdToNameMap[Rect_ToolBoxPadding],
411             Any(awt::Rectangle(2,2,2,2)));
412         setPropertyValue(
413             maPropertyIdToNameMap[Rect_ToolBoxBorder],
414             Any(awt::Rectangle(0,0,0,0)));
415         setPropertyValue(
416             maPropertyIdToNameMap[Bool_UseToolBoxItemSeparator],
417             Any(true));
418 
419         */
420 
421         // Gradient style
422         setPropertyValue(
423             maPropertyIdToNameMap[Paint_ToolBoxBackground],
424             Any(Tools::VclToAwtGradient(Gradient(
425                         GRADIENT_LINEAR,
426                         Color(0xf2f2f2),
427                         Color(0xfefefe)
428                         ))));
429         setPropertyValue(
430             maPropertyIdToNameMap[Paint_ToolBoxBorderTopLeft],
431             mbIsHighContrastMode
432                 ? Any(util::Color(sal_uInt32(0x00ff00)))
433                 : Any(util::Color(sal_uInt32(0xf2f2f2))));
434         setPropertyValue(
435             maPropertyIdToNameMap[Paint_ToolBoxBorderCenterCorners],
436             mbIsHighContrastMode
437                 ? Any(util::Color(sal_uInt32(0x00ff00)))
438                 : Any(util::Color(sal_uInt32(0xf2f2f2))));
439         setPropertyValue(
440             maPropertyIdToNameMap[Paint_ToolBoxBorderBottomRight],
441             mbIsHighContrastMode
442                 ? Any(util::Color(sal_uInt32(0x00ff00)))
443                 : Any(util::Color(sal_uInt32(0xf2f2f2))));
444         setPropertyValue(
445             maPropertyIdToNameMap[Rect_ToolBoxPadding],
446             Any(awt::Rectangle(2,2,2,2)));
447         setPropertyValue(
448             maPropertyIdToNameMap[Rect_ToolBoxBorder],
449             Any(awt::Rectangle(1,1,1,1)));
450         setPropertyValue(
451             maPropertyIdToNameMap[Bool_UseToolBoxItemSeparator],
452             Any(false));
453     }
454     catch(beans::UnknownPropertyException& rException)
455     {
456         OSL_TRACE("unknown property: %s",
457             OUStringToOString(
458                 rException.Message,
459                 RTL_TEXTENCODING_ASCII_US).getStr());
460         OSL_ASSERT(false);
461     }
462 }
463 
464 
465 
466 
467 void SAL_CALL Theme::disposing (void)
468 {
469     ChangeListeners aListeners;
470     maChangeListeners.swap(aListeners);
471 
472     const lang::EventObject aEvent (static_cast<XWeak*>(this));
473 
474     for (ChangeListeners::const_iterator
475              iContainer(maChangeListeners.begin()),
476              iContainerEnd(maChangeListeners.end());
477          iContainerEnd!=iContainerEnd;
478          ++iContainerEnd)
479     {
480         for (ChangeListenerContainer::const_iterator
481                  iListener(iContainer->second.begin()),
482                  iEnd(iContainer->second.end());
483              iListener!=iEnd;
484              ++iListener)
485         {
486             try
487             {
488                 (*iListener)->disposing(aEvent);
489             }
490             catch(const Exception&)
491             {
492             }
493         }
494     }
495 }
496 
497 
498 
499 
500 Reference<beans::XPropertySet> Theme::GetPropertySet (void)
501 {
502     return Reference<beans::XPropertySet>(static_cast<XWeak*>(&GetCurrentTheme()), UNO_QUERY);
503 }
504 
505 
506 
507 
508 Reference<beans::XPropertySetInfo> SAL_CALL Theme::getPropertySetInfo (void)
509     throw(cssu::RuntimeException)
510 {
511     return Reference<beans::XPropertySetInfo>(this);
512 }
513 
514 
515 
516 
517 void SAL_CALL Theme::setPropertyValue (
518     const ::rtl::OUString& rsPropertyName,
519     const cssu::Any& rValue)
520     throw(cssu::RuntimeException)
521 {
522     PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
523     if (iId == maPropertyNameToIdMap.end())
524         throw beans::UnknownPropertyException(rsPropertyName, NULL);
525 
526     const PropertyType eType (GetPropertyType(iId->second));
527     if (eType == PT_Invalid)
528         throw beans::UnknownPropertyException(rsPropertyName, NULL);
529 
530     const ThemeItem eItem (iId->second);
531 
532     if (rValue == maRawValues[eItem])
533     {
534         // Value is not different from the one in the property
535         // set => nothing to do.
536         return;
537     }
538 
539     const Any aOldValue (maRawValues[eItem]);
540 
541     const beans::PropertyChangeEvent aEvent(
542         static_cast<XWeak*>(this),
543         rsPropertyName,
544         sal_False,
545         eItem,
546         aOldValue,
547         rValue);
548 
549     if (DoVetoableListenersVeto(GetVetoableListeners(__AnyItem, false), aEvent))
550         return;
551     if (DoVetoableListenersVeto(GetVetoableListeners(eItem, false), aEvent))
552         return;
553 
554     maRawValues[eItem] = rValue;
555     ProcessNewValue(rValue, eItem, eType);
556 
557     BroadcastPropertyChange(GetChangeListeners(__AnyItem, false), aEvent);
558     BroadcastPropertyChange(GetChangeListeners(eItem, false), aEvent);
559 }
560 
561 
562 
563 
564 Any SAL_CALL Theme::getPropertyValue (
565     const ::rtl::OUString& rsPropertyName)
566     throw(css::beans::UnknownPropertyException,
567         css::lang::WrappedTargetException,
568         cssu::RuntimeException)
569 {
570     PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
571     if (iId == maPropertyNameToIdMap.end())
572         throw beans::UnknownPropertyException();
573 
574     const PropertyType eType (GetPropertyType(iId->second));
575     if (eType == PT_Invalid)
576         throw beans::UnknownPropertyException();
577 
578     const ThemeItem eItem (iId->second);
579 
580     return maRawValues[eItem];
581 }
582 
583 
584 
585 
586 void SAL_CALL Theme::addPropertyChangeListener(
587     const ::rtl::OUString& rsPropertyName,
588     const cssu::Reference<css::beans::XPropertyChangeListener>& rxListener)
589     throw(css::beans::UnknownPropertyException,
590         css::lang::WrappedTargetException,
591         cssu::RuntimeException)
592 {
593     ThemeItem eItem (__AnyItem);
594     if (rsPropertyName.getLength() > 0)
595     {
596         PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
597         if (iId == maPropertyNameToIdMap.end())
598             throw beans::UnknownPropertyException();
599 
600         const PropertyType eType (GetPropertyType(iId->second));
601         if (eType == PT_Invalid)
602             throw beans::UnknownPropertyException();
603 
604         eItem = iId->second;
605     }
606     ChangeListenerContainer* pListeners = GetChangeListeners(eItem, true);
607     if (pListeners != NULL)
608         pListeners->push_back(rxListener);
609 }
610 
611 
612 
613 
614 void SAL_CALL Theme::removePropertyChangeListener(
615     const ::rtl::OUString& rsPropertyName,
616     const cssu::Reference<css::beans::XPropertyChangeListener>& rxListener)
617     throw(css::beans::UnknownPropertyException,
618         css::lang::WrappedTargetException,
619         cssu::RuntimeException)
620 {
621     ThemeItem eItem (__AnyItem);
622     if (rsPropertyName.getLength() > 0)
623     {
624         PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
625         if (iId == maPropertyNameToIdMap.end())
626             throw beans::UnknownPropertyException();
627 
628         const PropertyType eType (GetPropertyType(iId->second));
629         if (eType == PT_Invalid)
630             throw beans::UnknownPropertyException();
631 
632         eItem = iId->second;
633     }
634     ChangeListenerContainer* pContainer = GetChangeListeners(eItem, false);
635     if (pContainer != NULL)
636     {
637         ChangeListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener));
638         if (iListener != pContainer->end())
639         {
640             pContainer->erase(iListener);
641 
642             // Remove the listener container when empty.
643             if (pContainer->empty())
644                 maChangeListeners.erase(eItem);
645         }
646     }
647 }
648 
649 
650 
651 
652 void SAL_CALL Theme::addVetoableChangeListener(
653     const ::rtl::OUString& rsPropertyName,
654     const cssu::Reference<css::beans::XVetoableChangeListener>& rxListener)
655     throw(css::beans::UnknownPropertyException,
656         css::lang::WrappedTargetException,
657         cssu::RuntimeException)
658 {
659     ThemeItem eItem (__AnyItem);
660     if (rsPropertyName.getLength() > 0)
661     {
662         PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
663         if (iId == maPropertyNameToIdMap.end())
664             throw beans::UnknownPropertyException();
665 
666         const PropertyType eType (GetPropertyType(iId->second));
667         if (eType == PT_Invalid)
668             throw beans::UnknownPropertyException();
669 
670         eItem = iId->second;
671     }
672     VetoableListenerContainer* pListeners = GetVetoableListeners(eItem, true);
673     if (pListeners != NULL)
674         pListeners->push_back(rxListener);
675 }
676 
677 
678 
679 
680 void SAL_CALL Theme::removeVetoableChangeListener(
681     const ::rtl::OUString& rsPropertyName,
682     const cssu::Reference<css::beans::XVetoableChangeListener>& rxListener)
683     throw(css::beans::UnknownPropertyException,
684         css::lang::WrappedTargetException,
685         cssu::RuntimeException)
686 {
687     ThemeItem eItem (__AnyItem);
688     if (rsPropertyName.getLength() > 0)
689     {
690         PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
691         if (iId == maPropertyNameToIdMap.end())
692             throw beans::UnknownPropertyException();
693 
694         const PropertyType eType (GetPropertyType(iId->second));
695         if (eType == PT_Invalid)
696             throw beans::UnknownPropertyException();
697 
698         eItem = iId->second;
699     }
700     VetoableListenerContainer* pContainer = GetVetoableListeners(eItem, false);
701     if (pContainer != NULL)
702     {
703         VetoableListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener));
704         if (iListener != pContainer->end())
705         {
706             pContainer->erase(iListener);
707             // Remove container when empty.
708             if (pContainer->empty())
709                 maVetoableListeners.erase(eItem);
710         }
711     }
712 }
713 
714 
715 
716 
717 cssu::Sequence<css::beans::Property> SAL_CALL Theme::getProperties (void)
718     throw(cssu::RuntimeException)
719 {
720     ::std::vector<beans::Property> aProperties;
721 
722     for (sal_Int32 nItem(__Begin),nEnd(__End); nItem!=nEnd; ++nItem)
723     {
724         const ThemeItem eItem (static_cast<ThemeItem>(nItem));
725         const PropertyType eType (GetPropertyType(eItem));
726         if (eType == PT_Invalid)
727             continue;
728 
729         const beans::Property aProperty(
730             maPropertyIdToNameMap[eItem],
731             eItem,
732             GetCppuType(eType),
733             0);
734         aProperties.push_back(aProperty);
735     }
736 
737     return cssu::Sequence<css::beans::Property>(
738         &aProperties.front(),
739         aProperties.size());
740 }
741 
742 
743 
744 
745 beans::Property SAL_CALL Theme::getPropertyByName (const ::rtl::OUString& rsPropertyName)
746     throw(css::beans::UnknownPropertyException,
747         cssu::RuntimeException)
748 {
749     PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
750     if (iId == maPropertyNameToIdMap.end())
751         throw beans::UnknownPropertyException();
752 
753     const PropertyType eType (GetPropertyType(iId->second));
754     if (eType == PT_Invalid)
755         throw beans::UnknownPropertyException();
756 
757     const ThemeItem eItem (iId->second);
758 
759     return beans::Property(
760         rsPropertyName,
761         eItem,
762         GetCppuType(eType),
763         0);
764 }
765 
766 
767 
768 
769 sal_Bool SAL_CALL Theme::hasPropertyByName (const ::rtl::OUString& rsPropertyName)
770     throw(cssu::RuntimeException)
771 {
772     PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
773     if (iId == maPropertyNameToIdMap.end())
774         return sal_False;
775 
776     const PropertyType eType (GetPropertyType(iId->second));
777     if (eType == PT_Invalid)
778         return sal_False;
779 
780     return sal_True;
781 }
782 
783 
784 
785 
786 void Theme::SetupPropertyMaps (void)
787 {
788     maPropertyIdToNameMap.resize(__Post_Rect);
789     maImages.resize(__Image_Color - __Pre_Image - 1);
790     maColors.resize(__Color_Paint - __Image_Color - 1);
791     maPaints.resize(__Paint_Int - __Color_Paint - 1);
792     maIntegers.resize(__Int_Bool - __Paint_Int - 1);
793     maBooleans.resize(__Bool_Rect - __Int_Bool - 1);
794     maRectangles.resize(__Post_Rect - __Bool_Rect - 1);
795 
796     #define AddEntry(e) maPropertyNameToIdMap[A2S(#e)]=e; maPropertyIdToNameMap[e]=A2S(#e)
797 
798     AddEntry(Image_Grip);
799     AddEntry(Image_Expand);
800     AddEntry(Image_Collapse);
801     AddEntry(Image_TabBarMenu);
802     AddEntry(Image_PanelMenu);
803     AddEntry(Image_ToolBoxItemSeparator);
804     AddEntry(Image_Closer);
805 
806     AddEntry(Color_DeckTitleFont);
807     AddEntry(Color_PanelTitleFont);
808     AddEntry(Color_TabMenuSeparator);
809     AddEntry(Color_TabItemBorder);
810     AddEntry(Color_DropDownBorder);
811     AddEntry(Color_Highlight);
812     AddEntry(Color_HighlightText);
813 
814     AddEntry(Paint_DeckBackground);
815     AddEntry(Paint_DeckTitleBarBackground);
816     AddEntry(Paint_PanelBackground);
817     AddEntry(Paint_PanelTitleBarBackground);
818     AddEntry(Paint_TabBarBackground);
819     AddEntry(Paint_TabItemBackgroundNormal);
820     AddEntry(Paint_TabItemBackgroundHighlight);
821     AddEntry(Paint_HorizontalBorder);
822     AddEntry(Paint_VerticalBorder);
823     AddEntry(Paint_ToolBoxBackground);
824     AddEntry(Paint_ToolBoxBorderTopLeft);
825     AddEntry(Paint_ToolBoxBorderCenterCorners);
826     AddEntry(Paint_ToolBoxBorderBottomRight);
827     AddEntry(Paint_DropDownBackground);
828 
829     AddEntry(Int_DeckTitleBarHeight);
830     AddEntry(Int_DeckBorderSize);
831     AddEntry(Int_DeckSeparatorHeight);
832     AddEntry(Int_PanelTitleBarHeight);
833     AddEntry(Int_TabMenuPadding);
834     AddEntry(Int_TabMenuSeparatorPadding);
835     AddEntry(Int_TabItemWidth);
836     AddEntry(Int_TabItemHeight);
837     AddEntry(Int_DeckLeftPadding);
838     AddEntry(Int_DeckTopPadding);
839     AddEntry(Int_DeckRightPadding);
840     AddEntry(Int_DeckBottomPadding);
841     AddEntry(Int_TabBarLeftPadding);
842     AddEntry(Int_TabBarTopPadding);
843     AddEntry(Int_TabBarRightPadding);
844     AddEntry(Int_TabBarBottomPadding);
845 
846     AddEntry(Bool_UseSymphonyIcons);
847     AddEntry(Bool_UseSystemColors);
848     AddEntry(Bool_UseToolBoxItemSeparator);
849     AddEntry(Bool_IsHighContrastModeActive);
850 
851     AddEntry(Rect_ToolBoxPadding);
852     AddEntry(Rect_ToolBoxBorder);
853 
854     #undef AddEntry
855 
856     maRawValues.resize(maPropertyIdToNameMap.size());
857 }
858 
859 
860 
861 
862 Theme::PropertyType Theme::GetPropertyType (const ThemeItem eItem)
863 {
864     switch(eItem)
865     {
866         case Image_Grip:
867         case Image_Expand:
868         case Image_Collapse:
869         case Image_TabBarMenu:
870         case Image_PanelMenu:
871         case Image_ToolBoxItemSeparator:
872         case Image_Closer:
873             return PT_Image;
874 
875         case Color_DeckTitleFont:
876         case Color_PanelTitleFont:
877         case Color_TabMenuSeparator:
878         case Color_TabItemBorder:
879         case Color_DropDownBorder:
880         case Color_Highlight:
881         case Color_HighlightText:
882             return PT_Color;
883 
884         case Paint_DeckBackground:
885         case Paint_DeckTitleBarBackground:
886         case Paint_PanelBackground:
887         case Paint_PanelTitleBarBackground:
888         case Paint_TabBarBackground:
889         case Paint_TabItemBackgroundNormal:
890         case Paint_TabItemBackgroundHighlight:
891         case Paint_HorizontalBorder:
892         case Paint_VerticalBorder:
893         case Paint_ToolBoxBackground:
894         case Paint_ToolBoxBorderTopLeft:
895         case Paint_ToolBoxBorderCenterCorners:
896         case Paint_ToolBoxBorderBottomRight:
897         case Paint_DropDownBackground:
898             return PT_Paint;
899 
900         case Int_DeckTitleBarHeight:
901         case Int_DeckBorderSize:
902         case Int_DeckSeparatorHeight:
903         case Int_PanelTitleBarHeight:
904         case Int_TabMenuPadding:
905         case Int_TabMenuSeparatorPadding:
906         case Int_TabItemWidth:
907         case Int_TabItemHeight:
908         case Int_DeckLeftPadding:
909         case Int_DeckTopPadding:
910         case Int_DeckRightPadding:
911         case Int_DeckBottomPadding:
912         case Int_TabBarLeftPadding:
913         case Int_TabBarTopPadding:
914         case Int_TabBarRightPadding:
915         case Int_TabBarBottomPadding:
916             return PT_Integer;
917 
918         case Bool_UseSymphonyIcons:
919         case Bool_UseSystemColors:
920         case Bool_UseToolBoxItemSeparator:
921         case Bool_IsHighContrastModeActive:
922             return PT_Boolean;
923 
924         case Rect_ToolBoxBorder:
925         case Rect_ToolBoxPadding:
926             return PT_Rectangle;
927 
928         default:
929             return PT_Invalid;
930     }
931 }
932 
933 
934 
935 
936 cssu::Type Theme::GetCppuType (const PropertyType eType)
937 {
938     switch(eType)
939     {
940         case PT_Image:
941             return getCppuType((rtl::OUString*)NULL);
942 
943         case PT_Color:
944             return getCppuType((sal_uInt32*)NULL);
945 
946         case PT_Paint:
947             return getCppuVoidType();
948 
949         case PT_Integer:
950             return getCppuType((sal_Int32*)NULL);
951 
952         case PT_Boolean:
953             return getCppuType((sal_Bool*)NULL);
954 
955         case PT_Rectangle:
956             return getCppuType((awt::Rectangle*)NULL);
957 
958         case PT_Invalid:
959         default:
960             return getCppuVoidType();
961     }
962 }
963 
964 
965 
966 
967 sal_Int32 Theme::GetIndex (const ThemeItem eItem, const PropertyType eType)
968 {
969     switch(eType)
970     {
971         case PT_Image:
972             return eItem - __Pre_Image-1;
973         case PT_Color:
974             return eItem - __Image_Color-1;
975         case PT_Paint:
976             return eItem - __Color_Paint-1;
977         case PT_Integer:
978             return eItem - __Paint_Int-1;
979         case PT_Boolean:
980             return eItem - __Int_Bool-1;
981         case PT_Rectangle:
982             return eItem - __Bool_Rect-1;
983 
984         default:
985             OSL_ASSERT(false);
986             return 0;
987     }
988 }
989 
990 
991 
992 
993 Theme::VetoableListenerContainer* Theme::GetVetoableListeners (
994     const ThemeItem eItem,
995     const bool bCreate)
996 {
997     VetoableListeners::iterator iContainer (maVetoableListeners.find(eItem));
998     if (iContainer != maVetoableListeners.end())
999         return &iContainer->second;
1000     else if (bCreate)
1001     {
1002         maVetoableListeners[eItem] = VetoableListenerContainer();
1003         return &maVetoableListeners[eItem];
1004     }
1005     else
1006         return NULL;
1007 }
1008 
1009 
1010 
1011 
1012 Theme::ChangeListenerContainer* Theme::GetChangeListeners (
1013     const ThemeItem eItem,
1014     const bool bCreate)
1015 {
1016     ChangeListeners::iterator iContainer (maChangeListeners.find(eItem));
1017     if (iContainer != maChangeListeners.end())
1018         return &iContainer->second;
1019     else if (bCreate)
1020     {
1021         maChangeListeners[eItem] = ChangeListenerContainer();
1022         return &maChangeListeners[eItem];
1023     }
1024     else
1025         return NULL;
1026 }
1027 
1028 
1029 
1030 
1031 bool Theme::DoVetoableListenersVeto (
1032     const VetoableListenerContainer* pListeners,
1033     const beans::PropertyChangeEvent& rEvent) const
1034 {
1035     if (pListeners == NULL)
1036         return false;
1037 
1038     VetoableListenerContainer aListeners (*pListeners);
1039     try
1040     {
1041         for (VetoableListenerContainer::const_iterator
1042                  iListener(aListeners.begin()),
1043                  iEnd(aListeners.end());
1044              iListener!=iEnd;
1045              ++iListener)
1046         {
1047             (*iListener)->vetoableChange(rEvent);
1048         }
1049     }
1050     catch(const beans::PropertyVetoException&)
1051     {
1052         return true;
1053     }
1054     catch(const Exception&)
1055     {
1056         // Ignore any other errors (such as disposed listeners).
1057     }
1058     return false;
1059 }
1060 
1061 
1062 
1063 
1064 void Theme::BroadcastPropertyChange (
1065     const ChangeListenerContainer* pListeners,
1066     const beans::PropertyChangeEvent& rEvent) const
1067 {
1068     if (pListeners == NULL)
1069         return;
1070 
1071     const ChangeListenerContainer aListeners (*pListeners);
1072     try
1073     {
1074         for (ChangeListenerContainer::const_iterator
1075                  iListener(aListeners.begin()),
1076                  iEnd(aListeners.end());
1077              iListener!=iEnd;
1078              ++iListener)
1079         {
1080             (*iListener)->propertyChange(rEvent);
1081         }
1082     }
1083     catch(const Exception&)
1084     {
1085         // Ignore any errors (such as disposed listeners).
1086     }
1087 }
1088 
1089 
1090 
1091 
1092 void Theme::ProcessNewValue (
1093     const Any& rValue,
1094     const ThemeItem eItem,
1095     const PropertyType eType)
1096 {
1097     const sal_Int32 nIndex (GetIndex (eItem, eType));
1098     switch (eType)
1099     {
1100         case PT_Image:
1101         {
1102             ::rtl::OUString sURL;
1103             if (rValue >>= sURL)
1104             {
1105                 maImages[nIndex] = Tools::GetImage(sURL, NULL);
1106             }
1107             break;
1108         }
1109         case PT_Color:
1110         {
1111             sal_Int32 nColorValue (0);
1112             if (rValue >>= nColorValue)
1113             {
1114                 maColors[nIndex] = Color(nColorValue);
1115             }
1116             break;
1117         }
1118         case PT_Paint:
1119         {
1120             maPaints[nIndex] = Paint::Create(rValue);
1121             break;
1122         }
1123         case PT_Integer:
1124         {
1125             sal_Int32 nValue (0);
1126             if (rValue >>= nValue)
1127             {
1128                 maIntegers[nIndex] = nValue;
1129             }
1130             break;
1131         }
1132         case PT_Boolean:
1133         {
1134             sal_Bool nValue (0);
1135             if (rValue >>= nValue)
1136             {
1137                 maBooleans[nIndex] = (nValue==sal_True);
1138                 if (eItem == Bool_IsHighContrastModeActive)
1139                 {
1140                     mbIsHighContrastModeSetManually = true;
1141                     mbIsHighContrastMode = maBooleans[nIndex];
1142                     HandleDataChange();
1143                 }
1144                 else if (eItem == Bool_UseSystemColors)
1145                 {
1146                     HandleDataChange();
1147                 }
1148             }
1149             break;
1150         }
1151         case PT_Rectangle:
1152         {
1153             awt::Rectangle aBox;
1154             if (rValue >>= aBox)
1155             {
1156                 maRectangles[nIndex] = Rectangle(
1157                     aBox.X,
1158                     aBox.Y,
1159                     aBox.Width,
1160                     aBox.Height);
1161             }
1162             break;
1163         }
1164         case PT_Invalid:
1165             OSL_ASSERT(eType != PT_Invalid);
1166             throw RuntimeException();
1167     }
1168 }
1169 
1170 
1171 
1172 
1173 } } // end of namespace sfx2::sidebar
1174