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 /// StyleManager informs applications of 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 an be specified along with any sub folders, e.g 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 (swigCPtr.Handle != global::System.IntPtr.Zero)
71 NDalicPINVOKE.delete_StyleManager(swigCPtr);
73 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
80 /// Style changed event arguments
82 public class StyleChangedEventArgs : EventArgs
84 private StyleManager _styleManager;
85 private StyleChangeType _styleChange;
90 public StyleManager StyleManager
98 _styleManager = value;
103 /// StyleChange - contains Style change information (default font changed or
104 /// default font size changed or theme has changed).<br>
106 public StyleChangeType StyleChange
114 _styleChange = value;
120 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
121 private delegate void StyleChangedCallbackDelegate(IntPtr styleManager, Tizen.NUI.StyleChangeType styleChange);
122 private EventHandler<StyleChangedEventArgs> _styleManagerStyleChangedEventHandler;
123 private StyleChangedCallbackDelegate _styleManagerStyleChangedCallbackDelegate;
126 /// Event for StyleChanged signal which can be used to subscribe/unsubscribe the
127 /// event handler provided by the user.<br>
128 /// StyleChanged signal is is emitted after the style (e.g. theme/font change) has changed
129 /// and the controls have been informed.<br>
131 public event EventHandler<StyleChangedEventArgs> StyleChanged
135 if (_styleManagerStyleChangedEventHandler == null)
137 _styleManagerStyleChangedCallbackDelegate = (OnStyleChanged);
138 StyleChangedSignal().Connect(_styleManagerStyleChangedCallbackDelegate);
140 _styleManagerStyleChangedEventHandler += value;
144 _styleManagerStyleChangedEventHandler -= value;
145 if (_styleManagerStyleChangedEventHandler == null && StyleChangedSignal().Empty() == false)
147 StyleChangedSignal().Disconnect(_styleManagerStyleChangedCallbackDelegate);
152 // Callback for StyleManager StyleChangedsignal
153 private void OnStyleChanged(IntPtr styleManager, StyleChangeType styleChange)
155 StyleChangedEventArgs e = new StyleChangedEventArgs();
157 // Populate all members of "e" (StyleChangedEventArgs) with real data
158 e.StyleManager = Registry.GetManagedBaseHandleFromNativePtr(styleManager) as StyleManager;
159 e.StyleChange = styleChange;
161 if (_styleManagerStyleChangedEventHandler != null)
163 //here we send all data to user event handlers
164 _styleManagerStyleChangedEventHandler(this, e);
169 /// Creates a StyleManager handle.<br>
170 /// this can be initialized with StyleManager::Get().<br>
172 public StyleManager() : this(NDalicPINVOKE.new_StyleManager(), true)
174 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
178 /// Gets the singleton of StyleManager object.
180 /// <returns>A handle to the StyleManager control</returns>
181 public static StyleManager Get()
183 StyleManager ret = new StyleManager(NDalicPINVOKE.StyleManager_Get(), true);
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189 /// Applies a new theme to the application. <br>
190 /// This will be merged on top of the default Toolkit theme.<br>
191 /// If the application theme file doesn't style all controls that the
192 /// application uses, then the default Toolkit theme will be used
193 /// instead for those controls.<br>
195 /// <param name="themeFile">A relative path is specified for style theme</param>
196 public void ApplyTheme(string themeFile)
198 NDalicPINVOKE.StyleManager_ApplyTheme(swigCPtr, themeFile);
199 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203 /// Applies the default Toolkit theme.
205 public void ApplyDefaultTheme()
207 NDalicPINVOKE.StyleManager_ApplyDefaultTheme(swigCPtr);
208 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
212 /// Sets a constant for use when building styles.
214 /// <param name="key">The key of the constant</param>
215 /// <param name="value">The value of the constant</param>
216 public void AddConstant(string key, PropertyValue value)
218 NDalicPINVOKE.StyleManager_SetStyleConstant(swigCPtr, key, PropertyValue.getCPtr(value));
219 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223 /// Returns the style constant set for a specific key.
225 /// <param name="key">The key of the constant</param>
226 /// <param name="valueOut">The value of the constant if it exists</param>
227 /// <returns></returns>
228 public bool GetConstant(string key, PropertyValue valueOut)
230 bool ret = NDalicPINVOKE.StyleManager_GetStyleConstant(swigCPtr, key, PropertyValue.getCPtr(valueOut));
231 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236 /// Applies the specified style to the control.
238 /// <param name="control">The control to which to apply the style</param>
239 /// <param name="jsonFileName">The name of the JSON style file to apply</param>
240 /// <param name="styleName">The name of the style within the JSON file to apply</param>
241 public void ApplyStyle(View control, string jsonFileName, string styleName)
243 NDalicPINVOKE.StyleManager_ApplyStyle(swigCPtr, View.getCPtr(control), jsonFileName, styleName);
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247 internal StyleChangedSignal StyleChangedSignal()
249 StyleChangedSignal ret = new StyleChangedSignal(NDalicPINVOKE.StyleManager_StyleChangedSignal(swigCPtr), false);
250 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();