[NUI] Fix CA2000 Warnings for View (#2546)
[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             PropertyValue temp;
674             if (width != null)
675             {
676                 temp = new Tizen.NUI.PropertyValue((float)width);
677                 Tizen.NUI.Object.SetProperty(this.SwigCPtr, View.Property.SizeWidth, temp);
678                 temp.Dispose();
679             }
680             if (height != null)
681             {
682                 temp = new Tizen.NUI.PropertyValue((float)height);
683                 Tizen.NUI.Object.SetProperty(this.SwigCPtr, View.Property.SizeHeight, temp);
684                 temp.Dispose();
685             }
686         }
687
688         private void OnMinimumSizeChanged(int? width, int? height)
689         {
690             if (width != null && height != null)
691             {
692                 MinimumSize = new Size2D((int)width, (int)height);
693             }
694             else if (width != null && height == null)
695             {
696                 MinimumSize = new Size2D((int)width, (int)this.GetMinimumSize().Height);
697             }
698             else if (width == null && height != null)
699             {
700                 MinimumSize = new Size2D((int)this.GetMinimumSize().Width, (int)height);
701             }
702             else
703             {
704                 //both are null, do nothing.
705             }
706         }
707
708         private void OnMaximumSizeChanged(int? width, int? height)
709         {
710             if (width != null && height != null)
711             {
712                 MaximumSize = new Size2D((int)width, (int)height);
713             }
714             else if (width != null && height == null)
715             {
716                 MaximumSize = new Size2D((int)width, (int)this.GetMaximumSize().Height);
717             }
718             else if (width == null && height != null)
719             {
720                 MaximumSize = new Size2D((int)this.GetMaximumSize().Width, (int)height);
721             }
722             else
723             {
724                 //both are null, do nothing.
725             }
726         }
727
728         private void OnPosition2DChanged(int x, int y)
729         {
730             Position2D = new Position2D(x, y);
731         }
732
733         private void OnSizeChanged(float? width, float? height, float? depth)
734         {
735             PropertyValue temp;
736             if (width != null)
737             {
738                 temp = new Tizen.NUI.PropertyValue((float)width);
739                 Tizen.NUI.Object.SetProperty(this.SwigCPtr, View.Property.SizeWidth, temp);
740                 temp.Dispose();
741             }
742             if (height != null)
743             {
744                 temp = new Tizen.NUI.PropertyValue((float)height);
745                 Tizen.NUI.Object.SetProperty(this.SwigCPtr, View.Property.SizeHeight, temp);
746                 temp.Dispose();
747             }
748             if (depth != null)
749             {
750                 temp = new Tizen.NUI.PropertyValue((float)depth);
751                 Tizen.NUI.Object.SetProperty(this.SwigCPtr, View.Property.SizeDepth, temp);
752                 temp.Dispose();
753             }
754         }
755
756         private void OnPositionChanged(float x, float y, float z)
757         {
758             Position = new Position(x, y, z);
759         }
760
761         private void OnParentOriginChanged(float x, float y, float z)
762         {
763             ParentOrigin = new Position(x, y, z);
764         }
765
766         private void OnPivotPointChanged(float x, float y, float z)
767         {
768             PivotPoint = new Position(x, y, z);
769         }
770
771         private void OnImageShadowChanged(ShadowBase instance)
772         {
773             ImageShadow = (ImageShadow)instance;
774         }
775
776         private void OnBoxShadowChanged(ShadowBase instance)
777         {
778             BoxShadow = (Shadow)instance;
779         }
780
781         private void OnBackgroundImageBorderChanged(int left, int right, int bottom, int top)
782         {
783             BackgroundImageBorder = new Rectangle(left, right, bottom, top);
784         }
785
786         private void OnKeyInputFocusGained(IntPtr view)
787         {
788             if (_keyInputFocusGainedEventHandler != null)
789             {
790                 _keyInputFocusGainedEventHandler(this, null);
791             }
792         }
793
794         private void OnKeyInputFocusLost(IntPtr view)
795         {
796             if (_keyInputFocusLostEventHandler != null)
797             {
798                 _keyInputFocusLostEventHandler(this, null);
799             }
800         }
801
802         private bool OnKeyEvent(IntPtr view, IntPtr keyEvent)
803         {
804             if (keyEvent == global::System.IntPtr.Zero)
805             {
806                 NUILog.Error("keyEvent should not be null!");
807                 return true;
808             }
809
810             KeyEventArgs e = new KeyEventArgs();
811
812             bool result = false;
813
814             e.Key = Tizen.NUI.Key.GetKeyFromPtr(keyEvent);
815
816             if (_keyEventHandler != null)
817             {
818                 Delegate[] delegateList = _keyEventHandler.GetInvocationList();
819
820                 // Oring the result of each callback.
821                 foreach (EventHandlerWithReturnType<object, KeyEventArgs, bool> del in delegateList)
822                 {
823                     result |= del(this, e);
824                 }
825             }
826
827             return result;
828         }
829
830         // Callback for View OnRelayout signal
831         private void OnRelayout(IntPtr data)
832         {
833             if (_onRelayoutEventHandler != null)
834             {
835                 _onRelayoutEventHandler(this, null);
836             }
837         }
838
839         // Callback for View TouchSignal
840         private bool OnInterceptTouch(IntPtr view, IntPtr touchData)
841         {
842             if (touchData == global::System.IntPtr.Zero)
843             {
844                 NUILog.Error("touchData should not be null!");
845                 return true;
846             }
847
848             // DisallowInterceptTouchEvent prevents the parent from intercepting touch.
849             if (DisallowInterceptTouchEvent)
850             {
851                 return false;
852             }
853
854             TouchEventArgs e = new TouchEventArgs();
855
856             e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
857
858             bool consumed = false;
859
860             if (_interceptTouchDataEventHandler != null)
861             {
862                 consumed = _interceptTouchDataEventHandler(this, e);
863             }
864
865             return consumed;
866         }
867
868         // Callback for View TouchSignal
869         private bool OnTouch(IntPtr view, IntPtr touchData)
870         {
871             if (touchData == global::System.IntPtr.Zero)
872             {
873                 NUILog.Error("touchData should not be null!");
874                 return true;
875             }
876
877             TouchEventArgs e = new TouchEventArgs();
878
879             e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
880
881             bool consumed = false;
882
883             if (_touchDataEventHandler != null)
884             {
885                 consumed = _touchDataEventHandler(this, e);
886             }
887
888             if (enableControlState && !consumed)
889             {
890                 consumed = HandleControlStateOnTouch(e.Touch);
891             }
892
893             return consumed;
894         }
895
896         // Callback for View Hover signal
897         private bool OnHoverEvent(IntPtr view, IntPtr hoverEvent)
898         {
899             if (hoverEvent == global::System.IntPtr.Zero)
900             {
901                 NUILog.Error("hoverEvent should not be null!");
902                 return true;
903             }
904
905             HoverEventArgs e = new HoverEventArgs();
906
907             e.Hover = Tizen.NUI.Hover.GetHoverFromPtr(hoverEvent);
908
909             if (_hoverEventHandler != null)
910             {
911                 return _hoverEventHandler(this, e);
912             }
913             return false;
914         }
915
916         // Callback for View Wheel signal
917         private bool OnWheelEvent(IntPtr view, IntPtr wheelEvent)
918         {
919             if (wheelEvent == global::System.IntPtr.Zero)
920             {
921                 NUILog.Error("wheelEvent should not be null!");
922                 return true;
923             }
924
925             WheelEventArgs e = new WheelEventArgs();
926
927             e.Wheel = Tizen.NUI.Wheel.GetWheelFromPtr(wheelEvent);
928
929             if (_wheelEventHandler != null)
930             {
931                 return _wheelEventHandler(this, e);
932             }
933             return false;
934         }
935
936         // Callback for View OnWindow signal
937         private void OnWindow(IntPtr data)
938         {
939             if (_onWindowEventHandler != null)
940             {
941                 _onWindowEventHandler(this, null);
942             }
943         }
944
945         // Callback for View OffWindow signal
946         private void OffWindow(IntPtr data)
947         {
948             if (_offWindowEventHandler != null)
949             {
950                 _offWindowEventHandler(this, null);
951             }
952         }
953
954         // Callback for View visibility change signal
955         private void OnVisibilityChanged(IntPtr data, bool visibility, VisibilityChangeType type)
956         {
957             VisibilityChangedEventArgs e = new VisibilityChangedEventArgs();
958             if (data != null)
959             {
960                 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
961             }
962             e.Visibility = visibility;
963             e.Type = type;
964
965             if (_visibilityChangedEventHandler != null)
966             {
967                 _visibilityChangedEventHandler(this, e);
968             }
969         }
970
971         // Callback for View layout direction change signal
972         private void OnLayoutDirectionChanged(IntPtr data, ViewLayoutDirectionType type)
973         {
974             LayoutDirectionChangedEventArgs e = new LayoutDirectionChangedEventArgs();
975             if (data != null)
976             {
977                 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
978             }
979             e.Type = type;
980
981             if (_layoutDirectionChangedEventHandler != null)
982             {
983                 _layoutDirectionChangedEventHandler(this, e);
984             }
985         }
986
987         private void OnResourcesLoaded(IntPtr view)
988         {
989             if (_resourcesLoadedEventHandler != null)
990             {
991                 _resourcesLoadedEventHandler(this, null);
992             }
993         }
994
995         private void OnBackgroundResourceLoaded(IntPtr view)
996         {
997             BackgroundResourceLoadedEventArgs e = new BackgroundResourceLoadedEventArgs();
998             e.Status = (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.BACKGROUND);
999
1000             if (_backgroundResourceLoadedEventHandler != null)
1001             {
1002                 _backgroundResourceLoadedEventHandler(this, e);
1003             }
1004         }
1005
1006         /// <summary>
1007         /// Event argument passed through the ChildAdded event.
1008         /// </summary>
1009         /// <since_tizen> 5 </since_tizen>
1010         public class ChildAddedEventArgs : EventArgs
1011         {
1012             /// <summary>
1013             /// Added child view at moment.
1014             /// </summary>
1015             /// <since_tizen> 5 </since_tizen>
1016             public View Added { get; set; }
1017         }
1018
1019         /// <summary>
1020         /// Event argument passed through the ChildRemoved event.
1021         /// </summary>
1022         /// <since_tizen> 5 </since_tizen>
1023         public class ChildRemovedEventArgs : EventArgs
1024         {
1025             /// <summary>
1026             /// Removed child view at moment.
1027             /// </summary>
1028             /// <since_tizen> 5 </since_tizen>
1029             public View Removed { get; set; }
1030         }
1031
1032         /// <summary>
1033         /// Event arguments that passed via the KeyEvent signal.
1034         /// </summary>
1035         /// <since_tizen> 3 </since_tizen>
1036         public class KeyEventArgs : EventArgs
1037         {
1038             private Key _key;
1039
1040             /// <summary>
1041             /// Key - is the key sent to the view.
1042             /// </summary>
1043             /// <since_tizen> 3 </since_tizen>
1044             public Key Key
1045             {
1046                 get
1047                 {
1048                     return _key;
1049                 }
1050                 set
1051                 {
1052                     _key = value;
1053                 }
1054             }
1055         }
1056
1057         /// <summary>
1058         /// Event arguments that passed via the touch signal.
1059         /// </summary>
1060         /// <since_tizen> 3 </since_tizen>
1061         public class TouchEventArgs : EventArgs
1062         {
1063             private Touch _touch;
1064
1065             /// <summary>
1066             /// Touch - contains the information of touch points.
1067             /// </summary>
1068             /// <since_tizen> 3 </since_tizen>
1069             public Touch Touch
1070             {
1071                 get
1072                 {
1073                     return _touch;
1074                 }
1075                 set
1076                 {
1077                     _touch = value;
1078                 }
1079             }
1080         }
1081
1082         /// <summary>
1083         /// Event arguments that passed via the hover signal.
1084         /// </summary>
1085         /// <since_tizen> 3 </since_tizen>
1086         public class HoverEventArgs : EventArgs
1087         {
1088             private Hover _hover;
1089
1090             /// <summary>
1091             /// Hover - contains touch points that represent the points that are currently being hovered or the points where a hover has stopped.
1092             /// </summary>
1093             /// <since_tizen> 3 </since_tizen>
1094             public Hover Hover
1095             {
1096                 get
1097                 {
1098                     return _hover;
1099                 }
1100                 set
1101                 {
1102                     _hover = value;
1103                 }
1104             }
1105         }
1106
1107         /// <summary>
1108         /// Event arguments that passed via the wheel signal.
1109         /// </summary>
1110         /// <since_tizen> 3 </since_tizen>
1111         public class WheelEventArgs : EventArgs
1112         {
1113             private Wheel _wheel;
1114
1115             /// <summary>
1116             /// WheelEvent - store a wheel rolling type: MOUSE_WHEEL or CUSTOM_WHEEL.
1117             /// </summary>
1118             /// <since_tizen> 3 </since_tizen>
1119             public Wheel Wheel
1120             {
1121                 get
1122                 {
1123                     return _wheel;
1124                 }
1125                 set
1126                 {
1127                     _wheel = value;
1128                 }
1129             }
1130         }
1131
1132         /// <summary>
1133         /// Event arguments of visibility changed.
1134         /// </summary>
1135         /// <since_tizen> 3 </since_tizen>
1136         public class VisibilityChangedEventArgs : EventArgs
1137         {
1138             private View _view;
1139             private bool _visibility;
1140             private VisibilityChangeType _type;
1141
1142             /// <summary>
1143             /// The view, or child of view, whose visibility has changed.
1144             /// </summary>
1145             /// <since_tizen> 3 </since_tizen>
1146             public View View
1147             {
1148                 get
1149                 {
1150                     return _view;
1151                 }
1152                 set
1153                 {
1154                     _view = value;
1155                 }
1156             }
1157
1158             /// <summary>
1159             /// Whether the view is now visible or not.
1160             /// </summary>
1161             /// <since_tizen> 3 </since_tizen>
1162             public bool Visibility
1163             {
1164                 get
1165                 {
1166                     return _visibility;
1167                 }
1168                 set
1169                 {
1170                     _visibility = value;
1171                 }
1172             }
1173
1174             /// <summary>
1175             /// Whether the view's visible property has changed or a parent's.
1176             /// </summary>
1177             /// <since_tizen> 3 </since_tizen>
1178             public VisibilityChangeType Type
1179             {
1180                 get
1181                 {
1182                     return _type;
1183                 }
1184                 set
1185                 {
1186                     _type = value;
1187                 }
1188             }
1189         }
1190
1191         /// <summary>
1192         /// Event arguments of layout direction changed.
1193         /// </summary>
1194         /// <since_tizen> 4 </since_tizen>
1195         public class LayoutDirectionChangedEventArgs : EventArgs
1196         {
1197             private View _view;
1198             private ViewLayoutDirectionType _type;
1199
1200             /// <summary>
1201             /// The view, or child of view, whose layout direction has changed.
1202             /// </summary>
1203             /// <since_tizen> 4 </since_tizen>
1204             public View View
1205             {
1206                 get
1207                 {
1208                     return _view;
1209                 }
1210                 set
1211                 {
1212                     _view = value;
1213                 }
1214             }
1215
1216             /// <summary>
1217             /// Whether the view's layout direction property has changed or a parent's.
1218             /// </summary>
1219             /// <since_tizen> 4 </since_tizen>
1220             public ViewLayoutDirectionType Type
1221             {
1222                 get
1223                 {
1224                     return _type;
1225                 }
1226                 set
1227                 {
1228                     _type = value;
1229                 }
1230             }
1231         }
1232
1233         internal class BackgroundResourceLoadedEventArgs : EventArgs
1234         {
1235             private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1236             public ResourceLoadingStatusType Status
1237             {
1238                 get
1239                 {
1240                     return status;
1241                 }
1242                 set
1243                 {
1244                     status = value;
1245                 }
1246             }
1247         }
1248
1249         /// <summary>
1250         /// The class represents the information of the situation where the View's control state changes.
1251         /// </summary>
1252         [EditorBrowsable(EditorBrowsableState.Never)]
1253         public class ControlStateChangedEventArgs : EventArgs
1254         {
1255             /// <summary>
1256             /// Create an instance with mandatory fields.
1257             /// </summary>
1258             /// <param name="previousState">The previous control state.</param>
1259             /// <param name="currentState">The current control state.</param>
1260             [EditorBrowsable(EditorBrowsableState.Never)]
1261             public ControlStateChangedEventArgs(ControlState previousState, ControlState currentState)
1262             {
1263                 PreviousState = previousState;
1264                 CurrentState = currentState;
1265             }
1266
1267             /// <summary>
1268             /// The previous control state.
1269             /// </summary>
1270             [EditorBrowsable(EditorBrowsableState.Never)]
1271             public ControlState PreviousState { get; }
1272
1273             /// <summary>
1274             /// The current control state.
1275             /// </summary>
1276             [EditorBrowsable(EditorBrowsableState.Never)]
1277             public ControlState CurrentState { get; }
1278         }
1279
1280         private EventHandlerWithReturnType<object, WheelEventArgs, bool> WindowWheelEventHandler;
1281         private void OnWindowWheelEvent(object sender, Window.WheelEventArgs e)
1282         {
1283             if (e != null)
1284             {
1285                 if (e.Wheel.Type == Wheel.WheelType.CustomWheel)
1286                 {
1287                     var arg = new WheelEventArgs()
1288                     {
1289                         Wheel = e.Wheel,
1290                     };
1291                     WindowWheelEventHandler?.Invoke(this, arg);
1292                 }
1293             }
1294         }
1295
1296     }
1297 }