1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 #ifndef INCLUDED_SFX2_SIDEBAR_THEME_HXX 20 #define INCLUDED_SFX2_SIDEBAR_THEME_HXX 21 22 #include <sfx2/dllapi.h> 23 24 #include <tools/color.hxx> 25 #include <vcl/image.hxx> 26 #include <cppuhelper/compbase.hxx> 27 #include <cppuhelper/basemutex.hxx> 28 #include <tools/gen.hxx> 29 #include <vcl/wall.hxx> 30 31 #include <com/sun/star/beans/XPropertySet.hpp> 32 33 #include <map> 34 #include <unordered_map> 35 36 37 namespace sfx2 { namespace sidebar { 38 39 typedef cppu::WeakComponentImplHelper < 40 css::beans::XPropertySet, 41 css::beans::XPropertySetInfo 42 > ThemeInterfaceBase; 43 44 class Paint; 45 46 /** Simple collection of colors, gradients, fonts that define the 47 look of the sidebar and its controls. 48 */ 49 class SFX2_DLLPUBLIC Theme final 50 : private ::cppu::BaseMutex, 51 public ThemeInterfaceBase 52 { 53 public: 54 enum ThemeItem 55 { 56 Begin_, 57 Pre_Image_ = Begin_, 58 59 AnyItem_ = Pre_Image_, 60 61 Image_Grip, 62 Image_Expand, 63 Image_Collapse, 64 Image_TabBarMenu, 65 Image_PanelMenu, 66 Image_Closer, 67 Image_CloseIndicator, 68 69 Image_Color_, 70 71 Color_DeckTitleFont, 72 Color_PanelTitleFont, 73 Color_TabMenuSeparator, 74 Color_TabItemBorder, 75 Color_DropDownBorder, 76 Color_Highlight, 77 Color_HighlightText, 78 79 Color_Paint_, 80 81 Paint_DeckBackground, 82 Paint_DeckTitleBarBackground, 83 Paint_PanelBackground, 84 Paint_PanelTitleBarBackground, 85 Paint_TabBarBackground, 86 Paint_TabItemBackgroundNormal, 87 Paint_TabItemBackgroundHighlight, 88 Paint_HorizontalBorder, 89 Paint_VerticalBorder, 90 Paint_ToolBoxBackground, 91 Paint_ToolBoxBorderTopLeft, 92 Paint_ToolBoxBorderCenterCorners, 93 Paint_ToolBoxBorderBottomRight, 94 Paint_DropDownBackground, 95 96 Paint_Int_, 97 98 Int_DeckTitleBarHeight, 99 Int_DeckBorderSize, 100 Int_DeckSeparatorHeight, 101 Int_PanelTitleBarHeight, 102 Int_TabMenuPadding, 103 Int_TabMenuSeparatorPadding, 104 Int_TabItemWidth, 105 Int_TabItemHeight, 106 Int_DeckLeftPadding, 107 Int_DeckTopPadding, 108 Int_DeckRightPadding, 109 Int_DeckBottomPadding, 110 Int_TabBarLeftPadding, 111 Int_TabBarTopPadding, 112 Int_TabBarRightPadding, 113 Int_TabBarBottomPadding, 114 Int_ButtonCornerRadius, 115 116 Int_Bool_, 117 118 Bool_UseSystemColors, 119 Bool_IsHighContrastModeActive, 120 121 Bool_Rect_, 122 123 Rect_ToolBoxPadding, 124 Rect_ToolBoxBorder, 125 126 Post_Rect_, 127 End_=Post_Rect_ 128 }; 129 130 static Image GetImage (const ThemeItem eItem); 131 static Color GetColor (const ThemeItem eItem); 132 static const Paint& GetPaint (const ThemeItem eItem); 133 static Wallpaper GetWallpaper (const ThemeItem eItem); 134 static sal_Int32 GetInteger (const ThemeItem eItem); 135 static bool GetBoolean (const ThemeItem eItem); 136 137 static bool IsHighContrastMode(); 138 139 static void HandleDataChange(); 140 141 void InitializeTheme(); 142 143 Theme(); 144 virtual ~Theme() override; 145 Theme(const Theme&) = delete; 146 Theme& operator=( const Theme& ) = delete; 147 148 virtual void SAL_CALL disposing() override; 149 150 static css::uno::Reference<css::beans::XPropertySet> GetPropertySet(); 151 152 // beans::XPropertySet 153 virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override; 154 virtual void SAL_CALL setPropertyValue ( 155 const OUString& rsPropertyName, 156 const css::uno::Any& rValue) override; 157 virtual css::uno::Any SAL_CALL getPropertyValue ( 158 const OUString& rsPropertyName) override; 159 virtual void SAL_CALL addPropertyChangeListener( 160 const OUString& rsPropertyName, 161 const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener) override; 162 virtual void SAL_CALL removePropertyChangeListener( 163 const OUString& rsPropertyName, 164 const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener) override; 165 virtual void SAL_CALL addVetoableChangeListener( 166 const OUString& rsPropertyName, 167 const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener) override; 168 virtual void SAL_CALL removeVetoableChangeListener( 169 const OUString& rsPropertyName, 170 const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener) override; 171 172 // beans::XPropertySetInfo 173 virtual css::uno::Sequence<css::beans::Property> SAL_CALL getProperties() override; 174 virtual css::beans::Property SAL_CALL getPropertyByName (const OUString& rsName) override; 175 virtual sal_Bool SAL_CALL hasPropertyByName (const OUString& rsName) override; 176 177 private: 178 static Theme& GetCurrentTheme(); 179 180 std::vector<Image> maImages; 181 std::vector<Color> maColors; 182 std::vector<Paint> maPaints; 183 std::vector<sal_Int32> maIntegers; 184 std::vector<bool> maBooleans; 185 std::vector<tools::Rectangle> maRectangles; 186 bool mbIsHighContrastMode; 187 bool mbIsHighContrastModeSetManually; 188 189 typedef std::unordered_map<OUString,ThemeItem> PropertyNameToIdMap; 190 PropertyNameToIdMap maPropertyNameToIdMap; 191 typedef std::vector<OUString> PropertyIdToNameMap; 192 PropertyIdToNameMap maPropertyIdToNameMap; 193 typedef ::std::vector<css::uno::Any> RawValueContainer; 194 RawValueContainer maRawValues; 195 196 typedef std::vector<css::uno::Reference<css::beans::XPropertyChangeListener> > ChangeListenerContainer; 197 typedef std::map<ThemeItem,ChangeListenerContainer> ChangeListeners; 198 ChangeListeners maChangeListeners; 199 typedef std::vector<css::uno::Reference<css::beans::XVetoableChangeListener> > VetoableListenerContainer; 200 typedef std::map<ThemeItem,VetoableListenerContainer> VetoableListeners; 201 VetoableListeners maVetoableListeners; 202 203 enum PropertyType 204 { 205 PT_Image, 206 PT_Color, 207 PT_Paint, 208 PT_Integer, 209 PT_Boolean, 210 PT_Rectangle, 211 PT_Invalid 212 }; 213 214 void SetupPropertyMaps(); 215 void UpdateTheme(); 216 static PropertyType GetPropertyType (const ThemeItem eItem); 217 static css::uno::Type const & GetCppuType (const PropertyType eType); 218 static sal_Int32 GetIndex ( 219 const ThemeItem eItem, 220 const PropertyType eType); 221 222 VetoableListenerContainer* GetVetoableListeners ( 223 const ThemeItem eItem, 224 const bool bCreate); 225 ChangeListenerContainer* GetChangeListeners ( 226 const ThemeItem eItem, 227 const bool bCreate); 228 static bool DoVetoableListenersVeto ( 229 const VetoableListenerContainer* pListeners, 230 const css::beans::PropertyChangeEvent& rEvent); 231 static void BroadcastPropertyChange ( 232 const ChangeListenerContainer* pListeners, 233 const css::beans::PropertyChangeEvent& rEvent); 234 void ProcessNewValue ( 235 const css::uno::Any& rValue, 236 const ThemeItem eItem, 237 const PropertyType eType); 238 }; 239 240 241 } } // end of namespace sfx2::sidebar 242 243 #endif 244 245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 246