[NUI] Fix Dropdown runtime error (#1232)
[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
294                 _wheelEventHandler += value;
295             }
296
297             remove
298             {
299                 _wheelEventHandler -= value;
300
301                 if (_wheelEventHandler == null && WheelEventSignal().Empty() == false)
302                 {
303                     this.WheelEventSignal().Disconnect(_wheelEventCallback);
304                 }
305
306             }
307         }
308
309         /// <summary>
310         /// An event for the OnWindow signal which can be used to subscribe or unsubscribe the event handler.<br />
311         /// The OnWindow signal is emitted after the view has been connected to the window.<br />
312         /// </summary>
313         /// <since_tizen> 3 </since_tizen>
314         public event EventHandler AddedToWindow
315         {
316             add
317             {
318                 if (_onWindowEventHandler == null)
319                 {
320                     _onWindowEventCallback = OnWindow;
321                     this.OnWindowSignal().Connect(_onWindowEventCallback);
322                 }
323
324                 _onWindowEventHandler += value;
325             }
326
327             remove
328             {
329                 _onWindowEventHandler -= value;
330
331                 if (_onWindowEventHandler == null && OnWindowSignal().Empty() == false)
332                 {
333                     this.OnWindowSignal().Disconnect(_onWindowEventCallback);
334                 }
335             }
336         }
337
338         /// <summary>
339         /// An event for the OffWindow signal, which can be used to subscribe or unsubscribe the event handler.<br />
340         /// OffWindow signal is emitted after the view has been disconnected from the window.<br />
341         /// </summary>
342         /// <since_tizen> 3 </since_tizen>
343         public event EventHandler RemovedFromWindow
344         {
345             add
346             {
347                 if (_offWindowEventHandler == null)
348                 {
349                     _offWindowEventCallback = OffWindow;
350                     this.OffWindowSignal().Connect(_offWindowEventCallback);
351                 }
352
353                 _offWindowEventHandler += value;
354             }
355
356             remove
357             {
358                 _offWindowEventHandler -= value;
359
360                 if (_offWindowEventHandler == null && OffWindowSignal().Empty() == false)
361                 {
362                     this.OffWindowSignal().Disconnect(_offWindowEventCallback);
363                 }
364             }
365         }
366
367         /// <summary>
368         /// An event for visibility change which can be used to subscribe or unsubscribe the event handler.<br />
369         /// This signal is emitted when the visible property of this or a parent view is changed.<br />
370         /// </summary>
371         /// <since_tizen> 3 </since_tizen>
372         public event EventHandler<VisibilityChangedEventArgs> VisibilityChanged
373         {
374             add
375             {
376                 if (_visibilityChangedEventHandler == null)
377                 {
378                     _visibilityChangedEventCallback = OnVisibilityChanged;
379                     VisibilityChangedSignal(this).Connect(_visibilityChangedEventCallback);
380                 }
381
382                 _visibilityChangedEventHandler += value;
383             }
384
385             remove
386             {
387                 _visibilityChangedEventHandler -= value;
388
389                 if (_visibilityChangedEventHandler == null && VisibilityChangedSignal(this).Empty() == false)
390                 {
391                     VisibilityChangedSignal(this).Disconnect(_visibilityChangedEventCallback);
392                 }
393             }
394         }
395
396         /// <summary>
397         /// Event for layout direction change which can be used to subscribe/unsubscribe the event handler.<br />
398         /// This signal is emitted when the layout direction property of this or a parent view is changed.<br />
399         /// </summary>
400         /// <since_tizen> 4 </since_tizen>
401         public event EventHandler<LayoutDirectionChangedEventArgs> LayoutDirectionChanged
402         {
403             add
404             {
405                 if (_layoutDirectionChangedEventHandler == null)
406                 {
407                     _layoutDirectionChangedEventCallback = OnLayoutDirectionChanged;
408                     LayoutDirectionChangedSignal(this).Connect(_layoutDirectionChangedEventCallback);
409                 }
410
411                 _layoutDirectionChangedEventHandler += value;
412             }
413
414             remove
415             {
416                 _layoutDirectionChangedEventHandler -= value;
417
418                 if (_layoutDirectionChangedEventHandler == null && LayoutDirectionChangedSignal(this).Empty() == false)
419                 {
420                     LayoutDirectionChangedSignal(this).Disconnect(_layoutDirectionChangedEventCallback);
421                 }
422             }
423         }
424
425         /// <summary>
426         /// An event for the ResourcesLoadedSignal signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
427         /// This signal is emitted after all resources required by a view are loaded and ready.<br />
428         /// </summary>
429         /// <since_tizen> 3 </since_tizen>
430         public event EventHandler ResourcesLoaded
431         {
432             add
433             {
434                 if (_resourcesLoadedEventHandler == null)
435                 {
436                     _ResourcesLoadedCallback = OnResourcesLoaded;
437                     this.ResourcesLoadedSignal().Connect(_ResourcesLoadedCallback);
438                 }
439
440                 _resourcesLoadedEventHandler += value;
441             }
442
443             remove
444             {
445                 _resourcesLoadedEventHandler -= value;
446
447                 if (_resourcesLoadedEventHandler == null && ResourcesLoadedSignal().Empty() == false)
448                 {
449                     this.ResourcesLoadedSignal().Disconnect(_ResourcesLoadedCallback);
450                 }
451             }
452         }
453
454         internal event EventHandler<BackgroundResourceLoadedEventArgs> BackgroundResourceLoaded
455         {
456             add
457             {
458                 if (_backgroundResourceLoadedEventHandler == null)
459                 {
460                     _backgroundResourceLoadedCallback = OnBackgroundResourceLoaded;
461                     this.ResourcesLoadedSignal().Connect(_backgroundResourceLoadedCallback);
462                 }
463
464                 _backgroundResourceLoadedEventHandler += value;
465             }
466             remove
467             {
468                 _backgroundResourceLoadedEventHandler -= value;
469
470                 if (_backgroundResourceLoadedEventHandler == null && ResourcesLoadedSignal().Empty() == false)
471                 {
472                     this.ResourcesLoadedSignal().Disconnect(_backgroundResourceLoadedCallback);
473                 }
474             }
475         }
476
477         internal TouchDataSignal TouchSignal()
478         {
479             TouchDataSignal ret = new TouchDataSignal(Interop.ActorSignal.Actor_TouchSignal(swigCPtr), false);
480             if (NDalicPINVOKE.SWIGPendingException.Pending)
481                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
482             return ret;
483         }
484
485         internal HoverSignal HoveredSignal()
486         {
487             HoverSignal ret = new HoverSignal(Interop.ActorSignal.Actor_HoveredSignal(swigCPtr), false);
488             if (NDalicPINVOKE.SWIGPendingException.Pending)
489                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
490             return ret;
491         }
492
493         internal WheelSignal WheelEventSignal()
494         {
495             WheelSignal ret = new WheelSignal(Interop.ActorSignal.Actor_WheelEventSignal(swigCPtr), false);
496             if (NDalicPINVOKE.SWIGPendingException.Pending)
497                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
498             return ret;
499         }
500
501         internal ViewSignal OnWindowSignal()
502         {
503             ViewSignal ret = new ViewSignal(Interop.ActorSignal.Actor_OnStageSignal(swigCPtr), false);
504             if (NDalicPINVOKE.SWIGPendingException.Pending)
505                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
506             return ret;
507         }
508
509         internal ViewSignal OffWindowSignal()
510         {
511             ViewSignal ret = new ViewSignal(Interop.ActorSignal.Actor_OffStageSignal(swigCPtr), false);
512             if (NDalicPINVOKE.SWIGPendingException.Pending)
513                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
514             return ret;
515         }
516
517         internal ViewSignal OnRelayoutSignal()
518         {
519             ViewSignal ret = new ViewSignal(Interop.ActorSignal.Actor_OnRelayoutSignal(swigCPtr), false);
520             if (NDalicPINVOKE.SWIGPendingException.Pending)
521                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
522             return ret;
523         }
524
525         internal ViewVisibilityChangedSignal VisibilityChangedSignal(View view)
526         {
527             ViewVisibilityChangedSignal ret = new ViewVisibilityChangedSignal(Interop.NDalic.VisibilityChangedSignal(View.getCPtr(view)), false);
528             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
529             return ret;
530         }
531
532         internal ViewLayoutDirectionChangedSignal LayoutDirectionChangedSignal(View view)
533         {
534             ViewLayoutDirectionChangedSignal ret = new ViewLayoutDirectionChangedSignal(Interop.Layout.LayoutDirectionChangedSignal(View.getCPtr(view)), false);
535             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
536             return ret;
537         }
538
539         internal ViewSignal ResourcesLoadedSignal()
540         {
541             ViewSignal ret = new ViewSignal(Interop.View.ResourceReadySignal(swigCPtr), false);
542             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
543             return ret;
544         }
545
546         internal ControlKeySignal KeyEventSignal()
547         {
548             ControlKeySignal ret = new ControlKeySignal(Interop.ViewSignal.View_KeyEventSignal(swigCPtr), false);
549             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
550             return ret;
551         }
552
553         internal KeyInputFocusSignal KeyInputFocusGainedSignal()
554         {
555             KeyInputFocusSignal ret = new KeyInputFocusSignal(Interop.ViewSignal.View_KeyInputFocusGainedSignal(swigCPtr), false);
556             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
557             return ret;
558         }
559
560         internal KeyInputFocusSignal KeyInputFocusLostSignal()
561         {
562             KeyInputFocusSignal ret = new KeyInputFocusSignal(Interop.ViewSignal.View_KeyInputFocusLostSignal(swigCPtr), false);
563             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
564             return ret;
565         }
566
567         private void OnSize2DChanged(int width, int height)
568         {
569             Size2D = new Size2D(width, height);
570         }
571
572         private void OnMinimumSizeChanged(int width, int height)
573         {
574             MinimumSize = new Size2D(width, height);
575         }
576
577         private void OnMaximumSizeChanged(int width, int height)
578         {
579             MaximumSize = new Size2D(width, height);
580         }
581
582         private void OnPosition2DChanged(int x, int y)
583         {
584             Position2D = new Position2D(x, y);
585         }
586
587         private void OnSizeChanged(float width, float height, float depth)
588         {
589             Size = new Size(width, height, depth);
590         }
591
592         private void OnPositionChanged(float x, float y, float z)
593         {
594             Position = new Position(x, y, z);
595         }
596
597         private void OnParentOriginChanged(float x, float y, float z)
598         {
599             ParentOrigin = new Position(x, y, z);
600         }
601
602         private void OnPivotPointChanged(float x, float y, float z)
603         {
604             PivotPoint = new Position(x, y, z);
605         }
606
607         private void OnKeyInputFocusGained(IntPtr view)
608         {
609             if (_keyInputFocusGainedEventHandler != null)
610             {
611                 _keyInputFocusGainedEventHandler(this, null);
612             }
613         }
614
615         private void OnKeyInputFocusLost(IntPtr view)
616         {
617             if (_keyInputFocusLostEventHandler != null)
618             {
619                 _keyInputFocusLostEventHandler(this, null);
620             }
621         }
622
623         private bool OnKeyEvent(IntPtr view, IntPtr keyEvent)
624         {
625             if (keyEvent == global::System.IntPtr.Zero)
626             {
627                 NUILog.Error("keyEvent should not be null!");
628                 return true;
629             }
630
631             KeyEventArgs e = new KeyEventArgs();
632
633             bool result = false;
634
635             e.Key = Tizen.NUI.Key.GetKeyFromPtr(keyEvent);
636
637             if (_keyEventHandler != null)
638             {
639                 Delegate[] delegateList = _keyEventHandler.GetInvocationList();
640
641                 // Oring the result of each callback.
642                 foreach (EventHandlerWithReturnType<object, KeyEventArgs, bool> del in delegateList)
643                 {
644                     result |= del(this, e);
645                 }
646             }
647
648             return result;
649         }
650
651         // Callback for View OnRelayout signal
652         private void OnRelayout(IntPtr data)
653         {
654             if (_onRelayoutEventHandler != null)
655             {
656                 _onRelayoutEventHandler(this, null);
657             }
658         }
659
660         // Callback for View TouchSignal
661         private bool OnTouch(IntPtr view, IntPtr touchData)
662         {
663             if (touchData == global::System.IntPtr.Zero)
664             {
665                 NUILog.Error("touchData should not be null!");
666                 return true;
667             }
668
669             TouchEventArgs e = new TouchEventArgs();
670
671             e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
672
673             if (_touchDataEventHandler != null)
674             {
675                 return _touchDataEventHandler(this, e);
676             }
677             return false;
678         }
679
680         // Callback for View Hover signal
681         private bool OnHoverEvent(IntPtr view, IntPtr hoverEvent)
682         {
683             if (hoverEvent == global::System.IntPtr.Zero)
684             {
685                 NUILog.Error("hoverEvent should not be null!");
686                 return true;
687             }
688
689             HoverEventArgs e = new HoverEventArgs();
690
691             e.Hover = Tizen.NUI.Hover.GetHoverFromPtr(hoverEvent);
692
693             if (_hoverEventHandler != null)
694             {
695                 return _hoverEventHandler(this, e);
696             }
697             return false;
698         }
699
700         // Callback for View Wheel signal
701         private bool OnWheelEvent(IntPtr view, IntPtr wheelEvent)
702         {
703             if (wheelEvent == global::System.IntPtr.Zero)
704             {
705                 NUILog.Error("wheelEvent should not be null!");
706                 return true;
707             }
708
709             WheelEventArgs e = new WheelEventArgs();
710
711             e.Wheel = Tizen.NUI.Wheel.GetWheelFromPtr(wheelEvent);
712
713             if (_wheelEventHandler != null)
714             {
715                 return _wheelEventHandler(this, e);
716             }
717             return false;
718         }
719
720         // Callback for View OnWindow signal
721         private void OnWindow(IntPtr data)
722         {
723             if (_onWindowEventHandler != null)
724             {
725                 _onWindowEventHandler(this, null);
726             }
727         }
728
729         // Callback for View OffWindow signal
730         private void OffWindow(IntPtr data)
731         {
732             if (_offWindowEventHandler != null)
733             {
734                 _offWindowEventHandler(this, null);
735             }
736         }
737
738         // Callback for View visibility change signal
739         private void OnVisibilityChanged(IntPtr data, bool visibility, VisibilityChangeType type)
740         {
741             VisibilityChangedEventArgs e = new VisibilityChangedEventArgs();
742             if (data != null)
743             {
744                 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
745             }
746             e.Visibility = visibility;
747             e.Type = type;
748
749             if (_visibilityChangedEventHandler != null)
750             {
751                 _visibilityChangedEventHandler(this, e);
752             }
753         }
754
755         // Callback for View layout direction change signal
756         private void OnLayoutDirectionChanged(IntPtr data, ViewLayoutDirectionType type)
757         {
758             LayoutDirectionChangedEventArgs e = new LayoutDirectionChangedEventArgs();
759             if (data != null)
760             {
761                 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
762             }
763             e.Type = type;
764
765             if (_layoutDirectionChangedEventHandler != null)
766             {
767                 _layoutDirectionChangedEventHandler(this, e);
768             }
769         }
770
771         private void OnResourcesLoaded(IntPtr view)
772         {
773             if (_resourcesLoadedEventHandler != null)
774             {
775                 _resourcesLoadedEventHandler(this, null);
776             }
777         }
778
779         private void OnBackgroundResourceLoaded(IntPtr view)
780         {
781             BackgroundResourceLoadedEventArgs e = new BackgroundResourceLoadedEventArgs();
782             e.Status = (ResourceLoadingStatusType)Interop.View.View_GetVisualResourceStatus(this.swigCPtr, Property.BACKGROUND);
783
784             if (_backgroundResourceLoadedEventHandler != null)
785             {
786                 _backgroundResourceLoadedEventHandler(this, e);
787             }
788         }
789
790         /// <summary>
791         /// Event argument passed through the ChildAdded event.
792         /// </summary>
793         /// <since_tizen> 5 </since_tizen>
794         public class ChildAddedEventArgs : EventArgs
795         {
796             /// <summary>
797             /// Added child view at moment.
798             /// </summary>
799             /// <since_tizen> 5 </since_tizen>
800             public View Added { get; set; }
801         }
802
803         /// <summary>
804         /// Event argument passed through the ChildRemoved event.
805         /// </summary>
806         /// <since_tizen> 5 </since_tizen>
807         public class ChildRemovedEventArgs : EventArgs
808         {
809             /// <summary>
810             /// Removed child view at moment.
811             /// </summary>
812             /// <since_tizen> 5 </since_tizen>
813             public View Removed { get; set; }
814         }
815
816         /// <summary>
817         /// Event arguments that passed via the KeyEvent signal.
818         /// </summary>
819         /// <since_tizen> 3 </since_tizen>
820         public class KeyEventArgs : EventArgs
821         {
822             private Key _key;
823
824             /// <summary>
825             /// Key - is the key sent to the view.
826             /// </summary>
827             /// <since_tizen> 3 </since_tizen>
828             public Key Key
829             {
830                 get
831                 {
832                     return _key;
833                 }
834                 set
835                 {
836                     _key = value;
837                 }
838             }
839         }
840
841         /// <summary>
842         /// Event arguments that passed via the touch signal.
843         /// </summary>
844         /// <since_tizen> 3 </since_tizen>
845         public class TouchEventArgs : EventArgs
846         {
847             private Touch _touch;
848
849             /// <summary>
850             /// Touch - contains the information of touch points.
851             /// </summary>
852             /// <since_tizen> 3 </since_tizen>
853             public Touch Touch
854             {
855                 get
856                 {
857                     return _touch;
858                 }
859                 set
860                 {
861                     _touch = value;
862                 }
863             }
864         }
865
866         /// <summary>
867         /// Event arguments that passed via the hover signal.
868         /// </summary>
869         /// <since_tizen> 3 </since_tizen>
870         public class HoverEventArgs : EventArgs
871         {
872             private Hover _hover;
873
874             /// <summary>
875             /// Hover - contains touch points that represent the points that are currently being hovered or the points where a hover has stopped.
876             /// </summary>
877             /// <since_tizen> 3 </since_tizen>
878             public Hover Hover
879             {
880                 get
881                 {
882                     return _hover;
883                 }
884                 set
885                 {
886                     _hover = value;
887                 }
888             }
889         }
890
891         /// <summary>
892         /// Event arguments that passed via the wheel signal.
893         /// </summary>
894         /// <since_tizen> 3 </since_tizen>
895         public class WheelEventArgs : EventArgs
896         {
897             private Wheel _wheel;
898
899             /// <summary>
900             /// WheelEvent - store a wheel rolling type: MOUSE_WHEEL or CUSTOM_WHEEL.
901             /// </summary>
902             /// <since_tizen> 3 </since_tizen>
903             public Wheel Wheel
904             {
905                 get
906                 {
907                     return _wheel;
908                 }
909                 set
910                 {
911                     _wheel = value;
912                 }
913             }
914         }
915
916         /// <summary>
917         /// Event arguments of visibility changed.
918         /// </summary>
919         /// <since_tizen> 3 </since_tizen>
920         public class VisibilityChangedEventArgs : EventArgs
921         {
922             private View _view;
923             private bool _visibility;
924             private VisibilityChangeType _type;
925
926             /// <summary>
927             /// The view, or child of view, whose visibility has changed.
928             /// </summary>
929             /// <since_tizen> 3 </since_tizen>
930             public View View
931             {
932                 get
933                 {
934                     return _view;
935                 }
936                 set
937                 {
938                     _view = value;
939                 }
940             }
941
942             /// <summary>
943             /// Whether the view is now visible or not.
944             /// </summary>
945             /// <since_tizen> 3 </since_tizen>
946             public bool Visibility
947             {
948                 get
949                 {
950                     return _visibility;
951                 }
952                 set
953                 {
954                     _visibility = value;
955                 }
956             }
957
958             /// <summary>
959             /// Whether the view's visible property has changed or a parent's.
960             /// </summary>
961             /// <since_tizen> 3 </since_tizen>
962             public VisibilityChangeType Type
963             {
964                 get
965                 {
966                     return _type;
967                 }
968                 set
969                 {
970                     _type = value;
971                 }
972             }
973         }
974
975         /// <summary>
976         /// Event arguments of layout direction changed.
977         /// </summary>
978         /// <since_tizen> 4 </since_tizen>
979         public class LayoutDirectionChangedEventArgs : EventArgs
980         {
981             private View _view;
982             private ViewLayoutDirectionType _type;
983
984             /// <summary>
985             /// The view, or child of view, whose layout direction has changed.
986             /// </summary>
987             /// <since_tizen> 4 </since_tizen>
988             public View View
989             {
990                 get
991                 {
992                     return _view;
993                 }
994                 set
995                 {
996                     _view = value;
997                 }
998             }
999
1000             /// <summary>
1001             /// Whether the view's layout direction property has changed or a parent's.
1002             /// </summary>
1003             /// <since_tizen> 4 </since_tizen>
1004             public ViewLayoutDirectionType Type
1005             {
1006                 get
1007                 {
1008                     return _type;
1009                 }
1010                 set
1011                 {
1012                     _type = value;
1013                 }
1014             }
1015         }
1016
1017         internal class BackgroundResourceLoadedEventArgs : EventArgs
1018         {
1019             private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1020             public ResourceLoadingStatusType Status
1021             {
1022                 get
1023                 {
1024                     return status;
1025                 }
1026                 set
1027                 {
1028                     status = value;
1029                 }
1030             }
1031         }
1032     }
1033 }