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.StdCall)]
66 private delegate void OffWindowEventCallbackType(IntPtr control);
67 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
68 private delegate bool WheelEventCallbackType(IntPtr view, IntPtr wheelEvent);
69 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
70 private delegate bool KeyCallbackType(IntPtr control, IntPtr keyEvent);
71 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
72 private delegate bool TouchDataCallbackType(IntPtr view, IntPtr touchData);
73 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
74 private delegate bool HoverEventCallbackType(IntPtr view, IntPtr hoverEvent);
75 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
76 private delegate void VisibilityChangedEventCallbackType(IntPtr data, bool visibility, VisibilityChangeType type);
77 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
78 private delegate void ResourcesLoadedCallbackType(IntPtr control);
79 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
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.StdCall)]
88 private delegate void OnRelayoutEventCallbackType(IntPtr control);
89 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
90 private delegate void OnWindowEventCallbackType(IntPtr control);
91 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
92 private delegate void LayoutDirectionChangedEventCallbackType(IntPtr data, ViewLayoutDirectionType type);
95 /// Event when a child is removed.
97 /// <since_tizen> 5 </since_tizen>
98 public new event EventHandler<ChildRemovedEventArgs> ChildRemoved;
100 /// Event when a child is added.
102 /// <since_tizen> 5 </since_tizen>
103 public new event EventHandler<ChildAddedEventArgs> ChildAdded;
106 /// An event for the KeyInputFocusGained signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
107 /// The KeyInputFocusGained signal is emitted when the control gets the key input focus.<br />
109 /// <since_tizen> 3 </since_tizen>
110 public event EventHandler FocusGained
114 if (keyInputFocusGainedEventHandler == null)
116 keyInputFocusGainedCallback = OnKeyInputFocusGained;
117 Interop.ViewSignal.KeyInputFocusGainedConnect(SwigCPtr, keyInputFocusGainedCallback.ToHandleRef(this));
118 NDalicPINVOKE.ThrowExceptionIfExists();
120 keyInputFocusGainedEventHandler += value;
125 keyInputFocusGainedEventHandler -= value;
126 if (keyInputFocusGainedEventHandler == null && keyInputFocusGainedCallback != null)
128 Interop.ViewSignal.KeyInputFocusGainedDisconnect(SwigCPtr, keyInputFocusGainedCallback.ToHandleRef(this));
129 NDalicPINVOKE.ThrowExceptionIfExists();
130 keyInputFocusGainedCallback = null;
136 /// An event for the KeyInputFocusLost signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
137 /// The KeyInputFocusLost signal is emitted when the control loses the key input focus.<br />
139 /// <since_tizen> 3 </since_tizen>
140 public event EventHandler FocusLost
144 if (keyInputFocusLostEventHandler == null)
146 keyInputFocusLostCallback = OnKeyInputFocusLost;
147 Interop.ViewSignal.KeyInputFocusLostConnect(SwigCPtr, keyInputFocusLostCallback.ToHandleRef(this));
148 NDalicPINVOKE.ThrowExceptionIfExists();
150 keyInputFocusLostEventHandler += value;
155 keyInputFocusLostEventHandler -= value;
156 if (keyInputFocusLostEventHandler == null && keyInputFocusLostCallback != null)
158 Interop.ViewSignal.KeyInputFocusLostDisconnect(SwigCPtr, keyInputFocusLostCallback.ToHandleRef(this));
159 NDalicPINVOKE.ThrowExceptionIfExists();
160 keyInputFocusLostCallback = null;
166 /// An event for the KeyPressed signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
167 /// The KeyPressed signal is emitted when the key event is received.<br />
169 /// <since_tizen> 3 </since_tizen>
170 public event EventHandlerWithReturnType<object, KeyEventArgs, bool> KeyEvent
174 if (keyEventHandler == null)
176 keyCallback = OnKeyEvent;
177 Interop.ViewSignal.KeyEventConnect(SwigCPtr, keyCallback.ToHandleRef(this));
178 NDalicPINVOKE.ThrowExceptionIfExists();
180 keyEventHandler += value;
185 keyEventHandler -= value;
186 if (keyEventHandler == null && keyCallback != null)
188 Interop.ViewSignal.KeyEventDisconnect(SwigCPtr, keyCallback.ToHandleRef(this));
189 NDalicPINVOKE.ThrowExceptionIfExists();
196 /// An event for the OnRelayout signal which can be used to subscribe or unsubscribe the event handler.<br />
197 /// The OnRelayout signal is emitted after the size has been set on the view during relayout.<br />
199 /// <since_tizen> 3 </since_tizen>
200 public event EventHandler Relayout
204 if (onRelayoutEventHandler == null)
206 onRelayoutEventCallback = OnRelayout;
207 Interop.ActorSignal.OnRelayoutConnect(SwigCPtr, onRelayoutEventCallback.ToHandleRef(this));
208 NDalicPINVOKE.ThrowExceptionIfExists();
210 onRelayoutEventHandler += value;
215 onRelayoutEventHandler -= value;
216 if (onRelayoutEventHandler == null && onRelayoutEventCallback != null)
218 Interop.ActorSignal.OnRelayoutDisconnect(SwigCPtr, onRelayoutEventCallback.ToHandleRef(this));
219 NDalicPINVOKE.ThrowExceptionIfExists();
220 onRelayoutEventCallback = null;
226 /// An event for the touched signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
227 /// The touched signal is emitted when the touch input is received.<br />
228 /// This can receive touch events before child. <br />
229 /// 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 />
231 [EditorBrowsable(EditorBrowsableState.Never)]
232 public event EventHandlerWithReturnType<object, TouchEventArgs, bool> InterceptTouchEvent
236 if (interceptTouchDataEventHandler == null)
238 interceptTouchDataCallback = OnInterceptTouch;
239 Interop.ActorSignal.InterceptTouchConnect(SwigCPtr, interceptTouchDataCallback.ToHandleRef(this));
240 NDalicPINVOKE.ThrowExceptionIfExists();
242 interceptTouchDataEventHandler += value;
247 interceptTouchDataEventHandler -= value;
248 if (interceptTouchDataEventHandler == null && interceptTouchDataCallback != null)
250 Interop.ActorSignal.InterceptTouchDisconnect(SwigCPtr, interceptTouchDataCallback.ToHandleRef(this));
251 NDalicPINVOKE.ThrowExceptionIfExists();
252 interceptTouchDataCallback = null;
258 /// If child view doesn't want the parent's view to intercept the touch, you can set it to true.
260 /// parent.Add(child);
261 /// parent.InterceptTouchEvent += OnInterceptTouchEvent;
262 /// View view = child.GetParent() as View;
263 /// view.DisallowInterceptTouchEvent = true;
264 /// This prevents the parent from intercepting touch.
266 [EditorBrowsable(EditorBrowsableState.Never)]
267 public bool DisallowInterceptTouchEvent { get; set; }
271 /// An event for the touched signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
272 /// The touched signal is emitted when the touch input is received.<br />
274 /// <since_tizen> 3 </since_tizen>
275 public event EventHandlerWithReturnType<object, TouchEventArgs, bool> TouchEvent
279 if (touchDataEventHandler == null)
281 touchDataCallback = OnTouch;
282 Interop.ActorSignal.TouchConnect(SwigCPtr, touchDataCallback.ToHandleRef(this));
283 NDalicPINVOKE.ThrowExceptionIfExists();
285 touchDataEventHandler += value;
290 touchDataEventHandler -= value;
291 if (touchDataEventHandler == null && touchDataCallback != null)
293 Interop.ActorSignal.TouchDisconnect(SwigCPtr, touchDataCallback.ToHandleRef(this));
294 NDalicPINVOKE.ThrowExceptionIfExists();
295 touchDataCallback = null;
301 /// An event for the hovered signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
302 /// The hovered signal is emitted when the hover input is received.<br />
304 /// <since_tizen> 3 </since_tizen>
305 public event EventHandlerWithReturnType<object, HoverEventArgs, bool> HoverEvent
309 if (hoverEventHandler == null)
311 hoverEventCallback = OnHoverEvent;
312 Interop.ActorSignal.HoveredConnect(SwigCPtr, hoverEventCallback.ToHandleRef(this));
313 NDalicPINVOKE.ThrowExceptionIfExists();
315 hoverEventHandler += value;
320 hoverEventHandler -= value;
321 if (hoverEventHandler == null && hoverEventCallback != null)
323 Interop.ActorSignal.HoveredDisconnect(SwigCPtr, hoverEventCallback.ToHandleRef(this));
324 NDalicPINVOKE.ThrowExceptionIfExists();
325 hoverEventCallback = null;
331 /// An event for the wheel which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
332 /// The wheel event is emitted when the wheel input is received.<br />
333 /// This can receive wheel events before child. <br />
334 /// 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 />
336 [EditorBrowsable(EditorBrowsableState.Never)]
337 public event EventHandlerWithReturnType<object, WheelEventArgs, bool> InterceptWheelEvent
341 if (interceptWheelHandler == null)
343 interceptWheelCallback = OnInterceptWheel;
344 Interop.ActorSignal.InterceptWheelConnect(SwigCPtr, interceptWheelCallback.ToHandleRef(this));
345 NDalicPINVOKE.ThrowExceptionIfExists();
347 interceptWheelHandler += value;
352 interceptWheelHandler -= value;
353 if (interceptWheelHandler == null && interceptWheelCallback != null)
355 Interop.ActorSignal.InterceptWheelDisconnect(SwigCPtr, interceptWheelCallback.ToHandleRef(this));
356 NDalicPINVOKE.ThrowExceptionIfExists();
357 interceptWheelCallback = null;
363 /// If child view doesn't want the parent's view to intercept the wheel event, you can set it to true.
365 /// parent.Add(child);
366 /// parent.InterceptWheelEvent += OnInterceptWheelEvent;
367 /// View view = child.GetParent() as View;
368 /// view.DisallowInterceptWheelEvent = true;
369 /// This prevents the parent from intercepting wheel event.
371 [EditorBrowsable(EditorBrowsableState.Never)]
372 public bool DisallowInterceptWheelEvent { get; set; }
375 /// An event for the WheelMoved signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
376 /// The WheelMoved signal is emitted when the wheel event is received.<br />
378 /// <since_tizen> 3 </since_tizen>
379 public event EventHandlerWithReturnType<object, WheelEventArgs, bool> WheelEvent
383 if (wheelEventHandler == null)
385 wheelEventCallback = OnWheelEvent;
386 Interop.ActorSignal.WheelEventConnect(SwigCPtr, wheelEventCallback.ToHandleRef(this));
387 NDalicPINVOKE.ThrowExceptionIfExists();
389 wheelEventHandler += value;
394 wheelEventHandler -= value;
395 if (wheelEventHandler == null && wheelEventCallback != null)
397 Interop.ActorSignal.WheelEventDisconnect(SwigCPtr, wheelEventCallback.ToHandleRef(this));
398 NDalicPINVOKE.ThrowExceptionIfExists();
399 wheelEventCallback = null;
405 /// An event for the OnWindow signal which can be used to subscribe or unsubscribe the event handler.<br />
406 /// The OnWindow signal is emitted after the view has been connected to the window.<br />
408 /// <since_tizen> 3 </since_tizen>
409 public event EventHandler AddedToWindow
413 if (onWindowEventHandler == null)
415 onWindowEventCallback = OnWindow;
416 Interop.ActorSignal.OnSceneConnect(SwigCPtr, onWindowEventCallback.ToHandleRef(this));
417 NDalicPINVOKE.ThrowExceptionIfExists();
419 onWindowEventHandler += value;
424 onWindowEventHandler -= value;
425 if (onWindowEventHandler == null && onWindowEventCallback != null)
427 Interop.ActorSignal.OnSceneDisconnect(SwigCPtr, onWindowEventCallback.ToHandleRef(this));
428 NDalicPINVOKE.ThrowExceptionIfExists();
429 onWindowEventCallback = null;
435 /// An event for the OffWindow signal, which can be used to subscribe or unsubscribe the event handler.<br />
436 /// OffWindow signal is emitted after the view has been disconnected from the window.<br />
438 /// <since_tizen> 3 </since_tizen>
439 public event EventHandler RemovedFromWindow
443 if (offWindowEventHandler == null)
445 offWindowEventCallback = OffWindow;
446 Interop.ActorSignal.OffSceneConnect(SwigCPtr, offWindowEventCallback.ToHandleRef(this));
447 NDalicPINVOKE.ThrowExceptionIfExists();
449 offWindowEventHandler += value;
454 offWindowEventHandler -= value;
455 if (offWindowEventHandler == null && offWindowEventCallback != null)
457 Interop.ActorSignal.OffSceneDisconnect(SwigCPtr, offWindowEventCallback.ToHandleRef(this));
458 NDalicPINVOKE.ThrowExceptionIfExists();
459 offWindowEventCallback = null;
464 /// An event for visibility change which can be used to subscribe or unsubscribe the event handler.<br />
465 /// This event is sent when the visibility of this or a parent view is changed.<br />
469 /// When VisibilityChangedEventArgs.Type is SELF, VisibilityChangedEventArgs.Visibility is true means this View's Visibility property is true.
470 /// When VisibilityChangedEventArgs.Type is PARENT, VisibilityChangedEventArgs.Visibility is true means a parent's Visibility property has changed to true.
473 /// This event is NOT sent if the view becomes transparent (or the reverse), it's ONLY linked with View.Show() and View.Hide().
474 /// 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.
475 /// So if its parent is not visible, the view is not shown even though VisibilityChangedEventArgs.Type is SELF and VisibilityChangedEventArgs.Visibility is true.
478 /// <since_tizen> 3 </since_tizen>
479 public event EventHandler<VisibilityChangedEventArgs> VisibilityChanged
483 if (visibilityChangedEventHandler == null)
485 visibilityChangedEventCallback = OnVisibilityChanged;
486 Interop.ActorSignal.VisibilityChangedConnect(SwigCPtr, visibilityChangedEventCallback.ToHandleRef(this));
487 NDalicPINVOKE.ThrowExceptionIfExists();
489 visibilityChangedEventHandler += value;
494 visibilityChangedEventHandler -= value;
495 if (visibilityChangedEventHandler == null && visibilityChangedEventCallback != null)
497 Interop.ActorSignal.VisibilityChangedDisconnect(SwigCPtr, visibilityChangedEventCallback.ToHandleRef(this));
498 NDalicPINVOKE.ThrowExceptionIfExists();
499 visibilityChangedEventCallback = null;
505 /// Event for layout direction change which can be used to subscribe/unsubscribe the event handler.<br />
506 /// This signal is emitted when the layout direction property of this or a parent view is changed.<br />
508 /// <since_tizen> 4 </since_tizen>
509 public event EventHandler<LayoutDirectionChangedEventArgs> LayoutDirectionChanged
513 if (layoutDirectionChangedEventHandler == null)
515 layoutDirectionChangedEventCallback = OnLayoutDirectionChanged;
516 Interop.ActorSignal.LayoutDirectionChangedConnect(SwigCPtr, layoutDirectionChangedEventCallback.ToHandleRef(this));
517 NDalicPINVOKE.ThrowExceptionIfExists();
520 layoutDirectionChangedEventHandler += value;
525 layoutDirectionChangedEventHandler -= value;
527 if (layoutDirectionChangedEventHandler == null && layoutDirectionChangedEventCallback != null)
529 Interop.ActorSignal.LayoutDirectionChangedDisconnect(SwigCPtr, layoutDirectionChangedEventCallback.ToHandleRef(this));
530 NDalicPINVOKE.ThrowExceptionIfExists();
531 layoutDirectionChangedEventCallback = null;
537 /// An event for the ResourcesLoadedSignal signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
538 /// This signal is emitted after all resources required by a view are loaded and ready.<br />
540 /// <since_tizen> 3 </since_tizen>
541 public event EventHandler ResourcesLoaded
545 if (resourcesLoadedEventHandler == null)
547 resourcesLoadedCallback = OnResourcesLoaded;
548 Interop.ViewSignal.ResourceReadyConnect(SwigCPtr, resourcesLoadedCallback.ToHandleRef(this));
549 NDalicPINVOKE.ThrowExceptionIfExists();
551 resourcesLoadedEventHandler += value;
556 resourcesLoadedEventHandler -= value;
557 if (resourcesLoadedEventHandler == null && resourcesLoadedCallback != null)
559 Interop.ViewSignal.ResourceReadyDisconnect(SwigCPtr, resourcesLoadedCallback.ToHandleRef(this));
560 NDalicPINVOKE.ThrowExceptionIfExists();
561 resourcesLoadedCallback = null;
566 private EventHandler _backKeyPressed;
569 /// An event for getting notice when physical back key is pressed.<br />
570 /// This event is emitted BackKey is up.<br />
572 [EditorBrowsable(EditorBrowsableState.Never)]
573 public event EventHandler BackKeyPressed
577 _backKeyPressed += value;
578 BackKeyManager.Instance.Subscriber.Add(this);
583 BackKeyManager.Instance.Subscriber.Remove(this);
584 _backKeyPressed -= value;
589 /// Function for emitting BackKeyPressed event outside of View instance
591 [EditorBrowsable(EditorBrowsableState.Never)]
592 internal void EmitBackKeyPressed()
594 _backKeyPressed.Invoke(this, null);
598 internal event EventHandler<BackgroundResourceLoadedEventArgs> BackgroundResourceLoaded
602 if (backgroundResourceLoadedEventHandler == null)
604 backgroundResourceLoadedCallback = OnBackgroundResourceLoaded;
605 Interop.ViewSignal.ResourceReadyConnect(SwigCPtr, backgroundResourceLoadedCallback.ToHandleRef(this));
606 NDalicPINVOKE.ThrowExceptionIfExists();
608 backgroundResourceLoadedEventHandler += value;
613 backgroundResourceLoadedEventHandler -= value;
614 if (backgroundResourceLoadedEventHandler == null && backgroundResourceLoadedCallback != null)
616 Interop.ViewSignal.ResourceReadyDisconnect(SwigCPtr, backgroundResourceLoadedCallback.ToHandleRef(this));
617 NDalicPINVOKE.ThrowExceptionIfExists();
618 backgroundResourceLoadedCallback = null;
623 private void OnColorChanged(float r, float g, float b, float a)
625 Color = new Color(r, g, b, a);
628 private void OnMinimumSizeChanged(int width, int height)
630 MinimumSize = new Size2D(width, height);
633 private void OnMaximumSizeChanged(int width, int height)
635 MaximumSize = new Size2D(width, height);
638 private void OnPosition2DChanged(int x, int y)
640 SetPosition((float)x, (float)y, 0);
643 private void OnPositionChanged(float x, float y, float z)
645 SetPosition(x, y, z);
648 private void OnSize2DChanged(int width, int height)
650 SetSize((float)width, (float)height, 0);
653 private void OnSizeChanged(float width, float height, float depth)
655 SetSize(width, height, depth);
658 private void OnParentOriginChanged(float x, float y, float z)
660 ParentOrigin = new Position(x, y, z);
663 private void OnPivotPointChanged(float x, float y, float z)
665 PivotPoint = new Position(x, y, z);
668 private void OnImageShadowChanged(ShadowBase instance)
670 ImageShadow = (ImageShadow)instance;
673 private void OnBoxShadowChanged(ShadowBase instance)
675 BoxShadow = (Shadow)instance;
678 private void OnBackgroundImageBorderChanged(int left, int right, int bottom, int top)
680 BackgroundImageBorder = new Rectangle(left, right, bottom, top);
683 private void OnKeyInputFocusGained(IntPtr view)
685 if (IsNativeHandleInvalid())
689 if (keyInputFocusGainedEventHandler != null)
691 var process = global::System.Diagnostics.Process.GetCurrentProcess().Id;
692 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
693 var me = this.GetType().FullName;
695 throw new ObjectDisposedException(nameof(SwigCPtr), $"Error! NUI's native dali object is already disposed. " +
696 $"OR the native dali object handle of NUI becomes null! \n" +
697 $" process:{process} thread:{thread}, isDisposed:{this.Disposed}, isDisposeQueued:{this.IsDisposeQueued}, me:{me}\n");
702 if (this.IsDisposeQueued)
704 var process = global::System.Diagnostics.Process.GetCurrentProcess().Id;
705 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
706 var me = this.GetType().FullName;
708 //in this case, the View object is ready to be disposed waiting on DisposeQueue, so event callback should not be invoked!
709 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" +
710 $"process:{process} thread:{thread}, isDisposed:{this.Disposed}, isDisposeQueued:{this.IsDisposeQueued}, me:{me}\n");
716 keyInputFocusGainedEventHandler?.Invoke(this, null);
719 private void OnKeyInputFocusLost(IntPtr view)
721 if (IsNativeHandleInvalid())
725 if (keyInputFocusLostEventHandler != null)
727 var process = global::System.Diagnostics.Process.GetCurrentProcess().Id;
728 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
729 var me = this.GetType().FullName;
731 throw new ObjectDisposedException(nameof(SwigCPtr), $"Error! NUI's native dali object is already disposed. " +
732 $"OR the native dali object handle of NUI becomes null! \n" +
733 $" process:{process} thread:{thread}, isDisposed:{this.Disposed}, isDisposeQueued:{this.IsDisposeQueued}, me:{me}\n");
738 if (this.IsDisposeQueued)
740 var process = global::System.Diagnostics.Process.GetCurrentProcess().Id;
741 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
742 var me = this.GetType().FullName;
744 //in this case, the View object is ready to be disposed waiting on DisposeQueue, so event callback should not be invoked!
745 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" +
746 $"process:{process} thread:{thread}, isDisposed:{this.Disposed}, isDisposeQueued:{this.IsDisposeQueued}, me:{me}\n");
752 keyInputFocusLostEventHandler?.Invoke(this, null);
755 private bool OnKeyEvent(IntPtr view, IntPtr keyEvent)
757 if (keyEvent == global::System.IntPtr.Zero)
759 NUILog.Error("keyEvent should not be null!");
763 KeyEventArgs e = new KeyEventArgs();
767 e.Key = Tizen.NUI.Key.GetKeyFromPtr(keyEvent);
769 if (keyEventHandler != null)
771 Delegate[] delegateList = keyEventHandler.GetInvocationList();
773 // Oring the result of each callback.
774 foreach (EventHandlerWithReturnType<object, KeyEventArgs, bool> del in delegateList)
776 result |= del(this, e);
783 // Callback for View OnRelayout signal
784 private void OnRelayout(IntPtr data)
786 if (onRelayoutEventHandler != null)
788 onRelayoutEventHandler(this, null);
792 // Callback for View HitTestResultSignal
793 private bool OnHitTestResult(IntPtr view, IntPtr touchData)
795 if (touchData == global::System.IntPtr.Zero)
797 NUILog.Error("touchData should not be null!");
801 TouchEventArgs e = new TouchEventArgs();
802 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
803 return HitTest(e.Touch);
806 // Callback for View TouchSignal
807 private bool OnInterceptTouch(IntPtr view, IntPtr touchData)
809 if (touchData == global::System.IntPtr.Zero)
811 NUILog.Error("touchData should not be null!");
815 // DisallowInterceptTouchEvent prevents the parent from intercepting touch.
816 if (DisallowInterceptTouchEvent)
821 TouchEventArgs e = new TouchEventArgs();
823 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
825 bool consumed = false;
827 if (interceptTouchDataEventHandler != null)
829 consumed = interceptTouchDataEventHandler(this, e);
835 // Callback for View TouchSignal
836 private bool OnTouch(IntPtr view, IntPtr touchData)
838 if (touchData == global::System.IntPtr.Zero)
840 NUILog.Error("touchData should not be null!");
844 if (DispatchTouchEvents == false)
846 NUILog.Debug("If DispatchTouchEvents is false, it can not dispatch.");
850 TouchEventArgs e = new TouchEventArgs();
852 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
854 bool consumed = false;
856 if (touchDataEventHandler != null)
858 consumed = touchDataEventHandler(this, e);
861 if (enableControlState && !consumed)
863 consumed = HandleControlStateOnTouch(e.Touch);
866 if (DispatchParentTouchEvents == false)
868 NUILog.Debug("If DispatchParentTouchEvents is false, it can not dispatch to parent.");
875 // Callback for View Hover signal
876 private bool OnHoverEvent(IntPtr view, IntPtr hoverEvent)
878 if (hoverEvent == global::System.IntPtr.Zero)
880 NUILog.Error("hoverEvent should not be null!");
884 if (DispatchHoverEvents == false)
886 NUILog.Debug("If DispatchHoverEvents is false, it can not dispatch.");
890 HoverEventArgs e = new HoverEventArgs();
892 e.Hover = Tizen.NUI.Hover.GetHoverFromPtr(hoverEvent);
894 bool consumed = false;
896 if (hoverEventHandler != null)
898 consumed = hoverEventHandler(this, e);
901 if (DispatchParentHoverEvents == false && consumed == false)
903 NUILog.Debug("If DispatchParentHoverEvents is false, it can not dispatch to parent.");
910 // Callback for View InterceptWheel signal
911 private bool OnInterceptWheel(IntPtr view, IntPtr wheelEvent)
913 if (wheelEvent == global::System.IntPtr.Zero)
915 NUILog.Error("wheelEvent should not be null!");
919 // DisallowInterceptWheelEvent prevents the parent from intercepting wheel.
920 if (DisallowInterceptWheelEvent)
925 WheelEventArgs e = new WheelEventArgs();
927 e.Wheel = Tizen.NUI.Wheel.GetWheelFromPtr(wheelEvent);
929 bool consumed = false;
931 if (interceptWheelHandler != null)
933 consumed = interceptWheelHandler(this, e);
939 // Callback for View Wheel signal
940 private bool OnWheelEvent(IntPtr view, IntPtr wheelEvent)
942 if (wheelEvent == global::System.IntPtr.Zero)
944 NUILog.Error("wheelEvent should not be null!");
948 WheelEventArgs e = new WheelEventArgs();
950 e.Wheel = Tizen.NUI.Wheel.GetWheelFromPtr(wheelEvent);
952 if (wheelEventHandler != null)
954 return wheelEventHandler(this, e);
959 // Callback for View OnWindow signal
960 private void OnWindow(IntPtr data)
962 if (onWindowEventHandler != null)
964 onWindowEventHandler(this, null);
968 // Callback for View OffWindow signal
969 private void OffWindow(IntPtr data)
971 if (offWindowEventHandler != null)
973 offWindowEventHandler(this, null);
977 // Callback for View visibility change signal
978 private void OnVisibilityChanged(IntPtr data, bool visibility, VisibilityChangeType type)
980 VisibilityChangedEventArgs e = new VisibilityChangedEventArgs();
983 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
985 e.Visibility = visibility;
988 if (visibilityChangedEventHandler != null)
990 visibilityChangedEventHandler(this, e);
994 // Callback for View layout direction change signal
995 private void OnLayoutDirectionChanged(IntPtr data, ViewLayoutDirectionType type)
997 LayoutDirectionChangedEventArgs e = new LayoutDirectionChangedEventArgs();
1000 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
1004 if (layoutDirectionChangedEventHandler != null)
1006 layoutDirectionChangedEventHandler(this, e);
1010 private void OnResourcesLoaded(IntPtr view)
1012 if(!CheckResourceReady())
1017 if (resourcesLoadedEventHandler != null)
1019 resourcesLoadedEventHandler(this, null);
1023 private void OnBackgroundResourceLoaded(IntPtr view)
1025 BackgroundResourceLoadedEventArgs e = new BackgroundResourceLoadedEventArgs();
1026 e.Status = (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.BACKGROUND);
1028 if (backgroundResourceLoadedEventHandler != null)
1030 backgroundResourceLoadedEventHandler(this, e);
1035 /// Event argument passed through the ChildAdded event.
1037 /// <since_tizen> 5 </since_tizen>
1038 public class ChildAddedEventArgs : EventArgs
1041 /// Added child view at moment.
1043 /// <since_tizen> 5 </since_tizen>
1044 public View Added { get; set; }
1048 /// Event argument passed through the ChildRemoved event.
1050 /// <since_tizen> 5 </since_tizen>
1051 public class ChildRemovedEventArgs : EventArgs
1054 /// Removed child view at moment.
1056 /// <since_tizen> 5 </since_tizen>
1057 public View Removed { get; set; }
1061 /// Event arguments that passed via the KeyEvent signal.
1063 /// <since_tizen> 3 </since_tizen>
1064 public class KeyEventArgs : EventArgs
1069 /// Key - is the key sent to the view.
1071 /// <since_tizen> 3 </since_tizen>
1086 /// Event arguments that passed via the touch signal.
1088 /// <since_tizen> 3 </since_tizen>
1089 public class TouchEventArgs : EventArgs
1091 private Touch _touch;
1094 /// Touch - contains the information of touch points.
1096 /// <since_tizen> 3 </since_tizen>
1111 /// Event arguments that passed via the hover signal.
1113 /// <since_tizen> 3 </since_tizen>
1114 public class HoverEventArgs : EventArgs
1116 private Hover _hover;
1119 /// Hover - contains touch points that represent the points that are currently being hovered or the points where a hover has stopped.
1121 /// <since_tizen> 3 </since_tizen>
1136 /// Event arguments that passed via the wheel signal.
1138 /// <since_tizen> 3 </since_tizen>
1139 public class WheelEventArgs : EventArgs
1141 private Wheel _wheel;
1144 /// WheelEvent - store a wheel rolling type: MOUSE_WHEEL or CUSTOM_WHEEL.
1146 /// <since_tizen> 3 </since_tizen>
1161 /// Event arguments of visibility changed.
1163 /// <since_tizen> 3 </since_tizen>
1164 public class VisibilityChangedEventArgs : EventArgs
1167 private bool _visibility;
1168 private VisibilityChangeType _type;
1171 /// The view, or child of view, whose visibility has changed.
1173 /// <since_tizen> 3 </since_tizen>
1187 /// Whether the view is now visible or not.
1189 /// <since_tizen> 3 </since_tizen>
1190 public bool Visibility
1198 _visibility = value;
1203 /// Whether the view's visible property has changed or a parent's.
1205 /// <since_tizen> 3 </since_tizen>
1206 public VisibilityChangeType Type
1220 /// Event arguments of layout direction changed.
1222 /// <since_tizen> 4 </since_tizen>
1223 public class LayoutDirectionChangedEventArgs : EventArgs
1226 private ViewLayoutDirectionType _type;
1229 /// The view, or child of view, whose layout direction has changed.
1231 /// <since_tizen> 4 </since_tizen>
1245 /// Whether the view's layout direction property has changed or a parent's.
1247 /// <since_tizen> 4 </since_tizen>
1248 public ViewLayoutDirectionType Type
1261 internal class BackgroundResourceLoadedEventArgs : EventArgs
1263 private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1264 public ResourceLoadingStatusType Status
1278 /// The class represents the information of the situation where the View's control state changes.
1280 [EditorBrowsable(EditorBrowsableState.Never)]
1281 public class ControlStateChangedEventArgs : EventArgs
1284 /// Create an instance with mandatory fields.
1286 /// <param name="previousState">The previous control state.</param>
1287 /// <param name="currentState">The current control state.</param>
1288 [EditorBrowsable(EditorBrowsableState.Never)]
1289 public ControlStateChangedEventArgs(ControlState previousState, ControlState currentState)
1291 PreviousState = previousState;
1292 CurrentState = currentState;
1296 /// The previous control state.
1298 [EditorBrowsable(EditorBrowsableState.Never)]
1299 public ControlState PreviousState { get; }
1302 /// The current control state.
1304 [EditorBrowsable(EditorBrowsableState.Never)]
1305 public ControlState CurrentState { get; }
1309 /// The expanded touch area.
1310 /// TouchArea can expand the view's touchable area.<br/>
1311 /// 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/>
1314 /// This is based on the top left x, y coordinates.<br/>
1315 /// For example) <br/>
1317 /// view.Size = new Size(100, 100);
1318 /// view.TouchAreaOffset = new Offset(-10, 20, 30, -40); // left, right, bottom, top
1320 /// Then, touch area is 130x170.<br/>
1321 /// This is view.width + TouchAreaOffset.right - TouchAreaOffset.left and view.height + TouchAreaOffset.bottom - TouchAreaOffset.top <br/>
1322 /// +---------------------+ <br/>
1328 /// | +----+----+ | <br/>
1330 /// | -10| | 20 | <br/>
1331 /// |<---+ +----->| <br/>
1334 /// | +----+----+ | <br/>
1339 /// +---------------------+ <br/>
1341 [EditorBrowsable(EditorBrowsableState.Never)]
1342 public Offset TouchAreaOffset
1346 return (Offset)GetValue(TouchAreaOffsetProperty);
1350 SetValue(TouchAreaOffsetProperty, value);
1351 NotifyPropertyChanged();
1355 private Offset InternalTouchAreaOffset
1359 Interop.ActorInternal.GetTouchAreaOffset(SwigCPtr, out int left, out int right, out int bottom, out int top);
1360 if (NDalicPINVOKE.SWIGPendingException.Pending)
1361 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1362 return new Offset(left, right, bottom, top);
1366 Interop.ActorInternal.SetTouchAreaOffset(SwigCPtr, value.Left, value.Right, value.Bottom, value.Top);
1367 if (NDalicPINVOKE.SWIGPendingException.Pending)
1368 throw NDalicPINVOKE.SWIGPendingException.Retrieve();