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 Flat 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 bool _registerMe;
46 //A Flag to check who called Dispose(). (By User or DisposeQueue)
47 private bool isDisposeQueued = false;
50 /// Create an instance of BaseHandle.
52 /// <since_tizen> 3 </since_tizen>
53 public BaseHandle() : this(Interop.BaseHandle.new_BaseHandle__SWIG_1())
55 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
59 /// Create an instance of BaseHandle.
61 /// <param name="handle">The BaseHandle instance.</param>
62 /// <since_tizen> 3 </since_tizen>
63 public BaseHandle(BaseHandle handle) : this(Interop.BaseHandle.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)))
65 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
68 internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn)
70 //to catch derived classes dali native exceptions
71 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
73 _registerMe = swigCMemOwn = cMemoryOwn;
74 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
75 // using copy constructor to create another native handle so Registry.Unregister works fine.
76 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, Interop.BaseHandle.new_BaseHandle__SWIG_2(swigCPtr));
77 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
82 // Register this instance of BaseHandle in the registry.
83 Registry.Register(this);
87 internal BaseHandle(global::System.IntPtr cPtr)
89 _registerMe = swigCMemOwn = true;
91 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
93 // using copy constructor to create another native handle so Registry.Unregister works fine.
94 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, Interop.BaseHandle.new_BaseHandle__SWIG_2(swigCPtr));
95 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99 // Register this instance of BaseHandle in the registry.
100 Registry.Register(this);
107 /// <since_tizen> 3 </since_tizen>
110 if (!isDisposeQueued)
112 isDisposeQueued = true;
113 DisposeQueue.Instance.Add(this);
118 /// Event when a property is set.
120 /// <since_tizen> 5 </since_tizen>
121 public event PropertyChangedEventHandler PropertySet;
123 internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef
132 /// Returns the bool value true to indicate that an operand is true and returns false otherwise.
134 /// <since_tizen> 3 </since_tizen>
135 public static bool operator true(BaseHandle handle)
137 // if the C# object is null, return false
138 if (BaseHandle.ReferenceEquals(handle, null))
142 // returns true if the handle has a body, false otherwise
143 return handle.HasBody();
147 /// Returns the bool false to indicate that an operand is false and returns true otherwise.
149 /// <since_tizen> 3 </since_tizen>
150 public static bool operator false(BaseHandle handle)
152 // if the C# object is null, return true
153 if (BaseHandle.ReferenceEquals(handle, null))
157 return !handle.HasBody();
161 /// Explicit conversion from Handle to bool.
163 /// <since_tizen> 3 </since_tizen>
164 public static explicit operator bool(BaseHandle handle)
166 // if the C# object is null, return false
167 if (BaseHandle.ReferenceEquals(handle, null))
171 // returns true if the handle has a body, false otherwise
172 return handle.HasBody();
176 /// Equality operator
178 /// <since_tizen> 3 </since_tizen>
179 public static bool operator ==(BaseHandle x, BaseHandle y)
181 // if the C# objects are the same return true
182 if (BaseHandle.ReferenceEquals(x, y))
186 if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
188 // drop into native code to see if both handles point to the same body
192 if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
194 if (y.HasBody()) return false;
197 if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
199 if (x.HasBody()) return false;
207 /// Inequality operator. Returns Null if either operand is Null
209 /// <since_tizen> 3 </since_tizen>
210 public static bool operator !=(BaseHandle x, BaseHandle y)
216 /// Logical AND operator.<br />
217 /// It's possible when doing a operator this function (opBitwiseAnd) is never called due to short circuiting.<br />
219 /// <since_tizen> 3 </since_tizen>
220 public static BaseHandle operator &(BaseHandle x, BaseHandle y)
230 /// Logical OR operator for ||.<br />
231 /// It's possible when doing a || this function (opBitwiseOr) is never called due to short circuiting.<br />
233 /// <since_tizen> 3 </since_tizen>
234 public static BaseHandle operator |(BaseHandle x, BaseHandle y)
236 if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
238 if (x != null && x.HasBody())
242 if (y != null && y.HasBody())
252 /// Logical ! operator
254 /// <since_tizen> 3 </since_tizen>
255 public static bool operator !(BaseHandle x)
257 // if the C# object is null, return true
258 if (BaseHandle.ReferenceEquals(x, null))
272 /// <param name="o">The object should be compared.</param>
273 /// <returns>True if equal.</returns>
274 /// <since_tizen> 5 </since_tizen>
275 public override bool Equals(object o)
277 return base.Equals(o);
281 /// Gets the the hash code of this baseHandle.
283 /// <returns>The hash code.</returns>
284 /// <since_tizen> 5 </since_tizen>
285 public override int GetHashCode()
287 return base.GetHashCode();
293 /// <since_tizen> 3 </since_tizen>
294 public void Dispose()
296 //Throw excpetion if Dispose() is called in separate thread.
297 if (!Window.IsInstalled())
299 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
304 Dispose(DisposeTypes.Implicit);
308 Dispose(DisposeTypes.Explicit);
309 System.GC.SuppressFinalize(this);
314 /// Performs an action on this object with the given action name and attributes.
316 /// <param name="actionName">The command for the action.</param>
317 /// <param name="attributes">The list of attributes for the action.</param>
318 /// <returns>The action is performed by the object or not.</returns>
319 /// <since_tizen> 3 </since_tizen>
320 public bool DoAction(string actionName, PropertyMap attributes)
322 bool ret = Interop.BaseHandle.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
323 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328 /// Returns the type name for the Handle.<br />
329 /// Will return an empty string if the typename does not exist. This will happen for types that
330 /// have not registered with type-registry.
332 /// <returns>The type name. Empty string if the typename does not exist.</returns>
333 /// <since_tizen> 3 </since_tizen>
334 public string GetTypeName()
336 string ret = Interop.BaseHandle.BaseHandle_GetTypeName(swigCPtr);
337 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
342 /// Returns the type info for the Handle.<br />
344 /// <param name="info">The type information.</param>
345 /// <returns>True If get the type info.</returns>
346 /// <since_tizen> 3 </since_tizen>
347 public bool GetTypeInfo(Tizen.NUI.TypeInfo info)
349 bool ret = Interop.BaseHandle.BaseHandle_GetTypeInfo(swigCPtr, Tizen.NUI.TypeInfo.getCPtr(info));
350 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355 /// Resets the handle.
357 /// <since_tizen> 3 </since_tizen>
360 Interop.BaseHandle.BaseHandle_Reset(swigCPtr);
361 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
365 /// To check the BaseHandle instance is equal or not.
367 /// <param name="rhs">The baseHandle instance.</param>
368 /// <returns>True If equal.</returns>
369 /// <since_tizen> 3 </since_tizen>
370 public bool EqualTo(BaseHandle rhs)
372 bool ret = Interop.BaseHandle.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 /// To check the BaseHandle instance is equal or not.
380 /// <param name="rhs">The baseHandle instance.</param>
381 /// <returns>True If not equal.</returns>
382 /// <since_tizen> 3 </since_tizen>
383 public bool NotEqualTo(BaseHandle rhs)
385 bool ret = Interop.BaseHandle.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
386 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391 /// To check the BaseHandle instance has body or not.
393 /// <returns>True If the baseHandle instance has body.</returns>
394 /// <since_tizen> 3 </since_tizen>
395 public bool HasBody()
397 if (disposed == true)
402 bool ret = Interop.BaseHandle.BaseHandle_HasBody(swigCPtr);
403 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
408 /// To check the BaseHandle instance is equal or not.
410 /// <param name="rhs">The baseHandle instance.</param>
411 /// <returns>True If equal.</returns>
412 /// <since_tizen> 3 </since_tizen>
413 public bool IsEqual(BaseHandle rhs)
415 if (disposed == true)
420 bool ret = Interop.BaseHandle.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
421 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
425 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
427 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
430 internal void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
432 PropertySet?.Invoke(this, new PropertyChangedEventArgs(propertyName));
435 internal RefObject GetObjectPtr()
437 global::System.IntPtr cPtr = Interop.BaseHandle.BaseHandle_GetObjectPtr(swigCPtr);
438 RefObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new RefObject(cPtr, false);
439 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
446 /// <since_tizen> 3 </since_tizen>
447 protected virtual void Dispose(DisposeTypes type)
454 if (type == DisposeTypes.Explicit)
457 //Release your own managed resources here.
458 //You should release all of your own disposable objects here.
462 //Release your own unmanaged resources here.
463 //You should not access any managed member here except static instance.
464 //because the execution order of Finalizes is non-deterministic.
466 //Unreference this instance from Registry.
469 Registry.Unregister(this);
472 if (swigCPtr.Handle != global::System.IntPtr.Zero)
475 Interop.BaseHandle.delete_BaseHandle(swigCPtr);
476 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
483 /// Contains event arguments for the FocusChangeRequested event.
485 public class FocusRequestArgs : EventArgs
489 /// Gets or sets a value that indicates the starting focus state of the element for which a focus change is requested.
491 public bool Focus { get; set; }
494 /// Gets or sets a value that indicates the ending focus state of the element for which a focus change is requested.
496 public bool Result { get; set; }