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