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
53 * @return The StyleManager object
55 static Toolkit::StyleManager Get();
58 * Construct a new StyleManager.
66 virtual ~StyleManager();
71 * @copydoc Toolkit::StyleManager::SetOrientationValue
73 void SetOrientationValue( int orientation );
76 * @copydoc Toolkit::StyleManager::GetOrientationValue
78 int GetOrientationValue();
81 * @copydoc Toolkit::StyleManager::SetOrientation( Orientation orientation )
83 void SetOrientation( Orientation orientation );
86 * @copydoc Toolkit::StyleManager::GetOrientation
88 Orientation GetOrientation();
91 * @copydoc Toolkit::StyleManager::GetDefaultFontFamily
93 std::string GetDefaultFontFamily() const;
96 * @copydoc Toolkit::StyleManager::SetStyleConstant
98 void SetStyleConstant( const std::string& key, const Property::Value& value );
101 * @copydoc Toolkit::StyleManager::GetStyleConstant
103 bool GetStyleConstant( const std::string& key, Property::Value& valueOut );
106 * @copydoc Toolkit::StyleManager::RequestThemeChange
108 void RequestThemeChange( const std::string& themeFile );
111 * @copydoc Toolkit::StyleManager::RequestDefaultTheme
113 void RequestDefaultTheme();
116 * @brief Apply the theme style to a control.
118 * @param[in] control The control to apply style.
120 void ApplyThemeStyle( Toolkit::Control control );
123 * @brief Apply the theme style to a control at initialization.
125 * @param[in] control The control to apply style.
127 void ApplyThemeStyleAtInit( Toolkit::Control control );
130 * @copydoc Toolkit::StyleManager::ApplyStyle
132 void ApplyStyle( Toolkit::Control control, const std::string& jsonFileName, const std::string& styleName );
138 * @copydoc Toolkit::StyleManager::StyleChangeSignal
140 Toolkit::StyleManager::StyleChangeSignalType& StyleChangeSignal();
143 typedef std::vector<std::string> StringList;
146 * @brief Set the current theme. Called only once per event processing cycle.
147 * @param[in] themeFile The name of the theme file to read.
149 void SetTheme( const std::string& themeFile );
152 * @brief Internal helper method to read a file from file system.
153 * @param filename The name of the file to read.
154 * @param[out] stringOut The string to return the file in
156 * @param Return true if file was found
158 bool LoadFile(const std::string& filename, std::string& stringOut);
161 * @brief Create a new builder.
163 * @param[in] constants A map of constants to be used by the builder
165 * @return Return the newly created builder
167 Toolkit::Builder CreateBuilder( const Property::Map& constants );
170 * @brief Load a JSON file into given builder
172 * @param[in] builder The builder object to load the theme file
173 * @param[in] jsonFileName The name of the JSON file to load
174 * @return Return true if file was loaded
176 bool LoadJSON( Toolkit::Builder builder, const std::string& jsonFileName );
179 * @brief Collect qualifiers (e.g. Landscape, portrait etc) for a given style
181 * @param[in,out] qualifiersOut The list to populate with qualifiers
183 void CollectQualifiers( StringList& qualifiersOut );
186 * @brief Construct a qualified style name out of qualifiers
188 * A qualifed style name will be in the format: style-qualifier0-qualifier1-qualifierN
190 * @param[in] styleName The root name of the style
191 * @param[in] qualifiers List of qualifier names
192 * @param[out] qualifiedStyleOut The qualified style name
194 void BuildQualifiedStyleName( const std::string& styleName, const StringList& qualifiers, std::string& qualifiedStyleOut );
197 * @brief Apply a style to the control using the given builder
199 * @param[in] builder The builder to apply the style from
200 * @param[in] control The control to apply the style to
202 void ApplyStyle( Toolkit::Builder builder, Toolkit::Control control );
205 * @brief Callback for orientation changes
207 * @param[in] orientation The orientation object
209 void OnOrientationChanged( Orientation orientation );
212 * Search for a builder in the cache
214 * @param[in] key The key the builder was cached under
215 * @return Return the cached builder if found or an empty builder object if not found
217 Toolkit::Builder FindCachedBuilder( const std::string& key );
220 * Store a given builder in the cache keyed to the given key
222 * @param[in] builder The builder object to store
223 * @param[in] key The key to store the builder under
225 void CacheBuilder( Toolkit::Builder builder, const std::string& key );
228 * Callback for when style monitor raises a signal
230 * @param[in] styleMonitor The style monitor object
231 * @param[in] styleChange The style change type
233 void StyleMonitorChange( StyleMonitor styleMonitor, StyleChange::Type styleChange );
236 StyleManager(const StyleManager&);
238 StyleManager& operator=(const StyleManager& rhs);
242 // Map to store builders keyed by JSON file name
243 typedef std::map< std::string, Toolkit::Builder > BuilderMap;
245 Toolkit::Builder mThemeBuilder; ///< Builder for all default theme properties
246 StyleMonitor mStyleMonitor; ///< Style monitor handle
248 Orientation mOrientation; ///< Handle to application orientation object
249 int mOrientationDegrees; ///< Directly set value of orientation
251 int mDefaultFontSize; ///< Logical size, not a point-size
252 std::string mDefaultFontFamily;
253 std::string mThemeFile; ///< The full path of the current theme file
255 Property::Map mThemeBuilderConstants; ///< Contants to give the theme builder
256 Property::Map mStyleBuilderConstants; ///< Constants specific to building styles
258 BuilderMap mBuilderCache; ///< Cache of builders keyed by JSON file name
260 Toolkit::Internal::FeedbackStyle* mFeedbackStyle; ///< Feedback style
263 Toolkit::StyleManager::StyleChangeSignalType mStyleChangeSignal; ///< Emitted when the style( theme/font ) changes
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__