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 Flora License, Version 1.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://floralicense.org/license/
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::ThemeChangeSignal
121 Toolkit::StyleManager::ThemeChangeSignalType& ThemeChangeSignal();
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 Emit theme changed signal
198 void EmitThemeChangeSignal();
201 * @brief Callback for orientation changes
203 * @param[in] orientation The orientation object
205 void OnOrientationChanged( Orientation orientation );
208 * Search for a builder in the cache
210 * @param[in] key The key the builder was cached under
211 * @return Return the cached builder if found or an empty builder object if not found
213 Toolkit::Builder FindCachedBuilder( const std::string& key );
216 * Store a given builder in the cache keyed to the given key
218 * @param[in] builder The builder object to store
219 * @param[in] key The key to store the builder under
221 void CacheBuilder( Toolkit::Builder builder, const std::string& key );
224 StyleManager(const StyleManager&);
226 StyleManager& operator=(const StyleManager& rhs);
230 // Map to store builders keyed by JSON file name
231 typedef std::map< std::string, Toolkit::Builder > BuilderMap;
233 Toolkit::Builder mThemeBuilder; ///< Builder for all default theme properties
235 Orientation mOrientation; ///< Handle to application orientation object
236 int mOrientationDegrees; ///< Directly set value of orientation
238 std::string mThemeFile; ///< The full path of the current theme file
240 Toolkit::PropertyValueMap mThemeBuilderConstants; ///< Contants to give the theme builder
241 Toolkit::PropertyValueMap mStyleBuilderConstants; ///< Constants specific to building styles
243 BuilderMap mBuilderCache; ///< Cache of builders keyed by JSON file name
245 bool mSetThemeConnection; ///< Has the callback to set the theme been set
248 Toolkit::StyleManager::ThemeChangeSignalType mThemeChangeSignal; ///< Emitted when the theme changes
251 } // namespace Internal
253 inline Internal::StyleManager& GetImpl( Dali::Toolkit::StyleManager& obj )
255 DALI_ASSERT_ALWAYS( obj );
257 Dali::BaseObject& handle = obj.GetBaseObject();
259 return static_cast< Internal::StyleManager& >( handle );
262 inline const Internal::StyleManager& GetImpl( const Dali::Toolkit::StyleManager& obj )
264 DALI_ASSERT_ALWAYS( obj );
266 const Dali::BaseObject& handle = obj.GetBaseObject();
268 return static_cast< const Internal::StyleManager& >( handle );
271 } // namespace Toolkit
275 #endif // __DALI_TOOLKIT_INTERNAL_STYLE_MANAGER_H__