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.
26 #include <dali/dali.h>
27 #include <dali-toolkit/public-api/styling/style-manager.h>
28 #include <dali-toolkit/public-api/builder/builder.h>
39 * @copydoc Toolkit::StyleManager
41 class StyleManager : public Dali::BaseObject, public ConnectionTracker
48 * @return The StyleManager object
50 static Toolkit::StyleManager Get();
53 * Construct a new StyleManager.
58 * @copydoc Toolkit::StyleManager::SetOrientationValue
60 void SetOrientationValue( int orientation );
63 * @copydoc Toolkit::StyleManager::GetOrientationValue
65 int GetOrientationValue();
68 * @copydoc Toolkit::StyleManager::SetOrientation( Orientation orientation )
70 void SetOrientation( Orientation orientation );
73 * @copydoc Toolkit::StyleManager::GetOrientation
75 Orientation GetOrientation();
78 * @copydoc Toolkit::StyleManager::SetStyleConstant
80 void SetStyleConstant( const std::string& key, const Property::Value& value );
83 * @copydoc Toolkit::StyleManager::GetStyleConstant
85 bool GetStyleConstant( const std::string& key, Property::Value& valueOut );
88 * @copydoc Toolkit::StyleManager::RequestThemeChange
90 void RequestThemeChange( const std::string& themeFile );
93 * @copydoc Toolkit::StyleManager::RequestDefaultTheme
95 void RequestDefaultTheme();
98 * Determine if a theme change has been requested
99 * @return Whether a theme request is pending
101 bool IsThemeRequestPending();
104 * @brief Apply the theme style to a control.
106 * @param[in] control The control to apply style.
108 void ApplyThemeStyle( Toolkit::Control control );
111 * @copydoc Toolkit::StyleManager::ApplyStyle
113 void ApplyStyle( Toolkit::Control control, const std::string& jsonFileName, const std::string& styleName );
119 * @copydoc Toolkit::StyleManager::StyleChangeSignal
121 Toolkit::StyleManager::StyleChangeSignalType& StyleChangeSignal();
128 virtual ~StyleManager();
134 * @brief Set the current theme. Called only once per event processing cycle.
140 typedef std::list<std::string> StringList;
143 * @brief Internal helper method to read a file from file system.
144 * @param filename The name of the file to read.
145 * @param[out] stringOut The string to return the file in
147 * @param Return true if file was found
149 bool LoadFile(const std::string& filename, std::string& stringOut);
152 * @brief Create a new builder.
154 * @param[in] constants A map of constants to be used by the builder
156 * @return Return the newly created builder
158 Toolkit::Builder CreateBuilder( const PropertyValueMap& constants );
161 * @brief Load a JSON file into given builder
163 * @param[in] builder The builder object to load the theme file
164 * @param[in] jsonFileName The name of the JSON file to load
165 * @return Return true if file was loaded
167 bool LoadJSON( Toolkit::Builder builder, const std::string& jsonFileName );
170 * @brief Collect qualifiers (e.g. Landscape, portrait etc) for a given style
172 * @param[in,out] qualifiersOut The list to populate with qualifiers
174 void CollectQualifiers( StringList& qualifiersOut );
177 * @brief Construct a qualified style name out of qualifiers
179 * A qualifed style name will be in the format: style-qualifier0-qualifier1-qualifierN
181 * @param[in] styleName The root name of the style
182 * @param[in] qualifiers List of qualifier names
183 * @param[out] qualifiedStyleOut The qualified style name
185 void BuildQualifiedStyleName( const std::string& styleName, const StringList& qualifiers, std::string& qualifiedStyleOut );
188 * @brief Apply a style to the control using the given builder
190 * @param[in] builder The builder to apply the style from
191 * @param[in] control The control to apply the style to
193 void ApplyStyle( Toolkit::Builder builder, Toolkit::Control control );
196 * @brief Callback for orientation changes
198 * @param[in] orientation The orientation object
200 void OnOrientationChanged( Orientation orientation );
203 * Search for a builder in the cache
205 * @param[in] key The key the builder was cached under
206 * @return Return the cached builder if found or an empty builder object if not found
208 Toolkit::Builder FindCachedBuilder( const std::string& key );
211 * Store a given builder in the cache keyed to the given key
213 * @param[in] builder The builder object to store
214 * @param[in] key The key to store the builder under
216 void CacheBuilder( Toolkit::Builder builder, const std::string& key );
219 * Callback for when style monitor raises a signal
221 * @param[in] styleMonitor The style monitor object
222 * @param[in] styleChange The style change data
224 void StyleMonitorChange( StyleMonitor styleMonitor, StyleChange styleChange );
227 StyleManager(const StyleManager&);
229 StyleManager& operator=(const StyleManager& rhs);
233 // Map to store builders keyed by JSON file name
234 typedef std::map< std::string, Toolkit::Builder > BuilderMap;
236 Toolkit::Builder mThemeBuilder; ///< Builder for all default theme properties
238 Orientation mOrientation; ///< Handle to application orientation object
239 int mOrientationDegrees; ///< Directly set value of orientation
241 std::string mThemeFile; ///< The full path of the current theme file
243 Toolkit::PropertyValueMap mThemeBuilderConstants; ///< Contants to give the theme builder
244 Toolkit::PropertyValueMap mStyleBuilderConstants; ///< Constants specific to building styles
246 BuilderMap mBuilderCache; ///< Cache of builders keyed by JSON file name
248 bool mSetThemeConnection; ///< Has the callback to set the theme been set
251 Toolkit::StyleManager::StyleChangeSignalType mStyleChangeSignal; ///< Emitted when the style( theme/font ) changes
254 } // namespace Internal
256 inline Internal::StyleManager& GetImpl( Dali::Toolkit::StyleManager& obj )
258 DALI_ASSERT_ALWAYS( obj );
260 Dali::BaseObject& handle = obj.GetBaseObject();
262 return static_cast< Internal::StyleManager& >( handle );
265 inline const Internal::StyleManager& GetImpl( const Dali::Toolkit::StyleManager& obj )
267 DALI_ASSERT_ALWAYS( obj );
269 const Dali::BaseObject& handle = obj.GetBaseObject();
271 return static_cast< const Internal::StyleManager& >( handle );
274 } // namespace Toolkit
278 #endif // __DALI_TOOLKIT_INTERNAL_STYLE_MANAGER_H__