Merge "Updated @since tags for APIs added since 1.2.0 that are required for Tizen...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / styling / style-manager-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_STYLE_MANAGER_H__
2 #define __DALI_TOOLKIT_INTERNAL_STYLE_MANAGER_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <string>
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>
28
29 // INTERNAL INCLUDES
30 #include <dali-toolkit/public-api/styling/style-manager.h>
31 #include <dali-toolkit/devel-api/builder/builder.h>
32
33 namespace Dali
34 {
35
36 namespace Toolkit
37 {
38
39 namespace Internal
40 {
41
42 class FeedbackStyle;
43
44 /**
45  * @copydoc Toolkit::StyleManager
46  */
47 class StyleManager : public Dali::BaseObject, public ConnectionTracker
48 {
49 public:
50   /**
51    * Singleton access
52    *
53    * @return The StyleManager object
54    */
55   static Toolkit::StyleManager Get();
56
57   /**
58    * Construct a new StyleManager.
59    */
60   StyleManager();
61
62 protected:
63   /**
64    * @brief Destructor
65    */
66   virtual ~StyleManager();
67
68 public: // Public API
69
70 /**
71    * @copydoc Toolkit::StyleManager::ApplyTheme
72    */
73   void ApplyTheme( const std::string& themeFile );
74
75   /**
76    * @copydoc Toolkit::StyleManager::ApplyDefaultTheme
77    */
78   void ApplyDefaultTheme();
79
80   /**
81    * @copydoc Toolkit::StyleManager::GetDefaultFontFamily
82    */
83   const std::string& GetDefaultFontFamily() const;
84
85   /**
86    * @copydoc Toolkit::StyleManager::SetStyleConstant
87    */
88   void SetStyleConstant( const std::string& key, const Property::Value& value );
89
90   /**
91    * @copydoc Toolkit::StyleManager::GetStyleConstant
92    */
93   bool GetStyleConstant( const std::string& key, Property::Value& valueOut );
94
95   /**
96    * @brief Apply the theme style to a control.
97    *
98    * @param[in] control The control to apply style.
99    */
100   void ApplyThemeStyle( Toolkit::Control control );
101
102   /**
103    * @brief Apply the theme style to a control at initialization.
104    *
105    * @param[in] control The control to apply style.
106    */
107   void ApplyThemeStyleAtInit( Toolkit::Control control );
108
109   /**
110    * @copydoc Toolkit::StyleManager::ApplyStyle
111    */
112   void ApplyStyle( Toolkit::Control control, const std::string& jsonFileName, const std::string& styleName );
113
114 public:
115   // SIGNALS
116
117   /**
118    * @copydoc Toolkit::StyleManager::StyleChangeSignal
119    * This signal is sent after all the controls have been updated
120    * due to style change
121    */
122   Toolkit::StyleManager::StyleChangedSignalType& StyleChangedSignal();
123
124   /**
125    * This signal is sent to the controls following a style change.
126    * It should not be exposed in the public API
127    */
128   Toolkit::StyleManager::StyleChangedSignalType& ControlStyleChangeSignal();
129
130 private:
131   typedef std::vector<std::string> StringList;
132
133   /**
134    * @brief Set the current theme. Called only once per event processing cycle.
135    * @param[in] themeFile The name of the theme file to read.
136    */
137   void SetTheme( const std::string& themeFile );
138
139   /**
140    * @brief Internal helper method to read a file from file system.
141    * @param filename The name of the file to read.
142    * @param[out] stringOut The string to return the file in
143    *
144    * @param Return true if file was found
145    */
146   bool LoadFile(const std::string& filename, std::string& stringOut);
147
148   /**
149    * @brief Create a new builder.
150    *
151    * @param[in] constants A map of constants to be used by the builder
152    *
153    * @return Return the newly created builder
154    */
155   Toolkit::Builder CreateBuilder( const Property::Map& constants );
156
157   /**
158    * @brief Load a JSON file into given builder
159    *
160    * @param[in] builder The builder object to load the theme file
161    * @param[in] jsonFileName The name of the JSON file to load
162    * @return Return true if file was loaded
163    */
164   bool LoadJSON( Toolkit::Builder builder, const std::string& jsonFileName );
165
166   /**
167    * @brief Collect qualifiers (e.g. Landscape, portrait etc) for a given style
168    *
169    * @param[in,out] qualifiersOut The list to populate with qualifiers
170    */
171   void CollectQualifiers( StringList& qualifiersOut );
172
173   /**
174    * @brief Construct a qualified style name out of qualifiers
175    *
176    * A qualifed style name will be in the format: style-qualifier0-qualifier1-qualifierN
177    *
178    * @param[in] styleName The root name of the style
179    * @param[in] qualifiers List of qualifier names
180    * @param[out] qualifiedStyleOut The qualified style name
181    */
182   void BuildQualifiedStyleName( const std::string& styleName, const StringList& qualifiers, std::string& qualifiedStyleOut );
183
184   /**
185    * @brief Apply a style to the control using the given builder
186    *
187    * @param[in] builder The builder to apply the style from
188    * @param[in] control The control to apply the style to
189    */
190   void ApplyStyle( Toolkit::Builder builder, Toolkit::Control control );
191
192   /**
193    * Search for a builder in the cache
194    *
195    * @param[in] key The key the builder was cached under
196    * @return Return the cached builder if found or an empty builder object if not found
197    */
198   Toolkit::Builder FindCachedBuilder( const std::string& key );
199
200   /**
201    * Store a given builder in the cache keyed to the given key
202    *
203    * @param[in] builder The builder object to store
204    * @param[in] key The key to store the builder under
205    */
206   void CacheBuilder( Toolkit::Builder builder, const std::string& key );
207
208   /**
209    * Callback for when style monitor raises a signal
210    *
211    * @param[in] styleMonitor The style monitor object
212    * @param[in] styleChange The style change type
213    */
214   void StyleMonitorChange( StyleMonitor styleMonitor, StyleChange::Type styleChange );
215
216   /**
217    * Emit signals to controls first, app second
218    */
219   void EmitStyleChangeSignals( StyleChange::Type styleChange );
220
221
222   // Undefined
223   StyleManager(const StyleManager&);
224
225   StyleManager& operator=(const StyleManager& rhs);
226
227 private:
228
229   // Map to store builders keyed by JSON file name
230   typedef std::map< std::string, Toolkit::Builder > BuilderMap;
231
232   Toolkit::Builder mThemeBuilder;     ///< Builder for all default theme properties
233   StyleMonitor mStyleMonitor;         ///< Style monitor handle
234
235   int mDefaultFontSize;               ///< Logical size, not a point-size
236   std::string mDefaultFontFamily;
237   std::string mThemeFile;             ///< The full path of the current theme file
238
239   Property::Map mThemeBuilderConstants;   ///< Contants to give the theme builder
240   Property::Map mStyleBuilderConstants;   ///< Constants specific to building styles
241
242   BuilderMap mBuilderCache;           ///< Cache of builders keyed by JSON file name
243
244   Toolkit::Internal::FeedbackStyle* mFeedbackStyle; ///< Feedback style
245
246   // Signals
247   Toolkit::StyleManager::StyleChangedSignalType mControlStyleChangeSignal; ///< Emitted when the style( theme/font ) changes for the controls to style themselves
248   Toolkit::StyleManager::StyleChangedSignalType mStyleChangedSignal; ///< Emitted after the controls have been styled
249 };
250
251 } // namespace Internal
252
253 inline Internal::StyleManager& GetImpl( Dali::Toolkit::StyleManager& obj )
254 {
255   DALI_ASSERT_ALWAYS( obj );
256
257   Dali::BaseObject& handle = obj.GetBaseObject();
258
259   return static_cast< Internal::StyleManager& >( handle );
260 }
261
262 inline const Internal::StyleManager& GetImpl( const Dali::Toolkit::StyleManager& obj )
263 {
264   DALI_ASSERT_ALWAYS( obj );
265
266   const Dali::BaseObject& handle = obj.GetBaseObject();
267
268   return static_cast< const Internal::StyleManager& >( handle );
269 }
270
271 } // namespace Toolkit
272
273 } // namespace Dali
274
275 #endif // __DALI_TOOLKIT_INTERNAL_STYLE_MANAGER_H__