[NUI] Fixing the emtpy finalizers(CA1821)
[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<TransitionEffectEventArgs> 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<TransitionEffectEventArgs> 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.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.ActorTouchSignal(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.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.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.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.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.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.ActorWheelEventSignal(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             if (transitionEffectSignal == null)
569             {
570                 transitionEffectSignal = new WindowTransitionEffectSignal(this);
571                 if (NDalicPINVOKE.SWIGPendingException.Pending)
572                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
573             }
574             return transitionEffectSignal;
575         }
576
577         private KeyboardRepeatSettingsChangedSignal KeyboardRepeatSettingsChangedEventSignal()
578         {
579             if (keyboardRepeatSettingsChangedSignal == null)
580             {
581                 keyboardRepeatSettingsChangedSignal = new KeyboardRepeatSettingsChangedSignal(this);
582                 if (NDalicPINVOKE.SWIGPendingException.Pending)
583                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
584             }
585             return keyboardRepeatSettingsChangedSignal;
586         }
587
588         private void OnWindowFocusedChanged(IntPtr window, bool focusGained)
589         {
590             if (window == IntPtr.Zero)
591             {
592                 NUILog.Error("OnWindowFocusedChanged() Window is null! Do nothing!");
593                 return;
594             }
595
596             FocusChangedEventArgs e = new FocusChangedEventArgs();
597
598             e.FocusGained = focusGained;
599
600             if (_windowFocusChangedEventHandler != null)
601             {
602                 _windowFocusChangedEventHandler(this, e);
603             }
604         }
605
606         private bool OnWindowTouch(IntPtr view, IntPtr touchData)
607         {
608             if (touchData == global::System.IntPtr.Zero)
609             {
610                 NUILog.Error("touchData should not be null!");
611                 return false;
612             }
613
614             TouchEventArgs e = new TouchEventArgs();
615
616             e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
617
618             if (_rootLayerTouchDataEventHandler != null)
619             {
620                 _rootLayerTouchDataEventHandler(this, e);
621             }
622             return false;
623         }
624
625         private bool OnStageWheel(IntPtr rootLayer, IntPtr wheelEvent)
626         {
627             if (wheelEvent == global::System.IntPtr.Zero)
628             {
629                 NUILog.Error("wheelEvent should not be null!");
630                 return true;
631             }
632
633             WheelEventArgs e = new WheelEventArgs();
634
635             e.Wheel = Tizen.NUI.Wheel.GetWheelFromPtr(wheelEvent);
636
637             if (_stageWheelHandler != null)
638             {
639                 _stageWheelHandler(this, e);
640             }
641             return true;
642         }
643
644         // Callback for Stage KeyEventsignal
645         private void OnStageKey(IntPtr data)
646         {
647             KeyEventArgs e = new KeyEventArgs();
648             e.Key = Tizen.NUI.Key.GetKeyFromPtr(data);
649
650
651             if (_stageKeyHandler != null)
652             {
653                 //here we send all data to user event handlers
654                 _stageKeyHandler(this, e);
655             }
656         }
657
658         // Callback for Stage EventProcessingFinishedSignal
659         private void OnEventProcessingFinished()
660         {
661             if (_stageEventProcessingFinishedEventHandler != null)
662             {
663                 _stageEventProcessingFinishedEventHandler(this, null);
664             }
665         }
666
667         // Callback for Stage ContextLostSignal
668         private void OnContextLost()
669         {
670             if (_stageContextLostEventHandler != null)
671             {
672                 _stageContextLostEventHandler(this, null);
673             }
674         }
675
676         // Callback for Stage ContextRegainedSignal
677         private void OnContextRegained()
678         {
679             if (_stageContextRegainedEventHandler != null)
680             {
681                 _stageContextRegainedEventHandler(this, null);
682             }
683         }
684
685         // Callback for Stage SceneCreatedSignal
686         private void OnSceneCreated()
687         {
688             if (_stageSceneCreatedEventHandler != null)
689             {
690                 _stageSceneCreatedEventHandler(this, null);
691             }
692         }
693
694         private void OnResized(IntPtr window, IntPtr windowSize)
695         {
696             if (window == IntPtr.Zero)
697             {
698                 NUILog.Error("OnResized() Window is null! Do nothing!");
699                 return;
700             }
701
702             ResizedEventArgs e = new ResizedEventArgs();
703             // var val = new Uint16Pair(windowSize, false);
704             // e.WindowSize = new Size2D(val.GetWidth(), val.GetHeight());
705             // val.Dispose();
706
707             // Workaround : windowSize should be valid pointer from dali, 
708             // but currenlty it is fixed and is not Uint16Pair class.
709             // will be fixed later.
710             e.WindowSize = this.WindowSize;
711
712             if (_windowResizeEventHandler != null)
713             {
714                 _windowResizeEventHandler(this, e);
715             }
716         }
717
718         private void OnWindowFocusedChanged2(IntPtr window, bool focusGained)
719         {
720             if (window == IntPtr.Zero)
721             {
722                 NUILog.Error("OnWindowFocusedChanged() Window is null! Do nothing!");
723                 return;
724             }
725
726             FocusChangedEventArgs e = new FocusChangedEventArgs();
727
728             e.FocusGained = focusGained;
729
730             if (_windowFocusChangedEventHandler2 != null)
731             {
732                 _windowFocusChangedEventHandler2(this, e);
733             }
734         }
735
736         private void OnTransitionEffect(IntPtr window, int state, int type)
737         {
738             if (window == global::System.IntPtr.Zero)
739             {
740                 return;
741             }
742
743             TransitionEffectEventArgs e = new TransitionEffectEventArgs();
744
745             e.State = (EffectStates)state;
746
747             e.Type = (EffectTypes)type;
748
749             if (transitionEffectHandler != null)
750             {
751                 transitionEffectHandler(this, e);
752             }
753             return;
754         }
755
756         private void OnKeyboardRepeatSettingsChanged()
757         {
758             if (keyboardRepeatSettingsChangedHandler != null)
759             {
760                 keyboardRepeatSettingsChangedHandler(this, null);
761             }
762             return;
763         }
764
765         /// <summary>
766         /// The focus changed event argument.
767         /// </summary>
768         /// <since_tizen> 3 </since_tizen>
769         public class FocusChangedEventArgs : EventArgs
770         {
771             /// <summary>
772             /// FocusGained flag.
773             /// </summary>
774             /// <since_tizen> 3 </since_tizen>
775             public bool FocusGained
776             {
777                 get;
778                 set;
779             }
780         }
781
782         /// <summary>
783         /// The touch event argument.
784         /// </summary>
785         /// <since_tizen> 3 </since_tizen>
786         public class TouchEventArgs : EventArgs
787         {
788             private Touch _touch;
789
790             /// <summary>
791             /// Touch.
792             /// </summary>
793             /// <since_tizen> 3 </since_tizen>
794             public Touch Touch
795             {
796                 get
797                 {
798                     return _touch;
799                 }
800                 set
801                 {
802                     _touch = value;
803                 }
804             }
805         }
806
807         /// <summary>
808         /// Wheel event arguments.
809         /// </summary>
810         /// <since_tizen> 3 </since_tizen>
811         public class WheelEventArgs : EventArgs
812         {
813             private Wheel _wheel;
814
815             /// <summary>
816             /// Wheel.
817             /// </summary>
818             /// <since_tizen> 3 </since_tizen>
819             public Wheel Wheel
820             {
821                 get
822                 {
823                     return _wheel;
824                 }
825                 set
826                 {
827                     _wheel = value;
828                 }
829             }
830         }
831
832         /// <summary>
833         /// Key event arguments.
834         /// </summary>
835         /// <since_tizen> 3 </since_tizen>
836         public class KeyEventArgs : EventArgs
837         {
838             private Key _key;
839
840             /// <summary>
841             /// Key.
842             /// </summary>
843             /// <since_tizen> 3 </since_tizen>
844             public Key Key
845             {
846                 get
847                 {
848                     return _key;
849                 }
850                 set
851                 {
852                     _key = value;
853                 }
854             }
855         }
856
857         /// <summary>
858         /// Feeds a key event into the window.
859         /// This resized event arguments.
860         /// </summary>
861         /// <since_tizen> 3 </since_tizen>
862         public class ResizedEventArgs : EventArgs
863         {
864             Size2D _windowSize;
865
866             /// <summary>
867             /// This window size.
868             /// </summary>
869             /// <since_tizen> 4 </since_tizen>
870             public Size2D WindowSize
871             {
872                 get
873                 {
874                     return _windowSize;
875                 }
876                 set
877                 {
878                     _windowSize = value;
879                 }
880             }
881         }
882
883         /// <summary>
884         /// Please do not use! this will be deprecated
885         /// </summary>
886         /// <since_tizen> 3 </since_tizen>
887         [Obsolete("Please do not use! This will be deprecated! Please use FocusChangedEventArgs instead! " +
888             "Like: " +
889             "NUIApplication.GetDefaultWindow().FocusChanged = OnFocusChanged; " +
890             "private void OnFocusChanged(object source, Window.FocusChangedEventArgs args) {...}")]
891         [EditorBrowsable(EditorBrowsableState.Never)]
892         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
893         public class WindowFocusChangedEventArgs : EventArgs
894         {
895             /// <summary>
896             /// Please do not use! this will be deprecated
897             /// </summary>
898             /// <since_tizen> 3 </since_tizen>
899             public bool FocusGained
900             {
901                 get;
902                 set;
903             }
904         }
905
906         /// <summary>
907         /// Contains and encapsulates Native Window handle.
908         /// </summary>
909         /// <since_tizen> 4 </since_tizen>
910         public class SafeNativeWindowHandle : SafeHandle
911         {
912             /// <summary>
913             /// Contructor, Native window handle is set to handle.
914             /// </summary>
915             /// <since_tizen> 4 </since_tizen>
916             public SafeNativeWindowHandle() : base(IntPtr.Zero, false)
917             {
918                 SetHandle(NUIApplication.GetDefaultWindow().GetNativeWindowHandler());
919             }
920             /// <summary>
921             /// Null check if the handle is valid or not.
922             /// </summary>
923             /// <since_tizen> 4 </since_tizen>
924             public override bool IsInvalid
925             {
926                 get
927                 {
928                     return this.handle == IntPtr.Zero;
929                 }
930             }
931             /// <summary>
932             /// Release handle itself.
933             /// </summary>
934             /// <returns>true when released successfully.</returns>
935             /// <since_tizen> 4 </since_tizen>
936             protected override bool ReleaseHandle()
937             {
938                 return true;
939             }
940         }
941
942         /// <summary>
943         /// TransitionEffectArgs
944         /// </summary>
945         [EditorBrowsable(EditorBrowsableState.Never)]
946         public class TransitionEffectEventArgs : EventArgs
947         {
948             private EffectStates state;
949             private EffectTypes type;
950
951             /// <summary>
952             /// State
953             /// </summary>
954             [EditorBrowsable(EditorBrowsableState.Never)]
955             public EffectStates State
956             {
957                 get
958                 {
959                     return state;
960                 }
961                 set
962                 {
963                     state = value;
964                 }
965             }
966             /// <summary>
967             /// Type
968             /// </summary>
969             [EditorBrowsable(EditorBrowsableState.Never)]
970             public EffectTypes Type
971             {
972                 get
973                 {
974                     return type;
975                 }
976                 set
977                 {
978                     type = value;
979                 }
980             }
981         }
982
983         private EventHandler<WheelEventArgs> DetentEventHandler;
984
985         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
986         private delegate void DetentEventCallbackType(IntPtr arg1);
987
988         private DetentEventCallbackType DetentEventCallback;
989
990         private void OnDetentEvent(IntPtr wheelEvent)
991         {
992             WheelEventArgs e = new WheelEventArgs();
993
994             if (wheelEvent != global::System.IntPtr.Zero)
995             {
996                 e.Wheel = Wheel.GetWheelFromPtr(wheelEvent);
997             }
998
999             DetentEventHandler?.Invoke(this, e);
1000         }
1001
1002         /// <summary>
1003         /// VisibilityChangedArgs
1004         /// </summary>
1005         [EditorBrowsable(EditorBrowsableState.Never)]
1006         public class VisibilityChangedEventArgs : EventArgs
1007         {
1008             private bool visibility;
1009             /// <summary>
1010             /// Visibility
1011             /// </summary>
1012             [EditorBrowsable(EditorBrowsableState.Never)]
1013             public bool Visibility
1014             {
1015                 get => visibility;
1016                 set
1017                 {
1018                     visibility = value;
1019                 }
1020             }
1021         }
1022
1023         private void OnVisibilityChanged(IntPtr window, bool visibility)
1024         {
1025             if (window == global::System.IntPtr.Zero)
1026             {
1027                 NUILog.Error("[ERR] OnVisibilityChanged() window is null");
1028                 return;
1029             }
1030
1031             VisibilityChangedEventArgs e = new VisibilityChangedEventArgs();
1032             e.Visibility = visibility;
1033             if (VisibilityChangedEventHandler != null)
1034             {
1035                 VisibilityChangedEventHandler.Invoke(this, e);
1036             }
1037         }
1038
1039         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
1040         private delegate void VisibilityChangedEventCallbackType(IntPtr window, bool visibility);
1041         private VisibilityChangedEventCallbackType VisibilityChangedEventCallback;
1042         private event EventHandler<VisibilityChangedEventArgs> VisibilityChangedEventHandler;
1043         private WindowVisibilityChangedEvent VisibilityChangedEventSignal;
1044
1045         /// <summary>
1046         /// EffectStart
1047         /// </summary>
1048         [EditorBrowsable(EditorBrowsableState.Never)]
1049         public event EventHandler<VisibilityChangedEventArgs> VisibilityChanged
1050         {
1051             add
1052             {
1053                 if (VisibilityChangedEventHandler == null)
1054                 {
1055                     VisibilityChangedEventCallback = OnVisibilityChanged;
1056                     VisibilityChangedEventSignal = new WindowVisibilityChangedEvent(this);
1057                     VisibilityChangedEventSignal.Connect(VisibilityChangedEventCallback);
1058                 }
1059                 VisibilityChangedEventHandler += value;
1060             }
1061             remove
1062             {
1063                 VisibilityChangedEventHandler -= value;
1064                 if (VisibilityChangedEventHandler == null)
1065                 {
1066                     if (VisibilityChangedEventSignal != null)
1067                     {
1068                         if (VisibilityChangedEventSignal.Empty() == false)
1069                         {
1070                             VisibilityChangedEventSignal.Disconnect(VisibilityChangedEventCallback);
1071                         }
1072                     }
1073                 }
1074             }
1075         }
1076
1077         /// <summary>
1078         /// VisibiltyChangedSignalEmit
1079         /// </summary>
1080         [EditorBrowsable(EditorBrowsableState.Never)]
1081         public void VisibiltyChangedSignalEmit(bool visibility)
1082         {
1083             if (VisibilityChangedEventSignal == null)
1084             {
1085                 VisibilityChangedEventSignal = new WindowVisibilityChangedEvent(this);
1086             }
1087             VisibilityChangedEventSignal.Emit(this, visibility);
1088         }
1089
1090
1091
1092     }
1093 }