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