[NUI] Add license, delete unnecessary code(public)
[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. Please 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. Please 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.StdCall)]
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. Please 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. Please 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. Please 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. Please 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. Please 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. Please 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. Please 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. Please 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         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(StyleManager obj)
179         {
180             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
181         }
182
183         internal StyleManager(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
184         {
185         }
186
187         internal StyleChangedSignal StyleChangedSignal()
188         {
189             StyleChangedSignal ret = new StyleChangedSignal(Interop.StyleManager.StyleChangedSignal(SwigCPtr), false);
190             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191             return ret;
192         }
193
194         // Callback for StyleManager StyleChangedsignal
195         private void OnStyleChanged(IntPtr styleManager, StyleChangeType styleChange)
196         {
197             if (styleManagerStyleChangedEventHandler != null)
198             {
199                 StyleChangedEventArgs e = new StyleChangedEventArgs();
200
201                 // Populate all members of "e" (StyleChangedEventArgs) with real data.
202                 e.StyleManager = Registry.GetManagedBaseHandleFromNativePtr(styleManager) as StyleManager;
203                 e.StyleChange = styleChange;
204                 //Here we send all data to user event handlers.
205                 styleManagerStyleChangedEventHandler(this, e);
206             }
207         }
208
209         /// <summary>
210         /// Style changed event arguments.
211         /// </summary>
212         /// <since_tizen> 3 </since_tizen>
213         [Obsolete("Deprecated in API9, Will be removed in API11. Please use ThemeManager instead.")]
214         public class StyleChangedEventArgs : EventArgs
215         {
216             private StyleManager styleManager;
217             private StyleChangeType styleChange;
218
219             /// <summary>
220             /// StyleManager.
221             /// </summary>
222             /// <since_tizen> 3 </since_tizen>
223             [Obsolete("Deprecated in API9, Will be removed in API11. Please use ThemeManager instead.")]
224             public StyleManager StyleManager
225             {
226                 get
227                 {
228                     return styleManager;
229                 }
230                 set
231                 {
232                     styleManager = value;
233                 }
234             }
235
236             /// <summary>
237             /// StyleChange - contains the style change information (default font changed or
238             /// default font size changed or theme has changed).<br />
239             /// </summary>
240             /// <since_tizen> 3 </since_tizen>
241             [Obsolete("Deprecated in API9, Will be removed in API11. Please use ThemeManager instead.")]
242             public StyleChangeType StyleChange
243             {
244                 get
245                 {
246                     return styleChange;
247                 }
248                 set
249                 {
250                     styleChange = value;
251                 }
252             }
253         }
254     }
255 }