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 <vcl/image.hxx>
25 #include <cppuhelper/compbase.hxx>
26 #include <cppuhelper/basemutex.hxx>
27 #include <tools/gen.hxx>
28 #include <vcl/wall.hxx>
30 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <unordered_map>
36 namespace sfx2::sidebar
{
38 typedef cppu::WeakComponentImplHelper
<
39 css::beans::XPropertySet
,
40 css::beans::XPropertySetInfo
43 /** Simple collection of colors, gradients, fonts that define the
44 look of the sidebar and its controls.
46 class SFX2_DLLPUBLIC Theme final
47 : private ::cppu::BaseMutex
,
48 public ThemeInterfaceBase
56 AnyItem_
= Pre_Image_
,
65 Color_DeckTitleBarBackground
,
66 Color_PanelBackground
,
67 Color_PanelTitleBarBackground
,
68 Color_TabBarBackground
,
73 Int_DeckSeparatorHeight
,
77 Int_DeckBottomPadding
,
82 Bool_IsHighContrastModeActive
,
88 static Image
GetImage (const ThemeItem eItem
);
89 static Color
GetColor (const ThemeItem eItem
);
90 static sal_Int32
GetInteger (const ThemeItem eItem
);
91 static bool GetBoolean (const ThemeItem eItem
);
93 static bool IsHighContrastMode();
95 static void HandleDataChange();
97 void InitializeTheme();
100 virtual ~Theme() override
;
101 Theme(const Theme
&) = delete;
102 Theme
& operator=( const Theme
& ) = delete;
104 virtual void SAL_CALL
disposing() override
;
106 static css::uno::Reference
<css::beans::XPropertySet
> GetPropertySet();
108 // beans::XPropertySet
109 virtual css::uno::Reference
<css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
;
110 virtual void SAL_CALL
setPropertyValue (
111 const OUString
& rsPropertyName
,
112 const css::uno::Any
& rValue
) override
;
113 virtual css::uno::Any SAL_CALL
getPropertyValue (
114 const OUString
& rsPropertyName
) override
;
115 virtual void SAL_CALL
addPropertyChangeListener(
116 const OUString
& rsPropertyName
,
117 const css::uno::Reference
<css::beans::XPropertyChangeListener
>& rxListener
) override
;
118 virtual void SAL_CALL
removePropertyChangeListener(
119 const OUString
& rsPropertyName
,
120 const css::uno::Reference
<css::beans::XPropertyChangeListener
>& rxListener
) override
;
121 virtual void SAL_CALL
addVetoableChangeListener(
122 const OUString
& rsPropertyName
,
123 const css::uno::Reference
<css::beans::XVetoableChangeListener
>& rxListener
) override
;
124 virtual void SAL_CALL
removeVetoableChangeListener(
125 const OUString
& rsPropertyName
,
126 const css::uno::Reference
<css::beans::XVetoableChangeListener
>& rxListener
) override
;
128 // beans::XPropertySetInfo
129 virtual css::uno::Sequence
<css::beans::Property
> SAL_CALL
getProperties() override
;
130 virtual css::beans::Property SAL_CALL
getPropertyByName (const OUString
& rsName
) override
;
131 virtual sal_Bool SAL_CALL
hasPropertyByName (const OUString
& rsName
) override
;
134 static Theme
& GetCurrentTheme();
136 std::vector
<Image
> maImages
;
137 std::vector
<Color
> maColors
;
138 std::vector
<sal_Int32
> maIntegers
;
139 std::vector
<bool> maBooleans
;
140 bool mbIsHighContrastMode
;
141 bool mbIsHighContrastModeSetManually
;
143 typedef std::unordered_map
<OUString
,ThemeItem
> PropertyNameToIdMap
;
144 PropertyNameToIdMap maPropertyNameToIdMap
;
145 typedef std::vector
<OUString
> PropertyIdToNameMap
;
146 PropertyIdToNameMap maPropertyIdToNameMap
;
147 typedef ::std::vector
<css::uno::Any
> RawValueContainer
;
148 RawValueContainer maRawValues
;
150 typedef std::vector
<css::uno::Reference
<css::beans::XPropertyChangeListener
> > ChangeListenerContainer
;
151 typedef std::map
<ThemeItem
,ChangeListenerContainer
> ChangeListeners
;
152 ChangeListeners maChangeListeners
;
153 typedef std::vector
<css::uno::Reference
<css::beans::XVetoableChangeListener
> > VetoableListenerContainer
;
154 typedef std::map
<ThemeItem
,VetoableListenerContainer
> VetoableListeners
;
155 VetoableListeners maVetoableListeners
;
166 void SetupPropertyMaps();
168 static PropertyType
GetPropertyType (const ThemeItem eItem
);
169 static css::uno::Type
const & GetCppuType (const PropertyType eType
);
170 static sal_Int32
GetIndex (
171 const ThemeItem eItem
,
172 const PropertyType eType
);
174 VetoableListenerContainer
* GetVetoableListeners (
175 const ThemeItem eItem
,
177 ChangeListenerContainer
* GetChangeListeners (
178 const ThemeItem eItem
,
180 static bool DoVetoableListenersVeto (
181 const VetoableListenerContainer
* pListeners
,
182 const css::beans::PropertyChangeEvent
& rEvent
);
183 static void BroadcastPropertyChange (
184 const ChangeListenerContainer
* pListeners
,
185 const css::beans::PropertyChangeEvent
& rEvent
);
186 void ProcessNewValue (
187 const css::uno::Any
& rValue
,
188 const ThemeItem eItem
,
189 const PropertyType eType
);
193 } // end of namespace sfx2::sidebar
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */