/* * Copyright(c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ namespace Tizen.NUI { using System; using System.Runtime.InteropServices; using Tizen.NUI.BaseComponents; /// /// The StyleManager informs applications of the system theme change, and supports application theme change at runtime.
/// Applies various styles to controls using the properties system.
/// On theme change, it automatically updates all controls, then raises a event to inform the application.
/// If the application wants to customize the theme, RequestThemeChange needs to be called.
/// 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.
///
public class StyleManager : BaseHandle { private global::System.Runtime.InteropServices.HandleRef swigCPtr; internal StyleManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.StyleManager_SWIGUpcast(cPtr), cMemoryOwn) { swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); } internal static global::System.Runtime.InteropServices.HandleRef getCPtr(StyleManager obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } /// /// Dispose. /// protected override void Dispose(DisposeTypes type) { if(disposed) { return; } if(type == DisposeTypes.Explicit) { //Called by User //Release your own managed resources here. //You should release all of your own disposable objects here. } //Release your own unmanaged resources here. //You should not access any managed member here except static instance. //because the execution order of Finalizes is non-deterministic. if (_styleManagerStyleChangedCallbackDelegate != null) { StyleChangedSignal().Disconnect(_styleManagerStyleChangedCallbackDelegate); } if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwn) { swigCMemOwn = false; NDalicPINVOKE.delete_StyleManager(swigCPtr); } swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } base.Dispose(type); } /// /// Style changed event arguments. /// public class StyleChangedEventArgs : EventArgs { private StyleManager _styleManager; private StyleChangeType _styleChange; /// /// StyleManager. /// /// 3 public StyleManager StyleManager { get { return _styleManager; } set { _styleManager = value; } } /// /// StyleChange - contains the style change information (default font changed or /// default font size changed or theme has changed).
///
/// 3 public StyleChangeType StyleChange { get { return _styleChange; } set { _styleChange = value; } } } [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void StyleChangedCallbackDelegate(IntPtr styleManager, Tizen.NUI.StyleChangeType styleChange); private EventHandler _styleManagerStyleChangedEventHandler; private StyleChangedCallbackDelegate _styleManagerStyleChangedCallbackDelegate; /// /// An event for the StyleChanged signal which can be used to subscribe or unsubscribe the /// event handler provided by the user.
/// The StyleChanged signal is emitted after the style (for example, theme or font change) has changed /// and the controls have been informed.
///
/// 3 public event EventHandler StyleChanged { add { if (_styleManagerStyleChangedEventHandler == null) { _styleManagerStyleChangedCallbackDelegate = (OnStyleChanged); StyleChangedSignal().Connect(_styleManagerStyleChangedCallbackDelegate); } _styleManagerStyleChangedEventHandler += value; } remove { _styleManagerStyleChangedEventHandler -= value; if (_styleManagerStyleChangedEventHandler == null && StyleChangedSignal().Empty() == false) { StyleChangedSignal().Disconnect(_styleManagerStyleChangedCallbackDelegate); } } } // Callback for StyleManager StyleChangedsignal private void OnStyleChanged(IntPtr styleManager, StyleChangeType styleChange) { StyleChangedEventArgs e = new StyleChangedEventArgs(); // Populate all members of "e" (StyleChangedEventArgs) with real data e.StyleManager = Registry.GetManagedBaseHandleFromNativePtr(styleManager) as StyleManager; e.StyleChange = styleChange; if (_styleManagerStyleChangedEventHandler != null) { //here we send all data to user event handlers _styleManagerStyleChangedEventHandler(this, e); } } /// /// Creates a StyleManager handle.
/// This can be initialized with StyleManager::Get().
///
/// 3 public StyleManager() : this(NDalicPINVOKE.new_StyleManager(), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Gets the singleton of StyleManager object. /// /// A handle to the StyleManager control. /// 3 public static StyleManager Get() { StyleManager ret = new StyleManager(NDalicPINVOKE.StyleManager_Get(), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Applies a new theme to the application.
/// This will be merged on the top of the default Toolkit theme.
/// If the application theme file doesn't style all controls that the /// application uses, then the default Toolkit theme will be used /// instead for those controls.
///
/// A relative path is specified for style theme. /// 3 public void ApplyTheme(string themeFile) { NDalicPINVOKE.StyleManager_ApplyTheme(swigCPtr, themeFile); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Applies the default Toolkit theme. /// /// 3 public void ApplyDefaultTheme() { NDalicPINVOKE.StyleManager_ApplyDefaultTheme(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Sets a constant for use when building styles. /// /// The key of the constant. /// The value of the constant. /// 3 public void AddConstant(string key, PropertyValue value) { NDalicPINVOKE.StyleManager_SetStyleConstant(swigCPtr, key, PropertyValue.getCPtr(value)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Returns the style constant set for a specific key. /// /// The key of the constant. /// The value of the constant if it exists. /// /// 3 public bool GetConstant(string key, PropertyValue valueOut) { bool ret = NDalicPINVOKE.StyleManager_GetStyleConstant(swigCPtr, key, PropertyValue.getCPtr(valueOut)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Applies the specified style to the control. /// /// The control to which to apply the style. /// The name of the JSON style file to apply. /// The name of the style within the JSON file to apply. /// 3 public void ApplyStyle(View control, string jsonFileName, string styleName) { NDalicPINVOKE.StyleManager_ApplyStyle(swigCPtr, View.getCPtr(control), jsonFileName, styleName); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal StyleChangedSignal StyleChangedSignal() { StyleChangedSignal ret = new StyleChangedSignal(NDalicPINVOKE.StyleManager_StyleChangedSignal(swigCPtr), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } } }