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