36cc3a3ba667a2bc399e8c374b1802d162eccf17
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Window.cs
1 /*
2  * Copyright(c) 2019 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
18 extern alias TizenSystemInformation;
19 using TizenSystemInformation.Tizen.System;
20 using global::System;
21 using System.ComponentModel;
22 using System.Collections.Generic;
23 using global::System.Runtime.InteropServices;
24 using Tizen.NUI.BaseComponents;
25
26 namespace Tizen.NUI
27 {
28     /// <summary>
29     /// The window class is used internally for drawing.<br />
30     /// The window has an orientation and indicator properties.<br />
31     /// </summary>
32     /// <since_tizen> 3 </since_tizen>
33     public partial class Window : BaseHandle
34     {
35         private static readonly Window instance = Application.Instance?.GetWindow();
36         private global::System.Runtime.InteropServices.HandleRef stageCPtr;
37         private Layer _rootLayer;
38         private string _windowTitle;
39         private List<Layer> _childLayers = new List<Layer>();
40         private LayoutController localController;
41
42         private bool IsSupportedMultiWindow()
43         {
44             bool isSupported = false;
45             Information.TryGetValue("http://tizen.org/feature/opengles.surfaceless_context", out isSupported);
46             return isSupported;
47         }
48
49         internal Window(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Window.Upcast(cPtr), cMemoryOwn)
50         {
51             if (Interop.Stage.IsInstalled())
52             {
53                 stageCPtr = new global::System.Runtime.InteropServices.HandleRef(this, Interop.Stage.GetCurrent());
54
55                 localController = new LayoutController(this);
56                 NUILog.Debug("layoutController id:" + localController.GetId());
57             }
58         }
59
60         /// <summary>
61         /// Creates a new Window.<br />
62         /// This creates an extra window in addition to the default main window<br />
63         /// </summary>
64         /// <param name="windowPosition">The position and size of the Window.</param>
65         /// <param name="isTranslucent">Whether Window is translucent.</param>
66         /// <returns>A new Window.</returns>
67         /// <since_tizen> 6 </since_tizen>
68         /// <feature> http://tizen.org/feature/opengles.surfaceless_context </feature>
69         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
70         public Window(Rectangle windowPosition = null, bool isTranslucent = false) : this(Interop.Window.New(Rectangle.getCPtr(windowPosition), "", isTranslucent), true)
71         {
72             if (IsSupportedMultiWindow() == false)
73             {
74                 NUILog.Error("This device does not support surfaceless_context. So Window cannot be created. ");
75             }
76             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77         }
78
79         /// <summary>
80         /// Creates a new Window with a specific name.<br />
81         /// This creates an extra window in addition to the default main window<br />
82         /// </summary>
83         /// <param name="name">The name for extra window. </param>
84         /// <param name="windowPosition">The position and size of the Window.</param>
85         /// <param name="isTranslucent">Whether Window is translucent.</param>
86         /// <returns>A new Window.</returns>
87         /// <since_tizen> 6 </since_tizen>
88         /// <feature> http://tizen.org/feature/opengles.surfaceless_context </feature>
89         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
90         public Window(string name, Rectangle windowPosition = null, bool isTranslucent = false) : this(Interop.Window.New(Rectangle.getCPtr(windowPosition), name, isTranslucent), true)
91         {
92             if (IsSupportedMultiWindow() == false)
93             {
94                 NUILog.Error("This device does not support surfaceless_context. So Window cannot be created. ");
95             }
96             this._windowTitle = name;
97             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
98         }
99
100         /// <summary>
101         /// Enumeration for orientation of the window is the way in which a rectangular page is oriented for normal viewing.
102         /// </summary>
103         /// <since_tizen> 3 </since_tizen>
104         public enum WindowOrientation
105         {
106             /// <summary>
107             /// Portrait orientation. The height of the display area is greater than the width.
108             /// </summary>
109             /// <since_tizen> 3 </since_tizen>
110             Portrait = 0,
111             /// <summary>
112             /// Landscape orientation. A wide view area is needed.
113             /// </summary>
114             /// <since_tizen> 3 </since_tizen>
115             Landscape = 90,
116             /// <summary>
117             /// Portrait inverse orientation.
118             /// </summary>
119             /// <since_tizen> 3 </since_tizen>
120             PortraitInverse = 180,
121             /// <summary>
122             /// Landscape inverse orientation.
123             /// </summary>
124             /// <since_tizen> 3 </since_tizen>
125             LandscapeInverse = 270,
126             /// <summary>
127             /// No orientation. It is for the preferred orientation
128             /// Especially, NoOrientationPreference only has the effect for the preferred orientation.
129             /// It is used to unset the preferred orientation with SetPreferredOrientation.
130             /// </summary>
131             [EditorBrowsable(EditorBrowsableState.Never)]
132             NoOrientationPreference = -1
133         }
134
135         /// <summary>
136         /// Enumeration for the key grab mode for platform-level APIs.
137         /// </summary>
138         /// <since_tizen> 3 </since_tizen>
139         public enum KeyGrabMode
140         {
141             /// <summary>
142             /// Grabs a key only when on the top of the grabbing-window stack mode.
143             /// </summary>
144             Topmost = 0,
145             /// <summary>
146             /// Grabs a key together with the other client window(s) mode.
147             /// </summary>
148             Shared,
149             /// <summary>
150             /// 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.
151             /// </summary>
152             OverrideExclusive,
153             /// <summary>
154             /// Grabs a key exclusively regardless of the grabbing-window's position on the window stack mode.
155             /// </summary>
156             Exclusive
157         };
158
159         /// <summary>
160         /// Enumeration for transition effect's state.
161         /// </summary>
162         [Obsolete("Please do not use! This will be removed. Please use Window.EffectState instead!")]
163         [EditorBrowsable(EditorBrowsableState.Never)]
164         public enum EffectStates
165         {
166             /// <summary>
167             /// None state.
168             /// </summary>
169             [Obsolete("Please do not use! This will be removed. Please use Window.EffectState.None instead!")]
170             [EditorBrowsable(EditorBrowsableState.Never)]
171             None = 0,
172             /// <summary>
173             /// Transition effect is started.
174             /// </summary>
175             [Obsolete("Please do not use! This will be removed. Please use Window.EffectState.Start instead!")]
176             [EditorBrowsable(EditorBrowsableState.Never)]
177             Start,
178             /// <summary>
179             /// Transition effect is ended.
180             /// </summary>
181             [Obsolete("Please do not use! This will be removed. Please use Window.EffectState.End instead!")]
182             [EditorBrowsable(EditorBrowsableState.Never)]
183             End,
184         }
185
186         /// <summary>
187         /// Enumeration for transition effect's state.
188         /// </summary>
189         [EditorBrowsable(EditorBrowsableState.Never)]
190         public enum EffectState
191         {
192             /// <summary>
193             /// None state.
194             /// </summary>
195             [EditorBrowsable(EditorBrowsableState.Never)]
196             None = 0,
197             /// <summary>
198             /// Transition effect is started.
199             /// </summary>
200             [EditorBrowsable(EditorBrowsableState.Never)]
201             Start,
202             /// <summary>
203             /// Transition effect is ended.
204             /// </summary>
205             [EditorBrowsable(EditorBrowsableState.Never)]
206             End,
207         }
208
209         /// <summary>
210         /// Enumeration for transition effect's type.
211         /// </summary>
212         [Obsolete("Please do not use! This will be removed. Please use Window.EffectType instead!")]
213         [EditorBrowsable(EditorBrowsableState.Never)]
214         public enum EffectTypes
215         {
216             /// <summary>
217             /// None type.
218             /// </summary>
219             [Obsolete("Please do not use! This will be removed. Please use Window.EffectType.None instead!")]
220             [EditorBrowsable(EditorBrowsableState.Never)]
221             None = 0,
222             /// <summary>
223             /// Window show effect.
224             /// </summary>
225             [Obsolete("Please do not use! This will be removed. Please use Window.EffectType.Show instead!")]
226             [EditorBrowsable(EditorBrowsableState.Never)]
227             Show,
228             /// <summary>
229             /// Window hide effect.
230             /// </summary>
231             [Obsolete("Please do not use! This will be removed. Please use Window.EffectType.Hide instead!")]
232             [EditorBrowsable(EditorBrowsableState.Never)]
233             Hide,
234         }
235
236         /// <summary>
237         /// Enumeration for transition effect's type.
238         /// </summary>
239         [EditorBrowsable(EditorBrowsableState.Never)]
240         public enum EffectType
241         {
242             /// <summary>
243             /// None type.
244             /// </summary>
245             [EditorBrowsable(EditorBrowsableState.Never)]
246             None = 0,
247             /// <summary>
248             /// Window show effect.
249             /// </summary>
250             [EditorBrowsable(EditorBrowsableState.Never)]
251             Show,
252             /// <summary>
253             /// Window hide effect.
254             /// </summary>
255             [EditorBrowsable(EditorBrowsableState.Never)]
256             Hide,
257         }
258
259         /// <summary>
260         /// The stage instance property (read-only).<br />
261         /// Gets the current window.<br />
262         /// </summary>
263         /// <since_tizen> 3 </since_tizen>
264         public static Window Instance
265         {
266             get
267             {
268                 return instance;
269             }
270         }
271
272         /// <summary>
273         /// Gets or sets a window type.
274         /// </summary>
275         /// <since_tizen> 3 </since_tizen>
276         public WindowType Type
277         {
278             get
279             {
280                 WindowType ret = (WindowType)Interop.Window.GetType(SwigCPtr);
281                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
282                 return ret;
283             }
284             set
285             {
286                 Interop.Window.SetType(SwigCPtr, (int)value);
287                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288             }
289         }
290
291         /// <summary>
292         /// Gets/Sets a window title.
293         /// </summary>
294         /// <since_tizen> 4 </since_tizen>
295         public string Title
296         {
297             get
298             {
299                 return _windowTitle;
300             }
301             set
302             {
303                 _windowTitle = value;
304                 SetClass(_windowTitle, "");
305             }
306         }
307
308         /// <summary>
309         /// The rendering behavior of a Window.
310         /// </summary>
311         /// <since_tizen> 5 </since_tizen>
312         public RenderingBehaviorType RenderingBehavior
313         {
314             get
315             {
316                 return GetRenderingBehavior();
317             }
318             set
319             {
320                 SetRenderingBehavior(value);
321             }
322         }
323
324         /// <summary>
325         /// The window size property (read-only).
326         /// </summary>
327         /// <since_tizen> 3 </since_tizen>
328         public Size2D Size
329         {
330             get
331             {
332                 Size2D ret = GetSize();
333                 return ret;
334             }
335         }
336
337         /// <summary>
338         /// The background color property.
339         /// </summary>
340         /// <since_tizen> 3 </since_tizen>
341         public Color BackgroundColor
342         {
343             set
344             {
345                 SetBackgroundColor(value);
346             }
347             get
348             {
349                 Color ret = GetBackgroundColor();
350                 return ret;
351             }
352         }
353
354         /// <summary>
355         /// The DPI property (read-only).<br />
356         /// Retrieves the DPI of the display device to which the Window is connected.<br />
357         /// </summary>
358         /// <since_tizen> 3 </since_tizen>
359         public Vector2 Dpi
360         {
361             get
362             {
363                 return GetDpi();
364             }
365         }
366
367         /// <summary>
368         /// The layer count property (read-only).<br />
369         /// Queries the number of on-Window layers.<br />
370         /// </summary>
371         /// <since_tizen> 3 </since_tizen>
372         public uint LayerCount
373         {
374             get
375             {
376                 return GetLayerCount();
377             }
378         }
379
380         /// <summary>
381         /// Gets or sets a size of the window.
382         /// </summary>
383         /// <exception cref="ArgumentNullException"> Thrown when value is null. </exception>
384         /// <since_tizen> 4 </since_tizen>
385         public Size2D WindowSize
386         {
387             get
388             {
389                 return GetWindowSize();
390             }
391             set
392             {
393                 SetWindowSize(value);
394             }
395         }
396
397         /// <summary>
398         /// Gets or sets a position of the window.
399         /// </summary>
400         /// <exception cref="ArgumentNullException"> Thrown when value is null. </exception>
401         /// <since_tizen> 4 </since_tizen>
402         public Position2D WindowPosition
403         {
404             get
405             {
406                 return GetPosition();
407             }
408             set
409             {
410                 SetPosition(value);
411             }
412         }
413
414         /// <summary>
415         /// Sets position and size of the window. This API guarantees that
416         /// both moving and resizing of window will appear on the screen at once.
417         /// </summary>
418         [EditorBrowsable(EditorBrowsableState.Never)]
419         public Rectangle WindowPositionSize
420         {
421             get
422             {
423                 Position2D position = GetPosition();
424                 Size2D size = GetSize();
425                 Rectangle ret = new Rectangle(position.X, position.Y, size.Width, size.Height);
426                 position.Dispose();
427                 return ret;
428             }
429             set
430             {
431                 SetPositionSize(value);
432             }
433         }
434
435         internal static Vector4 DEFAULT_BACKGROUND_COLOR
436         {
437             get
438             {
439                 global::System.IntPtr cPtr = Interop.Stage.DefaultBackgroundColorGet();
440                 Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false);
441                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
442                 return ret;
443             }
444         }
445
446         internal static Vector4 DEBUG_BACKGROUND_COLOR
447         {
448             get
449             {
450                 global::System.IntPtr cPtr = Interop.Stage.DebugBackgroundColorGet();
451                 Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false);
452                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
453                 return ret;
454             }
455         }
456
457         internal List<Layer> LayersChildren
458         {
459             get
460             {
461                 return _childLayers;
462             }
463         }
464
465         /// <summary>
466         ///  Get the LayoutController for this Window.
467         /// </summary>
468         internal LayoutController LayoutController
469         {
470             get
471             {
472                 return localController;
473             }
474         }
475
476         /// <summary>
477         /// Feed a key-event into the window.
478         /// </summary>
479         /// <param name="keyEvent">The key event to feed.</param>
480         /// <since_tizen> 4 </since_tizen>
481         [Obsolete("Please do not use! This will be deprecated! Please use FeedKey(Key keyEvent) instead!")]
482         public static void FeedKeyEvent(Key keyEvent)
483         {
484             Interop.Window.FeedKeyEvent(Key.getCPtr(keyEvent));
485             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
486         }
487
488         /// <summary>
489         /// Sets whether the window accepts a focus or not.
490         /// </summary>
491         /// <param name="accept">If a focus is accepted or not. The default is true.</param>
492         /// <since_tizen> 3 </since_tizen>
493         public void SetAcceptFocus(bool accept)
494         {
495             Interop.Window.SetAcceptFocus(SwigCPtr, accept);
496             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
497         }
498
499         /// <summary>
500         /// Returns whether the window accepts a focus or not.
501         /// </summary>
502         /// <returns>True if the window accepts a focus, false otherwise.</returns>
503         /// <since_tizen> 3 </since_tizen>
504         public bool IsFocusAcceptable()
505         {
506             bool ret = Interop.Window.IsFocusAcceptable(SwigCPtr);
507             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
508
509             return ret;
510         }
511
512         /// <summary>
513         /// Shows the window if it is hidden.
514         /// </summary>
515         /// <since_tizen> 3 </since_tizen>
516         public void Show()
517         {
518             Interop.Window.Show(SwigCPtr);
519             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
520         }
521
522         /// <summary>
523         /// Hides the window if it is showing.
524         /// </summary>
525         /// <since_tizen> 3 </since_tizen>
526         public void Hide()
527         {
528             Interop.Window.Hide(SwigCPtr);
529             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
530         }
531
532         /// <summary>
533         /// Retrieves whether the window is visible or not.
534         /// </summary>
535         /// <returns>True if the window is visible.</returns>
536         /// <since_tizen> 3 </since_tizen>
537         public bool IsVisible()
538         {
539             bool temp = Interop.Window.IsVisible(SwigCPtr);
540             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
541             return temp;
542         }
543
544         /// <summary>
545         /// Gets the count of supported auxiliary hints of the window.
546         /// </summary>
547         /// <returns>The number of supported auxiliary hints.</returns>
548         /// <since_tizen> 3 </since_tizen>
549         public uint GetSupportedAuxiliaryHintCount()
550         {
551             uint ret = Interop.Window.GetSupportedAuxiliaryHintCount(SwigCPtr);
552             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
553             return ret;
554         }
555
556         /// <summary>
557         /// Gets the supported auxiliary hint string of the window.
558         /// </summary>
559         /// <param name="index">The index of the supported auxiliary hint lists.</param>
560         /// <returns>The auxiliary hint string of the index.</returns>
561         /// <since_tizen> 3 </since_tizen>
562         public string GetSupportedAuxiliaryHint(uint index)
563         {
564             string ret = Interop.Window.GetSupportedAuxiliaryHint(SwigCPtr, index);
565             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
566             return ret;
567         }
568
569         /// <summary>
570         /// Creates an auxiliary hint of the window.
571         /// </summary>
572         /// <param name="hint">The auxiliary hint string.</param>
573         /// <param name="value">The value string.</param>
574         /// <returns>The ID of created auxiliary hint, or 0 on failure.</returns>
575         /// <since_tizen> 3 </since_tizen>
576         public uint AddAuxiliaryHint(string hint, string value)
577         {
578             uint ret = Interop.Window.AddAuxiliaryHint(SwigCPtr, hint, value);
579             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
580             return ret;
581         }
582
583         /// <summary>
584         /// Removes an auxiliary hint of the window.
585         /// </summary>
586         /// <param name="id">The ID of the auxiliary hint.</param>
587         /// <returns>True if no error occurred, false otherwise.</returns>
588         /// <since_tizen> 3 </since_tizen>
589         public bool RemoveAuxiliaryHint(uint id)
590         {
591             bool ret = Interop.Window.RemoveAuxiliaryHint(SwigCPtr, id);
592             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
593             return ret;
594         }
595
596         /// <summary>
597         /// Changes a value of the auxiliary hint.
598         /// </summary>
599         /// <param name="id">The auxiliary hint ID.</param>
600         /// <param name="value">The value string to be set.</param>
601         /// <returns>True if no error occurred, false otherwise.</returns>
602         /// <since_tizen> 3 </since_tizen>
603         public bool SetAuxiliaryHintValue(uint id, string value)
604         {
605             bool ret = Interop.Window.SetAuxiliaryHintValue(SwigCPtr, id, value);
606             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
607             return ret;
608         }
609
610         /// <summary>
611         /// Gets a value of the auxiliary hint.
612         /// </summary>
613         /// <param name="id">The auxiliary hint ID.</param>
614         /// <returns>The string value of the auxiliary hint ID, or an empty string if none exists.</returns>
615         /// <since_tizen> 3 </since_tizen>
616         public string GetAuxiliaryHintValue(uint id)
617         {
618             string ret = Interop.Window.GetAuxiliaryHintValue(SwigCPtr, id);
619             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
620             return ret;
621         }
622
623         /// <summary>
624         /// Gets an ID of the auxiliary hint string.
625         /// </summary>
626         /// <param name="hint">The auxiliary hint string.</param>
627         /// <returns>The ID of auxiliary hint string, or 0 on failure.</returns>
628         /// <since_tizen> 3 </since_tizen>
629         public uint GetAuxiliaryHintId(string hint)
630         {
631             uint ret = Interop.Window.GetAuxiliaryHintId(SwigCPtr, hint);
632             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
633             return ret;
634         }
635
636         /// <summary>
637         /// Sets a region to accept input events.
638         /// </summary>
639         /// <param name="inputRegion">The region to accept input events.</param>
640         /// <since_tizen> 3 </since_tizen>
641         public void SetInputRegion(Rectangle inputRegion)
642         {
643             Interop.Window.SetInputRegion(SwigCPtr, Rectangle.getCPtr(inputRegion));
644             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
645         }
646
647         /// <summary>
648         /// Sets a priority level for the specified notification window.
649         /// </summary>
650         /// <param name="level">The notification window level.</param>
651         /// <returns>True if no error occurred, false otherwise.</returns>
652         /// <since_tizen> 3 </since_tizen>
653         public bool SetNotificationLevel(NotificationLevel level)
654         {
655             bool ret = Interop.Window.SetNotificationLevel(SwigCPtr, (int)level);
656             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
657             return ret;
658         }
659
660         /// <summary>
661         /// Gets a priority level for the specified notification window.
662         /// </summary>
663         /// <returns>The notification window level.</returns>
664         /// <since_tizen> 3 </since_tizen>
665         public NotificationLevel GetNotificationLevel()
666         {
667             NotificationLevel ret = (NotificationLevel)Interop.Window.GetNotificationLevel(SwigCPtr);
668             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
669             return ret;
670         }
671
672         /// <summary>
673         /// Sets a transparent window's visual state to opaque. <br />
674         /// If a visual state of a transparent window is opaque, <br />
675         /// then the window manager could handle it as an opaque window when calculating visibility.
676         /// </summary>
677         /// <param name="opaque">Whether the window's visual state is opaque.</param>
678         /// <remarks>This will have no effect on an opaque window. <br />
679         /// It doesn't change transparent window to opaque window but lets the window manager know the visual state of the window.
680         /// </remarks>
681         /// <since_tizen> 3 </since_tizen>
682         public void SetOpaqueState(bool opaque)
683         {
684             Interop.Window.SetOpaqueState(SwigCPtr, opaque);
685             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
686         }
687
688         /// <summary>
689         /// Returns whether a transparent window's visual state is opaque or not.
690         /// </summary>
691         /// <returns>True if the window's visual state is opaque, false otherwise.</returns>
692         /// <remarks> The return value has no meaning on an opaque window. </remarks>
693         /// <since_tizen> 3 </since_tizen>
694         public bool IsOpaqueState()
695         {
696             bool ret = Interop.Window.IsOpaqueState(SwigCPtr);
697             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
698             return ret;
699         }
700
701         /// <summary>
702         /// Sets a window's screen off mode.
703         /// </summary>
704         /// <param name="screenOffMode">The screen mode.</param>
705         /// <returns>True if no error occurred, false otherwise.</returns>
706         /// <since_tizen> 4 </since_tizen>
707         public bool SetScreenOffMode(ScreenOffMode screenOffMode)
708         {
709             bool ret = Interop.Window.SetScreenOffMode(SwigCPtr, (int)screenOffMode);
710             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
711             return ret;
712         }
713
714         /// <summary>
715         /// Gets the screen mode of the window.
716         /// </summary>
717         /// <returns>The screen off mode.</returns>
718         /// <since_tizen> 4 </since_tizen>
719         public ScreenOffMode GetScreenOffMode()
720         {
721             ScreenOffMode ret = (ScreenOffMode)Interop.Window.GetScreenOffMode(SwigCPtr);
722             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
723             return ret;
724         }
725
726         /// <summary>
727         /// Sets preferred brightness of the window.
728         /// </summary>
729         /// <param name="brightness">The preferred brightness (0 to 100).</param>
730         /// <returns>True if no error occurred, false otherwise.</returns>
731         /// <since_tizen> 3 </since_tizen>
732         public bool SetBrightness(int brightness)
733         {
734             bool ret = Interop.Window.SetBrightness(SwigCPtr, brightness);
735             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
736             return ret;
737         }
738
739         /// <summary>
740         /// Gets the preferred brightness of the window.
741         /// </summary>
742         /// <returns>The preferred brightness.</returns>
743         /// <since_tizen> 3 </since_tizen>
744         public int GetBrightness()
745         {
746             int ret = Interop.Window.GetBrightness(SwigCPtr);
747             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
748             return ret;
749         }
750
751         /// <summary>
752         /// Sets the window name and the class string.
753         /// </summary>
754         /// <param name="name">The name of the window.</param>
755         /// <param name="klass">The class of the window.</param>
756         /// <since_tizen> 4 </since_tizen>
757         public void SetClass(string name, string klass)
758         {
759             Interop.Window.SetClass(SwigCPtr, name, klass);
760             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
761         }
762
763         /// <summary>
764         /// Raises the window to the top of the window stack.
765         /// </summary>
766         /// <since_tizen> 3 </since_tizen>
767         public void Raise()
768         {
769             Interop.Window.Raise(SwigCPtr);
770             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
771         }
772
773         /// <summary>
774         /// Lowers the window to the bottom of the window stack.
775         /// </summary>
776         /// <since_tizen> 3 </since_tizen>
777         public void Lower()
778         {
779             Interop.Window.Lower(SwigCPtr);
780             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
781         }
782
783         /// <summary>
784         /// Activates the window to the top of the window stack even it is iconified.
785         /// </summary>
786         /// <since_tizen> 3 </since_tizen>
787         public void Activate()
788         {
789             Interop.Window.Activate(SwigCPtr);
790             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
791         }
792
793         /// <summary>
794         /// Gets the default ( root ) layer.
795         /// </summary>
796         /// <returns>The root layer.</returns>
797         /// <since_tizen> 3 </since_tizen>
798         public Layer GetDefaultLayer()
799         {
800             return this.GetRootLayer();
801         }
802
803         /// <summary>
804         /// Add a child view to window.
805         /// </summary>
806         /// <param name="view">the child should be added to the window.</param>
807         /// <since_tizen> 3 </since_tizen>
808         public void Add(View view)
809         {
810             Interop.Actor.Add(Layer.getCPtr(GetRootLayer()), View.getCPtr(view));
811             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
812             this.GetRootLayer().AddViewToLayerList(view); // Maintain the children list in the Layer
813             if (null != view)
814             {
815                 view.InternalParent = this.GetRootLayer();
816             }
817         }
818
819         /// <summary>
820         /// Remove a child view from window.
821         /// </summary>
822         /// <param name="view">the child to be removed.</param>
823         /// <since_tizen> 3 </since_tizen>
824         public void Remove(View view)
825         {
826             Interop.Actor.Remove(Layer.getCPtr(GetRootLayer()), View.getCPtr(view));
827             this.GetRootLayer().RemoveViewFromLayerList(view); // Maintain the children list in the Layer
828             if (null != view)
829             {
830                 view.InternalParent = null;
831             }
832         }
833
834         /// <summary>
835         /// Retrieves the layer at a specified depth.
836         /// </summary>
837         /// <param name="depth">The layer's depth index.</param>
838         /// <returns>The layer found at the given depth.</returns>
839         /// <since_tizen> 3 </since_tizen>
840         public Layer GetLayer(uint depth)
841         {
842             if (depth < LayersChildren?.Count)
843             {
844                 Layer ret = LayersChildren?[Convert.ToInt32(depth)];
845                 return ret;
846             }
847             else
848             {
849                 return null;
850             }
851         }
852
853         /// <summary>
854         /// Destroy the window immediately.
855         /// </summary>
856         [EditorBrowsable(EditorBrowsableState.Never)]
857         public void Destroy()
858         {
859             this.Dispose();
860         }
861
862         /// <summary>
863         /// Keep rendering for at least the given amount of time.
864         /// </summary>
865         /// <param name="durationSeconds">Time to keep rendering, 0 means render at least one more frame.</param>
866         /// <since_tizen> 3 </since_tizen>
867         public void KeepRendering(float durationSeconds)
868         {
869             Interop.Stage.KeepRendering(stageCPtr, durationSeconds);
870             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
871         }
872
873         /// <summary>
874         /// Grabs the key specified by a key for a window only when a window is the topmost window.<br />
875         /// This function can be used for following example scenarios: <br />
876         /// - Mobile - Using volume up or down as zoom up or down in camera apps.<br />
877         /// </summary>
878         /// <param name="DaliKey">The key code to grab.</param>
879         /// <returns>True if the grab succeeds.</returns>
880         /// <since_tizen> 3 </since_tizen>
881         public bool GrabKeyTopmost(int DaliKey)
882         {
883             bool ret = Interop.Window.GrabKeyTopmost(HandleRef.ToIntPtr(this.SwigCPtr), DaliKey);
884             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
885             return ret;
886         }
887
888         /// <summary>
889         /// Ungrabs the key specified by a key for the window.<br />
890         /// 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 />
891         /// </summary>
892         /// <param name="DaliKey">The key code to ungrab.</param>
893         /// <returns>True if the ungrab succeeds.</returns>
894         /// <since_tizen> 3 </since_tizen>
895         public bool UngrabKeyTopmost(int DaliKey)
896         {
897             bool ret = Interop.Window.UngrabKeyTopmost(HandleRef.ToIntPtr(this.SwigCPtr), DaliKey);
898             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
899             return ret;
900         }
901
902         /// <summary>
903         ///  Grabs the key specified by a key for a window in a GrabMode. <br />
904         ///  Details: This function can be used for following example scenarios: <br />
905         ///  - TV - A user might want to change the volume or channel of the background TV contents while focusing on the foregrund app. <br />
906         ///  - Mobile - When a user presses the Home key, the homescreen appears regardless of the current foreground app. <br />
907         ///  - Mobile - Using the volume up or down as zoom up or down in camera apps. <br />
908         /// </summary>
909         /// <param name="DaliKey">The key code to grab.</param>
910         /// <param name="GrabMode">The grab mode for the key.</param>
911         /// <returns>True if the grab succeeds.</returns>
912         /// <since_tizen> 3 </since_tizen>
913         public bool GrabKey(int DaliKey, KeyGrabMode GrabMode)
914         {
915             bool ret = Interop.Window.GrabKey(HandleRef.ToIntPtr(this.SwigCPtr), DaliKey, (int)GrabMode);
916             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
917             return ret;
918         }
919
920         /// <summary>
921         /// Ungrabs the key specified by a key for a window.<br />
922         /// 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 />
923         /// </summary>
924         /// <param name="DaliKey">The key code to ungrab.</param>
925         /// <returns>True if the ungrab succeeds.</returns>
926         /// <since_tizen> 3 </since_tizen>
927         public bool UngrabKey(int DaliKey)
928         {
929             bool ret = Interop.Window.UngrabKey(HandleRef.ToIntPtr(this.SwigCPtr), DaliKey);
930             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
931             return ret;
932         }
933
934         /// <summary>
935         /// Sets the keyboard repeat information.
936         /// </summary>
937         /// <param name="rate">The key repeat rate value in seconds.</param>
938         /// <param name="delay">The key repeat delay value in seconds.</param>
939         /// <returns>True if setting the keyboard repeat succeeds.</returns>
940         /// <since_tizen> 5 </since_tizen>
941         public bool SetKeyboardRepeatInfo(float rate, float delay)
942         {
943             bool ret = Interop.Window.SetKeyboardRepeatInfo(rate, delay);
944             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
945             return ret;
946         }
947
948         /// <summary>
949         /// Gets the keyboard repeat information.
950         /// </summary>
951         /// <param name="rate">The key repeat rate value in seconds.</param>
952         /// <param name="delay">The key repeat delay value in seconds.</param>
953         /// <returns>True if setting the keyboard repeat succeeds.</returns>
954         /// <since_tizen> 5 </since_tizen>
955         public bool GetKeyboardRepeatInfo(out float rate, out float delay)
956         {
957             bool ret = Interop.Window.GetKeyboardRepeatInfo(out rate, out delay);
958             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
959             return ret;
960         }
961
962         /// <summary>
963         /// Adds a layer to the stage.
964         /// </summary>
965         /// <param name="layer">Layer to add.</param>
966         /// <exception cref="ArgumentNullException"> Thrown when layer is null. </exception>
967         /// <since_tizen> 3 </since_tizen>
968         public void AddLayer(Layer layer)
969         {
970             Add(layer);
971         }
972
973         /// <summary>
974         /// Removes a layer from the stage.
975         /// </summary>
976         /// <param name="layer">Layer to remove.</param>
977         /// <exception cref="ArgumentNullException"> Thrown when layer is null. </exception>
978         /// <since_tizen> 3 </since_tizen>
979         public void RemoveLayer(Layer layer)
980         {
981             Remove(layer);
982         }
983
984         /// <summary>
985         /// Feeds a key event into the window.
986         /// </summary>
987         /// <param name="keyEvent">The key event to feed.</param>
988         /// <since_tizen> 5 </since_tizen>
989         public void FeedKey(Key keyEvent)
990         {
991             Interop.Window.FeedKeyEvent(Key.getCPtr(keyEvent));
992             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
993         }
994
995         /// <summary>
996         /// Allows at least one more render, even when paused.
997         /// The window should be shown, not minimised.
998         /// </summary>
999         /// <since_tizen> 4 </since_tizen>
1000         public void RenderOnce()
1001         {
1002             Interop.Window.RenderOnce(SwigCPtr);
1003             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1004         }
1005
1006         /// <summary>
1007         /// Sets whether the window is transparent or not.
1008         /// </summary>
1009         /// <param name="transparent">Whether the window is transparent or not.</param>
1010         /// <since_tizen> 5 </since_tizen>
1011         public void SetTransparency(bool transparent)
1012         {
1013             Interop.Window.SetTransparency(SwigCPtr, transparent);
1014             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1015
1016             // Setting transparency of the window should request a relayout of the tree in the case the window changes from fully transparent.
1017         }
1018
1019         /// <summary>
1020         /// Sets parent window of the window.
1021         /// After setting that, these windows do together when raise-up, lower and iconified/deiconified.
1022         /// Initially, the window is located on top of the parent. The window can go below parent by calling Lower().
1023         /// If parent's window stack is changed by calling Raise() or Lower(), child windows are located on top of the parent again.
1024         /// </summary>
1025         /// <param name="parent">The parent window.</param>
1026         /// <since_tizen> 6 </since_tizen>
1027         /// <feature> http://tizen.org/feature/opengles.surfaceless_context </feature>
1028         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
1029         public void SetParent(Window parent)
1030         {
1031             if (IsSupportedMultiWindow() == false)
1032             {
1033                 NUILog.Error("This device does not support surfaceless_context. So Window cannot be created. ");
1034             }
1035             Interop.Window.SetParent(SwigCPtr, Window.getCPtr(parent));
1036             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1037         }
1038
1039         /// <summary>
1040         /// Unsets parent window of the window.
1041         /// After unsetting, the window is disconnected his parent window.
1042         /// </summary>
1043         /// <since_tizen> 6 </since_tizen>
1044         /// <feature> http://tizen.org/feature/opengles.surfaceless_context </feature>
1045         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
1046         public void Unparent()
1047         {
1048             if (IsSupportedMultiWindow() == false)
1049             {
1050                 NUILog.Error("Fail to create window. because this device does not support opengles.surfaceless_context.");
1051             }
1052             Interop.Window.Unparent(SwigCPtr);
1053             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1054         }
1055
1056         /// <summary>
1057         /// Gets parent window of the window.
1058         /// </summary>
1059         /// <returns>The parent window of the window.</returns>
1060         /// <since_tizen> 6 </since_tizen>
1061         /// <feature> http://tizen.org/feature/opengles.surfaceless_context </feature>
1062         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
1063         public Window GetParent()
1064         {
1065             if (IsSupportedMultiWindow() == false)
1066             {
1067                 NUILog.Error("This device does not support surfaceless_context. So Window cannot be created. ");
1068             }
1069             Window ret = Registry.GetManagedBaseHandleFromNativePtr(Interop.Window.GetParent(SwigCPtr)) as Window;
1070             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1071             return ret;
1072         }
1073
1074         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
1075         [EditorBrowsable(EditorBrowsableState.Never)]
1076         public void ObjectDump()
1077         {
1078             Layer rootLayer = GetRootLayer();
1079             foreach (View view in rootLayer.Children)
1080             {
1081                 view.ObjectDump();
1082             }
1083         }
1084
1085         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Window obj)
1086         {
1087             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
1088         }
1089
1090         internal static bool IsInstalled()
1091         {
1092             bool ret = Interop.Stage.IsInstalled();
1093             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1094             return ret;
1095         }
1096
1097         /// <summary>
1098         /// Adds an orientation to the list of available orientations.
1099         /// </summary>
1100         /// <param name="orientation">The available orientation to add</param>
1101         /// <since_tizen> 6 </since_tizen>
1102         public void AddAvailableOrientation(Window.WindowOrientation orientation)
1103         {
1104             Interop.Window.AddAvailableOrientation(SwigCPtr, (int)orientation);
1105             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1106         }
1107
1108         /// <summary>
1109         /// Removes an orientation from the list of available orientations.
1110         /// </summary>
1111         /// <param name="orientation">The available orientation to remove.</param>
1112         /// <since_tizen> 6 </since_tizen>
1113         public void RemoveAvailableOrientation(Window.WindowOrientation orientation)
1114         {
1115             Interop.Window.RemoveAvailableOrientation(SwigCPtr, (int)orientation);
1116             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1117         }
1118
1119         /// <summary>
1120         /// Sets a preferred orientation.
1121         /// </summary>
1122         /// <param name="orientation">The preferred orientation.</param>
1123         /// <since_tizen> 6 </since_tizen>
1124         public void SetPreferredOrientation(Window.WindowOrientation orientation)
1125         {
1126             Interop.Window.SetPreferredOrientation(SwigCPtr, (int)orientation);
1127             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1128         }
1129
1130         /// <summary>
1131         /// Gets the preferred orientation.
1132         /// </summary>
1133         /// <since_tizen> 6 </since_tizen>
1134         /// <returns>The preferred orientation if previously set, or none.</returns>
1135         public Window.WindowOrientation GetPreferredOrientation()
1136         {
1137             Window.WindowOrientation ret = (Window.WindowOrientation)Interop.Window.GetPreferredOrientation(SwigCPtr);
1138             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1139             return ret;
1140         }
1141
1142         /// <summary>
1143         /// Gets current orientation of the window.
1144         /// </summary>
1145         /// <since_tizen> 6 </since_tizen>
1146         /// <returns>The current window orientation if previously set, or none.</returns>
1147         [EditorBrowsable(EditorBrowsableState.Never)]
1148         public Window.WindowOrientation GetCurrentOrientation()
1149         {
1150             Window.WindowOrientation ret = (Window.WindowOrientation)Interop.Window.GetCurrentOrientation(SwigCPtr);
1151             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1152             return ret;
1153         }
1154
1155         /// <summary>
1156         /// Sets available orientations of the window.
1157         /// This API is for setting several orientations one time.
1158         /// </summary>
1159         /// <param name="orientations">The list of orientations.</param>
1160         /// <since_tizen> 6 </since_tizen>
1161         [EditorBrowsable(EditorBrowsableState.Never)]
1162         public void SetAvailableOrientations(List<Window.WindowOrientation> orientations)
1163         {
1164             PropertyArray orientationArray = new PropertyArray();
1165             if (null != orientations)
1166             {
1167                 for (int i = 0; i < orientations.Count; i++)
1168                 {
1169                     PropertyValue value = new PropertyValue((int)orientations[i]);
1170                     orientationArray.PushBack(value);
1171                     value.Dispose();
1172                 }
1173             }
1174
1175             Interop.Window.SetAvailableOrientations(SwigCPtr, PropertyArray.getCPtr(orientationArray));
1176             orientationArray.Dispose();
1177             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1178         }
1179
1180         /// <summary>
1181         /// Get native window ID
1182         /// </summary>
1183         /// <returns>native window ID</returns>
1184         [EditorBrowsable(EditorBrowsableState.Never)]
1185         public int GetNativeId()
1186         {
1187             int ret = Interop.Window.GetNativeId(SwigCPtr);
1188             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1189             return ret;
1190         }
1191
1192         internal Any GetNativeHandle()
1193         {
1194             Any ret = new Any(Interop.WindowInternal.WindowGetNativeHandle(SwigCPtr), true);
1195             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1196             return ret;
1197         }
1198
1199         internal void Add(Layer layer)
1200         {
1201             if (null == layer)
1202             {
1203                 throw new ArgumentNullException(nameof(layer));
1204             }
1205             Interop.Window.Add(SwigCPtr, Layer.getCPtr(layer));
1206             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1207
1208             LayersChildren?.Add(layer);
1209             layer.SetWindow(this);
1210         }
1211
1212         internal void Remove(Layer layer)
1213         {
1214             if (null == layer)
1215             {
1216                 throw new ArgumentNullException(nameof(layer));
1217             }
1218             Interop.Window.Remove(SwigCPtr, Layer.getCPtr(layer));
1219             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1220
1221             LayersChildren?.Remove(layer);
1222             layer.SetWindow(null);
1223         }
1224
1225         internal Vector2 GetSize()
1226         {
1227             var val = new Uint16Pair(Interop.Window.GetSize(SwigCPtr), false);
1228             Vector2 ret = new Vector2(val.GetWidth(), val.GetHeight());
1229             val.Dispose();
1230             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1231             return ret;
1232         }
1233
1234         internal RenderTaskList GetRenderTaskList()
1235         {
1236             RenderTaskList ret = new RenderTaskList(Interop.Stage.GetRenderTaskList(stageCPtr), true);
1237             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1238             return ret;
1239         }
1240
1241         /// <summary>
1242         /// Queries the number of on-window layers.
1243         /// </summary>
1244         /// <returns>The number of layers.</returns>
1245         /// <remarks>Note that a default layer is always provided (count >= 1).</remarks>
1246         internal uint GetLayerCount()
1247         {
1248             if (LayersChildren == null || LayersChildren.Count < 0)
1249                 return 0;
1250
1251             return (uint)LayersChildren.Count;
1252         }
1253
1254         internal Layer GetRootLayer()
1255         {
1256             // Window.IsInstalled() is actually true only when called from event thread and
1257             // Core has been initialized, not when Stage is ready.
1258             if (_rootLayer == null && Window.IsInstalled())
1259             {
1260                 _rootLayer = new Layer(Interop.Window.GetRootLayer(SwigCPtr), true);
1261                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1262                 LayersChildren?.Add(_rootLayer);
1263                 _rootLayer.SetWindow(this);
1264             }
1265             return _rootLayer;
1266         }
1267
1268         internal void SetBackgroundColor(Vector4 color)
1269         {
1270             Interop.Window.SetBackgroundColor(SwigCPtr, Vector4.getCPtr(color));
1271             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1272         }
1273
1274         internal Vector4 GetBackgroundColor()
1275         {
1276             Vector4 ret = new Vector4(Interop.Window.GetBackgroundColor(SwigCPtr), true);
1277             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1278             return ret;
1279         }
1280
1281         internal Vector2 GetDpi()
1282         {
1283             Vector2 ret = new Vector2(Interop.Stage.GetDpi(stageCPtr), true);
1284             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1285             return ret;
1286         }
1287
1288         internal ObjectRegistry GetObjectRegistry()
1289         {
1290             ObjectRegistry ret = new ObjectRegistry(Interop.Stage.GetObjectRegistry(stageCPtr), true);
1291             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1292             return ret;
1293         }
1294
1295         internal void SetRenderingBehavior(RenderingBehaviorType renderingBehavior)
1296         {
1297             Interop.Stage.SetRenderingBehavior(stageCPtr, (int)renderingBehavior);
1298             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1299         }
1300
1301         internal RenderingBehaviorType GetRenderingBehavior()
1302         {
1303             RenderingBehaviorType ret = (RenderingBehaviorType)Interop.Stage.GetRenderingBehavior(stageCPtr);
1304             if (NDalicPINVOKE.SWIGPendingException.Pending)
1305                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1306             return ret;
1307         }
1308
1309         internal void SetWindowSize(Size2D size)
1310         {
1311             if (null == size)
1312             {
1313                 throw new ArgumentNullException(nameof(size));
1314             }
1315             var val = new Uint16Pair((uint)size.Width, (uint)size.Height);
1316             Interop.Window.SetSize(SwigCPtr, Uint16Pair.getCPtr(val));
1317             val.Dispose();
1318             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1319             // Resetting Window size should request a relayout of the tree.
1320         }
1321
1322         internal Size2D GetWindowSize()
1323         {
1324             var val = new Uint16Pair(Interop.Window.GetSize(SwigCPtr), false);
1325             Size2D ret = new Size2D(val.GetWidth(), val.GetHeight());
1326             val.Dispose();
1327             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1328             return ret;
1329         }
1330
1331         internal void SetPosition(Position2D position)
1332         {
1333             if (null == position)
1334             {
1335                 throw new ArgumentNullException(nameof(position));
1336             }
1337             var val = new Uint16Pair((uint)position.X, (uint)position.Y);
1338             Interop.Window.SetPosition(SwigCPtr, Uint16Pair.getCPtr(val));
1339             val.Dispose();
1340             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1341             // Setting Position of the window should request a relayout of the tree.
1342         }
1343
1344         internal Position2D GetPosition()
1345         {
1346             var val = new Uint16Pair(Interop.Window.GetPosition(SwigCPtr), true);
1347             Position2D ret = new Position2D(val.GetX(), val.GetY());
1348             val.Dispose();
1349             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1350             return ret;
1351         }
1352
1353         internal void SetPositionSize(Rectangle positionSize)
1354         {
1355             Interop.Window.SetPositionSize(SwigCPtr, Rectangle.getCPtr(positionSize));
1356
1357             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1358
1359             // Setting Position of the window should request a relayout of the tree.
1360         }
1361
1362         /// <summary>
1363         /// Add FrameUpdateCallback
1364         /// </summary>
1365         [EditorBrowsable(EditorBrowsableState.Never)]
1366         public void AddFrameUpdateCallback(FrameUpdateCallbackInterface frameUpdateCallback)
1367         {
1368             frameUpdateCallback?.AddFrameUpdateCallback(stageCPtr, Layer.getCPtr(GetRootLayer()));
1369         }
1370
1371         /// <summary>
1372         /// Remove FrameUpdateCallback
1373         /// </summary>
1374         [EditorBrowsable(EditorBrowsableState.Never)]
1375         public void RemoveFrameUpdateCallback(FrameUpdateCallbackInterface frameUpdateCallback)
1376         {
1377             frameUpdateCallback?.RemoveFrameUpdateCallback(stageCPtr);
1378         }
1379
1380         /// <summary>
1381         /// Dispose for Window
1382         /// </summary>
1383         [EditorBrowsable(EditorBrowsableState.Never)]
1384         protected override void Dispose(DisposeTypes type)
1385         {
1386             if (disposed)
1387             {
1388                 return;
1389             }
1390
1391             if (type == DisposeTypes.Explicit)
1392             {
1393                 //Called by User
1394                 //Release your own managed resources here.
1395                 //You should release all of your own disposable objects here.
1396
1397                 if (_rootLayer != null)
1398                 {
1399                     _rootLayer.Dispose();
1400                 }
1401
1402                 localController?.Dispose();
1403
1404                 foreach (var layer in _childLayers)
1405                 {
1406                     if (layer != null)
1407                     {
1408                         layer.Dispose();
1409                     }
1410                 }
1411
1412                 _childLayers.Clear();
1413             }
1414
1415             this.DisconnectNativeSignals();
1416
1417             base.Dispose(type);
1418         }
1419
1420         /// This will not be public opened.
1421         [EditorBrowsable(EditorBrowsableState.Never)]
1422         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1423         {
1424             Interop.Window.DeleteWindow(swigCPtr);
1425         }
1426
1427         private static Dictionary<int, internalHookCallbackType> frameCallbackList = new Dictionary<int, internalHookCallbackType>();
1428
1429         private static readonly object locker = new object();
1430
1431         private static int key = 0;
1432
1433         private static FrameCallbackType internalHookFrameCallback = OnInternalHookFrameCallback;
1434
1435         private struct internalHookCallbackType
1436         {
1437             public FrameCallbackType userCallback;
1438             public int frameId;
1439         }
1440
1441         private static void OnInternalHookFrameCallback(int id)
1442         {
1443             lock (locker)
1444             {
1445                 if (frameCallbackList.ContainsKey(id))
1446                 {
1447                     if (frameCallbackList[id].userCallback != null)
1448                     {
1449                         frameCallbackList[id].userCallback.Invoke(frameCallbackList[id].frameId);
1450                         frameCallbackList.Remove(id);
1451                     }
1452                     else
1453                     {
1454                         NUILog.Error($"found userCallback is NULL");
1455                         frameCallbackList.Remove(id);
1456                     }
1457                 }
1458             }
1459         }
1460
1461         private int AddInterHookCallback(FrameCallbackType callback, int frameId)
1462         {
1463             if (null == callback)
1464             {
1465                 throw new ArgumentNullException(nameof(callback), "FrameCallbackType should not be null");
1466             }
1467             var assignedKey = 0;
1468             lock (locker)
1469             {
1470                 key++;
1471                 assignedKey = key;
1472                 frameCallbackList.Add(assignedKey, new internalHookCallbackType()
1473                 {
1474                     userCallback = callback,
1475                     frameId = frameId,
1476                 });
1477             }
1478             return assignedKey;
1479         }
1480
1481         /// <summary>
1482         /// Type of callback which is called when the frame rendering is done by graphics driver or when the frame is displayed on display.
1483         /// </summary>
1484         /// <param name="frameId">The Id to specify the frame. It will be passed when the callback is called.</param>
1485         [EditorBrowsable(EditorBrowsableState.Never)]
1486         public delegate void FrameCallbackType(int frameId);
1487
1488         /// <summary>
1489         /// Adds a callback that is called when the frame rendering is done by the graphics driver.
1490         /// A callback of the following type may be used:
1491         /// <code>
1492         /// void MyFunction( int frameId )
1493         /// </code>
1494         /// This callback will be deleted once it is called.
1495         /// <remarks>
1496         /// Ownership of the callback is passed onto this class
1497         /// </remarks>
1498         /// </summary>
1499         /// <param name="callback">The function to call</param>
1500         /// <param name="frameId">The Id to specify the frame. It will be passed when the callback is called.</param>
1501         /// <exception cref="ArgumentNullException">This exception can occur by the callback is null.</exception>
1502         [EditorBrowsable(EditorBrowsableState.Never)]
1503         public void AddFrameRenderedCallback(FrameCallbackType callback, int frameId)
1504         {
1505             var assignedKey = AddInterHookCallback(callback, frameId);
1506             Interop.WindowInternal.AddFrameRenderedCallback(SwigCPtr, new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(internalHookFrameCallback)), assignedKey);
1507
1508             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1509         }
1510
1511         /// <summary>
1512         /// Adds a callback that is called when the frame is displayed on the display.
1513         /// A callback of the following type may be used:
1514         /// <code>
1515         /// void MyFunction( int frameId )
1516         /// </code>
1517         /// This callback will be deleted once it is called.
1518         /// <remarks>
1519         /// Ownership of the callback is passed onto this class
1520         /// </remarks>
1521         /// </summary>
1522         /// <param name="callback">The function to call</param>
1523         /// <param name="frameId">The Id to specify the frame. It will be passed when the callback is called.</param>
1524         /// <exception cref="ArgumentNullException">This exception can occur by the callback is null.</exception>
1525         [EditorBrowsable(EditorBrowsableState.Never)]
1526         public void AddFramePresentedCallback(FrameCallbackType callback, int frameId)
1527         {
1528             var assignedKey = AddInterHookCallback(callback, frameId);
1529             Interop.WindowInternal.AddFramePresentedCallback(SwigCPtr, new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(internalHookFrameCallback)), assignedKey);
1530
1531             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1532         }
1533     }
1534 }