1 #ifndef __DALI_TOOLKIT_STYLE_MANAGER_H__
2 #define __DALI_TOOLKIT_STYLE_MANAGER_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/adaptor-framework/orientation.h>
22 #include <dali/public-api/adaptor-framework/style-change.h>
25 #include <dali-toolkit/public-api/controls/control.h>
33 namespace Internal DALI_INTERNAL
39 * @brief StyleManager provides the following functionalities:
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.
44 * The default theme is automatically loaded and applied.
46 * If the application wants to customize the theme, RequestThemeChange needs to be called.
47 * Also, the default orientation is Portrait, if the application wants to adapt to the orientation change, call SetOrientation or SetOrienationValue.
49 * const char* CUSTOM_THEME = DALI_SCRIPT_DIR "tizen-dark-theme.json";
51 * void OnInit(Application& app)
53 * Toolkit::StyleManager::Get().RequestThemeChange( CUSTOM_THEME );
54 * Toolkit::StyleManager::Get().SetOrientation( app.GetOrientation() );
59 * Internal::Control can be configured to register for the signals that are required from StyleManager,
60 * such as theme change.
62 class DALI_IMPORT_API StyleManager : public BaseHandle
67 typedef Signal< void ( StyleManager, StyleChange ) > StyleChangeSignalType;
70 * @brief Create a StyleManager handle; this can be initialised with StyleManager::Get()
71 * Calling member functions with an uninitialised handle is not allowed.
78 * This is non-virtual since derived Handle types must not contain data or virtual methods.
83 * @brief Get the singleton of StyleManager object.
85 * @return A handle to the StyleManager control.
87 static StyleManager Get();
90 * @brief Specify the orientation value directly for the style manager
92 * @param[in] orientation The orientation in degrees
94 void SetOrientationValue( int orientation );
97 * @brief Return the orientation value
99 * @return The orientation value
101 int GetOrientationValue();
104 * @brief Set the orientation object. This will take precedence over setting the orientation value.
106 * @param[in] orientation Device orientation
108 void SetOrientation( Orientation orientation );
111 * @brief Return the orientation object
113 * @return The orientation.
115 Orientation GetOrientation();
118 * @brief Make a request to set the theme JSON file to one that exists in the Toolkit package.
120 * Multiple requests per event processing cycle can be made, but only the final one will be acted
121 * on in the event processing finished callback.
123 * @param[in] themeFile This is just the JSON theme file name and not the full path.
125 void RequestThemeChange( const std::string& themeFile );
128 * @brief Request a change to the default theme
130 void RequestDefaultTheme();
133 * @brief Set a constant for use when building styles
135 * A constant is used in JSON files e.g. "my-image":"{ROOT_PATH}/mypath/image.jpg"
136 * where the string "{ROOT_PATH}" is substituted with the value.
138 * @param[in] key The key of the constant
139 * @param[in] value The value of the constant
141 void SetStyleConstant( const std::string& key, const Property::Value& value );
144 * @brief Return the style constant set for a specific key
146 * @param[in] key The key of the constant
147 * @param[out] valueOut The value of the constant if it exists
149 * @return If the constant for key exists then return the constant in valueOut and return true
151 bool GetStyleConstant( const std::string& key, Property::Value& valueOut );
154 * @brief Apply the specified style to the control.
156 * The JSON file will be cached and subsequent calls using the same JSON file name will
157 * use the already loaded cached values instead.
159 * @param[in] control The control to apply style.
160 * @param[in] jsonFileName The name of the JSON style file to apply.
161 * @param[in] styleName The name of the style within the JSON file to apply.
163 void ApplyStyle( Toolkit::Control control, const std::string& jsonFileName, const std::string& styleName );
168 * @brief This signal is emitted whenever the style (e.g. theme/font change) is changed on device
169 * A callback of the following type may be connected:
171 * void YourCallbackName( StyleManager styleManager, StyleChange change );
173 * @return The signal to connect to.
175 StyleChangeSignalType& StyleChangeSignal();
180 * @brief Creates a new handle from the implementation.
182 * @param[in] impl A pointer to the object.
184 explicit DALI_INTERNAL StyleManager( Internal::StyleManager *impl );
186 }; // class StyleManager
188 } // namespace Toolkit
193 #endif /* __DALI_TOOLKIT_STYLE_MANAGER_H__ */