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