2 * Copyright(c) 2021 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.
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
22 namespace Tizen.NUI.BaseComponents
25 /// View is the base class for all views.
27 /// <since_tizen> 3 </since_tizen>
28 public partial class View
30 private EventHandler offWindowEventHandler;
31 private OffWindowEventCallbackType offWindowEventCallback;
32 private EventHandlerWithReturnType<object, WheelEventArgs, bool> interceptWheelHandler;
33 private WheelEventCallbackType interceptWheelCallback;
34 private EventHandlerWithReturnType<object, WheelEventArgs, bool> wheelEventHandler;
35 private WheelEventCallbackType wheelEventCallback;
36 private EventHandlerWithReturnType<object, KeyEventArgs, bool> keyEventHandler;
37 private KeyCallbackType keyCallback;
38 private EventHandlerWithReturnType<object, TouchEventArgs, bool> interceptTouchDataEventHandler;
39 private TouchDataCallbackType interceptTouchDataCallback;
40 private EventHandlerWithReturnType<object, TouchEventArgs, bool> touchDataEventHandler;
41 private TouchDataCallbackType touchDataCallback;
42 private EventHandlerWithReturnType<object, HoverEventArgs, bool> hoverEventHandler;
43 private HoverEventCallbackType hoverEventCallback;
44 private EventHandler<VisibilityChangedEventArgs> visibilityChangedEventHandler;
45 private VisibilityChangedEventCallbackType visibilityChangedEventCallback;
46 private EventHandler keyInputFocusGainedEventHandler;
48 private KeyInputFocusGainedCallbackType keyInputFocusGainedCallback;
49 private EventHandler keyInputFocusLostEventHandler;
51 private KeyInputFocusLostCallbackType keyInputFocusLostCallback;
52 private EventHandler onRelayoutEventHandler;
53 private OnRelayoutEventCallbackType onRelayoutEventCallback;
54 private EventHandler onWindowEventHandler;
55 private OnWindowEventCallbackType onWindowEventCallback;
56 private EventHandler<LayoutDirectionChangedEventArgs> layoutDirectionChangedEventHandler;
57 private LayoutDirectionChangedEventCallbackType layoutDirectionChangedEventCallback;
58 // Resource Ready Signal
59 private EventHandler resourcesLoadedEventHandler;
60 private ResourcesLoadedCallbackType resourcesLoadedCallback;
61 private EventHandler<BackgroundResourceLoadedEventArgs> backgroundResourceLoadedEventHandler;
62 private _backgroundResourceLoadedCallbackType backgroundResourceLoadedCallback;
63 private TouchDataCallbackType hitTestResultDataCallback;
65 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
66 private delegate void OffWindowEventCallbackType(IntPtr control);
67 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
68 private delegate bool WheelEventCallbackType(IntPtr view, IntPtr wheelEvent);
69 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
70 private delegate bool KeyCallbackType(IntPtr control, IntPtr keyEvent);
71 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
72 private delegate bool TouchDataCallbackType(IntPtr view, IntPtr touchData);
73 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
74 private delegate bool HoverEventCallbackType(IntPtr view, IntPtr hoverEvent);
75 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
76 private delegate void VisibilityChangedEventCallbackType(IntPtr data, bool visibility, VisibilityChangeType type);
77 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
78 private delegate void ResourcesLoadedCallbackType(IntPtr control);
79 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
80 private delegate void _backgroundResourceLoadedCallbackType(IntPtr view);
82 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
83 private delegate void KeyInputFocusGainedCallbackType(IntPtr control);
84 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
85 private delegate void KeyInputFocusLostCallbackType(IntPtr control);
87 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
88 private delegate void OnRelayoutEventCallbackType(IntPtr control);
89 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
90 private delegate void OnWindowEventCallbackType(IntPtr control);
91 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
92 private delegate void LayoutDirectionChangedEventCallbackType(IntPtr data, ViewLayoutDirectionType type);
94 // List of dispatch Event
95 private PanGestureDetector panGestureDetector = null;
96 private LongPressGestureDetector longGestureDetector = null;
97 private PinchGestureDetector pinchGestureDetector = null;
98 private TapGestureDetector tapGestureDetector = null;
99 private RotationGestureDetector rotationGestureDetector = null;
100 private int configGestureCount = 0;
101 private bool dispatchTouchEvents = true;
102 private bool dispatchParentTouchEvents = true;
103 private bool dispatchHoverEvents = true;
104 private bool dispatchParentHoverEvents = true;
105 private bool dispatchGestureEvents = true;
106 private bool dispatchParentGestureEvents = true;
107 private bool dispatchTouchMotion = true;
108 private bool dispatchHoverMotion = true;
112 /// Event when a child is removed.
114 /// <since_tizen> 5 </since_tizen>
115 public new event EventHandler<ChildRemovedEventArgs> ChildRemoved;
117 /// Event when a child is added.
119 /// <since_tizen> 5 </since_tizen>
120 public new event EventHandler<ChildAddedEventArgs> ChildAdded;
123 /// An event for the KeyInputFocusGained signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
124 /// The KeyInputFocusGained signal is emitted when the control gets the key input focus.<br />
126 /// <since_tizen> 3 </since_tizen>
127 public event EventHandler FocusGained
131 if (keyInputFocusGainedEventHandler == null)
133 keyInputFocusGainedCallback = OnKeyInputFocusGained;
134 Interop.ViewSignal.KeyInputFocusGainedConnect(SwigCPtr, keyInputFocusGainedCallback.ToHandleRef(this));
135 NDalicPINVOKE.ThrowExceptionIfExists();
137 keyInputFocusGainedEventHandler += value;
142 keyInputFocusGainedEventHandler -= value;
143 if (keyInputFocusGainedEventHandler == null && keyInputFocusGainedCallback != null)
145 Interop.ViewSignal.KeyInputFocusGainedDisconnect(SwigCPtr, keyInputFocusGainedCallback.ToHandleRef(this));
146 NDalicPINVOKE.ThrowExceptionIfExists();
147 keyInputFocusGainedCallback = null;
153 /// An event for the KeyInputFocusLost signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
154 /// The KeyInputFocusLost signal is emitted when the control loses the key input focus.<br />
156 /// <since_tizen> 3 </since_tizen>
157 public event EventHandler FocusLost
161 if (keyInputFocusLostEventHandler == null)
163 keyInputFocusLostCallback = OnKeyInputFocusLost;
164 Interop.ViewSignal.KeyInputFocusLostConnect(SwigCPtr, keyInputFocusLostCallback.ToHandleRef(this));
165 NDalicPINVOKE.ThrowExceptionIfExists();
167 keyInputFocusLostEventHandler += value;
172 keyInputFocusLostEventHandler -= value;
173 if (keyInputFocusLostEventHandler == null && keyInputFocusLostCallback != null)
175 Interop.ViewSignal.KeyInputFocusLostDisconnect(SwigCPtr, keyInputFocusLostCallback.ToHandleRef(this));
176 NDalicPINVOKE.ThrowExceptionIfExists();
177 keyInputFocusLostCallback = null;
183 /// An event for the KeyPressed signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
184 /// The KeyPressed signal is emitted when the key event is received.<br />
186 /// <since_tizen> 3 </since_tizen>
187 public event EventHandlerWithReturnType<object, KeyEventArgs, bool> KeyEvent
191 if (keyEventHandler == null)
193 keyCallback = OnKeyEvent;
194 Interop.ViewSignal.KeyEventConnect(SwigCPtr, keyCallback.ToHandleRef(this));
195 NDalicPINVOKE.ThrowExceptionIfExists();
197 keyEventHandler += value;
202 keyEventHandler -= value;
203 if (keyEventHandler == null && keyCallback != null)
205 Interop.ViewSignal.KeyEventDisconnect(SwigCPtr, keyCallback.ToHandleRef(this));
206 NDalicPINVOKE.ThrowExceptionIfExists();
213 /// An event for the OnRelayout signal which can be used to subscribe or unsubscribe the event handler.<br />
214 /// The OnRelayout signal is emitted after the size has been set on the view during relayout.<br />
216 /// <since_tizen> 3 </since_tizen>
217 public event EventHandler Relayout
221 if (onRelayoutEventHandler == null)
223 onRelayoutEventCallback = OnRelayout;
224 Interop.ActorSignal.OnRelayoutConnect(SwigCPtr, onRelayoutEventCallback.ToHandleRef(this));
225 NDalicPINVOKE.ThrowExceptionIfExists();
227 onRelayoutEventHandler += value;
232 onRelayoutEventHandler -= value;
233 if (onRelayoutEventHandler == null && onRelayoutEventCallback != null)
235 Interop.ActorSignal.OnRelayoutDisconnect(SwigCPtr, onRelayoutEventCallback.ToHandleRef(this));
236 NDalicPINVOKE.ThrowExceptionIfExists();
237 onRelayoutEventCallback = null;
243 /// An event for the touched signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
244 /// The touched signal is emitted when the touch input is received.<br />
245 /// This can receive touch events before child. <br />
246 /// If it returns false, the child can receive the touch event. If it returns true, the touch event is intercepted. So child cannot receive touch event.<br />
248 [EditorBrowsable(EditorBrowsableState.Never)]
249 public event EventHandlerWithReturnType<object, TouchEventArgs, bool> InterceptTouchEvent
253 if (interceptTouchDataEventHandler == null)
255 interceptTouchDataCallback = OnInterceptTouch;
256 Interop.ActorSignal.InterceptTouchConnect(SwigCPtr, interceptTouchDataCallback.ToHandleRef(this));
257 NDalicPINVOKE.ThrowExceptionIfExists();
259 interceptTouchDataEventHandler += value;
264 interceptTouchDataEventHandler -= value;
265 if (interceptTouchDataEventHandler == null && interceptTouchDataCallback != null)
267 Interop.ActorSignal.InterceptTouchDisconnect(SwigCPtr, interceptTouchDataCallback.ToHandleRef(this));
268 NDalicPINVOKE.ThrowExceptionIfExists();
269 interceptTouchDataCallback = null;
275 /// If child view doesn't want the parent's view to intercept the touch, you can set it to true.
277 /// parent.Add(child);
278 /// parent.InterceptTouchEvent += OnInterceptTouchEvent;
279 /// View view = child.GetParent() as View;
280 /// view.DisallowInterceptTouchEvent = true;
281 /// This prevents the parent from intercepting touch.
283 [EditorBrowsable(EditorBrowsableState.Never)]
284 public bool DisallowInterceptTouchEvent { get; set; }
288 /// An event for the touched signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
289 /// The touched signal is emitted when the touch input is received.<br />
291 /// <since_tizen> 3 </since_tizen>
292 public event EventHandlerWithReturnType<object, TouchEventArgs, bool> TouchEvent
296 if (touchDataEventHandler == null)
298 touchDataCallback = OnTouch;
299 Interop.ActorSignal.TouchConnect(SwigCPtr, touchDataCallback.ToHandleRef(this));
300 NDalicPINVOKE.ThrowExceptionIfExists();
302 touchDataEventHandler += value;
307 touchDataEventHandler -= value;
308 if (touchDataEventHandler == null && touchDataCallback != null)
310 Interop.ActorSignal.TouchDisconnect(SwigCPtr, touchDataCallback.ToHandleRef(this));
311 NDalicPINVOKE.ThrowExceptionIfExists();
312 touchDataCallback = null;
318 /// An event for the hovered signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
319 /// The hovered signal is emitted when the hover input is received.<br />
321 /// <since_tizen> 3 </since_tizen>
322 public event EventHandlerWithReturnType<object, HoverEventArgs, bool> HoverEvent
326 if (hoverEventHandler == null)
328 hoverEventCallback = OnHoverEvent;
329 Interop.ActorSignal.HoveredConnect(SwigCPtr, hoverEventCallback.ToHandleRef(this));
330 NDalicPINVOKE.ThrowExceptionIfExists();
332 hoverEventHandler += value;
337 hoverEventHandler -= value;
338 if (hoverEventHandler == null && hoverEventCallback != null)
340 Interop.ActorSignal.HoveredDisconnect(SwigCPtr, hoverEventCallback.ToHandleRef(this));
341 NDalicPINVOKE.ThrowExceptionIfExists();
342 hoverEventCallback = null;
348 /// An event for the wheel which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
349 /// The wheel event is emitted when the wheel input is received.<br />
350 /// This can receive wheel events before child. <br />
351 /// If it returns false, the child can receive the wheel event. If it returns true, the wheel event is intercepted. So child cannot receive wheel event.<br />
353 [EditorBrowsable(EditorBrowsableState.Never)]
354 public event EventHandlerWithReturnType<object, WheelEventArgs, bool> InterceptWheelEvent
358 if (interceptWheelHandler == null)
360 interceptWheelCallback = OnInterceptWheel;
361 Interop.ActorSignal.InterceptWheelConnect(SwigCPtr, interceptWheelCallback.ToHandleRef(this));
362 NDalicPINVOKE.ThrowExceptionIfExists();
364 interceptWheelHandler += value;
369 interceptWheelHandler -= value;
370 if (interceptWheelHandler == null && interceptWheelCallback != null)
372 Interop.ActorSignal.InterceptWheelDisconnect(SwigCPtr, interceptWheelCallback.ToHandleRef(this));
373 NDalicPINVOKE.ThrowExceptionIfExists();
374 interceptWheelCallback = null;
380 /// If child view doesn't want the parent's view to intercept the wheel event, you can set it to true.
382 /// parent.Add(child);
383 /// parent.InterceptWheelEvent += OnInterceptWheelEvent;
384 /// View view = child.GetParent() as View;
385 /// view.DisallowInterceptWheelEvent = true;
386 /// This prevents the parent from intercepting wheel event.
388 [EditorBrowsable(EditorBrowsableState.Never)]
389 public bool DisallowInterceptWheelEvent { get; set; }
392 /// An event for the WheelMoved signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
393 /// The WheelMoved signal is emitted when the wheel event is received.<br />
395 /// <since_tizen> 3 </since_tizen>
396 public event EventHandlerWithReturnType<object, WheelEventArgs, bool> WheelEvent
400 if (wheelEventHandler == null)
402 wheelEventCallback = OnWheelEvent;
403 Interop.ActorSignal.WheelEventConnect(SwigCPtr, wheelEventCallback.ToHandleRef(this));
404 NDalicPINVOKE.ThrowExceptionIfExists();
406 wheelEventHandler += value;
411 wheelEventHandler -= value;
412 if (wheelEventHandler == null && wheelEventCallback != null)
414 Interop.ActorSignal.WheelEventDisconnect(SwigCPtr, wheelEventCallback.ToHandleRef(this));
415 NDalicPINVOKE.ThrowExceptionIfExists();
416 wheelEventCallback = null;
422 /// An event for the OnWindow signal which can be used to subscribe or unsubscribe the event handler.<br />
423 /// The OnWindow signal is emitted after the view has been connected to the window.<br />
425 /// <since_tizen> 3 </since_tizen>
426 public event EventHandler AddedToWindow
430 if (onWindowEventHandler == null)
432 onWindowEventCallback = OnWindow;
433 Interop.ActorSignal.OnSceneConnect(SwigCPtr, onWindowEventCallback.ToHandleRef(this));
434 NDalicPINVOKE.ThrowExceptionIfExists();
436 onWindowEventHandler += value;
441 onWindowEventHandler -= value;
442 if (onWindowEventHandler == null && onWindowEventCallback != null)
444 Interop.ActorSignal.OnSceneDisconnect(SwigCPtr, onWindowEventCallback.ToHandleRef(this));
445 NDalicPINVOKE.ThrowExceptionIfExists();
446 onWindowEventCallback = null;
452 /// An event for the OffWindow signal, which can be used to subscribe or unsubscribe the event handler.<br />
453 /// OffWindow signal is emitted after the view has been disconnected from the window.<br />
455 /// <since_tizen> 3 </since_tizen>
456 public event EventHandler RemovedFromWindow
460 if (offWindowEventHandler == null)
462 offWindowEventCallback = OffWindow;
463 Interop.ActorSignal.OffSceneConnect(SwigCPtr, offWindowEventCallback.ToHandleRef(this));
464 NDalicPINVOKE.ThrowExceptionIfExists();
466 offWindowEventHandler += value;
471 offWindowEventHandler -= value;
472 if (offWindowEventHandler == null && offWindowEventCallback != null)
474 Interop.ActorSignal.OffSceneDisconnect(SwigCPtr, offWindowEventCallback.ToHandleRef(this));
475 NDalicPINVOKE.ThrowExceptionIfExists();
476 offWindowEventCallback = null;
481 /// An event for visibility change which can be used to subscribe or unsubscribe the event handler.<br />
482 /// This event is sent when the visibility of this or a parent view is changed.<br />
486 /// When VisibilityChangedEventArgs.Type is SELF, VisibilityChangedEventArgs.Visibility is true means this View's Visibility property is true.
487 /// When VisibilityChangedEventArgs.Type is PARENT, VisibilityChangedEventArgs.Visibility is true means a parent's Visibility property has changed to true.
490 /// This event is NOT sent if the view becomes transparent (or the reverse), it's ONLY linked with View.Show() and View.Hide().
491 /// For reference, a view is only shown if the view and its parents (up to the root view) are also visible, they are not transparent, and the view has a non-zero size.
492 /// So if its parent is not visible, the view is not shown even though VisibilityChangedEventArgs.Type is SELF and VisibilityChangedEventArgs.Visibility is true.
495 /// <since_tizen> 3 </since_tizen>
496 public event EventHandler<VisibilityChangedEventArgs> VisibilityChanged
500 if (visibilityChangedEventHandler == null)
502 visibilityChangedEventCallback = OnVisibilityChanged;
503 Interop.ActorSignal.VisibilityChangedConnect(SwigCPtr, visibilityChangedEventCallback.ToHandleRef(this));
504 NDalicPINVOKE.ThrowExceptionIfExists();
506 visibilityChangedEventHandler += value;
511 visibilityChangedEventHandler -= value;
512 if (visibilityChangedEventHandler == null && visibilityChangedEventCallback != null)
514 Interop.ActorSignal.VisibilityChangedDisconnect(SwigCPtr, visibilityChangedEventCallback.ToHandleRef(this));
515 NDalicPINVOKE.ThrowExceptionIfExists();
516 visibilityChangedEventCallback = null;
522 /// Event for layout direction change which can be used to subscribe/unsubscribe the event handler.<br />
523 /// This signal is emitted when the layout direction property of this or a parent view is changed.<br />
525 /// <since_tizen> 4 </since_tizen>
526 public event EventHandler<LayoutDirectionChangedEventArgs> LayoutDirectionChanged
530 if (layoutDirectionChangedEventHandler == null)
532 layoutDirectionChangedEventCallback = OnLayoutDirectionChanged;
533 Interop.ActorSignal.LayoutDirectionChangedConnect(SwigCPtr, layoutDirectionChangedEventCallback.ToHandleRef(this));
534 NDalicPINVOKE.ThrowExceptionIfExists();
537 layoutDirectionChangedEventHandler += value;
542 layoutDirectionChangedEventHandler -= value;
544 if (layoutDirectionChangedEventHandler == null && layoutDirectionChangedEventCallback != null)
546 Interop.ActorSignal.LayoutDirectionChangedDisconnect(SwigCPtr, layoutDirectionChangedEventCallback.ToHandleRef(this));
547 NDalicPINVOKE.ThrowExceptionIfExists();
548 layoutDirectionChangedEventCallback = null;
554 /// An event for the ResourcesLoadedSignal signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
555 /// This signal is emitted after all resources required by a view are loaded and ready.<br />
557 /// <since_tizen> 3 </since_tizen>
558 public event EventHandler ResourcesLoaded
562 if (resourcesLoadedEventHandler == null)
564 resourcesLoadedCallback = OnResourcesLoaded;
565 Interop.ViewSignal.ResourceReadyConnect(SwigCPtr, resourcesLoadedCallback.ToHandleRef(this));
566 NDalicPINVOKE.ThrowExceptionIfExists();
568 resourcesLoadedEventHandler += value;
573 resourcesLoadedEventHandler -= value;
574 if (resourcesLoadedEventHandler == null && resourcesLoadedCallback != null)
576 Interop.ViewSignal.ResourceReadyDisconnect(SwigCPtr, resourcesLoadedCallback.ToHandleRef(this));
577 NDalicPINVOKE.ThrowExceptionIfExists();
578 resourcesLoadedCallback = null;
583 private EventHandler _backKeyPressed;
586 /// An event for getting notice when physical back key is pressed.<br />
587 /// This event is emitted BackKey is up.<br />
589 [EditorBrowsable(EditorBrowsableState.Never)]
590 public event EventHandler BackKeyPressed
594 _backKeyPressed += value;
595 BackKeyManager.Instance.Subscriber.Add(this);
600 BackKeyManager.Instance.Subscriber.Remove(this);
601 _backKeyPressed -= value;
606 /// Function for emitting BackKeyPressed event outside of View instance
608 [EditorBrowsable(EditorBrowsableState.Never)]
609 internal void EmitBackKeyPressed()
611 _backKeyPressed.Invoke(this, null);
615 internal event EventHandler<BackgroundResourceLoadedEventArgs> BackgroundResourceLoaded
619 if (backgroundResourceLoadedEventHandler == null)
621 backgroundResourceLoadedCallback = OnBackgroundResourceLoaded;
622 Interop.ViewSignal.ResourceReadyConnect(SwigCPtr, backgroundResourceLoadedCallback.ToHandleRef(this));
623 NDalicPINVOKE.ThrowExceptionIfExists();
625 backgroundResourceLoadedEventHandler += value;
630 backgroundResourceLoadedEventHandler -= value;
631 if (backgroundResourceLoadedEventHandler == null && backgroundResourceLoadedCallback != null)
633 Interop.ViewSignal.ResourceReadyDisconnect(SwigCPtr, backgroundResourceLoadedCallback.ToHandleRef(this));
634 NDalicPINVOKE.ThrowExceptionIfExists();
635 backgroundResourceLoadedCallback = null;
640 private void OnColorChanged(float r, float g, float b, float a)
642 Color = new Color(r, g, b, a);
645 private void OnMinimumSizeChanged(int width, int height)
647 MinimumSize = new Size2D(width, height);
650 private void OnMaximumSizeChanged(int width, int height)
652 MaximumSize = new Size2D(width, height);
655 private void OnPosition2DChanged(int x, int y)
657 SetPosition((float)x, (float)y, 0);
660 private void OnPositionChanged(float x, float y, float z)
662 SetPosition(x, y, z);
665 private void OnSize2DChanged(int width, int height)
667 SetSize((float)width, (float)height, 0);
670 private void OnSizeChanged(float width, float height, float depth)
672 SetSize(width, height, depth);
675 private void OnParentOriginChanged(float x, float y, float z)
677 ParentOrigin = new Position(x, y, z);
680 private void OnPivotPointChanged(float x, float y, float z)
682 PivotPoint = new Position(x, y, z);
685 private void OnImageShadowChanged(ShadowBase instance)
687 ImageShadow = (ImageShadow)instance;
690 private void OnBoxShadowChanged(ShadowBase instance)
692 BoxShadow = (Shadow)instance;
695 private void OnBackgroundImageBorderChanged(int left, int right, int bottom, int top)
697 BackgroundImageBorder = new Rectangle(left, right, bottom, top);
700 private void OnKeyInputFocusGained(IntPtr view)
702 if (IsNativeHandleInvalid())
706 if (keyInputFocusGainedEventHandler != null)
708 using var process = global::System.Diagnostics.Process.GetCurrentProcess();
709 var processId = process.Id;
710 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
711 var me = this.GetType().FullName;
713 throw new ObjectDisposedException(nameof(SwigCPtr), $"Error! NUI's native dali object is already disposed. " +
714 $"OR the native dali object handle of NUI becomes null! \n" +
715 $" process:{processId} thread:{thread}, isDisposed:{this.Disposed}, isDisposeQueued:{this.IsDisposeQueued}, me:{me}\n");
720 if (this.IsDisposeQueued)
722 var process = global::System.Diagnostics.Process.GetCurrentProcess().Id;
723 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
724 var me = this.GetType().FullName;
726 //in this case, the View object is ready to be disposed waiting on DisposeQueue, so event callback should not be invoked!
727 Tizen.Log.Error("NUI", "in this case, the View object is ready to be disposed waiting on DisposeQueue, so event callback should not be invoked! just return here! \n" +
728 $"process:{process} thread:{thread}, isDisposed:{this.Disposed}, isDisposeQueued:{this.IsDisposeQueued}, me:{me}\n");
734 keyInputFocusGainedEventHandler?.Invoke(this, null);
737 private void OnKeyInputFocusLost(IntPtr view)
739 if (IsNativeHandleInvalid())
743 if (keyInputFocusLostEventHandler != null)
745 var process = global::System.Diagnostics.Process.GetCurrentProcess().Id;
746 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
747 var me = this.GetType().FullName;
749 throw new ObjectDisposedException(nameof(SwigCPtr), $"Error! NUI's native dali object is already disposed. " +
750 $"OR the native dali object handle of NUI becomes null! \n" +
751 $" process:{process} thread:{thread}, isDisposed:{this.Disposed}, isDisposeQueued:{this.IsDisposeQueued}, me:{me}\n");
756 if (this.IsDisposeQueued)
758 var process = global::System.Diagnostics.Process.GetCurrentProcess().Id;
759 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
760 var me = this.GetType().FullName;
762 //in this case, the View object is ready to be disposed waiting on DisposeQueue, so event callback should not be invoked!
763 Tizen.Log.Error("NUI", "in this case, the View object is ready to be disposed waiting on DisposeQueue, so event callback should not be invoked! just return here! \n" +
764 $"process:{process} thread:{thread}, isDisposed:{this.Disposed}, isDisposeQueued:{this.IsDisposeQueued}, me:{me}\n");
770 keyInputFocusLostEventHandler?.Invoke(this, null);
773 private bool OnKeyEvent(IntPtr view, IntPtr keyEvent)
775 if (keyEvent == global::System.IntPtr.Zero)
777 NUILog.Error("keyEvent should not be null!");
781 KeyEventArgs e = new KeyEventArgs();
785 e.Key = Tizen.NUI.Key.GetKeyFromPtr(keyEvent);
787 if (keyEventHandler != null)
789 Delegate[] delegateList = keyEventHandler.GetInvocationList();
791 // Oring the result of each callback.
792 foreach (EventHandlerWithReturnType<object, KeyEventArgs, bool> del in delegateList)
794 result |= del(this, e);
801 // Callback for View OnRelayout signal
802 private void OnRelayout(IntPtr data)
804 if (onRelayoutEventHandler != null)
806 onRelayoutEventHandler(this, null);
810 // Callback for View HitTestResultSignal
811 private bool OnHitTestResult(IntPtr view, IntPtr touchData)
813 if (touchData == global::System.IntPtr.Zero)
815 NUILog.Error("touchData should not be null!");
819 TouchEventArgs e = new TouchEventArgs();
820 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
821 return HitTest(e.Touch);
824 // Callback for View TouchSignal
825 private bool OnInterceptTouch(IntPtr view, IntPtr touchData)
827 if (touchData == global::System.IntPtr.Zero)
829 NUILog.Error("touchData should not be null!");
833 // DisallowInterceptTouchEvent prevents the parent from intercepting touch.
834 if (DisallowInterceptTouchEvent)
839 TouchEventArgs e = new TouchEventArgs();
840 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
842 // If DispatchTouchMotion is false, Motion event is not dispatched.
843 if (DispatchTouchMotion == false && e.Touch.GetState(0) == PointStateType.Motion)
848 bool consumed = false;
850 if (interceptTouchDataEventHandler != null)
852 consumed = interceptTouchDataEventHandler(this, e);
858 // Callback for View TouchSignal
859 private bool OnTouch(IntPtr view, IntPtr touchData)
861 if (touchData == global::System.IntPtr.Zero)
863 NUILog.Error("touchData should not be null!");
867 if (DispatchTouchEvents == false)
869 NUILog.Debug("If DispatchTouchEvents is false, it can not dispatch.");
873 TouchEventArgs e = new TouchEventArgs();
874 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
876 // If DispatchTouchMotion is false, Motion event is not dispatched.
877 if (DispatchTouchMotion == false && e.Touch.GetState(0) == PointStateType.Motion)
883 bool consumed = false;
885 if (touchDataEventHandler != null)
887 consumed = touchDataEventHandler(this, e);
890 if (enableControlState && !consumed)
892 consumed = HandleControlStateOnTouch(e.Touch);
895 if (DispatchParentTouchEvents == false)
897 NUILog.Debug("If DispatchParentTouchEvents is false, it can not dispatch to parent.");
904 // Callback for View Hover signal
905 private bool OnHoverEvent(IntPtr view, IntPtr hoverEvent)
907 if (hoverEvent == global::System.IntPtr.Zero)
909 NUILog.Error("hoverEvent should not be null!");
913 if (DispatchHoverEvents == false)
915 NUILog.Debug("If DispatchHoverEvents is false, it can not dispatch.");
919 HoverEventArgs e = new HoverEventArgs();
920 e.Hover = Tizen.NUI.Hover.GetHoverFromPtr(hoverEvent);
922 // If DispatchHoverMotion is false, Motion event is not dispatched.
923 if (DispatchHoverMotion == false && e.Hover.GetState(0) == PointStateType.Motion)
928 bool consumed = false;
930 if (hoverEventHandler != null)
932 consumed = hoverEventHandler(this, e);
935 if (DispatchParentHoverEvents == false && consumed == false)
937 NUILog.Debug("If DispatchParentHoverEvents is false, it can not dispatch to parent.");
944 // Callback for View InterceptWheel signal
945 private bool OnInterceptWheel(IntPtr view, IntPtr wheelEvent)
947 if (wheelEvent == global::System.IntPtr.Zero)
949 NUILog.Error("wheelEvent should not be null!");
953 // DisallowInterceptWheelEvent prevents the parent from intercepting wheel.
954 if (DisallowInterceptWheelEvent)
959 WheelEventArgs e = new WheelEventArgs();
961 e.Wheel = Tizen.NUI.Wheel.GetWheelFromPtr(wheelEvent);
963 bool consumed = false;
965 if (interceptWheelHandler != null)
967 consumed = interceptWheelHandler(this, e);
973 // Callback for View Wheel signal
974 private bool OnWheelEvent(IntPtr view, IntPtr wheelEvent)
976 if (wheelEvent == global::System.IntPtr.Zero)
978 NUILog.Error("wheelEvent should not be null!");
982 WheelEventArgs e = new WheelEventArgs();
984 e.Wheel = Tizen.NUI.Wheel.GetWheelFromPtr(wheelEvent);
986 if (wheelEventHandler != null)
988 return wheelEventHandler(this, e);
993 // Callback for View OnWindow signal
994 private void OnWindow(IntPtr data)
996 if (onWindowEventHandler != null)
998 onWindowEventHandler(this, null);
1002 // Callback for View OffWindow signal
1003 private void OffWindow(IntPtr data)
1005 if (offWindowEventHandler != null)
1007 offWindowEventHandler(this, null);
1011 // Callback for View visibility change signal
1012 private void OnVisibilityChanged(IntPtr data, bool visibility, VisibilityChangeType type)
1014 VisibilityChangedEventArgs e = new VisibilityChangedEventArgs();
1015 if (data != IntPtr.Zero)
1017 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
1019 e.Visibility = visibility;
1022 if (visibilityChangedEventHandler != null)
1024 visibilityChangedEventHandler(this, e);
1028 // Callback for View layout direction change signal
1029 private void OnLayoutDirectionChanged(IntPtr data, ViewLayoutDirectionType type)
1031 LayoutDirectionChangedEventArgs e = new LayoutDirectionChangedEventArgs();
1032 if (data != IntPtr.Zero)
1034 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
1038 if (layoutDirectionChangedEventHandler != null)
1040 layoutDirectionChangedEventHandler(this, e);
1044 private void OnResourcesLoaded(IntPtr view)
1046 if(!CheckResourceReady())
1051 if (resourcesLoadedEventHandler != null)
1053 resourcesLoadedEventHandler(this, null);
1057 private void OnBackgroundResourceLoaded(IntPtr view)
1059 BackgroundResourceLoadedEventArgs e = new BackgroundResourceLoadedEventArgs();
1060 e.Status = (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.BACKGROUND);
1062 if (backgroundResourceLoadedEventHandler != null)
1064 backgroundResourceLoadedEventHandler(this, e);
1069 /// Event argument passed through the ChildAdded event.
1071 /// <since_tizen> 5 </since_tizen>
1072 public class ChildAddedEventArgs : EventArgs
1075 /// Added child view at moment.
1077 /// <since_tizen> 5 </since_tizen>
1078 public View Added { get; set; }
1082 /// Event argument passed through the ChildRemoved event.
1084 /// <since_tizen> 5 </since_tizen>
1085 public class ChildRemovedEventArgs : EventArgs
1088 /// Removed child view at moment.
1090 /// <since_tizen> 5 </since_tizen>
1091 public View Removed { get; set; }
1095 /// Event arguments that passed via the KeyEvent signal.
1097 /// <since_tizen> 3 </since_tizen>
1098 public class KeyEventArgs : EventArgs
1103 /// Key - is the key sent to the view.
1105 /// <since_tizen> 3 </since_tizen>
1120 /// Event arguments that passed via the touch signal.
1122 /// <since_tizen> 3 </since_tizen>
1123 public class TouchEventArgs : EventArgs
1125 private Touch _touch;
1128 /// Touch - contains the information of touch points.
1130 /// <since_tizen> 3 </since_tizen>
1145 /// Event arguments that passed via the hover signal.
1147 /// <since_tizen> 3 </since_tizen>
1148 public class HoverEventArgs : EventArgs
1150 private Hover _hover;
1153 /// Hover - contains touch points that represent the points that are currently being hovered or the points where a hover has stopped.
1155 /// <since_tizen> 3 </since_tizen>
1170 /// Event arguments that passed via the wheel signal.
1172 /// <since_tizen> 3 </since_tizen>
1173 public class WheelEventArgs : EventArgs
1175 private Wheel _wheel;
1178 /// WheelEvent - store a wheel rolling type: MOUSE_WHEEL or CUSTOM_WHEEL.
1180 /// <since_tizen> 3 </since_tizen>
1195 /// Event arguments of visibility changed.
1197 /// <since_tizen> 3 </since_tizen>
1198 public class VisibilityChangedEventArgs : EventArgs
1201 private bool _visibility;
1202 private VisibilityChangeType _type;
1205 /// The view, or child of view, whose visibility has changed.
1207 /// <since_tizen> 3 </since_tizen>
1221 /// Whether the view is now visible or not.
1223 /// <since_tizen> 3 </since_tizen>
1224 public bool Visibility
1232 _visibility = value;
1237 /// Whether the view's visible property has changed or a parent's.
1239 /// <since_tizen> 3 </since_tizen>
1240 public VisibilityChangeType Type
1254 /// Event arguments of layout direction changed.
1256 /// <since_tizen> 4 </since_tizen>
1257 public class LayoutDirectionChangedEventArgs : EventArgs
1260 private ViewLayoutDirectionType _type;
1263 /// The view, or child of view, whose layout direction has changed.
1265 /// <since_tizen> 4 </since_tizen>
1279 /// Whether the view's layout direction property has changed or a parent's.
1281 /// <since_tizen> 4 </since_tizen>
1282 public ViewLayoutDirectionType Type
1295 internal class BackgroundResourceLoadedEventArgs : EventArgs
1297 private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1298 public ResourceLoadingStatusType Status
1312 /// The class represents the information of the situation where the View's control state changes.
1314 [EditorBrowsable(EditorBrowsableState.Never)]
1315 public class ControlStateChangedEventArgs : EventArgs
1318 /// Create an instance with mandatory fields.
1320 /// <param name="previousState">The previous control state.</param>
1321 /// <param name="currentState">The current control state.</param>
1322 [EditorBrowsable(EditorBrowsableState.Never)]
1323 public ControlStateChangedEventArgs(ControlState previousState, ControlState currentState)
1325 PreviousState = previousState;
1326 CurrentState = currentState;
1330 /// The previous control state.
1332 [EditorBrowsable(EditorBrowsableState.Never)]
1333 public ControlState PreviousState { get; }
1336 /// The current control state.
1338 [EditorBrowsable(EditorBrowsableState.Never)]
1339 public ControlState CurrentState { get; }
1343 /// The expanded touch area.
1344 /// TouchArea can expand the view's touchable area.<br/>
1345 /// If you set the TouchAreaOffset on an view, when you touch the view, the touch area is used rather than the size of the view.<br/>
1348 /// This is based on the top left x, y coordinates.<br/>
1349 /// For example) <br/>
1351 /// view.Size = new Size(100, 100);
1352 /// view.TouchAreaOffset = new Offset(-10, 20, 30, -40); // left, right, bottom, top
1354 /// Then, touch area is 130x170.<br/>
1355 /// This is view.width + TouchAreaOffset.right - TouchAreaOffset.left and view.height + TouchAreaOffset.bottom - TouchAreaOffset.top <br/>
1356 /// +---------------------+ <br/>
1362 /// | +----+----+ | <br/>
1364 /// | -10| | 20 | <br/>
1365 /// |<---+ +----->| <br/>
1368 /// | +----+----+ | <br/>
1373 /// +---------------------+ <br/>
1375 [EditorBrowsable(EditorBrowsableState.Never)]
1376 public Offset TouchAreaOffset
1380 return (Offset)GetValue(TouchAreaOffsetProperty);
1384 SetValue(TouchAreaOffsetProperty, value);
1385 NotifyPropertyChanged();
1389 private Offset InternalTouchAreaOffset
1393 Interop.ActorInternal.GetTouchAreaOffset(SwigCPtr, out int left, out int right, out int bottom, out int top);
1394 if (NDalicPINVOKE.SWIGPendingException.Pending)
1395 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1396 return new Offset(left, right, bottom, top);
1400 Interop.ActorInternal.SetTouchAreaOffset(SwigCPtr, value.Left, value.Right, value.Bottom, value.Top);
1401 if (NDalicPINVOKE.SWIGPendingException.Pending)
1402 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1408 /// Gets or sets the status of whether the view should emit key event signals.
1409 /// If a View's DispatchKeyEvents is set to false, then itself and parents will not receive key event signals.
1411 [EditorBrowsable(EditorBrowsableState.Never)]
1412 public bool DispatchKeyEvents
1416 return (bool)GetValue(DispatchKeyEventsProperty);
1420 SetValue(DispatchKeyEventsProperty, value);
1421 NotifyPropertyChanged();
1426 /// Gets or sets the status of whether touch events can be dispatched.
1427 /// If a View's DispatchTouchEvents is set to false, then it's can not will receive touch and parents will not receive a touch event signal either.
1428 /// This works without adding a TouchEvent callback in the View.
1430 /// If the <see cref="Tizen.NUI.BaseComponents.View.Sensitive"/> is a property that determines whether or not to be hittable, then this property prevents the propagation of the hit touch event.
1433 [EditorBrowsable(EditorBrowsableState.Never)]
1434 public bool DispatchTouchEvents
1438 return dispatchTouchEvents;
1442 if (dispatchTouchEvents != value)
1444 dispatchTouchEvents = value;
1445 if (dispatchTouchEvents == false)
1447 TouchEvent += OnDispatchTouchEvent;
1451 TouchEvent -= OnDispatchTouchEvent;
1457 private bool OnDispatchTouchEvent(object source, View.TouchEventArgs e)
1463 /// Gets or sets the status of whether touch events can be dispatched to the parent.
1464 /// If a View's DispatchParentTouchEvents is set to false, then parents will not receive a touch event signal either.
1465 /// This works without adding a TouchEvent callback in the View.
1467 /// If the <see cref="Tizen.NUI.BaseComponents.View.Sensitive"/> is a property that determines whether or not to be hittable, then this property prevents the propagation of the hit touch event.
1470 [EditorBrowsable(EditorBrowsableState.Never)]
1471 public bool DispatchParentTouchEvents
1475 return dispatchParentTouchEvents;
1479 if (dispatchParentTouchEvents != value)
1481 dispatchParentTouchEvents = value;
1482 if (dispatchParentTouchEvents == false)
1484 TouchEvent += OnDispatchParentTouchEvent;
1488 TouchEvent -= OnDispatchParentTouchEvent;
1494 private bool OnDispatchParentTouchEvent(object source, View.TouchEventArgs e)
1500 /// Gets or sets the status of whether hover events can be dispatched.
1501 /// If a View's DispatchHoverEvents is set to false, then it's can not will receive hover event and parents will not receive a hover event signal either.
1502 /// This works without adding a HoverEvent callback in the View.
1504 /// If the <see cref="Tizen.NUI.BaseComponents.View.Sensitive"/> is a property that determines whether or not to be hittable, then this property prevents the propagation of the hit hover event.
1507 [EditorBrowsable(EditorBrowsableState.Never)]
1508 public bool DispatchHoverEvents
1512 return dispatchHoverEvents;
1516 if (dispatchHoverEvents != value)
1518 dispatchHoverEvents = value;
1519 if (dispatchHoverEvents == false)
1521 HoverEvent += OnDispatchHoverEvent;
1525 HoverEvent -= OnDispatchHoverEvent;
1531 private bool OnDispatchHoverEvent(object source, View.HoverEventArgs e)
1537 /// Gets or sets the status of whether hover events can be dispatched to the parent.
1538 /// If a View's DispatchParentHoverEvents is set to false, then parents will not receive a hover event signal either.
1539 /// This works without adding a HoverEvent callback in the View.
1541 /// If the <see cref="Tizen.NUI.BaseComponents.View.Sensitive"/> is a property that determines whether or not to be hittable, then this property prevents the propagation of the hit hover event.
1544 [EditorBrowsable(EditorBrowsableState.Never)]
1545 public bool DispatchParentHoverEvents
1549 return dispatchParentHoverEvents;
1553 if (dispatchParentHoverEvents != value)
1555 dispatchParentHoverEvents = value;
1556 if (dispatchParentHoverEvents == false)
1558 HoverEvent += OnDispatchParentHoverEvent;
1562 HoverEvent -= OnDispatchParentHoverEvent;
1568 private bool OnDispatchParentHoverEvent(object source, View.HoverEventArgs e)
1574 /// Gets or sets the status of whether the view should emit Gesture event signals.
1575 /// If a View's DispatchGestureEvents is set to false, then itself and parents will not receive all gesture event signals.
1576 /// The itself and parents does not receive tap, pinch, pan, rotation, or longpress gestures.
1578 [EditorBrowsable(EditorBrowsableState.Never)]
1579 public bool DispatchGestureEvents
1583 return dispatchGestureEvents;
1587 if (dispatchGestureEvents != value)
1589 dispatchGestureEvents = value;
1590 ConfigGestureDetector(dispatchGestureEvents);
1596 /// Gets or sets the status of whether the view should emit Gesture event signals.
1597 /// If a View's DispatchParentGestureEvents is set to false, then parents will not receive all gesture event signals.
1598 /// The parents does not receive tap, pinch, pan, rotation, or longpress gestures.
1600 [EditorBrowsable(EditorBrowsableState.Never)]
1601 public bool DispatchParentGestureEvents
1605 return dispatchParentGestureEvents;
1609 if (dispatchParentGestureEvents != value)
1611 dispatchParentGestureEvents = value;
1612 ConfigGestureDetector(dispatchParentGestureEvents);
1617 private void ConfigGestureDetector(bool dispatch)
1619 if (panGestureDetector == null) panGestureDetector = new PanGestureDetector();
1620 if (longGestureDetector == null) longGestureDetector = new LongPressGestureDetector();
1621 if (pinchGestureDetector == null) pinchGestureDetector = new PinchGestureDetector();
1622 if (tapGestureDetector == null) tapGestureDetector = new TapGestureDetector();
1623 if (rotationGestureDetector == null) rotationGestureDetector = new RotationGestureDetector();
1625 if (dispatch == true)
1627 configGestureCount = configGestureCount > 0 ? configGestureCount - 1 : 0;
1628 if (configGestureCount == 0)
1630 panGestureDetector.Detach(this);
1631 longGestureDetector.Detach(this);
1632 pinchGestureDetector.Detach(this);
1633 tapGestureDetector.Detach(this);
1634 rotationGestureDetector.Detach(this);
1636 panGestureDetector.Detected -= OnGestureDetected;
1637 longGestureDetector.Detected -= OnGestureDetected;
1638 pinchGestureDetector.Detected -= OnGestureDetected;
1639 tapGestureDetector.Detected -= OnGestureDetected;
1640 rotationGestureDetector.Detected -= OnGestureDetected;
1645 if (configGestureCount == 0)
1647 panGestureDetector.Attach(this);
1648 longGestureDetector.Attach(this);
1649 pinchGestureDetector.Attach(this);
1650 tapGestureDetector.Attach(this);
1651 rotationGestureDetector.Attach(this);
1653 panGestureDetector.Detected += OnGestureDetected;
1654 longGestureDetector.Detected += OnGestureDetected;
1655 pinchGestureDetector.Detected += OnGestureDetected;
1656 tapGestureDetector.Detected += OnGestureDetected;
1657 rotationGestureDetector.Detected += OnGestureDetected;
1659 configGestureCount++;
1663 private void OnGestureDetected(object source, EventArgs e)
1665 // Does notting. This is to consume the gesture.
1669 /// Gets or sets the status of whether motion event of Touch can be dispatched.
1670 /// If a View's DispatchTouchMotion is set to false, then it's can not will receive motion event of TouchEvent.
1672 [EditorBrowsable(EditorBrowsableState.Never)]
1673 public bool DispatchTouchMotion
1677 return dispatchTouchMotion;
1681 dispatchTouchMotion = value;
1686 /// Gets or sets the status of whether motion event of Hover can be dispatched.
1687 /// If a View's DispatchHoverMotion is set to false, then it's can not will receive motion event of HoverEvent.
1689 [EditorBrowsable(EditorBrowsableState.Never)]
1690 public bool DispatchHoverMotion
1694 return dispatchHoverMotion;
1698 dispatchHoverMotion = value;