Follow formatting NUI
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / WindowEvent.cs
1 /*
2  * Copyright(c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
21 using Tizen.NUI.BaseComponents;
22
23 namespace Tizen.NUI
24 {
25     /// <summary>
26     /// The window class is used internally for drawing.<br />
27     /// The window has an orientation and indicator properties.<br />
28     /// </summary>
29     /// <since_tizen> 3 </since_tizen>
30     public partial class Window
31     {
32         private WindowFocusChangedEventCallbackType _windowFocusChangedEventCallback;
33         private RootLayerTouchDataCallbackType _rootLayerTouchDataCallback;
34         private WheelEventCallbackType _wheelEventCallback;
35         private EventCallbackDelegateType1 _stageKeyCallbackDelegate;
36         private EventCallbackDelegateType0 _stageEventProcessingFinishedEventCallbackDelegate;
37         private EventHandler _stageContextLostEventHandler;
38         private EventCallbackDelegateType0 _stageContextLostEventCallbackDelegate;
39         private EventHandler _stageContextRegainedEventHandler;
40         private EventCallbackDelegateType0 _stageContextRegainedEventCallbackDelegate;
41         private EventHandler _stageSceneCreatedEventHandler;
42         private EventCallbackDelegateType0 _stageSceneCreatedEventCallbackDelegate;
43         private WindowResizeEventCallbackType _windowResizeEventCallback;
44         private WindowFocusChangedEventCallbackType _windowFocusChangedEventCallback2;
45         private TransitionEffectEventCallbackType transitionEffectEventCallback;
46         private WindowTransitionEffectSignal transitionEffectSignal;
47         private KeyboardRepeatSettingsChangedEventCallbackType keyboardRepeatSettingsChangedEventCallback;
48         private KeyboardRepeatSettingsChangedSignal keyboardRepeatSettingsChangedSignal;
49
50         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
51         private delegate void WindowFocusChangedEventCallbackType(IntPtr window, bool focusGained);
52         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
53         private delegate bool RootLayerTouchDataCallbackType(IntPtr view, IntPtr touchData);
54         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
55         private delegate bool WheelEventCallbackType(IntPtr view, IntPtr wheelEvent);
56         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
57         private delegate void WindowResizeEventCallbackType(IntPtr window, IntPtr windowSize);
58         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
59         private delegate void WindowFocusChangedEventCallbackType2(IntPtr window, bool focusGained);
60         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
61         private delegate void TransitionEffectEventCallbackType(IntPtr window, int state, int type);
62         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
63         private delegate void KeyboardRepeatSettingsChangedEventCallbackType();
64
65         /// <summary>
66         /// FocusChanged event.
67         /// </summary>
68         /// <since_tizen> 3 </since_tizen>
69         public event EventHandler<FocusChangedEventArgs> FocusChanged
70         {
71             add
72             {
73                 if (_windowFocusChangedEventHandler == null)
74                 {
75                     _windowFocusChangedEventCallback = OnWindowFocusedChanged;
76                     WindowFocusChangedSignal().Connect(_windowFocusChangedEventCallback);
77                 }
78
79                 _windowFocusChangedEventHandler += value;
80             }
81             remove
82             {
83                 _windowFocusChangedEventHandler -= value;
84
85                 if (_windowFocusChangedEventHandler == null && WindowFocusChangedSignal().Empty() == false && _windowFocusChangedEventCallback != null)
86                 {
87                     WindowFocusChangedSignal().Disconnect(_windowFocusChangedEventCallback);
88                 }
89             }
90         }
91
92         /// <summary>
93         /// Emits the event when the screen is touched and when the touch ends.<br />
94         /// If there are multiple touch points then it is emitted when the first touch occurs and
95         /// when the last finger is lifted too.<br />
96         /// Even though incoming events are interrupted, the event occurs.<br />
97         /// </summary>
98         /// <since_tizen> 3 </since_tizen>
99         public event EventHandler<TouchEventArgs> TouchEvent
100         {
101             add
102             {
103                 if (_rootLayerTouchDataEventHandler == null)
104                 {
105                     _rootLayerTouchDataCallback = OnWindowTouch;
106                     this.TouchDataSignal().Connect(_rootLayerTouchDataCallback);
107                 }
108                 _rootLayerTouchDataEventHandler += value;
109             }
110             remove
111             {
112                 _rootLayerTouchDataEventHandler -= value;
113                 if (_rootLayerTouchDataEventHandler == null && TouchSignal().Empty() == false && _rootLayerTouchDataCallback != null)
114                 {
115                     this.TouchDataSignal().Disconnect(_rootLayerTouchDataCallback);
116                 }
117             }
118         }
119
120         /// <summary>
121         /// Emits the event when the wheel event is received.
122         /// </summary>
123         /// <since_tizen> 3 </since_tizen>
124         public event EventHandler<WheelEventArgs> WheelEvent
125         {
126             add
127             {
128                 if (_stageWheelHandler == null)
129                 {
130                     _wheelEventCallback = OnStageWheel;
131                     WheelEventSignal().Connect(_wheelEventCallback);
132                 }
133                 _stageWheelHandler += value;
134
135                 if (DetentEventHandler == null)
136                 {
137                     DetentEventCallback = OnDetentEvent;
138                     StageWheelEventSignal().Connect(DetentEventCallback);
139                 }
140                 DetentEventHandler += value;
141             }
142             remove
143             {
144                 _stageWheelHandler -= value;
145                 if (_stageWheelHandler == null && WheelEventSignal().Empty() == false)
146                 {
147                     WheelEventSignal().Disconnect(_wheelEventCallback);
148                 }
149
150                 DetentEventHandler -= value;
151                 if (DetentEventHandler == null && StageWheelEventSignal().Empty() == false)
152                 {
153                     StageWheelEventSignal().Disconnect(DetentEventCallback);
154                 }
155             }
156         }
157
158         /// <summary>
159         /// Emits the event when the key event is received.
160         /// </summary>
161         /// <since_tizen> 3 </since_tizen>
162         public event EventHandler<KeyEventArgs> KeyEvent
163         {
164             add
165             {
166                 if (_stageKeyHandler == null)
167                 {
168                     _stageKeyCallbackDelegate = OnStageKey;
169                     KeyEventSignal().Connect(_stageKeyCallbackDelegate);
170                 }
171                 _stageKeyHandler += value;
172             }
173             remove
174             {
175                 _stageKeyHandler -= value;
176                 if (_stageKeyHandler == null && KeyEventSignal().Empty() == false)
177                 {
178                     KeyEventSignal().Disconnect(_stageKeyCallbackDelegate);
179                 }
180             }
181         }
182
183         /// <summary>
184         /// Emits the event when the window resized.
185         /// </summary>
186         /// <since_tizen> 3 </since_tizen>
187         public event EventHandler<ResizedEventArgs> Resized
188         {
189             add
190             {
191                 if (_windowResizeEventHandler == null)
192                 {
193                     _windowResizeEventCallback = OnResized;
194                     ResizeSignal().Connect(_windowResizeEventCallback);
195                 }
196
197                 _windowResizeEventHandler += value;
198             }
199             remove
200             {
201                 _windowResizeEventHandler -= value;
202
203                 if (_windowResizeEventHandler == null && ResizeSignal().Empty() == false && _windowResizeEventCallback != null)
204                 {
205                     ResizeSignal().Disconnect(_windowResizeEventCallback);
206                 }
207             }
208         }
209
210         /// <summary>
211         /// Please do not use! this will be deprecated. Please use 'FocusChanged' event instead.
212         /// </summary>
213         /// <since_tizen> 3 </since_tizen>
214         /// Please do not use! this will be deprecated!
215         /// Instead please use FocusChanged.
216         [Obsolete("Please do not use! This will be deprecated! Please use FocusChanged instead! " +
217             "Like: " +
218             "NUIApplication.GetDefaultWindow().FocusChanged = OnFocusChanged; " +
219             "private void OnFocusChanged(object source, Window.FocusChangedEventArgs args) {...}")]
220         [EditorBrowsable(EditorBrowsableState.Never)]
221         public event EventHandler<FocusChangedEventArgs> WindowFocusChanged
222         {
223             add
224             {
225                 if (_windowFocusChangedEventHandler2 == null)
226                 {
227                     _windowFocusChangedEventCallback2 = OnWindowFocusedChanged2;
228                     WindowFocusChangedSignal().Connect(_windowFocusChangedEventCallback2);
229                 }
230
231                 _windowFocusChangedEventHandler2 += value;
232             }
233             remove
234             {
235                 _windowFocusChangedEventHandler2 -= value;
236
237                 if (_windowFocusChangedEventHandler2 == null && WindowFocusChangedSignal().Empty() == false && _windowFocusChangedEventCallback2 != null)
238                 {
239                     WindowFocusChangedSignal().Disconnect(_windowFocusChangedEventCallback2);
240                 }
241             }
242         }
243
244         /// <summary>
245         /// EffectStart
246         /// </summary>
247         [EditorBrowsable(EditorBrowsableState.Never)]
248         public event EventHandler<TransitionEffectArgs> TransitionEffect
249         {
250             add
251             {
252                 if (transitionEffectHandler == null)
253                 {
254                     transitionEffectEventCallback = OnTransitionEffect;
255                     TransitionEffectEventSignal().Connect(transitionEffectEventCallback);
256                 }
257                 transitionEffectHandler += value;
258             }
259             remove
260             {
261                 transitionEffectHandler -= value;
262                 if (transitionEffectHandler == null && TransitionEffectEventSignal().Empty() == false)
263                 {
264                     TransitionEffectEventSignal().Disconnect(transitionEffectEventCallback);
265                 }
266             }
267         }
268
269         /// <summary>
270         /// Keyboard Repeat Settings Changed
271         /// </summary>
272         [EditorBrowsable(EditorBrowsableState.Never)]
273         public event EventHandler KeyboardRepeatSettingsChanged
274         {
275             add
276             {
277                 if (keyboardRepeatSettingsChangedHandler == null)
278                 {
279                     keyboardRepeatSettingsChangedEventCallback = OnKeyboardRepeatSettingsChanged;
280                     KeyboardRepeatSettingsChangedEventSignal().Connect(keyboardRepeatSettingsChangedEventCallback);
281                 }
282                 keyboardRepeatSettingsChangedHandler += value;
283             }
284             remove
285             {
286                 keyboardRepeatSettingsChangedHandler -= value;
287                 if (keyboardRepeatSettingsChangedHandler == null && KeyboardRepeatSettingsChangedEventSignal().Empty() == false)
288                 {
289                     KeyboardRepeatSettingsChangedEventSignal().Disconnect(keyboardRepeatSettingsChangedEventCallback);
290                 }
291             }
292         }
293
294         /// <summary>
295         /// ViewAdded will be triggered when the view added on Window
296         /// </summary>
297         /// <since_tizen> 6 </since_tizen>
298         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
299         [EditorBrowsable(EditorBrowsableState.Never)]
300         public event EventHandler ViewAdded;
301         private event EventHandler<FocusChangedEventArgs> _windowFocusChangedEventHandler;
302         private event EventHandler<TouchEventArgs> _rootLayerTouchDataEventHandler;
303         private event EventHandler<WheelEventArgs> _stageWheelHandler;
304         private event EventHandler<KeyEventArgs> _stageKeyHandler;
305         private event EventHandler _stageEventProcessingFinishedEventHandler;
306         private event EventHandler<ResizedEventArgs> _windowResizeEventHandler;
307         private event EventHandler<FocusChangedEventArgs> _windowFocusChangedEventHandler2;
308         private event EventHandler<TransitionEffectArgs> transitionEffectHandler;
309         private event EventHandler keyboardRepeatSettingsChangedHandler;
310
311         internal void SendViewAdded(View view)
312         {
313             ViewAdded?.Invoke(view, EventArgs.Empty);
314         }
315
316         internal event EventHandler EventProcessingFinished
317         {
318             add
319             {
320                 if (_stageEventProcessingFinishedEventHandler == null)
321                 {
322                     _stageEventProcessingFinishedEventCallbackDelegate = OnEventProcessingFinished;
323                     EventProcessingFinishedSignal().Connect(_stageEventProcessingFinishedEventCallbackDelegate);
324                 }
325                 _stageEventProcessingFinishedEventHandler += value;
326
327             }
328             remove
329             {
330                 _stageEventProcessingFinishedEventHandler -= value;
331                 if (_stageEventProcessingFinishedEventHandler == null && EventProcessingFinishedSignal().Empty() == false)
332                 {
333                     EventProcessingFinishedSignal().Disconnect(_stageEventProcessingFinishedEventCallbackDelegate);
334                 }
335             }
336         }
337
338         internal event EventHandler ContextLost
339         {
340             add
341             {
342                 if (_stageContextLostEventHandler == null)
343                 {
344                     _stageContextLostEventCallbackDelegate = OnContextLost;
345                     ContextLostSignal().Connect(_stageContextLostEventCallbackDelegate);
346                 }
347                 _stageContextLostEventHandler += value;
348             }
349             remove
350             {
351                 _stageContextLostEventHandler -= value;
352                 if (_stageContextLostEventHandler == null && ContextLostSignal().Empty() == false)
353                 {
354                     ContextLostSignal().Disconnect(_stageContextLostEventCallbackDelegate);
355                 }
356             }
357         }
358
359         internal event EventHandler ContextRegained
360         {
361             add
362             {
363                 if (_stageContextRegainedEventHandler == null)
364                 {
365                     _stageContextRegainedEventCallbackDelegate = OnContextRegained;
366                     ContextRegainedSignal().Connect(_stageContextRegainedEventCallbackDelegate);
367                 }
368                 _stageContextRegainedEventHandler += value;
369             }
370             remove
371             {
372                 _stageContextRegainedEventHandler -= value;
373                 if (_stageContextRegainedEventHandler == null && ContextRegainedSignal().Empty() == false)
374                 {
375                     this.ContextRegainedSignal().Disconnect(_stageContextRegainedEventCallbackDelegate);
376                 }
377             }
378         }
379
380         internal event EventHandler SceneCreated
381         {
382             add
383             {
384                 if (_stageSceneCreatedEventHandler == null)
385                 {
386                     _stageSceneCreatedEventCallbackDelegate = OnSceneCreated;
387                     SceneCreatedSignal().Connect(_stageSceneCreatedEventCallbackDelegate);
388                 }
389                 _stageSceneCreatedEventHandler += value;
390             }
391             remove
392             {
393                 _stageSceneCreatedEventHandler -= value;
394                 if (_stageSceneCreatedEventHandler == null && SceneCreatedSignal().Empty() == false)
395                 {
396                     SceneCreatedSignal().Disconnect(_stageSceneCreatedEventCallbackDelegate);
397                 }
398             }
399         }
400
401         internal WindowFocusSignalType WindowFocusChangedSignal()
402         {
403             WindowFocusSignalType ret = new WindowFocusSignalType(Interop.Window.FocusChangedSignal(swigCPtr), false);
404             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
405             return ret;
406         }
407
408         internal WindowFocusSignalType FocusChangedSignal()
409         {
410             WindowFocusSignalType ret = new WindowFocusSignalType(Interop.Window.FocusChangedSignal(swigCPtr), false);
411             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
412             return ret;
413         }
414
415         internal KeyEventSignal KeyEventSignal()
416         {
417             KeyEventSignal ret = new KeyEventSignal(Interop.Window.KeyEventSignal(swigCPtr), false);
418             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
419             return ret;
420         }
421
422         internal VoidSignal EventProcessingFinishedSignal()
423         {
424             VoidSignal ret = new VoidSignal(Interop.StageSignal.Stage_EventProcessingFinishedSignal(stageCPtr), false);
425             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
426             return ret;
427         }
428
429         internal TouchSignal TouchSignal()
430         {
431             TouchSignal ret = new TouchSignal(Interop.Window.TouchSignal(swigCPtr), false);
432             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
433             return ret;
434         }
435
436         internal TouchDataSignal TouchDataSignal()
437         {
438             TouchDataSignal ret = new TouchDataSignal(Interop.ActorSignal.Actor_TouchSignal(Layer.getCPtr(GetRootLayer())), false);
439             if (NDalicPINVOKE.SWIGPendingException.Pending)
440                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
441             return ret;
442         }
443
444         internal VoidSignal ContextLostSignal()
445         {
446             VoidSignal ret = new VoidSignal(Interop.StageSignal.Stage_ContextLostSignal(stageCPtr), false);
447             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
448             return ret;
449         }
450
451         internal VoidSignal ContextRegainedSignal()
452         {
453             VoidSignal ret = new VoidSignal(Interop.StageSignal.Stage_ContextRegainedSignal(stageCPtr), false);
454             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
455             return ret;
456         }
457
458         internal VoidSignal SceneCreatedSignal()
459         {
460             VoidSignal ret = new VoidSignal(Interop.StageSignal.Stage_SceneCreatedSignal(stageCPtr), false);
461             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
462             return ret;
463         }
464
465         internal ResizeSignal ResizeSignal()
466         {
467             ResizeSignal ret = new ResizeSignal(Interop.Window.Window_ResizeSignal(swigCPtr), false);
468             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
469             return ret;
470         }
471
472         internal System.IntPtr GetNativeWindowHandler()
473         {
474             System.IntPtr ret = Interop.Window.GetNativeWindowHandler(HandleRef.ToIntPtr(this.swigCPtr));
475             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
476             return ret;
477         }
478
479         /// <summary>
480         /// Disconnect all native signals
481         /// </summary>
482         /// <since_tizen> 5 </since_tizen>
483         internal void DisconnectNativeSignals()
484         {
485             if (_windowFocusChangedEventCallback != null)
486             {
487                 WindowFocusChangedSignal().Disconnect(_windowFocusChangedEventCallback);
488             }
489
490             if (_rootLayerTouchDataCallback != null)
491             {
492                 TouchDataSignal().Disconnect(_rootLayerTouchDataCallback);
493             }
494
495             if (_wheelEventCallback != null)
496             {
497                 WheelEventSignal().Disconnect(_wheelEventCallback);
498             }
499
500             if (DetentEventCallback != null)
501             {
502                 StageWheelEventSignal().Disconnect(DetentEventCallback);
503             }
504
505             if (_stageKeyCallbackDelegate != null)
506             {
507                 KeyEventSignal().Disconnect(_stageKeyCallbackDelegate);
508             }
509
510             if (_stageEventProcessingFinishedEventCallbackDelegate != null)
511             {
512                 EventProcessingFinishedSignal().Disconnect(_stageEventProcessingFinishedEventCallbackDelegate);
513             }
514
515             if (_stageContextLostEventCallbackDelegate != null)
516             {
517                 ContextLostSignal().Disconnect(_stageContextLostEventCallbackDelegate);
518             }
519
520             if (_stageContextRegainedEventCallbackDelegate != null)
521             {
522                 ContextRegainedSignal().Disconnect(_stageContextRegainedEventCallbackDelegate);
523             }
524
525             if (_stageSceneCreatedEventCallbackDelegate != null)
526             {
527                 SceneCreatedSignal().Disconnect(_stageSceneCreatedEventCallbackDelegate);
528             }
529
530             if (_windowResizeEventCallback != null)
531             {
532                 ResizeSignal().Disconnect(_windowResizeEventCallback);
533             }
534
535             if (_windowFocusChangedEventCallback2 != null)
536             {
537                 WindowFocusChangedSignal().Disconnect(_windowFocusChangedEventCallback2);
538             }
539
540             if (transitionEffectSignal != null)
541             {
542                 TransitionEffectEventSignal().Disconnect(transitionEffectEventCallback);
543             }
544
545             if (keyboardRepeatSettingsChangedSignal != null)
546             {
547                 KeyboardRepeatSettingsChangedEventSignal().Disconnect(keyboardRepeatSettingsChangedEventCallback);
548             }
549         }
550
551         private StageWheelSignal StageWheelEventSignal()
552         {
553             StageWheelSignal ret = new StageWheelSignal(Interop.StageSignal.Stage_WheelEventSignal(stageCPtr), false);
554             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
555             return ret;
556         }
557
558         private WheelSignal WheelEventSignal()
559         {
560             WheelSignal ret = new WheelSignal(Interop.ActorSignal.Actor_WheelEventSignal(Layer.getCPtr(this.GetRootLayer())), false);
561             if (NDalicPINVOKE.SWIGPendingException.Pending)
562                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
563             return ret;
564         }
565
566         private WindowTransitionEffectSignal TransitionEffectEventSignal()
567         {
568             //Tizen.Log.Fatal("NUITEST", "TransitionEffectEventSignal()!");
569             if (transitionEffectSignal == null)
570             {
571                 transitionEffectSignal = new WindowTransitionEffectSignal(this);
572                 if (NDalicPINVOKE.SWIGPendingException.Pending)
573                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
574                 //Tizen.Log.Fatal("NUITEST", $"transitionEffectSignal is null, new here!");
575             }
576             return transitionEffectSignal;
577         }
578
579         private KeyboardRepeatSettingsChangedSignal KeyboardRepeatSettingsChangedEventSignal()
580         {
581             if (keyboardRepeatSettingsChangedSignal == null)
582             {
583                 keyboardRepeatSettingsChangedSignal = new KeyboardRepeatSettingsChangedSignal(this);
584                 if (NDalicPINVOKE.SWIGPendingException.Pending)
585                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
586             }
587             return keyboardRepeatSettingsChangedSignal;
588         }
589
590         private void OnWindowFocusedChanged(IntPtr window, bool focusGained)
591         {
592             if (window == IntPtr.Zero)
593             {
594                 NUILog.Error("OnWindowFocusedChanged() Window is null! Do nothing!");
595                 return;
596             }
597
598             FocusChangedEventArgs e = new FocusChangedEventArgs();
599
600             e.FocusGained = focusGained;
601
602             if (_windowFocusChangedEventHandler != null)
603             {
604                 _windowFocusChangedEventHandler(this, e);
605             }
606         }
607
608         private bool OnWindowTouch(IntPtr view, IntPtr touchData)
609         {
610             if (touchData == global::System.IntPtr.Zero)
611             {
612                 NUILog.Error("touchData should not be null!");
613                 return false;
614             }
615
616             TouchEventArgs e = new TouchEventArgs();
617
618             e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
619
620             if (_rootLayerTouchDataEventHandler != null)
621             {
622                 _rootLayerTouchDataEventHandler(this, e);
623             }
624             return false;
625         }
626
627         private bool OnStageWheel(IntPtr rootLayer, IntPtr wheelEvent)
628         {
629             if (wheelEvent == global::System.IntPtr.Zero)
630             {
631                 NUILog.Error("wheelEvent should not be null!");
632                 return true;
633             }
634
635             WheelEventArgs e = new WheelEventArgs();
636
637             e.Wheel = Tizen.NUI.Wheel.GetWheelFromPtr(wheelEvent);
638
639             if (_stageWheelHandler != null)
640             {
641                 _stageWheelHandler(this, e);
642             }
643             return true;
644         }
645
646         // Callback for Stage KeyEventsignal
647         private void OnStageKey(IntPtr data)
648         {
649             KeyEventArgs e = new KeyEventArgs();
650             e.Key = Tizen.NUI.Key.GetKeyFromPtr(data);
651
652
653             if (_stageKeyHandler != null)
654             {
655                 //here we send all data to user event handlers
656                 _stageKeyHandler(this, e);
657             }
658         }
659
660         // Callback for Stage EventProcessingFinishedSignal
661         private void OnEventProcessingFinished()
662         {
663             if (_stageEventProcessingFinishedEventHandler != null)
664             {
665                 _stageEventProcessingFinishedEventHandler(this, null);
666             }
667         }
668
669         // Callback for Stage ContextLostSignal
670         private void OnContextLost()
671         {
672             if (_stageContextLostEventHandler != null)
673             {
674                 _stageContextLostEventHandler(this, null);
675             }
676         }
677
678         // Callback for Stage ContextRegainedSignal
679         private void OnContextRegained()
680         {
681             if (_stageContextRegainedEventHandler != null)
682             {
683                 _stageContextRegainedEventHandler(this, null);
684             }
685         }
686
687         // Callback for Stage SceneCreatedSignal
688         private void OnSceneCreated()
689         {
690             if (_stageSceneCreatedEventHandler != null)
691             {
692                 _stageSceneCreatedEventHandler(this, null);
693             }
694         }
695
696         private void OnResized(IntPtr window, IntPtr windowSize)
697         {
698             if (window == IntPtr.Zero)
699             {
700                 NUILog.Error("OnResized() Window is null! Do nothing!");
701                 return;
702             }
703
704             ResizedEventArgs e = new ResizedEventArgs();
705             // var val = new Uint16Pair(windowSize, false);
706             // e.WindowSize = new Size2D(val.GetWidth(), val.GetHeight());
707             // val.Dispose();
708
709             // Workaround : windowSize should be valid pointer from dali, 
710             // but currenlty it is fixed and is not Uint16Pair class.
711             // will be fixed later.
712             e.WindowSize = this.WindowSize;
713
714             if (_windowResizeEventHandler != null)
715             {
716                 _windowResizeEventHandler(this, e);
717             }
718         }
719
720         private void OnWindowFocusedChanged2(IntPtr window, bool focusGained)
721         {
722             if (window == IntPtr.Zero)
723             {
724                 NUILog.Error("OnWindowFocusedChanged() Window is null! Do nothing!");
725                 return;
726             }
727
728             FocusChangedEventArgs e = new FocusChangedEventArgs();
729
730             e.FocusGained = focusGained;
731
732             if (_windowFocusChangedEventHandler2 != null)
733             {
734                 _windowFocusChangedEventHandler2(this, e);
735             }
736         }
737
738         private void OnTransitionEffect(IntPtr window, int state, int type)
739         {
740             //Tizen.Log.Fatal("NUITEST", $"OnTransitionEffect() called");
741             if (window == global::System.IntPtr.Zero)
742             {
743                 //Tizen.Log.Error("NUI", $"OnTransitionEffect() IntPtr window is null!");
744                 return;
745             }
746
747             TransitionEffectArgs e = new TransitionEffectArgs();
748
749             e.State = (EffectStates)state;
750             //Tizen.Log.Error("NUITEST", $"e.State={e.State}");
751
752             e.Type = (EffectTypes)type;
753             //Tizen.Log.Error("NUITEST", $"e.Type={e.Type}");
754
755             if (transitionEffectHandler != null)
756             {
757                 //Tizen.Log.Fatal("NUITEST", $"Execute transitionEffectHandler(this, e)!!!");
758                 transitionEffectHandler(this, e);
759             }
760             return;
761         }
762
763         private void OnKeyboardRepeatSettingsChanged()
764         {
765             if (keyboardRepeatSettingsChangedHandler != null)
766             {
767                 keyboardRepeatSettingsChangedHandler(this, null);
768             }
769             return;
770         }
771
772         /// <summary>
773         /// The focus changed event argument.
774         /// </summary>
775         /// <since_tizen> 3 </since_tizen>
776         public class FocusChangedEventArgs : EventArgs
777         {
778             /// <summary>
779             /// FocusGained flag.
780             /// </summary>
781             /// <since_tizen> 3 </since_tizen>
782             public bool FocusGained
783             {
784                 get;
785                 set;
786             }
787         }
788
789         /// <summary>
790         /// The touch event argument.
791         /// </summary>
792         /// <since_tizen> 3 </since_tizen>
793         public class TouchEventArgs : EventArgs
794         {
795             private Touch _touch;
796
797             /// <summary>
798             /// Touch.
799             /// </summary>
800             /// <since_tizen> 3 </since_tizen>
801             public Touch Touch
802             {
803                 get
804                 {
805                     return _touch;
806                 }
807                 set
808                 {
809                     _touch = value;
810                 }
811             }
812         }
813
814         /// <summary>
815         /// Wheel event arguments.
816         /// </summary>
817         /// <since_tizen> 3 </since_tizen>
818         public class WheelEventArgs : EventArgs
819         {
820             private Wheel _wheel;
821
822             /// <summary>
823             /// Wheel.
824             /// </summary>
825             /// <since_tizen> 3 </since_tizen>
826             public Wheel Wheel
827             {
828                 get
829                 {
830                     return _wheel;
831                 }
832                 set
833                 {
834                     _wheel = value;
835                 }
836             }
837         }
838
839         /// <summary>
840         /// Key event arguments.
841         /// </summary>
842         /// <since_tizen> 3 </since_tizen>
843         public class KeyEventArgs : EventArgs
844         {
845             private Key _key;
846
847             /// <summary>
848             /// Key.
849             /// </summary>
850             /// <since_tizen> 3 </since_tizen>
851             public Key Key
852             {
853                 get
854                 {
855                     return _key;
856                 }
857                 set
858                 {
859                     _key = value;
860                 }
861             }
862         }
863
864         /// <summary>
865         /// Feeds a key event into the window.
866         /// This resized event arguments.
867         /// </summary>
868         /// <since_tizen> 3 </since_tizen>
869         public class ResizedEventArgs : EventArgs
870         {
871             Size2D _windowSize;
872
873             /// <summary>
874             /// This window size.
875             /// </summary>
876             /// <since_tizen> 4 </since_tizen>
877             public Size2D WindowSize
878             {
879                 get
880                 {
881                     return _windowSize;
882                 }
883                 set
884                 {
885                     _windowSize = value;
886                 }
887             }
888         }
889
890         /// <summary>
891         /// Please do not use! this will be deprecated
892         /// </summary>
893         /// <since_tizen> 3 </since_tizen>
894         [Obsolete("Please do not use! This will be deprecated! Please use FocusChangedEventArgs instead! " +
895             "Like: " +
896             "NUIApplication.GetDefaultWindow().FocusChanged = OnFocusChanged; " +
897             "private void OnFocusChanged(object source, Window.FocusChangedEventArgs args) {...}")]
898         [EditorBrowsable(EditorBrowsableState.Never)]
899         public class WindowFocusChangedEventArgs : EventArgs
900         {
901             /// <summary>
902             /// Please do not use! this will be deprecated
903             /// </summary>
904             /// <since_tizen> 3 </since_tizen>
905             public bool FocusGained
906             {
907                 get;
908                 set;
909             }
910         }
911
912         /// <summary>
913         /// Contains and encapsulates Native Window handle.
914         /// </summary>
915         /// <since_tizen> 4 </since_tizen>
916         public class SafeNativeWindowHandle : SafeHandle
917         {
918             /// <summary>
919             /// Contructor, Native window handle is set to handle.
920             /// </summary>
921             /// <since_tizen> 4 </since_tizen>
922             public SafeNativeWindowHandle() : base(IntPtr.Zero, false)
923             {
924                 SetHandle(NUIApplication.GetDefaultWindow().GetNativeWindowHandler());
925             }
926             /// <summary>
927             /// Null check if the handle is valid or not.
928             /// </summary>
929             /// <since_tizen> 4 </since_tizen>
930             public override bool IsInvalid
931             {
932                 get
933                 {
934                     return this.handle == IntPtr.Zero;
935                 }
936             }
937             /// <summary>
938             /// Release handle itself.
939             /// </summary>
940             /// <returns>true when released successfully.</returns>
941             /// <since_tizen> 4 </since_tizen>
942             protected override bool ReleaseHandle()
943             {
944                 return true;
945             }
946         }
947
948         /// <summary>
949         /// TransitionEffectArgs
950         /// </summary>
951         [EditorBrowsable(EditorBrowsableState.Never)]
952         public class TransitionEffectArgs : EventArgs
953         {
954             private EffectStates state;
955             private EffectTypes type;
956
957             /// <summary>
958             /// State
959             /// </summary>
960             [EditorBrowsable(EditorBrowsableState.Never)]
961             public EffectStates State
962             {
963                 get
964                 {
965                     return state;
966                 }
967                 set
968                 {
969                     state = value;
970                 }
971             }
972             /// <summary>
973             /// Type
974             /// </summary>
975             [EditorBrowsable(EditorBrowsableState.Never)]
976             public EffectTypes Type
977             {
978                 get
979                 {
980                     return type;
981                 }
982                 set
983                 {
984                     type = value;
985                 }
986             }
987         }
988
989         private EventHandler<WheelEventArgs> DetentEventHandler;
990
991         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
992         private delegate void DetentEventCallbackType(IntPtr arg1);
993
994         private DetentEventCallbackType DetentEventCallback;
995
996         private void OnDetentEvent(IntPtr wheelEvent)
997         {
998             WheelEventArgs e = new WheelEventArgs();
999
1000             if (wheelEvent != global::System.IntPtr.Zero)
1001             {
1002                 e.Wheel = Wheel.GetWheelFromPtr(wheelEvent);
1003             }
1004
1005             DetentEventHandler?.Invoke(this, e);
1006         }
1007
1008         /// <summary>
1009         /// VisibilityChangedArgs
1010         /// </summary>
1011         [EditorBrowsable(EditorBrowsableState.Never)]
1012         public class VisibilityChangedArgs : EventArgs
1013         {
1014             private bool visibility;
1015             /// <summary>
1016             /// Visibility
1017             /// </summary>
1018             [EditorBrowsable(EditorBrowsableState.Never)]
1019             public bool Visibility
1020             {
1021                 get => visibility;
1022                 set
1023                 {
1024                     visibility = value;
1025                 }
1026             }
1027         }
1028
1029         private void OnVisibilityChanged(IntPtr window, bool visibility)
1030         {
1031             if (window == global::System.IntPtr.Zero)
1032             {
1033                 NUILog.Error("[ERR] OnVisibilityChanged() window is null");
1034                 return;
1035             }
1036
1037             VisibilityChangedArgs e = new VisibilityChangedArgs();
1038             e.Visibility = visibility;
1039             if (VisibilityChangedEventHandler != null)
1040             {
1041                 VisibilityChangedEventHandler.Invoke(this, e);
1042             }
1043         }
1044
1045         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
1046         private delegate void VisibilityChangedEventCallbackType(IntPtr window, bool visibility);
1047         private VisibilityChangedEventCallbackType VisibilityChangedEventCallback;
1048         private event EventHandler<VisibilityChangedArgs> VisibilityChangedEventHandler;
1049         private WindowVisibilityChangedEvent VisibilityChangedEventSignal;
1050
1051         /// <summary>
1052         /// EffectStart
1053         /// </summary>
1054         [EditorBrowsable(EditorBrowsableState.Never)]
1055         public event EventHandler<VisibilityChangedArgs> VisibilityChanged
1056         {
1057             add
1058             {
1059                 if (VisibilityChangedEventHandler == null)
1060                 {
1061                     VisibilityChangedEventCallback = OnVisibilityChanged;
1062                     VisibilityChangedEventSignal = new WindowVisibilityChangedEvent(this);
1063                     VisibilityChangedEventSignal.Connect(VisibilityChangedEventCallback);
1064                 }
1065                 VisibilityChangedEventHandler += value;
1066             }
1067             remove
1068             {
1069                 VisibilityChangedEventHandler -= value;
1070                 if (VisibilityChangedEventHandler == null)
1071                 {
1072                     if (VisibilityChangedEventSignal != null)
1073                     {
1074                         if (VisibilityChangedEventSignal.Empty() == false)
1075                         {
1076                             VisibilityChangedEventSignal.Disconnect(VisibilityChangedEventCallback);
1077                         }
1078                     }
1079                 }
1080             }
1081         }
1082
1083         /// <summary>
1084         /// VisibiltyChangedSignalEmit
1085         /// </summary>
1086         [EditorBrowsable(EditorBrowsableState.Never)]
1087         public void VisibiltyChangedSignalEmit(bool visibility)
1088         {
1089             if (VisibilityChangedEventSignal == null)
1090             {
1091                 VisibilityChangedEventSignal = new WindowVisibilityChangedEvent(this);
1092             }
1093             VisibilityChangedEventSignal.Emit(this, visibility);
1094         }
1095
1096
1097
1098     }
1099 }