[NUI] Sync dalihub and Samsung TizenFX (#349)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Layouting / LayoutSize.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     /// <summary>
24     /// [Draft] This class represents a layout size (width and height)
25     /// </summary>
26     internal class LayoutSize : global::System.IDisposable
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29         protected bool swigCMemOwn;
30
31         internal LayoutSize(global::System.IntPtr cPtr, bool cMemoryOwn)
32         {
33             swigCMemOwn = cMemoryOwn;
34             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
35         }
36
37         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(LayoutSize obj)
38         {
39             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
40         }
41
42         ~LayoutSize()
43         {
44             Dispose();
45         }
46
47         public virtual void Dispose()
48         {
49             lock(this)
50             {
51                 if (swigCPtr.Handle != global::System.IntPtr.Zero)
52                 {
53                     if (swigCMemOwn)
54                     {
55                         swigCMemOwn = false;
56                         LayoutPINVOKE.delete_LayoutSize(swigCPtr);
57                     }
58                     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
59                 }
60                 global::System.GC.SuppressFinalize(this);
61             }
62         }
63
64         public LayoutSize() : this(LayoutPINVOKE.new_LayoutSize__SWIG_0(), true)
65         {
66             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
67         }
68
69         public LayoutSize(int x, int y) : this(LayoutPINVOKE.new_LayoutSize__SWIG_1(x, y), true)
70         {
71             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
72         }
73
74         internal void SetWidth(LayoutLength value)
75         {
76             LayoutPINVOKE.LayoutSize_SetWidth__SWIG_1(swigCPtr, LayoutLength.getCPtr(value));
77             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
78         }
79
80         internal void SetHeight(LayoutLength value)
81         {
82             LayoutPINVOKE.LayoutSize_SetHeight__SWIG_1(swigCPtr, LayoutLength.getCPtr(value));
83             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
84         }
85
86         private bool EqualTo(LayoutSize rhs)
87         {
88             bool ret = LayoutPINVOKE.LayoutSize_EqualTo(swigCPtr, LayoutSize.getCPtr(rhs));
89             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
90             return ret;
91         }
92
93         public bool IsEqualTo(LayoutSize target)
94         {
95             if (this.Width == target.Width && this.Height == target.Height)
96             {
97                 return true;
98             }
99             return false;
100         }
101
102
103         // This causes crash!
104         // compile warning message :
105         //'LayoutSize' defines operator == or operator != but does not override Object.Equals(object o)
106         //'LayoutSize' defines operator == or operator != but does not override Object.GetHashCode()
107         //public static bool operator ==(LayoutSize r1, LayoutSize r2)
108         //{
109         //    return r1.EqualTo(r2);
110         //}
111         //public static bool operator !=(LayoutSize r1, LayoutSize r2)
112         //{
113         //    return !r1.EqualTo(r2);
114         //}
115
116
117         public int Width
118         {
119             //This should be blocked! Otherwise, user can set multiple-cascading property setting like "LinearLayout.CellPadding.Width = 100;". This will not be working!
120             //set
121             //{
122             //    LayoutPINVOKE.LayoutSize_width_set(swigCPtr, value);
123             //    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124             //}
125             get
126             {
127                 int ret = LayoutPINVOKE.LayoutSize_width_get(swigCPtr);
128                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
129                 return ret;
130             }
131         }
132
133         public int Height
134         {
135             //This should be blocked! Otherwise, user can set multiple-cascading property setting like "LinearLayout.CellPadding.Height = 100;". This will not be working!
136             //set
137             //{
138             //    LayoutPINVOKE.LayoutSize_height_set(swigCPtr, value);
139             //    if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140             //}
141             get
142             {
143                 int ret = LayoutPINVOKE.LayoutSize_height_get(swigCPtr);
144                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145                 return ret;
146             }
147         }
148     }
149 }