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