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