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