2 * Copyright(c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Runtime.InteropServices;
20 using Tizen.NUI.BaseComponents;
21 using System.ComponentModel;
26 /// The StyleManager informs applications of the system theme change, and supports application theme change at runtime.<br />
27 /// Applies various styles to controls using the properties system.<br />
28 /// On theme change, it automatically updates all controls, then raises a event to inform the application.<br />
29 /// If the application wants to customize the theme, RequestThemeChange needs to be called.<br />
30 /// It provides the path to the application resource root folder, from there the filename can be specified along with any subfolders, for example, Images, Models, etc.<br />
32 /// <since_tizen> 3 </since_tizen>
33 public class StyleManager : BaseHandle
35 private static readonly StyleManager instance = StyleManager.Get();
36 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
37 private EventHandler<StyleChangedEventArgs> _styleManagerStyleChangedEventHandler;
38 private StyleChangedCallbackDelegate _styleManagerStyleChangedCallbackDelegate;
41 /// Creates a StyleManager handle.<br />
42 /// This can be initialized with StyleManager::Get().<br />
44 /// <since_tizen> 3 </since_tizen>
45 public StyleManager() : this(Interop.StyleManager.new_StyleManager(), true)
47 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
50 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
51 private delegate void StyleChangedCallbackDelegate(IntPtr styleManager, Tizen.NUI.StyleChangeType styleChange);
54 /// An event for the StyleChanged signal which can be used to subscribe or unsubscribe the
55 /// event handler provided by the user.<br />
56 /// The StyleChanged signal is emitted after the style (for example, theme or font change) has changed
57 /// and the controls have been informed.<br />
59 /// <since_tizen> 3 </since_tizen>
60 public event EventHandler<StyleChangedEventArgs> StyleChanged
64 if (_styleManagerStyleChangedEventHandler == null)
66 _styleManagerStyleChangedCallbackDelegate = (OnStyleChanged);
67 StyleChangedSignal().Connect(_styleManagerStyleChangedCallbackDelegate);
69 _styleManagerStyleChangedEventHandler += value;
73 _styleManagerStyleChangedEventHandler -= value;
74 if (_styleManagerStyleChangedEventHandler == null && StyleChangedSignal().Empty() == false)
76 StyleChangedSignal().Disconnect(_styleManagerStyleChangedCallbackDelegate);
82 /// Gets the singleton of the StyleManager object.
84 /// <since_tizen> 5 </since_tizen>
85 public static StyleManager Instance
94 /// Gets the singleton of StyleManager object.
96 /// <returns>A handle to the StyleManager control.</returns>
97 /// <since_tizen> 3 </since_tizen>
98 public static StyleManager Get()
100 StyleManager ret = new StyleManager(Interop.StyleManager.StyleManager_Get(), true);
101 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
106 /// Applies a new theme to the application.<br />
107 /// This will be merged on the top of the default Toolkit theme.<br />
108 /// If the application theme file doesn't style all controls that the
109 /// application uses, then the default Toolkit theme will be used
110 /// instead for those controls.<br />
112 /// <param name="themeFile">A relative path is specified for style theme.</param>
113 /// <since_tizen> 3 </since_tizen>
114 public void ApplyTheme(string themeFile)
116 Interop.StyleManager.StyleManager_ApplyTheme(swigCPtr, themeFile);
117 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
121 /// Applies the default Toolkit theme.
123 /// <since_tizen> 3 </since_tizen>
124 public void ApplyDefaultTheme()
126 Interop.StyleManager.StyleManager_ApplyDefaultTheme(swigCPtr);
127 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
131 /// Sets a constant for use when building styles.
133 /// <param name="key">The key of the constant.</param>
134 /// <param name="value">The value of the constant.</param>
135 /// <since_tizen> 3 </since_tizen>
136 public void AddConstant(string key, PropertyValue value)
138 Interop.StyleManager.StyleManager_SetStyleConstant(swigCPtr, key, PropertyValue.getCPtr(value));
139 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143 /// Returns the style constant set for a specific key.
145 /// <param name="key">The key of the constant.</param>
146 /// <param name="valueOut">The value of the constant if it exists.</param>
147 /// <returns></returns>
148 /// <since_tizen> 3 </since_tizen>
149 public bool GetConstant(string key, PropertyValue valueOut)
151 bool ret = Interop.StyleManager.StyleManager_GetStyleConstant(swigCPtr, key, PropertyValue.getCPtr(valueOut));
152 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157 /// Applies the specified style to the control.
159 /// <param name="control">The control to which to apply the style.</param>
160 /// <param name="jsonFileName">The name of the JSON style file to apply.</param>
161 /// <param name="styleName">The name of the style within the JSON file to apply.</param>
162 /// <since_tizen> 3 </since_tizen>
163 public void ApplyStyle(View control, string jsonFileName, string styleName)
165 Interop.StyleManager.StyleManager_ApplyStyle(swigCPtr, View.getCPtr(control), jsonFileName, styleName);
166 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(StyleManager obj)
171 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
174 internal StyleManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.StyleManager.StyleManager_SWIGUpcast(cPtr), cMemoryOwn)
176 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
179 internal StyleChangedSignal StyleChangedSignal()
181 StyleChangedSignal ret = new StyleChangedSignal(Interop.StyleManager.StyleManager_StyleChangedSignal(swigCPtr), false);
182 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186 // Callback for StyleManager StyleChangedsignal
187 private void OnStyleChanged(IntPtr styleManager, StyleChangeType styleChange)
189 StyleChangedEventArgs e = new StyleChangedEventArgs();
191 // Populate all members of "e" (StyleChangedEventArgs) with real data.
192 e.StyleManager = Registry.GetManagedBaseHandleFromNativePtr(styleManager) as StyleManager;
193 e.StyleChange = styleChange;
195 if (_styleManagerStyleChangedEventHandler != null)
197 //Here we send all data to user event handlers.
198 _styleManagerStyleChangedEventHandler(this, e);
203 /// Style changed event arguments.
205 /// <since_tizen> 3 </since_tizen>
206 public class StyleChangedEventArgs : EventArgs
208 private StyleManager _styleManager;
209 private StyleChangeType _styleChange;
214 /// <since_tizen> 3 </since_tizen>
215 public StyleManager StyleManager
219 return _styleManager;
223 _styleManager = value;
228 /// StyleChange - contains the style change information (default font changed or
229 /// default font size changed or theme has changed).<br />
231 /// <since_tizen> 3 </since_tizen>
232 public StyleChangeType StyleChange
240 _styleChange = value;