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