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