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;
44 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
45 private global::System.Runtime.InteropServices.HandleRef swigCPtrCopy;
46 private bool registerMe;
48 //A Flag to check who called Dispose(). (By User or DisposeQueue)
49 private bool isDisposeQueued = false;
52 /// Create an instance of BaseHandle.
54 /// <since_tizen> 3 </since_tizen>
55 public BaseHandle() : this(Interop.BaseHandle.NewBaseHandle())
57 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
61 /// Create an instance of BaseHandle.
63 /// <param name="handle">The BaseHandle instance.</param>
64 /// <since_tizen> 3 </since_tizen>
65 public BaseHandle(BaseHandle handle) : this(Interop.BaseHandle.NewBaseHandle(BaseHandle.getCPtr(handle)))
67 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70 internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn)
72 //to catch derived classes dali native exceptions
73 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
75 registerMe = swigCMemOwn = cMemoryOwn;
76 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
77 // using copy constructor to create another native handle so Registry.Unregister works fine.
78 swigCPtrCopy = new global::System.Runtime.InteropServices.HandleRef(this, Interop.BaseHandle.NewBaseHandle(swigCPtr));
79 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
84 // Register this instance of BaseHandle in the registry.
85 Registry.Register(this);
89 internal BaseHandle(global::System.IntPtr cPtr)
91 registerMe = swigCMemOwn = true;
93 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
95 // using copy constructor to create another native handle so Registry.Unregister works fine.
96 swigCPtrCopy = new global::System.Runtime.InteropServices.HandleRef(this, Interop.BaseHandle.NewBaseHandle(SwigCPtr));
97 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
101 // Register this instance of BaseHandle in the registry.
102 Registry.Register(this);
109 /// <since_tizen> 3 </since_tizen>
112 if (!isDisposeQueued)
114 isDisposeQueued = true;
115 DisposeQueue.Instance.Add(this);
120 /// Event when a property is set.
122 /// <since_tizen> 5 </since_tizen>
123 public event PropertyChangedEventHandler PropertySet;
125 internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef
134 /// Returns the bool value true to indicate that an operand is true and returns false otherwise.
136 /// <since_tizen> 3 </since_tizen>
137 public static bool operator true(BaseHandle handle)
139 // if the C# object is null, return false
140 if (BaseHandle.ReferenceEquals(handle, null))
144 // returns true if the handle has a body, false otherwise
145 return handle.HasBody();
149 /// Returns the bool false to indicate that an operand is false and returns true otherwise.
151 /// <since_tizen> 3 </since_tizen>
152 public static bool operator false(BaseHandle handle)
154 // if the C# object is null, return true
155 if (BaseHandle.ReferenceEquals(handle, null))
159 return !handle.HasBody();
163 /// Explicit conversion from Handle to bool.
165 /// <since_tizen> 3 </since_tizen>
166 public static explicit operator bool(BaseHandle handle)
168 // if the C# object is null, return false
169 if (BaseHandle.ReferenceEquals(handle, null))
173 // returns true if the handle has a body, false otherwise
174 return handle.HasBody();
178 /// Equality operator
180 /// <since_tizen> 3 </since_tizen>
181 public static bool operator ==(BaseHandle x, BaseHandle y)
183 // if the C# objects are the same return true
184 if (BaseHandle.ReferenceEquals(x, y))
188 if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
190 // drop into native code to see if both handles point to the same body
194 if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
196 if (y.HasBody()) return false;
199 if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
201 if (x.HasBody()) return false;
209 /// Inequality operator. Returns Null if either operand is Null
211 /// <since_tizen> 3 </since_tizen>
212 public static bool operator !=(BaseHandle x, BaseHandle y)
218 /// Logical AND operator.<br />
219 /// It's possible when doing a operator this function (opBitwiseAnd) is never called due to short circuiting.<br />
221 /// <since_tizen> 3 </since_tizen>
222 public static BaseHandle operator &(BaseHandle x, BaseHandle y)
232 /// Logical OR operator for ||.<br />
233 /// It's possible when doing a || this function (opBitwiseOr) is never called due to short circuiting.<br />
235 /// <since_tizen> 3 </since_tizen>
236 public static BaseHandle operator |(BaseHandle x, BaseHandle y)
238 if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
240 if (x != null && x.HasBody())
244 if (y != null && y.HasBody())
254 /// Logical ! operator
256 /// <since_tizen> 3 </since_tizen>
257 public static bool operator !(BaseHandle x)
259 // if the C# object is null, return true
260 if (BaseHandle.ReferenceEquals(x, null))
274 /// <param name="o">The object should be compared.</param>
275 /// <returns>True if equal.</returns>
276 /// <since_tizen> 5 </since_tizen>
277 public override bool Equals(object o)
279 return base.Equals(o);
283 /// Gets the the hash code of this baseHandle.
285 /// <returns>The hash code.</returns>
286 /// <since_tizen> 5 </since_tizen>
287 public override int GetHashCode()
289 return base.GetHashCode();
295 /// <since_tizen> 3 </since_tizen>
296 public void Dispose()
298 //Throw excpetion if Dispose() is called in separate thread.
299 if (!Window.IsInstalled())
301 Tizen.Log.Error("NUI", "This API called from separate thread.This API must be called from MainThread.");
307 Dispose(DisposeTypes.Implicit);
311 Dispose(DisposeTypes.Explicit);
312 System.GC.SuppressFinalize(this);
317 /// Performs an action on this object with the given action name and attributes.
319 /// <param name="actionName">The command for the action.</param>
320 /// <param name="attributes">The list of attributes for the action.</param>
321 /// <returns>The action is performed by the object or not.</returns>
322 /// <since_tizen> 3 </since_tizen>
323 public bool DoAction(string actionName, PropertyMap attributes)
325 bool ret = Interop.BaseHandle.DoAction(swigCPtrCopy, actionName, PropertyMap.getCPtr(attributes));
326 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
331 /// Returns the type name for the Handle.<br />
332 /// Will return an empty string if the typename does not exist. This will happen for types that
333 /// have not registered with type-registry.
335 /// <returns>The type name. Empty string if the typename does not exist.</returns>
336 /// <since_tizen> 3 </since_tizen>
337 public string GetTypeName()
339 string ret = Interop.BaseHandle.GetTypeName(swigCPtrCopy);
340 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345 /// Returns the type info for the Handle.<br />
347 /// <param name="info">The type information.</param>
348 /// <returns>True If get the type info.</returns>
349 /// <since_tizen> 3 </since_tizen>
350 public bool GetTypeInfo(Tizen.NUI.TypeInfo info)
352 bool ret = Interop.BaseHandle.GetTypeInfo(swigCPtrCopy, Tizen.NUI.TypeInfo.getCPtr(info));
353 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
358 /// Resets the handle.
360 /// <since_tizen> 3 </since_tizen>
363 Interop.BaseHandle.Reset(swigCPtrCopy);
364 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368 /// To check the BaseHandle instance is equal or not.
370 /// <param name="rhs">The baseHandle instance.</param>
371 /// <returns>True If equal.</returns>
372 /// <since_tizen> 3 </since_tizen>
373 public bool EqualTo(BaseHandle rhs)
375 bool ret = Interop.BaseHandle.EqualTo(swigCPtrCopy, BaseHandle.getCPtr(rhs));
376 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
381 /// To check the BaseHandle instance is equal or not.
383 /// <param name="rhs">The baseHandle instance.</param>
384 /// <returns>True If not equal.</returns>
385 /// <since_tizen> 3 </since_tizen>
386 public bool NotEqualTo(BaseHandle rhs)
388 bool ret = Interop.BaseHandle.NotEqualTo(swigCPtrCopy, BaseHandle.getCPtr(rhs));
389 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
394 /// To check the BaseHandle instance has body or not.
396 /// <returns>True If the baseHandle instance has body.</returns>
397 /// <since_tizen> 3 </since_tizen>
398 public bool HasBody()
400 if (swigCPtrCopy.Handle == IntPtr.Zero)
405 if (disposed == true)
409 bool ret = Interop.BaseHandle.HasBody(swigCPtrCopy);
410 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
415 /// To check the BaseHandle instance is equal or not.
417 /// <param name="rhs">The baseHandle instance.</param>
418 /// <returns>True If equal.</returns>
419 /// <since_tizen> 3 </since_tizen>
420 public bool IsEqual(BaseHandle rhs)
422 if (disposed == true)
427 bool ret = Interop.BaseHandle.IsEqual(swigCPtrCopy, BaseHandle.getCPtr(rhs));
428 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
432 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
434 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtrCopy;
437 internal void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
439 PropertySet?.Invoke(this, new PropertyChangedEventArgs(propertyName));
445 /// <since_tizen> 3 </since_tizen>
446 protected virtual void Dispose(DisposeTypes type)
453 if (type == DisposeTypes.Explicit)
456 //Release your own managed resources here.
457 //You should release all of your own disposable objects here.
461 //Release your own unmanaged resources here.
462 //You should not access any managed member here except static instance.
463 //because the execution order of Finalizes is non-deterministic.
465 //Unreference this instance from Registry.
468 Registry.Unregister(this);
471 if (SwigCPtr.Handle != IntPtr.Zero)
476 ReleaseSwigCPtr(SwigCPtr);
478 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
480 if (swigCPtrCopy.Handle != global::System.IntPtr.Zero)
483 Interop.BaseHandle.DeleteBaseHandle(swigCPtrCopy);
484 swigCPtrCopy = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
491 /// Release swigCPtr.
493 /// <since_tizen> 6 </since_tizen>
494 /// This will not be public opened.
495 [EditorBrowsable(EditorBrowsableState.Never)]
496 protected virtual void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
501 /// Contains event arguments for the FocusChangeRequested event.
503 public class FocusRequestArgs : EventArgs
507 /// Gets or sets a value that indicates the starting focus state of the element for which a focus change is requested.
509 public bool Focus { get; set; }
512 /// Gets or sets a value that indicates the ending focus state of the element for which a focus change is requested.
514 public bool Result { get; set; }
517 internal global::System.Runtime.InteropServices.HandleRef SwigCPtr