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