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
33 /// Event which is occurred when a property is set
35 /// <since_tizen> 5 </since_tizen>
36 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
37 [EditorBrowsable(EditorBrowsableState.Never)]
38 public event PropertyChangedEventHandler PropertySet;
40 internal void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
42 PropertySet?.Invoke(this, new PropertyChangedEventArgs(propertyName));
45 internal static readonly BindablePropertyKey NavigationPropertyKey = BindableProperty.CreateReadOnly("Navigation", typeof(INavigation), typeof(/*VisualElement*/BaseHandle), default(INavigation));
47 /// Backing store for the Navigation property.
49 internal static readonly BindableProperty NavigationProperty = NavigationPropertyKey.BindableProperty;
51 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
55 /// <since_tizen> 3 </since_tizen>
56 protected bool swigCMemOwn;
57 private bool _registerMe;
59 internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn)
61 //to catch derived classes dali native exceptions
62 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
64 _registerMe = swigCMemOwn = cMemoryOwn;
65 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
67 // using copy constructor to create another native handle so Registry.Unregister works fine.
68 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
70 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
75 // Register this instance of BaseHandle in the registry.
76 Registry.Register(this);
80 internal BaseHandle(global::System.IntPtr cPtr)
82 _registerMe = swigCMemOwn = true;
84 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
86 // using copy constructor to create another native handle so Registry.Unregister works fine.
87 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
88 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92 // Register this instance of BaseHandle in the registry.
93 Registry.Register(this);
97 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
99 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
102 //A Flag to check who called Dispose(). (By User or DisposeQueue)
103 private bool isDisposeQueued = false;
106 /// A Flat to check if it is already disposed.
108 /// <since_tizen> 3 </since_tizen>
109 protected bool disposed = false;
114 /// <since_tizen> 3 </since_tizen>
117 if (!isDisposeQueued)
119 isDisposeQueued = true;
120 DisposeQueue.Instance.Add(this);
127 /// <since_tizen> 3 </since_tizen>
128 public void Dispose()
130 //Throw excpetion if Dispose() is called in separate thread.
131 if (!Window.IsInstalled())
133 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
138 Dispose(DisposeTypes.Implicit);
142 Dispose(DisposeTypes.Explicit);
143 System.GC.SuppressFinalize(this);
150 /// <since_tizen> 3 </since_tizen>
151 protected virtual void Dispose(DisposeTypes type)
158 if (type == DisposeTypes.Explicit)
161 //Release your own managed resources here.
162 //You should release all of your own disposable objects here.
166 //Release your own unmanaged resources here.
167 //You should not access any managed member here except static instance.
168 //because the execution order of Finalizes is non-deterministic.
170 //Unreference this instance from Registry.
173 Registry.Unregister(this);
176 if (swigCPtr.Handle != global::System.IntPtr.Zero)
179 NDalicPINVOKE.delete_BaseHandle(swigCPtr);
180 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
187 /// Returns the bool value true to indicate that an operand is true and returns false otherwise.
189 /// <since_tizen> 3 </since_tizen>
190 public static bool operator true(BaseHandle handle)
192 // if the C# object is null, return false
193 if (BaseHandle.ReferenceEquals(handle, null))
197 // returns true if the handle has a body, false otherwise
198 return handle.HasBody();
202 /// Returns the bool false to indicate that an operand is false and returns true otherwise.
204 /// <since_tizen> 3 </since_tizen>
205 public static bool operator false(BaseHandle handle)
207 // if the C# object is null, return true
208 if (BaseHandle.ReferenceEquals(handle, null))
212 return !handle.HasBody();
216 /// Explicit conversion from Handle to bool.
218 /// <since_tizen> 3 </since_tizen>
219 public static explicit operator bool(BaseHandle handle)
221 // if the C# object is null, return false
222 if (BaseHandle.ReferenceEquals(handle, null))
226 // returns true if the handle has a body, false otherwise
227 return handle.HasBody();
231 /// Equality operator
233 /// <since_tizen> 3 </since_tizen>
234 public static bool operator ==(BaseHandle x, BaseHandle y)
236 // if the C# objects are the same return true
237 if (BaseHandle.ReferenceEquals(x, y))
241 if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
243 // drop into native code to see if both handles point to the same body
247 if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
249 if (y.HasBody()) return false;
252 if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
254 if (x.HasBody()) return false;
262 /// Inequality operator. Returns Null if either operand is Null
264 /// <since_tizen> 3 </since_tizen>
265 public static bool operator !=(BaseHandle x, BaseHandle y)
271 /// Logical AND operator.<br />
272 /// It's possible when doing a operator this function (opBitwiseAnd) is never called due to short circuiting.<br />
274 /// <since_tizen> 3 </since_tizen>
275 public static BaseHandle operator &(BaseHandle x, BaseHandle y)
285 /// Logical OR operator for ||.<br />
286 /// It's possible when doing a || this function (opBitwiseOr) is never called due to short circuiting.<br />
288 /// <since_tizen> 3 </since_tizen>
289 public static BaseHandle operator |(BaseHandle x, BaseHandle y)
291 if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
307 /// Logical ! operator
309 /// <since_tizen> 3 </since_tizen>
310 public static bool operator !(BaseHandle x)
312 // if the C# object is null, return true
313 if (BaseHandle.ReferenceEquals(x, null))
327 /// <param name="o">The object should be compared.</param>
328 /// <returns>True if equal.</returns>
329 /// <since_tizen> 5 </since_tizen>
330 public override bool Equals(object o)
332 return base.Equals(o);
336 /// Gets the the hash code of this baseHandle.
338 /// <returns>The Hash Code.</returns>
339 /// <since_tizen> 5 </since_tizen>
340 public override int GetHashCode()
342 return base.GetHashCode();
346 /// Create an instance of BaseHandle.
348 /// <since_tizen> 3 </since_tizen>
349 public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1())
351 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355 /// Create an instance of BaseHandle.
357 /// <param name="handle">The BaseHandle instance.</param>
358 /// <since_tizen> 3 </since_tizen>
359 public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)))
361 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
366 /// Performs an action on this object with the given action name and attributes.
368 /// <param name="actionName">The command for the action.</param>
369 /// <param name="attributes">The list of attributes for the action.</param>
370 /// <returns>The action is performed by the object or not.</returns>
371 /// <since_tizen> 3 </since_tizen>
372 public bool DoAction(string actionName, PropertyMap attributes)
374 bool ret = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
375 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380 /// Returns the type name for the Handle.<br />
381 /// Will return an empty string if the typename does not exist. This will happen for types that
382 /// have not registered with type-registry.
384 /// <returns>The type name. Empty string if the typename does not exist.</returns>
385 /// <since_tizen> 3 </since_tizen>
386 public string GetTypeName()
388 string ret = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr);
389 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
394 /// Returns the type info for the Handle.<br />
396 /// <param name="info">The type information.</param>
397 /// <returns>True If get the type info.</returns>
398 /// <since_tizen> 3 </since_tizen>
399 public bool GetTypeInfo(Tizen.NUI.TypeInfo info)
401 bool ret = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, Tizen.NUI.TypeInfo.getCPtr(info));
402 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
407 /// Resets the handle.
409 /// <since_tizen> 3 </since_tizen>
412 NDalicPINVOKE.BaseHandle_Reset(swigCPtr);
413 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
417 /// To check the BaseHandle instance is equal or not.
419 /// <param name="rhs">The baseHandle instance.</param>
420 /// <returns>True If equal.</returns>
421 /// <since_tizen> 3 </since_tizen>
422 public bool EqualTo(BaseHandle rhs)
424 bool ret = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
425 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
430 /// To check the BaseHandle instance is equal or not.
432 /// <param name="rhs">The baseHandle instance.</param>
433 /// <returns>True If not equal.</returns>
434 /// <since_tizen> 3 </since_tizen>
435 public bool NotEqualTo(BaseHandle rhs)
437 bool ret = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
438 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
442 internal RefObject GetObjectPtr()
444 global::System.IntPtr cPtr = NDalicPINVOKE.BaseHandle_GetObjectPtr(swigCPtr);
445 RefObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new RefObject(cPtr, false);
446 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
451 /// To check the BaseHandle instance has body or not.
453 /// <returns>True If the baseHandle instance has body.</returns>
454 /// <since_tizen> 3 </since_tizen>
455 public bool HasBody()
457 if (disposed == true)
462 bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
463 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
468 /// To check the BaseHandle instance is equal or not.
470 /// <param name="rhs">The baseHandle instance.</param>
471 /// <returns>True If equal.</returns>
472 /// <since_tizen> 3 </since_tizen>
473 public bool IsEqual(BaseHandle rhs)
475 if (disposed == true)
480 bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
481 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
485 internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef
494 /// For internal use.
496 [EditorBrowsable(EditorBrowsableState.Never)]
497 internal NavigationProxy NavigationProxy
499 get { return Navigation as NavigationProxy; }
503 /// Gets the navigation.
505 internal INavigation Navigation
507 get { return (INavigation)GetValue(NavigationProperty); }
508 set { SetValue(NavigationPropertyKey, value); }
512 /// Contains event arguments for the FocusChangeRequested event.
514 public class FocusRequestArgs : EventArgs
518 /// Gets or sets a value that indicates the starting focus state of the element for which a focus change is requested.
520 public bool Focus { get; set; }
523 /// Gets or sets a value that indicates the ending focus state of the element for which a focus change is requested.
525 public bool Result { get; set; }