/* * 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. * */ using System; using System.Runtime.InteropServices; using Tizen.NUI.BaseComponents; using System.ComponentModel; namespace Tizen.NUI { /// /// 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.
///
/// 3 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")] public class StyleManager : BaseHandle { private static readonly StyleManager instance = StyleManager.Get(); private EventHandler styleManagerStyleChangedEventHandler; private StyleChangedCallbackDelegate styleManagerStyleChangedCallbackDelegate; /// /// Creates a StyleManager handle.
/// This can be initialized with StyleManager::Get().
///
/// 3 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")] public StyleManager() : this(Interop.StyleManager.NewStyleManager(), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void StyleChangedCallbackDelegate(IntPtr styleManager, Tizen.NUI.StyleChangeType styleChange); /// /// 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 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")] 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); } } } /// /// Gets the singleton of the StyleManager object. /// /// 5 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")] public static StyleManager Instance { get { return instance; } } /// /// Gets the singleton of StyleManager object. /// /// A handle to the StyleManager control. /// 3 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")] public static StyleManager Get() { StyleManager ret = new StyleManager(Interop.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 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")] public void ApplyTheme(string themeFile) { Interop.StyleManager.ApplyTheme(SwigCPtr, themeFile); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Applies the default Toolkit theme. /// /// 3 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")] public void ApplyDefaultTheme() { Interop.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 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")] public void AddConstant(string key, PropertyValue value) { Interop.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 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")] public bool GetConstant(string key, PropertyValue valueOut) { bool ret = Interop.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 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")] public void ApplyStyle(View control, string jsonFileName, string styleName) { Interop.StyleManager.ApplyStyle(SwigCPtr, View.getCPtr(control), jsonFileName, styleName); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// The Type of BrokenImage /// internal enum BrokenImageType { Small = 0, Normal = 1, Large = 2 } /// /// Sets the broken image url. /// The broken image is the image to show when image loading is failed. /// When the broken image and type are set in the Application, /// the proper brokenImage is set automatically considering the size of view and the size of the brokenImage. /// This Api is used from theme manager. /// /// The type for brokenImage /// The url for brokenImage internal void SetBrokenImageUrl(BrokenImageType type, string url) { Interop.StyleManager.SetBrokenImageUrl(SwigCPtr, (uint)type, url); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Gets the broken image url /// /// The type for brokenImage /// the url for brokenImage internal string GetBrokenImageUrl(BrokenImageType type) { string ret = Interop.StyleManager.GetBrokenImageUrl(SwigCPtr, (uint)type); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } internal StyleManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) { } internal StyleChangedSignal StyleChangedSignal() { StyleChangedSignal ret = new StyleChangedSignal(Interop.StyleManager.StyleChangedSignal(SwigCPtr), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } // Callback for StyleManager StyleChangedsignal private void OnStyleChanged(IntPtr styleManager, StyleChangeType styleChange) { if (styleManagerStyleChangedEventHandler != null) { StyleChangedEventArgs e = new StyleChangedEventArgs(); // Populate all members of "e" (StyleChangedEventArgs) with real data. e.StyleManager = Registry.GetManagedBaseHandleFromNativePtr(styleManager) as StyleManager; e.StyleChange = styleChange; //Here we send all data to user event handlers. styleManagerStyleChangedEventHandler(this, e); } } /// /// Style changed event arguments. /// /// 3 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")] public class StyleChangedEventArgs : EventArgs { private StyleManager styleManager; private StyleChangeType styleChange; /// /// StyleManager. /// /// 3 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")] 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 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")] public StyleChangeType StyleChange { get { return styleChange; } set { styleChange = value; } } } internal static void SetBrokenImage(BrokenImageType type, string url) { Interop.StyleManager.SetBrokenImageUrl(Instance.SwigCPtr, (uint)type, url); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal static string GetBrokenImageURL(BrokenImageType type) { string ret = Interop.StyleManager.GetBrokenImageUrl(Instance.SwigCPtr, (uint)type); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } } }