0b8b956764980931831c0282d903d289d5cbc18a
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Layouting / MeasuredSize.cs
1 /*
2  * Copyright (c) 2018 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.ComponentModel;
19 using Tizen.NUI.BaseComponents;
20
21 namespace Tizen.NUI
22 {
23     /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
24     [EditorBrowsable(EditorBrowsableState.Never)]
25     public class MeasuredSize : global::System.IDisposable
26     {
27         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
28         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
29         [EditorBrowsable(EditorBrowsableState.Never)]
30         protected bool swigCMemOwn;
31
32         internal MeasuredSize(global::System.IntPtr cPtr, bool cMemoryOwn)
33         {
34             swigCMemOwn = cMemoryOwn;
35             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
36         }
37
38         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(MeasuredSize obj)
39         {
40             return (obj.Equals(null)) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
41         }
42
43         //A Flag to check who called Dispose(). (By User or DisposeQueue)
44         private bool isDisposeQueued = false;
45         /// <summary>
46         /// A Flat to check if it is already disposed.
47         /// </summary>
48         /// <since_tizen> 3 </since_tizen>
49         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
50         [EditorBrowsable(EditorBrowsableState.Never)]
51         protected bool disposed = false;
52
53         /// <summary>
54         /// Dispose.
55         /// </summary>
56         /// <since_tizen> 3 </since_tizen>
57         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
58         [EditorBrowsable(EditorBrowsableState.Never)]
59         ~MeasuredSize()
60         {
61             if (!isDisposeQueued)
62             {
63                 isDisposeQueued = true;
64                 DisposeQueue.Instance.Add(this);
65             }
66         }
67
68         /// <summary>
69         /// Dispose.
70         /// </summary>
71         /// <since_tizen> 3 </since_tizen>
72         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
73         [EditorBrowsable(EditorBrowsableState.Never)]
74         public void Dispose()
75         {
76             //Throw excpetion if Dispose() is called in separate thread.
77             if (!Window.IsInstalled())
78             {
79                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
80             }
81
82             if (isDisposeQueued)
83             {
84                 Dispose(DisposeTypes.Implicit);
85             }
86             else
87             {
88                 Dispose(DisposeTypes.Explicit);
89                 System.GC.SuppressFinalize(this);
90             }
91         }
92
93         /// <summary>
94         /// Dispose.
95         /// </summary>
96         /// <since_tizen> 3 </since_tizen>
97         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
98         [EditorBrowsable(EditorBrowsableState.Never)]
99         protected virtual void Dispose(DisposeTypes type)
100         {
101             if (disposed)
102             {
103                 return;
104             }
105
106             if (type == DisposeTypes.Explicit)
107             {
108                 //Called by User
109                 //Release your own managed resources here.
110                 //You should release all of your own disposable objects here.
111             }
112
113             //Release your own unmanaged resources here.
114             //You should not access any managed member here except static instance.
115             //because the execution order of Finalizes is non-deterministic.
116
117             if (swigCPtr.Handle != global::System.IntPtr.Zero)
118             {
119                 if (swigCMemOwn)
120                 {
121                     swigCMemOwn = false;
122                     LayoutPINVOKE.delete_MeasuredSize(swigCPtr);
123                 }
124                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
125             }
126             disposed = true;
127         }
128
129         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
130         [EditorBrowsable(EditorBrowsableState.Never)]
131         public MeasuredSize() : this(LayoutPINVOKE.new_MeasuredSize__SWIG_0(), true)
132         {
133             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134         }
135
136         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
137         [EditorBrowsable(EditorBrowsableState.Never)]
138         public MeasuredSize(LayoutLength measuredSize) : this(LayoutPINVOKE.new_MeasuredSize__SWIG_1(LayoutLength.getCPtr(measuredSize)), true)
139         {
140             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
141         }
142
143         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
144         [EditorBrowsable(EditorBrowsableState.Never)]
145         public MeasuredSize(LayoutLength measuredSize, MeasuredSize.StateType state) : this(LayoutPINVOKE.new_MeasuredSize__SWIG_2(LayoutLength.getCPtr(measuredSize), (int)state), true)
146         {
147             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
148         }
149
150         private bool EqualTo(MeasuredSize value)
151         {
152             bool ret = LayoutPINVOKE.MeasuredSize_EqualTo(swigCPtr, MeasuredSize.getCPtr(value));
153             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154             return ret;
155         }
156
157         private bool NotEqualTo(MeasuredSize value)
158         {
159             bool ret = LayoutPINVOKE.MeasuredSize_NotEqualTo(swigCPtr, MeasuredSize.getCPtr(value));
160             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161             return ret;
162         }
163
164         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
165         [EditorBrowsable(EditorBrowsableState.Never)]
166         public static bool operator ==(MeasuredSize r1, MeasuredSize r2)
167         {
168             return r1.EqualTo(r2);
169         }
170
171         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
172         [EditorBrowsable(EditorBrowsableState.Never)]
173         public static bool operator !=(MeasuredSize r1, MeasuredSize r2)
174         {
175             return r1.NotEqualTo(r2);
176         }
177
178         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
179         [EditorBrowsable(EditorBrowsableState.Never)]
180         public MeasuredSize.StateType State
181         {
182             get
183             {
184                 return GetState();
185             }
186             set
187             {
188                 SetState(value);
189             }
190         }
191
192         private void SetState(MeasuredSize.StateType state)
193         {
194             LayoutPINVOKE.MeasuredSize_SetState(swigCPtr, (int)state);
195             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196         }
197
198         private MeasuredSize.StateType GetState()
199         {
200             MeasuredSize.StateType ret = (MeasuredSize.StateType)LayoutPINVOKE.MeasuredSize_GetState(swigCPtr);
201             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202             return ret;
203         }
204
205         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
206         [EditorBrowsable(EditorBrowsableState.Never)]
207         public LayoutLength Size
208         {
209             get
210             {
211                 return GetSize();
212             }
213             set
214             {
215                 SetSize(value);
216             }
217         }
218
219         private void SetSize(LayoutLength size)
220         {
221             LayoutPINVOKE.MeasuredSize_SetSize(swigCPtr, LayoutLength.getCPtr(size));
222             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223         }
224
225         private LayoutLength GetSize()
226         {
227             LayoutLength ret = new LayoutLength(LayoutPINVOKE.MeasuredSize_GetSize(swigCPtr), true);
228             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229             return ret;
230         }
231
232         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
233         [EditorBrowsable(EditorBrowsableState.Never)]
234         public enum StateType
235         {
236             MEASURED_SIZE_OK,
237             MEASURED_SIZE_TOO_SMALL
238         }
239     }
240 }