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