Merge "[NUI] Fix WidgetView dispose issue"
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Window.cs
1 /*
2  * Copyright(c) 2017 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 using System;
18 using System.Runtime.InteropServices;
19 using Tizen.NUI.BaseComponents;
20 using System.ComponentModel;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// The window class is used internally for drawing.<br />
26     /// The window has an orientation and indicator properties.<br />
27     /// </summary>
28     public class Window : BaseHandle
29     {
30         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
31         private global::System.Runtime.InteropServices.HandleRef stageCPtr;
32         private Layer _rootLayer;
33         private string _windowTitle;
34
35         internal Window(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Window_SWIGUpcast(cPtr), cMemoryOwn)
36         {
37             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
38             if (NDalicPINVOKE.Stage_IsInstalled())
39             {
40                 stageCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.Stage_GetCurrent());
41             }
42         }
43
44         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Window obj)
45         {
46             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
47         }
48
49         /// <summary>
50         /// To make the window instance be disposed.
51         /// </summary>
52         /// Please DO NOT use! This will be deprecated!
53         /// Dispose() method in Singletone classes (ex: FocusManager, StyleManager, VisualFactory, IMFManager, TtsPlayer, Window) is not required.
54         /// Because it is Sigletone, so it is alive for one thread until the NUI is terminated, so it never be disposed.
55         [EditorBrowsable(EditorBrowsableState.Never)]
56         protected override void Dispose(DisposeTypes type)
57         {
58             if (disposed)
59             {
60                 return;
61             }
62
63             if (type == DisposeTypes.Explicit)
64             {
65                 //Called by User
66                 //Release your own managed resources here.
67                 //You should release all of your own disposable objects here.
68             }
69
70             //Release your own unmanaged resources here.
71             //You should not access any managed member here except static instance.
72             //because the execution order of Finalizes is non-deterministic.
73
74             if (_windowFocusChangedEventCallback != null)
75             {
76                 WindowFocusChangedSignal().Disconnect(_windowFocusChangedEventCallback);
77             }
78
79             if (_stageTouchCallbackDelegate != null)
80             {
81                 TouchSignal().Disconnect(_stageTouchCallbackDelegate);
82             }
83
84             if (_stageWheelCallbackDelegate != null)
85             {
86                 WheelEventSignal().Disconnect(_stageWheelCallbackDelegate);
87             }
88
89             if (_stageKeyCallbackDelegate != null)
90             {
91                 KeyEventSignal().Disconnect(_stageKeyCallbackDelegate);
92             }
93
94             if (_stageEventProcessingFinishedEventCallbackDelegate != null)
95             {
96                 EventProcessingFinishedSignal().Disconnect(_stageEventProcessingFinishedEventCallbackDelegate);
97             }
98
99             if (_stageContextLostEventCallbackDelegate != null)
100             {
101                 ContextLostSignal().Disconnect(_stageContextLostEventCallbackDelegate);
102             }
103
104             if (_stageContextRegainedEventCallbackDelegate != null)
105             {
106                 this.ContextRegainedSignal().Disconnect(_stageContextRegainedEventCallbackDelegate);
107             }
108
109             if (_stageSceneCreatedEventCallbackDelegate != null)
110             {
111                 SceneCreatedSignal().Disconnect(_stageSceneCreatedEventCallbackDelegate);
112             }
113
114             if (_windowResizedEventCallback != null)
115             {
116                 ResizedSignal().Disconnect(_windowResizedEventCallback);
117             }
118
119             if (_windowFocusChangedEventCallback2 != null)
120             {
121                 WindowFocusChangedSignal().Disconnect(_windowFocusChangedEventCallback2);
122             }
123
124             if (swigCPtr.Handle != global::System.IntPtr.Zero)
125             {
126                 if (swigCMemOwn)
127                 {
128                     swigCMemOwn = false;
129                     NDalicPINVOKE.delete_Window(swigCPtr);
130                     NDalicPINVOKE.delete_Stage(stageCPtr);
131                 }
132                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
133             }
134
135             base.Dispose(type);
136         }
137
138         internal static Window GetCurrent()
139         {
140             Window ret = new Window(NDalicPINVOKE.Stage_GetCurrent(), true);
141             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
142             return ret;
143         }
144
145         internal static bool IsInstalled()
146         {
147             bool ret = NDalicPINVOKE.Stage_IsInstalled();
148             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
149             return ret;
150         }
151
152         /// <summary>
153         /// Sets whether the window accepts a focus or not.
154         /// </summary>
155         /// <param name="accept">If a focus is accepted or not. The default is true.</param>
156         /// <since_tizen> 3 </since_tizen>
157         public void SetAcceptFocus(bool accept)
158         {
159             NDalicPINVOKE.SetAcceptFocus(swigCPtr, accept);
160             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161         }
162
163         /// <summary>
164         /// Returns whether the window accepts a focus or not.
165         /// </summary>
166         /// <returns>True if the window accepts a focus, false otherwise.</returns>
167         /// <since_tizen> 3 </since_tizen>
168         public bool IsFocusAcceptable()
169         {
170             bool ret = NDalicPINVOKE.IsFocusAcceptable(swigCPtr);
171             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172
173             return ret;
174         }
175
176         /// <summary>
177         /// Shows the window if it is hidden.
178         /// </summary>
179         /// <since_tizen> 3 </since_tizen>
180         public void Show()
181         {
182             NDalicPINVOKE.Show(swigCPtr);
183             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184         }
185
186         /// <summary>
187         /// Hides the window if it is showing.
188         /// </summary>
189         /// <since_tizen> 3 </since_tizen>
190         public void Hide()
191         {
192             NDalicPINVOKE.Hide(swigCPtr);
193             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194         }
195
196         /// <summary>
197         /// Retrieves whether the window is visible or not.
198         /// </summary>
199         /// <returns>True if the window is visible.</returns>
200         /// <since_tizen> 3 </since_tizen>
201         public bool IsVisible()
202         {
203             bool temp = NDalicPINVOKE.IsVisible(swigCPtr);
204             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
205             return temp;
206         }
207
208         /// <summary>
209         /// Gets the count of supported auxiliary hints of the window.
210         /// </summary>
211         /// <returns>The number of supported auxiliary hints.</returns>
212         /// <since_tizen> 3 </since_tizen>
213         public uint GetSupportedAuxiliaryHintCount()
214         {
215             uint ret = NDalicPINVOKE.GetSupportedAuxiliaryHintCount(swigCPtr);
216             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217             return ret;
218         }
219
220         /// <summary>
221         /// Gets the supported auxiliary hint string of the window.
222         /// </summary>
223         /// <param name="index">The index of the supported auxiliary hint lists.</param>
224         /// <returns>The auxiliary hint string of the index.</returns>
225         /// <since_tizen> 3 </since_tizen>
226         public string GetSupportedAuxiliaryHint(uint index)
227         {
228             string ret = NDalicPINVOKE.GetSupportedAuxiliaryHint(swigCPtr, index);
229             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230             return ret;
231         }
232
233         /// <summary>
234         /// Creates an auxiliary hint of the window.
235         /// </summary>
236         /// <param name="hint">The auxiliary hint string.</param>
237         /// <param name="value">The value string.</param>
238         /// <returns>The ID of created auxiliary hint, or 0 on failure.</returns>
239         /// <since_tizen> 3 </since_tizen>
240         public uint AddAuxiliaryHint(string hint, string value)
241         {
242             uint ret = NDalicPINVOKE.AddAuxiliaryHint(swigCPtr, hint, value);
243             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244             return ret;
245         }
246
247         /// <summary>
248         /// Removes an auxiliary hint of the window.
249         /// </summary>
250         /// <param name="id">The ID of the auxiliary hint.</param>
251         /// <returns>True if no error occurred, false otherwise.</returns>
252         /// <since_tizen> 3 </since_tizen>
253         public bool RemoveAuxiliaryHint(uint id)
254         {
255             bool ret = NDalicPINVOKE.RemoveAuxiliaryHint(swigCPtr, id);
256             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257             return ret;
258         }
259
260         /// <summary>
261         /// Changes a value of the auxiliary hint.
262         /// </summary>
263         /// <param name="id">The auxiliary hint ID.</param>
264         /// <param name="value">The value string to be set.</param>
265         /// <returns>True if no error occurred, false otherwise.</returns>
266         /// <since_tizen> 3 </since_tizen>
267         public bool SetAuxiliaryHintValue(uint id, string value)
268         {
269             bool ret = NDalicPINVOKE.SetAuxiliaryHintValue(swigCPtr, id, value);
270             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271             return ret;
272         }
273
274         /// <summary>
275         /// Gets a value of the auxiliary hint.
276         /// </summary>
277         /// <param name="id">The auxiliary hint ID.</param>
278         /// <returns>The string value of the auxiliary hint ID, or an empty string if none exists.</returns>
279         /// <since_tizen> 3 </since_tizen>
280         public string GetAuxiliaryHintValue(uint id)
281         {
282             string ret = NDalicPINVOKE.GetAuxiliaryHintValue(swigCPtr, id);
283             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284             return ret;
285         }
286
287         /// <summary>
288         /// Gets an ID of the auxiliary hint string.
289         /// </summary>
290         /// <param name="hint">The auxiliary hint string.</param>
291         /// <returns>The ID of auxiliary hint string, or 0 on failure.</returns>
292         /// <since_tizen> 3 </since_tizen>
293         public uint GetAuxiliaryHintId(string hint)
294         {
295             uint ret = NDalicPINVOKE.GetAuxiliaryHintId(swigCPtr, hint);
296             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297             return ret;
298         }
299
300         /// <summary>
301         /// Sets a region to accept input events.
302         /// </summary>
303         /// <param name="inputRegion">The region to accept input events.</param>
304         /// <since_tizen> 3 </since_tizen>
305         public void SetInputRegion(Rectangle inputRegion)
306         {
307             NDalicPINVOKE.SetInputRegion(swigCPtr, Rectangle.getCPtr(inputRegion));
308             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309         }
310
311         /// <summary>
312         /// Gets or sets a window type.
313         /// </summary>
314         /// <since_tizen> 3 </since_tizen>
315         public WindowType Type
316         {
317             get
318             {
319                 WindowType ret = (WindowType)NDalicPINVOKE.GetType(swigCPtr);
320                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
321                 return ret;
322             }
323             set
324             {
325                 NDalicPINVOKE.SetType(swigCPtr, (int)value);
326                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
327             }
328         }
329
330         /// <summary>
331         /// Sets a priority level for the specified notification window.
332         /// </summary>
333         /// <param name="level">The notification window level.</param>
334         /// <returns>True if no error occurred, false otherwise.</returns>
335         /// <since_tizen> 3 </since_tizen>
336         public bool SetNotificationLevel(NotificationLevel level)
337         {
338             bool ret = NDalicPINVOKE.SetNotificationLevel(swigCPtr, (int)level);
339             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340             return ret;
341         }
342
343         /// <summary>
344         /// Gets a priority level for the specified notification window.
345         /// </summary>
346         /// <returns>The notification window level.</returns>
347         /// <since_tizen> 3 </since_tizen>
348         public NotificationLevel GetNotificationLevel()
349         {
350             NotificationLevel ret = (NotificationLevel)NDalicPINVOKE.GetNotificationLevel(swigCPtr);
351             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352             return ret;
353         }
354
355         /// <summary>
356         /// Sets a transparent window's visual state to opaque.
357         /// </summary>
358         /// <param name="opaque">Whether the window's visual state is opaque.</param>
359         /// <since_tizen> 3 </since_tizen>
360         public void SetOpaqueState(bool opaque)
361         {
362             NDalicPINVOKE.SetOpaqueState(swigCPtr, opaque);
363             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364         }
365
366         /// <summary>
367         /// Returns whether a transparent window's visual state is opaque or not.
368         /// </summary>
369         /// <returns>True if the window's visual state is opaque, false otherwise.</returns>
370         /// <since_tizen> 3 </since_tizen>
371         public bool IsOpaqueState()
372         {
373             bool ret = NDalicPINVOKE.IsOpaqueState(swigCPtr);
374             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
375             return ret;
376         }
377
378         /// <summary>
379         /// Sets a window's screen off mode.
380         /// </summary>
381         /// <param name="screenOffMode">The screen mode.</param>
382         /// <returns>True if no error occurred, false otherwise.</returns>
383         /// <since_tizen> 3 </since_tizen>
384         public bool SetScreenOffMode(ScreenOffMode screenOffMode)
385         {
386             bool ret = NDalicPINVOKE.SetScreenOffMode(swigCPtr, (int)screenOffMode);
387             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
388             return ret;
389         }
390
391         /// <summary>
392         /// Gets the screen mode of the window.
393         /// </summary>
394         /// <returns>The screen off mode.</returns>
395         /// <since_tizen> 3 </since_tizen>
396         public ScreenOffMode GetScreenOffMode()
397         {
398             ScreenOffMode ret = (ScreenOffMode)NDalicPINVOKE.GetScreenOffMode(swigCPtr);
399             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400             return ret;
401         }
402
403         /// <summary>
404         /// Sets preferred brightness of the window.
405         /// </summary>
406         /// <param name="brightness">The preferred brightness (0 to 100).</param>
407         /// <returns>True if no error occurred, false otherwise.</returns>
408         /// <since_tizen> 3 </since_tizen>
409         public bool SetBrightness(int brightness)
410         {
411             bool ret = NDalicPINVOKE.SetBrightness(swigCPtr, brightness);
412             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
413             return ret;
414         }
415
416         /// <summary>
417         /// Gets the preferred brightness of the window.
418         /// </summary>
419         /// <returns>The preferred brightness.</returns>
420         /// <since_tizen> 3 </since_tizen>
421         public int GetBrightness()
422         {
423             int ret = NDalicPINVOKE.GetBrightness(swigCPtr);
424             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
425             return ret;
426         }
427
428         /// <summary>
429         /// The focus changed event argument.
430         /// </summary>
431         public class FocusChangedEventArgs : EventArgs
432         {
433             /// <summary>
434             /// FocusGained flag.
435             /// </summary>
436             /// <since_tizen> 3 </since_tizen>
437             public bool FocusGained
438             {
439                 get;
440                 set;
441             }
442         }
443
444         private WindowFocusChangedEventCallbackType _windowFocusChangedEventCallback;
445         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
446         private delegate void WindowFocusChangedEventCallbackType(bool focusGained);
447         private event EventHandler<FocusChangedEventArgs> _windowFocusChangedEventHandler;
448
449         /// <summary>
450         /// FocusChanged event.
451         /// </summary>
452         /// <since_tizen> 4 </since_tizen>
453         public event EventHandler<FocusChangedEventArgs> FocusChanged
454         {
455             add
456             {
457                 if (_windowFocusChangedEventHandler == null)
458                 {
459                     _windowFocusChangedEventCallback = OnWindowFocusedChanged;
460                     WindowFocusChangedSignal().Connect(_windowFocusChangedEventCallback);
461                 }
462
463                 _windowFocusChangedEventHandler += value;
464             }
465             remove
466             {
467                 _windowFocusChangedEventHandler -= value;
468
469                 if (_windowFocusChangedEventHandler == null && WindowFocusChangedSignal().Empty() == false && _windowFocusChangedEventCallback != null)
470                 {
471                     WindowFocusChangedSignal().Disconnect(_windowFocusChangedEventCallback);
472                 }
473             }
474         }
475
476         private void OnWindowFocusedChanged(bool focusGained)
477         {
478             FocusChangedEventArgs e = new FocusChangedEventArgs();
479
480             e.FocusGained = focusGained;
481
482             if (_windowFocusChangedEventHandler != null)
483             {
484                 _windowFocusChangedEventHandler(this, e);
485             }
486         }
487
488         /// <summary>
489         /// Gets/Sets a window title.
490         /// </summary>
491         /// <since_tizen> 4 </since_tizen>
492         public string Title
493         {
494             get
495             {
496                 return _windowTitle;
497             }
498             set
499             {
500                 _windowTitle = value;
501                 SetClass(_windowTitle, "");
502             }
503         }
504
505         internal WindowFocusSignalType WindowFocusChangedSignal()
506         {
507             WindowFocusSignalType ret = new WindowFocusSignalType(NDalicPINVOKE.FocusChangedSignal(swigCPtr), false);
508             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
509             return ret;
510         }
511
512         internal Window(Rectangle windowPosition, string name, bool isTransparent) : this(NDalicPINVOKE.Window_New__SWIG_0(Rectangle.getCPtr(windowPosition), name, isTransparent), true)
513         {
514             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
515         }
516
517         internal Window(Rectangle windowPosition, string name) : this(NDalicPINVOKE.Window_New__SWIG_1(Rectangle.getCPtr(windowPosition), name), true)
518         {
519             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
520         }
521
522         internal Window(Rectangle windowPosition, string name, string className, bool isTransparent) : this(NDalicPINVOKE.Window_New__SWIG_2(Rectangle.getCPtr(windowPosition), name, className, isTransparent), true)
523         {
524             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
525         }
526
527         internal Window(Rectangle windowPosition, string name, string className) : this(NDalicPINVOKE.Window_New__SWIG_3(Rectangle.getCPtr(windowPosition), name, className), true)
528         {
529             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
530         }
531
532         internal void ShowIndicator(Window.IndicatorVisibleMode visibleMode)
533         {
534             NDalicPINVOKE.Window_ShowIndicator(swigCPtr, (int)visibleMode);
535             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
536         }
537
538         internal void SetIndicatorBackgroundOpacity(Window.IndicatorBackgroundOpacity opacity)
539         {
540             NDalicPINVOKE.Window_SetIndicatorBgOpacity(swigCPtr, (int)opacity);
541             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
542         }
543
544         internal void RotateIndicator(Window.WindowOrientation orientation)
545         {
546             NDalicPINVOKE.Window_RotateIndicator(swigCPtr, (int)orientation);
547             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
548         }
549
550         /// <summary>
551         /// Sets the window name and the class string.
552         /// </summary>
553         /// <param name="name">The name of the window.</param>
554         /// <param name="klass">The class of the window.</param>
555         /// <since_tizen> 4 </since_tizen>
556         public void SetClass(string name, string klass)
557         {
558             NDalicPINVOKE.Window_SetClass(swigCPtr, name, klass);
559             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
560         }
561
562         /// <summary>
563         /// Raises the window to the top of the window stack.
564         /// </summary>
565         /// <since_tizen> 3 </since_tizen>
566         public void Raise()
567         {
568             NDalicPINVOKE.Window_Raise(swigCPtr);
569             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
570         }
571
572         /// <summary>
573         /// Lowers the window to the bottom of the window stack.
574         /// </summary>
575         /// <since_tizen> 3 </since_tizen>
576         public void Lower()
577         {
578             NDalicPINVOKE.Window_Lower(swigCPtr);
579             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
580         }
581
582         /// <summary>
583         /// Activates the window to the top of the window stack even it is iconified.
584         /// </summary>
585         /// <since_tizen> 3 </since_tizen>
586         public void Activate()
587         {
588             NDalicPINVOKE.Window_Activate(swigCPtr);
589             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
590         }
591
592         internal void AddAvailableOrientation(Window.WindowOrientation orientation)
593         {
594             NDalicPINVOKE.Window_AddAvailableOrientation(swigCPtr, (int)orientation);
595             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
596         }
597
598         internal void RemoveAvailableOrientation(Window.WindowOrientation orientation)
599         {
600             NDalicPINVOKE.Window_RemoveAvailableOrientation(swigCPtr, (int)orientation);
601             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
602         }
603
604         internal void SetPreferredOrientation(Window.WindowOrientation orientation)
605         {
606             NDalicPINVOKE.Window_SetPreferredOrientation(swigCPtr, (int)orientation);
607             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
608         }
609
610         internal Window.WindowOrientation GetPreferredOrientation()
611         {
612             Window.WindowOrientation ret = (Window.WindowOrientation)NDalicPINVOKE.Window_GetPreferredOrientation(swigCPtr);
613             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
614             return ret;
615         }
616
617         internal DragAndDropDetector GetDragAndDropDetector()
618         {
619             DragAndDropDetector ret = new DragAndDropDetector(NDalicPINVOKE.Window_GetDragAndDropDetector(swigCPtr), true);
620             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
621             return ret;
622         }
623
624         internal Any GetNativeHandle()
625         {
626             Any ret = new Any(NDalicPINVOKE.Window_GetNativeHandle(swigCPtr), true);
627             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
628             return ret;
629         }
630
631         internal WindowFocusSignalType FocusChangedSignal()
632         {
633             WindowFocusSignalType ret = new WindowFocusSignalType(NDalicPINVOKE.FocusChangedSignal(swigCPtr), false);
634             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
635             return ret;
636         }
637
638         /// <summary>
639         /// Gets the default ( root ) layer.
640         /// </summary>
641         /// <returns>The root layer.</returns>
642         /// <since_tizen> 3 </since_tizen>
643         public Layer GetDefaultLayer()
644         {
645             return this.GetRootLayer();
646         }
647
648         internal void Add(Layer layer)
649         {
650             NDalicPINVOKE.Stage_Add(stageCPtr, Layer.getCPtr(layer));
651             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
652         }
653
654         internal void Remove(Layer layer)
655         {
656             NDalicPINVOKE.Stage_Remove(stageCPtr, Layer.getCPtr(layer));
657             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
658         }
659
660         /// <summary>
661         /// Add a child view to window.
662         /// </summary>
663         /// <param name="view">the child should be added to the window.</param>
664         /// <since_tizen> 3 </since_tizen>
665         public void Add(View view)
666         {
667             GetRootLayer()?.Add(view);
668         }
669
670         /// <summary>
671         /// Remove a child view from window.
672         /// </summary>
673         /// <param name="view">the child to be removed.</param>
674         /// <since_tizen> 3 </since_tizen>
675         public void Remove(View view)
676         {
677             GetRootLayer()?.Remove(view);
678         }
679
680         internal Vector2 GetSize()
681         {
682             Vector2 ret = new Vector2(NDalicPINVOKE.Stage_GetSize(stageCPtr), true);
683             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
684             return ret;
685         }
686
687         internal RenderTaskList GetRenderTaskList()
688         {
689             RenderTaskList ret = new RenderTaskList(NDalicPINVOKE.Stage_GetRenderTaskList(stageCPtr), true);
690             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
691             return ret;
692         }
693
694         /// <summary>
695         /// Queries the number of on-window layers.
696         /// </summary>
697         /// <returns>The number of layers.</returns>
698         /// <remarks>Note that a default layer is always provided (count >= 1).</remarks>
699         internal uint GetLayerCount()
700         {
701             uint ret = NDalicPINVOKE.Stage_GetLayerCount(stageCPtr);
702             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
703             return ret;
704         }
705
706         /// <summary>
707         /// Retrieves the layer at a specified depth.
708         /// </summary>
709         /// <param name="depth">The layer's depth index.</param>
710         /// <returns>The layer found at the given depth.</returns>
711         /// <since_tizen> 3 </since_tizen>
712         public Layer GetLayer(uint depth)
713         {
714             IntPtr cPtr = NDalicPINVOKE.Stage_GetLayer(stageCPtr, depth);
715             Layer ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Layer;
716
717             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
718             return ret;
719         }
720
721         internal Layer GetRootLayer()
722         {
723             // Window.IsInstalled() is actually true only when called from event thread and
724             // Core has been initialized, not when Stage is ready.
725             if (_rootLayer == null && Window.IsInstalled())
726             {
727                 _rootLayer = new Layer(NDalicPINVOKE.Stage_GetRootLayer(stageCPtr), true);
728                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
729             }
730             return _rootLayer;
731         }
732
733         internal void SetBackgroundColor(Vector4 color)
734         {
735             NDalicPINVOKE.Stage_SetBackgroundColor(stageCPtr, Vector4.getCPtr(color));
736             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
737         }
738
739         internal Vector4 GetBackgroundColor()
740         {
741             Vector4 ret = new Vector4(NDalicPINVOKE.Stage_GetBackgroundColor(stageCPtr), true);
742             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
743             return ret;
744         }
745
746         internal Vector2 GetDpi()
747         {
748             Vector2 ret = new Vector2(NDalicPINVOKE.Stage_GetDpi(stageCPtr), true);
749             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
750             return ret;
751         }
752
753         internal ObjectRegistry GetObjectRegistry()
754         {
755             ObjectRegistry ret = new ObjectRegistry(NDalicPINVOKE.Stage_GetObjectRegistry(stageCPtr), true);
756             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
757             return ret;
758         }
759
760         /// <summary>
761         /// Keep rendering for at least the given amount of time.
762         /// </summary>
763         /// <param name="durationSeconds">Time to keep rendering, 0 means render at least one more frame.</param>
764         /// <since_tizen> 3 </since_tizen>
765         public void KeepRendering(float durationSeconds)
766         {
767             NDalicPINVOKE.Stage_KeepRendering(stageCPtr, durationSeconds);
768             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
769         }
770
771         internal KeyEventSignal KeyEventSignal()
772         {
773             KeyEventSignal ret = new KeyEventSignal(NDalicPINVOKE.Stage_KeyEventSignal(stageCPtr), false);
774             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
775             return ret;
776         }
777
778         internal VoidSignal EventProcessingFinishedSignal()
779         {
780             VoidSignal ret = new VoidSignal(NDalicPINVOKE.Stage_EventProcessingFinishedSignal(stageCPtr), false);
781             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
782             return ret;
783         }
784
785         internal TouchSignal TouchSignal()
786         {
787             TouchSignal ret = new TouchSignal(NDalicPINVOKE.Stage_TouchSignal(stageCPtr), false);
788             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
789             return ret;
790         }
791
792         private StageWheelSignal WheelEventSignal()
793         {
794             StageWheelSignal ret = new StageWheelSignal(NDalicPINVOKE.Stage_WheelEventSignal(stageCPtr), false);
795             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
796             return ret;
797         }
798
799         internal VoidSignal ContextLostSignal()
800         {
801             VoidSignal ret = new VoidSignal(NDalicPINVOKE.Stage_ContextLostSignal(stageCPtr), false);
802             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
803             return ret;
804         }
805
806         internal VoidSignal ContextRegainedSignal()
807         {
808             VoidSignal ret = new VoidSignal(NDalicPINVOKE.Stage_ContextRegainedSignal(stageCPtr), false);
809             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
810             return ret;
811         }
812
813         internal VoidSignal SceneCreatedSignal()
814         {
815             VoidSignal ret = new VoidSignal(NDalicPINVOKE.Stage_SceneCreatedSignal(stageCPtr), false);
816             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
817             return ret;
818         }
819
820         internal ResizedSignal ResizedSignal()
821         {
822             ResizedSignal ret = new ResizedSignal(NDalicManualPINVOKE.Window_ResizedSignal(swigCPtr), false);
823             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
824             return ret;
825         }
826
827         internal static Vector4 DEFAULT_BACKGROUND_COLOR
828         {
829             get
830             {
831                 global::System.IntPtr cPtr = NDalicPINVOKE.Stage_DEFAULT_BACKGROUND_COLOR_get();
832                 Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false);
833                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
834                 return ret;
835             }
836         }
837
838         internal static Vector4 DEBUG_BACKGROUND_COLOR
839         {
840             get
841             {
842                 global::System.IntPtr cPtr = NDalicPINVOKE.Stage_DEBUG_BACKGROUND_COLOR_get();
843                 Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false);
844                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
845                 return ret;
846             }
847         }
848
849         private static readonly Window instance = Application.Instance.GetWindow();
850
851         /// <summary>
852         /// The stage instance property (read-only).<br />
853         /// Gets the current window.<br />
854         /// </summary>
855         /// <since_tizen> 3 </since_tizen>
856         public static Window Instance
857         {
858             get
859             {
860                 return instance;
861             }
862         }
863
864         /// <summary>
865         /// Grabs the key specified by a key for a window only when a window is the topmost window.<br />
866         /// This function can be used for following example scenarios: <br />
867         /// - Mobile - Using volume up or down as zoom up or down in camera apps.<br />
868         /// </summary>
869         /// <param name="DaliKey">The key code to grab.</param>
870         /// <returns>True if the grab succeeds.</returns>
871         /// <since_tizen> 3 </since_tizen>
872         public bool GrabKeyTopmost(int DaliKey)
873         {
874             bool ret = NDalicManualPINVOKE.GrabKeyTopmost(HandleRef.ToIntPtr(this.swigCPtr), DaliKey);
875             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
876             return ret;
877         }
878
879         /// <summary>
880         /// Ungrabs the key specified by a key for the window.<br />
881         /// Note: If this function is called between key down and up events of a grabbed key, an application doesn't receive the key up event.<br />
882         /// </summary>
883         /// <param name="DaliKey">The key code to ungrab.</param>
884         /// <returns>True if the ungrab succeeds.</returns>
885         /// <since_tizen> 3 </since_tizen>
886         public bool UngrabKeyTopmost(int DaliKey)
887         {
888             bool ret = NDalicManualPINVOKE.UngrabKeyTopmost(HandleRef.ToIntPtr(this.swigCPtr), DaliKey);
889             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
890             return ret;
891         }
892
893         /// <summary>
894         ///  Grabs the key specified by a key for a window in a GrabMode. <br />
895         ///  Details: This function can be used for following example scenarios: <br />
896         ///  - TV - A user might want to change the volume or channel of the background TV contents while focusing on the foregrund app. <br />
897         ///  - Mobile - When a user presses the Home key, the homescreen appears regardless of the current foreground app. <br />
898         ///  - Mobile - Using the volume up or down as zoom up or down in camera apps. <br />
899         /// </summary>
900         /// <param name="DaliKey">The key code to grab.</param>
901         /// <param name="GrabMode">The grab mode for the key.</param>
902         /// <returns>True if the grab succeeds.</returns>
903         /// <since_tizen> 3 </since_tizen>
904         public bool GrabKey(int DaliKey, KeyGrabMode GrabMode)
905         {
906             bool ret = NDalicManualPINVOKE.GrabKey(HandleRef.ToIntPtr(this.swigCPtr), DaliKey, (int)GrabMode);
907             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
908             return ret;
909         }
910
911         /// <summary>
912         /// Ungrabs the key specified by a key for a window.<br />
913         /// Note: If this function is called between key down and up events of a grabbed key, an application doesn't receive the key up event. <br />
914         /// </summary>
915         /// <param name="DaliKey">The key code to ungrab.</param>
916         /// <returns>True if the ungrab succeeds.</returns>
917         /// <since_tizen> 3 </since_tizen>
918         public bool UngrabKey(int DaliKey)
919         {
920             bool ret = NDalicManualPINVOKE.UngrabKey(HandleRef.ToIntPtr(this.swigCPtr), DaliKey);
921             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
922             return ret;
923         }
924
925         internal System.IntPtr GetNativeWindowHandler()
926         {
927             System.IntPtr ret = NDalicManualPINVOKE.GetNativeWindowHandler(HandleRef.ToIntPtr(this.swigCPtr));
928             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
929             return ret;
930         }
931
932         /// <summary>
933         /// Enumeration for orientation of the window is the way in which a rectangular page is oriented for normal viewing.
934         /// </summary>
935         /// <since_tizen> 3 </since_tizen>
936         public enum WindowOrientation
937         {
938             /// <summary>
939             /// Portrait orientation. The height of the display area is greater than the width.
940             /// </summary>
941             /// <since_tizen> 3 </since_tizen>
942             Portrait = 0,
943             /// <summary>
944             /// Landscape orientation. A wide view area is needed.
945             /// </summary>
946             /// <since_tizen> 3 </since_tizen>
947             Landscape = 90,
948             /// <summary>
949             /// Portrait inverse orientation.
950             /// </summary>
951             /// <since_tizen> 3 </since_tizen>
952             PortraitInverse = 180,
953             /// <summary>
954             /// Landscape inverse orientation.
955             /// </summary>
956             /// <since_tizen> 3 </since_tizen>
957             LandscapeInverse = 270
958         }
959
960         /// <summary>
961         /// Enumeration for the key grab mode for platform-level APIs.
962         /// </summary>
963         /// <since_tizen> 3 </since_tizen>
964         public enum KeyGrabMode
965         {
966             /// <summary>
967             /// Grabs a key only when on the top of the grabbing-window stack mode.
968             /// </summary>
969             Topmost = 0,
970             /// <summary>
971             /// Grabs a key together with the other client window(s) mode.
972             /// </summary>
973             Shared,
974             /// <summary>
975             /// Grabs a key exclusively regardless of the grabbing-window's position on the window stack with the possibility of overriding the grab by the other client window mode.
976             /// </summary>
977             OverrideExclusive,
978             /// <summary>
979             /// Grabs a key exclusively regardless of the grabbing-window's position on the window stack mode.
980             /// </summary>
981             Exclusive
982         };
983
984         /// <summary>
985         /// Enumeration for opacity of the indicator.
986         /// </summary>
987         internal enum IndicatorBackgroundOpacity
988         {
989             Opaque = 100,
990             Translucent = 50,
991             Transparent = 0
992         }
993
994         /// <summary>
995         /// Enumeration for visible mode of the indicator.
996         /// </summary>
997         internal enum IndicatorVisibleMode
998         {
999             Invisible = 0,
1000             Visible = 1,
1001             Auto = 2
1002         }
1003
1004         /// <summary>
1005         /// The touch event argument.
1006         /// </summary>
1007         public class TouchEventArgs : EventArgs
1008         {
1009             private Touch _touch;
1010
1011             /// <summary>
1012             /// Touch.
1013             /// </summary>
1014             /// <since_tizen> 3 </since_tizen>
1015             public Touch Touch
1016             {
1017                 get
1018                 {
1019                     return _touch;
1020                 }
1021                 set
1022                 {
1023                     _touch = value;
1024                 }
1025             }
1026         }
1027
1028         private event EventHandler<TouchEventArgs> _stageTouchHandler;
1029         private EventCallbackDelegateType1 _stageTouchCallbackDelegate;
1030
1031         /// <summary>
1032         /// This event is emitted when the screen is touched and when the touch ends.<br />
1033         /// If there are multiple touch points, then this will be emitted when the first touch occurs and
1034         /// then when the last finger is lifted.<br />
1035         /// An interrupted event will also be emitted (if it occurs).<br />
1036         /// </summary>
1037         /// <since_tizen> 4 </since_tizen>
1038         public event EventHandler<TouchEventArgs> TouchEvent
1039         {
1040             add
1041             {
1042                 lock (this)
1043                 {
1044                     _stageTouchHandler += value;
1045                     _stageTouchCallbackDelegate = OnStageTouch;
1046                     this.TouchSignal().Connect(_stageTouchCallbackDelegate);
1047                 }
1048             }
1049             remove
1050             {
1051                 lock (this)
1052                 {
1053                     if (_stageTouchHandler != null)
1054                     {
1055                         this.TouchSignal().Disconnect(_stageTouchCallbackDelegate);
1056                     }
1057                     _stageTouchHandler -= value;
1058                 }
1059             }
1060         }
1061
1062         private void OnStageTouch(IntPtr data)
1063         {
1064             TouchEventArgs e = new TouchEventArgs();
1065
1066             if (data != null)
1067             {
1068                 e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(data);
1069             }
1070
1071             if (_stageTouchHandler != null)
1072             {
1073                 _stageTouchHandler(this, e);
1074             }
1075         }
1076
1077         /// <summary>
1078         /// Wheel event arguments.
1079         /// </summary>
1080         public class WheelEventArgs : EventArgs
1081         {
1082             private Wheel _wheel;
1083
1084             /// <summary>
1085             /// Wheel.
1086             /// </summary>
1087             /// <since_tizen> 3 </since_tizen>
1088             public Wheel Wheel
1089             {
1090                 get
1091                 {
1092                     return _wheel;
1093                 }
1094                 set
1095                 {
1096                     _wheel = value;
1097                 }
1098             }
1099         }
1100
1101         private event EventHandler<WheelEventArgs> _stageWheelHandler;
1102         private EventCallbackDelegateType1 _stageWheelCallbackDelegate;
1103
1104         /// <summary>
1105         /// This event is emitted when the wheel event is received.
1106         /// </summary>
1107         /// <since_tizen> 4 </since_tizen>
1108         public event EventHandler<WheelEventArgs> WheelEvent
1109         {
1110             add
1111             {
1112                 if (_stageWheelHandler == null)
1113                 {
1114                     _stageWheelCallbackDelegate = OnStageWheel;
1115                     WheelEventSignal().Connect(_stageWheelCallbackDelegate);
1116                 }
1117                 _stageWheelHandler += value;
1118             }
1119             remove
1120             {
1121                 _stageWheelHandler -= value;
1122                 if (_stageWheelHandler == null && WheelEventSignal().Empty() == false)
1123                 {
1124                     WheelEventSignal().Disconnect(_stageWheelCallbackDelegate);
1125                 }
1126             }
1127         }
1128
1129         private void OnStageWheel(IntPtr data)
1130         {
1131             WheelEventArgs e = new WheelEventArgs();
1132
1133             if (data != null)
1134             {
1135                 e.Wheel = Tizen.NUI.Wheel.GetWheelFromPtr(data);
1136             }
1137
1138             if (_stageWheelHandler != null)
1139             {
1140                 _stageWheelHandler(this, e);
1141             }
1142         }
1143
1144         /// <summary>
1145         /// Key event arguments.
1146         /// </summary>
1147         public class KeyEventArgs : EventArgs
1148         {
1149             private Key _key;
1150
1151             /// <summary>
1152             /// Key.
1153             /// </summary>
1154             /// <since_tizen> 3 </since_tizen>
1155             public Key Key
1156             {
1157                 get
1158                 {
1159                     return _key;
1160                 }
1161                 set
1162                 {
1163                     _key = value;
1164                 }
1165             }
1166         }
1167
1168         private event EventHandler<KeyEventArgs> _stageKeyHandler;
1169         private EventCallbackDelegateType1 _stageKeyCallbackDelegate;
1170
1171         /// <summary>
1172         /// This event is emitted when the key event is received.
1173         /// </summary>
1174         /// <since_tizen> 4 </since_tizen>
1175         public event EventHandler<KeyEventArgs> KeyEvent
1176         {
1177             add
1178             {
1179                 if (_stageKeyHandler == null)
1180                 {
1181                     _stageKeyCallbackDelegate = OnStageKey;
1182                     KeyEventSignal().Connect(_stageKeyCallbackDelegate);
1183                 }
1184                 _stageKeyHandler += value;
1185             }
1186             remove
1187             {
1188                 _stageKeyHandler -= value;
1189                 if (_stageKeyHandler == null && KeyEventSignal().Empty() == false)
1190                 {
1191                     KeyEventSignal().Disconnect(_stageKeyCallbackDelegate);
1192                 }
1193             }
1194         }
1195
1196         // Callback for Stage KeyEventsignal
1197         private void OnStageKey(IntPtr data)
1198         {
1199             KeyEventArgs e = new KeyEventArgs();
1200
1201             if (data != null)
1202             {
1203                 e.Key = Tizen.NUI.Key.GetKeyFromPtr(data);
1204             }
1205
1206             if (_stageKeyHandler != null)
1207             {
1208                 //here we send all data to user event handlers
1209                 _stageKeyHandler(this, e);
1210             }
1211         }
1212
1213
1214         private event EventHandler _stageEventProcessingFinishedEventHandler;
1215         private EventCallbackDelegateType0 _stageEventProcessingFinishedEventCallbackDelegate;
1216
1217         internal event EventHandler EventProcessingFinished
1218         {
1219             add
1220             {
1221                 if (_stageEventProcessingFinishedEventHandler == null)
1222                 {
1223                     _stageEventProcessingFinishedEventCallbackDelegate = OnEventProcessingFinished;
1224                     EventProcessingFinishedSignal().Connect(_stageEventProcessingFinishedEventCallbackDelegate);
1225                 }
1226                 _stageEventProcessingFinishedEventHandler += value;
1227
1228             }
1229             remove
1230             {
1231                 _stageEventProcessingFinishedEventHandler -= value;
1232                 if (_stageEventProcessingFinishedEventHandler == null && EventProcessingFinishedSignal().Empty() == false)
1233                 {
1234                     EventProcessingFinishedSignal().Disconnect(_stageEventProcessingFinishedEventCallbackDelegate);
1235                 }
1236             }
1237         }
1238
1239         // Callback for Stage EventProcessingFinishedSignal
1240         private void OnEventProcessingFinished()
1241         {
1242             if (_stageEventProcessingFinishedEventHandler != null)
1243             {
1244                 _stageEventProcessingFinishedEventHandler(this, null);
1245             }
1246         }
1247
1248
1249         private EventHandler _stageContextLostEventHandler;
1250         private EventCallbackDelegateType0 _stageContextLostEventCallbackDelegate;
1251
1252         internal event EventHandler ContextLost
1253         {
1254             add
1255             {
1256                 if (_stageContextLostEventHandler == null)
1257                 {
1258                     _stageContextLostEventCallbackDelegate = OnContextLost;
1259                     ContextLostSignal().Connect(_stageContextLostEventCallbackDelegate);
1260                 }
1261                 _stageContextLostEventHandler += value;
1262             }
1263             remove
1264             {
1265                 _stageContextLostEventHandler -= value;
1266                 if (_stageContextLostEventHandler == null && ContextLostSignal().Empty() == false)
1267                 {
1268                     ContextLostSignal().Disconnect(_stageContextLostEventCallbackDelegate);
1269                 }
1270             }
1271         }
1272
1273         // Callback for Stage ContextLostSignal
1274         private void OnContextLost()
1275         {
1276             if (_stageContextLostEventHandler != null)
1277             {
1278                 _stageContextLostEventHandler(this, null);
1279             }
1280         }
1281
1282
1283         private EventHandler _stageContextRegainedEventHandler;
1284         private EventCallbackDelegateType0 _stageContextRegainedEventCallbackDelegate;
1285
1286         internal event EventHandler ContextRegained
1287         {
1288             add
1289             {
1290                 if (_stageContextRegainedEventHandler == null)
1291                 {
1292                     _stageContextRegainedEventCallbackDelegate = OnContextRegained;
1293                     ContextRegainedSignal().Connect(_stageContextRegainedEventCallbackDelegate);
1294                 }
1295                 _stageContextRegainedEventHandler += value;
1296             }
1297             remove
1298             {
1299                 _stageContextRegainedEventHandler -= value;
1300                 if (_stageContextRegainedEventHandler == null && ContextRegainedSignal().Empty() == false)
1301                 {
1302                     this.ContextRegainedSignal().Disconnect(_stageContextRegainedEventCallbackDelegate);
1303                 }
1304             }
1305         }
1306
1307         // Callback for Stage ContextRegainedSignal
1308         private void OnContextRegained()
1309         {
1310             if (_stageContextRegainedEventHandler != null)
1311             {
1312                 _stageContextRegainedEventHandler(this, null);
1313             }
1314         }
1315
1316
1317         private EventHandler _stageSceneCreatedEventHandler;
1318         private EventCallbackDelegateType0 _stageSceneCreatedEventCallbackDelegate;
1319
1320         internal event EventHandler SceneCreated
1321         {
1322             add
1323             {
1324                 if (_stageSceneCreatedEventHandler == null)
1325                 {
1326                     _stageSceneCreatedEventCallbackDelegate = OnSceneCreated;
1327                     SceneCreatedSignal().Connect(_stageSceneCreatedEventCallbackDelegate);
1328                 }
1329                 _stageSceneCreatedEventHandler += value;
1330             }
1331             remove
1332             {
1333                 _stageSceneCreatedEventHandler -= value;
1334                 if (_stageSceneCreatedEventHandler == null && SceneCreatedSignal().Empty() == false)
1335                 {
1336                     SceneCreatedSignal().Disconnect(_stageSceneCreatedEventCallbackDelegate);
1337                 }
1338             }
1339         }
1340
1341         // Callback for Stage SceneCreatedSignal
1342         private void OnSceneCreated()
1343         {
1344             if (_stageSceneCreatedEventHandler != null)
1345             {
1346                 _stageSceneCreatedEventHandler(this, null);
1347             }
1348         }
1349
1350         /// <summary>
1351         /// This resized event arguments.
1352         /// </summary>
1353         /// <since_tizen> 4 </since_tizen>
1354         public class ResizedEventArgs : EventArgs
1355         {
1356             Size2D _windowSize;
1357
1358             /// <summary>
1359             /// This window size.
1360             /// </summary>
1361             /// <since_tizen> 4 </since_tizen>
1362             public Size2D WindowSize
1363             {
1364                 get
1365                 {
1366                     return _windowSize;
1367                 }
1368                 set
1369                 {
1370                     _windowSize = value;
1371                 }
1372             }
1373         }
1374
1375         private WindowResizedEventCallbackType _windowResizedEventCallback;
1376         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
1377         private delegate void WindowResizedEventCallbackType(IntPtr windowSize);
1378         private event EventHandler<ResizedEventArgs> _windowResizedEventHandler;
1379
1380         /// <summary>
1381         /// This event is emitted when the window resized.
1382         /// </summary>
1383         /// <since_tizen> 4 </since_tizen>
1384         public event EventHandler<ResizedEventArgs> Resized
1385         {
1386             add
1387             {
1388                 if (_windowResizedEventHandler == null)
1389                 {
1390                     _windowResizedEventCallback = OnResized;
1391                     ResizedSignal().Connect(_windowResizedEventCallback);
1392                 }
1393
1394                 _windowResizedEventHandler += value;
1395             }
1396             remove
1397             {
1398                 _windowResizedEventHandler -= value;
1399
1400                 if (_windowResizedEventHandler == null && ResizedSignal().Empty() == false && _windowResizedEventCallback != null)
1401                 {
1402                     ResizedSignal().Disconnect(_windowResizedEventCallback);
1403                 }
1404             }
1405         }
1406
1407         private void OnResized(IntPtr windowSize)
1408         {
1409             ResizedEventArgs e = new ResizedEventArgs();
1410             var val = new Uint16Pair(windowSize, false);
1411             e.WindowSize = new Size2D(val.GetWidth(), val.GetHeight());
1412             val.Dispose();
1413
1414             if (_windowResizedEventHandler != null)
1415             {
1416                 _windowResizedEventHandler(this, e);
1417             }
1418         }
1419
1420         internal void SetWindowSize(Size2D size)
1421         {
1422             var val = new Uint16Pair((uint)size.Width, (uint)size.Height);
1423             NDalicManualPINVOKE.SetSize(swigCPtr, Uint16Pair.getCPtr(val));
1424
1425             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1426         }
1427
1428         internal Size2D GetWindowSize()
1429         {
1430             var val = new Uint16Pair(NDalicManualPINVOKE.GetSize(swigCPtr), false);
1431             Size2D ret = new Size2D(val.GetWidth(), val.GetHeight());
1432
1433             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1434             return ret;
1435         }
1436
1437         internal void SetPosition(Position2D position)
1438         {
1439             var val = new Uint16Pair((uint)position.X, (uint)position.Y);
1440             NDalicManualPINVOKE.SetPosition(swigCPtr, Uint16Pair.getCPtr(val));
1441
1442             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1443         }
1444
1445         internal Position2D GetPosition()
1446         {
1447             var val = new Uint16Pair(NDalicManualPINVOKE.GetPosition(swigCPtr), true);
1448             Position2D ret = new Position2D(val.GetX(), val.GetY());
1449
1450             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1451             return ret;
1452         }
1453
1454         /// <summary>
1455         /// The window size property (read-only).
1456         /// </summary>
1457         /// <since_tizen> 3 </since_tizen>
1458         public Size2D Size
1459         {
1460             get
1461             {
1462                 Size2D ret = GetSize();
1463                 return ret;
1464             }
1465         }
1466
1467         /// <summary>
1468         /// The background color property.
1469         /// </summary>
1470         /// <since_tizen> 3 </since_tizen>
1471         public Color BackgroundColor
1472         {
1473             set
1474             {
1475                 SetBackgroundColor(value);
1476             }
1477             get
1478             {
1479                 Color ret = GetBackgroundColor();
1480                 return ret;
1481             }
1482         }
1483
1484         /// <summary>
1485         /// The DPI property (read-only).<br />
1486         /// Retrieves the DPI of the display device to which the Window is connected.<br />
1487         /// </summary>
1488         /// <since_tizen> 3 </since_tizen>
1489         public Vector2 Dpi
1490         {
1491             get
1492             {
1493                 return GetDpi();
1494             }
1495         }
1496
1497         /// <summary>
1498         /// The layer count property (read-only).<br />
1499         /// Queries the number of on-Window layers.<br />
1500         /// </summary>
1501         /// <since_tizen> 3 </since_tizen>
1502         public uint LayerCount
1503         {
1504             get
1505             {
1506                 return GetLayerCount();
1507             }
1508         }
1509
1510
1511         /// <summary>
1512         /// Adds a layer to the stage.
1513         /// </summary>
1514         /// <param name="layer">Layer to add.</param>
1515         /// <since_tizen> 3 </since_tizen>
1516         public void AddLayer(Layer layer)
1517         {
1518             NDalicPINVOKE.Stage_Add(stageCPtr, Layer.getCPtr(layer));
1519             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1520         }
1521
1522         /// <summary>
1523         /// Removes a layer from the stage.
1524         /// </summary>
1525         /// <param name="layer">Layer to remove.</param>
1526         /// <since_tizen> 4 </since_tizen>
1527         public void RemoveLayer(Layer layer)
1528         {
1529             NDalicPINVOKE.Stage_Remove(stageCPtr, Layer.getCPtr(layer));
1530             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1531         }
1532
1533         /// <summary>
1534         /// Please do not use! this will be deprecated
1535         /// </summary>
1536         /// <since_tizen> 3 </since_tizen>
1537         [EditorBrowsable(EditorBrowsableState.Never)]
1538         public class WindowFocusChangedEventArgs : EventArgs
1539         {
1540             /// <summary>
1541             /// Please do not use! this will be deprecated
1542             /// </summary>
1543             /// <since_tizen> 3 </since_tizen>
1544             public bool FocusGained
1545             {
1546                 get;
1547                 set;
1548             }
1549         }
1550
1551         private WindowFocusChangedEventCallbackType _windowFocusChangedEventCallback2;
1552         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
1553         private delegate void WindowFocusChangedEventCallbackType2(bool focusGained);
1554         private event EventHandler<WindowFocusChangedEventArgs> _windowFocusChangedEventHandler2;
1555
1556         /// <summary>
1557         /// Please do not use! this will be deprecated. Please use 'FocusChanged' event instead.
1558         /// </summary>
1559         /// <since_tizen> 3 </since_tizen>
1560         /// Please do not use! this will be deprecated!
1561         /// Instead please use FocusChanged.
1562         [Obsolete("Please do not use! this will be deprecated, instead please use FocusChanged")]
1563         [EditorBrowsable(EditorBrowsableState.Never)]
1564         public event EventHandler<WindowFocusChangedEventArgs> WindowFocusChanged
1565         {
1566             add
1567             {
1568                 if (_windowFocusChangedEventHandler2 == null)
1569                 {
1570                     _windowFocusChangedEventCallback2 = OnWindowFocusedChanged2;
1571                     WindowFocusChangedSignal().Connect(_windowFocusChangedEventCallback2);
1572                 }
1573
1574                 _windowFocusChangedEventHandler2 += value;
1575             }
1576             remove
1577             {
1578                 _windowFocusChangedEventHandler2 -= value;
1579
1580                 if (_windowFocusChangedEventHandler2 == null && WindowFocusChangedSignal().Empty() == false && _windowFocusChangedEventCallback2 != null)
1581                 {
1582                     WindowFocusChangedSignal().Disconnect(_windowFocusChangedEventCallback2);
1583                 }
1584             }
1585         }
1586
1587         private void OnWindowFocusedChanged2(bool focusGained)
1588         {
1589             WindowFocusChangedEventArgs e = new WindowFocusChangedEventArgs();
1590
1591             e.FocusGained = focusGained;
1592
1593             if (_windowFocusChangedEventHandler2 != null)
1594             {
1595                 _windowFocusChangedEventHandler2(this, e);
1596             }
1597         }
1598
1599         /// <summary>
1600         /// Gets or sets a size of the window.
1601         /// </summary>
1602         /// <since_tizen> 4 </since_tizen>
1603         public Size2D WindowSize
1604         {
1605             get
1606             {
1607                 return GetWindowSize();
1608             }
1609             set
1610             {
1611                 SetWindowSize(value);
1612             }
1613         }
1614
1615         /// <summary>
1616         /// Gets or sets a position of the window.
1617         /// </summary>
1618         /// <since_tizen> 4 </since_tizen>
1619         public Position2D WindowPosition
1620         {
1621             get
1622             {
1623                 return GetPosition();
1624             }
1625             set
1626             {
1627                 SetPosition(value);
1628             }
1629         }
1630
1631         /// <summary>
1632         /// Feed a key-event into the window.
1633         /// </summary>
1634         /// <since_tizen> 4 </since_tizen>
1635         public static void FeedKeyEvent(Key keyEvent)
1636         {
1637             NDalicManualPINVOKE.Window_FeedKeyEvent(Key.getCPtr(keyEvent));
1638             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1639         }
1640
1641         /// <summary>
1642         /// Allows at least one more render, even when paused.
1643         /// The window should be shown, not minimised.
1644         /// </summary>
1645         /// <since_tizen> 4 </since_tizen>
1646         public void RenderOnce()
1647         {
1648             NDalicManualPINVOKE.Window_RenderOnce(swigCPtr);
1649             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1650         }
1651
1652         /// <summary>
1653         /// Contains and encapsulates Native Window handle.
1654         /// </summary>
1655         /// <since_tizen> 4 </since_tizen>
1656         public class SafeNativeWindowHandle : SafeHandle
1657         {
1658             /// <summary>
1659             /// Contructor, Native window handle is set to handle.
1660             /// </summary>
1661             /// <since_tizen> 4 </since_tizen>
1662             public SafeNativeWindowHandle() : base(IntPtr.Zero, false)
1663             {
1664                 SetHandle(Tizen.NUI.Window.Instance.GetNativeWindowHandler());
1665             }
1666             /// <summary>
1667             /// Null check if the handle is valid or not.
1668             /// </summary>
1669             /// <since_tizen> 4 </since_tizen>
1670             public override bool IsInvalid
1671             {
1672                 get
1673                 {
1674                     return this.handle == IntPtr.Zero;
1675                 }
1676             }
1677             /// <summary>
1678             /// Release handle itself.
1679             /// </summary>
1680             /// <returns>true when released successfully.</returns>
1681             /// <since_tizen> 4 </since_tizen>
1682             protected override bool ReleaseHandle()
1683             {
1684                 return true;
1685             }
1686         }
1687
1688     }
1689 }