Remove dependency on DLOG.
[platform/core/uifw/dali-toolkit.git] / base / 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 <list>
23
24 // INTERNAL INCLUDES
25
26 #include <dali/dali.h>
27 #include <dali-toolkit/public-api/styling/style-manager.h>
28 #include <dali-toolkit/public-api/builder/builder.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38 /**
39  * @copydoc Toolkit::StyleManager
40  */
41 class StyleManager : public Dali::BaseObject, public ConnectionTracker
42 {
43 public:
44
45   /**
46    * Singleton access
47    *
48    * @return The StyleManager object
49    */
50   static Toolkit::StyleManager Get();
51
52   /**
53    * Construct a new StyleManager.
54    */
55   StyleManager();
56
57   /**
58    * @copydoc Toolkit::StyleManager::SetOrientationValue
59    */
60   void SetOrientationValue( int orientation );
61
62   /**
63    * @copydoc Toolkit::StyleManager::GetOrientationValue
64    */
65   int GetOrientationValue();
66
67   /**
68    * @copydoc Toolkit::StyleManager::SetOrientation( Orientation orientation )
69    */
70   void SetOrientation( Orientation orientation );
71
72   /**
73    * @copydoc Toolkit::StyleManager::GetOrientation
74    */
75   Orientation GetOrientation();
76
77   /**
78    * @copydoc Toolkit::StyleManager::SetStyleConstant
79    */
80   void SetStyleConstant( const std::string& key, const Property::Value& value );
81
82   /**
83    * @copydoc Toolkit::StyleManager::GetStyleConstant
84    */
85   bool GetStyleConstant( const std::string& key, Property::Value& valueOut );
86
87   /**
88    * @copydoc Toolkit::StyleManager::RequestThemeChange
89    */
90   void RequestThemeChange( const std::string& themeFile );
91
92   /**
93    * @copydoc Toolkit::StyleManager::RequestDefaultTheme
94    */
95   void RequestDefaultTheme();
96
97   /**
98    * Determine if a theme change has been requested
99    * @return Whether a theme request is pending
100    */
101   bool IsThemeRequestPending();
102
103   /**
104    * @brief Apply the theme style to a control.
105    *
106    * @param[in] control The control to apply style.
107    */
108   void ApplyThemeStyle( Toolkit::Control control );
109
110   /**
111    * @copydoc Toolkit::StyleManager::ApplyStyle
112    */
113   void ApplyStyle( Toolkit::Control control, const std::string& jsonFileName, const std::string& styleName );
114
115 public:
116   // SIGNALS
117
118   /**
119    * @copydoc Toolkit::StyleManager::StyleChangeSignal
120    */
121   Toolkit::StyleManager::StyleChangeSignalType& StyleChangeSignal();
122
123 protected:
124
125   /**
126    * @brief Destructor
127    */
128   virtual ~StyleManager();
129
130
131 public:
132
133   /**
134    * @brief Set the current theme. Called only once per event processing cycle.
135    */
136   void SetTheme();
137
138 private:
139
140   typedef std::list<std::string> StringList;
141
142   /**
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
146    *
147    * @param Return true if file was found
148    */
149   bool LoadFile(const std::string& filename, std::string& stringOut);
150
151   /**
152    * @brief Create a new builder.
153    *
154    * @param[in] constants A map of constants to be used by the builder
155    *
156    * @return Return the newly created builder
157    */
158   Toolkit::Builder CreateBuilder( const PropertyValueMap& constants );
159
160   /**
161    * @brief Load a JSON file into given builder
162    *
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
166    */
167   bool LoadJSON( Toolkit::Builder builder, const std::string& jsonFileName );
168
169   /**
170    * @brief Collect qualifiers (e.g. Landscape, portrait etc) for a given style
171    *
172    * @param[in,out] qualifiersOut The list to populate with qualifiers
173    */
174   void CollectQualifiers( StringList& qualifiersOut );
175
176   /**
177    * @brief Construct a qualified style name out of qualifiers
178    *
179    * A qualifed style name will be in the format: style-qualifier0-qualifier1-qualifierN
180    *
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
184    */
185   void BuildQualifiedStyleName( const std::string& styleName, const StringList& qualifiers, std::string& qualifiedStyleOut );
186
187   /**
188    * @brief Apply a style to the control using the given builder
189    *
190    * @param[in] builder The builder to apply the style from
191    * @param[in] control The control to apply the style to
192    */
193   void ApplyStyle( Toolkit::Builder builder, Toolkit::Control control );
194
195   /**
196    * @brief Callback for orientation changes
197    *
198    * @param[in] orientation The orientation object
199    */
200   void OnOrientationChanged( Orientation orientation );
201
202   /**
203    * Search for a builder in the cache
204    *
205    * @param[in] key The key the builder was cached under
206    * @return Return the cached builder if found or an empty builder object if not found
207    */
208   Toolkit::Builder FindCachedBuilder( const std::string& key );
209
210   /**
211    * Store a given builder in the cache keyed to the given key
212    *
213    * @param[in] builder The builder object to store
214    * @param[in] key The key to store the builder under
215    */
216   void CacheBuilder( Toolkit::Builder builder, const std::string& key );
217
218   /**
219    * Callback for when style monitor raises a signal
220    *
221    * @param[in] styleMonitor The style monitor object
222    * @param[in] styleChange The style change data
223    */
224   void StyleMonitorChange( StyleMonitor styleMonitor, StyleChange styleChange );
225
226   // Undefined
227   StyleManager(const StyleManager&);
228
229   StyleManager& operator=(const StyleManager& rhs);
230
231 private:
232
233   // Map to store builders keyed by JSON file name
234   typedef std::map< std::string, Toolkit::Builder > BuilderMap;
235
236   Toolkit::Builder mThemeBuilder;     ///< Builder for all default theme properties
237
238   Orientation mOrientation;           ///< Handle to application orientation object
239   int mOrientationDegrees;            ///< Directly set value of orientation
240
241   std::string mThemeFile;             ///< The full path of the current theme file
242
243   Toolkit::PropertyValueMap mThemeBuilderConstants;   ///< Contants to give the theme builder
244   Toolkit::PropertyValueMap mStyleBuilderConstants;   ///< Constants specific to building styles
245
246   BuilderMap mBuilderCache;           ///< Cache of builders keyed by JSON file name
247
248   bool mSetThemeConnection;           ///< Has the callback to set the theme been set
249
250   // Signals
251   Toolkit::StyleManager::StyleChangeSignalType       mStyleChangeSignal;         ///< Emitted when the style( theme/font ) changes
252 };
253
254 } // namespace Internal
255
256 inline Internal::StyleManager& GetImpl( Dali::Toolkit::StyleManager& obj )
257 {
258   DALI_ASSERT_ALWAYS( obj );
259
260   Dali::BaseObject& handle = obj.GetBaseObject();
261
262   return static_cast< Internal::StyleManager& >( handle );
263 }
264
265 inline const Internal::StyleManager& GetImpl( const Dali::Toolkit::StyleManager& obj )
266 {
267   DALI_ASSERT_ALWAYS( obj );
268
269   const Dali::BaseObject& handle = obj.GetBaseObject();
270
271   return static_cast< const Internal::StyleManager& >( handle );
272 }
273
274 } // namespace Toolkit
275
276 } // namespace Dali
277
278 #endif // __DALI_TOOLKIT_INTERNAL_STYLE_MANAGER_H__
279