Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / include / sfx2 / sidebar / Theme.hxx
blob2e12de396a928505f0e8190df55cb86b0a3994a0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SFX2_SIDEBAR_THEME_HXX
20 #define INCLUDED_SFX2_SIDEBAR_THEME_HXX
22 #include <sfx2/dllapi.h>
24 #include <tools/color.hxx>
25 #include <vcl/image.hxx>
26 #include <cppuhelper/compbase2.hxx>
27 #include <cppuhelper/basemutex.hxx>
28 #include <tools/gen.hxx>
29 #include <rtl/ref.hxx>
30 #include <vcl/wall.hxx>
32 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <map>
35 #include <unordered_map>
37 class SvBorder;
40 namespace sfx2 { namespace sidebar {
43 namespace
45 typedef ::cppu::WeakComponentImplHelper2 <
46 css::beans::XPropertySet,
47 css::beans::XPropertySetInfo
48 > ThemeInterfaceBase;
51 class Paint;
53 /** Simple collection of colors, gradients, fonts that define the
54 look of the sidebar and its controls.
56 class SFX2_DLLPUBLIC Theme
57 : private ::cppu::BaseMutex,
58 public ThemeInterfaceBase
60 public:
61 enum ThemeItem
63 Begin_,
64 Pre_Image_ = Begin_,
66 AnyItem_ = Pre_Image_,
68 Image_Grip,
69 Image_Expand,
70 Image_Collapse,
71 Image_TabBarMenu,
72 Image_PanelMenu,
73 Image_Closer,
74 Image_CloseIndicator,
76 Image_Color_,
78 Color_DeckTitleFont,
79 Color_PanelTitleFont,
80 Color_TabMenuSeparator,
81 Color_TabItemBorder,
82 Color_DropDownBorder,
83 Color_Highlight,
84 Color_HighlightText,
86 Color_Paint_,
88 Paint_DeckBackground,
89 Paint_DeckTitleBarBackground,
90 Paint_PanelBackground,
91 Paint_PanelTitleBarBackground,
92 Paint_TabBarBackground,
93 Paint_TabItemBackgroundNormal,
94 Paint_TabItemBackgroundHighlight,
95 Paint_HorizontalBorder,
96 Paint_VerticalBorder,
97 Paint_ToolBoxBackground,
98 Paint_ToolBoxBorderTopLeft,
99 Paint_ToolBoxBorderCenterCorners,
100 Paint_ToolBoxBorderBottomRight,
101 Paint_DropDownBackground,
103 Paint_Int_,
105 Int_DeckTitleBarHeight,
106 Int_DeckBorderSize,
107 Int_DeckSeparatorHeight,
108 Int_PanelTitleBarHeight,
109 Int_TabMenuPadding,
110 Int_TabMenuSeparatorPadding,
111 Int_TabItemWidth,
112 Int_TabItemHeight,
113 Int_DeckLeftPadding,
114 Int_DeckTopPadding,
115 Int_DeckRightPadding,
116 Int_DeckBottomPadding,
117 Int_TabBarLeftPadding,
118 Int_TabBarTopPadding,
119 Int_TabBarRightPadding,
120 Int_TabBarBottomPadding,
121 Int_ButtonCornerRadius,
123 Int_Bool_,
125 Bool_UseSystemColors,
126 Bool_IsHighContrastModeActive,
128 Bool_Rect_,
130 Rect_ToolBoxPadding,
131 Rect_ToolBoxBorder,
133 Post_Rect_,
134 End_=Post_Rect_
137 static Image GetImage (const ThemeItem eItem);
138 static Color GetColor (const ThemeItem eItem);
139 static const Paint& GetPaint (const ThemeItem eItem);
140 static const Wallpaper GetWallpaper (const ThemeItem eItem);
141 static sal_Int32 GetInteger (const ThemeItem eItem);
142 static bool GetBoolean (const ThemeItem eItem);
144 static bool IsHighContrastMode();
146 static void HandleDataChange();
148 void InitializeTheme();
150 Theme();
151 virtual ~Theme();
152 Theme(const Theme&) = delete;
153 Theme& operator=( const Theme& ) = delete;
155 virtual void SAL_CALL disposing() override;
157 static css::uno::Reference<css::beans::XPropertySet> GetPropertySet();
159 // beans::XPropertySet
160 virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo()
161 throw(css::uno::RuntimeException, std::exception) override;
162 virtual void SAL_CALL setPropertyValue (
163 const ::rtl::OUString& rsPropertyName,
164 const css::uno::Any& rValue)
165 throw (css::beans::UnknownPropertyException,
166 css::uno::RuntimeException,
167 std::exception) override;
168 virtual css::uno::Any SAL_CALL getPropertyValue (
169 const ::rtl::OUString& rsPropertyName)
170 throw(css::beans::UnknownPropertyException,
171 css::lang::WrappedTargetException,
172 css::uno::RuntimeException, std::exception) override;
173 virtual void SAL_CALL addPropertyChangeListener(
174 const ::rtl::OUString& rsPropertyName,
175 const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
176 throw(css::beans::UnknownPropertyException,
177 css::lang::WrappedTargetException,
178 css::uno::RuntimeException, std::exception) override;
179 virtual void SAL_CALL removePropertyChangeListener(
180 const ::rtl::OUString& rsPropertyName,
181 const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
182 throw(css::beans::UnknownPropertyException,
183 css::lang::WrappedTargetException,
184 css::uno::RuntimeException, std::exception) override;
185 virtual void SAL_CALL addVetoableChangeListener(
186 const ::rtl::OUString& rsPropertyName,
187 const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
188 throw(css::beans::UnknownPropertyException,
189 css::lang::WrappedTargetException,
190 css::uno::RuntimeException, std::exception) override;
191 virtual void SAL_CALL removeVetoableChangeListener(
192 const ::rtl::OUString& rsPropertyName,
193 const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
194 throw(css::beans::UnknownPropertyException,
195 css::lang::WrappedTargetException,
196 css::uno::RuntimeException, std::exception) override;
198 // beans::XPropertySetInfo
199 virtual css::uno::Sequence<css::beans::Property> SAL_CALL getProperties()
200 throw(css::uno::RuntimeException, std::exception) override;
201 virtual css::beans::Property SAL_CALL getPropertyByName (const ::rtl::OUString& rsName)
202 throw(css::beans::UnknownPropertyException,
203 css::uno::RuntimeException, std::exception) override;
204 virtual sal_Bool SAL_CALL hasPropertyByName (const ::rtl::OUString& rsName)
205 throw(css::uno::RuntimeException, std::exception) override;
207 private:
208 static Theme& GetCurrentTheme();
210 std::vector<Image> maImages;
211 std::vector<Color> maColors;
212 std::vector<Paint> maPaints;
213 std::vector<sal_Int32> maIntegers;
214 std::vector<bool> maBooleans;
215 std::vector<Rectangle> maRectangles;
216 bool mbIsHighContrastMode;
217 bool mbIsHighContrastModeSetManually;
219 typedef std::unordered_map<rtl::OUString,ThemeItem, rtl::OUStringHash> PropertyNameToIdMap;
220 PropertyNameToIdMap maPropertyNameToIdMap;
221 typedef std::vector<rtl::OUString> PropertyIdToNameMap;
222 PropertyIdToNameMap maPropertyIdToNameMap;
223 typedef ::std::vector<css::uno::Any> RawValueContainer;
224 RawValueContainer maRawValues;
226 typedef std::vector<css::uno::Reference<css::beans::XPropertyChangeListener> > ChangeListenerContainer;
227 typedef std::map<ThemeItem,ChangeListenerContainer> ChangeListeners;
228 ChangeListeners maChangeListeners;
229 typedef std::vector<css::uno::Reference<css::beans::XVetoableChangeListener> > VetoableListenerContainer;
230 typedef std::map<ThemeItem,VetoableListenerContainer> VetoableListeners;
231 VetoableListeners maVetoableListeners;
233 enum PropertyType
235 PT_Image,
236 PT_Color,
237 PT_Paint,
238 PT_Integer,
239 PT_Boolean,
240 PT_Rectangle,
241 PT_Invalid
244 void SetupPropertyMaps();
245 void UpdateTheme();
246 static PropertyType GetPropertyType (const ThemeItem eItem);
247 static css::uno::Type GetCppuType (const PropertyType eType);
248 static sal_Int32 GetIndex (
249 const ThemeItem eItem,
250 const PropertyType eType);
252 VetoableListenerContainer* GetVetoableListeners (
253 const ThemeItem eItem,
254 const bool bCreate);
255 ChangeListenerContainer* GetChangeListeners (
256 const ThemeItem eItem,
257 const bool bCreate);
258 static bool DoVetoableListenersVeto (
259 const VetoableListenerContainer* pListeners,
260 const css::beans::PropertyChangeEvent& rEvent);
261 static void BroadcastPropertyChange (
262 const ChangeListenerContainer* pListeners,
263 const css::beans::PropertyChangeEvent& rEvent);
264 void ProcessNewValue (
265 const css::uno::Any& rValue,
266 const ThemeItem eItem,
267 const PropertyType eType);
271 } } // end of namespace sfx2::sidebar
273 #endif
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */