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