1 #ifndef DALI_TOOLKIT_INTERNAL_STYLE_MANAGER_H
2 #define DALI_TOOLKIT_INTERNAL_STYLE_MANAGER_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #include <dali/devel-api/adaptor-framework/style-monitor.h>
22 #include <dali/devel-api/common/map-wrapper.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/object/property-map.h>
26 #include <dali/public-api/signals/connection-tracker.h>
30 #include <dali-toolkit/devel-api/builder/builder.h>
31 #include <dali-toolkit/devel-api/styling/style-manager-devel.h>
32 #include <dali-toolkit/internal/builder/style.h>
33 #include <dali-toolkit/public-api/styling/style-manager.h>
44 * @copydoc Toolkit::StyleManager
46 class StyleManager : public Dali::BaseObject, public ConnectionTracker
52 * @return The StyleManager object
54 static Toolkit::StyleManager Get();
57 * Construct a new StyleManager.
65 virtual ~StyleManager();
69 * @copydoc Toolkit::StyleManager::ApplyTheme
71 void ApplyTheme(const std::string& themeFile);
74 * @copydoc Toolkit::StyleManager::ApplyDefaultTheme
76 void ApplyDefaultTheme();
79 * @copydoc Toolkit::StyleManager::GetDefaultFontFamily
81 const std::string& GetDefaultFontFamily() const;
84 * @copydoc Toolkit::StyleManager::SetStyleConstant
86 void SetStyleConstant(const std::string& key, const Property::Value& value);
89 * @copydoc Toolkit::StyleManager::GetStyleConstant
91 bool GetStyleConstant(const std::string& key, Property::Value& valueOut);
94 * @copydoc Toolkit::StyleManager::GetConfigurations
96 const Property::Map& GetConfigurations();
99 * @copydoc Toolkit::DevelStyleManager::SetBrokenImageUrl
101 void SetBrokenImageUrl(DevelStyleManager::BrokenImageType brokenImageType, const std::string& brokenImageUrl);
104 * @copydoc Toolkit::DevelStyleManager::GetBrokenImageUrl
106 std::string GetBrokenImageUrl(DevelStyleManager::BrokenImageType brokenImageType);
109 * @copydoc Toolkit::DevelStyleManager::GetBrokenImageUrlList
111 std::vector<std::string> GetBrokenImageUrlList();
114 * @brief Apply the theme style to a control.
116 * @param[in] control The control to apply style.
118 void ApplyThemeStyle(Toolkit::Control control);
121 * @brief Apply the theme style to a control at initialization.
123 * @param[in] control The control to apply style.
125 void ApplyThemeStyleAtInit(Toolkit::Control control);
128 * @copydoc Toolkit::StyleManager::ApplyStyle
130 void ApplyStyle(Toolkit::Control control, const std::string& jsonFileName, const std::string& styleName);
133 * Get the state/style information for the given control
134 * @param[in] control The control to get state information for
135 * @return The style information (or empty ptr if not found)
137 const StylePtr GetRecordedStyle(Toolkit::Control control);
143 * @copydoc Toolkit::StyleManager::StyleChangeSignal
144 * This signal is sent after all the controls have been updated
145 * due to style change
147 Toolkit::StyleManager::StyleChangedSignalType& StyleChangedSignal();
150 * This signal is sent to the controls following a style change.
151 * It should not be exposed in the public API
153 Toolkit::StyleManager::StyleChangedSignalType& ControlStyleChangeSignal();
156 * This signal is sent to the visual factory following a broken image change.
157 * It should not be exposed in the public API
159 Toolkit::DevelStyleManager::BrokenImageChangedSignalType& BrokenImageChangedSignal();
162 typedef std::vector<std::string> StringList;
165 * @brief Set the current theme. Called only once per event processing cycle.
166 * @param[in] themeFile The name of the theme file to read.
168 void SetTheme(const std::string& themeFile);
171 * @brief Internal helper method to read a file from file system.
172 * @param filename The name of the file to read.
173 * @param[out] stringOut The string to return the file in
175 * @param Return true if file was found
177 bool LoadFile(const std::string& filename, std::string& stringOut);
180 * @brief Create a new builder.
182 * @param[in] constants A map of constants to be used by the builder
184 * @return Return the newly created builder
186 Toolkit::Builder CreateBuilder(const Property::Map& constants);
189 * @brief Load a JSON file into given builder
191 * @param[in] builder The builder object to load the theme file
192 * @param[in] jsonFileName The name of the JSON file to load
193 * @return Return true if file was loaded
195 bool LoadJSON(Toolkit::Builder builder, const std::string& jsonFileName);
198 * @brief Apply a style to the control using the given builder
200 * @param[in] builder The builder to apply the style from
201 * @param[in] control The control to apply the style to
203 void ApplyStyle(Toolkit::Builder builder, Toolkit::Control control);
206 * Search for a builder in the cache
208 * @param[in] key The key the builder was cached under
209 * @return Return the cached builder if found or an empty builder object if not found
211 Toolkit::Builder FindCachedBuilder(const std::string& key);
214 * Store a given builder in the cache keyed to the given key
216 * @param[in] builder The builder object to store
217 * @param[in] key The key to store the builder under
219 void CacheBuilder(Toolkit::Builder builder, const std::string& key);
222 * Callback for when style monitor raises a signal
224 * @param[in] styleMonitor The style monitor object
225 * @param[in] styleChange The style change type
227 void StyleMonitorChange(StyleMonitor styleMonitor, StyleChange::Type styleChange);
230 * Emit signals to controls first, app second
232 void EmitStyleChangeSignals(StyleChange::Type styleChange);
235 StyleManager(const StyleManager&);
237 StyleManager& operator=(const StyleManager& rhs);
240 // Map to store builders keyed by JSON file name
241 typedef std::map<std::string, Toolkit::Builder> BuilderMap;
243 Toolkit::Builder mThemeBuilder; ///< Builder for all default theme properties
244 StyleMonitor mStyleMonitor; ///< Style monitor handle
246 int mDefaultFontSize; ///< Logical size, not a point-size
247 std::string mDefaultFontFamily;
248 std::string mDefaultThemeFilePath; ///< The full path of the default theme file
249 std::string mThemeFile; ///< The full path of the current theme file
251 Property::Map mThemeBuilderConstants; ///< Contants to give the theme builder
252 Property::Map mStyleBuilderConstants; ///< Constants specific to building styles
254 BuilderMap mBuilderCache; ///< Cache of builders keyed by JSON file name
256 Toolkit::Internal::FeedbackStyle* mFeedbackStyle; ///< Feedback style
258 std::vector<std::string> mBrokenImageUrls; ///< Broken Image Urls received from user
261 Toolkit::StyleManager::StyleChangedSignalType mControlStyleChangeSignal; ///< Emitted when the style( theme/font ) changes for the controls to style themselves
262 Toolkit::StyleManager::StyleChangedSignalType mStyleChangedSignal; ///< Emitted after the controls have been styled
263 Toolkit::DevelStyleManager::BrokenImageChangedSignalType mBrokenImageChangedSignal; ///< Emitted after brokenImageChangedSignal
266 } // namespace Internal
268 inline Internal::StyleManager& GetImpl(Dali::Toolkit::StyleManager& obj)
270 DALI_ASSERT_ALWAYS(obj);
272 Dali::BaseObject& handle = obj.GetBaseObject();
274 return static_cast<Internal::StyleManager&>(handle);
277 inline const Internal::StyleManager& GetImpl(const Dali::Toolkit::StyleManager& obj)
279 DALI_ASSERT_ALWAYS(obj);
281 const Dali::BaseObject& handle = obj.GetBaseObject();
283 return static_cast<const Internal::StyleManager&>(handle);
286 } // namespace Toolkit
290 #endif // DALI_TOOLKIT_INTERNAL_STYLE_MANAGER_H