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