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 EventHandler<StyleChangedEventArgs> _styleManagerStyleChangedEventHandler;
37 private StyleChangedCallbackDelegate _styleManagerStyleChangedCallbackDelegate;
40 /// Creates a StyleManager handle.<br />
41 /// This can be initialized with StyleManager::Get().<br />
43 /// <since_tizen> 3 </since_tizen>
44 public StyleManager() : this(Interop.StyleManager.NewStyleManager(), true)
46 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
49 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
50 private delegate void StyleChangedCallbackDelegate(IntPtr styleManager, Tizen.NUI.StyleChangeType styleChange);
53 /// An event for the StyleChanged signal which can be used to subscribe or unsubscribe the
54 /// event handler provided by the user.<br />
55 /// The StyleChanged signal is emitted after the style (for example, theme or font change) has changed
56 /// and the controls have been informed.<br />
58 /// <since_tizen> 3 </since_tizen>
59 public event EventHandler<StyleChangedEventArgs> StyleChanged
63 if (_styleManagerStyleChangedEventHandler == null)
65 _styleManagerStyleChangedCallbackDelegate = (OnStyleChanged);
66 StyleChangedSignal().Connect(_styleManagerStyleChangedCallbackDelegate);
68 _styleManagerStyleChangedEventHandler += value;
72 _styleManagerStyleChangedEventHandler -= value;
73 if (_styleManagerStyleChangedEventHandler == null && StyleChangedSignal().Empty() == false)
75 StyleChangedSignal().Disconnect(_styleManagerStyleChangedCallbackDelegate);
81 /// Gets the singleton of the StyleManager object.
83 /// <since_tizen> 5 </since_tizen>
84 public static StyleManager Instance
93 /// Gets the singleton of StyleManager object.
95 /// <returns>A handle to the StyleManager control.</returns>
96 /// <since_tizen> 3 </since_tizen>
97 public static StyleManager Get()
99 StyleManager ret = new StyleManager(Interop.StyleManager.Get(), true);
100 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
105 /// Applies a new theme to the application.<br />
106 /// This will be merged on the top of the default Toolkit theme.<br />
107 /// If the application theme file doesn't style all controls that the
108 /// application uses, then the default Toolkit theme will be used
109 /// instead for those controls.<br />
111 /// <param name="themeFile">A relative path is specified for style theme.</param>
112 /// <since_tizen> 3 </since_tizen>
113 public void ApplyTheme(string themeFile)
115 Interop.StyleManager.ApplyTheme(SwigCPtr, themeFile);
116 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
120 /// Applies the default Toolkit theme.
122 /// <since_tizen> 3 </since_tizen>
123 public void ApplyDefaultTheme()
125 Interop.StyleManager.ApplyDefaultTheme(SwigCPtr);
126 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
130 /// Sets a constant for use when building styles.
132 /// <param name="key">The key of the constant.</param>
133 /// <param name="value">The value of the constant.</param>
134 /// <since_tizen> 3 </since_tizen>
135 public void AddConstant(string key, PropertyValue value)
137 Interop.StyleManager.SetStyleConstant(SwigCPtr, key, PropertyValue.getCPtr(value));
138 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
142 /// Returns the style constant set for a specific key.
144 /// <param name="key">The key of the constant.</param>
145 /// <param name="valueOut">The value of the constant if it exists.</param>
146 /// <returns></returns>
147 /// <since_tizen> 3 </since_tizen>
148 public bool GetConstant(string key, PropertyValue valueOut)
150 bool ret = Interop.StyleManager.GetStyleConstant(SwigCPtr, key, PropertyValue.getCPtr(valueOut));
151 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
156 /// Applies the specified style to the control.
158 /// <param name="control">The control to which to apply the style.</param>
159 /// <param name="jsonFileName">The name of the JSON style file to apply.</param>
160 /// <param name="styleName">The name of the style within the JSON file to apply.</param>
161 /// <since_tizen> 3 </since_tizen>
162 public void ApplyStyle(View control, string jsonFileName, string styleName)
164 Interop.StyleManager.ApplyStyle(SwigCPtr, View.getCPtr(control), jsonFileName, styleName);
165 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(StyleManager obj)
170 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
173 internal StyleManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
177 internal StyleChangedSignal StyleChangedSignal()
179 StyleChangedSignal ret = new StyleChangedSignal(Interop.StyleManager.StyleChangedSignal(SwigCPtr), false);
180 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184 // Callback for StyleManager StyleChangedsignal
185 private void OnStyleChanged(IntPtr styleManager, StyleChangeType styleChange)
187 StyleChangedEventArgs e = new StyleChangedEventArgs();
189 // Populate all members of "e" (StyleChangedEventArgs) with real data.
190 e.StyleManager = Registry.GetManagedBaseHandleFromNativePtr(styleManager) as StyleManager;
191 e.StyleChange = styleChange;
193 if (_styleManagerStyleChangedEventHandler != null)
195 //Here we send all data to user event handlers.
196 _styleManagerStyleChangedEventHandler(this, e);
201 /// Style changed event arguments.
203 /// <since_tizen> 3 </since_tizen>
204 public class StyleChangedEventArgs : EventArgs
206 private StyleManager _styleManager;
207 private StyleChangeType _styleChange;
212 /// <since_tizen> 3 </since_tizen>
213 public StyleManager StyleManager
217 return _styleManager;
221 _styleManager = value;
226 /// StyleChange - contains the style change information (default font changed or
227 /// default font size changed or theme has changed).<br />
229 /// <since_tizen> 3 </since_tizen>
230 public StyleChangeType StyleChange
238 _styleChange = value;