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