2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
21 using Tizen.NUI.BaseComponents;
22 using System.Collections.Generic;
27 /// The window class is used internally for drawing.<br />
28 /// The window has an orientation and indicator properties.<br />
30 /// <since_tizen> 3 </since_tizen>
31 public partial class Window
33 private WindowFocusChangedEventCallbackType windowFocusChangedEventCallback;
34 private RootLayerTouchDataCallbackType rootLayerTouchDataCallback;
35 private RootLayerTouchDataCallbackType rootLayerInterceptTouchDataCallback;
36 private WheelEventCallbackType wheelEventCallback;
37 private EventCallbackDelegateType1 stageKeyCallbackDelegate;
38 private InterceptKeyEventDelegateType stageInterceptKeyCallbackDelegate;
39 private EventCallbackDelegateType0 stageEventProcessingFinishedEventCallbackDelegate;
40 private EventHandler stageContextLostEventHandler;
41 private EventCallbackDelegateType0 stageContextLostEventCallbackDelegate;
42 private EventHandler stageContextRegainedEventHandler;
43 private EventCallbackDelegateType0 stageContextRegainedEventCallbackDelegate;
44 private EventHandler stageSceneCreatedEventHandler;
45 private EventCallbackDelegateType0 stageSceneCreatedEventCallbackDelegate;
46 private WindowResizeEventCallbackType windowResizeEventCallback;
47 private WindowFocusChangedEventCallbackType windowFocusChangedEventCallback2;
48 private TransitionEffectEventCallbackType transitionEffectEventCallback;
49 private WindowTransitionEffectSignal transitionEffectSignal;
50 private MovedEventCallbackType movedEventCallback;
51 private WindowMovedSignal movedSignal;
52 private KeyboardRepeatSettingsChangedEventCallbackType keyboardRepeatSettingsChangedEventCallback;
53 private KeyboardRepeatSettingsChangedSignal keyboardRepeatSettingsChangedSignal;
54 private WindowFocusSignalType windowFocusChangedSignal;
55 private WindowFocusSignalType windowFocusChangedSignal2;
56 private TouchDataSignal touchDataSignal;
57 private TouchSignal touchSignal;
58 private WheelSignal wheelSignal;
59 private StageWheelSignal stageWheelSignal;
60 private KeyEventSignal keyEventSignal;
61 private KeyEventSignal interceptKeyEventSignal;
62 private VoidSignal sceneCreatedSignal;
63 private ResizeSignal resizeSignal;
64 private VoidSignal eventProcessingFinishedSignal;
65 private VoidSignal contextLostSignal;
66 private VoidSignal contextRegainedSignal;
67 private AuxiliaryMessageEventCallbackType auxiliaryMessageEventCallback;
68 private TouchDataSignal interceptTouchDataSignal;
69 private TouchSignal interceptTouchSignal;
71 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
72 private delegate void WindowFocusChangedEventCallbackType(IntPtr window, bool focusGained);
73 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
74 private delegate bool RootLayerTouchDataCallbackType(IntPtr view, IntPtr touchData);
75 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
76 private delegate bool WheelEventCallbackType(IntPtr view, IntPtr wheelEvent);
77 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
78 private delegate void WindowResizeEventCallbackType(IntPtr window, IntPtr windowSize);
79 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
80 private delegate void WindowFocusChangedEventCallbackType2(IntPtr window, bool focusGained);
81 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
82 private delegate void TransitionEffectEventCallbackType(IntPtr window, int state, int type);
83 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
84 private delegate void MovedEventCallbackType(IntPtr window, IntPtr position);
85 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
86 private delegate void KeyboardRepeatSettingsChangedEventCallbackType();
87 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
88 private delegate void AuxiliaryMessageEventCallbackType(IntPtr kData, IntPtr vData, IntPtr optionsArray);
89 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
90 private delegate bool InterceptKeyEventDelegateType(IntPtr arg1);
93 /// FocusChanged event.
95 /// <since_tizen> 3 </since_tizen>
96 public event EventHandler<FocusChangedEventArgs> FocusChanged
100 if (windowFocusChangedEventHandler == null)
102 windowFocusChangedEventCallback = OnWindowFocusedChanged;
103 windowFocusChangedSignal = WindowFocusChangedSignal();
104 windowFocusChangedSignal?.Connect(windowFocusChangedEventCallback);
107 windowFocusChangedEventHandler += value;
111 windowFocusChangedEventHandler -= value;
113 if (windowFocusChangedEventHandler == null && windowFocusChangedSignal?.Empty() == false && windowFocusChangedEventCallback != null)
115 windowFocusChangedSignal?.Disconnect(windowFocusChangedEventCallback);
116 if (windowFocusChangedSignal?.Empty() == true)
118 windowFocusChangedEventCallback = null;
125 /// Emits the event when the screen is touched and when the touch ends.<br />
126 /// If there are multiple touch points then it is emitted when the first touch occurs and
127 /// when the last finger is lifted too.<br />
128 /// Even though incoming events are interrupted, the event occurs.<br />
130 /// <since_tizen> 3 </since_tizen>
131 public event EventHandler<TouchEventArgs> TouchEvent
135 if (rootLayerTouchDataEventHandler == null)
137 rootLayerTouchDataCallback = OnWindowTouch;
138 touchDataSignal = this.TouchDataSignal();
139 touchDataSignal?.Connect(rootLayerTouchDataCallback);
141 rootLayerTouchDataEventHandler += value;
145 rootLayerTouchDataEventHandler -= value;
146 touchSignal = TouchSignal();
147 if (rootLayerTouchDataEventHandler == null && touchSignal?.Empty() == false && rootLayerTouchDataCallback != null)
149 touchDataSignal?.Disconnect(rootLayerTouchDataCallback);
150 if (touchDataSignal?.Empty() == true)
152 rootLayerTouchDataCallback = null;
159 /// An event for the touched signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
160 /// The touched signal is emitted when the touch input is received.<br />
161 /// This can receive touch events before child. <br />
162 /// If it returns false, the child can receive the touch event. If it returns true, the touch event is intercepted. So child cannot receive touch event.<br />
164 [EditorBrowsable(EditorBrowsableState.Never)]
165 public event ReturnTypeEventHandler<object, TouchEventArgs, bool> InterceptTouchEvent
169 if (rootLayerInterceptTouchDataEventHandler == null)
171 rootLayerInterceptTouchDataCallback = OnWindowInterceptTouch;
172 interceptTouchDataSignal = this.InterceptTouchDataSignal();
173 interceptTouchDataSignal?.Connect(rootLayerInterceptTouchDataCallback);
175 rootLayerInterceptTouchDataEventHandler += value;
179 rootLayerInterceptTouchDataEventHandler -= value;
180 interceptTouchSignal = TouchSignal();
181 if (rootLayerInterceptTouchDataEventHandler == null && interceptTouchSignal?.Empty() == false && rootLayerInterceptTouchDataCallback != null)
183 interceptTouchDataSignal?.Disconnect(rootLayerInterceptTouchDataCallback);
184 if (interceptTouchDataSignal?.Empty() == true)
186 rootLayerInterceptTouchDataCallback = null;
193 /// Emits the event when the wheel event is received.
195 /// <since_tizen> 3 </since_tizen>
196 public event EventHandler<WheelEventArgs> WheelEvent
200 if (stageWheelHandler == null)
202 wheelEventCallback = OnStageWheel;
203 wheelSignal = WheelEventSignal();
204 wheelSignal?.Connect(wheelEventCallback);
206 stageWheelHandler += value;
208 if (DetentEventHandler == null)
210 DetentEventCallback = OnDetentEvent;
211 stageWheelSignal = StageWheelEventSignal();
212 stageWheelSignal?.Connect(DetentEventCallback);
214 DetentEventHandler += value;
218 stageWheelHandler -= value;
219 if (stageWheelHandler == null && wheelSignal?.Empty() == false)
221 wheelSignal?.Disconnect(wheelEventCallback);
222 if (wheelSignal?.Empty() == true)
224 wheelEventCallback = null;
228 DetentEventHandler -= value;
229 if (DetentEventHandler == null && stageWheelSignal?.Empty() == false)
231 stageWheelSignal?.Disconnect(DetentEventCallback);
232 if (stageWheelSignal?.Empty() == true)
234 DetentEventCallback = null;
241 /// Emits the event when the key event is received.
243 /// <since_tizen> 3 </since_tizen>
244 public event EventHandler<KeyEventArgs> KeyEvent
248 if (stageKeyHandler == null)
250 stageKeyCallbackDelegate = OnStageKey;
251 keyEventSignal = KeyEventSignal();
252 keyEventSignal?.Connect(stageKeyCallbackDelegate);
254 stageKeyHandler += value;
258 stageKeyHandler -= value;
259 if (stageKeyHandler == null && keyEventSignal?.Empty() == false)
261 keyEventSignal?.Disconnect(stageKeyCallbackDelegate);
262 if (keyEventSignal?.Empty() == true)
264 stageKeyCallbackDelegate = null;
271 /// Intercepts KeyEvents in the window before dispatching KeyEvents to the child.<br />
272 /// If it returns true(consumed), no KeyEvent is delivered to the child.
274 [EditorBrowsable(EditorBrowsableState.Never)]
275 public event ReturnTypeEventHandler<object, KeyEventArgs, bool> InterceptKeyEvent
279 if (stageInterceptKeyHandler == null)
281 stageInterceptKeyCallbackDelegate = OnStageInterceptKey;
282 interceptKeyEventSignal = InterceptKeyEventSignal();
283 interceptKeyEventSignal?.Connect(stageInterceptKeyCallbackDelegate);
285 stageInterceptKeyHandler += value;
289 stageInterceptKeyHandler -= value;
290 if (stageInterceptKeyHandler == null && interceptKeyEventSignal?.Empty() == false)
292 interceptKeyEventSignal?.Disconnect(stageInterceptKeyCallbackDelegate);
293 if (interceptKeyEventSignal?.Empty() == true)
295 stageInterceptKeyCallbackDelegate = null;
303 /// Emits the event when the window resized.
305 /// <since_tizen> 3 </since_tizen>
306 public event EventHandler<ResizedEventArgs> Resized
310 if (windowResizeEventHandler == null)
312 windowResizeEventCallback = OnResized;
313 resizeSignal = ResizeSignal();
314 resizeSignal?.Connect(windowResizeEventCallback);
317 windowResizeEventHandler += value;
321 windowResizeEventHandler -= value;
323 if (windowResizeEventHandler == null && resizeSignal?.Empty() == false && windowResizeEventCallback != null)
325 resizeSignal?.Disconnect(windowResizeEventCallback);
326 if (resizeSignal?.Empty() == true)
328 windowResizeEventCallback = null;
335 /// Do not use this, that will be deprecated. Use 'FocusChanged' event instead.
337 /// <since_tizen> 3 </since_tizen>
338 /// Do not use this, that will be deprecated.
339 /// Instead Use FocusChanged.
340 [Obsolete("Do not use this, that will be deprecated. Use FocusChanged instead. " +
342 "NUIApplication.GetDefaultWindow().FocusChanged = OnFocusChanged; " +
343 "private void OnFocusChanged(object source, Window.FocusChangedEventArgs args) {...}")]
344 [EditorBrowsable(EditorBrowsableState.Never)]
345 public event EventHandler<FocusChangedEventArgs> WindowFocusChanged
349 if (windowFocusChangedEventHandler2 == null)
351 windowFocusChangedEventCallback2 = OnWindowFocusedChanged2;
352 windowFocusChangedSignal2 = WindowFocusChangedSignal();
353 windowFocusChangedSignal2?.Connect(windowFocusChangedEventCallback2);
356 windowFocusChangedEventHandler2 += value;
360 windowFocusChangedEventHandler2 -= value;
362 if (windowFocusChangedEventHandler2 == null && windowFocusChangedSignal2?.Empty() == false && windowFocusChangedEventCallback2 != null)
364 windowFocusChangedSignal2?.Disconnect(windowFocusChangedEventCallback2);
365 if (windowFocusChangedSignal2?.Empty() == true)
367 windowFocusChangedEventCallback2 = null;
376 [EditorBrowsable(EditorBrowsableState.Never)]
377 public event EventHandler<TransitionEffectEventArgs> TransitionEffect
381 if (transitionEffectHandler == null)
383 transitionEffectEventCallback = OnTransitionEffect;
384 TransitionEffectEventSignal().Connect(transitionEffectEventCallback);
386 transitionEffectHandler += value;
390 transitionEffectHandler -= value;
391 if (transitionEffectHandler == null && TransitionEffectEventSignal().Empty() == false)
393 TransitionEffectEventSignal().Disconnect(transitionEffectEventCallback);
394 if (TransitionEffectEventSignal().Empty() == true)
396 transitionEffectEventCallback = null;
405 [EditorBrowsable(EditorBrowsableState.Never)]
406 public event EventHandler<WindowMovedEventArgs> Moved
410 if (movedHandler == null)
412 movedEventCallback = OnMoved;
413 MovedEventSignal().Connect(movedEventCallback);
415 movedHandler += value;
419 movedHandler -= value;
420 if (movedHandler == null && MovedEventSignal().Empty() == false)
422 MovedEventSignal().Disconnect(movedEventCallback);
423 if (MovedEventSignal().Empty() == true)
425 movedEventCallback = null;
432 /// Keyboard Repeat Settings Changed
434 [EditorBrowsable(EditorBrowsableState.Never)]
435 public event EventHandler KeyboardRepeatSettingsChanged
439 if (keyboardRepeatSettingsChangedHandler == null)
441 keyboardRepeatSettingsChangedEventCallback = OnKeyboardRepeatSettingsChanged;
442 KeyboardRepeatSettingsChangedEventSignal().Connect(keyboardRepeatSettingsChangedEventCallback);
444 keyboardRepeatSettingsChangedHandler += value;
448 keyboardRepeatSettingsChangedHandler -= value;
449 if (keyboardRepeatSettingsChangedHandler == null && KeyboardRepeatSettingsChangedEventSignal().Empty() == false)
451 KeyboardRepeatSettingsChangedEventSignal().Disconnect(keyboardRepeatSettingsChangedEventCallback);
452 if (KeyboardRepeatSettingsChangedEventSignal().Empty() == true)
454 keyboardRepeatSettingsChangedEventCallback = null;
461 /// ViewAdded will be triggered when the view added on Window
463 /// <since_tizen> 6 </since_tizen>
464 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
465 [EditorBrowsable(EditorBrowsableState.Never)]
466 public event EventHandler ViewAdded;
467 private event EventHandler<FocusChangedEventArgs> windowFocusChangedEventHandler;
468 private event EventHandler<TouchEventArgs> rootLayerTouchDataEventHandler;
469 private ReturnTypeEventHandler<object, TouchEventArgs, bool> rootLayerInterceptTouchDataEventHandler;
470 private event EventHandler<WheelEventArgs> stageWheelHandler;
471 private event EventHandler<KeyEventArgs> stageKeyHandler;
472 private ReturnTypeEventHandler<object, KeyEventArgs, bool> stageInterceptKeyHandler;
473 private event EventHandler stageEventProcessingFinishedEventHandler;
474 private event EventHandler<ResizedEventArgs> windowResizeEventHandler;
475 private event EventHandler<FocusChangedEventArgs> windowFocusChangedEventHandler2;
476 private event EventHandler<TransitionEffectEventArgs> transitionEffectHandler;
477 private event EventHandler<WindowMovedEventArgs> movedHandler;
478 private event EventHandler keyboardRepeatSettingsChangedHandler;
479 private event EventHandler<AuxiliaryMessageEventArgs> auxiliaryMessageEventHandler;
481 internal void SendViewAdded(View view)
483 ViewAdded?.Invoke(view, EventArgs.Empty);
486 internal event EventHandler EventProcessingFinished
490 if (stageEventProcessingFinishedEventHandler == null)
492 stageEventProcessingFinishedEventCallbackDelegate = OnEventProcessingFinished;
493 eventProcessingFinishedSignal = EventProcessingFinishedSignal();
494 eventProcessingFinishedSignal?.Connect(stageEventProcessingFinishedEventCallbackDelegate);
496 stageEventProcessingFinishedEventHandler += value;
501 stageEventProcessingFinishedEventHandler -= value;
502 if (stageEventProcessingFinishedEventHandler == null && eventProcessingFinishedSignal?.Empty() == false)
504 eventProcessingFinishedSignal?.Disconnect(stageEventProcessingFinishedEventCallbackDelegate);
509 internal event EventHandler ContextLost
513 if (stageContextLostEventHandler == null)
515 stageContextLostEventCallbackDelegate = OnContextLost;
516 contextLostSignal = ContextLostSignal();
517 contextLostSignal?.Connect(stageContextLostEventCallbackDelegate);
519 stageContextLostEventHandler += value;
523 stageContextLostEventHandler -= value;
524 if (stageContextLostEventHandler == null && contextLostSignal?.Empty() == false)
526 contextLostSignal?.Disconnect(stageContextLostEventCallbackDelegate);
527 if (contextLostSignal?.Empty() == true)
529 stageContextLostEventCallbackDelegate = null;
535 internal event EventHandler ContextRegained
539 if (stageContextRegainedEventHandler == null)
541 stageContextRegainedEventCallbackDelegate = OnContextRegained;
542 contextRegainedSignal = ContextRegainedSignal();
543 contextRegainedSignal?.Connect(stageContextRegainedEventCallbackDelegate);
545 stageContextRegainedEventHandler += value;
549 stageContextRegainedEventHandler -= value;
550 if (stageContextRegainedEventHandler == null && contextRegainedSignal?.Empty() == false)
552 contextRegainedSignal?.Disconnect(stageContextRegainedEventCallbackDelegate);
553 if (contextRegainedSignal?.Empty() == true)
555 stageContextRegainedEventCallbackDelegate = null;
561 internal event EventHandler SceneCreated
565 if (stageSceneCreatedEventHandler == null)
567 stageSceneCreatedEventCallbackDelegate = OnSceneCreated;
568 sceneCreatedSignal = SceneCreatedSignal();
569 sceneCreatedSignal?.Connect(stageSceneCreatedEventCallbackDelegate);
571 stageSceneCreatedEventHandler += value;
575 stageSceneCreatedEventHandler -= value;
576 if (stageSceneCreatedEventHandler == null && sceneCreatedSignal?.Empty() == false)
578 sceneCreatedSignal?.Disconnect(stageSceneCreatedEventCallbackDelegate);
579 if (sceneCreatedSignal?.Empty() == true)
581 stageSceneCreatedEventCallbackDelegate = null;
587 internal WindowFocusSignalType WindowFocusChangedSignal()
589 WindowFocusSignalType ret = new WindowFocusSignalType(Interop.Window.FocusChangedSignal(SwigCPtr), false);
590 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
594 internal WindowFocusSignalType FocusChangedSignal()
596 WindowFocusSignalType ret = new WindowFocusSignalType(Interop.Window.FocusChangedSignal(SwigCPtr), false);
597 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
601 internal KeyEventSignal KeyEventSignal()
603 KeyEventSignal ret = new KeyEventSignal(Interop.Window.KeyEventSignal(SwigCPtr), false);
604 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
608 internal KeyEventSignal InterceptKeyEventSignal()
610 KeyEventSignal ret = new KeyEventSignal(Interop.Window.InterceptKeyEventSignal(SwigCPtr), false);
611 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
615 internal VoidSignal EventProcessingFinishedSignal()
617 VoidSignal ret = new VoidSignal(Interop.StageSignal.EventProcessingFinishedSignal(stageCPtr), false);
618 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
622 internal TouchSignal TouchSignal()
624 TouchSignal ret = new TouchSignal(Interop.Window.TouchSignal(SwigCPtr), false);
625 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
629 internal TouchDataSignal TouchDataSignal()
631 TouchDataSignal ret = new TouchDataSignal(Interop.ActorSignal.ActorTouchSignal(Layer.getCPtr(GetRootLayer())), false);
632 if (NDalicPINVOKE.SWIGPendingException.Pending)
633 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
637 internal TouchDataSignal InterceptTouchDataSignal()
639 TouchDataSignal ret = new TouchDataSignal(Interop.ActorSignal.ActorInterceptTouchSignal(Layer.getCPtr(GetRootLayer())), false);
640 if (NDalicPINVOKE.SWIGPendingException.Pending)
641 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
646 internal VoidSignal ContextLostSignal()
648 VoidSignal ret = new VoidSignal(Interop.StageSignal.ContextLostSignal(stageCPtr), false);
649 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
653 internal VoidSignal ContextRegainedSignal()
655 VoidSignal ret = new VoidSignal(Interop.StageSignal.ContextRegainedSignal(stageCPtr), false);
656 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
660 internal VoidSignal SceneCreatedSignal()
662 VoidSignal ret = new VoidSignal(Interop.StageSignal.SceneCreatedSignal(stageCPtr), false);
663 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
667 internal ResizeSignal ResizeSignal()
669 ResizeSignal ret = new ResizeSignal(Interop.Window.ResizeSignal(SwigCPtr), false);
670 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
674 internal System.IntPtr GetNativeWindowHandler()
676 System.IntPtr ret = Interop.Window.GetNativeWindowHandler(HandleRef.ToIntPtr(this.SwigCPtr));
677 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
682 /// Disconnect all native signals
684 /// <since_tizen> 5 </since_tizen>
685 internal void DisconnectNativeSignals()
687 if (windowFocusChangedEventCallback != null)
689 windowFocusChangedSignal?.Disconnect(windowFocusChangedEventCallback);
690 windowFocusChangedEventCallback = null;
693 if (rootLayerTouchDataCallback != null)
695 touchDataSignal?.Disconnect(rootLayerTouchDataCallback);
696 rootLayerTouchDataCallback = null;
699 if (rootLayerInterceptTouchDataCallback != null)
701 interceptTouchDataSignal?.Disconnect(rootLayerInterceptTouchDataCallback);
702 rootLayerInterceptTouchDataCallback = null;
705 if (wheelEventCallback != null)
707 wheelSignal?.Disconnect(wheelEventCallback);
708 wheelEventCallback = null;
711 if (DetentEventCallback != null)
713 stageWheelSignal?.Disconnect(DetentEventCallback);
714 DetentEventCallback = null;
717 if (stageKeyCallbackDelegate != null)
719 keyEventSignal?.Disconnect(stageKeyCallbackDelegate);
720 stageKeyCallbackDelegate = null;
723 if (stageInterceptKeyCallbackDelegate != null)
725 interceptKeyEventSignal?.Disconnect(stageInterceptKeyCallbackDelegate);
726 stageInterceptKeyCallbackDelegate = null;
729 if (stageEventProcessingFinishedEventCallbackDelegate != null)
731 eventProcessingFinishedSignal?.Disconnect(stageEventProcessingFinishedEventCallbackDelegate);
732 stageEventProcessingFinishedEventCallbackDelegate = null;
735 if (stageContextLostEventCallbackDelegate != null)
737 contextLostSignal?.Disconnect(stageContextLostEventCallbackDelegate);
738 stageContextLostEventCallbackDelegate = null;
741 if (stageContextRegainedEventCallbackDelegate != null)
743 contextRegainedSignal?.Disconnect(stageContextRegainedEventCallbackDelegate);
744 stageContextRegainedEventCallbackDelegate = null;
747 if (stageSceneCreatedEventCallbackDelegate != null)
749 sceneCreatedSignal?.Disconnect(stageSceneCreatedEventCallbackDelegate);
750 stageSceneCreatedEventCallbackDelegate = null;
753 if (windowResizeEventCallback != null)
755 resizeSignal?.Disconnect(windowResizeEventCallback);
756 windowResizeEventCallback = null;
759 if (windowFocusChangedEventCallback2 != null)
761 windowFocusChangedSignal2?.Disconnect(windowFocusChangedEventCallback2);
762 windowFocusChangedEventCallback2 = null;
765 if (transitionEffectSignal != null)
767 TransitionEffectEventSignal().Disconnect(transitionEffectEventCallback);
768 transitionEffectEventCallback = null;
771 if (movedSignal != null)
773 MovedEventSignal().Disconnect(movedEventCallback);
774 movedEventCallback = null;
777 if (keyboardRepeatSettingsChangedSignal != null)
779 KeyboardRepeatSettingsChangedEventSignal().Disconnect(keyboardRepeatSettingsChangedEventCallback);
780 keyboardRepeatSettingsChangedEventCallback = null;
783 if (auxiliaryMessageEventCallback != null)
785 using var signal = new WindowAuxiliaryMessageSignal(this);
786 signal.Disconnect(auxiliaryMessageEventCallback);
787 auxiliaryMessageEventHandler = null;
788 auxiliaryMessageEventCallback = null;
791 if (AccessibilityHighlightEventCallback != null)
793 AccessibilityHighlightEventSignal?.Disconnect(AccessibilityHighlightEventCallback);
794 AccessibilityHighlightEventCallback = null;
798 private StageWheelSignal StageWheelEventSignal()
800 StageWheelSignal ret = new StageWheelSignal(Interop.StageSignal.WheelEventSignal(stageCPtr), false);
801 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
805 private WheelSignal WheelEventSignal()
807 WheelSignal ret = new WheelSignal(Interop.ActorSignal.ActorWheelEventSignal(Layer.getCPtr(this.GetRootLayer())), false);
808 if (NDalicPINVOKE.SWIGPendingException.Pending)
809 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
813 private WindowTransitionEffectSignal TransitionEffectEventSignal()
815 if (transitionEffectSignal == null)
817 transitionEffectSignal = new WindowTransitionEffectSignal(this);
818 if (NDalicPINVOKE.SWIGPendingException.Pending)
819 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
821 return transitionEffectSignal;
824 private WindowMovedSignal MovedEventSignal()
826 if (movedSignal == null)
828 movedSignal = new WindowMovedSignal(this);
829 if (NDalicPINVOKE.SWIGPendingException.Pending)
830 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
835 private KeyboardRepeatSettingsChangedSignal KeyboardRepeatSettingsChangedEventSignal()
837 if (keyboardRepeatSettingsChangedSignal == null)
839 keyboardRepeatSettingsChangedSignal = new KeyboardRepeatSettingsChangedSignal(this);
840 if (NDalicPINVOKE.SWIGPendingException.Pending)
841 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
843 return keyboardRepeatSettingsChangedSignal;
846 private void OnWindowFocusedChanged(IntPtr window, bool focusGained)
848 if (window == IntPtr.Zero)
850 NUILog.Error("OnWindowFocusedChanged() Window is null! Do nothing!");
854 if (windowFocusChangedEventHandler != null)
856 FocusChangedEventArgs e = new FocusChangedEventArgs();
857 e.FocusGained = focusGained;
858 windowFocusChangedEventHandler(this, e);
862 private bool OnWindowTouch(IntPtr view, IntPtr touchData)
864 if (touchData == global::System.IntPtr.Zero)
866 NUILog.Error("touchData should not be null!");
870 if (rootLayerTouchDataEventHandler != null)
872 TouchEventArgs e = new TouchEventArgs();
873 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
874 rootLayerTouchDataEventHandler(this, e);
879 private bool OnWindowInterceptTouch(IntPtr view, IntPtr touchData)
881 if (touchData == global::System.IntPtr.Zero)
883 NUILog.Error("touchData should not be null!");
887 bool consumed = false;
888 if (rootLayerInterceptTouchDataEventHandler != null)
890 TouchEventArgs e = new TouchEventArgs();
891 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
892 consumed = rootLayerInterceptTouchDataEventHandler(this, e);
897 private bool OnStageWheel(IntPtr rootLayer, IntPtr wheelEvent)
899 if (wheelEvent == global::System.IntPtr.Zero)
901 NUILog.Error("wheelEvent should not be null!");
905 if (stageWheelHandler != null)
907 WheelEventArgs e = new WheelEventArgs();
908 e.Wheel = Tizen.NUI.Wheel.GetWheelFromPtr(wheelEvent);
909 stageWheelHandler(this, e);
914 // Callback for Stage KeyEventsignal
915 private void OnStageKey(IntPtr data)
917 if (stageKeyHandler != null)
919 KeyEventArgs e = new KeyEventArgs();
920 e.Key = Tizen.NUI.Key.GetKeyFromPtr(data);
921 //here we send all data to user event handlers
922 stageKeyHandler(this, e);
926 // Callback for Stage InterceptKeyEventsignal
927 private bool OnStageInterceptKey(IntPtr data)
929 bool consumed = false;
930 if (stageInterceptKeyHandler != null)
932 KeyEventArgs e = new KeyEventArgs();
933 e.Key = Tizen.NUI.Key.GetKeyFromPtr(data);
934 //here we send all data to user event handlers
935 consumed = stageInterceptKeyHandler(this, e);
940 // Callback for Stage EventProcessingFinishedSignal
941 private void OnEventProcessingFinished()
943 stageEventProcessingFinishedEventHandler?.Invoke(this, null);
946 // Callback for Stage ContextLostSignal
947 private void OnContextLost()
949 stageContextLostEventHandler?.Invoke(this, null);
952 // Callback for Stage ContextRegainedSignal
953 private void OnContextRegained()
955 stageContextRegainedEventHandler?.Invoke(this, null);
958 // Callback for Stage SceneCreatedSignal
959 private void OnSceneCreated()
961 stageSceneCreatedEventHandler?.Invoke(this, null);
964 private void OnResized(IntPtr window, IntPtr windowSize)
966 if (window == IntPtr.Zero)
968 NUILog.Error("OnResized() Window is null! Do nothing!");
972 if (windowResizeEventHandler != null)
974 ResizedEventArgs e = new ResizedEventArgs();
975 // var val = new Uint16Pair(windowSize, false);
976 // e.WindowSize = new Size2D(val.GetWidth(), val.GetHeight());
979 // Workaround : windowSize should be valid pointer from dali,
980 // but currently it is fixed and is not Uint16Pair class.
981 // will be fixed later.
982 e.WindowSize = this.WindowSize;
983 windowResizeEventHandler(this, e);
987 private void OnWindowFocusedChanged2(IntPtr window, bool focusGained)
989 if (window == IntPtr.Zero)
991 NUILog.Error("OnWindowFocusedChanged() Window is null! Do nothing!");
995 if (windowFocusChangedEventHandler2 != null)
997 FocusChangedEventArgs e = new FocusChangedEventArgs();
998 e.FocusGained = focusGained;
999 windowFocusChangedEventHandler2(this, e);
1003 private void OnTransitionEffect(IntPtr window, int state, int type)
1005 if (window == global::System.IntPtr.Zero)
1010 if (transitionEffectHandler != null)
1012 TransitionEffectEventArgs e = new TransitionEffectEventArgs();
1013 e.State = (EffectState)state;
1014 e.Type = (EffectType)type;
1015 transitionEffectHandler(this, e);
1020 private void OnMoved(IntPtr window, IntPtr position)
1022 if (window == global::System.IntPtr.Zero)
1027 if (movedHandler != null)
1029 WindowMovedEventArgs e = new WindowMovedEventArgs();
1030 e.WindowPosition = this.WindowPosition;
1031 movedHandler(this, e);
1036 private void OnKeyboardRepeatSettingsChanged()
1038 keyboardRepeatSettingsChangedHandler?.Invoke(this, null);
1043 /// The focus changed event argument.
1045 /// <since_tizen> 3 </since_tizen>
1046 public class FocusChangedEventArgs : EventArgs
1049 /// FocusGained flag.
1051 /// <since_tizen> 3 </since_tizen>
1052 public bool FocusGained
1060 /// The touch event argument.
1062 /// <since_tizen> 3 </since_tizen>
1063 public class TouchEventArgs : EventArgs
1065 private Touch touch;
1070 /// <since_tizen> 3 </since_tizen>
1085 /// Wheel event arguments.
1087 /// <since_tizen> 3 </since_tizen>
1088 public class WheelEventArgs : EventArgs
1090 private Wheel wheel;
1095 /// <since_tizen> 3 </since_tizen>
1110 /// Key event arguments.
1112 /// <since_tizen> 3 </since_tizen>
1113 public class KeyEventArgs : EventArgs
1120 /// <since_tizen> 3 </since_tizen>
1135 /// Feeds a key event into the window.
1136 /// This resized event arguments.
1138 /// <since_tizen> 3 </since_tizen>
1139 public class ResizedEventArgs : EventArgs
1144 /// This window size.
1146 /// <since_tizen> 4 </since_tizen>
1147 public Size2D WindowSize
1161 /// Do not use this, that will be deprecated.
1163 /// <since_tizen> 3 </since_tizen>
1164 [Obsolete("Do not use this, that will be deprecated. Use FocusChangedEventArgs instead. " +
1166 "NUIApplication.GetDefaultWindow().FocusChanged = OnFocusChanged; " +
1167 "private void OnFocusChanged(object source, Window.FocusChangedEventArgs args) {...}")]
1168 [EditorBrowsable(EditorBrowsableState.Never)]
1169 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
1170 public class WindowFocusChangedEventArgs : EventArgs
1173 /// Do not use this, that will be deprecated.
1175 /// <since_tizen> 3 </since_tizen>
1176 public bool FocusGained
1184 /// Contains and encapsulates Native Window handle.
1186 /// <since_tizen> 4 </since_tizen>
1187 [Obsolete("This has been deprecated in API9 and will be removed in API11. Use Window.NativeHandle instead.")]
1188 public class SafeNativeWindowHandle : SafeHandle
1191 ///Constructor, Native window handle is set to handle.
1193 /// <since_tizen> 4 </since_tizen>
1194 public SafeNativeWindowHandle() : base(IntPtr.Zero, false)
1196 SetHandle(NUIApplication.GetDefaultWindow().GetNativeWindowHandler());
1199 /// Null check if the handle is valid or not.
1201 /// <since_tizen> 4 </since_tizen>
1202 public override bool IsInvalid
1206 return this.handle == IntPtr.Zero;
1210 /// Release handle itself.
1212 /// <returns>true when released successfully.</returns>
1213 /// <since_tizen> 4 </since_tizen>
1214 protected override bool ReleaseHandle()
1221 /// TransitionEffectArgs
1223 [EditorBrowsable(EditorBrowsableState.Never)]
1224 public class TransitionEffectEventArgs : EventArgs
1226 private EffectState state;
1227 private EffectType type;
1232 [EditorBrowsable(EditorBrowsableState.Never)]
1233 public EffectState State
1247 [EditorBrowsable(EditorBrowsableState.Never)]
1248 public EffectType Type
1261 private EventHandler<WheelEventArgs> DetentEventHandler;
1263 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
1264 private delegate void DetentEventCallbackType(IntPtr arg1);
1266 private DetentEventCallbackType DetentEventCallback;
1268 private void OnDetentEvent(IntPtr wheelEvent)
1270 WheelEventArgs e = new WheelEventArgs();
1272 if (wheelEvent != global::System.IntPtr.Zero)
1274 e.Wheel = Wheel.GetWheelFromPtr(wheelEvent);
1277 DetentEventHandler?.Invoke(this, e);
1281 /// VisibilityChangedArgs
1283 [EditorBrowsable(EditorBrowsableState.Never)]
1284 public class VisibilityChangedEventArgs : EventArgs
1286 private bool visibility;
1290 [EditorBrowsable(EditorBrowsableState.Never)]
1291 public bool Visibility
1301 private void OnVisibilityChanged(IntPtr window, bool visibility)
1303 if (window == global::System.IntPtr.Zero)
1305 NUILog.Error("[ERR] OnVisibilityChanged() window is null");
1309 VisibilityChangedEventArgs e = new VisibilityChangedEventArgs();
1310 e.Visibility = visibility;
1311 if (VisibilityChangedEventHandler != null)
1313 VisibilityChangedEventHandler.Invoke(this, e);
1317 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
1318 private delegate void VisibilityChangedEventCallbackType(IntPtr window, bool visibility);
1319 private VisibilityChangedEventCallbackType VisibilityChangedEventCallback;
1320 private event EventHandler<VisibilityChangedEventArgs> VisibilityChangedEventHandler;
1321 private WindowVisibilityChangedEvent VisibilityChangedEventSignal;
1326 [EditorBrowsable(EditorBrowsableState.Never)]
1327 public event EventHandler<VisibilityChangedEventArgs> VisibilityChanged
1331 if (VisibilityChangedEventHandler == null)
1333 VisibilityChangedEventCallback = OnVisibilityChanged;
1334 VisibilityChangedEventSignal = new WindowVisibilityChangedEvent(this);
1335 VisibilityChangedEventSignal.Connect(VisibilityChangedEventCallback);
1337 VisibilityChangedEventHandler += value;
1341 VisibilityChangedEventHandler -= value;
1342 if (VisibilityChangedEventHandler == null)
1344 if (VisibilityChangedEventSignal != null)
1346 if (VisibilityChangedEventSignal.Empty() == false)
1348 VisibilityChangedEventSignal.Disconnect(VisibilityChangedEventCallback);
1356 /// VisibiltyChangedSignalEmit
1358 [EditorBrowsable(EditorBrowsableState.Never)]
1359 public void VisibiltyChangedSignalEmit(bool visibility)
1361 if (VisibilityChangedEventSignal == null)
1363 VisibilityChangedEventSignal = new WindowVisibilityChangedEvent(this);
1365 VisibilityChangedEventSignal.Emit(this, visibility);
1368 private void OnAuxiliaryMessage(IntPtr kData, IntPtr vData, IntPtr optionsArray)
1370 if(kData == IntPtr.Zero || vData == IntPtr.Zero)
1375 using var tmp = new PropertyArray(optionsArray, false);
1376 var size = tmp.Size();
1378 List<string> tmpList = new List<string>();
1380 for (int i = 0; i < size; i++)
1382 string option = "none";
1383 tmp.GetElementAt((uint)i).Get(out option);
1384 tmpList.Add(option);
1389 AuxiliaryMessageEventArgs e = new AuxiliaryMessageEventArgs();
1390 e.Key = StringToVoidSignal.GetResult(kData);
1391 e.Value = StringToVoidSignal.GetResult(vData);;
1392 e.Options = tmpList;
1394 auxiliaryMessageEventHandler?.Invoke(this, e);
1398 /// Auxiliary message is sent by displayer server when window's auxiliary was changed then display server sent the message.
1399 /// When client application added the window's auxiliary hint and if the auxiliary is changed,
1400 /// display server send the auxiliary message.
1401 /// Auxiliary message has the key, value and options.
1403 [EditorBrowsable(EditorBrowsableState.Never)]
1404 public event EventHandler<AuxiliaryMessageEventArgs> AuxiliaryMessage
1408 if (auxiliaryMessageEventHandler == null)
1410 auxiliaryMessageEventCallback = OnAuxiliaryMessage;
1411 using var signal = new WindowAuxiliaryMessageSignal(this);
1412 signal.Connect(auxiliaryMessageEventCallback);
1414 auxiliaryMessageEventHandler += value;
1418 auxiliaryMessageEventHandler -= value;
1419 if (auxiliaryMessageEventHandler == null)
1421 if (auxiliaryMessageEventCallback != null)
1423 using var signal = new WindowAuxiliaryMessageSignal(this);
1424 signal.Disconnect(auxiliaryMessageEventCallback);
1428 auxiliaryMessageEventCallback = null;
1436 /// AccessibilityHighlightArgs
1438 [EditorBrowsable(EditorBrowsableState.Never)]
1439 public class AccessibilityHighlightEventArgs : EventArgs
1441 private bool accessibilityHighlight;
1443 /// accessibilityHighlight
1445 [EditorBrowsable(EditorBrowsableState.Never)]
1446 public bool AccessibilityHighlight
1448 get => accessibilityHighlight;
1451 accessibilityHighlight = value;
1456 private void OnAccessibilityHighlight(IntPtr window, bool highlight)
1458 if (window == global::System.IntPtr.Zero)
1460 NUILog.Error("[ERR] OnAccessibilityHighlight() window is null");
1464 AccessibilityHighlightEventArgs e = new AccessibilityHighlightEventArgs();
1465 e.AccessibilityHighlight = highlight;
1466 if (AccessibilityHighlightEventHandler != null)
1468 AccessibilityHighlightEventHandler.Invoke(this, e);
1472 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
1473 private delegate void AccessibilityHighlightEventCallbackType(IntPtr window, bool highlight);
1474 private AccessibilityHighlightEventCallbackType AccessibilityHighlightEventCallback;
1475 private event EventHandler<AccessibilityHighlightEventArgs> AccessibilityHighlightEventHandler;
1476 private WindowAccessibilityHighlightEvent AccessibilityHighlightEventSignal;
1479 /// Emits the event when the window needs to grab or clear highlight.
1481 [EditorBrowsable(EditorBrowsableState.Never)]
1482 public event EventHandler<AccessibilityHighlightEventArgs> AccessibilityHighlight
1486 if (AccessibilityHighlightEventHandler == null)
1488 AccessibilityHighlightEventCallback = OnAccessibilityHighlight;
1489 AccessibilityHighlightEventSignal = new WindowAccessibilityHighlightEvent(this);
1490 AccessibilityHighlightEventSignal.Connect(AccessibilityHighlightEventCallback);
1492 AccessibilityHighlightEventHandler += value;
1496 AccessibilityHighlightEventHandler -= value;
1497 if (AccessibilityHighlightEventHandler == null)
1499 if (AccessibilityHighlightEventSignal != null)
1501 if (AccessibilityHighlightEventSignal.Empty() == false)
1503 AccessibilityHighlightEventSignal.Disconnect(AccessibilityHighlightEventCallback);
1504 if (AccessibilityHighlightEventSignal.Empty() == true)
1506 AccessibilityHighlightEventCallback = null;
1518 [EditorBrowsable(EditorBrowsableState.Never)]
1519 public class WindowMovedEventArgs : EventArgs
1521 private Position2D position;
1523 [EditorBrowsable(EditorBrowsableState.Never)]
1524 public Position2D WindowPosition