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 when a property is set.
35 /// <since_tizen> 5 </since_tizen>
36 public event PropertyChangedEventHandler PropertySet;
38 internal void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
40 PropertySet?.Invoke(this, new PropertyChangedEventArgs(propertyName));
43 internal static readonly BindablePropertyKey NavigationPropertyKey = BindableProperty.CreateReadOnly("Navigation", typeof(INavigation), typeof(/*VisualElement*/BaseHandle), default(INavigation));
45 /// Backing store for the Navigation property.
47 internal static readonly BindableProperty NavigationProperty = NavigationPropertyKey.BindableProperty;
49 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
53 /// <since_tizen> 3 </since_tizen>
54 protected bool swigCMemOwn;
55 private bool _registerMe;
57 internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn)
59 //to catch derived classes dali native exceptions
60 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
62 _registerMe = swigCMemOwn = cMemoryOwn;
63 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
65 // using copy constructor to create another native handle so Registry.Unregister works fine.
66 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
68 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
73 // Register this instance of BaseHandle in the registry.
74 Registry.Register(this);
78 internal BaseHandle(global::System.IntPtr cPtr)
80 _registerMe = swigCMemOwn = true;
82 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
84 // using copy constructor to create another native handle so Registry.Unregister works fine.
85 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
86 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
90 // Register this instance of BaseHandle in the registry.
91 Registry.Register(this);
95 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
97 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
100 //A Flag to check who called Dispose(). (By User or DisposeQueue)
101 private bool isDisposeQueued = false;
104 /// A Flat to check if it is already disposed.
106 /// <since_tizen> 3 </since_tizen>
107 protected bool disposed = false;
112 /// <since_tizen> 3 </since_tizen>
115 if (!isDisposeQueued)
117 isDisposeQueued = true;
118 DisposeQueue.Instance.Add(this);
125 /// <since_tizen> 3 </since_tizen>
126 public void Dispose()
128 //Throw excpetion if Dispose() is called in separate thread.
129 if (!Window.IsInstalled())
131 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
136 Dispose(DisposeTypes.Implicit);
140 Dispose(DisposeTypes.Explicit);
141 System.GC.SuppressFinalize(this);
148 /// <since_tizen> 3 </since_tizen>
149 protected virtual void Dispose(DisposeTypes type)
156 if (type == DisposeTypes.Explicit)
159 //Release your own managed resources here.
160 //You should release all of your own disposable objects here.
164 //Release your own unmanaged resources here.
165 //You should not access any managed member here except static instance.
166 //because the execution order of Finalizes is non-deterministic.
168 //Unreference this instance from Registry.
171 Registry.Unregister(this);
174 if (swigCPtr.Handle != global::System.IntPtr.Zero)
177 NDalicPINVOKE.delete_BaseHandle(swigCPtr);
178 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
185 /// Returns the bool value true to indicate that an operand is true and returns false otherwise.
187 /// <since_tizen> 3 </since_tizen>
188 public static bool operator true(BaseHandle handle)
190 // if the C# object is null, return false
191 if (BaseHandle.ReferenceEquals(handle, null))
195 // returns true if the handle has a body, false otherwise
196 return handle.HasBody();
200 /// Returns the bool false to indicate that an operand is false and returns true otherwise.
202 /// <since_tizen> 3 </since_tizen>
203 public static bool operator false(BaseHandle handle)
205 // if the C# object is null, return true
206 if (BaseHandle.ReferenceEquals(handle, null))
210 return !handle.HasBody();
214 /// Explicit conversion from Handle to bool.
216 /// <since_tizen> 3 </since_tizen>
217 public static explicit operator bool(BaseHandle handle)
219 // if the C# object is null, return false
220 if (BaseHandle.ReferenceEquals(handle, null))
224 // returns true if the handle has a body, false otherwise
225 return handle.HasBody();
229 /// Equality operator
231 /// <since_tizen> 3 </since_tizen>
232 public static bool operator ==(BaseHandle x, BaseHandle y)
234 // if the C# objects are the same return true
235 if (BaseHandle.ReferenceEquals(x, y))
239 if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
241 // drop into native code to see if both handles point to the same body
245 if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
247 if (y.HasBody()) return false;
250 if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
252 if (x.HasBody()) return false;
260 /// Inequality operator. Returns Null if either operand is Null
262 /// <since_tizen> 3 </since_tizen>
263 public static bool operator !=(BaseHandle x, BaseHandle y)
269 /// Logical AND operator.<br />
270 /// It's possible when doing a operator this function (opBitwiseAnd) is never called due to short circuiting.<br />
272 /// <since_tizen> 3 </since_tizen>
273 public static BaseHandle operator &(BaseHandle x, BaseHandle y)
283 /// Logical OR operator for ||.<br />
284 /// It's possible when doing a || this function (opBitwiseOr) is never called due to short circuiting.<br />
286 /// <since_tizen> 3 </since_tizen>
287 public static BaseHandle operator |(BaseHandle x, BaseHandle y)
289 if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
305 /// Logical ! operator
307 /// <since_tizen> 3 </since_tizen>
308 public static bool operator !(BaseHandle x)
310 // if the C# object is null, return true
311 if (BaseHandle.ReferenceEquals(x, null))
325 /// <param name="o">The object should be compared.</param>
326 /// <returns>True if equal.</returns>
327 /// <since_tizen> 5 </since_tizen>
328 public override bool Equals(object o)
330 return base.Equals(o);
334 /// Gets the the hash code of this baseHandle.
336 /// <returns>The hash code.</returns>
337 /// <since_tizen> 5 </since_tizen>
338 public override int GetHashCode()
340 return base.GetHashCode();
344 /// Create an instance of BaseHandle.
346 /// <since_tizen> 3 </since_tizen>
347 public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1())
349 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353 /// Create an instance of BaseHandle.
355 /// <param name="handle">The BaseHandle instance.</param>
356 /// <since_tizen> 3 </since_tizen>
357 public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)))
359 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364 /// Performs an action on this object with the given action name and attributes.
366 /// <param name="actionName">The command for the action.</param>
367 /// <param name="attributes">The list of attributes for the action.</param>
368 /// <returns>The action is performed by the object or not.</returns>
369 /// <since_tizen> 3 </since_tizen>
370 public bool DoAction(string actionName, PropertyMap attributes)
372 bool ret = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 /// Returns the type name for the Handle.<br />
379 /// Will return an empty string if the typename does not exist. This will happen for types that
380 /// have not registered with type-registry.
382 /// <returns>The type name. Empty string if the typename does not exist.</returns>
383 /// <since_tizen> 3 </since_tizen>
384 public string GetTypeName()
386 string ret = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr);
387 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
392 /// Returns the type info for the Handle.<br />
394 /// <param name="info">The type information.</param>
395 /// <returns>True If get the type info.</returns>
396 /// <since_tizen> 3 </since_tizen>
397 public bool GetTypeInfo(Tizen.NUI.TypeInfo info)
399 bool ret = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, Tizen.NUI.TypeInfo.getCPtr(info));
400 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
405 /// Resets the handle.
407 /// <since_tizen> 3 </since_tizen>
410 NDalicPINVOKE.BaseHandle_Reset(swigCPtr);
411 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 EqualTo(BaseHandle rhs)
422 bool ret = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
423 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
428 /// To check the BaseHandle instance is equal or not.
430 /// <param name="rhs">The baseHandle instance.</param>
431 /// <returns>True If not equal.</returns>
432 /// <since_tizen> 3 </since_tizen>
433 public bool NotEqualTo(BaseHandle rhs)
435 bool ret = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
436 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
440 internal RefObject GetObjectPtr()
442 global::System.IntPtr cPtr = NDalicPINVOKE.BaseHandle_GetObjectPtr(swigCPtr);
443 RefObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new RefObject(cPtr, false);
444 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
449 /// To check the BaseHandle instance has body or not.
451 /// <returns>True If the baseHandle instance has body.</returns>
452 /// <since_tizen> 3 </since_tizen>
453 public bool HasBody()
455 if (disposed == true)
460 bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
461 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
466 /// To check the BaseHandle instance is equal or not.
468 /// <param name="rhs">The baseHandle instance.</param>
469 /// <returns>True If equal.</returns>
470 /// <since_tizen> 3 </since_tizen>
471 public bool IsEqual(BaseHandle rhs)
473 if (disposed == true)
478 bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
479 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
483 internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef
492 /// For internal use.
494 internal NavigationProxy NavigationProxy
496 get { return Navigation as NavigationProxy; }
500 /// Gets the navigation.
502 internal INavigation Navigation
504 get { return (INavigation)GetValue(NavigationProperty); }
505 set { SetValue(NavigationPropertyKey, value); }
509 /// Contains event arguments for the FocusChangeRequested event.
511 public class FocusRequestArgs : EventArgs
515 /// Gets or sets a value that indicates the starting focus state of the element for which a focus change is requested.
517 public bool Focus { get; set; }
520 /// Gets or sets a value that indicates the ending focus state of the element for which a focus change is requested.
522 public bool Result { get; set; }