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