2 * Copyright(c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.ComponentModel;
19 using System.Runtime.CompilerServices;
20 using Tizen.NUI.Binding;
21 using Tizen.NUI.Binding.Internals;
27 /// BaseHandle is a handle to an internal Dali resource.
29 /// <since_tizen> 3 </since_tizen>
30 public class BaseHandle : Element, global::System.IDisposable
35 /// <since_tizen> 3 </since_tizen>
36 protected bool swigCMemOwn;
39 /// A flag to check if it is already disposed.
41 /// <since_tizen> 3 </since_tizen>
42 protected bool disposed = false;
46 /// <since_tizen> 6 </since_tizen>
47 /// This will not be public opened.
48 [EditorBrowsable(EditorBrowsableState.Never)]
49 protected global::System.Runtime.InteropServices.HandleRef swigCPtr;
50 private global::System.Runtime.InteropServices.HandleRef swigCPtrCopy;
51 private bool _registerMe;
52 //A Flag to check who called Dispose(). (By User or DisposeQueue)
53 private bool isDisposeQueued = false;
56 /// Create an instance of BaseHandle.
58 /// <since_tizen> 3 </since_tizen>
59 public BaseHandle() : this(Interop.BaseHandle.new_BaseHandle__SWIG_1())
61 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
65 /// Create an instance of BaseHandle.
67 /// <param name="handle">The BaseHandle instance.</param>
68 /// <since_tizen> 3 </since_tizen>
69 public BaseHandle(BaseHandle handle) : this(Interop.BaseHandle.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)))
71 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74 internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn)
76 //to catch derived classes dali native exceptions
77 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
79 _registerMe = swigCMemOwn = cMemoryOwn;
80 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
81 // using copy constructor to create another native handle so Registry.Unregister works fine.
82 swigCPtrCopy = new global::System.Runtime.InteropServices.HandleRef(this, Interop.BaseHandle.new_BaseHandle__SWIG_2(swigCPtr));
83 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
88 // Register this instance of BaseHandle in the registry.
89 Registry.Register(this);
93 internal BaseHandle(global::System.IntPtr cPtr)
95 _registerMe = swigCMemOwn = true;
97 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
99 // using copy constructor to create another native handle so Registry.Unregister works fine.
100 swigCPtrCopy = new global::System.Runtime.InteropServices.HandleRef(this, Interop.BaseHandle.new_BaseHandle__SWIG_2(swigCPtr));
101 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
105 // Register this instance of BaseHandle in the registry.
106 Registry.Register(this);
113 /// <since_tizen> 3 </since_tizen>
116 if (!isDisposeQueued)
118 isDisposeQueued = true;
119 DisposeQueue.Instance.Add(this);
124 /// Event when a property is set.
126 /// <since_tizen> 5 </since_tizen>
127 public event PropertyChangedEventHandler PropertySet;
129 internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef
138 /// Returns the bool value true to indicate that an operand is true and returns false otherwise.
140 /// <since_tizen> 3 </since_tizen>
141 public static bool operator true(BaseHandle handle)
143 // if the C# object is null, return false
144 if (BaseHandle.ReferenceEquals(handle, null))
148 // returns true if the handle has a body, false otherwise
149 return handle.HasBody();
153 /// Returns the bool false to indicate that an operand is false and returns true otherwise.
155 /// <since_tizen> 3 </since_tizen>
156 public static bool operator false(BaseHandle handle)
158 // if the C# object is null, return true
159 if (BaseHandle.ReferenceEquals(handle, null))
163 return !handle.HasBody();
167 /// Explicit conversion from Handle to bool.
169 /// <since_tizen> 3 </since_tizen>
170 public static explicit operator bool(BaseHandle handle)
172 // if the C# object is null, return false
173 if (BaseHandle.ReferenceEquals(handle, null))
177 // returns true if the handle has a body, false otherwise
178 return handle.HasBody();
182 /// Equality operator
184 /// <since_tizen> 3 </since_tizen>
185 public static bool operator ==(BaseHandle x, BaseHandle y)
187 // if the C# objects are the same return true
188 if (BaseHandle.ReferenceEquals(x, y))
192 if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
194 // drop into native code to see if both handles point to the same body
198 if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
200 if (y.HasBody()) return false;
203 if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
205 if (x.HasBody()) return false;
213 /// Inequality operator. Returns Null if either operand is Null
215 /// <since_tizen> 3 </since_tizen>
216 public static bool operator !=(BaseHandle x, BaseHandle y)
222 /// Logical AND operator.<br />
223 /// It's possible when doing a operator this function (opBitwiseAnd) is never called due to short circuiting.<br />
225 /// <since_tizen> 3 </since_tizen>
226 public static BaseHandle operator &(BaseHandle x, BaseHandle y)
236 /// Logical OR operator for ||.<br />
237 /// It's possible when doing a || this function (opBitwiseOr) is never called due to short circuiting.<br />
239 /// <since_tizen> 3 </since_tizen>
240 public static BaseHandle operator |(BaseHandle x, BaseHandle y)
242 if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
244 if (x != null && x.HasBody())
248 if (y != null && y.HasBody())
258 /// Logical ! operator
260 /// <since_tizen> 3 </since_tizen>
261 public static bool operator !(BaseHandle x)
263 // if the C# object is null, return true
264 if (BaseHandle.ReferenceEquals(x, null))
278 /// <param name="o">The object should be compared.</param>
279 /// <returns>True if equal.</returns>
280 /// <since_tizen> 5 </since_tizen>
281 public override bool Equals(object o)
283 return base.Equals(o);
287 /// Gets the the hash code of this baseHandle.
289 /// <returns>The hash code.</returns>
290 /// <since_tizen> 5 </since_tizen>
291 public override int GetHashCode()
293 return base.GetHashCode();
299 /// <since_tizen> 3 </since_tizen>
300 public void Dispose()
302 //Throw excpetion if Dispose() is called in separate thread.
303 if (!Window.IsInstalled())
305 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
310 Dispose(DisposeTypes.Implicit);
314 Dispose(DisposeTypes.Explicit);
315 System.GC.SuppressFinalize(this);
320 /// Performs an action on this object with the given action name and attributes.
322 /// <param name="actionName">The command for the action.</param>
323 /// <param name="attributes">The list of attributes for the action.</param>
324 /// <returns>The action is performed by the object or not.</returns>
325 /// <since_tizen> 3 </since_tizen>
326 public bool DoAction(string actionName, PropertyMap attributes)
328 bool ret = Interop.BaseHandle.BaseHandle_DoAction(swigCPtrCopy, actionName, PropertyMap.getCPtr(attributes));
329 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 /// Returns the type name for the Handle.<br />
335 /// Will return an empty string if the typename does not exist. This will happen for types that
336 /// have not registered with type-registry.
338 /// <returns>The type name. Empty string if the typename does not exist.</returns>
339 /// <since_tizen> 3 </since_tizen>
340 public string GetTypeName()
342 string ret = Interop.BaseHandle.BaseHandle_GetTypeName(swigCPtrCopy);
343 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348 /// Returns the type info for the Handle.<br />
350 /// <param name="info">The type information.</param>
351 /// <returns>True If get the type info.</returns>
352 /// <since_tizen> 3 </since_tizen>
353 public bool GetTypeInfo(Tizen.NUI.TypeInfo info)
355 bool ret = Interop.BaseHandle.BaseHandle_GetTypeInfo(swigCPtrCopy, Tizen.NUI.TypeInfo.getCPtr(info));
356 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361 /// Resets the handle.
363 /// <since_tizen> 3 </since_tizen>
366 Interop.BaseHandle.BaseHandle_Reset(swigCPtrCopy);
367 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
371 /// To check the BaseHandle instance is equal or not.
373 /// <param name="rhs">The baseHandle instance.</param>
374 /// <returns>True If equal.</returns>
375 /// <since_tizen> 3 </since_tizen>
376 public bool EqualTo(BaseHandle rhs)
378 bool ret = Interop.BaseHandle.BaseHandle_EqualTo(swigCPtrCopy, BaseHandle.getCPtr(rhs));
379 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384 /// To check the BaseHandle instance is equal or not.
386 /// <param name="rhs">The baseHandle instance.</param>
387 /// <returns>True If not equal.</returns>
388 /// <since_tizen> 3 </since_tizen>
389 public bool NotEqualTo(BaseHandle rhs)
391 bool ret = Interop.BaseHandle.BaseHandle_NotEqualTo(swigCPtrCopy, BaseHandle.getCPtr(rhs));
392 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
397 /// To check the BaseHandle instance has body or not.
399 /// <returns>True If the baseHandle instance has body.</returns>
400 /// <since_tizen> 3 </since_tizen>
401 public bool HasBody()
403 if (swigCPtrCopy.Handle == IntPtr.Zero)
408 if (disposed == true)
412 bool ret = Interop.BaseHandle.BaseHandle_HasBody(swigCPtrCopy);
413 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
418 /// To check the BaseHandle instance is equal or not.
420 /// <param name="rhs">The baseHandle instance.</param>
421 /// <returns>True If equal.</returns>
422 /// <since_tizen> 3 </since_tizen>
423 public bool IsEqual(BaseHandle rhs)
425 if (disposed == true)
430 bool ret = Interop.BaseHandle.BaseHandle_IsEqual(swigCPtrCopy, BaseHandle.getCPtr(rhs));
431 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
437 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtrCopy;
440 internal void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
442 PropertySet?.Invoke(this, new PropertyChangedEventArgs(propertyName));
448 /// <since_tizen> 3 </since_tizen>
449 protected virtual void Dispose(DisposeTypes type)
456 if (type == DisposeTypes.Explicit)
459 //Release your own managed resources here.
460 //You should release all of your own disposable objects here.
464 //Release your own unmanaged resources here.
465 //You should not access any managed member here except static instance.
466 //because the execution order of Finalizes is non-deterministic.
468 //Unreference this instance from Registry.
471 Registry.Unregister(this);
474 if (swigCPtr.Handle != IntPtr.Zero)
479 ReleaseSwigCPtr(swigCPtr);
481 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
483 if (swigCPtrCopy.Handle != global::System.IntPtr.Zero)
486 Interop.BaseHandle.delete_BaseHandle(swigCPtrCopy);
487 swigCPtrCopy = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
494 /// Release swigCPtr.
496 /// <since_tizen> 6 </since_tizen>
497 /// This will not be public opened.
498 [EditorBrowsable(EditorBrowsableState.Never)]
499 protected virtual void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
504 /// Contains event arguments for the FocusChangeRequested event.
506 public class FocusRequestArgs : EventArgs
510 /// Gets or sets a value that indicates the starting focus state of the element for which a focus change is requested.
512 public bool Focus { get; set; }
515 /// Gets or sets a value that indicates the ending focus state of the element for which a focus change is requested.
517 public bool Result { get; set; }
520 internal global::System.Runtime.InteropServices.HandleRef SwigCPtr