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.
19 using System.Runtime.InteropServices;
20 using Tizen.NUI.BaseComponents;
21 using System.ComponentModel;
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 /// <since_tizen> 3 </since_tizen>
33 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
34 public class StyleManager : BaseHandle
36 private static readonly StyleManager instance = StyleManager.Get();
37 private EventHandler<StyleChangedEventArgs> styleManagerStyleChangedEventHandler;
38 private StyleChangedCallbackDelegate styleManagerStyleChangedCallbackDelegate;
41 /// Creates a StyleManager handle.<br />
42 /// This can be initialized with StyleManager::Get().<br />
44 /// <since_tizen> 3 </since_tizen>
45 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
46 public StyleManager() : this(Interop.StyleManager.NewStyleManager(), true)
48 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
51 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
52 private delegate void StyleChangedCallbackDelegate(IntPtr styleManager, Tizen.NUI.StyleChangeType styleChange);
55 /// An event for the StyleChanged signal which can be used to subscribe or unsubscribe the
56 /// event handler provided by the user.<br />
57 /// The StyleChanged signal is emitted after the style (for example, theme or font change) has changed
58 /// and the controls have been informed.<br />
60 /// <since_tizen> 3 </since_tizen>
61 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
62 public event EventHandler<StyleChangedEventArgs> StyleChanged
66 if (styleManagerStyleChangedEventHandler == null)
68 styleManagerStyleChangedCallbackDelegate = (OnStyleChanged);
69 StyleChangedSignal().Connect(styleManagerStyleChangedCallbackDelegate);
71 styleManagerStyleChangedEventHandler += value;
75 styleManagerStyleChangedEventHandler -= value;
76 if (styleManagerStyleChangedEventHandler == null && StyleChangedSignal().Empty() == false)
78 StyleChangedSignal().Disconnect(styleManagerStyleChangedCallbackDelegate);
84 /// Gets the singleton of the StyleManager object.
86 /// <since_tizen> 5 </since_tizen>
87 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
88 public static StyleManager Instance
97 /// Gets the singleton of StyleManager object.
99 /// <returns>A handle to the StyleManager control.</returns>
100 /// <since_tizen> 3 </since_tizen>
101 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
102 public static StyleManager Get()
104 StyleManager ret = new StyleManager(Interop.StyleManager.Get(), true);
105 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110 /// Applies a new theme to the application.<br />
111 /// This will be merged on the top of the default Toolkit theme.<br />
112 /// If the application theme file doesn't style all controls that the
113 /// application uses, then the default Toolkit theme will be used
114 /// instead for those controls.<br />
116 /// <param name="themeFile">A relative path is specified for style theme.</param>
117 /// <since_tizen> 3 </since_tizen>
118 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
119 public void ApplyTheme(string themeFile)
121 Interop.StyleManager.ApplyTheme(SwigCPtr, themeFile);
122 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
126 /// Applies the default Toolkit theme.
128 /// <since_tizen> 3 </since_tizen>
129 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
130 public void ApplyDefaultTheme()
132 Interop.StyleManager.ApplyDefaultTheme(SwigCPtr);
133 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137 /// Sets a constant for use when building styles.
139 /// <param name="key">The key of the constant.</param>
140 /// <param name="value">The value of the constant.</param>
141 /// <since_tizen> 3 </since_tizen>
142 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
143 public void AddConstant(string key, PropertyValue value)
145 Interop.StyleManager.SetStyleConstant(SwigCPtr, key, PropertyValue.getCPtr(value));
146 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150 /// Returns the style constant set for a specific key.
152 /// <param name="key">The key of the constant.</param>
153 /// <param name="valueOut">The value of the constant if it exists.</param>
154 /// <returns></returns>
155 /// <since_tizen> 3 </since_tizen>
156 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
157 public bool GetConstant(string key, PropertyValue valueOut)
159 bool ret = Interop.StyleManager.GetStyleConstant(SwigCPtr, key, PropertyValue.getCPtr(valueOut));
160 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
165 /// Applies the specified style to the control.
167 /// <param name="control">The control to which to apply the style.</param>
168 /// <param name="jsonFileName">The name of the JSON style file to apply.</param>
169 /// <param name="styleName">The name of the style within the JSON file to apply.</param>
170 /// <since_tizen> 3 </since_tizen>
171 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
172 public void ApplyStyle(View control, string jsonFileName, string styleName)
174 Interop.StyleManager.ApplyStyle(SwigCPtr, View.getCPtr(control), jsonFileName, styleName);
175 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179 /// The Type of BrokenImage
181 internal enum BrokenImageType
189 /// Sets the broken image url.
190 /// The broken image is the image to show when image loading is failed.
191 /// When the broken image and type are set in the Application,
192 /// the proper brokenImage is set automatically considering the size of view and the size of the brokenImage.
193 /// This Api is used from theme manager.
195 /// <param name="type"> The type for brokenImage </param>
196 /// <param name="url"> The url for brokenImage </param>
197 internal void SetBrokenImageUrl(BrokenImageType type, string url)
199 Interop.StyleManager.SetBrokenImageUrl(SwigCPtr, (uint)type, url);
200 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204 /// Gets the broken image url
206 /// <param name="type"> The type for brokenImage</param>
207 /// <returns> the url for brokenImage </returns>
208 internal string GetBrokenImageUrl(BrokenImageType type)
210 string ret = Interop.StyleManager.GetBrokenImageUrl(SwigCPtr, (uint)type);
211 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215 internal StyleManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
219 internal StyleChangedSignal StyleChangedSignal()
221 StyleChangedSignal ret = new StyleChangedSignal(Interop.StyleManager.StyleChangedSignal(SwigCPtr), false);
222 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226 // Callback for StyleManager StyleChangedsignal
227 private void OnStyleChanged(IntPtr styleManager, StyleChangeType styleChange)
229 if (styleManagerStyleChangedEventHandler != null)
231 StyleChangedEventArgs e = new StyleChangedEventArgs();
233 // Populate all members of "e" (StyleChangedEventArgs) with real data.
234 e.StyleManager = Registry.GetManagedBaseHandleFromNativePtr(styleManager) as StyleManager;
235 e.StyleChange = styleChange;
236 //Here we send all data to user event handlers.
237 styleManagerStyleChangedEventHandler(this, e);
242 /// Style changed event arguments.
244 /// <since_tizen> 3 </since_tizen>
245 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
246 public class StyleChangedEventArgs : EventArgs
248 private StyleManager styleManager;
249 private StyleChangeType styleChange;
254 /// <since_tizen> 3 </since_tizen>
255 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
256 public StyleManager StyleManager
264 styleManager = value;
269 /// StyleChange - contains the style change information (default font changed or
270 /// default font size changed or theme has changed).<br />
272 /// <since_tizen> 3 </since_tizen>
273 [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
274 public StyleChangeType StyleChange
287 internal static void SetBrokenImage(BrokenImageType type, string url)
289 Interop.StyleManager.SetBrokenImageUrl(Instance.SwigCPtr, (uint)type, url);
290 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292 internal static string GetBrokenImageURL(BrokenImageType type)
294 string ret = Interop.StyleManager.GetBrokenImageUrl(Instance.SwigCPtr, (uint)type);
295 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();