[NUI] Add InterceptTouchEvent (#2098)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / ViewEvent.cs
1 /*
2  * Copyright(c) 2020 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System;
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
21 using Tizen.NUI.Components;
22
23 namespace Tizen.NUI.BaseComponents
24 {
25     /// <summary>
26     /// View is the base class for all views.
27     /// </summary>
28     /// <since_tizen> 3 </since_tizen>
29     public partial class View
30     {
31         private EventHandler _offWindowEventHandler;
32         private OffWindowEventCallbackType _offWindowEventCallback;
33         private EventHandlerWithReturnType<object, WheelEventArgs, bool> _wheelEventHandler;
34         private WheelEventCallbackType _wheelEventCallback;
35         private EventHandlerWithReturnType<object, KeyEventArgs, bool> _keyEventHandler;
36         private KeyCallbackType _keyCallback;
37         private EventHandlerWithReturnType<object, TouchEventArgs, bool> _interceptTouchDataEventHandler;
38         private TouchDataCallbackType _interceptTouchDataCallback;
39         private EventHandlerWithReturnType<object, TouchEventArgs, bool> _touchDataEventHandler;
40         private TouchDataCallbackType _touchDataCallback;
41         private EventHandlerWithReturnType<object, HoverEventArgs, bool> _hoverEventHandler;
42         private HoverEventCallbackType _hoverEventCallback;
43         private EventHandler<VisibilityChangedEventArgs> _visibilityChangedEventHandler;
44         private VisibilityChangedEventCallbackType _visibilityChangedEventCallback;
45         private EventHandler _keyInputFocusGainedEventHandler;
46         private KeyInputFocusGainedCallbackType _keyInputFocusGainedCallback;
47         private EventHandler _keyInputFocusLostEventHandler;
48         private KeyInputFocusLostCallbackType _keyInputFocusLostCallback;
49         private EventHandler _onRelayoutEventHandler;
50         private OnRelayoutEventCallbackType _onRelayoutEventCallback;
51         private EventHandler _onWindowEventHandler;
52         private OnWindowEventCallbackType _onWindowEventCallback;
53         private EventHandler<LayoutDirectionChangedEventArgs> _layoutDirectionChangedEventHandler;
54         private LayoutDirectionChangedEventCallbackType _layoutDirectionChangedEventCallback;
55         // Resource Ready Signal
56         private EventHandler _resourcesLoadedEventHandler;
57         private ResourcesLoadedCallbackType _ResourcesLoadedCallback;
58         private EventHandler<BackgroundResourceLoadedEventArgs> _backgroundResourceLoadedEventHandler;
59         private _backgroundResourceLoadedCallbackType _backgroundResourceLoadedCallback;
60
61         private OnWindowEventCallbackType _onWindowSendEventCallback;
62
63         private void SendViewAddedEventToWindow(IntPtr data)
64         {
65             NUIApplication.GetDefaultWindow()?.SendViewAdded(this);
66         }
67
68         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
69         private delegate void OffWindowEventCallbackType(IntPtr control);
70         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
71         private delegate bool WheelEventCallbackType(IntPtr view, IntPtr wheelEvent);
72         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
73         private delegate bool KeyCallbackType(IntPtr control, IntPtr keyEvent);
74         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
75         private delegate bool TouchDataCallbackType(IntPtr view, IntPtr touchData);
76         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
77         private delegate bool HoverEventCallbackType(IntPtr view, IntPtr hoverEvent);
78         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
79         private delegate void VisibilityChangedEventCallbackType(IntPtr data, bool visibility, VisibilityChangeType type);
80         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
81         private delegate void ResourcesLoadedCallbackType(IntPtr control);
82         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
83         private delegate void _backgroundResourceLoadedCallbackType(IntPtr view);
84         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
85         private delegate void KeyInputFocusGainedCallbackType(IntPtr control);
86         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
87         private delegate void KeyInputFocusLostCallbackType(IntPtr control);
88         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
89         private delegate void OnRelayoutEventCallbackType(IntPtr control);
90         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
91         private delegate void OnWindowEventCallbackType(IntPtr control);
92         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
93         private delegate void LayoutDirectionChangedEventCallbackType(IntPtr data, ViewLayoutDirectionType type);
94
95         /// <summary>
96         /// Event when a child is removed.
97         /// </summary>
98         /// <since_tizen> 5 </since_tizen>
99         public new event EventHandler<ChildRemovedEventArgs> ChildRemoved;
100         /// <summary>
101         /// Event when a child is added.
102         /// </summary>
103         /// <since_tizen> 5 </since_tizen>
104         public new event EventHandler<ChildAddedEventArgs> ChildAdded;
105
106         /// <summary>
107         /// An event for the KeyInputFocusGained signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
108         /// The KeyInputFocusGained signal is emitted when the control gets the key input focus.<br />
109         /// </summary>
110         /// <since_tizen> 3 </since_tizen>
111         public event EventHandler FocusGained
112         {
113             add
114             {
115                 if (_keyInputFocusGainedEventHandler == null)
116                 {
117                     _keyInputFocusGainedCallback = OnKeyInputFocusGained;
118                     this.KeyInputFocusGainedSignal().Connect(_keyInputFocusGainedCallback);
119                 }
120
121                 _keyInputFocusGainedEventHandler += value;
122             }
123
124             remove
125             {
126                 _keyInputFocusGainedEventHandler -= value;
127
128                 if (_keyInputFocusGainedEventHandler == null && KeyInputFocusGainedSignal().Empty() == false)
129                 {
130                     this.KeyInputFocusGainedSignal().Disconnect(_keyInputFocusGainedCallback);
131                 }
132             }
133         }
134
135         /// <summary>
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 />
138         /// </summary>
139         /// <since_tizen> 3 </since_tizen>
140         public event EventHandler FocusLost
141         {
142             add
143             {
144                 if (_keyInputFocusLostEventHandler == null)
145                 {
146                     _keyInputFocusLostCallback = OnKeyInputFocusLost;
147                     this.KeyInputFocusLostSignal().Connect(_keyInputFocusLostCallback);
148                 }
149
150                 _keyInputFocusLostEventHandler += value;
151             }
152
153             remove
154             {
155                 _keyInputFocusLostEventHandler -= value;
156
157                 if (_keyInputFocusLostEventHandler == null && KeyInputFocusLostSignal().Empty() == false)
158                 {
159                     this.KeyInputFocusLostSignal().Disconnect(_keyInputFocusLostCallback);
160                 }
161             }
162         }
163
164         /// <summary>
165         /// An event for the KeyPressed signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
166         /// The KeyPressed signal is emitted when the key event is received.<br />
167         /// </summary>
168         /// <since_tizen> 3 </since_tizen>
169         public event EventHandlerWithReturnType<object, KeyEventArgs, bool> KeyEvent
170         {
171             add
172             {
173                 if (_keyEventHandler == null)
174                 {
175                     _keyCallback = OnKeyEvent;
176                     this.KeyEventSignal().Connect(_keyCallback);
177                 }
178
179                 _keyEventHandler += value;
180             }
181
182             remove
183             {
184                 _keyEventHandler -= value;
185
186                 if (_keyEventHandler == null && KeyEventSignal().Empty() == false)
187                 {
188                     this.KeyEventSignal().Disconnect(_keyCallback);
189                 }
190             }
191         }
192
193         /// <summary>
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 />
196         /// </summary>
197         /// <since_tizen> 3 </since_tizen>
198         public event EventHandler Relayout
199         {
200             add
201             {
202                 if (_onRelayoutEventHandler == null)
203                 {
204                     _onRelayoutEventCallback = OnRelayout;
205                     this.OnRelayoutSignal().Connect(_onRelayoutEventCallback);
206                 }
207
208                 _onRelayoutEventHandler += value;
209             }
210
211             remove
212             {
213                 _onRelayoutEventHandler -= value;
214
215                 if (_onRelayoutEventHandler == null && OnRelayoutSignal().Empty() == false)
216                 {
217                     this.OnRelayoutSignal().Disconnect(_onRelayoutEventCallback);
218                 }
219
220             }
221         }
222
223         /// <summary>
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 />
228         /// </summary>
229         [EditorBrowsable(EditorBrowsableState.Never)]
230         public event EventHandlerWithReturnType<object, TouchEventArgs, bool> InterceptTouchEvent
231         {
232             add
233             {
234                 if (_interceptTouchDataEventHandler == null)
235                 {
236                     _interceptTouchDataCallback = OnInterceptTouch;
237                     this.InterceptTouchSignal().Connect(_interceptTouchDataCallback);
238                 }
239
240                 _interceptTouchDataEventHandler += value;
241             }
242
243             remove
244             {
245                 _interceptTouchDataEventHandler -= value;
246
247                 if (_interceptTouchDataEventHandler == null && InterceptTouchSignal().Empty() == false)
248                 {
249                     this.InterceptTouchSignal().Disconnect(_interceptTouchDataCallback);
250                 }
251             }
252         }
253
254         /// <summary>
255         /// An event for the touched signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
256         /// The touched signal is emitted when the touch input is received.<br />
257         /// </summary>
258         /// <since_tizen> 3 </since_tizen>
259         public event EventHandlerWithReturnType<object, TouchEventArgs, bool> TouchEvent
260         {
261             add
262             {
263                 if (_touchDataEventHandler == null)
264                 {
265                     _touchDataCallback = OnTouch;
266                     this.TouchSignal().Connect(_touchDataCallback);
267                 }
268
269                 _touchDataEventHandler += value;
270             }
271
272             remove
273             {
274                 _touchDataEventHandler -= value;
275
276                 if (_touchDataEventHandler == null && TouchSignal().Empty() == false)
277                 {
278                     this.TouchSignal().Disconnect(_touchDataCallback);
279                 }
280             }
281         }
282
283         /// <summary>
284         /// An event for the hovered signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
285         /// The hovered signal is emitted when the hover input is received.<br />
286         /// </summary>
287         /// <since_tizen> 3 </since_tizen>
288         public event EventHandlerWithReturnType<object, HoverEventArgs, bool> HoverEvent
289         {
290             add
291             {
292                 if (_hoverEventHandler == null)
293                 {
294                     _hoverEventCallback = OnHoverEvent;
295                     this.HoveredSignal().Connect(_hoverEventCallback);
296                 }
297
298                 _hoverEventHandler += value;
299             }
300
301             remove
302             {
303                 _hoverEventHandler -= value;
304
305                 if (_hoverEventHandler == null && HoveredSignal().Empty() == false)
306                 {
307                     this.HoveredSignal().Disconnect(_hoverEventCallback);
308                 }
309
310             }
311         }
312
313         /// <summary>
314         /// An event for the WheelMoved signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
315         /// The WheelMoved signal is emitted when the wheel event is received.<br />
316         /// </summary>
317         /// <since_tizen> 3 </since_tizen>
318         public event EventHandlerWithReturnType<object, WheelEventArgs, bool> WheelEvent
319         {
320             add
321             {
322                 if (_wheelEventHandler == null)
323                 {
324                     _wheelEventCallback = OnWheelEvent;
325                     this.WheelEventSignal().Connect(_wheelEventCallback);
326                 }
327                 _wheelEventHandler += value;
328
329                 if (WindowWheelEventHandler == null)
330                 {
331                     NUIApplication.GetDefaultWindow().WheelEvent += OnWindowWheelEvent;
332                 }
333                 WindowWheelEventHandler += value;
334             }
335
336             remove
337             {
338                 _wheelEventHandler -= value;
339                 if (_wheelEventHandler == null && WheelEventSignal().Empty() == false)
340                 {
341                     this.WheelEventSignal().Disconnect(_wheelEventCallback);
342                 }
343
344                 WindowWheelEventHandler -= value;
345                 if (WindowWheelEventHandler == null)
346                 {
347                     NUIApplication.GetDefaultWindow().WheelEvent -= OnWindowWheelEvent;
348                 }
349             }
350         }
351
352         /// <summary>
353         /// An event for the OnWindow signal which can be used to subscribe or unsubscribe the event handler.<br />
354         /// The OnWindow signal is emitted after the view has been connected to the window.<br />
355         /// </summary>
356         /// <since_tizen> 3 </since_tizen>
357         public event EventHandler AddedToWindow
358         {
359             add
360             {
361                 if (_onWindowEventHandler == null)
362                 {
363                     _onWindowEventCallback = OnWindow;
364                     this.OnWindowSignal().Connect(_onWindowEventCallback);
365                 }
366
367                 _onWindowEventHandler += value;
368             }
369
370             remove
371             {
372                 _onWindowEventHandler -= value;
373
374                 if (_onWindowEventHandler == null && OnWindowSignal().Empty() == false)
375                 {
376                     this.OnWindowSignal().Disconnect(_onWindowEventCallback);
377                 }
378             }
379         }
380
381         /// <summary>
382         /// An event for the OffWindow signal, which can be used to subscribe or unsubscribe the event handler.<br />
383         /// OffWindow signal is emitted after the view has been disconnected from the window.<br />
384         /// </summary>
385         /// <since_tizen> 3 </since_tizen>
386         public event EventHandler RemovedFromWindow
387         {
388             add
389             {
390                 if (_offWindowEventHandler == null)
391                 {
392                     _offWindowEventCallback = OffWindow;
393                     this.OffWindowSignal().Connect(_offWindowEventCallback);
394                 }
395
396                 _offWindowEventHandler += value;
397             }
398
399             remove
400             {
401                 _offWindowEventHandler -= value;
402
403                 if (_offWindowEventHandler == null && OffWindowSignal().Empty() == false)
404                 {
405                     this.OffWindowSignal().Disconnect(_offWindowEventCallback);
406                 }
407             }
408         }
409
410         /// <summary>
411         /// An event for visibility change which can be used to subscribe or unsubscribe the event handler.<br />
412         /// This signal is emitted when the visible property of this or a parent view is changed.<br />
413         /// </summary>
414         /// <since_tizen> 3 </since_tizen>
415         public event EventHandler<VisibilityChangedEventArgs> VisibilityChanged
416         {
417             add
418             {
419                 if (_visibilityChangedEventHandler == null)
420                 {
421                     _visibilityChangedEventCallback = OnVisibilityChanged;
422                     VisibilityChangedSignal(this).Connect(_visibilityChangedEventCallback);
423                 }
424
425                 _visibilityChangedEventHandler += value;
426             }
427
428             remove
429             {
430                 _visibilityChangedEventHandler -= value;
431
432                 if (_visibilityChangedEventHandler == null && VisibilityChangedSignal(this).Empty() == false)
433                 {
434                     VisibilityChangedSignal(this).Disconnect(_visibilityChangedEventCallback);
435                 }
436             }
437         }
438
439         /// <summary>
440         /// Event for layout direction change which can be used to subscribe/unsubscribe the event handler.<br />
441         /// This signal is emitted when the layout direction property of this or a parent view is changed.<br />
442         /// </summary>
443         /// <since_tizen> 4 </since_tizen>
444         public event EventHandler<LayoutDirectionChangedEventArgs> LayoutDirectionChanged
445         {
446             add
447             {
448                 if (_layoutDirectionChangedEventHandler == null)
449                 {
450                     _layoutDirectionChangedEventCallback = OnLayoutDirectionChanged;
451                     LayoutDirectionChangedSignal(this).Connect(_layoutDirectionChangedEventCallback);
452                 }
453
454                 _layoutDirectionChangedEventHandler += value;
455             }
456
457             remove
458             {
459                 _layoutDirectionChangedEventHandler -= value;
460
461                 if (_layoutDirectionChangedEventHandler == null && LayoutDirectionChangedSignal(this).Empty() == false)
462                 {
463                     LayoutDirectionChangedSignal(this).Disconnect(_layoutDirectionChangedEventCallback);
464                 }
465             }
466         }
467
468         /// <summary>
469         /// An event for the ResourcesLoadedSignal signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
470         /// This signal is emitted after all resources required by a view are loaded and ready.<br />
471         /// </summary>
472         /// <since_tizen> 3 </since_tizen>
473         public event EventHandler ResourcesLoaded
474         {
475             add
476             {
477                 if (_resourcesLoadedEventHandler == null)
478                 {
479                     _ResourcesLoadedCallback = OnResourcesLoaded;
480                     this.ResourcesLoadedSignal().Connect(_ResourcesLoadedCallback);
481                 }
482
483                 _resourcesLoadedEventHandler += value;
484             }
485
486             remove
487             {
488                 _resourcesLoadedEventHandler -= value;
489
490                 if (_resourcesLoadedEventHandler == null && ResourcesLoadedSignal().Empty() == false)
491                 {
492                     this.ResourcesLoadedSignal().Disconnect(_ResourcesLoadedCallback);
493                 }
494             }
495         }
496
497         private EventHandler _backKeyPressed;
498
499         /// <summary>
500         /// An event for getting notice when physical back key is pressed.<br />
501         /// This event is emitted BackKey is up.<br />
502         /// </summary>
503         [EditorBrowsable(EditorBrowsableState.Never)]
504         public event EventHandler BackKeyPressed
505         {
506             add
507             {
508                 _backKeyPressed += value;
509                 BackKeyManager.Instance.Subscriber.Add(this);
510             }
511
512             remove
513             {
514                 BackKeyManager.Instance.Subscriber.Remove(this);
515                 _backKeyPressed -= value;
516             }
517         }
518
519         /// <summary>
520         /// Function for emitting BackKeyPressed event outside of View instance
521         /// </summary>
522         [EditorBrowsable(EditorBrowsableState.Never)]
523         internal void EmitBackKeyPressed()
524         {
525             _backKeyPressed.Invoke(this,null);
526         }
527
528
529         internal event EventHandler<BackgroundResourceLoadedEventArgs> BackgroundResourceLoaded
530         {
531             add
532             {
533                 if (_backgroundResourceLoadedEventHandler == null)
534                 {
535                     _backgroundResourceLoadedCallback = OnBackgroundResourceLoaded;
536                     this.ResourcesLoadedSignal().Connect(_backgroundResourceLoadedCallback);
537                 }
538
539                 _backgroundResourceLoadedEventHandler += value;
540             }
541             remove
542             {
543                 _backgroundResourceLoadedEventHandler -= value;
544
545                 if (_backgroundResourceLoadedEventHandler == null && ResourcesLoadedSignal().Empty() == false)
546                 {
547                     this.ResourcesLoadedSignal().Disconnect(_backgroundResourceLoadedCallback);
548                 }
549             }
550         }
551
552         internal TouchDataSignal InterceptTouchSignal()
553         {
554             TouchDataSignal ret = new TouchDataSignal(Interop.ActorSignal.Actor_InterceptTouchSignal(swigCPtr), false);
555             if (NDalicPINVOKE.SWIGPendingException.Pending)
556                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
557             return ret;
558         }
559
560         internal TouchDataSignal TouchSignal()
561         {
562             TouchDataSignal ret = new TouchDataSignal(Interop.ActorSignal.Actor_TouchSignal(swigCPtr), false);
563             if (NDalicPINVOKE.SWIGPendingException.Pending)
564                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
565             return ret;
566         }
567
568         internal HoverSignal HoveredSignal()
569         {
570             HoverSignal ret = new HoverSignal(Interop.ActorSignal.Actor_HoveredSignal(swigCPtr), false);
571             if (NDalicPINVOKE.SWIGPendingException.Pending)
572                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
573             return ret;
574         }
575
576         internal WheelSignal WheelEventSignal()
577         {
578             WheelSignal ret = new WheelSignal(Interop.ActorSignal.Actor_WheelEventSignal(swigCPtr), false);
579             if (NDalicPINVOKE.SWIGPendingException.Pending)
580                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
581             return ret;
582         }
583
584         internal ViewSignal OnWindowSignal()
585         {
586             ViewSignal ret = new ViewSignal(Interop.ActorSignal.Actor_OnSceneSignal(swigCPtr), false);
587             if (NDalicPINVOKE.SWIGPendingException.Pending)
588                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
589             return ret;
590         }
591
592         internal ViewSignal OffWindowSignal()
593         {
594             ViewSignal ret = new ViewSignal(Interop.ActorSignal.Actor_OffSceneSignal(swigCPtr), false);
595             if (NDalicPINVOKE.SWIGPendingException.Pending)
596                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
597             return ret;
598         }
599
600         internal ViewSignal OnRelayoutSignal()
601         {
602             ViewSignal ret = new ViewSignal(Interop.ActorSignal.Actor_OnRelayoutSignal(swigCPtr), false);
603             if (NDalicPINVOKE.SWIGPendingException.Pending)
604                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
605             return ret;
606         }
607
608         internal ViewVisibilityChangedSignal VisibilityChangedSignal(View view)
609         {
610             ViewVisibilityChangedSignal ret = new ViewVisibilityChangedSignal(Interop.NDalic.VisibilityChangedSignal(View.getCPtr(view)), false);
611             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
612             return ret;
613         }
614
615         internal ViewLayoutDirectionChangedSignal LayoutDirectionChangedSignal(View view)
616         {
617             ViewLayoutDirectionChangedSignal ret = new ViewLayoutDirectionChangedSignal(Interop.Layout.LayoutDirectionChangedSignal(View.getCPtr(view)), false);
618             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
619             return ret;
620         }
621
622         internal ViewSignal ResourcesLoadedSignal()
623         {
624             ViewSignal ret = new ViewSignal(Interop.View.ResourceReadySignal(swigCPtr), false);
625             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
626             return ret;
627         }
628
629         internal ControlKeySignal KeyEventSignal()
630         {
631             ControlKeySignal ret = new ControlKeySignal(Interop.ViewSignal.View_KeyEventSignal(swigCPtr), false);
632             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
633             return ret;
634         }
635
636         internal KeyInputFocusSignal KeyInputFocusGainedSignal()
637         {
638             KeyInputFocusSignal ret = new KeyInputFocusSignal(Interop.ViewSignal.View_KeyInputFocusGainedSignal(swigCPtr), false);
639             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
640             return ret;
641         }
642
643         internal KeyInputFocusSignal KeyInputFocusLostSignal()
644         {
645             KeyInputFocusSignal ret = new KeyInputFocusSignal(Interop.ViewSignal.View_KeyInputFocusLostSignal(swigCPtr), false);
646             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
647             return ret;
648         }
649
650         private void OnSize2DChanged(int? width, int? height)
651         {
652             if (width != null)
653             {
654                 Tizen.NUI.Object.SetProperty(this.swigCPtr, View.Property.SIZE_WIDTH, new Tizen.NUI.PropertyValue((float)width));
655             }
656             if (height != null)
657             {
658                 Tizen.NUI.Object.SetProperty(this.swigCPtr, View.Property.SIZE_HEIGHT, new Tizen.NUI.PropertyValue((float)height));
659             }
660         }
661
662         private void OnMinimumSizeChanged(int? width, int? height)
663         {
664             if (width != null && height != null)
665             {
666                 MinimumSize = new Size2D((int)width, (int)height);
667             }
668             else if (width != null && height == null)
669             {
670                 MinimumSize = new Size2D((int)width, (int)this.GetMinimumSize().Height);
671             }
672             else if (width == null && height != null)
673             {
674                 MinimumSize = new Size2D((int)this.GetMinimumSize().Width, (int)height);
675             }
676             else
677             {
678                 //both are null, do nothing.
679             }
680         }
681
682         private void OnMaximumSizeChanged(int? width, int? height)
683         {
684             if (width != null && height != null)
685             {
686                 MaximumSize = new Size2D((int)width, (int)height);
687             }
688             else if (width != null && height == null)
689             {
690                 MaximumSize = new Size2D((int)width, (int)this.GetMaximumSize().Height);
691             }
692             else if (width == null && height != null)
693             {
694                 MaximumSize = new Size2D((int)this.GetMaximumSize().Width, (int)height);
695             }
696             else
697             {
698                 //both are null, do nothing.
699             }
700         }
701
702         private void OnPosition2DChanged(int x, int y)
703         {
704             Position2D = new Position2D(x, y);
705         }
706
707         private void OnSizeChanged(float? width, float? height, float? depth)
708         {
709             if (width != null)
710             {
711                 Tizen.NUI.Object.SetProperty(this.swigCPtr, View.Property.SIZE_WIDTH, new Tizen.NUI.PropertyValue((float)width));
712             }
713             if (height != null)
714             {
715                 Tizen.NUI.Object.SetProperty(this.swigCPtr, View.Property.SIZE_HEIGHT, new Tizen.NUI.PropertyValue((float)height));
716             }
717             if (depth != null)
718             {
719                 Tizen.NUI.Object.SetProperty(this.swigCPtr, View.Property.SIZE_DEPTH, new Tizen.NUI.PropertyValue((float)depth));
720             }
721         }
722
723         private void OnPositionChanged(float x, float y, float z)
724         {
725             Position = new Position(x, y, z);
726         }
727
728         private void OnParentOriginChanged(float x, float y, float z)
729         {
730             ParentOrigin = new Position(x, y, z);
731         }
732
733         private void OnPivotPointChanged(float x, float y, float z)
734         {
735             PivotPoint = new Position(x, y, z);
736         }
737
738         private void OnImageShadowChanged(ShadowBase instance)
739         {
740             ImageShadow = (ImageShadow)instance;
741         }
742
743         private void OnBoxShadowChanged(ShadowBase instance)
744         {
745             BoxShadow = (Shadow)instance;
746         }
747
748         private void OnBackgroundImageBorderChanged(int left, int right, int bottom, int top)
749         {
750             BackgroundImageBorder = new Rectangle(left, right, bottom, top);
751         }
752
753         private void OnKeyInputFocusGained(IntPtr view)
754         {
755             if (_keyInputFocusGainedEventHandler != null)
756             {
757                 _keyInputFocusGainedEventHandler(this, null);
758             }
759         }
760
761         private void OnKeyInputFocusLost(IntPtr view)
762         {
763             if (_keyInputFocusLostEventHandler != null)
764             {
765                 _keyInputFocusLostEventHandler(this, null);
766             }
767         }
768
769         private bool OnKeyEvent(IntPtr view, IntPtr keyEvent)
770         {
771             if (keyEvent == global::System.IntPtr.Zero)
772             {
773                 NUILog.Error("keyEvent should not be null!");
774                 return true;
775             }
776
777             KeyEventArgs e = new KeyEventArgs();
778
779             bool result = false;
780
781             e.Key = Tizen.NUI.Key.GetKeyFromPtr(keyEvent);
782
783             if (_keyEventHandler != null)
784             {
785                 Delegate[] delegateList = _keyEventHandler.GetInvocationList();
786
787                 // Oring the result of each callback.
788                 foreach (EventHandlerWithReturnType<object, KeyEventArgs, bool> del in delegateList)
789                 {
790                     result |= del(this, e);
791                 }
792             }
793
794             return result;
795         }
796
797         // Callback for View OnRelayout signal
798         private void OnRelayout(IntPtr data)
799         {
800             if (_onRelayoutEventHandler != null)
801             {
802                 _onRelayoutEventHandler(this, null);
803             }
804         }
805
806         // Callback for View TouchSignal
807         private bool OnInterceptTouch(IntPtr view, IntPtr touchData)
808         {
809             if (touchData == global::System.IntPtr.Zero)
810             {
811                 NUILog.Error("touchData should not be null!");
812                 return true;
813             }
814
815             TouchEventArgs e = new TouchEventArgs();
816
817             e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
818
819             bool consumed = false;
820
821             if (_interceptTouchDataEventHandler != null)
822             {
823                 consumed = _interceptTouchDataEventHandler(this, e);
824             }
825
826             if (enableControlState && !consumed)
827             {
828                 consumed = HandleControlStateOnTouch(e.Touch);
829             }
830
831             return consumed;
832         }
833
834         // Callback for View TouchSignal
835         private bool OnTouch(IntPtr view, IntPtr touchData)
836         {
837             if (touchData == global::System.IntPtr.Zero)
838             {
839                 NUILog.Error("touchData should not be null!");
840                 return true;
841             }
842
843             TouchEventArgs e = new TouchEventArgs();
844
845             e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
846
847             bool consumed = false;
848
849             if (_touchDataEventHandler != null)
850             {
851                 consumed = _touchDataEventHandler(this, e);
852             }
853
854             if (enableControlState && !consumed)
855             {
856                 consumed = HandleControlStateOnTouch(e.Touch);
857             }
858
859             return consumed;
860         }
861
862         // Callback for View Hover signal
863         private bool OnHoverEvent(IntPtr view, IntPtr hoverEvent)
864         {
865             if (hoverEvent == global::System.IntPtr.Zero)
866             {
867                 NUILog.Error("hoverEvent should not be null!");
868                 return true;
869             }
870
871             HoverEventArgs e = new HoverEventArgs();
872
873             e.Hover = Tizen.NUI.Hover.GetHoverFromPtr(hoverEvent);
874
875             if (_hoverEventHandler != null)
876             {
877                 return _hoverEventHandler(this, e);
878             }
879             return false;
880         }
881
882         // Callback for View Wheel signal
883         private bool OnWheelEvent(IntPtr view, IntPtr wheelEvent)
884         {
885             if (wheelEvent == global::System.IntPtr.Zero)
886             {
887                 NUILog.Error("wheelEvent should not be null!");
888                 return true;
889             }
890
891             WheelEventArgs e = new WheelEventArgs();
892
893             e.Wheel = Tizen.NUI.Wheel.GetWheelFromPtr(wheelEvent);
894
895             if (_wheelEventHandler != null)
896             {
897                 return _wheelEventHandler(this, e);
898             }
899             return false;
900         }
901
902         // Callback for View OnWindow signal
903         private void OnWindow(IntPtr data)
904         {
905             if (_onWindowEventHandler != null)
906             {
907                 _onWindowEventHandler(this, null);
908             }
909         }
910
911         // Callback for View OffWindow signal
912         private void OffWindow(IntPtr data)
913         {
914             if (_offWindowEventHandler != null)
915             {
916                 _offWindowEventHandler(this, null);
917             }
918         }
919
920         // Callback for View visibility change signal
921         private void OnVisibilityChanged(IntPtr data, bool visibility, VisibilityChangeType type)
922         {
923             VisibilityChangedEventArgs e = new VisibilityChangedEventArgs();
924             if (data != null)
925             {
926                 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
927             }
928             e.Visibility = visibility;
929             e.Type = type;
930
931             if (_visibilityChangedEventHandler != null)
932             {
933                 _visibilityChangedEventHandler(this, e);
934             }
935         }
936
937         // Callback for View layout direction change signal
938         private void OnLayoutDirectionChanged(IntPtr data, ViewLayoutDirectionType type)
939         {
940             LayoutDirectionChangedEventArgs e = new LayoutDirectionChangedEventArgs();
941             if (data != null)
942             {
943                 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
944             }
945             e.Type = type;
946
947             if (_layoutDirectionChangedEventHandler != null)
948             {
949                 _layoutDirectionChangedEventHandler(this, e);
950             }
951         }
952
953         private void OnResourcesLoaded(IntPtr view)
954         {
955             if (_resourcesLoadedEventHandler != null)
956             {
957                 _resourcesLoadedEventHandler(this, null);
958             }
959         }
960
961         private void OnBackgroundResourceLoaded(IntPtr view)
962         {
963             BackgroundResourceLoadedEventArgs e = new BackgroundResourceLoadedEventArgs();
964             e.Status = (ResourceLoadingStatusType)Interop.View.View_GetVisualResourceStatus(this.swigCPtr, Property.BACKGROUND);
965
966             if (_backgroundResourceLoadedEventHandler != null)
967             {
968                 _backgroundResourceLoadedEventHandler(this, e);
969             }
970         }
971
972         /// <summary>
973         /// Event argument passed through the ChildAdded event.
974         /// </summary>
975         /// <since_tizen> 5 </since_tizen>
976         public class ChildAddedEventArgs : EventArgs
977         {
978             /// <summary>
979             /// Added child view at moment.
980             /// </summary>
981             /// <since_tizen> 5 </since_tizen>
982             public View Added { get; set; }
983         }
984
985         /// <summary>
986         /// Event argument passed through the ChildRemoved event.
987         /// </summary>
988         /// <since_tizen> 5 </since_tizen>
989         public class ChildRemovedEventArgs : EventArgs
990         {
991             /// <summary>
992             /// Removed child view at moment.
993             /// </summary>
994             /// <since_tizen> 5 </since_tizen>
995             public View Removed { get; set; }
996         }
997
998         /// <summary>
999         /// Event arguments that passed via the KeyEvent signal.
1000         /// </summary>
1001         /// <since_tizen> 3 </since_tizen>
1002         public class KeyEventArgs : EventArgs
1003         {
1004             private Key _key;
1005
1006             /// <summary>
1007             /// Key - is the key sent to the view.
1008             /// </summary>
1009             /// <since_tizen> 3 </since_tizen>
1010             public Key Key
1011             {
1012                 get
1013                 {
1014                     return _key;
1015                 }
1016                 set
1017                 {
1018                     _key = value;
1019                 }
1020             }
1021         }
1022
1023         /// <summary>
1024         /// Event arguments that passed via the touch signal.
1025         /// </summary>
1026         /// <since_tizen> 3 </since_tizen>
1027         public class TouchEventArgs : EventArgs
1028         {
1029             private Touch _touch;
1030
1031             /// <summary>
1032             /// Touch - contains the information of touch points.
1033             /// </summary>
1034             /// <since_tizen> 3 </since_tizen>
1035             public Touch Touch
1036             {
1037                 get
1038                 {
1039                     return _touch;
1040                 }
1041                 set
1042                 {
1043                     _touch = value;
1044                 }
1045             }
1046         }
1047
1048         /// <summary>
1049         /// Event arguments that passed via the hover signal.
1050         /// </summary>
1051         /// <since_tizen> 3 </since_tizen>
1052         public class HoverEventArgs : EventArgs
1053         {
1054             private Hover _hover;
1055
1056             /// <summary>
1057             /// Hover - contains touch points that represent the points that are currently being hovered or the points where a hover has stopped.
1058             /// </summary>
1059             /// <since_tizen> 3 </since_tizen>
1060             public Hover Hover
1061             {
1062                 get
1063                 {
1064                     return _hover;
1065                 }
1066                 set
1067                 {
1068                     _hover = value;
1069                 }
1070             }
1071         }
1072
1073         /// <summary>
1074         /// Event arguments that passed via the wheel signal.
1075         /// </summary>
1076         /// <since_tizen> 3 </since_tizen>
1077         public class WheelEventArgs : EventArgs
1078         {
1079             private Wheel _wheel;
1080
1081             /// <summary>
1082             /// WheelEvent - store a wheel rolling type: MOUSE_WHEEL or CUSTOM_WHEEL.
1083             /// </summary>
1084             /// <since_tizen> 3 </since_tizen>
1085             public Wheel Wheel
1086             {
1087                 get
1088                 {
1089                     return _wheel;
1090                 }
1091                 set
1092                 {
1093                     _wheel = value;
1094                 }
1095             }
1096         }
1097
1098         /// <summary>
1099         /// Event arguments of visibility changed.
1100         /// </summary>
1101         /// <since_tizen> 3 </since_tizen>
1102         public class VisibilityChangedEventArgs : EventArgs
1103         {
1104             private View _view;
1105             private bool _visibility;
1106             private VisibilityChangeType _type;
1107
1108             /// <summary>
1109             /// The view, or child of view, whose visibility has changed.
1110             /// </summary>
1111             /// <since_tizen> 3 </since_tizen>
1112             public View View
1113             {
1114                 get
1115                 {
1116                     return _view;
1117                 }
1118                 set
1119                 {
1120                     _view = value;
1121                 }
1122             }
1123
1124             /// <summary>
1125             /// Whether the view is now visible or not.
1126             /// </summary>
1127             /// <since_tizen> 3 </since_tizen>
1128             public bool Visibility
1129             {
1130                 get
1131                 {
1132                     return _visibility;
1133                 }
1134                 set
1135                 {
1136                     _visibility = value;
1137                 }
1138             }
1139
1140             /// <summary>
1141             /// Whether the view's visible property has changed or a parent's.
1142             /// </summary>
1143             /// <since_tizen> 3 </since_tizen>
1144             public VisibilityChangeType Type
1145             {
1146                 get
1147                 {
1148                     return _type;
1149                 }
1150                 set
1151                 {
1152                     _type = value;
1153                 }
1154             }
1155         }
1156
1157         /// <summary>
1158         /// Event arguments of layout direction changed.
1159         /// </summary>
1160         /// <since_tizen> 4 </since_tizen>
1161         public class LayoutDirectionChangedEventArgs : EventArgs
1162         {
1163             private View _view;
1164             private ViewLayoutDirectionType _type;
1165
1166             /// <summary>
1167             /// The view, or child of view, whose layout direction has changed.
1168             /// </summary>
1169             /// <since_tizen> 4 </since_tizen>
1170             public View View
1171             {
1172                 get
1173                 {
1174                     return _view;
1175                 }
1176                 set
1177                 {
1178                     _view = value;
1179                 }
1180             }
1181
1182             /// <summary>
1183             /// Whether the view's layout direction property has changed or a parent's.
1184             /// </summary>
1185             /// <since_tizen> 4 </since_tizen>
1186             public ViewLayoutDirectionType Type
1187             {
1188                 get
1189                 {
1190                     return _type;
1191                 }
1192                 set
1193                 {
1194                     _type = value;
1195                 }
1196             }
1197         }
1198
1199         internal class BackgroundResourceLoadedEventArgs : EventArgs
1200         {
1201             private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1202             public ResourceLoadingStatusType Status
1203             {
1204                 get
1205                 {
1206                     return status;
1207                 }
1208                 set
1209                 {
1210                     status = value;
1211                 }
1212             }
1213         }
1214
1215         /// <summary>
1216         /// The class represents the information of the situation where the View's control state changes.
1217         /// </summary>
1218         [EditorBrowsable(EditorBrowsableState.Never)]
1219         public class ControlStateChangedEventArgs : EventArgs
1220         {
1221             /// <summary>
1222             /// Create an instance with mandatory fields.
1223             /// </summary>
1224             /// <param name="previousState">The previous control state.</param>
1225             /// <param name="currentState">The current control state.</param>
1226             [EditorBrowsable(EditorBrowsableState.Never)]
1227             public ControlStateChangedEventArgs(ControlState previousState, ControlState currentState)
1228             {
1229                 PreviousState = previousState;
1230                 CurrentState = currentState;
1231             }
1232
1233             /// <summary>
1234             /// The previous control state.
1235             /// </summary>
1236             [EditorBrowsable(EditorBrowsableState.Never)]
1237             public ControlState PreviousState { get; }
1238
1239             /// <summary>
1240             /// The current control state.
1241             /// </summary>
1242             [EditorBrowsable(EditorBrowsableState.Never)]
1243             public ControlState CurrentState { get; }
1244         }
1245
1246         private EventHandlerWithReturnType<object, WheelEventArgs, bool> WindowWheelEventHandler;
1247         private void OnWindowWheelEvent(object sender, Window.WheelEventArgs e)
1248         {
1249             if(e != null)
1250             {
1251                 if(e.Wheel.Type == Wheel.WheelType.CustomWheel)
1252                 {
1253                     var arg = new WheelEventArgs()
1254                     {
1255                         Wheel = e.Wheel,
1256                     };
1257                     WindowWheelEventHandler?.Invoke(this, arg);
1258                 }
1259             }
1260         }
1261
1262     }
1263 }