1 #ifndef __DALI_TOOLKIT_INTERNAL_STYLE_MANAGER_H__
2 #define __DALI_TOOLKIT_INTERNAL_STYLE_MANAGER_H__
5 * Copyright (c) 2014 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.
23 #include <dali/devel-api/common/map-wrapper.h>
24 #include <dali/devel-api/adaptor-framework/style-monitor.h>
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/public-api/object/property-map.h>
27 #include <dali/public-api/signals/connection-tracker.h>
30 #include <dali-toolkit/devel-api/styling/style-manager.h>
31 #include <dali-toolkit/devel-api/builder/builder.h>
42 * @copydoc Toolkit::StyleManager
44 class StyleManager : public Dali::BaseObject, public ConnectionTracker
51 * @return The StyleManager object
53 static Toolkit::StyleManager Get();
56 * Construct a new StyleManager.
61 * @copydoc Toolkit::StyleManager::SetOrientationValue
63 void SetOrientationValue( int orientation );
66 * @copydoc Toolkit::StyleManager::GetOrientationValue
68 int GetOrientationValue();
71 * @copydoc Toolkit::StyleManager::SetOrientation( Orientation orientation )
73 void SetOrientation( Orientation orientation );
76 * @copydoc Toolkit::StyleManager::GetOrientation
78 Orientation GetOrientation();
81 * @copydoc Toolkit::StyleManager::SetStyleConstant
83 void SetStyleConstant( const std::string& key, const Property::Value& value );
86 * @copydoc Toolkit::StyleManager::GetStyleConstant
88 bool GetStyleConstant( const std::string& key, Property::Value& valueOut );
91 * @copydoc Toolkit::StyleManager::RequestThemeChange
93 void RequestThemeChange( const std::string& themeFile );
96 * @copydoc Toolkit::StyleManager::RequestDefaultTheme
98 void RequestDefaultTheme();
101 * Determine if a theme change has been requested
102 * @return Whether a theme request is pending
104 bool IsThemeRequestPending();
107 * @brief Apply the theme style to a control.
109 * @param[in] control The control to apply style.
111 void ApplyThemeStyle( Toolkit::Control control );
114 * @copydoc Toolkit::StyleManager::ApplyStyle
116 void ApplyStyle( Toolkit::Control control, const std::string& jsonFileName, const std::string& styleName );
122 * @copydoc Toolkit::StyleManager::StyleChangeSignal
124 Toolkit::StyleManager::StyleChangeSignalType& StyleChangeSignal();
131 virtual ~StyleManager();
137 * @brief Set the current theme. Called only once per event processing cycle.
143 typedef std::list<std::string> StringList;
146 * @brief Internal helper method to read a file from file system.
147 * @param filename The name of the file to read.
148 * @param[out] stringOut The string to return the file in
150 * @param Return true if file was found
152 bool LoadFile(const std::string& filename, std::string& stringOut);
155 * @brief Create a new builder.
157 * @param[in] constants A map of constants to be used by the builder
159 * @return Return the newly created builder
161 Toolkit::Builder CreateBuilder( const Property::Map& constants );
164 * @brief Load a JSON file into given builder
166 * @param[in] builder The builder object to load the theme file
167 * @param[in] jsonFileName The name of the JSON file to load
168 * @return Return true if file was loaded
170 bool LoadJSON( Toolkit::Builder builder, const std::string& jsonFileName );
173 * @brief Collect qualifiers (e.g. Landscape, portrait etc) for a given style
175 * @param[in,out] qualifiersOut The list to populate with qualifiers
177 void CollectQualifiers( StringList& qualifiersOut );
180 * @brief Construct a qualified style name out of qualifiers
182 * A qualifed style name will be in the format: style-qualifier0-qualifier1-qualifierN
184 * @param[in] styleName The root name of the style
185 * @param[in] qualifiers List of qualifier names
186 * @param[out] qualifiedStyleOut The qualified style name
188 void BuildQualifiedStyleName( const std::string& styleName, const StringList& qualifiers, std::string& qualifiedStyleOut );
191 * @brief Apply a style to the control using the given builder
193 * @param[in] builder The builder to apply the style from
194 * @param[in] control The control to apply the style to
196 void ApplyStyle( Toolkit::Builder builder, Toolkit::Control control );
199 * @brief Callback for orientation changes
201 * @param[in] orientation The orientation object
203 void OnOrientationChanged( Orientation orientation );
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 data
227 void StyleMonitorChange( StyleMonitor styleMonitor, StyleChange styleChange );
230 StyleManager(const StyleManager&);
232 StyleManager& operator=(const StyleManager& rhs);
236 // Map to store builders keyed by JSON file name
237 typedef std::map< std::string, Toolkit::Builder > BuilderMap;
239 Toolkit::Builder mThemeBuilder; ///< Builder for all default theme properties
241 Orientation mOrientation; ///< Handle to application orientation object
242 int mOrientationDegrees; ///< Directly set value of orientation
244 int mDefaultFontSize; ///< Logical size, not a point-size
246 std::string mThemeFile; ///< The full path of the current theme file
248 Property::Map mThemeBuilderConstants; ///< Contants to give the theme builder
249 Property::Map mStyleBuilderConstants; ///< Constants specific to building styles
251 BuilderMap mBuilderCache; ///< Cache of builders keyed by JSON file name
254 Toolkit::StyleManager::StyleChangeSignalType mStyleChangeSignal; ///< Emitted when the style( theme/font ) changes
257 } // namespace Internal
259 inline Internal::StyleManager& GetImpl( Dali::Toolkit::StyleManager& obj )
261 DALI_ASSERT_ALWAYS( obj );
263 Dali::BaseObject& handle = obj.GetBaseObject();
265 return static_cast< Internal::StyleManager& >( handle );
268 inline const Internal::StyleManager& GetImpl( const Dali::Toolkit::StyleManager& obj )
270 DALI_ASSERT_ALWAYS( obj );
272 const Dali::BaseObject& handle = obj.GetBaseObject();
274 return static_cast< const Internal::StyleManager& >( handle );
277 } // namespace Toolkit
281 #endif // __DALI_TOOLKIT_INTERNAL_STYLE_MANAGER_H__