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