2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 extern alias TizenSystemInformation;
19 using TizenSystemInformation.Tizen.System;
21 using System.ComponentModel;
22 using System.Collections.Generic;
23 using global::System.Runtime.InteropServices;
24 using Tizen.NUI.BaseComponents;
29 /// The window class is used internally for drawing.<br />
30 /// The window has an orientation and indicator properties.<br />
32 /// <since_tizen> 3 </since_tizen>
33 public partial class Window : BaseHandle
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;
42 private bool IsSupportedMultiWindow()
44 bool isSupported = false;
45 Information.TryGetValue("http://tizen.org/feature/opengles.surfaceless_context", out isSupported);
49 internal Window(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Window.Window_SWIGUpcast(cPtr), cMemoryOwn)
51 if (Interop.Stage.Stage_IsInstalled())
53 stageCPtr = new global::System.Runtime.InteropServices.HandleRef(this, Interop.Stage.Stage_GetCurrent());
55 localController = new LayoutController(this);
56 NUILog.Debug("layoutController id:" + localController.GetId());
61 /// Creates a new Window.<br />
62 /// This creates an extra window in addition to the default main window<br />
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)
72 if (IsSupportedMultiWindow() == false)
74 NUILog.Error("This device does not support surfaceless_context. So Window cannot be created. ");
76 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
80 /// Creates a new Window with a specific name.<br />
81 /// This creates an extra window in addition to the default main window<br />
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)
92 if (IsSupportedMultiWindow() == false)
94 NUILog.Error("This device does not support surfaceless_context. So Window cannot be created. ");
96 this._windowTitle = name;
97 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
101 /// Enumeration for orientation of the window is the way in which a rectangular page is oriented for normal viewing.
103 /// <since_tizen> 3 </since_tizen>
104 public enum WindowOrientation
107 /// Portrait orientation. The height of the display area is greater than the width.
109 /// <since_tizen> 3 </since_tizen>
112 /// Landscape orientation. A wide view area is needed.
114 /// <since_tizen> 3 </since_tizen>
117 /// Portrait inverse orientation.
119 /// <since_tizen> 3 </since_tizen>
120 PortraitInverse = 180,
122 /// Landscape inverse orientation.
124 /// <since_tizen> 3 </since_tizen>
125 LandscapeInverse = 270,
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.
131 [EditorBrowsable(EditorBrowsableState.Never)]
132 NoOrientationPreference = -1
136 /// Enumeration for the key grab mode for platform-level APIs.
138 /// <since_tizen> 3 </since_tizen>
139 public enum KeyGrabMode
142 /// Grabs a key only when on the top of the grabbing-window stack mode.
146 /// Grabs a key together with the other client window(s) mode.
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.
154 /// Grabs a key exclusively regardless of the grabbing-window's position on the window stack mode.
160 /// Enumeration for transition effect's state.
162 [EditorBrowsable(EditorBrowsableState.Never)]
163 public enum EffectStates
168 [EditorBrowsable(EditorBrowsableState.Never)]
171 /// Transition effect is started.
173 [EditorBrowsable(EditorBrowsableState.Never)]
176 /// Transition effect is ended.
178 [EditorBrowsable(EditorBrowsableState.Never)]
183 /// Enumeration for transition effect's type.
185 [EditorBrowsable(EditorBrowsableState.Never)]
186 public enum EffectTypes
191 [EditorBrowsable(EditorBrowsableState.Never)]
194 /// Window show effect.
196 [EditorBrowsable(EditorBrowsableState.Never)]
199 /// Window hide effect.
201 [EditorBrowsable(EditorBrowsableState.Never)]
206 /// The stage instance property (read-only).<br />
207 /// Gets the current window.<br />
209 /// <since_tizen> 3 </since_tizen>
210 public static Window Instance
219 /// Gets or sets a window type.
221 /// <since_tizen> 3 </since_tizen>
222 public WindowType Type
226 WindowType ret = (WindowType)Interop.Window.GetType(swigCPtr);
227 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
232 Interop.Window.SetType(swigCPtr, (int)value);
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 /// Gets/Sets a window title.
240 /// <since_tizen> 4 </since_tizen>
249 _windowTitle = value;
250 SetClass(_windowTitle, "");
255 /// The rendering behavior of a Window.
257 /// <since_tizen> 5 </since_tizen>
258 public RenderingBehaviorType RenderingBehavior
262 return GetRenderingBehavior();
266 SetRenderingBehavior(value);
271 /// The window size property (read-only).
273 /// <since_tizen> 3 </since_tizen>
278 Size2D ret = GetSize();
284 /// The background color property.
286 /// <since_tizen> 3 </since_tizen>
287 public Color BackgroundColor
291 SetBackgroundColor(value);
295 Color ret = GetBackgroundColor();
301 /// The DPI property (read-only).<br />
302 /// Retrieves the DPI of the display device to which the Window is connected.<br />
304 /// <since_tizen> 3 </since_tizen>
314 /// The layer count property (read-only).<br />
315 /// Queries the number of on-Window layers.<br />
317 /// <since_tizen> 3 </since_tizen>
318 public uint LayerCount
322 return GetLayerCount();
327 /// Gets or sets a size of the window.
329 /// <exception cref="ArgumentNullException"> Thrown when value is null. </exception>
330 /// <since_tizen> 4 </since_tizen>
331 public Size2D WindowSize
335 return GetWindowSize();
339 SetWindowSize(value);
344 /// Gets or sets a position of the window.
346 /// <exception cref="ArgumentNullException"> Thrown when value is null. </exception>
347 /// <since_tizen> 4 </since_tizen>
348 public Position2D WindowPosition
352 return GetPosition();
361 /// Sets position and size of the window. This API guarantees that
362 /// both moving and resizing of window will appear on the screen at once.
364 [EditorBrowsable(EditorBrowsableState.Never)]
365 public Rectangle WindowPositionSize
369 Position2D position = GetPosition();
370 Size2D size = GetSize();
371 Rectangle ret = new Rectangle(position.X, position.Y, size.Width, size.Height);
376 SetPositionSize(value);
380 internal static Vector4 DEFAULT_BACKGROUND_COLOR
384 global::System.IntPtr cPtr = Interop.Stage.Stage_DEFAULT_BACKGROUND_COLOR_get();
385 Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false);
386 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391 internal static Vector4 DEBUG_BACKGROUND_COLOR
395 global::System.IntPtr cPtr = Interop.Stage.Stage_DEBUG_BACKGROUND_COLOR_get();
396 Vector4 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector4(cPtr, false);
397 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
402 internal List<Layer> LayersChildren
411 /// Get the LayoutController for this Window.
413 internal LayoutController LayoutController
417 return localController;
422 /// Feed a key-event into the window.
424 /// <param name="keyEvent">The key event to feed.</param>
425 /// <since_tizen> 4 </since_tizen>
426 [Obsolete("Please do not use! This will be deprecated! Please use FeedKey(Key keyEvent) instead!")]
427 public static void FeedKeyEvent(Key keyEvent)
429 Interop.Window.Window_FeedKeyEvent(Key.getCPtr(keyEvent));
430 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
434 /// Sets whether the window accepts a focus or not.
436 /// <param name="accept">If a focus is accepted or not. The default is true.</param>
437 /// <since_tizen> 3 </since_tizen>
438 public void SetAcceptFocus(bool accept)
440 Interop.Window.SetAcceptFocus(swigCPtr, accept);
441 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
445 /// Returns whether the window accepts a focus or not.
447 /// <returns>True if the window accepts a focus, false otherwise.</returns>
448 /// <since_tizen> 3 </since_tizen>
449 public bool IsFocusAcceptable()
451 bool ret = Interop.Window.IsFocusAcceptable(swigCPtr);
452 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
458 /// Shows the window if it is hidden.
460 /// <since_tizen> 3 </since_tizen>
463 Interop.Window.Show(swigCPtr);
464 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
468 /// Hides the window if it is showing.
470 /// <since_tizen> 3 </since_tizen>
473 Interop.Window.Hide(swigCPtr);
474 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
478 /// Retrieves whether the window is visible or not.
480 /// <returns>True if the window is visible.</returns>
481 /// <since_tizen> 3 </since_tizen>
482 public bool IsVisible()
484 bool temp = Interop.Window.IsVisible(swigCPtr);
485 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
490 /// Gets the count of supported auxiliary hints of the window.
492 /// <returns>The number of supported auxiliary hints.</returns>
493 /// <since_tizen> 3 </since_tizen>
494 public uint GetSupportedAuxiliaryHintCount()
496 uint ret = Interop.Window.GetSupportedAuxiliaryHintCount(swigCPtr);
497 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
502 /// Gets the supported auxiliary hint string of the window.
504 /// <param name="index">The index of the supported auxiliary hint lists.</param>
505 /// <returns>The auxiliary hint string of the index.</returns>
506 /// <since_tizen> 3 </since_tizen>
507 public string GetSupportedAuxiliaryHint(uint index)
509 string ret = Interop.Window.GetSupportedAuxiliaryHint(swigCPtr, index);
510 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
515 /// Creates an auxiliary hint of the window.
517 /// <param name="hint">The auxiliary hint string.</param>
518 /// <param name="value">The value string.</param>
519 /// <returns>The ID of created auxiliary hint, or 0 on failure.</returns>
520 /// <since_tizen> 3 </since_tizen>
521 public uint AddAuxiliaryHint(string hint, string value)
523 uint ret = Interop.Window.AddAuxiliaryHint(swigCPtr, hint, value);
524 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
529 /// Removes an auxiliary hint of the window.
531 /// <param name="id">The ID of the auxiliary hint.</param>
532 /// <returns>True if no error occurred, false otherwise.</returns>
533 /// <since_tizen> 3 </since_tizen>
534 public bool RemoveAuxiliaryHint(uint id)
536 bool ret = Interop.Window.RemoveAuxiliaryHint(swigCPtr, id);
537 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
542 /// Changes a value of the auxiliary hint.
544 /// <param name="id">The auxiliary hint ID.</param>
545 /// <param name="value">The value string to be set.</param>
546 /// <returns>True if no error occurred, false otherwise.</returns>
547 /// <since_tizen> 3 </since_tizen>
548 public bool SetAuxiliaryHintValue(uint id, string value)
550 bool ret = Interop.Window.SetAuxiliaryHintValue(swigCPtr, id, value);
551 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
556 /// Gets a value of the auxiliary hint.
558 /// <param name="id">The auxiliary hint ID.</param>
559 /// <returns>The string value of the auxiliary hint ID, or an empty string if none exists.</returns>
560 /// <since_tizen> 3 </since_tizen>
561 public string GetAuxiliaryHintValue(uint id)
563 string ret = Interop.Window.GetAuxiliaryHintValue(swigCPtr, id);
564 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
569 /// Gets an ID of the auxiliary hint string.
571 /// <param name="hint">The auxiliary hint string.</param>
572 /// <returns>The ID of auxiliary hint string, or 0 on failure.</returns>
573 /// <since_tizen> 3 </since_tizen>
574 public uint GetAuxiliaryHintId(string hint)
576 uint ret = Interop.Window.GetAuxiliaryHintId(swigCPtr, hint);
577 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
582 /// Sets a region to accept input events.
584 /// <param name="inputRegion">The region to accept input events.</param>
585 /// <since_tizen> 3 </since_tizen>
586 public void SetInputRegion(Rectangle inputRegion)
588 Interop.Window.SetInputRegion(swigCPtr, Rectangle.getCPtr(inputRegion));
589 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
593 /// Sets a priority level for the specified notification window.
595 /// <param name="level">The notification window level.</param>
596 /// <returns>True if no error occurred, false otherwise.</returns>
597 /// <since_tizen> 3 </since_tizen>
598 public bool SetNotificationLevel(NotificationLevel level)
600 bool ret = Interop.Window.SetNotificationLevel(swigCPtr, (int)level);
601 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
606 /// Gets a priority level for the specified notification window.
608 /// <returns>The notification window level.</returns>
609 /// <since_tizen> 3 </since_tizen>
610 public NotificationLevel GetNotificationLevel()
612 NotificationLevel ret = (NotificationLevel)Interop.Window.GetNotificationLevel(swigCPtr);
613 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
618 /// Sets a transparent window's visual state to opaque. <br />
619 /// If a visual state of a transparent window is opaque, <br />
620 /// then the window manager could handle it as an opaque window when calculating visibility.
622 /// <param name="opaque">Whether the window's visual state is opaque.</param>
623 /// <remarks>This will have no effect on an opaque window. <br />
624 /// It doesn't change transparent window to opaque window but lets the window manager know the visual state of the window.
626 /// <since_tizen> 3 </since_tizen>
627 public void SetOpaqueState(bool opaque)
629 Interop.Window.SetOpaqueState(swigCPtr, opaque);
630 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
634 /// Returns whether a transparent window's visual state is opaque or not.
636 /// <returns>True if the window's visual state is opaque, false otherwise.</returns>
637 /// <remarks> The return value has no meaning on an opaque window. </remarks>
638 /// <since_tizen> 3 </since_tizen>
639 public bool IsOpaqueState()
641 bool ret = Interop.Window.IsOpaqueState(swigCPtr);
642 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
647 /// Sets a window's screen off mode.
649 /// <param name="screenOffMode">The screen mode.</param>
650 /// <returns>True if no error occurred, false otherwise.</returns>
651 /// <since_tizen> 4 </since_tizen>
652 public bool SetScreenOffMode(ScreenOffMode screenOffMode)
654 bool ret = Interop.Window.SetScreenOffMode(swigCPtr, (int)screenOffMode);
655 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
660 /// Gets the screen mode of the window.
662 /// <returns>The screen off mode.</returns>
663 /// <since_tizen> 4 </since_tizen>
664 public ScreenOffMode GetScreenOffMode()
666 ScreenOffMode ret = (ScreenOffMode)Interop.Window.GetScreenOffMode(swigCPtr);
667 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
672 /// Sets preferred brightness of the window.
674 /// <param name="brightness">The preferred brightness (0 to 100).</param>
675 /// <returns>True if no error occurred, false otherwise.</returns>
676 /// <since_tizen> 3 </since_tizen>
677 public bool SetBrightness(int brightness)
679 bool ret = Interop.Window.SetBrightness(swigCPtr, brightness);
680 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
685 /// Gets the preferred brightness of the window.
687 /// <returns>The preferred brightness.</returns>
688 /// <since_tizen> 3 </since_tizen>
689 public int GetBrightness()
691 int ret = Interop.Window.GetBrightness(swigCPtr);
692 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
697 /// Sets the window name and the class string.
699 /// <param name="name">The name of the window.</param>
700 /// <param name="klass">The class of the window.</param>
701 /// <since_tizen> 4 </since_tizen>
702 public void SetClass(string name, string klass)
704 Interop.Window.Window_SetClass(swigCPtr, name, klass);
705 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
709 /// Raises the window to the top of the window stack.
711 /// <since_tizen> 3 </since_tizen>
714 Interop.Window.Window_Raise(swigCPtr);
715 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
719 /// Lowers the window to the bottom of the window stack.
721 /// <since_tizen> 3 </since_tizen>
724 Interop.Window.Window_Lower(swigCPtr);
725 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
729 /// Activates the window to the top of the window stack even it is iconified.
731 /// <since_tizen> 3 </since_tizen>
732 public void Activate()
734 Interop.Window.Window_Activate(swigCPtr);
735 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
739 /// Gets the default ( root ) layer.
741 /// <returns>The root layer.</returns>
742 /// <since_tizen> 3 </since_tizen>
743 public Layer GetDefaultLayer()
745 return this.GetRootLayer();
749 /// Add a child view to window.
751 /// <param name="view">the child should be added to the window.</param>
752 /// <since_tizen> 3 </since_tizen>
753 public void Add(View view)
755 Interop.Actor.Actor_Add(Layer.getCPtr(GetRootLayer()), View.getCPtr(view));
756 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
757 this.GetRootLayer().AddViewToLayerList(view); // Maintain the children list in the Layer
760 view.InternalParent = this.GetRootLayer();
765 /// Remove a child view from window.
767 /// <param name="view">the child to be removed.</param>
768 /// <since_tizen> 3 </since_tizen>
769 public void Remove(View view)
771 Interop.Actor.Actor_Remove(Layer.getCPtr(GetRootLayer()), View.getCPtr(view));
772 this.GetRootLayer().RemoveViewFromLayerList(view); // Maintain the children list in the Layer
775 view.InternalParent = null;
780 /// Retrieves the layer at a specified depth.
782 /// <param name="depth">The layer's depth index.</param>
783 /// <returns>The layer found at the given depth.</returns>
784 /// <since_tizen> 3 </since_tizen>
785 public Layer GetLayer(uint depth)
787 if (depth < LayersChildren?.Count)
789 Layer ret = LayersChildren?[Convert.ToInt32(depth)];
799 /// Destroy the window immediately.
801 [EditorBrowsable(EditorBrowsableState.Never)]
802 public void Destroy()
808 /// Keep rendering for at least the given amount of time.
810 /// <param name="durationSeconds">Time to keep rendering, 0 means render at least one more frame.</param>
811 /// <since_tizen> 3 </since_tizen>
812 public void KeepRendering(float durationSeconds)
814 Interop.Stage.Stage_KeepRendering(stageCPtr, durationSeconds);
815 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
819 /// Grabs the key specified by a key for a window only when a window is the topmost window.<br />
820 /// This function can be used for following example scenarios: <br />
821 /// - Mobile - Using volume up or down as zoom up or down in camera apps.<br />
823 /// <param name="DaliKey">The key code to grab.</param>
824 /// <returns>True if the grab succeeds.</returns>
825 /// <since_tizen> 3 </since_tizen>
826 public bool GrabKeyTopmost(int DaliKey)
828 bool ret = Interop.Window.GrabKeyTopmost(HandleRef.ToIntPtr(this.swigCPtr), DaliKey);
829 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
834 /// Ungrabs the key specified by a key for the window.<br />
835 /// 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 />
837 /// <param name="DaliKey">The key code to ungrab.</param>
838 /// <returns>True if the ungrab succeeds.</returns>
839 /// <since_tizen> 3 </since_tizen>
840 public bool UngrabKeyTopmost(int DaliKey)
842 bool ret = Interop.Window.UngrabKeyTopmost(HandleRef.ToIntPtr(this.swigCPtr), DaliKey);
843 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
848 /// Grabs the key specified by a key for a window in a GrabMode. <br />
849 /// Details: This function can be used for following example scenarios: <br />
850 /// - TV - A user might want to change the volume or channel of the background TV contents while focusing on the foregrund app. <br />
851 /// - Mobile - When a user presses the Home key, the homescreen appears regardless of the current foreground app. <br />
852 /// - Mobile - Using the volume up or down as zoom up or down in camera apps. <br />
854 /// <param name="DaliKey">The key code to grab.</param>
855 /// <param name="GrabMode">The grab mode for the key.</param>
856 /// <returns>True if the grab succeeds.</returns>
857 /// <since_tizen> 3 </since_tizen>
858 public bool GrabKey(int DaliKey, KeyGrabMode GrabMode)
860 bool ret = Interop.Window.GrabKey(HandleRef.ToIntPtr(this.swigCPtr), DaliKey, (int)GrabMode);
861 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
866 /// Ungrabs the key specified by a key for a window.<br />
867 /// 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 />
869 /// <param name="DaliKey">The key code to ungrab.</param>
870 /// <returns>True if the ungrab succeeds.</returns>
871 /// <since_tizen> 3 </since_tizen>
872 public bool UngrabKey(int DaliKey)
874 bool ret = Interop.Window.UngrabKey(HandleRef.ToIntPtr(this.swigCPtr), DaliKey);
875 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
880 /// Sets the keyboard repeat information.
882 /// <param name="rate">The key repeat rate value in seconds.</param>
883 /// <param name="delay">The key repeat delay value in seconds.</param>
884 /// <returns>True if setting the keyboard repeat succeeds.</returns>
885 /// <since_tizen> 5 </since_tizen>
886 public bool SetKeyboardRepeatInfo(float rate, float delay)
888 bool ret = Interop.Window.SetKeyboardRepeatInfo(rate, delay);
889 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
894 /// Gets the keyboard repeat information.
896 /// <param name="rate">The key repeat rate value in seconds.</param>
897 /// <param name="delay">The key repeat delay value in seconds.</param>
898 /// <returns>True if setting the keyboard repeat succeeds.</returns>
899 /// <since_tizen> 5 </since_tizen>
900 public bool GetKeyboardRepeatInfo(out float rate, out float delay)
902 bool ret = Interop.Window.GetKeyboardRepeatInfo(out rate, out delay);
903 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
908 /// Adds a layer to the stage.
910 /// <param name="layer">Layer to add.</param>
911 /// <exception cref="ArgumentNullException"> Thrown when layer is null. </exception>
912 /// <since_tizen> 3 </since_tizen>
913 public void AddLayer(Layer layer)
919 /// Removes a layer from the stage.
921 /// <param name="layer">Layer to remove.</param>
922 /// <exception cref="ArgumentNullException"> Thrown when layer is null. </exception>
923 /// <since_tizen> 3 </since_tizen>
924 public void RemoveLayer(Layer layer)
930 /// Feeds a key event into the window.
932 /// <param name="keyEvent">The key event to feed.</param>
933 /// <since_tizen> 5 </since_tizen>
934 public void FeedKey(Key keyEvent)
936 Interop.Window.Window_FeedKeyEvent(Key.getCPtr(keyEvent));
937 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
941 /// Allows at least one more render, even when paused.
942 /// The window should be shown, not minimised.
944 /// <since_tizen> 4 </since_tizen>
945 public void RenderOnce()
947 Interop.Window.Window_RenderOnce(swigCPtr);
948 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
952 /// Sets whether the window is transparent or not.
954 /// <param name="transparent">Whether the window is transparent or not.</param>
955 /// <since_tizen> 5 </since_tizen>
956 public void SetTransparency(bool transparent)
958 Interop.Window.SetTransparency(swigCPtr, transparent);
959 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
961 // Setting transparency of the window should request a relayout of the tree in the case the window changes from fully transparent.
965 /// Sets parent window of the window.
966 /// After setting that, these windows do together when raise-up, lower and iconified/deiconified.
967 /// Initially, the window is located on top of the parent. The window can go below parent by calling Lower().
968 /// If parent's window stack is changed by calling Raise() or Lower(), child windows are located on top of the parent again.
970 /// <param name="parent">The parent window.</param>
971 /// <since_tizen> 6 </since_tizen>
972 /// <feature> http://tizen.org/feature/opengles.surfaceless_context </feature>
973 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
974 public void SetParent(Window parent)
976 if (IsSupportedMultiWindow() == false)
978 NUILog.Error("This device does not support surfaceless_context. So Window cannot be created. ");
980 Interop.Window.SetParent(swigCPtr, Window.getCPtr(parent));
981 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
985 /// Unsets parent window of the window.
986 /// After unsetting, the window is disconnected his parent window.
988 /// <since_tizen> 6 </since_tizen>
989 /// <feature> http://tizen.org/feature/opengles.surfaceless_context </feature>
990 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
991 public void Unparent()
993 if (IsSupportedMultiWindow() == false)
995 NUILog.Error("Fail to create window. because this device does not support opengles.surfaceless_context.");
997 Interop.Window.Unparent(swigCPtr);
998 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1002 /// Gets parent window of the window.
1004 /// <returns>The parent window of the window.</returns>
1005 /// <since_tizen> 6 </since_tizen>
1006 /// <feature> http://tizen.org/feature/opengles.surfaceless_context </feature>
1007 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
1008 public Window GetParent()
1010 if (IsSupportedMultiWindow() == false)
1012 NUILog.Error("This device does not support surfaceless_context. So Window cannot be created. ");
1014 Window ret = Registry.GetManagedBaseHandleFromNativePtr(Interop.Window.GetParent(swigCPtr)) as Window;
1015 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1019 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
1020 [EditorBrowsable(EditorBrowsableState.Never)]
1021 public void ObjectDump()
1023 Layer rootLayer = GetRootLayer();
1024 foreach (View view in rootLayer.Children)
1030 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Window obj)
1032 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
1035 internal static bool IsInstalled()
1037 bool ret = Interop.Stage.Stage_IsInstalled();
1038 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1043 /// Adds an orientation to the list of available orientations.
1045 /// <param name="orientation">The available orientation to add</param>
1046 /// <since_tizen> 6 </since_tizen>
1047 public void AddAvailableOrientation(Window.WindowOrientation orientation)
1049 Interop.Window.Window_AddAvailableOrientation(swigCPtr, (int)orientation);
1050 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1054 /// Removes an orientation from the list of available orientations.
1056 /// <param name="orientation">The available orientation to remove.</param>
1057 /// <since_tizen> 6 </since_tizen>
1058 public void RemoveAvailableOrientation(Window.WindowOrientation orientation)
1060 Interop.Window.Window_RemoveAvailableOrientation(swigCPtr, (int)orientation);
1061 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1065 /// Sets a preferred orientation.
1067 /// <param name="orientation">The preferred orientation.</param>
1068 /// <since_tizen> 6 </since_tizen>
1069 public void SetPreferredOrientation(Window.WindowOrientation orientation)
1071 Interop.Window.Window_SetPreferredOrientation(swigCPtr, (int)orientation);
1072 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1076 /// Gets the preferred orientation.
1078 /// <since_tizen> 6 </since_tizen>
1079 /// <returns>The preferred orientation if previously set, or none.</returns>
1080 public Window.WindowOrientation GetPreferredOrientation()
1082 Window.WindowOrientation ret = (Window.WindowOrientation)Interop.Window.Window_GetPreferredOrientation(swigCPtr);
1083 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1088 /// Gets current orientation of the window.
1090 /// <since_tizen> 6 </since_tizen>
1091 /// <returns>The current window orientation if previously set, or none.</returns>
1092 [EditorBrowsable(EditorBrowsableState.Never)]
1093 public Window.WindowOrientation GetCurrentOrientation()
1095 Window.WindowOrientation ret = (Window.WindowOrientation)Interop.Window.Window_GetCurrentOrientation(swigCPtr);
1096 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1101 /// Sets available orientations of the window.
1102 /// This API is for setting several orientations one time.
1104 /// <param name="orientations">The list of orientations.</param>
1105 /// <since_tizen> 6 </since_tizen>
1106 [EditorBrowsable(EditorBrowsableState.Never)]
1107 public void SetAvailableOrientations(List<Window.WindowOrientation> orientations)
1109 PropertyArray orientationArray = new PropertyArray();
1110 if (null != orientations)
1112 for (int i = 0; i < orientations.Count; i++)
1114 orientationArray.PushBack(new PropertyValue((int)orientations[i]));
1118 Interop.Window.Window_SetAvailableOrientations(swigCPtr, PropertyArray.getCPtr(orientationArray));
1119 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1123 /// Get native window ID
1125 /// <returns>native window ID</returns>
1126 [EditorBrowsable(EditorBrowsableState.Never)]
1127 public int GetNativeId()
1129 int ret = Interop.Window.GetNativeId(swigCPtr);
1130 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1134 internal Any GetNativeHandle()
1136 Any ret = new Any(Interop.WindowInternal.Window_GetNativeHandle(swigCPtr), true);
1137 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1141 internal void Add(Layer layer)
1145 throw new ArgumentNullException(nameof(layer));
1147 Interop.Window.Add(swigCPtr, Layer.getCPtr(layer));
1148 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1150 LayersChildren?.Add(layer);
1151 layer.SetWindow(this);
1154 internal void Remove(Layer layer)
1158 throw new ArgumentNullException(nameof(layer));
1160 Interop.Window.Remove(swigCPtr, Layer.getCPtr(layer));
1161 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1163 LayersChildren?.Remove(layer);
1164 layer.SetWindow(null);
1167 internal Vector2 GetSize()
1169 var val = new Uint16Pair(Interop.Window.GetSize(swigCPtr), false);
1170 Vector2 ret = new Vector2(val.GetWidth(), val.GetHeight());
1171 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1175 internal RenderTaskList GetRenderTaskList()
1177 RenderTaskList ret = new RenderTaskList(Interop.Stage.Stage_GetRenderTaskList(stageCPtr), true);
1178 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1183 /// Queries the number of on-window layers.
1185 /// <returns>The number of layers.</returns>
1186 /// <remarks>Note that a default layer is always provided (count >= 1).</remarks>
1187 internal uint GetLayerCount()
1189 if (LayersChildren == null || LayersChildren.Count < 0)
1192 return (uint)LayersChildren.Count;
1195 internal Layer GetRootLayer()
1197 // Window.IsInstalled() is actually true only when called from event thread and
1198 // Core has been initialized, not when Stage is ready.
1199 if (_rootLayer == null && Window.IsInstalled())
1201 _rootLayer = new Layer(Interop.Window.GetRootLayer(swigCPtr), true);
1202 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1203 LayersChildren?.Add(_rootLayer);
1204 _rootLayer.SetWindow(this);
1209 internal void SetBackgroundColor(Vector4 color)
1211 Interop.Window.SetBackgroundColor(swigCPtr, Vector4.getCPtr(color));
1212 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1215 internal Vector4 GetBackgroundColor()
1217 Vector4 ret = new Vector4(Interop.Window.GetBackgroundColor(swigCPtr), true);
1218 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1222 internal Vector2 GetDpi()
1224 Vector2 ret = new Vector2(Interop.Stage.Stage_GetDpi(stageCPtr), true);
1225 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1229 internal ObjectRegistry GetObjectRegistry()
1231 ObjectRegistry ret = new ObjectRegistry(Interop.Stage.Stage_GetObjectRegistry(stageCPtr), true);
1232 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1236 internal void SetRenderingBehavior(RenderingBehaviorType renderingBehavior)
1238 Interop.Stage.Stage_SetRenderingBehavior(stageCPtr, (int)renderingBehavior);
1239 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1242 internal RenderingBehaviorType GetRenderingBehavior()
1244 RenderingBehaviorType ret = (RenderingBehaviorType)Interop.Stage.Stage_GetRenderingBehavior(stageCPtr);
1245 if (NDalicPINVOKE.SWIGPendingException.Pending)
1246 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1250 internal void SetWindowSize(Size2D size)
1254 throw new ArgumentNullException(nameof(size));
1256 var val = new Uint16Pair((uint)size.Width, (uint)size.Height);
1257 Interop.Window.SetSize(swigCPtr, Uint16Pair.getCPtr(val));
1259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1261 // Resetting Window size should request a relayout of the tree.
1264 internal Size2D GetWindowSize()
1266 var val = new Uint16Pair(Interop.Window.GetSize(swigCPtr), false);
1267 Size2D ret = new Size2D(val.GetWidth(), val.GetHeight());
1269 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1273 internal void SetPosition(Position2D position)
1275 if (null == position)
1277 throw new ArgumentNullException(nameof(position));
1279 var val = new Uint16Pair((uint)position.X, (uint)position.Y);
1280 Interop.Window.SetPosition(swigCPtr, Uint16Pair.getCPtr(val));
1282 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1283 // Setting Position of the window should request a relayout of the tree.
1286 internal Position2D GetPosition()
1288 var val = new Uint16Pair(Interop.Window.GetPosition(swigCPtr), true);
1289 Position2D ret = new Position2D(val.GetX(), val.GetY());
1291 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1295 internal void SetPositionSize(Rectangle positionSize)
1297 Interop.Window.Window_SetPositionSize(swigCPtr, Rectangle.getCPtr(positionSize));
1299 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1301 // Setting Position of the window should request a relayout of the tree.
1305 /// Add FrameCallback
1307 [EditorBrowsable(EditorBrowsableState.Never)]
1308 public void AddFrameCallback(FrameCallbackInterface frameCallback)
1310 frameCallback?.AddFrameCallback(stageCPtr, Layer.getCPtr(GetRootLayer()));
1314 /// Remove FrameCallback
1316 [EditorBrowsable(EditorBrowsableState.Never)]
1317 public void RemoveFrameCallback(FrameCallbackInterface frameCallback)
1319 frameCallback?.RemoveFrameCallback(stageCPtr);
1323 /// Dispose for Window
1325 [EditorBrowsable(EditorBrowsableState.Never)]
1326 protected override void Dispose(DisposeTypes type)
1333 if (type == DisposeTypes.Explicit)
1336 //Release your own managed resources here.
1337 //You should release all of your own disposable objects here.
1339 if (_rootLayer != null)
1341 _rootLayer.Dispose();
1344 localController?.Dispose();
1346 foreach (var layer in _childLayers)
1354 _childLayers.Clear();
1357 this.DisconnectNativeSignals();
1362 /// This will not be public opened.
1363 [EditorBrowsable(EditorBrowsableState.Never)]
1364 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1366 Interop.Window.delete_Window(swigCPtr);
1369 private static Dictionary<int, internalHookCallbackType> frameCallbackList = new Dictionary<int, internalHookCallbackType>();
1371 private static readonly object locker = new object();
1373 private static int key = 0;
1375 private static FrameCallbackType internalHookFrameCallback = OnInternalHookFrameCallback;
1377 private struct internalHookCallbackType
1379 public FrameCallbackType userCallback;
1383 private static void OnInternalHookFrameCallback(int id)
1387 if (frameCallbackList.ContainsKey(id))
1389 if (frameCallbackList[id].userCallback != null)
1391 frameCallbackList[id].userCallback.Invoke(frameCallbackList[id].frameId);
1392 frameCallbackList.Remove(id);
1396 NUILog.Error($"found userCallback is NULL");
1397 frameCallbackList.Remove(id);
1403 private int AddInterHookCallback(FrameCallbackType callback, int frameId)
1405 if (null == callback)
1407 throw new ArgumentNullException(nameof(callback), "FrameCallbackType should not be null");
1409 var assignedKey = 0;
1414 frameCallbackList.Add(assignedKey, new internalHookCallbackType()
1416 userCallback = callback,
1424 /// Type of callback which is called when the frame rendering is done by graphics driver or when the frame is displayed on display.
1426 /// <param name="frameId">The Id to specify the frame. It will be passed when the callback is called.</param>
1427 [EditorBrowsable(EditorBrowsableState.Never)]
1428 public delegate void FrameCallbackType(int frameId);
1431 /// Adds a callback that is called when the frame rendering is done by the graphics driver.
1432 /// A callback of the following type may be used:
1434 /// void MyFunction( int frameId )
1436 /// This callback will be deleted once it is called.
1438 /// Ownership of the callback is passed onto this class
1441 /// <param name="callback">The function to call</param>
1442 /// <param name="frameId">The Id to specify the frame. It will be passed when the callback is called.</param>
1443 /// <exception cref="ArgumentNullException">This exception can occur by the callback is null.</exception>
1444 [EditorBrowsable(EditorBrowsableState.Never)]
1445 public void AddFrameRenderedCallback(FrameCallbackType callback, int frameId)
1447 var assignedKey = AddInterHookCallback(callback, frameId);
1448 Interop.WindowInternal.AddFrameRenderedCallback(swigCPtr, new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(internalHookFrameCallback)), assignedKey);
1450 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1454 /// Adds a callback that is called when the frame is displayed on the display.
1455 /// A callback of the following type may be used:
1457 /// void MyFunction( int frameId )
1459 /// This callback will be deleted once it is called.
1461 /// Ownership of the callback is passed onto this class
1464 /// <param name="callback">The function to call</param>
1465 /// <param name="frameId">The Id to specify the frame. It will be passed when the callback is called.</param>
1466 /// <exception cref="ArgumentNullException">This exception can occur by the callback is null.</exception>
1467 [EditorBrowsable(EditorBrowsableState.Never)]
1468 public void AddFramePresentedCallback(FrameCallbackType callback, int frameId)
1470 var assignedKey = AddInterHookCallback(callback, frameId);
1471 Interop.WindowInternal.AddFramePresentedCallback(swigCPtr, new HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(internalHookFrameCallback)), assignedKey);
1473 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();