[NUI] Fix build warning & clean code [CA1051]
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Style / ControlStyle.cs
1 /*
2  * Copyright(c) 2019 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 using System.ComponentModel;
18 using Tizen.NUI.BaseComponents;
19
20 namespace Tizen.NUI.Components
21 {
22     /// <summary>
23     /// ControlStyle is a base class of NUI.Components style.
24     /// </summary>
25     /// <since_tizen> 6 </since_tizen>
26     /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
27     [EditorBrowsable(EditorBrowsableState.Never)]
28     public class ControlStyle : ViewStyle, global::System.IDisposable
29     {
30         private bool isDisposeQueued = false;
31
32         static ControlStyle()
33         {
34             ThemeManager.AddPackageTheme(new DefaultThemeCreator());
35         }
36
37         /// <summary>
38         /// Creates a new instance of a ControlStyle.
39         /// </summary>
40         /// <since_tizen> 6 </since_tizen>
41         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
42         [EditorBrowsable(EditorBrowsableState.Never)]
43         public ControlStyle() : base()
44         {
45         }
46
47
48         /// <summary>
49         /// Creates a new instance of a ControlStyle with style.
50         /// </summary>
51         /// <param name="style">Create ControlStyle by style customized by user.</param>
52         /// <since_tizen> 6 </since_tizen>
53         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
54         [EditorBrowsable(EditorBrowsableState.Never)]
55         public ControlStyle(ControlStyle style) : base(style)
56         {
57         }
58
59         /// <summary>
60         /// Dispose.
61         /// </summary>
62         [EditorBrowsable(EditorBrowsableState.Never)]
63         ~ControlStyle()
64         {
65             if (!isDisposeQueued)
66             {
67                 isDisposeQueued = true;
68                 DisposeQueue.Instance.Add(this);
69             }
70         }
71
72         /// <summary>
73         /// A Flag to check if it is already disposed.
74         /// </summary>
75         [EditorBrowsable(EditorBrowsableState.Never)]
76         protected bool Disposed { get; set; }
77
78         /// <summary>
79         /// Dispose.
80         /// </summary>
81         [EditorBrowsable(EditorBrowsableState.Never)]
82         public void Dispose()
83         {
84             //Throw excpetion if Dispose() is called in separate thread.
85             if (!Window.IsInstalled())
86             {
87                 throw new global::System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
88             }
89
90             if (isDisposeQueued)
91             {
92                 Dispose(DisposeTypes.Implicit);
93             }
94             else
95             {
96                 Dispose(DisposeTypes.Explicit);
97                 global::System.GC.SuppressFinalize(this);
98             }
99         }
100
101         /// <summary>
102         /// Dispose.
103         /// </summary>
104         [EditorBrowsable(EditorBrowsableState.Never)]
105         protected virtual void Dispose(DisposeTypes type)
106         {
107             if (Disposed)
108             {
109                 return;
110             }
111
112             if (type == DisposeTypes.Explicit)
113             {
114                 //Called by User
115                 //Release your own managed resources here.
116                 //You should release all of your own disposable objects here.
117             }
118
119             Disposed = true;
120         }
121
122         private void SubStyleCalledEvent(object sender, global::System.EventArgs e)
123         {
124             OnPropertyChanged();
125         }
126     }
127 }