1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <sfx2/dllapi.h>
23 #include <tools/color.hxx>
24 #include <comphelper/compbase.hxx>
26 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <unordered_map>
32 namespace sfx2::sidebar
{
34 typedef comphelper::WeakComponentImplHelper
<
35 css::beans::XPropertySet
,
36 css::beans::XPropertySetInfo
39 /** Simple collection of colors, gradients, fonts that define the
40 look of the sidebar and its controls.
42 class SFX2_DLLPUBLIC Theme final
43 : public ThemeInterfaceBase
51 AnyItem_
= Pre_Color_
,
58 Color_DeckTitleBarBackground
,
59 Color_PanelBackground
,
60 Color_PanelTitleBarBackground
,
61 Color_TabBarBackground
,
66 Int_DeckSeparatorHeight
,
70 Int_DeckBottomPadding
,
75 Bool_IsHighContrastModeActive
,
81 static Color
GetColor (const ThemeItem eItem
);
82 static sal_Int32
GetInteger (const ThemeItem eItem
);
84 static bool IsHighContrastMode();
86 static void HandleDataChange();
88 void InitializeTheme();
91 virtual ~Theme() override
;
92 Theme(const Theme
&) = delete;
93 Theme
& operator=( const Theme
& ) = delete;
95 virtual void disposing(std::unique_lock
<std::mutex
>&) override
;
97 static css::uno::Reference
<css::beans::XPropertySet
> GetPropertySet();
99 // beans::XPropertySet
100 virtual css::uno::Reference
<css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
;
101 virtual void SAL_CALL
setPropertyValue (
102 const OUString
& rsPropertyName
,
103 const css::uno::Any
& rValue
) override
;
104 virtual css::uno::Any SAL_CALL
getPropertyValue (
105 const OUString
& rsPropertyName
) override
;
106 virtual void SAL_CALL
addPropertyChangeListener(
107 const OUString
& rsPropertyName
,
108 const css::uno::Reference
<css::beans::XPropertyChangeListener
>& rxListener
) override
;
109 virtual void SAL_CALL
removePropertyChangeListener(
110 const OUString
& rsPropertyName
,
111 const css::uno::Reference
<css::beans::XPropertyChangeListener
>& rxListener
) override
;
112 virtual void SAL_CALL
addVetoableChangeListener(
113 const OUString
& rsPropertyName
,
114 const css::uno::Reference
<css::beans::XVetoableChangeListener
>& rxListener
) override
;
115 virtual void SAL_CALL
removeVetoableChangeListener(
116 const OUString
& rsPropertyName
,
117 const css::uno::Reference
<css::beans::XVetoableChangeListener
>& rxListener
) override
;
119 // beans::XPropertySetInfo
120 virtual css::uno::Sequence
<css::beans::Property
> SAL_CALL
getProperties() override
;
121 virtual css::beans::Property SAL_CALL
getPropertyByName (const OUString
& rsName
) override
;
122 virtual sal_Bool SAL_CALL
hasPropertyByName (const OUString
& rsName
) override
;
125 static Theme
& GetCurrentTheme();
127 std::vector
<Color
> maColors
;
128 std::vector
<sal_Int32
> maIntegers
;
129 std::vector
<bool> maBooleans
;
130 bool mbIsHighContrastMode
;
131 bool mbIsHighContrastModeSetManually
;
133 typedef std::unordered_map
<OUString
,ThemeItem
> PropertyNameToIdMap
;
134 PropertyNameToIdMap maPropertyNameToIdMap
;
135 typedef std::vector
<OUString
> PropertyIdToNameMap
;
136 PropertyIdToNameMap maPropertyIdToNameMap
;
137 typedef ::std::vector
<css::uno::Any
> RawValueContainer
;
138 RawValueContainer maRawValues
;
140 typedef std::vector
<css::uno::Reference
<css::beans::XPropertyChangeListener
> > ChangeListenerContainer
;
141 typedef std::map
<ThemeItem
,ChangeListenerContainer
> ChangeListeners
;
142 ChangeListeners maChangeListeners
;
143 typedef std::vector
<css::uno::Reference
<css::beans::XVetoableChangeListener
> > VetoableListenerContainer
;
144 typedef std::map
<ThemeItem
,VetoableListenerContainer
> VetoableListeners
;
145 VetoableListeners maVetoableListeners
;
155 void SetupPropertyMaps();
157 static PropertyType
GetPropertyType (const ThemeItem eItem
);
158 static css::uno::Type
const & GetCppuType (const PropertyType eType
);
159 static sal_Int32
GetIndex (
160 const ThemeItem eItem
,
161 const PropertyType eType
);
163 VetoableListenerContainer
* GetVetoableListeners (
164 const ThemeItem eItem
,
166 ChangeListenerContainer
* GetChangeListeners (
167 const ThemeItem eItem
,
169 static bool DoVetoableListenersVeto (
170 const VetoableListenerContainer
* pListeners
,
171 const css::beans::PropertyChangeEvent
& rEvent
);
172 static void BroadcastPropertyChange (
173 const ChangeListenerContainer
* pListeners
,
174 const css::beans::PropertyChangeEvent
& rEvent
);
175 void ProcessNewValue (
176 const css::uno::Any
& rValue
,
177 const ThemeItem eItem
,
178 const PropertyType eType
);
182 } // end of namespace sfx2::sidebar
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */