[NUI] Add Obsolete attributes for EditorBrowsable apis
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / 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     public class StyleManager : BaseHandle
34     {
35         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
36
37         internal StyleManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.StyleManager_SWIGUpcast(cPtr), cMemoryOwn)
38         {
39             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
40         }
41
42         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(StyleManager obj)
43         {
44             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
45         }
46
47         private static readonly StyleManager instance = StyleManager.Get();
48
49         /// <summary>
50         /// Gets the singleton of the StyleManager object.
51         /// </summary>
52         /// <since_tizen> 5 </since_tizen>
53         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
54         [EditorBrowsable(EditorBrowsableState.Never)]
55         public static StyleManager Instance
56         {
57             get
58             {
59                 return instance;
60             }
61         }
62
63         /// <summary>
64         /// Dispose.
65         /// </summary>
66         /// Please DO NOT use! This will be deprecated!
67         /// Dispose() method in Singletone classes (ex: FocusManager, StyleManager, VisualFactory, IMFManager, TtsPlayer, Window) is not required.
68         /// Because it is Sigletone, so it is alive for one thread until the NUI is terminated, so it never be disposed.
69         /// <since_tizen> 3 </since_tizen>
70         [Obsolete("Please do not use! This will be deprecated!")]
71         [EditorBrowsable(EditorBrowsableState.Never)]
72         protected override void Dispose(DisposeTypes type)
73         {
74             if (disposed)
75             {
76                 return;
77             }
78
79             if (type == DisposeTypes.Explicit)
80             {
81                 //Called by User
82                 //Release your own managed resources here.
83                 //You should release all of your own disposable objects here.
84             }
85
86             //Release your own unmanaged resources here.
87             //You should not access any managed member here except static instance.
88             //because the execution order of Finalizes is non-deterministic.
89
90             if (_styleManagerStyleChangedCallbackDelegate != null)
91             {
92                 StyleChangedSignal().Disconnect(_styleManagerStyleChangedCallbackDelegate);
93             }
94
95             if (swigCPtr.Handle != global::System.IntPtr.Zero)
96             {
97                 if (swigCMemOwn)
98                 {
99                     swigCMemOwn = false;
100                     NDalicPINVOKE.delete_StyleManager(swigCPtr);
101                 }
102                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
103             }
104
105             base.Dispose(type);
106         }
107
108         /// <summary>
109         /// Style changed event arguments.
110         /// </summary>
111         /// <since_tizen> 3 </since_tizen>
112         public class StyleChangedEventArgs : EventArgs
113         {
114             private StyleManager _styleManager;
115             private StyleChangeType _styleChange;
116
117             /// <summary>
118             /// StyleManager.
119             /// </summary>
120             /// <since_tizen> 3 </since_tizen>
121             public StyleManager StyleManager
122             {
123                 get
124                 {
125                     return _styleManager;
126                 }
127                 set
128                 {
129                     _styleManager = value;
130                 }
131             }
132
133             /// <summary>
134             /// StyleChange - contains the style change information (default font changed or
135             /// default font size changed or theme has changed).<br />
136             /// </summary>
137             /// <since_tizen> 3 </since_tizen>
138             public StyleChangeType StyleChange
139             {
140                 get
141                 {
142                     return _styleChange;
143                 }
144                 set
145                 {
146                     _styleChange = value;
147                 }
148             }
149
150         }
151
152         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
153         private delegate void StyleChangedCallbackDelegate(IntPtr styleManager, Tizen.NUI.StyleChangeType styleChange);
154         private EventHandler<StyleChangedEventArgs> _styleManagerStyleChangedEventHandler;
155         private StyleChangedCallbackDelegate _styleManagerStyleChangedCallbackDelegate;
156
157         /// <summary>
158         /// An event for the StyleChanged signal which can be used to subscribe or unsubscribe the
159         /// event handler provided by the user.<br />
160         /// The StyleChanged signal is emitted after the style (for example, theme or font change) has changed
161         /// and the controls have been informed.<br />
162         /// </summary>
163         /// <since_tizen> 3 </since_tizen>
164         public event EventHandler<StyleChangedEventArgs> StyleChanged
165         {
166             add
167             {
168                 if (_styleManagerStyleChangedEventHandler == null)
169                 {
170                     _styleManagerStyleChangedCallbackDelegate = (OnStyleChanged);
171                     StyleChangedSignal().Connect(_styleManagerStyleChangedCallbackDelegate);
172                 }
173                 _styleManagerStyleChangedEventHandler += value;
174             }
175             remove
176             {
177                 _styleManagerStyleChangedEventHandler -= value;
178                 if (_styleManagerStyleChangedEventHandler == null && StyleChangedSignal().Empty() == false)
179                 {
180                     StyleChangedSignal().Disconnect(_styleManagerStyleChangedCallbackDelegate);
181                 }
182             }
183         }
184
185         // Callback for StyleManager StyleChangedsignal
186         private void OnStyleChanged(IntPtr styleManager, StyleChangeType styleChange)
187         {
188             StyleChangedEventArgs e = new StyleChangedEventArgs();
189
190             // Populate all members of "e" (StyleChangedEventArgs) with real data
191             e.StyleManager = Registry.GetManagedBaseHandleFromNativePtr(styleManager) as StyleManager;
192             e.StyleChange = styleChange;
193
194             if (_styleManagerStyleChangedEventHandler != null)
195             {
196                 //here we send all data to user event handlers
197                 _styleManagerStyleChangedEventHandler(this, e);
198             }
199         }
200
201         /// <summary>
202         /// Creates a StyleManager handle.<br />
203         /// This can be initialized with StyleManager::Get().<br />
204         /// </summary>
205         /// <since_tizen> 3 </since_tizen>
206         public StyleManager() : this(NDalicPINVOKE.new_StyleManager(), true)
207         {
208             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209         }
210
211         /// <summary>
212         /// Gets the singleton of StyleManager object.
213         /// </summary>
214         /// <returns>A handle to the StyleManager control.</returns>
215         /// <since_tizen> 3 </since_tizen>
216         public static StyleManager Get()
217         {
218             StyleManager ret = new StyleManager(NDalicPINVOKE.StyleManager_Get(), true);
219             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220             return ret;
221         }
222
223         /// <summary>
224         /// Applies a new theme to the application.<br />
225         /// This will be merged on the top of the default Toolkit theme.<br />
226         /// If the application theme file doesn't style all controls that the
227         /// application uses, then the default Toolkit theme will be used
228         /// instead for those controls.<br />
229         /// </summary>
230         /// <param name="themeFile">A relative path is specified for style theme.</param>
231         /// <since_tizen> 3 </since_tizen>
232         public void ApplyTheme(string themeFile)
233         {
234             NDalicPINVOKE.StyleManager_ApplyTheme(swigCPtr, themeFile);
235             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236         }
237
238         /// <summary>
239         /// Applies the default Toolkit theme.
240         /// </summary>
241         /// <since_tizen> 3 </since_tizen>
242         public void ApplyDefaultTheme()
243         {
244             NDalicPINVOKE.StyleManager_ApplyDefaultTheme(swigCPtr);
245             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246         }
247
248         /// <summary>
249         /// Sets a constant for use when building styles.
250         /// </summary>
251         /// <param name="key">The key of the constant.</param>
252         /// <param name="value">The value of the constant.</param>
253         /// <since_tizen> 3 </since_tizen>
254         public void AddConstant(string key, PropertyValue value)
255         {
256             NDalicPINVOKE.StyleManager_SetStyleConstant(swigCPtr, key, PropertyValue.getCPtr(value));
257             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258         }
259
260         /// <summary>
261         /// Returns the style constant set for a specific key.
262         /// </summary>
263         /// <param name="key">The key of the constant.</param>
264         /// <param name="valueOut">The value of the constant if it exists.</param>
265         /// <returns></returns>
266         /// <since_tizen> 3 </since_tizen>
267         public bool GetConstant(string key, PropertyValue valueOut)
268         {
269             bool ret = NDalicPINVOKE.StyleManager_GetStyleConstant(swigCPtr, key, PropertyValue.getCPtr(valueOut));
270             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271             return ret;
272         }
273
274         /// <summary>
275         /// Applies the specified style to the control.
276         /// </summary>
277         /// <param name="control">The control to which to apply the style.</param>
278         /// <param name="jsonFileName">The name of the JSON style file to apply.</param>
279         /// <param name="styleName">The name of the style within the JSON file to apply.</param>
280         /// <since_tizen> 3 </since_tizen>
281         public void ApplyStyle(View control, string jsonFileName, string styleName)
282         {
283             NDalicPINVOKE.StyleManager_ApplyStyle(swigCPtr, View.getCPtr(control), jsonFileName, styleName);
284             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285         }
286
287         internal StyleChangedSignal StyleChangedSignal()
288         {
289             StyleChangedSignal ret = new StyleChangedSignal(NDalicPINVOKE.StyleManager_StyleChangedSignal(swigCPtr), false);
290             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291             return ret;
292         }
293
294     }
295 }