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