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 #ifndef SFX_SIDEBAR_THEME_HXX 23 #define SFX_SIDEBAR_THEME_HXX 24 25 #include "sfx2/dllapi.h" 26 27 #include <tools/color.hxx> 28 #include <vcl/image.hxx> 29 #include <cppuhelper/compbase2.hxx> 30 #include <cppuhelper/basemutex.hxx> 31 #include <tools/gen.hxx> 32 #include <rtl/ref.hxx> 33 #include <vcl/wall.hxx> 34 35 #include <com/sun/star/beans/XPropertySet.hpp> 36 37 #include <hash_map> 38 #include <map> 39 #include <boost/optional.hpp> 40 41 42 class SvBorder; 43 44 namespace css = ::com::sun::star; 45 namespace cssu = ::com::sun::star::uno; 46 47 48 namespace sfx2 { namespace sidebar { 49 50 51 namespace 52 { 53 typedef ::cppu::WeakComponentImplHelper2 < 54 css::beans::XPropertySet, 55 css::beans::XPropertySetInfo 56 > ThemeInterfaceBase; 57 } 58 59 class Paint; 60 61 /** Simple collection of colors, gradients, fonts that define the 62 look of the sidebar and its controls. 63 */ 64 class SFX2_DLLPUBLIC Theme 65 : private ::boost::noncopyable, 66 private ::cppu::BaseMutex, 67 public ThemeInterfaceBase 68 { 69 public: 70 enum ThemeItem 71 { 72 __Begin, 73 __Pre_Image = __Begin, 74 75 __AnyItem = __Pre_Image, 76 77 Image_Grip, 78 Image_Expand, 79 Image_Collapse, 80 Image_TabBarMenu, 81 Image_PanelMenu, 82 Image_ToolBoxItemSeparator, 83 Image_Closer, 84 Image_CloseIndicator, 85 86 __Image_Color, 87 88 Color_DeckTitleFont, 89 Color_PanelTitleFont, 90 Color_TabMenuSeparator, 91 Color_TabItemBorder, 92 Color_DropDownBorder, 93 Color_Highlight, 94 Color_HighlightText, 95 96 __Color_Paint, 97 98 Paint_DeckBackground, 99 Paint_DeckTitleBarBackground, 100 Paint_PanelBackground, 101 Paint_PanelTitleBarBackground, 102 Paint_TabBarBackground, 103 Paint_TabItemBackgroundNormal, 104 Paint_TabItemBackgroundHighlight, 105 Paint_HorizontalBorder, 106 Paint_VerticalBorder, 107 Paint_ToolBoxBackground, 108 Paint_ToolBoxBorderTopLeft, 109 Paint_ToolBoxBorderCenterCorners, 110 Paint_ToolBoxBorderBottomRight, 111 Paint_DropDownBackground, 112 113 __Paint_Int, 114 115 Int_DeckTitleBarHeight, 116 Int_DeckBorderSize, 117 Int_DeckSeparatorHeight, 118 Int_PanelTitleBarHeight, 119 Int_TabMenuPadding, 120 Int_TabMenuSeparatorPadding, 121 Int_TabItemWidth, 122 Int_TabItemHeight, 123 Int_DeckLeftPadding, 124 Int_DeckTopPadding, 125 Int_DeckRightPadding, 126 Int_DeckBottomPadding, 127 Int_TabBarLeftPadding, 128 Int_TabBarTopPadding, 129 Int_TabBarRightPadding, 130 Int_TabBarBottomPadding, 131 Int_ButtonCornerRadius, 132 133 __Int_Bool, 134 135 Bool_UseSymphonyIcons, 136 Bool_UseSystemColors, 137 Bool_UseToolBoxItemSeparator, 138 Bool_IsHighContrastModeActive, 139 140 __Bool_Rect, 141 142 Rect_ToolBoxPadding, 143 Rect_ToolBoxBorder, 144 145 __Post_Rect, 146 __End=__Post_Rect 147 }; 148 149 static Image GetImage (const ThemeItem eItem); 150 static Color GetColor (const ThemeItem eItem); 151 static const Paint& GetPaint (const ThemeItem eItem); 152 static const Wallpaper GetWallpaper (const ThemeItem eItem); 153 static sal_Int32 GetInteger (const ThemeItem eItem); 154 static bool GetBoolean (const ThemeItem eItem); 155 static Rectangle GetRectangle (const ThemeItem eItem); 156 157 static bool IsHighContrastMode (void); 158 159 static void HandleDataChange (void); 160 161 Theme (void); 162 virtual ~Theme (void); 163 164 virtual void SAL_CALL disposing (void); 165 166 static cssu::Reference<css::beans::XPropertySet> GetPropertySet (void); 167 168 // beans::XPropertySet 169 virtual cssu::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo (void) 170 throw(cssu::RuntimeException); 171 virtual void SAL_CALL setPropertyValue ( 172 const ::rtl::OUString& rsPropertyName, 173 const cssu::Any& rValue) 174 throw(cssu::RuntimeException); 175 virtual cssu::Any SAL_CALL getPropertyValue ( 176 const ::rtl::OUString& rsPropertyName) 177 throw(css::beans::UnknownPropertyException, 178 css::lang::WrappedTargetException, 179 cssu::RuntimeException); 180 virtual void SAL_CALL addPropertyChangeListener( 181 const ::rtl::OUString& rsPropertyName, 182 const cssu::Reference<css::beans::XPropertyChangeListener>& rxListener) 183 throw(css::beans::UnknownPropertyException, 184 css::lang::WrappedTargetException, 185 cssu::RuntimeException); 186 virtual void SAL_CALL removePropertyChangeListener( 187 const ::rtl::OUString& rsPropertyName, 188 const cssu::Reference<css::beans::XPropertyChangeListener>& rxListener) 189 throw(css::beans::UnknownPropertyException, 190 css::lang::WrappedTargetException, 191 cssu::RuntimeException); 192 virtual void SAL_CALL addVetoableChangeListener( 193 const ::rtl::OUString& rsPropertyName, 194 const cssu::Reference<css::beans::XVetoableChangeListener>& rxListener) 195 throw(css::beans::UnknownPropertyException, 196 css::lang::WrappedTargetException, 197 cssu::RuntimeException); 198 virtual void SAL_CALL removeVetoableChangeListener( 199 const ::rtl::OUString& rsPropertyName, 200 const cssu::Reference<css::beans::XVetoableChangeListener>& rxListener) 201 throw(css::beans::UnknownPropertyException, 202 css::lang::WrappedTargetException, 203 cssu::RuntimeException); 204 205 // beans::XPropertySetInfo 206 virtual cssu::Sequence<css::beans::Property> SAL_CALL getProperties (void) 207 throw(cssu::RuntimeException); 208 virtual css::beans::Property SAL_CALL getPropertyByName (const ::rtl::OUString& rsName) 209 throw(css::beans::UnknownPropertyException, 210 cssu::RuntimeException); 211 virtual sal_Bool SAL_CALL hasPropertyByName (const ::rtl::OUString& rsName) 212 throw(cssu::RuntimeException); 213 214 private: 215 static ::rtl::Reference<Theme> mpInstance; 216 static Theme& GetCurrentTheme (void); 217 218 ::std::vector<Image> maImages; 219 ::std::vector<Color> maColors; 220 ::std::vector<Paint> maPaints; 221 ::std::vector<sal_Int32> maIntegers; 222 ::std::vector<bool> maBooleans; 223 ::std::vector<Rectangle> maRectangles; 224 bool mbIsHighContrastMode; 225 bool mbIsHighContrastModeSetManually; 226 227 typedef ::std::hash_map<rtl::OUString,ThemeItem, rtl::OUStringHash> PropertyNameToIdMap; 228 PropertyNameToIdMap maPropertyNameToIdMap; 229 typedef ::std::vector<rtl::OUString> PropertyIdToNameMap; 230 PropertyIdToNameMap maPropertyIdToNameMap; 231 typedef ::std::vector<cssu::Any> RawValueContainer; 232 RawValueContainer maRawValues; 233 234 typedef ::std::vector<cssu::Reference<css::beans::XPropertyChangeListener> > ChangeListenerContainer; 235 typedef ::std::map<ThemeItem,ChangeListenerContainer> ChangeListeners; 236 ChangeListeners maChangeListeners; 237 typedef ::std::vector<cssu::Reference<css::beans::XVetoableChangeListener> > VetoableListenerContainer; 238 typedef ::std::map<ThemeItem,VetoableListenerContainer> VetoableListeners; 239 VetoableListeners maVetoableListeners; 240 241 enum PropertyType 242 { 243 PT_Image, 244 PT_Color, 245 PT_Paint, 246 PT_Integer, 247 PT_Boolean, 248 PT_Rectangle, 249 PT_Invalid 250 }; 251 252 void SetupPropertyMaps (void); 253 void InitializeTheme (void); 254 void UpdateTheme (void); 255 static PropertyType GetPropertyType (const ThemeItem eItem); 256 static cssu::Type GetCppuType (const PropertyType eType); 257 static sal_Int32 GetIndex ( 258 const ThemeItem eItem, 259 const PropertyType eType); 260 261 VetoableListenerContainer* GetVetoableListeners ( 262 const ThemeItem eItem, 263 const bool bCreate); 264 ChangeListenerContainer* GetChangeListeners ( 265 const ThemeItem eItem, 266 const bool bCreate); 267 bool DoVetoableListenersVeto ( 268 const VetoableListenerContainer* pListeners, 269 const css::beans::PropertyChangeEvent& rEvent) const; 270 void BroadcastPropertyChange ( 271 const ChangeListenerContainer* pListeners, 272 const css::beans::PropertyChangeEvent& rEvent) const; 273 void ProcessNewValue ( 274 const cssu::Any& rValue, 275 const ThemeItem eItem, 276 const PropertyType eType); 277 }; 278 279 280 281 } } // end of namespace sfx2::sidebar 282 283 #endif 284