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 this.TouchSignal().Connect(windowTouchDataCallback);
82 windoTouchDataEventHandler += value;
86 windoTouchDataEventHandler -= value;
87 if (windoTouchDataEventHandler == null && TouchSignal().Empty() == false && windowTouchDataCallback != null)
89 this.TouchSignal().Disconnect(windowTouchDataCallback);
95 /// Emits the event when the key event is received.
97 [EditorBrowsable(EditorBrowsableState.Never)]
98 public event EventHandler<KeyEventArgs> KeyEvent
102 if (stageKeyHandler == null)
104 windowKeyCallbackDelegate = OnStageKey;
105 KeyEventSignal().Connect(windowKeyCallbackDelegate);
107 stageKeyHandler += value;
111 stageKeyHandler -= value;
112 if (stageKeyHandler == null && KeyEventSignal().Empty() == false)
114 KeyEventSignal().Disconnect(windowKeyCallbackDelegate);
120 /// Emits the event when the window resized.
122 [EditorBrowsable(EditorBrowsableState.Never)]
123 public event EventHandler<ResizedEventArgs> Resized
127 if (windowResizedEventHandler == null)
129 windowResizedEventCallback = OnResized;
130 GLWindowResizedSignal().Connect(windowResizedEventCallback);
133 windowResizedEventHandler += value;
137 windowResizedEventHandler -= value;
139 if (windowResizedEventHandler == null && GLWindowResizedSignal().Empty() == false && windowResizedEventCallback != null)
141 GLWindowResizedSignal().Disconnect(windowResizedEventCallback);
146 private event EventHandler<FocusChangedEventArgs> focusChangedEventHandler;
147 private event EventHandler<TouchEventArgs> windoTouchDataEventHandler;
148 private event EventHandler<KeyEventArgs> stageKeyHandler;
149 private event EventHandler<ResizedEventArgs> windowResizedEventHandler;
151 internal WindowFocusSignalType FocusChangedSignal()
153 WindowFocusSignalType ret = new WindowFocusSignalType(Interop.GLWindow.GlWindowFocusChangedSignal(SwigCPtr), false);
154 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158 internal KeyEventSignal KeyEventSignal()
160 KeyEventSignal ret = new KeyEventSignal(Interop.GLWindow.GlWindowKeyEventSignal(SwigCPtr), false);
161 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
165 internal TouchSignal TouchSignal()
167 TouchSignal ret = new TouchSignal(Interop.GLWindow.GlWindowTouchSignal(SwigCPtr), false);
168 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172 internal GLWindowResizedSignal GLWindowResizedSignal()
174 GLWindowResizedSignal ret = new GLWindowResizedSignal(Interop.GLWindow.GlWindowResizedSignal(SwigCPtr), false);
175 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180 /// Disconnect all native signals
182 internal void DisconnectNativeSignals()
184 if (focusChangedEventCallback != null)
186 FocusChangedSignal().Disconnect(focusChangedEventCallback);
189 if (windowTouchDataCallback != null)
191 TouchSignal().Disconnect(windowTouchDataCallback);
194 if (windowKeyCallbackDelegate != null)
196 KeyEventSignal().Disconnect(windowKeyCallbackDelegate);
199 if (windowResizedEventCallback != null)
201 GLWindowResizedSignal().Disconnect(windowResizedEventCallback);
205 private void OnWindowFocusedChanged(IntPtr window, bool focusGained)
207 if (window == IntPtr.Zero)
209 NUILog.Error("OnWindowFocusedChanged() Window is null! Do nothing!");
213 FocusChangedEventArgs e = new FocusChangedEventArgs();
215 e.FocusGained = focusGained;
217 if (focusChangedEventHandler != null)
219 focusChangedEventHandler(this, e);
223 private bool OnWindowTouch(IntPtr touchData)
225 if (touchData == global::System.IntPtr.Zero)
227 NUILog.Error("touchData should not be null!");
231 if (windoTouchDataEventHandler != null)
233 TouchEventArgs e = new TouchEventArgs();
234 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
235 windoTouchDataEventHandler(this, e);
240 // Callback for Stage KeyEventsignal
241 private void OnStageKey(IntPtr data)
243 if (stageKeyHandler != null)
245 KeyEventArgs e = new KeyEventArgs();
246 e.Key = Tizen.NUI.Key.GetKeyFromPtr(data);
247 //here we send all data to user event handlers
248 stageKeyHandler(this, e);
252 private void OnResized(IntPtr windowSize)
254 if (windowResizedEventHandler != null)
256 ResizedEventArgs e = new ResizedEventArgs();
257 // var val = new Uint16Pair(windowSize, false);
258 // e.WindowSize = new Size2D(val.GetWidth(), val.GetHeight());
261 // Workaround : windowSize should be valid pointer from dali,
262 // but currently it is fixed and is not Uint16Pair class.
263 // will be fixed later.
264 e.WindowSize = this.WindowSize;
265 windowResizedEventHandler(this, e);
270 /// The focus changed event argument.
272 [EditorBrowsable(EditorBrowsableState.Never)]
273 public class FocusChangedEventArgs : EventArgs
276 /// FocusGained flag.
278 [EditorBrowsable(EditorBrowsableState.Never)]
279 public bool FocusGained
287 /// The touch event argument.
289 [EditorBrowsable(EditorBrowsableState.Never)]
290 public class TouchEventArgs : EventArgs
297 [EditorBrowsable(EditorBrowsableState.Never)]
312 /// Key event arguments.
314 [EditorBrowsable(EditorBrowsableState.Never)]
315 public class KeyEventArgs : EventArgs
322 [EditorBrowsable(EditorBrowsableState.Never)]
337 /// Feeds a key event into the window.
338 /// This resized event arguments.
340 [EditorBrowsable(EditorBrowsableState.Never)]
341 public class ResizedEventArgs : EventArgs
346 /// This window size.
348 [EditorBrowsable(EditorBrowsableState.Never)]
349 public Size2D WindowSize
363 /// VisibilityChangedArgs
365 [EditorBrowsable(EditorBrowsableState.Never)]
366 public class VisibilityChangedEventArgs : EventArgs
368 private bool visibility;
372 [EditorBrowsable(EditorBrowsableState.Never)]
373 public bool Visibility
383 private void OnVisibilityChanged(IntPtr window, bool visibility)
385 if (window == global::System.IntPtr.Zero)
387 NUILog.Error("[ERR] OnVisibilityChanged() window is null");
391 VisibilityChangedEventArgs e = new VisibilityChangedEventArgs();
392 e.Visibility = visibility;
393 if (visibilityChangedEventHandler != null)
395 visibilityChangedEventHandler.Invoke(this, e);
399 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
400 private delegate void GLVisibilityChangedEventCallbackType(IntPtr window, bool visibility);
401 private GLVisibilityChangedEventCallbackType glVisibilityChangedEventCallback;
402 private event EventHandler<VisibilityChangedEventArgs> visibilityChangedEventHandler;
403 private GLWindowVisibilityChangedEvent glVisibilityChangedEventSignal;
408 [EditorBrowsable(EditorBrowsableState.Never)]
409 public event EventHandler<VisibilityChangedEventArgs> VisibilityChanged
413 if (visibilityChangedEventHandler == null)
415 glVisibilityChangedEventCallback = OnVisibilityChanged;
416 glVisibilityChangedEventSignal = new GLWindowVisibilityChangedEvent(this);
417 glVisibilityChangedEventSignal.Connect(glVisibilityChangedEventCallback);
419 visibilityChangedEventHandler += value;
423 visibilityChangedEventHandler -= value;
424 if (visibilityChangedEventHandler == null)
426 if (glVisibilityChangedEventSignal != null)
428 if (glVisibilityChangedEventSignal.Empty() == false)
430 glVisibilityChangedEventSignal.Disconnect(glVisibilityChangedEventCallback);
438 /// VisibiltyChangedSignalEmit
440 [EditorBrowsable(EditorBrowsableState.Never)]
441 public void VisibiltyChangedSignalEmit(bool visibility)
443 if (glVisibilityChangedEventSignal == null)
445 glVisibilityChangedEventSignal = new GLWindowVisibilityChangedEvent(this);
447 glVisibilityChangedEventSignal.Emit(this, visibility);