2 * Copyright(c) 2020 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.GlWindow_FocusChangedSignal(swigCPtr), false);
154 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158 internal KeyEventSignal KeyEventSignal()
160 KeyEventSignal ret = new KeyEventSignal(Interop.GLWindow.GlWindow_KeyEventSignal(swigCPtr), false);
161 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
165 internal TouchSignal TouchSignal()
167 TouchSignal ret = new TouchSignal(Interop.GLWindow.GlWindow_TouchSignal(swigCPtr), false);
168 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172 internal GLWindowResizedSignal GLWindowResizedSignal()
174 GLWindowResizedSignal ret = new GLWindowResizedSignal(Interop.GLWindow.GlWindow_ResizedSignal(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 TouchEventArgs e = new TouchEventArgs();
233 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
235 if (_windoTouchDataEventHandler != null)
237 _windoTouchDataEventHandler(this, e);
242 // Callback for Stage KeyEventsignal
243 private void OnStageKey(IntPtr data)
245 KeyEventArgs e = new KeyEventArgs();
246 e.Key = Tizen.NUI.Key.GetKeyFromPtr(data);
249 if (_stageKeyHandler != null)
251 //here we send all data to user event handlers
252 _stageKeyHandler(this, e);
256 private void OnResized(IntPtr windowSize)
258 ResizedEventArgs e = new ResizedEventArgs();
259 // var val = new Uint16Pair(windowSize, false);
260 // e.WindowSize = new Size2D(val.GetWidth(), val.GetHeight());
263 // Workaround : windowSize should be valid pointer from dali,
264 // but currenlty it is fixed and is not Uint16Pair class.
265 // will be fixed later.
266 e.WindowSize = this.WindowSize;
268 if (_windowResizedEventHandler != null)
270 _windowResizedEventHandler(this, e);
275 /// The focus changed event argument.
277 [EditorBrowsable(EditorBrowsableState.Never)]
278 public class FocusChangedEventArgs : EventArgs
281 /// FocusGained flag.
283 [EditorBrowsable(EditorBrowsableState.Never)]
284 public bool FocusGained
292 /// The touch event argument.
294 [EditorBrowsable(EditorBrowsableState.Never)]
295 public class TouchEventArgs : EventArgs
297 private Touch _touch;
302 [EditorBrowsable(EditorBrowsableState.Never)]
317 /// Key event arguments.
319 [EditorBrowsable(EditorBrowsableState.Never)]
320 public class KeyEventArgs : EventArgs
327 [EditorBrowsable(EditorBrowsableState.Never)]
342 /// Feeds a key event into the window.
343 /// This resized event arguments.
345 [EditorBrowsable(EditorBrowsableState.Never)]
346 public class ResizedEventArgs : EventArgs
351 /// This window size.
353 [EditorBrowsable(EditorBrowsableState.Never)]
354 public Size2D WindowSize
368 /// VisibilityChangedArgs
370 [EditorBrowsable(EditorBrowsableState.Never)]
371 public class VisibilityChangedArgs : EventArgs
373 private bool _visibility;
377 [EditorBrowsable(EditorBrowsableState.Never)]
378 public bool Visibility
387 private void OnVisibilityChanged(IntPtr window, bool visibility)
389 if (window == global::System.IntPtr.Zero)
391 NUILog.Error("[ERR] OnVisibilityChanged() window is null");
395 VisibilityChangedArgs e = new VisibilityChangedArgs();
396 e.Visibility = visibility;
397 if (VisibilityChangedEventHandler != null)
399 VisibilityChangedEventHandler.Invoke(this, e);
403 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
404 private delegate void GLVisibilityChangedEventCallbackType(IntPtr window, bool visibility);
405 private GLVisibilityChangedEventCallbackType _GLVisibilityChangedEventCallback;
406 private event EventHandler<VisibilityChangedArgs> VisibilityChangedEventHandler;
407 private GLWindowVisibilityChangedEvent _GLVisibilityChangedEventSignal;
412 [EditorBrowsable(EditorBrowsableState.Never)]
413 public event EventHandler<VisibilityChangedArgs> VisibilityChanged
417 if (VisibilityChangedEventHandler == null)
419 _GLVisibilityChangedEventCallback = OnVisibilityChanged;
420 _GLVisibilityChangedEventSignal = new GLWindowVisibilityChangedEvent(this);
421 _GLVisibilityChangedEventSignal.Connect(_GLVisibilityChangedEventCallback);
423 VisibilityChangedEventHandler += value;
427 VisibilityChangedEventHandler -= value;
428 if (VisibilityChangedEventHandler == null)
430 if(_GLVisibilityChangedEventSignal != null)
432 if(_GLVisibilityChangedEventSignal.Empty() == false)
434 _GLVisibilityChangedEventSignal.Disconnect(_GLVisibilityChangedEventCallback);
442 /// VisibiltyChangedSignalEmit
444 [EditorBrowsable(EditorBrowsableState.Never)]
445 public void VisibiltyChangedSignalEmit(bool visibility)
447 if(_GLVisibilityChangedEventSignal == null)
449 _GLVisibilityChangedEventSignal = new GLWindowVisibilityChangedEvent(this);
451 _GLVisibilityChangedEventSignal.Emit(this, visibility);