Merge "Fix VD prevent issues" into devel/master
[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/devel-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   /**
52    * Singleton access
53    *
54    * @return The StyleManager object
55    */
56   static Toolkit::StyleManager Get();
57
58   /**
59    * Construct a new StyleManager.
60    */
61   StyleManager();
62
63   /**
64    * @copydoc Toolkit::StyleManager::SetOrientationValue
65    */
66   void SetOrientationValue( int orientation );
67
68   /**
69    * @copydoc Toolkit::StyleManager::GetOrientationValue
70    */
71   int GetOrientationValue();
72
73   /**
74    * @copydoc Toolkit::StyleManager::SetOrientation( Orientation orientation )
75    */
76   void SetOrientation( Orientation orientation );
77
78   /**
79    * @copydoc Toolkit::StyleManager::GetOrientation
80    */
81   Orientation GetOrientation();
82
83   /**
84    * @copydoc Toolkit::StyleManager::GetDefaultFontFamily
85    */
86   std::string GetDefaultFontFamily() const;
87
88   /**
89    * @copydoc Toolkit::StyleManager::SetStyleConstant
90    */
91   void SetStyleConstant( const std::string& key, const Property::Value& value );
92
93   /**
94    * @copydoc Toolkit::StyleManager::GetStyleConstant
95    */
96   bool GetStyleConstant( const std::string& key, Property::Value& valueOut );
97
98   /**
99    * @copydoc Toolkit::StyleManager::RequestThemeChange
100    */
101   void RequestThemeChange( const std::string& themeFile );
102
103   /**
104    * @copydoc Toolkit::StyleManager::RequestDefaultTheme
105    */
106   void RequestDefaultTheme();
107
108   /**
109    * Determine if a theme change has been requested
110    * @return Whether a theme request is pending
111    */
112   bool IsThemeRequestPending();
113
114   /**
115    * @brief Apply the theme style to a control.
116    *
117    * @param[in] control The control to apply style.
118    */
119   void ApplyThemeStyle( Toolkit::Control control );
120
121   /**
122    * @brief Apply the theme style to a control at initialization.
123    *
124    * @param[in] control The control to apply style.
125    */
126   void ApplyThemeStyleAtInit( Toolkit::Control control );
127
128   /**
129    * @copydoc Toolkit::StyleManager::ApplyStyle
130    */
131   void ApplyStyle( Toolkit::Control control, const std::string& jsonFileName, const std::string& styleName );
132
133 public:
134   // SIGNALS
135
136   /**
137    * @copydoc Toolkit::StyleManager::StyleChangeSignal
138    */
139   Toolkit::StyleManager::StyleChangeSignalType& StyleChangeSignal();
140
141 protected:
142
143   /**
144    * @brief Destructor
145    */
146   virtual ~StyleManager();
147
148
149 public:
150
151   /**
152    * @brief Set the current theme. Called only once per event processing cycle.
153    */
154   void SetTheme();
155
156 private:
157
158   typedef std::vector<std::string> StringList;
159
160   /**
161    * @brief Internal helper method to read a file from file system.
162    * @param filename The name of the file to read.
163    * @param[out] stringOut The string to return the file in
164    *
165    * @param Return true if file was found
166    */
167   bool LoadFile(const std::string& filename, std::string& stringOut);
168
169   /**
170    * @brief Create a new builder.
171    *
172    * @param[in] constants A map of constants to be used by the builder
173    *
174    * @return Return the newly created builder
175    */
176   Toolkit::Builder CreateBuilder( const Property::Map& constants );
177
178   /**
179    * @brief Load a JSON file into given builder
180    *
181    * @param[in] builder The builder object to load the theme file
182    * @param[in] jsonFileName The name of the JSON file to load
183    * @return Return true if file was loaded
184    */
185   bool LoadJSON( Toolkit::Builder builder, const std::string& jsonFileName );
186
187   /**
188    * @brief Collect qualifiers (e.g. Landscape, portrait etc) for a given style
189    *
190    * @param[in,out] qualifiersOut The list to populate with qualifiers
191    */
192   void CollectQualifiers( StringList& qualifiersOut );
193
194   /**
195    * @brief Construct a qualified style name out of qualifiers
196    *
197    * A qualifed style name will be in the format: style-qualifier0-qualifier1-qualifierN
198    *
199    * @param[in] styleName The root name of the style
200    * @param[in] qualifiers List of qualifier names
201    * @param[out] qualifiedStyleOut The qualified style name
202    */
203   void BuildQualifiedStyleName( const std::string& styleName, const StringList& qualifiers, std::string& qualifiedStyleOut );
204
205   /**
206    * @brief Apply a style to the control using the given builder
207    *
208    * @param[in] builder The builder to apply the style from
209    * @param[in] control The control to apply the style to
210    */
211   void ApplyStyle( Toolkit::Builder builder, Toolkit::Control control );
212
213   /**
214    * @brief Callback for orientation changes
215    *
216    * @param[in] orientation The orientation object
217    */
218   void OnOrientationChanged( Orientation orientation );
219
220   /**
221    * Search for a builder in the cache
222    *
223    * @param[in] key The key the builder was cached under
224    * @return Return the cached builder if found or an empty builder object if not found
225    */
226   Toolkit::Builder FindCachedBuilder( const std::string& key );
227
228   /**
229    * Store a given builder in the cache keyed to the given key
230    *
231    * @param[in] builder The builder object to store
232    * @param[in] key The key to store the builder under
233    */
234   void CacheBuilder( Toolkit::Builder builder, const std::string& key );
235
236   /**
237    * Callback for when style monitor raises a signal
238    *
239    * @param[in] styleMonitor The style monitor object
240    * @param[in] styleChange The style change type
241    */
242   void StyleMonitorChange( StyleMonitor styleMonitor, StyleChange::Type styleChange );
243
244   // Undefined
245   StyleManager(const StyleManager&);
246
247   StyleManager& operator=(const StyleManager& rhs);
248
249 private:
250
251   // Map to store builders keyed by JSON file name
252   typedef std::map< std::string, Toolkit::Builder > BuilderMap;
253
254   Toolkit::Builder mThemeBuilder;     ///< Builder for all default theme properties
255   StyleMonitor mStyleMonitor;         ///< Style monitor handle
256
257   Orientation mOrientation;           ///< Handle to application orientation object
258   int mOrientationDegrees;            ///< Directly set value of orientation
259
260   int mDefaultFontSize;               ///< Logical size, not a point-size
261
262   std::string mDefaultFontFamily;
263
264   std::string mThemeFile;             ///< The full path of the current theme file
265
266   Property::Map mThemeBuilderConstants;   ///< Contants to give the theme builder
267   Property::Map mStyleBuilderConstants;   ///< Constants specific to building styles
268
269   BuilderMap mBuilderCache;           ///< Cache of builders keyed by JSON file name
270
271   Toolkit::Internal::FeedbackStyle* mFeedbackStyle; ///< Feedback style
272
273   // Signals
274   Toolkit::StyleManager::StyleChangeSignalType       mStyleChangeSignal;         ///< Emitted when the style( theme/font ) changes
275 };
276
277 } // namespace Internal
278
279 inline Internal::StyleManager& GetImpl( Dali::Toolkit::StyleManager& obj )
280 {
281   DALI_ASSERT_ALWAYS( obj );
282
283   Dali::BaseObject& handle = obj.GetBaseObject();
284
285   return static_cast< Internal::StyleManager& >( handle );
286 }
287
288 inline const Internal::StyleManager& GetImpl( const Dali::Toolkit::StyleManager& obj )
289 {
290   DALI_ASSERT_ALWAYS( obj );
291
292   const Dali::BaseObject& handle = obj.GetBaseObject();
293
294   return static_cast< const Internal::StyleManager& >( handle );
295 }
296
297 } // namespace Toolkit
298
299 } // namespace Dali
300
301 #endif // __DALI_TOOLKIT_INTERNAL_STYLE_MANAGER_H__
302