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.
22 #include <dali/public-api/common/vector-wrapper.h>
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>
45 * @copydoc Toolkit::StyleManager
47 class StyleManager : public Dali::BaseObject, public ConnectionTracker
54 * @return The StyleManager object
56 static Toolkit::StyleManager Get();
59 * Construct a new StyleManager.
64 * @copydoc Toolkit::StyleManager::SetOrientationValue
66 void SetOrientationValue( int orientation );
69 * @copydoc Toolkit::StyleManager::GetOrientationValue
71 int GetOrientationValue();
74 * @copydoc Toolkit::StyleManager::SetOrientation( Orientation orientation )
76 void SetOrientation( Orientation orientation );
79 * @copydoc Toolkit::StyleManager::GetOrientation
81 Orientation GetOrientation();
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::RequestThemeChange
96 void RequestThemeChange( const std::string& themeFile );
99 * @copydoc Toolkit::StyleManager::RequestDefaultTheme
101 void RequestDefaultTheme();
104 * Determine if a theme change has been requested
105 * @return Whether a theme request is pending
107 bool IsThemeRequestPending();
110 * @brief Apply the theme style to a control.
112 * @param[in] control The control to apply style.
114 void ApplyThemeStyle( Toolkit::Control control );
117 * @brief Apply the theme style to a control at initialization.
119 * @param[in] control The control to apply style.
121 void ApplyThemeStyleAtInit( Toolkit::Control control );
124 * @copydoc Toolkit::StyleManager::ApplyStyle
126 void ApplyStyle( Toolkit::Control control, const std::string& jsonFileName, const std::string& styleName );
132 * @copydoc Toolkit::StyleManager::StyleChangeSignal
134 Toolkit::StyleManager::StyleChangeSignalType& StyleChangeSignal();
141 virtual ~StyleManager();
147 * @brief Set the current theme. Called only once per event processing cycle.
153 typedef std::vector<std::string> StringList;
156 * @brief Internal helper method to read a file from file system.
157 * @param filename The name of the file to read.
158 * @param[out] stringOut The string to return the file in
160 * @param Return true if file was found
162 bool LoadFile(const std::string& filename, std::string& stringOut);
165 * @brief Create a new builder.
167 * @param[in] constants A map of constants to be used by the builder
169 * @return Return the newly created builder
171 Toolkit::Builder CreateBuilder( const Property::Map& constants );
174 * @brief Load a JSON file into given builder
176 * @param[in] builder The builder object to load the theme file
177 * @param[in] jsonFileName The name of the JSON file to load
178 * @return Return true if file was loaded
180 bool LoadJSON( Toolkit::Builder builder, const std::string& jsonFileName );
183 * @brief Collect qualifiers (e.g. Landscape, portrait etc) for a given style
185 * @param[in,out] qualifiersOut The list to populate with qualifiers
187 void CollectQualifiers( StringList& qualifiersOut );
190 * @brief Construct a qualified style name out of qualifiers
192 * A qualifed style name will be in the format: style-qualifier0-qualifier1-qualifierN
194 * @param[in] styleName The root name of the style
195 * @param[in] qualifiers List of qualifier names
196 * @param[out] qualifiedStyleOut The qualified style name
198 void BuildQualifiedStyleName( const std::string& styleName, const StringList& qualifiers, std::string& qualifiedStyleOut );
201 * @brief Apply a style to the control using the given builder
203 * @param[in] builder The builder to apply the style from
204 * @param[in] control The control to apply the style to
206 void ApplyStyle( Toolkit::Builder builder, Toolkit::Control control );
209 * @brief Callback for orientation changes
211 * @param[in] orientation The orientation object
213 void OnOrientationChanged( Orientation orientation );
216 * Search for a builder in the cache
218 * @param[in] key The key the builder was cached under
219 * @return Return the cached builder if found or an empty builder object if not found
221 Toolkit::Builder FindCachedBuilder( const std::string& key );
224 * Store a given builder in the cache keyed to the given key
226 * @param[in] builder The builder object to store
227 * @param[in] key The key to store the builder under
229 void CacheBuilder( Toolkit::Builder builder, const std::string& key );
232 * Callback for when style monitor raises a signal
234 * @param[in] styleMonitor The style monitor object
235 * @param[in] styleChange The style change type
237 void StyleMonitorChange( StyleMonitor styleMonitor, StyleChange::Type styleChange );
240 StyleManager(const StyleManager&);
242 StyleManager& operator=(const StyleManager& rhs);
246 // Map to store builders keyed by JSON file name
247 typedef std::map< std::string, Toolkit::Builder > BuilderMap;
249 Toolkit::Builder mThemeBuilder; ///< Builder for all default theme properties
250 StyleMonitor mStyleMonitor; ///< Style monitor handle
252 Orientation mOrientation; ///< Handle to application orientation object
253 int mOrientationDegrees; ///< Directly set value of orientation
255 int mDefaultFontSize; ///< Logical size, not a point-size
257 std::string mThemeFile; ///< The full path of the current theme file
259 Property::Map mThemeBuilderConstants; ///< Contants to give the theme builder
260 Property::Map mStyleBuilderConstants; ///< Constants specific to building styles
262 BuilderMap mBuilderCache; ///< Cache of builders keyed by JSON file name
264 Toolkit::Internal::FeedbackStyle* mFeedbackStyle; ///< Feedback style
267 Toolkit::StyleManager::StyleChangeSignalType mStyleChangeSignal; ///< Emitted when the style( theme/font ) changes
270 } // namespace Internal
272 inline Internal::StyleManager& GetImpl( Dali::Toolkit::StyleManager& obj )
274 DALI_ASSERT_ALWAYS( obj );
276 Dali::BaseObject& handle = obj.GetBaseObject();
278 return static_cast< Internal::StyleManager& >( handle );
281 inline const Internal::StyleManager& GetImpl( const Dali::Toolkit::StyleManager& obj )
283 DALI_ASSERT_ALWAYS( obj );
285 const Dali::BaseObject& handle = obj.GetBaseObject();
287 return static_cast< const Internal::StyleManager& >( handle );
290 } // namespace Toolkit
294 #endif // __DALI_TOOLKIT_INTERNAL_STYLE_MANAGER_H__