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