1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
21 using System.Runtime.InteropServices;
22 using Tizen.NUI.BaseComponents;
25 /// The StyleManager informs applications of the system theme change, and supports application theme change at runtime.<br>
26 /// Applies various styles to controls using the properties system.<br>
27 /// On theme change, it automatically updates all controls, then raises a event to inform the application.<br>
28 /// If the application wants to customize the theme, RequestThemeChange needs to be called.<br>
29 /// 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>
31 public class StyleManager : BaseHandle
33 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
35 internal StyleManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.StyleManager_SWIGUpcast(cPtr), cMemoryOwn)
37 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
40 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(StyleManager obj)
42 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
48 protected override void Dispose(DisposeTypes type)
55 if(type == DisposeTypes.Explicit)
58 //Release your own managed resources here.
59 //You should release all of your own disposable objects here.
62 //Release your own unmanaged resources here.
63 //You should not access any managed member here except static instance.
64 //because the execution order of Finalizes is non-deterministic.
66 if (_styleManagerStyleChangedCallbackDelegate != null)
68 StyleChangedSignal().Disconnect(_styleManagerStyleChangedCallbackDelegate);
71 if (swigCPtr.Handle != global::System.IntPtr.Zero)
76 NDalicPINVOKE.delete_StyleManager(swigCPtr);
78 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
85 /// Style changed event arguments.
87 public class StyleChangedEventArgs : EventArgs
89 private StyleManager _styleManager;
90 private StyleChangeType _styleChange;
95 public StyleManager StyleManager
103 _styleManager = value;
108 /// StyleChange - contains the style change information (default font changed or
109 /// default font size changed or theme has changed).<br>
111 public StyleChangeType StyleChange
119 _styleChange = value;
125 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
126 private delegate void StyleChangedCallbackDelegate(IntPtr styleManager, Tizen.NUI.StyleChangeType styleChange);
127 private EventHandler<StyleChangedEventArgs> _styleManagerStyleChangedEventHandler;
128 private StyleChangedCallbackDelegate _styleManagerStyleChangedCallbackDelegate;
131 /// An event for the StyleChanged signal which can be used to subscribe or unsubscribe the
132 /// event handler provided by the user.<br>
133 /// The StyleChanged signal is emitted after the style (for example, theme or font change) has changed
134 /// and the controls have been informed.<br>
136 public event EventHandler<StyleChangedEventArgs> StyleChanged
140 if (_styleManagerStyleChangedEventHandler == null)
142 _styleManagerStyleChangedCallbackDelegate = (OnStyleChanged);
143 StyleChangedSignal().Connect(_styleManagerStyleChangedCallbackDelegate);
145 _styleManagerStyleChangedEventHandler += value;
149 _styleManagerStyleChangedEventHandler -= value;
150 if (_styleManagerStyleChangedEventHandler == null && StyleChangedSignal().Empty() == false)
152 StyleChangedSignal().Disconnect(_styleManagerStyleChangedCallbackDelegate);
157 // Callback for StyleManager StyleChangedsignal
158 private void OnStyleChanged(IntPtr styleManager, StyleChangeType styleChange)
160 StyleChangedEventArgs e = new StyleChangedEventArgs();
162 // Populate all members of "e" (StyleChangedEventArgs) with real data
163 e.StyleManager = Registry.GetManagedBaseHandleFromNativePtr(styleManager) as StyleManager;
164 e.StyleChange = styleChange;
166 if (_styleManagerStyleChangedEventHandler != null)
168 //here we send all data to user event handlers
169 _styleManagerStyleChangedEventHandler(this, e);
174 /// Creates a StyleManager handle.<br>
175 /// This can be initialized with StyleManager::Get().<br>
177 public StyleManager() : this(NDalicPINVOKE.new_StyleManager(), true)
179 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183 /// Gets the singleton of StyleManager object.
185 /// <returns>A handle to the StyleManager control.</returns>
186 public static StyleManager Get()
188 StyleManager ret = new StyleManager(NDalicPINVOKE.StyleManager_Get(), true);
189 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194 /// Applies a new theme to the application.<br>
195 /// This will be merged on the top of the default Toolkit theme.<br>
196 /// If the application theme file doesn't style all controls that the
197 /// application uses, then the default Toolkit theme will be used
198 /// instead for those controls.<br>
200 /// <param name="themeFile">A relative path is specified for style theme.</param>
201 public void ApplyTheme(string themeFile)
203 NDalicPINVOKE.StyleManager_ApplyTheme(swigCPtr, themeFile);
204 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208 /// Applies the default Toolkit theme.
210 public void ApplyDefaultTheme()
212 NDalicPINVOKE.StyleManager_ApplyDefaultTheme(swigCPtr);
213 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217 /// Sets a constant for use when building styles.
219 /// <param name="key">The key of the constant.</param>
220 /// <param name="value">The value of the constant.</param>
221 public void AddConstant(string key, PropertyValue value)
223 NDalicPINVOKE.StyleManager_SetStyleConstant(swigCPtr, key, PropertyValue.getCPtr(value));
224 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228 /// Returns the style constant set for a specific key.
230 /// <param name="key">The key of the constant.</param>
231 /// <param name="valueOut">The value of the constant if it exists.</param>
232 /// <returns></returns>
233 public bool GetConstant(string key, PropertyValue valueOut)
235 bool ret = NDalicPINVOKE.StyleManager_GetStyleConstant(swigCPtr, key, PropertyValue.getCPtr(valueOut));
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241 /// Applies the specified style to the control.
243 /// <param name="control">The control to which to apply the style.</param>
244 /// <param name="jsonFileName">The name of the JSON style file to apply.</param>
245 /// <param name="styleName">The name of the style within the JSON file to apply.</param>
246 public void ApplyStyle(View control, string jsonFileName, string styleName)
248 NDalicPINVOKE.StyleManager_ApplyStyle(swigCPtr, View.getCPtr(control), jsonFileName, styleName);
249 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252 internal StyleChangedSignal StyleChangedSignal()
254 StyleChangedSignal ret = new StyleChangedSignal(NDalicPINVOKE.StyleManager_StyleChangedSignal(swigCPtr), false);
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();