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.
22 using System.Runtime.InteropServices;
23 using Tizen.NUI.BaseComponents;
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 public class StyleManager : BaseHandle
34 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
36 internal StyleManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.StyleManager_SWIGUpcast(cPtr), cMemoryOwn)
38 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
41 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(StyleManager obj)
43 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
49 protected override void Dispose(DisposeTypes type)
56 if(type == DisposeTypes.Explicit)
59 //Release your own managed resources here.
60 //You should release all of your own disposable objects here.
63 //Release your own unmanaged resources here.
64 //You should not access any managed member here except static instance.
65 //because the execution order of Finalizes is non-deterministic.
67 if (_styleManagerStyleChangedCallbackDelegate != null)
69 StyleChangedSignal().Disconnect(_styleManagerStyleChangedCallbackDelegate);
72 if (swigCPtr.Handle != global::System.IntPtr.Zero)
77 NDalicPINVOKE.delete_StyleManager(swigCPtr);
79 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
86 /// Style changed event arguments.
88 public class StyleChangedEventArgs : EventArgs
90 private StyleManager _styleManager;
91 private StyleChangeType _styleChange;
96 /// <since_tizen> 3 </since_tizen>
97 public StyleManager StyleManager
101 return _styleManager;
105 _styleManager = value;
110 /// StyleChange - contains the style change information (default font changed or
111 /// default font size changed or theme has changed).<br />
113 /// <since_tizen> 3 </since_tizen>
114 public StyleChangeType StyleChange
122 _styleChange = value;
128 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
129 private delegate void StyleChangedCallbackDelegate(IntPtr styleManager, Tizen.NUI.StyleChangeType styleChange);
130 private EventHandler<StyleChangedEventArgs> _styleManagerStyleChangedEventHandler;
131 private StyleChangedCallbackDelegate _styleManagerStyleChangedCallbackDelegate;
134 /// An event for the StyleChanged signal which can be used to subscribe or unsubscribe the
135 /// event handler provided by the user.<br />
136 /// The StyleChanged signal is emitted after the style (for example, theme or font change) has changed
137 /// and the controls have been informed.<br />
139 /// <since_tizen> 3 </since_tizen>
140 public event EventHandler<StyleChangedEventArgs> StyleChanged
144 if (_styleManagerStyleChangedEventHandler == null)
146 _styleManagerStyleChangedCallbackDelegate = (OnStyleChanged);
147 StyleChangedSignal().Connect(_styleManagerStyleChangedCallbackDelegate);
149 _styleManagerStyleChangedEventHandler += value;
153 _styleManagerStyleChangedEventHandler -= value;
154 if (_styleManagerStyleChangedEventHandler == null && StyleChangedSignal().Empty() == false)
156 StyleChangedSignal().Disconnect(_styleManagerStyleChangedCallbackDelegate);
161 // Callback for StyleManager StyleChangedsignal
162 private void OnStyleChanged(IntPtr styleManager, StyleChangeType styleChange)
164 StyleChangedEventArgs e = new StyleChangedEventArgs();
166 // Populate all members of "e" (StyleChangedEventArgs) with real data
167 e.StyleManager = Registry.GetManagedBaseHandleFromNativePtr(styleManager) as StyleManager;
168 e.StyleChange = styleChange;
170 if (_styleManagerStyleChangedEventHandler != null)
172 //here we send all data to user event handlers
173 _styleManagerStyleChangedEventHandler(this, e);
178 /// Creates a StyleManager handle.<br />
179 /// This can be initialized with StyleManager::Get().<br />
181 /// <since_tizen> 3 </since_tizen>
182 public StyleManager() : this(NDalicPINVOKE.new_StyleManager(), true)
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188 /// Gets the singleton of StyleManager object.
190 /// <returns>A handle to the StyleManager control.</returns>
191 /// <since_tizen> 3 </since_tizen>
192 public static StyleManager Get()
194 StyleManager ret = new StyleManager(NDalicPINVOKE.StyleManager_Get(), true);
195 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
200 /// Applies a new theme to the application.<br />
201 /// This will be merged on the top of the default Toolkit theme.<br />
202 /// If the application theme file doesn't style all controls that the
203 /// application uses, then the default Toolkit theme will be used
204 /// instead for those controls.<br />
206 /// <param name="themeFile">A relative path is specified for style theme.</param>
207 /// <since_tizen> 3 </since_tizen>
208 public void ApplyTheme(string themeFile)
210 NDalicPINVOKE.StyleManager_ApplyTheme(swigCPtr, themeFile);
211 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215 /// Applies the default Toolkit theme.
217 /// <since_tizen> 3 </since_tizen>
218 public void ApplyDefaultTheme()
220 NDalicPINVOKE.StyleManager_ApplyDefaultTheme(swigCPtr);
221 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
225 /// Sets a constant for use when building styles.
227 /// <param name="key">The key of the constant.</param>
228 /// <param name="value">The value of the constant.</param>
229 /// <since_tizen> 3 </since_tizen>
230 public void AddConstant(string key, PropertyValue value)
232 NDalicPINVOKE.StyleManager_SetStyleConstant(swigCPtr, key, PropertyValue.getCPtr(value));
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237 /// Returns the style constant set for a specific key.
239 /// <param name="key">The key of the constant.</param>
240 /// <param name="valueOut">The value of the constant if it exists.</param>
241 /// <returns></returns>
242 /// <since_tizen> 3 </since_tizen>
243 public bool GetConstant(string key, PropertyValue valueOut)
245 bool ret = NDalicPINVOKE.StyleManager_GetStyleConstant(swigCPtr, key, PropertyValue.getCPtr(valueOut));
246 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251 /// Applies the specified style to the control.
253 /// <param name="control">The control to which to apply the style.</param>
254 /// <param name="jsonFileName">The name of the JSON style file to apply.</param>
255 /// <param name="styleName">The name of the style within the JSON file to apply.</param>
256 /// <since_tizen> 3 </since_tizen>
257 public void ApplyStyle(View control, string jsonFileName, string styleName)
259 NDalicPINVOKE.StyleManager_ApplyStyle(swigCPtr, View.getCPtr(control), jsonFileName, styleName);
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263 internal StyleChangedSignal StyleChangedSignal()
265 StyleChangedSignal ret = new StyleChangedSignal(NDalicPINVOKE.StyleManager_StyleChangedSignal(swigCPtr), false);
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();