[NUI] Change all CallingConvention to `Cdecl`
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Common / StyleManager.cs
1 /*
2  * Copyright(c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System;
19 using System.Runtime.InteropServices;
20 using Tizen.NUI.BaseComponents;
21 using System.ComponentModel;
22
23 namespace Tizen.NUI
24 {
25     /// <summary>
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 />
31     /// </summary>
32     /// <since_tizen> 3 </since_tizen>
33     [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
34     public class StyleManager : BaseHandle
35     {
36         private static readonly StyleManager instance = StyleManager.Get();
37         private EventHandler<StyleChangedEventArgs> styleManagerStyleChangedEventHandler;
38         private StyleChangedCallbackDelegate styleManagerStyleChangedCallbackDelegate;
39
40         /// <summary>
41         /// Creates a StyleManager handle.<br />
42         /// This can be initialized with StyleManager::Get().<br />
43         /// </summary>
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)
47         {
48             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
49         }
50
51         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
52         private delegate void StyleChangedCallbackDelegate(IntPtr styleManager, Tizen.NUI.StyleChangeType styleChange);
53
54         /// <summary>
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 />
59         /// </summary>
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
63         {
64             add
65             {
66                 if (styleManagerStyleChangedEventHandler == null)
67                 {
68                     styleManagerStyleChangedCallbackDelegate = (OnStyleChanged);
69                     StyleChangedSignal().Connect(styleManagerStyleChangedCallbackDelegate);
70                 }
71                 styleManagerStyleChangedEventHandler += value;
72             }
73             remove
74             {
75                 styleManagerStyleChangedEventHandler -= value;
76                 if (styleManagerStyleChangedEventHandler == null && StyleChangedSignal().Empty() == false)
77                 {
78                     StyleChangedSignal().Disconnect(styleManagerStyleChangedCallbackDelegate);
79                 }
80             }
81         }
82
83         /// <summary>
84         /// Gets the singleton of the StyleManager object.
85         /// </summary>
86         /// <since_tizen> 5 </since_tizen>
87         [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
88         public static StyleManager Instance
89         {
90             get
91             {
92                 return instance;
93             }
94         }
95
96         /// <summary>
97         /// Gets the singleton of StyleManager object.
98         /// </summary>
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()
103         {
104             StyleManager ret = new StyleManager(Interop.StyleManager.Get(), true);
105             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
106             return ret;
107         }
108
109         /// <summary>
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 />
115         /// </summary>
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)
120         {
121             Interop.StyleManager.ApplyTheme(SwigCPtr, themeFile);
122             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123         }
124
125         /// <summary>
126         /// Applies the default Toolkit theme.
127         /// </summary>
128         /// <since_tizen> 3 </since_tizen>
129         [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
130         public void ApplyDefaultTheme()
131         {
132             Interop.StyleManager.ApplyDefaultTheme(SwigCPtr);
133             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134         }
135
136         /// <summary>
137         /// Sets a constant for use when building styles.
138         /// </summary>
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)
144         {
145             Interop.StyleManager.SetStyleConstant(SwigCPtr, key, PropertyValue.getCPtr(value));
146             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147         }
148
149         /// <summary>
150         /// Returns the style constant set for a specific key.
151         /// </summary>
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)
158         {
159             bool ret = Interop.StyleManager.GetStyleConstant(SwigCPtr, key, PropertyValue.getCPtr(valueOut));
160             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161             return ret;
162         }
163
164         /// <summary>
165         /// Applies the specified style to the control.
166         /// </summary>
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)
173         {
174             Interop.StyleManager.ApplyStyle(SwigCPtr, View.getCPtr(control), jsonFileName, styleName);
175             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
176         }
177
178         /// <summary>
179         /// The Type of BrokenImage
180         /// </summary>
181         internal enum BrokenImageType
182         {
183             Small = 0,
184             Normal = 1,
185             Large = 2
186         }
187
188         /// <summary>
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.
194         /// </summary>
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)
198         {
199             Interop.StyleManager.SetBrokenImageUrl(SwigCPtr, (uint)type, url);
200             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201         }
202
203         /// <summary>
204         /// Gets the broken image url
205         /// </summary>
206         /// <param name="type"> The type for brokenImage</param>
207         /// <returns> the url for brokenImage </returns>
208         internal string GetBrokenImageUrl(BrokenImageType type)
209         {
210             string ret = Interop.StyleManager.GetBrokenImageUrl(SwigCPtr, (uint)type);
211             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
212             return ret;
213         }
214
215         internal StyleManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
216         {
217         }
218
219         internal StyleChangedSignal StyleChangedSignal()
220         {
221             StyleChangedSignal ret = new StyleChangedSignal(Interop.StyleManager.StyleChangedSignal(SwigCPtr), false);
222             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223             return ret;
224         }
225
226         // Callback for StyleManager StyleChangedsignal
227         private void OnStyleChanged(IntPtr styleManager, StyleChangeType styleChange)
228         {
229             if (styleManagerStyleChangedEventHandler != null)
230             {
231                 StyleChangedEventArgs e = new StyleChangedEventArgs();
232
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);
238             }
239         }
240
241         /// <summary>
242         /// Style changed event arguments.
243         /// </summary>
244         /// <since_tizen> 3 </since_tizen>
245         [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
246         public class StyleChangedEventArgs : EventArgs
247         {
248             private StyleManager styleManager;
249             private StyleChangeType styleChange;
250
251             /// <summary>
252             /// StyleManager.
253             /// </summary>
254             /// <since_tizen> 3 </since_tizen>
255             [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
256             public StyleManager StyleManager
257             {
258                 get
259                 {
260                     return styleManager;
261                 }
262                 set
263                 {
264                     styleManager = value;
265                 }
266             }
267
268             /// <summary>
269             /// StyleChange - contains the style change information (default font changed or
270             /// default font size changed or theme has changed).<br />
271             /// </summary>
272             /// <since_tizen> 3 </since_tizen>
273             [Obsolete("Deprecated in API9, will be removed in API11. Use ThemeManager instead.")]
274             public StyleChangeType StyleChange
275             {
276                 get
277                 {
278                     return styleChange;
279                 }
280                 set
281                 {
282                     styleChange = value;
283                 }
284             }
285         }
286
287         internal static void SetBrokenImage(BrokenImageType type, string url)
288         {
289             Interop.StyleManager.SetBrokenImageUrl(Instance.SwigCPtr, (uint)type, url);
290             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291         }
292         internal static string GetBrokenImageURL(BrokenImageType type)
293         {
294             string ret = Interop.StyleManager.GetBrokenImageUrl(Instance.SwigCPtr, (uint)type);
295             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
296             return ret;
297         }
298     }
299 }