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 Tizen.NUI.Binding;
20 using Tizen.NUI.Internals;
26 /// BaseHandle is a handle to an internal Dali resource.
28 /// <since_tizen> 3 </since_tizen>
29 public class BaseHandle : Element, global::System.IDisposable
32 internal static readonly BindablePropertyKey NavigationPropertyKey = BindableProperty.CreateReadOnly("Navigation", typeof(INavigation), typeof(/*VisualElement*/BaseHandle), default(INavigation));
33 public static readonly BindableProperty NavigationProperty = NavigationPropertyKey.BindableProperty;
35 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
39 /// <since_tizen> 3 </since_tizen>
40 protected bool swigCMemOwn;
41 private bool _registerMe;
43 internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn)
45 //to catch derived classes dali native exceptions
46 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
48 _registerMe = swigCMemOwn = cMemoryOwn;
49 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
51 // using copy constructor to create another native handle so Registry.Unregister works fine.
52 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
54 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
59 // Register this instance of BaseHandle in the registry.
60 Registry.Register(this);
64 internal BaseHandle(global::System.IntPtr cPtr)
66 _registerMe = swigCMemOwn = true;
68 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
70 // using copy constructor to create another native handle so Registry.Unregister works fine.
71 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
72 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
76 // Register this instance of BaseHandle in the registry.
77 Registry.Register(this);
81 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
83 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
86 //A Flag to check who called Dispose(). (By User or DisposeQueue)
87 private bool isDisposeQueued = false;
90 /// A Flat to check if it is already disposed.
92 /// <since_tizen> 3 </since_tizen>
93 protected bool disposed = false;
98 /// <since_tizen> 3 </since_tizen>
101 if (!isDisposeQueued)
103 isDisposeQueued = true;
104 DisposeQueue.Instance.Add(this);
111 /// <since_tizen> 3 </since_tizen>
112 public void Dispose()
114 //Throw excpetion if Dispose() is called in separate thread.
115 if (!Window.IsInstalled())
117 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
122 Dispose(DisposeTypes.Implicit);
126 Dispose(DisposeTypes.Explicit);
127 System.GC.SuppressFinalize(this);
134 /// <since_tizen> 3 </since_tizen>
135 protected virtual void Dispose(DisposeTypes type)
142 if (type == DisposeTypes.Explicit)
145 //Release your own managed resources here.
146 //You should release all of your own disposable objects here.
150 //Release your own unmanaged resources here.
151 //You should not access any managed member here except static instance.
152 //because the execution order of Finalizes is non-deterministic.
154 //Unreference this instance from Registry.
157 Registry.Unregister(this);
160 if (swigCPtr.Handle != global::System.IntPtr.Zero)
163 NDalicPINVOKE.delete_BaseHandle(swigCPtr);
164 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
171 /// Returns the bool value true to indicate that an operand is true and returns false otherwise.
173 /// <since_tizen> 3 </since_tizen>
174 public static bool operator true(BaseHandle handle)
176 // if the C# object is null, return false
177 if (BaseHandle.ReferenceEquals(handle, null))
181 // returns true if the handle has a body, false otherwise
182 return handle.HasBody();
186 /// Returns the bool false to indicate that an operand is false and returns true otherwise.
188 /// <since_tizen> 3 </since_tizen>
189 public static bool operator false(BaseHandle handle)
191 // if the C# object is null, return true
192 if (BaseHandle.ReferenceEquals(handle, null))
196 return !handle.HasBody();
200 /// Explicit conversion from Handle to bool.
202 /// <since_tizen> 3 </since_tizen>
203 public static explicit operator bool(BaseHandle handle)
205 // if the C# object is null, return false
206 if (BaseHandle.ReferenceEquals(handle, null))
210 // returns true if the handle has a body, false otherwise
211 return handle.HasBody();
215 /// Equality operator
217 /// <since_tizen> 3 </since_tizen>
218 public static bool operator ==(BaseHandle x, BaseHandle y)
220 // if the C# objects are the same return true
221 if (BaseHandle.ReferenceEquals(x, y))
225 if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
227 // drop into native code to see if both handles point to the same body
231 if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
233 if (y.HasBody()) return false;
236 if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
238 if (x.HasBody()) return false;
246 /// Inequality operator. Returns Null if either operand is Null
248 /// <since_tizen> 3 </since_tizen>
249 public static bool operator !=(BaseHandle x, BaseHandle y)
255 /// Logical AND operator.<br />
256 /// It's possible when doing a operator this function (opBitwiseAnd) is never called due to short circuiting.<br />
258 /// <since_tizen> 3 </since_tizen>
259 public static BaseHandle operator &(BaseHandle x, BaseHandle y)
269 /// Logical OR operator for ||.<br />
270 /// It's possible when doing a || this function (opBitwiseOr) is never called due to short circuiting.<br />
272 /// <since_tizen> 3 </since_tizen>
273 public static BaseHandle operator |(BaseHandle x, BaseHandle y)
275 if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
291 /// Logical ! operator
293 /// <since_tizen> 3 </since_tizen>
294 public static bool operator !(BaseHandle x)
296 // if the C# object is null, return true
297 if (BaseHandle.ReferenceEquals(x, null))
311 /// <param name="o">The object should be compared.</param>
312 /// <returns>True if equal.</returns>
313 /// <since_tizen> 5 </since_tizen>
314 public override bool Equals(object o)
316 return base.Equals(o);
320 /// Gets the the hash code of this baseHandle.
322 /// <returns>The Hash Code.</returns>
323 /// <since_tizen> 5 </since_tizen>
324 public override int GetHashCode()
326 return base.GetHashCode();
330 /// Create an instance of BaseHandle.
332 /// <since_tizen> 3 </since_tizen>
333 public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1())
335 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339 /// Create an instance of BaseHandle.
341 /// <param name="handle">The BaseHandle instance.</param>
342 /// <since_tizen> 3 </since_tizen>
343 public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)))
345 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
350 /// Performs an action on this object with the given action name and attributes.
352 /// <param name="actionName">The command for the action.</param>
353 /// <param name="attributes">The list of attributes for the action.</param>
354 /// <returns>The action is performed by the object or not.</returns>
355 /// <since_tizen> 3 </since_tizen>
356 public bool DoAction(string actionName, PropertyMap attributes)
358 bool ret = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
359 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364 /// Returns the type name for the Handle.<br />
365 /// Will return an empty string if the typename does not exist. This will happen for types that
366 /// have not registered with type-registry.
368 /// <returns>The type name. Empty string if the typename does not exist.</returns>
369 /// <since_tizen> 3 </since_tizen>
370 public string GetTypeName()
372 string ret = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr);
373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 /// Returns the type info for the Handle.<br />
380 /// <param name="info">The type information.</param>
381 /// <returns>True If get the type info.</returns>
382 /// <since_tizen> 3 </since_tizen>
383 public bool GetTypeInfo(TypeInfo info)
385 bool ret = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, TypeInfo.getCPtr(info));
386 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391 /// Resets the handle.
393 /// <since_tizen> 3 </since_tizen>
396 NDalicPINVOKE.BaseHandle_Reset(swigCPtr);
397 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
401 /// To check the BaseHandle instance is equal or not.
403 /// <param name="rhs">The baseHandle instance.</param>
404 /// <returns>True If equal.</returns>
405 /// <since_tizen> 3 </since_tizen>
406 public bool EqualTo(BaseHandle rhs)
408 bool ret = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
409 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
414 /// To check the BaseHandle instance is equal or not.
416 /// <param name="rhs">The baseHandle instance.</param>
417 /// <returns>True If not equal.</returns>
418 /// <since_tizen> 3 </since_tizen>
419 public bool NotEqualTo(BaseHandle rhs)
421 bool ret = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
422 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
426 internal RefObject GetObjectPtr()
428 global::System.IntPtr cPtr = NDalicPINVOKE.BaseHandle_GetObjectPtr(swigCPtr);
429 RefObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new RefObject(cPtr, false);
430 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435 /// To check the BaseHandle instance has body or not.
437 /// <returns>True If the baseHandle instance has body.</returns>
438 /// <since_tizen> 3 </since_tizen>
439 public bool HasBody()
441 if (disposed == true)
446 bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
447 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
452 /// To check the BaseHandle instance is equal or not.
454 /// <param name="rhs">The baseHandle instance.</param>
455 /// <returns>True If equal.</returns>
456 /// <since_tizen> 3 </since_tizen>
457 public bool IsEqual(BaseHandle rhs)
459 if (disposed == true)
464 bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
465 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
469 internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef
477 [EditorBrowsable(EditorBrowsableState.Never)]
478 public NavigationProxy NavigationProxy
480 get { return Navigation as NavigationProxy; }
482 public INavigation Navigation
484 get { return (INavigation)GetValue(NavigationProperty); }
485 internal set { SetValue(NavigationPropertyKey, value); }
488 public class FocusRequestArgs : EventArgs
490 public bool Focus { get; set; }
491 public bool Result { get; set; }