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