[NUI] Remove bindings between Style and View (#1788)
[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             InitSubstyle();
51         }
52
53
54         /// <summary>
55         /// Creates a new instance of a ControlStyle with style.
56         /// </summary>
57         /// <param name="style">Create ControlStyle by style customized by user.</param>
58         /// <since_tizen> 6 </since_tizen>
59         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
60         [EditorBrowsable(EditorBrowsableState.Never)]
61         public ControlStyle(ControlStyle style) : base(style)
62         {
63             if(null == style) return;
64
65             this.CopyFrom(style);
66         }
67
68         /// <summary>
69         /// Dispose.
70         /// </summary>
71         [EditorBrowsable(EditorBrowsableState.Never)]
72         ~ControlStyle()
73         {
74             if (!isDisposeQueued)
75             {
76                 isDisposeQueued = true;
77                 DisposeQueue.Instance.Add(this);
78             }
79         }
80
81         /// <summary>
82         /// Dispose.
83         /// </summary>
84         [EditorBrowsable(EditorBrowsableState.Never)]
85         public void Dispose()
86         {
87             //Throw excpetion if Dispose() is called in separate thread.
88             if (!Window.IsInstalled())
89             {
90                 throw new global::System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
91             }
92
93             if (isDisposeQueued)
94             {
95                 Dispose(DisposeTypes.Implicit);
96             }
97             else
98             {
99                 Dispose(DisposeTypes.Explicit);
100                 global::System.GC.SuppressFinalize(this);
101             }
102         }
103
104         /// <summary>
105         /// Dispose.
106         /// </summary>
107         [EditorBrowsable(EditorBrowsableState.Never)]
108         protected virtual void Dispose(DisposeTypes type)
109         {
110             if (disposed)
111             {
112                 return;
113             }
114
115             if (type == DisposeTypes.Explicit)
116             {
117                 //Called by User
118                 //Release your own managed resources here.
119                 //You should release all of your own disposable objects here.
120             }
121
122             disposed = true;
123         }
124
125         private void InitSubstyle()
126         {
127         }
128
129         private void SubStyleCalledEvent(object sender, global::System.EventArgs e)
130         {
131             OnPropertyChanged();
132         }
133     }
134 }