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;
25 public partial class GLWindow
27 private FocusChangedEventCallbackType focusChangedEventCallback;
28 private GLWindowTouchDataCallbackType windowTouchDataCallback;
29 private EventCallbackDelegateType1 windowKeyCallbackDelegate;
30 private WindowResizedEventCallbackType windowResizedEventCallback;
32 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
33 private delegate void FocusChangedEventCallbackType(IntPtr window, bool focusGained);
34 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
35 private delegate bool GLWindowTouchDataCallbackType(IntPtr touchData);
36 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
37 private delegate void WindowResizedEventCallbackType(IntPtr windowSize);
40 /// FocusChanged event.
42 [EditorBrowsable(EditorBrowsableState.Never)]
43 public event EventHandler<FocusChangedEventArgs> FocusChanged
47 if (focusChangedEventCallback == null)
49 focusChangedEventCallback = OnWindowFocusedChanged;
50 FocusChangedSignal().Connect(focusChangedEventCallback);
53 focusChangedEventHandler += value;
57 focusChangedEventHandler -= value;
59 if (focusChangedEventHandler == null && FocusChangedSignal().Empty() == false && focusChangedEventCallback != null)
61 FocusChangedSignal().Disconnect(focusChangedEventCallback);
67 /// Emits the event when the screen is touched and when the touch ends.<br />
68 /// If there are multiple touch points then it is emitted when the first touch occurs and
69 /// when the last finger is lifted too.<br />
70 /// Even though incoming events are interrupted, the event occurs.<br />
72 [EditorBrowsable(EditorBrowsableState.Never)]
73 public event EventHandler<TouchEventArgs> TouchEvent
77 if (windoTouchDataEventHandler == null)
79 windowTouchDataCallback = OnWindowTouch;
80 Interop.GLWindow.GlWindowTouchSignalConnect(SwigCPtr, windowTouchDataCallback.ToHandleRef(this));
81 NDalicPINVOKE.ThrowExceptionIfExists();
83 windoTouchDataEventHandler += value;
87 windoTouchDataEventHandler -= value;
88 if (windoTouchDataEventHandler == null && windowTouchDataCallback != null)
90 Interop.GLWindow.GlWindowTouchSignalDisconnect(SwigCPtr, windowTouchDataCallback.ToHandleRef(this));
91 NDalicPINVOKE.ThrowExceptionIfExists();
92 windowTouchDataCallback = null;
98 /// Emits the event when the key event is received.
100 [EditorBrowsable(EditorBrowsableState.Never)]
101 public event EventHandler<KeyEventArgs> KeyEvent
105 if (stageKeyHandler == null)
107 windowKeyCallbackDelegate = OnStageKey;
108 KeyEventSignal().Connect(windowKeyCallbackDelegate);
110 stageKeyHandler += value;
114 stageKeyHandler -= value;
115 if (stageKeyHandler == null && KeyEventSignal().Empty() == false)
117 KeyEventSignal().Disconnect(windowKeyCallbackDelegate);
123 /// Emits the event when the window resized.
125 [EditorBrowsable(EditorBrowsableState.Never)]
126 public event EventHandler<ResizedEventArgs> Resized
130 if (windowResizedEventHandler == null)
132 windowResizedEventCallback = OnResized;
133 GLWindowResizedSignal().Connect(windowResizedEventCallback);
136 windowResizedEventHandler += value;
140 windowResizedEventHandler -= value;
142 if (windowResizedEventHandler == null && GLWindowResizedSignal().Empty() == false && windowResizedEventCallback != null)
144 GLWindowResizedSignal().Disconnect(windowResizedEventCallback);
149 private event EventHandler<FocusChangedEventArgs> focusChangedEventHandler;
150 private event EventHandler<TouchEventArgs> windoTouchDataEventHandler;
151 private event EventHandler<KeyEventArgs> stageKeyHandler;
152 private event EventHandler<ResizedEventArgs> windowResizedEventHandler;
154 internal WindowFocusSignalType FocusChangedSignal()
156 WindowFocusSignalType ret = new WindowFocusSignalType(Interop.GLWindow.GlWindowFocusChangedSignal(SwigCPtr), false);
157 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161 internal KeyEventSignal KeyEventSignal()
163 KeyEventSignal ret = new KeyEventSignal(Interop.GLWindow.GlWindowKeyEventSignal(SwigCPtr), false);
164 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168 internal GLWindowResizedSignal GLWindowResizedSignal()
170 GLWindowResizedSignal ret = new GLWindowResizedSignal(Interop.GLWindow.GlWindowResizedSignal(SwigCPtr), false);
171 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
176 /// Disconnect all native signals
178 internal void DisconnectNativeSignals()
180 if (focusChangedEventCallback != null)
182 FocusChangedSignal().Disconnect(focusChangedEventCallback);
185 if (windowTouchDataCallback != null)
187 Interop.GLWindow.GlWindowTouchSignalDisconnect(SwigCPtr, windowTouchDataCallback.ToHandleRef(this));
188 NDalicPINVOKE.ThrowExceptionIfExists();
191 if (windowKeyCallbackDelegate != null)
193 KeyEventSignal().Disconnect(windowKeyCallbackDelegate);
196 if (windowResizedEventCallback != null)
198 GLWindowResizedSignal().Disconnect(windowResizedEventCallback);
202 private void OnWindowFocusedChanged(IntPtr window, bool focusGained)
204 if (window == IntPtr.Zero)
206 NUILog.Error("OnWindowFocusedChanged() Window is null! Do nothing!");
210 FocusChangedEventArgs e = new FocusChangedEventArgs();
212 e.FocusGained = focusGained;
214 if (focusChangedEventHandler != null)
216 focusChangedEventHandler(this, e);
220 private bool OnWindowTouch(IntPtr touchData)
222 if (touchData == global::System.IntPtr.Zero)
224 NUILog.Error("touchData should not be null!");
228 if (windoTouchDataEventHandler != null)
230 TouchEventArgs e = new TouchEventArgs();
231 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
232 windoTouchDataEventHandler(this, e);
237 // Callback for Stage KeyEventsignal
238 private void OnStageKey(IntPtr data)
240 if (stageKeyHandler != null)
242 KeyEventArgs e = new KeyEventArgs();
243 e.Key = Tizen.NUI.Key.GetKeyFromPtr(data);
244 //here we send all data to user event handlers
245 stageKeyHandler(this, e);
249 private void OnResized(IntPtr windowSize)
251 if (windowResizedEventHandler != null)
253 ResizedEventArgs e = new ResizedEventArgs();
254 // var val = new Uint16Pair(windowSize, false);
255 // e.WindowSize = new Size2D(val.GetWidth(), val.GetHeight());
258 // Workaround : windowSize should be valid pointer from dali,
259 // but currently it is fixed and is not Uint16Pair class.
260 // will be fixed later.
261 e.WindowSize = this.WindowSize;
262 windowResizedEventHandler(this, e);
267 /// The focus changed event argument.
269 [EditorBrowsable(EditorBrowsableState.Never)]
270 public class FocusChangedEventArgs : EventArgs
273 /// FocusGained flag.
275 [EditorBrowsable(EditorBrowsableState.Never)]
276 public bool FocusGained
284 /// The touch event argument.
286 [EditorBrowsable(EditorBrowsableState.Never)]
287 public class TouchEventArgs : EventArgs
294 [EditorBrowsable(EditorBrowsableState.Never)]
309 /// Key event arguments.
311 [EditorBrowsable(EditorBrowsableState.Never)]
312 public class KeyEventArgs : EventArgs
319 [EditorBrowsable(EditorBrowsableState.Never)]
334 /// Feeds a key event into the window.
335 /// This resized event arguments.
337 [EditorBrowsable(EditorBrowsableState.Never)]
338 public class ResizedEventArgs : EventArgs
343 /// This window size.
345 [EditorBrowsable(EditorBrowsableState.Never)]
346 public Size2D WindowSize
360 /// VisibilityChangedArgs
362 [EditorBrowsable(EditorBrowsableState.Never)]
363 public class VisibilityChangedEventArgs : EventArgs
365 private bool visibility;
369 [EditorBrowsable(EditorBrowsableState.Never)]
370 public bool Visibility
380 private void OnVisibilityChanged(IntPtr window, bool visibility)
382 if (window == global::System.IntPtr.Zero)
384 NUILog.Error("[ERR] OnVisibilityChanged() window is null");
388 VisibilityChangedEventArgs e = new VisibilityChangedEventArgs();
389 e.Visibility = visibility;
390 if (visibilityChangedEventHandler != null)
392 visibilityChangedEventHandler.Invoke(this, e);
396 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
397 private delegate void GLVisibilityChangedEventCallbackType(IntPtr window, bool visibility);
398 private GLVisibilityChangedEventCallbackType glVisibilityChangedEventCallback;
399 private event EventHandler<VisibilityChangedEventArgs> visibilityChangedEventHandler;
400 private GLWindowVisibilityChangedEvent glVisibilityChangedEventSignal;
405 [EditorBrowsable(EditorBrowsableState.Never)]
406 public event EventHandler<VisibilityChangedEventArgs> VisibilityChanged
410 if (visibilityChangedEventHandler == null)
412 glVisibilityChangedEventCallback = OnVisibilityChanged;
413 glVisibilityChangedEventSignal = new GLWindowVisibilityChangedEvent(this);
414 glVisibilityChangedEventSignal.Connect(glVisibilityChangedEventCallback);
416 visibilityChangedEventHandler += value;
420 visibilityChangedEventHandler -= value;
421 if (visibilityChangedEventHandler == null)
423 if (glVisibilityChangedEventSignal != null)
425 if (glVisibilityChangedEventSignal.Empty() == false)
427 glVisibilityChangedEventSignal.Disconnect(glVisibilityChangedEventCallback);
435 /// VisibiltyChangedSignalEmit
437 [EditorBrowsable(EditorBrowsableState.Never)]
438 public void VisibiltyChangedSignalEmit(bool visibility)
440 if (glVisibilityChangedEventSignal == null)
442 glVisibilityChangedEventSignal = new GLWindowVisibilityChangedEvent(this);
444 glVisibilityChangedEventSignal.Emit(this, visibility);