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> wheelEventHandler;
33 private WheelEventCallbackType wheelEventCallback;
34 private EventHandlerWithReturnType<object, KeyEventArgs, bool> keyEventHandler;
35 private KeyCallbackType keyCallback;
36 private EventHandlerWithReturnType<object, TouchEventArgs, bool> interceptTouchDataEventHandler;
37 private TouchDataCallbackType interceptTouchDataCallback;
38 private EventHandlerWithReturnType<object, TouchEventArgs, bool> touchDataEventHandler;
39 private TouchDataCallbackType touchDataCallback;
40 private EventHandlerWithReturnType<object, HoverEventArgs, bool> hoverEventHandler;
41 private HoverEventCallbackType hoverEventCallback;
42 private EventHandler<VisibilityChangedEventArgs> visibilityChangedEventHandler;
43 private VisibilityChangedEventCallbackType visibilityChangedEventCallback;
44 private EventHandler keyInputFocusGainedEventHandler;
46 private KeyInputFocusGainedCallbackType keyInputFocusGainedCallback;
47 private EventHandler keyInputFocusLostEventHandler;
49 private KeyInputFocusLostCallbackType keyInputFocusLostCallback;
50 private EventHandler onRelayoutEventHandler;
51 private OnRelayoutEventCallbackType onRelayoutEventCallback;
52 private EventHandler onWindowEventHandler;
53 private OnWindowEventCallbackType onWindowEventCallback;
54 private EventHandler<LayoutDirectionChangedEventArgs> layoutDirectionChangedEventHandler;
55 private LayoutDirectionChangedEventCallbackType layoutDirectionChangedEventCallback;
56 // Resource Ready Signal
57 private EventHandler resourcesLoadedEventHandler;
58 private ResourcesLoadedCallbackType resourcesLoadedCallback;
59 private EventHandler<BackgroundResourceLoadedEventArgs> backgroundResourceLoadedEventHandler;
60 private _backgroundResourceLoadedCallbackType backgroundResourceLoadedCallback;
61 private TouchDataCallbackType hitTestResultDataCallback;
63 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
64 private delegate void OffWindowEventCallbackType(IntPtr control);
65 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
66 private delegate bool WheelEventCallbackType(IntPtr view, IntPtr wheelEvent);
67 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
68 private delegate bool KeyCallbackType(IntPtr control, IntPtr keyEvent);
69 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
70 private delegate bool TouchDataCallbackType(IntPtr view, IntPtr touchData);
71 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
72 private delegate bool HoverEventCallbackType(IntPtr view, IntPtr hoverEvent);
73 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
74 private delegate void VisibilityChangedEventCallbackType(IntPtr data, bool visibility, VisibilityChangeType type);
75 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
76 private delegate void ResourcesLoadedCallbackType(IntPtr control);
77 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
78 private delegate void _backgroundResourceLoadedCallbackType(IntPtr view);
80 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
81 private delegate void KeyInputFocusGainedCallbackType(IntPtr control);
82 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
83 private delegate void KeyInputFocusLostCallbackType(IntPtr control);
85 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
86 private delegate void OnRelayoutEventCallbackType(IntPtr control);
87 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
88 private delegate void OnWindowEventCallbackType(IntPtr control);
89 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
90 private delegate void LayoutDirectionChangedEventCallbackType(IntPtr data, ViewLayoutDirectionType type);
93 /// Event when a child is removed.
95 /// <since_tizen> 5 </since_tizen>
96 public new event EventHandler<ChildRemovedEventArgs> ChildRemoved;
98 /// Event when a child is added.
100 /// <since_tizen> 5 </since_tizen>
101 public new event EventHandler<ChildAddedEventArgs> ChildAdded;
104 /// An event for the KeyInputFocusGained signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
105 /// The KeyInputFocusGained signal is emitted when the control gets the key input focus.<br />
107 /// <since_tizen> 3 </since_tizen>
108 public event EventHandler FocusGained
112 if (keyInputFocusGainedEventHandler == null)
114 keyInputFocusGainedCallback = OnKeyInputFocusGained;
115 Interop.ViewSignal.KeyInputFocusGainedConnect(SwigCPtr, keyInputFocusGainedCallback.ToHandleRef(this));
116 NDalicPINVOKE.ThrowExceptionIfExists();
118 keyInputFocusGainedEventHandler += value;
123 keyInputFocusGainedEventHandler -= value;
124 if (keyInputFocusGainedEventHandler == null && keyInputFocusGainedCallback != null)
126 Interop.ViewSignal.KeyInputFocusGainedDisconnect(SwigCPtr, keyInputFocusGainedCallback.ToHandleRef(this));
127 NDalicPINVOKE.ThrowExceptionIfExists();
128 keyInputFocusGainedCallback = null;
134 /// An event for the KeyInputFocusLost signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
135 /// The KeyInputFocusLost signal is emitted when the control loses the key input focus.<br />
137 /// <since_tizen> 3 </since_tizen>
138 public event EventHandler FocusLost
142 if (keyInputFocusLostEventHandler == null)
144 keyInputFocusLostCallback = OnKeyInputFocusLost;
145 Interop.ViewSignal.KeyInputFocusLostConnect(SwigCPtr, keyInputFocusLostCallback.ToHandleRef(this));
146 NDalicPINVOKE.ThrowExceptionIfExists();
148 keyInputFocusLostEventHandler += value;
153 keyInputFocusLostEventHandler -= value;
154 if (keyInputFocusLostEventHandler == null && keyInputFocusLostCallback != null)
156 Interop.ViewSignal.KeyInputFocusLostDisconnect(SwigCPtr, keyInputFocusLostCallback.ToHandleRef(this));
157 NDalicPINVOKE.ThrowExceptionIfExists();
158 keyInputFocusLostCallback = null;
164 /// An event for the KeyPressed signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
165 /// The KeyPressed signal is emitted when the key event is received.<br />
167 /// <since_tizen> 3 </since_tizen>
168 public event EventHandlerWithReturnType<object, KeyEventArgs, bool> KeyEvent
172 if (keyEventHandler == null)
174 keyCallback = OnKeyEvent;
175 Interop.ViewSignal.KeyEventConnect(SwigCPtr, keyCallback.ToHandleRef(this));
176 NDalicPINVOKE.ThrowExceptionIfExists();
178 keyEventHandler += value;
183 keyEventHandler -= value;
184 if (keyEventHandler == null && keyCallback != null)
186 Interop.ViewSignal.KeyEventDisconnect(SwigCPtr, keyCallback.ToHandleRef(this));
187 NDalicPINVOKE.ThrowExceptionIfExists();
194 /// An event for the OnRelayout signal which can be used to subscribe or unsubscribe the event handler.<br />
195 /// The OnRelayout signal is emitted after the size has been set on the view during relayout.<br />
197 /// <since_tizen> 3 </since_tizen>
198 public event EventHandler Relayout
202 if (onRelayoutEventHandler == null)
204 onRelayoutEventCallback = OnRelayout;
205 Interop.ActorSignal.OnRelayoutConnect(SwigCPtr, onRelayoutEventCallback.ToHandleRef(this));
206 NDalicPINVOKE.ThrowExceptionIfExists();
208 onRelayoutEventHandler += value;
213 onRelayoutEventHandler -= value;
214 if (onRelayoutEventHandler == null && onRelayoutEventCallback != null)
216 Interop.ActorSignal.OnRelayoutDisconnect(SwigCPtr, onRelayoutEventCallback.ToHandleRef(this));
217 NDalicPINVOKE.ThrowExceptionIfExists();
218 onRelayoutEventCallback = null;
224 /// An event for the touched signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
225 /// The touched signal is emitted when the touch input is received.<br />
226 /// This can receive touch events before child. <br />
227 /// 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 />
229 [EditorBrowsable(EditorBrowsableState.Never)]
230 public event EventHandlerWithReturnType<object, TouchEventArgs, bool> InterceptTouchEvent
234 if (interceptTouchDataEventHandler == null)
236 interceptTouchDataCallback = OnInterceptTouch;
237 Interop.ActorSignal.InterceptTouchConnect(SwigCPtr, interceptTouchDataCallback.ToHandleRef(this));
238 NDalicPINVOKE.ThrowExceptionIfExists();
240 interceptTouchDataEventHandler += value;
245 interceptTouchDataEventHandler -= value;
246 if (interceptTouchDataEventHandler == null && interceptTouchDataCallback != null)
248 Interop.ActorSignal.InterceptTouchDisconnect(SwigCPtr, interceptTouchDataCallback.ToHandleRef(this));
249 NDalicPINVOKE.ThrowExceptionIfExists();
250 interceptTouchDataCallback = null;
256 /// If child view doesn't want the parent's view to intercept the touch, you can set it to true.
258 /// parent.Add(child);
259 /// parent.InterceptTouchEvent += OnInterceptTouchEvent;
260 /// View view = child.GetParent() as View;
261 /// view.DisallowInterceptTouchEvent = true;
262 /// This prevents the parent from intercepting touch.
264 [EditorBrowsable(EditorBrowsableState.Never)]
265 public bool DisallowInterceptTouchEvent { get; set; }
269 /// An event for the touched signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
270 /// The touched signal is emitted when the touch input is received.<br />
272 /// <since_tizen> 3 </since_tizen>
273 public event EventHandlerWithReturnType<object, TouchEventArgs, bool> TouchEvent
277 if (touchDataEventHandler == null)
279 touchDataCallback = OnTouch;
280 Interop.ActorSignal.TouchConnect(SwigCPtr, touchDataCallback.ToHandleRef(this));
281 NDalicPINVOKE.ThrowExceptionIfExists();
283 touchDataEventHandler += value;
288 touchDataEventHandler -= value;
289 if (touchDataEventHandler == null && touchDataCallback != null)
291 Interop.ActorSignal.TouchDisconnect(SwigCPtr, touchDataCallback.ToHandleRef(this));
292 NDalicPINVOKE.ThrowExceptionIfExists();
293 touchDataCallback = null;
299 /// An event for the hovered signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
300 /// The hovered signal is emitted when the hover input is received.<br />
302 /// <since_tizen> 3 </since_tizen>
303 public event EventHandlerWithReturnType<object, HoverEventArgs, bool> HoverEvent
307 if (hoverEventHandler == null)
309 hoverEventCallback = OnHoverEvent;
310 Interop.ActorSignal.HoveredConnect(SwigCPtr, hoverEventCallback.ToHandleRef(this));
311 NDalicPINVOKE.ThrowExceptionIfExists();
313 hoverEventHandler += value;
318 hoverEventHandler -= value;
319 if (hoverEventHandler == null && hoverEventCallback != null)
321 Interop.ActorSignal.HoveredDisconnect(SwigCPtr, hoverEventCallback.ToHandleRef(this));
322 NDalicPINVOKE.ThrowExceptionIfExists();
323 hoverEventCallback = null;
329 /// An event for the WheelMoved signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
330 /// The WheelMoved signal is emitted when the wheel event is received.<br />
332 /// <since_tizen> 3 </since_tizen>
333 public event EventHandlerWithReturnType<object, WheelEventArgs, bool> WheelEvent
337 if (wheelEventHandler == null)
339 wheelEventCallback = OnWheelEvent;
340 Interop.ActorSignal.WheelEventConnect(SwigCPtr, wheelEventCallback.ToHandleRef(this));
341 NDalicPINVOKE.ThrowExceptionIfExists();
343 wheelEventHandler += value;
348 wheelEventHandler -= value;
349 if (wheelEventHandler == null && wheelEventCallback != null)
351 Interop.ActorSignal.WheelEventDisconnect(SwigCPtr, wheelEventCallback.ToHandleRef(this));
352 NDalicPINVOKE.ThrowExceptionIfExists();
353 wheelEventCallback = null;
359 /// An event for the OnWindow signal which can be used to subscribe or unsubscribe the event handler.<br />
360 /// The OnWindow signal is emitted after the view has been connected to the window.<br />
362 /// <since_tizen> 3 </since_tizen>
363 public event EventHandler AddedToWindow
367 if (onWindowEventHandler == null)
369 onWindowEventCallback = OnWindow;
370 Interop.ActorSignal.OnSceneConnect(SwigCPtr, onWindowEventCallback.ToHandleRef(this));
371 NDalicPINVOKE.ThrowExceptionIfExists();
373 onWindowEventHandler += value;
378 onWindowEventHandler -= value;
379 if (onWindowEventHandler == null && onWindowEventCallback != null)
381 Interop.ActorSignal.OnSceneDisconnect(SwigCPtr, onWindowEventCallback.ToHandleRef(this));
382 NDalicPINVOKE.ThrowExceptionIfExists();
383 onWindowEventCallback = null;
389 /// An event for the OffWindow signal, which can be used to subscribe or unsubscribe the event handler.<br />
390 /// OffWindow signal is emitted after the view has been disconnected from the window.<br />
392 /// <since_tizen> 3 </since_tizen>
393 public event EventHandler RemovedFromWindow
397 if (offWindowEventHandler == null)
399 offWindowEventCallback = OffWindow;
400 Interop.ActorSignal.OffSceneConnect(SwigCPtr, offWindowEventCallback.ToHandleRef(this));
401 NDalicPINVOKE.ThrowExceptionIfExists();
403 offWindowEventHandler += value;
408 offWindowEventHandler -= value;
409 if (offWindowEventHandler == null && offWindowEventCallback != null)
411 Interop.ActorSignal.OffSceneDisconnect(SwigCPtr, offWindowEventCallback.ToHandleRef(this));
412 NDalicPINVOKE.ThrowExceptionIfExists();
413 offWindowEventCallback = null;
419 /// An event for visibility change which can be used to subscribe or unsubscribe the event handler.<br />
420 /// This signal is emitted when the visible property of this or a parent view is changed.<br />
422 /// <since_tizen> 3 </since_tizen>
423 public event EventHandler<VisibilityChangedEventArgs> VisibilityChanged
427 if (visibilityChangedEventHandler == null)
429 visibilityChangedEventCallback = OnVisibilityChanged;
430 Interop.ActorSignal.VisibilityChangedConnect(SwigCPtr, visibilityChangedEventCallback.ToHandleRef(this));
431 NDalicPINVOKE.ThrowExceptionIfExists();
433 visibilityChangedEventHandler += value;
438 visibilityChangedEventHandler -= value;
439 if (visibilityChangedEventHandler == null && visibilityChangedEventCallback != null)
441 Interop.ActorSignal.VisibilityChangedDisconnect(SwigCPtr, visibilityChangedEventCallback.ToHandleRef(this));
442 NDalicPINVOKE.ThrowExceptionIfExists();
443 visibilityChangedEventCallback = null;
449 /// Event for layout direction change which can be used to subscribe/unsubscribe the event handler.<br />
450 /// This signal is emitted when the layout direction property of this or a parent view is changed.<br />
452 /// <since_tizen> 4 </since_tizen>
453 public event EventHandler<LayoutDirectionChangedEventArgs> LayoutDirectionChanged
457 if (layoutDirectionChangedEventHandler == null)
459 layoutDirectionChangedEventCallback = OnLayoutDirectionChanged;
460 Interop.ActorSignal.LayoutDirectionChangedConnect(SwigCPtr, layoutDirectionChangedEventCallback.ToHandleRef(this));
461 NDalicPINVOKE.ThrowExceptionIfExists();
464 layoutDirectionChangedEventHandler += value;
469 layoutDirectionChangedEventHandler -= value;
471 if (layoutDirectionChangedEventHandler == null && layoutDirectionChangedEventCallback != null)
473 Interop.ActorSignal.LayoutDirectionChangedDisconnect(SwigCPtr, layoutDirectionChangedEventCallback.ToHandleRef(this));
474 NDalicPINVOKE.ThrowExceptionIfExists();
475 layoutDirectionChangedEventCallback = null;
481 /// An event for the ResourcesLoadedSignal signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
482 /// This signal is emitted after all resources required by a view are loaded and ready.<br />
484 /// <since_tizen> 3 </since_tizen>
485 public event EventHandler ResourcesLoaded
489 if (resourcesLoadedEventHandler == null)
491 resourcesLoadedCallback = OnResourcesLoaded;
492 Interop.ViewSignal.ResourceReadyConnect(SwigCPtr, resourcesLoadedCallback.ToHandleRef(this));
493 NDalicPINVOKE.ThrowExceptionIfExists();
495 resourcesLoadedEventHandler += value;
500 resourcesLoadedEventHandler -= value;
501 if (resourcesLoadedEventHandler == null && resourcesLoadedCallback != null)
503 Interop.ViewSignal.ResourceReadyDisconnect(SwigCPtr, resourcesLoadedCallback.ToHandleRef(this));
504 NDalicPINVOKE.ThrowExceptionIfExists();
505 resourcesLoadedCallback = null;
510 private EventHandler _backKeyPressed;
513 /// An event for getting notice when physical back key is pressed.<br />
514 /// This event is emitted BackKey is up.<br />
516 [EditorBrowsable(EditorBrowsableState.Never)]
517 public event EventHandler BackKeyPressed
521 _backKeyPressed += value;
522 BackKeyManager.Instance.Subscriber.Add(this);
527 BackKeyManager.Instance.Subscriber.Remove(this);
528 _backKeyPressed -= value;
533 /// Function for emitting BackKeyPressed event outside of View instance
535 [EditorBrowsable(EditorBrowsableState.Never)]
536 internal void EmitBackKeyPressed()
538 _backKeyPressed.Invoke(this, null);
542 internal event EventHandler<BackgroundResourceLoadedEventArgs> BackgroundResourceLoaded
546 if (backgroundResourceLoadedEventHandler == null)
548 backgroundResourceLoadedCallback = OnBackgroundResourceLoaded;
549 Interop.ViewSignal.ResourceReadyConnect(SwigCPtr, backgroundResourceLoadedCallback.ToHandleRef(this));
550 NDalicPINVOKE.ThrowExceptionIfExists();
552 backgroundResourceLoadedEventHandler += value;
557 backgroundResourceLoadedEventHandler -= value;
558 if (backgroundResourceLoadedEventHandler == null && backgroundResourceLoadedCallback != null)
560 Interop.ViewSignal.ResourceReadyDisconnect(SwigCPtr, backgroundResourceLoadedCallback.ToHandleRef(this));
561 NDalicPINVOKE.ThrowExceptionIfExists();
562 backgroundResourceLoadedCallback = null;
567 private void OnColorChanged(float r, float g, float b, float a)
569 Color = new Color(r, g, b, a);
572 private void OnMinimumSizeChanged(int width, int height)
574 MinimumSize = new Size2D(width, height);
577 private void OnMaximumSizeChanged(int width, int height)
579 MaximumSize = new Size2D(width, height);
582 private void OnPosition2DChanged(int x, int y)
584 SetPosition((float)x, (float)y, 0);
587 private void OnPositionChanged(float x, float y, float z)
589 SetPosition(x, y, z);
592 private void OnSize2DChanged(int width, int height)
594 SetSize((float)width, (float)height, 0);
597 private void OnSizeChanged(float width, float height, float depth)
599 SetSize(width, height, depth);
602 private void OnParentOriginChanged(float x, float y, float z)
604 ParentOrigin = new Position(x, y, z);
607 private void OnPivotPointChanged(float x, float y, float z)
609 PivotPoint = new Position(x, y, z);
612 private void OnImageShadowChanged(ShadowBase instance)
614 ImageShadow = (ImageShadow)instance;
617 private void OnBoxShadowChanged(ShadowBase instance)
619 BoxShadow = (Shadow)instance;
622 private void OnBackgroundImageBorderChanged(int left, int right, int bottom, int top)
624 BackgroundImageBorder = new Rectangle(left, right, bottom, top);
627 private void OnKeyInputFocusGained(IntPtr view)
629 if (IsNativeHandleInvalid())
633 if (keyInputFocusGainedEventHandler != null)
635 var process = global::System.Diagnostics.Process.GetCurrentProcess().Id;
636 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
637 var me = this.GetType().FullName;
639 throw new ObjectDisposedException(nameof(SwigCPtr), $"Error! NUI's native dali object is already disposed. " +
640 $"OR the native dali object handle of NUI becomes null! \n" +
641 $" process:{process} thread:{thread}, isDisposed:{this.Disposed}, isDisposeQueued:{this.IsDisposeQueued}, me:{me}\n");
646 if (this.IsDisposeQueued)
648 var process = global::System.Diagnostics.Process.GetCurrentProcess().Id;
649 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
650 var me = this.GetType().FullName;
652 //in this case, the View object is ready to be disposed waiting on DisposeQueue, so event callback should not be invoked!
653 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" +
654 $"process:{process} thread:{thread}, isDisposed:{this.Disposed}, isDisposeQueued:{this.IsDisposeQueued}, me:{me}\n");
660 keyInputFocusGainedEventHandler?.Invoke(this, null);
663 private void OnKeyInputFocusLost(IntPtr view)
665 if (IsNativeHandleInvalid())
669 if (keyInputFocusLostEventHandler != null)
671 var process = global::System.Diagnostics.Process.GetCurrentProcess().Id;
672 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
673 var me = this.GetType().FullName;
675 throw new ObjectDisposedException(nameof(SwigCPtr), $"Error! NUI's native dali object is already disposed. " +
676 $"OR the native dali object handle of NUI becomes null! \n" +
677 $" process:{process} thread:{thread}, isDisposed:{this.Disposed}, isDisposeQueued:{this.IsDisposeQueued}, me:{me}\n");
682 if (this.IsDisposeQueued)
684 var process = global::System.Diagnostics.Process.GetCurrentProcess().Id;
685 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
686 var me = this.GetType().FullName;
688 //in this case, the View object is ready to be disposed waiting on DisposeQueue, so event callback should not be invoked!
689 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" +
690 $"process:{process} thread:{thread}, isDisposed:{this.Disposed}, isDisposeQueued:{this.IsDisposeQueued}, me:{me}\n");
696 keyInputFocusLostEventHandler?.Invoke(this, null);
699 private bool OnKeyEvent(IntPtr view, IntPtr keyEvent)
701 if (keyEvent == global::System.IntPtr.Zero)
703 NUILog.Error("keyEvent should not be null!");
707 KeyEventArgs e = new KeyEventArgs();
711 e.Key = Tizen.NUI.Key.GetKeyFromPtr(keyEvent);
713 if (keyEventHandler != null)
715 Delegate[] delegateList = keyEventHandler.GetInvocationList();
717 // Oring the result of each callback.
718 foreach (EventHandlerWithReturnType<object, KeyEventArgs, bool> del in delegateList)
720 result |= del(this, e);
727 // Callback for View OnRelayout signal
728 private void OnRelayout(IntPtr data)
730 if (onRelayoutEventHandler != null)
732 onRelayoutEventHandler(this, null);
736 // Callback for View HitTestResultSignal
737 private bool OnHitTestResult(IntPtr view, IntPtr touchData)
739 if (touchData == global::System.IntPtr.Zero)
741 NUILog.Error("touchData should not be null!");
745 TouchEventArgs e = new TouchEventArgs();
746 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
747 return HitTest(e.Touch);
750 // Callback for View TouchSignal
751 private bool OnInterceptTouch(IntPtr view, IntPtr touchData)
753 if (touchData == global::System.IntPtr.Zero)
755 NUILog.Error("touchData should not be null!");
759 // DisallowInterceptTouchEvent prevents the parent from intercepting touch.
760 if (DisallowInterceptTouchEvent)
765 TouchEventArgs e = new TouchEventArgs();
767 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
769 bool consumed = false;
771 if (interceptTouchDataEventHandler != null)
773 consumed = interceptTouchDataEventHandler(this, e);
779 // Callback for View TouchSignal
780 private bool OnTouch(IntPtr view, IntPtr touchData)
782 if (touchData == global::System.IntPtr.Zero)
784 NUILog.Error("touchData should not be null!");
788 if (DispatchTouchEvents == false)
790 NUILog.Debug("If DispatchTouchEvents is false, it can not dispatch.");
794 TouchEventArgs e = new TouchEventArgs();
796 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
798 bool consumed = false;
800 if (touchDataEventHandler != null)
802 consumed = touchDataEventHandler(this, e);
805 if (enableControlState && !consumed)
807 consumed = HandleControlStateOnTouch(e.Touch);
810 if (DispatchParentTouchEvents == false)
812 NUILog.Debug("If DispatchParentTouchEvents is false, it can not dispatch to parent.");
819 // Callback for View Hover signal
820 private bool OnHoverEvent(IntPtr view, IntPtr hoverEvent)
822 if (hoverEvent == global::System.IntPtr.Zero)
824 NUILog.Error("hoverEvent should not be null!");
828 HoverEventArgs e = new HoverEventArgs();
830 e.Hover = Tizen.NUI.Hover.GetHoverFromPtr(hoverEvent);
832 if (hoverEventHandler != null)
834 return hoverEventHandler(this, e);
839 // Callback for View Wheel signal
840 private bool OnWheelEvent(IntPtr view, IntPtr wheelEvent)
842 if (wheelEvent == global::System.IntPtr.Zero)
844 NUILog.Error("wheelEvent should not be null!");
848 WheelEventArgs e = new WheelEventArgs();
850 e.Wheel = Tizen.NUI.Wheel.GetWheelFromPtr(wheelEvent);
852 if (wheelEventHandler != null)
854 return wheelEventHandler(this, e);
859 // Callback for View OnWindow signal
860 private void OnWindow(IntPtr data)
862 if (onWindowEventHandler != null)
864 onWindowEventHandler(this, null);
868 // Callback for View OffWindow signal
869 private void OffWindow(IntPtr data)
871 if (offWindowEventHandler != null)
873 offWindowEventHandler(this, null);
877 // Callback for View visibility change signal
878 private void OnVisibilityChanged(IntPtr data, bool visibility, VisibilityChangeType type)
880 VisibilityChangedEventArgs e = new VisibilityChangedEventArgs();
883 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
885 e.Visibility = visibility;
888 if (visibilityChangedEventHandler != null)
890 visibilityChangedEventHandler(this, e);
894 // Callback for View layout direction change signal
895 private void OnLayoutDirectionChanged(IntPtr data, ViewLayoutDirectionType type)
897 LayoutDirectionChangedEventArgs e = new LayoutDirectionChangedEventArgs();
900 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
904 if (layoutDirectionChangedEventHandler != null)
906 layoutDirectionChangedEventHandler(this, e);
910 private void OnResourcesLoaded(IntPtr view)
912 if(!CheckResourceReady())
917 if (resourcesLoadedEventHandler != null)
919 resourcesLoadedEventHandler(this, null);
923 private void OnBackgroundResourceLoaded(IntPtr view)
925 BackgroundResourceLoadedEventArgs e = new BackgroundResourceLoadedEventArgs();
926 e.Status = (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.BACKGROUND);
928 if (backgroundResourceLoadedEventHandler != null)
930 backgroundResourceLoadedEventHandler(this, e);
935 /// Event argument passed through the ChildAdded event.
937 /// <since_tizen> 5 </since_tizen>
938 public class ChildAddedEventArgs : EventArgs
941 /// Added child view at moment.
943 /// <since_tizen> 5 </since_tizen>
944 public View Added { get; set; }
948 /// Event argument passed through the ChildRemoved event.
950 /// <since_tizen> 5 </since_tizen>
951 public class ChildRemovedEventArgs : EventArgs
954 /// Removed child view at moment.
956 /// <since_tizen> 5 </since_tizen>
957 public View Removed { get; set; }
961 /// Event arguments that passed via the KeyEvent signal.
963 /// <since_tizen> 3 </since_tizen>
964 public class KeyEventArgs : EventArgs
969 /// Key - is the key sent to the view.
971 /// <since_tizen> 3 </since_tizen>
986 /// Event arguments that passed via the touch signal.
988 /// <since_tizen> 3 </since_tizen>
989 public class TouchEventArgs : EventArgs
991 private Touch _touch;
994 /// Touch - contains the information of touch points.
996 /// <since_tizen> 3 </since_tizen>
1011 /// Event arguments that passed via the hover signal.
1013 /// <since_tizen> 3 </since_tizen>
1014 public class HoverEventArgs : EventArgs
1016 private Hover _hover;
1019 /// Hover - contains touch points that represent the points that are currently being hovered or the points where a hover has stopped.
1021 /// <since_tizen> 3 </since_tizen>
1036 /// Event arguments that passed via the wheel signal.
1038 /// <since_tizen> 3 </since_tizen>
1039 public class WheelEventArgs : EventArgs
1041 private Wheel _wheel;
1044 /// WheelEvent - store a wheel rolling type: MOUSE_WHEEL or CUSTOM_WHEEL.
1046 /// <since_tizen> 3 </since_tizen>
1061 /// Event arguments of visibility changed.
1063 /// <since_tizen> 3 </since_tizen>
1064 public class VisibilityChangedEventArgs : EventArgs
1067 private bool _visibility;
1068 private VisibilityChangeType _type;
1071 /// The view, or child of view, whose visibility has changed.
1073 /// <since_tizen> 3 </since_tizen>
1087 /// Whether the view is now visible or not.
1089 /// <since_tizen> 3 </since_tizen>
1090 public bool Visibility
1098 _visibility = value;
1103 /// Whether the view's visible property has changed or a parent's.
1105 /// <since_tizen> 3 </since_tizen>
1106 public VisibilityChangeType Type
1120 /// Event arguments of layout direction changed.
1122 /// <since_tizen> 4 </since_tizen>
1123 public class LayoutDirectionChangedEventArgs : EventArgs
1126 private ViewLayoutDirectionType _type;
1129 /// The view, or child of view, whose layout direction has changed.
1131 /// <since_tizen> 4 </since_tizen>
1145 /// Whether the view's layout direction property has changed or a parent's.
1147 /// <since_tizen> 4 </since_tizen>
1148 public ViewLayoutDirectionType Type
1161 internal class BackgroundResourceLoadedEventArgs : EventArgs
1163 private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1164 public ResourceLoadingStatusType Status
1178 /// The class represents the information of the situation where the View's control state changes.
1180 [EditorBrowsable(EditorBrowsableState.Never)]
1181 public class ControlStateChangedEventArgs : EventArgs
1184 /// Create an instance with mandatory fields.
1186 /// <param name="previousState">The previous control state.</param>
1187 /// <param name="currentState">The current control state.</param>
1188 [EditorBrowsable(EditorBrowsableState.Never)]
1189 public ControlStateChangedEventArgs(ControlState previousState, ControlState currentState)
1191 PreviousState = previousState;
1192 CurrentState = currentState;
1196 /// The previous control state.
1198 [EditorBrowsable(EditorBrowsableState.Never)]
1199 public ControlState PreviousState { get; }
1202 /// The current control state.
1204 [EditorBrowsable(EditorBrowsableState.Never)]
1205 public ControlState CurrentState { get; }
1209 /// The expanded touch area.
1210 /// TouchArea can expand the view's touchable area.<br/>
1211 /// 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/>
1214 /// This is based on the top left x, y coordinates.<br/>
1215 /// For example) <br/>
1217 /// view.Size = new Size(100, 100);
1218 /// view.TouchAreaOffset = new Offset(-10, 20, 30, -40); // left, right, bottom, top
1220 /// Then, touch area is 130x170.<br/>
1221 /// This is view.width + TouchAreaOffset.right - TouchAreaOffset.left and view.height + TouchAreaOffset.bottom - TouchAreaOffset.top <br/>
1222 /// +---------------------+ <br/>
1228 /// | +----+----+ | <br/>
1230 /// | -10| | 20 | <br/>
1231 /// |<---+ +----->| <br/>
1234 /// | +----+----+ | <br/>
1239 /// +---------------------+ <br/>
1241 [EditorBrowsable(EditorBrowsableState.Never)]
1242 public Offset TouchAreaOffset
1246 return (Offset)GetValue(TouchAreaOffsetProperty);
1250 SetValue(TouchAreaOffsetProperty, value);
1251 NotifyPropertyChanged();
1255 private Offset InternalTouchAreaOffset
1259 Interop.ActorInternal.GetTouchAreaOffset(SwigCPtr, out int left, out int right, out int bottom, out int top);
1260 if (NDalicPINVOKE.SWIGPendingException.Pending)
1261 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1262 return new Offset(left, right, bottom, top);
1266 Interop.ActorInternal.SetTouchAreaOffset(SwigCPtr, value.Left, value.Right, value.Bottom, value.Top);
1267 if (NDalicPINVOKE.SWIGPendingException.Pending)
1268 throw NDalicPINVOKE.SWIGPendingException.Retrieve();