2d790a44bd85725dad25e80b04f9cd55b9e9215c
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / styling / style-manager.h
1 #ifndef __DALI_TOOLKIT_STYLE_MANAGER_H__
2 #define __DALI_TOOLKIT_STYLE_MANAGER_H__
3
4 /*
5  * Copyright (c) 2015 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 <dali/devel-api/adaptor-framework/orientation.h>
22 #include <dali/public-api/adaptor-framework/style-change.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Internal DALI_INTERNAL
34 {
35 class StyleManager;
36 }
37
38 /**
39  * @brief StyleManager provides the following functionalities:
40  *
41  * Applies various styles to Controls using the properties system.
42  * On theme change a signal is raised that controls can be configured to listen to.
43  *
44  * The default theme is automatically loaded and applied.
45  *
46  * If the application wants to customize the theme, RequestThemeChange
47  * needs to be called.  Internal::Control can be configured to
48  * register for the signals that are required from StyleManager, such
49  * as theme change.
50  */
51 class DALI_IMPORT_API StyleManager : public BaseHandle
52 {
53 public:
54
55   // Signals
56   typedef Signal< void ( StyleManager, StyleChange::Type ) >  StyleChangedSignalType;
57
58   /**
59    * @brief Create a StyleManager handle; this can be initialised with StyleManager::Get()
60    * Calling member functions with an uninitialised handle is not allowed.
61    */
62   StyleManager();
63
64   /**
65    * @brief Destructor
66    *
67    * This is non-virtual since derived Handle types must not contain data or virtual methods.
68    */
69   ~StyleManager();
70
71   /**
72    * @brief Get the singleton of StyleManager object.
73    *
74    * @return A handle to the StyleManager control.
75    */
76   static StyleManager Get();
77
78   /**
79    * @brief Specify the orientation value directly for the style manager
80    *
81    * @param[in] orientation The orientation in degrees
82    */
83   void SetOrientationValue( int orientation );
84
85   /**
86    * @brief Return the orientation value
87    *
88    * @return The orientation value
89    */
90   int GetOrientationValue();
91
92   /**
93    * @brief Set the orientation object. This will take precedence over setting the orientation value.
94    *
95    * @param[in] orientation Device orientation
96    */
97   void SetOrientation( Orientation orientation );
98
99   /**
100    * @brief Return the orientation object
101    *
102    * @return The orientation.
103    */
104   Orientation GetOrientation();
105
106   /**
107    * @brief Retrieves the default font family.
108    * @return The default font family.
109    */
110   std::string GetDefaultFontFamily() const;
111
112   /**
113    * @brief Make a request to set the theme JSON file to one that exists in the Toolkit package.
114    *
115    * Multiple requests per event processing cycle can be made, but only the final one will be acted
116    * on in the event processing finished callback.
117    *
118    * @param[in] themeFile This is just the JSON theme file name and not the full path.
119    */
120   void RequestThemeChange( const std::string& themeFile );
121
122   /**
123    * @brief Request a change to the default theme
124    */
125   void RequestDefaultTheme();
126
127   /**
128    * @brief Set a constant for use when building styles
129    *
130    * A constant is used in JSON files e.g. "myImage":"{ROOT_PATH}/mypath/image.jpg"
131    * where the string "{ROOT_PATH}" is substituted with the value.
132    *
133    * @param[in] key The key of the constant
134    * @param[in] value The value of the constant
135    */
136   void SetStyleConstant( const std::string& key, const Property::Value& value );
137
138   /**
139    * @brief Return the style constant set for a specific key
140    *
141    * @param[in] key The key of the constant
142    * @param[out] valueOut The value of the constant if it exists
143    *
144    * @return If the constant for key exists then return the constant in valueOut and return true
145    */
146   bool GetStyleConstant( const std::string& key, Property::Value& valueOut );
147
148   /**
149    * @brief Apply the specified style to the control.
150    *
151    * The JSON file will be cached and subsequent calls using the same JSON file name will
152    * use the already loaded cached values instead.
153    *
154    * @param[in] control The control to apply style.
155    * @param[in] jsonFileName The name of the JSON style file to apply.
156    * @param[in] styleName The name of the style within the JSON file to apply.
157    */
158   void ApplyStyle( Toolkit::Control control, const std::string& jsonFileName, const std::string& styleName );
159
160 public: // Signals
161
162   /**
163    * @brief This signal is emitted after the style (e.g. theme/font change) has changed
164    * and the controls have been informed.
165    *
166    * A callback of the following type may be connected:
167    * @code
168    *   void YourCallbackName( StyleManager styleManager, StyleChange change );
169    * @endcode
170    * @return The signal to connect to.
171    */
172   StyleChangedSignalType& StyleChangedSignal();
173
174 public:
175
176   /**
177    * @brief Creates a new handle from the implementation.
178    *
179    * @param[in] impl A pointer to the object.
180    */
181   explicit DALI_INTERNAL StyleManager( Internal::StyleManager *impl );
182
183 }; // class StyleManager
184
185 } // namespace Toolkit
186
187 } // namespace Dali
188
189
190 #endif /* __DALI_TOOLKIT_STYLE_MANAGER_H__ */