Merge "[Tizen.Pims.Contacts]Fix XML Doc warnings"
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Rectangle.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 namespace Tizen.NUI
18 {
19
20     /// <summary>
21     /// The Rectangle class.
22     /// </summary>
23     public class Rectangle : global::System.IDisposable
24     {
25         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
26         protected bool swigCMemOwn;
27
28         internal Rectangle(global::System.IntPtr cPtr, bool cMemoryOwn)
29         {
30             swigCMemOwn = cMemoryOwn;
31             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
32         }
33
34         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Rectangle obj)
35         {
36             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
37         }
38
39         //A Flag to check who called Dispose(). (By User or DisposeQueue)
40         private bool isDisposeQueued = false;
41         //A Flat to check if it is already disposed.
42         protected bool disposed = false;
43
44         ~Rectangle()
45         {
46             if(!isDisposeQueued)
47             {
48                 isDisposeQueued = true;
49                 DisposeQueue.Instance.Add(this);
50             }
51         }
52
53         public void Dispose()
54         {
55             //Throw excpetion if Dispose() is called in separate thread.
56             if (!Window.IsInstalled())
57             {
58                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
59             }
60
61             if (isDisposeQueued)
62             {
63                 Dispose(DisposeTypes.Implicit);
64             }
65             else
66             {
67                 Dispose(DisposeTypes.Explicit);
68                 System.GC.SuppressFinalize(this);
69             }
70         }
71
72         protected virtual void Dispose(DisposeTypes type)
73         {
74             if (disposed)
75             {
76                 return;
77             }
78
79             if(type == DisposeTypes.Explicit)
80             {
81                 //Called by User
82                 //Release your own managed resources here.
83                 //You should release all of your own disposable objects here.
84             }
85
86             //Release your own unmanaged resources here.
87             //You should not access any managed member here except static instance.
88             //because the execution order of Finalizes is non-deterministic.
89
90             if (swigCPtr.Handle != global::System.IntPtr.Zero)
91             {
92                 if (swigCMemOwn)
93                 {
94                     swigCMemOwn = false;
95                     NDalicPINVOKE.delete_Rectangle(swigCPtr);
96                 }
97                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
98             }
99             disposed = true;
100         }
101
102         /// <summary>
103         /// THe Equality operator.
104         /// </summary>
105         /// <param name="a">The first operand.</param>
106         /// <param name="b">The second operand.</param>
107         /// <returns>True if the boxes are exactly the same.</returns>
108         /// <since_tizen> 3 </since_tizen>
109         public static bool operator ==(Rectangle a, Rectangle b)
110         {
111             // If both are null, or both are same instance, return true.
112             if (System.Object.ReferenceEquals(a, b))
113             {
114                 return true;
115             }
116
117             // If one is null, but not both, return false.
118             if (((object)a == null) || ((object)b == null))
119             {
120                 return false;
121             }
122
123             // Return true if the fields match:
124             return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
125         }
126
127         /// <summary>
128         /// Equality operator.
129         /// </summary>
130         /// <param name="o">The object to compare with the current object.</param>
131         /// <returns>True if boxes are exactly same.</returns>
132         /// <since_tizen> 4 </since_tizen>
133         public override bool Equals(object o)
134         {
135             if(o == null)
136             {
137                 return false;
138             }
139             if(!(o is Rectangle))
140             {
141                 return false;
142             }
143             Rectangle r = (Rectangle)o;
144
145             // Return true if the fields match:
146             return X == r.X && Y == r.Y && Width == r.Width && Height == r.Height;
147         }
148
149         /// <summary>
150         /// Serves as the default hash function.
151         /// </summary>
152         /// <returns>A hash code for the current object.</returns>
153         /// <since_tizen> 4 </since_tizen>
154         public override int GetHashCode()
155         {
156             return base.GetHashCode();
157         }
158
159         /// <summary>
160         /// Inequality operator.
161         /// </summary>
162         /// <param name="a">The first rectangle.</param>
163         /// <param name="b">The second rectangle.</param>
164         /// <returns>True if the rectangles are not identical.</returns>
165         /// <since_tizen> 3 </since_tizen>
166         public static bool operator !=(Rectangle a, Rectangle b)
167         {
168             return !(a == b);
169         }
170
171         /// <summary>
172         /// The x position of the rectangle.
173         /// </summary>
174         /// <since_tizen> 3 </since_tizen>
175         public int X
176         {
177             set
178             {
179                 x = ( value );
180             }
181             get
182             {
183                 return x;
184             }
185             }
186
187         /// <summary>
188         /// The Y position of the rectangle.
189         /// </summary>
190         /// <since_tizen> 3 </since_tizen>
191         public int Y
192         {
193             set
194             {
195                 y = ( value );
196             }
197             get
198             {
199                 return y;
200             }
201         }
202
203         /// <summary>
204         /// The width of the rectangle.
205         /// </summary>
206         /// <since_tizen> 3 </since_tizen>
207         public int Width
208         {
209             set
210             {
211                 width = ( value );
212             }
213             get
214             {
215                 return width;
216             }
217         }
218
219         /// <summary>
220         /// The height of the rectangle.
221         /// </summary>
222         /// <since_tizen> 3 </since_tizen>
223         public int Height
224         {
225             set
226             {
227                 height = ( value );
228             }
229             get
230             {
231                 return height;
232             }
233         }
234
235         /// <summary>
236         /// The constructor.
237         /// </summary>
238         /// <since_tizen> 3 </since_tizen>
239         public Rectangle() : this(NDalicPINVOKE.new_Rectangle__SWIG_0(), true)
240         {
241             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242         }
243
244         /// <summary>
245         /// The constructor.
246         /// </summary>
247         /// <param name="x">The x coordinate (or left).</param>
248         /// <param name="y">The y coordinate (or right).</param>
249         /// <param name="width">The width (or bottom).</param>
250         /// <param name="height">The height (or top).</param>
251         /// <since_tizen> 3 </since_tizen>
252         public Rectangle(int x, int y, int width, int height) : this(NDalicPINVOKE.new_Rectangle__SWIG_1(x, y, width, height), true)
253         {
254             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255         }
256
257         /// <summary>
258         /// Assignment from individual values.
259         /// </summary>
260         /// <param name="newX">The x coordinate.</param>
261         /// <param name="newY">The y coordinate.</param>
262         /// <param name="newWidth">The width.</param>
263         /// <param name="newHeight">The height./param>
264         /// <since_tizen> 3 </since_tizen>
265         public void Set(int newX, int newY, int newWidth, int newHeight)
266         {
267             NDalicPINVOKE.Rectangle_Set(swigCPtr, newX, newY, newWidth, newHeight);
268             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269         }
270
271         /// <summary>
272         /// Determines whether or not this rectangle is empty.
273         /// </summary>
274         /// <returns>True if width or height are zero.</returns>
275         /// <since_tizen> 3 </since_tizen>
276         public bool IsEmpty()
277         {
278             bool ret = NDalicPINVOKE.Rectangle_IsEmpty(swigCPtr);
279             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280             return ret;
281         }
282
283         /// <summary>
284         /// Gets the left of the rectangle.
285         /// </summary>
286         /// <returns>The left edge of the rectangle.</returns>
287         /// <since_tizen> 3 </since_tizen>
288         public int Left()
289         {
290             int ret = NDalicPINVOKE.Rectangle_Left(swigCPtr);
291             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292             return ret;
293         }
294
295         /// <summary>
296         /// Gets the right of the rectangle.
297         /// </summary>
298         /// <returns>The right edge of the rectangle.</returns>
299         /// <since_tizen> 3 </since_tizen>
300         public int Right()
301         {
302             int ret = NDalicPINVOKE.Rectangle_Right(swigCPtr);
303             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304             return ret;
305         }
306
307         /// <summary>
308         /// Gets the top of the rectangle.
309         /// </summary>
310         /// <returns>The top of the rectangle.</returns>
311         /// <since_tizen> 3 </since_tizen>
312         public int Top()
313         {
314             int ret = NDalicPINVOKE.Rectangle_Top(swigCPtr);
315             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316             return ret;
317         }
318
319         /// <summary>
320         /// Gets the bottom of the rectangle.
321         /// </summary>
322         /// <returns>The bottom of the rectangle.</returns>
323         /// <since_tizen> 3 </since_tizen>
324         public int Bottom()
325         {
326             int ret = NDalicPINVOKE.Rectangle_Bottom(swigCPtr);
327             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328             return ret;
329         }
330
331         /// <summary>
332         /// Gets the area of the rectangle.
333         /// </summary>
334         /// <returns>The area of the rectangle.</returns>
335         /// <since_tizen> 3 </since_tizen>
336         public int Area()
337         {
338             int ret = NDalicPINVOKE.Rectangle_Area(swigCPtr);
339             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340             return ret;
341         }
342
343         /// <summary>
344         /// Determines whether or not this rectangle and the specified rectangle intersect.
345         /// </summary>
346         /// <param name="other">The other rectangle to test against this rectangle.</param>
347         /// <returns>True if the rectangles intersect.</returns>
348         /// <since_tizen> 3 </since_tizen>
349         public bool Intersects(Rectangle other)
350         {
351             bool ret = NDalicPINVOKE.Rectangle_Intersects(swigCPtr, Rectangle.getCPtr(other));
352             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353             return ret;
354         }
355
356         /// <summary>
357         /// Determines whether or not this rectangle contains the specified rectangle.
358         /// </summary>
359         /// <param name="other">The other rectangle to test against this rectangle.</param>
360         /// <returns>True if the specified rectangle is contained.</returns>
361         /// <since_tizen> 3 </since_tizen>
362         public bool Contains(Rectangle other)
363         {
364             bool ret = NDalicPINVOKE.Rectangle_Contains(swigCPtr, Rectangle.getCPtr(other));
365             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
366             return ret;
367         }
368
369         private int x
370         {
371             set
372             {
373                 NDalicPINVOKE.Rectangle_x_set(swigCPtr, value);
374                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
375             }
376             get
377             {
378                 int ret = NDalicPINVOKE.Rectangle_x_get(swigCPtr);
379                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380                 return ret;
381             }
382         }
383
384         private int left
385         {
386             set
387             {
388                 NDalicPINVOKE.Rectangle_left_set(swigCPtr, value);
389                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
390             }
391             get
392             {
393                 int ret = NDalicPINVOKE.Rectangle_left_get(swigCPtr);
394                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
395                 return ret;
396             }
397         }
398
399         private int y
400         {
401             set
402             {
403                 NDalicPINVOKE.Rectangle_y_set(swigCPtr, value);
404                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
405             }
406             get
407             {
408                 int ret = NDalicPINVOKE.Rectangle_y_get(swigCPtr);
409                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
410                 return ret;
411             }
412         }
413
414         private int right
415         {
416             set
417             {
418                 NDalicPINVOKE.Rectangle_right_set(swigCPtr, value);
419                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
420             }
421             get
422             {
423                 int ret = NDalicPINVOKE.Rectangle_right_get(swigCPtr);
424                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
425                 return ret;
426             }
427         }
428
429         private int width
430         {
431             set
432             {
433                 NDalicPINVOKE.Rectangle_width_set(swigCPtr, value);
434                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435             }
436             get
437             {
438                 int ret = NDalicPINVOKE.Rectangle_width_get(swigCPtr);
439                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
440                 return ret;
441             }
442         }
443
444         private int bottom
445         {
446             set
447             {
448                 NDalicPINVOKE.Rectangle_bottom_set(swigCPtr, value);
449                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
450             }
451             get
452             {
453                 int ret = NDalicPINVOKE.Rectangle_bottom_get(swigCPtr);
454                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
455                 return ret;
456             }
457         }
458
459         private int height
460         {
461             set
462             {
463                 NDalicPINVOKE.Rectangle_height_set(swigCPtr, value);
464                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
465             }
466             get
467             {
468                 int ret = NDalicPINVOKE.Rectangle_height_get(swigCPtr);
469                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
470                 return ret;
471             }
472         }
473
474         private int top
475         {
476             set
477             {
478                 NDalicPINVOKE.Rectangle_top_set(swigCPtr, value);
479                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
480             }
481             get
482             {
483                 int ret = NDalicPINVOKE.Rectangle_top_get(swigCPtr);
484                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
485                 return ret;
486             }
487         }
488
489     }
490
491 }