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