2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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 using System.Collections.Generic;
19 using System.ComponentModel;
24 /// Enumeration for the display rotation of window.
26 /// <since_tizen> preview </since_tizen>
28 public enum DisplayRotation
31 /// Rotation value of window is 0 degree
36 /// Rotation value of window is 90 degree
41 /// Rotation value of window is 180 degree
46 /// Rotation value of window is 270 degree
52 /// Enumeration for the indicator opacity
54 /// <since_tizen> preview </since_tizen>
55 public enum StatusBarMode
58 /// Opacifies the status bar
63 /// Be translucent the status bar
71 /// Transparentizes the status bar
77 /// Enumeration for the keygrab modes of window.
79 /// <since_tizen> preview </since_tizen>
80 [EditorBrowsable(EditorBrowsableState.Never)]
81 public enum KeyGrabMode
84 /// Unknown keygrab mode
89 /// Getting the grabbed-key together with the other client windows.
94 /// Getting the grabbed-key only when window is top of the stack.
99 /// Getting the grabbed-key exclusively regardless of window's position.
101 OverrideExclusive = 2048,
105 /// Enumeration for the indicator mode.
107 /// <since_tizen> preview </since_tizen>
108 public enum IndicatorMode
111 /// Unknown indicator state.
116 /// Hides the indicator.
121 /// Shows the indicator.
127 /// Enumeration for the keyboard mode
129 /// <since_tizen> preview </since_tizen>
130 public enum KeyboardMode
133 /// Unknown keyboard state
138 /// Request to deactivate the keyboard
143 /// Enable keyboard with default layout
148 /// Alpha (a-z) keyboard layout
153 /// Numeric keyboard layout
158 /// PIN keyboard layout
163 /// Phone keyboard layout
168 /// Hexadecimal numeric keyboard layout
173 /// Full (QWERTY) keyboard layout
178 /// Password keyboard layout
183 /// IP keyboard layout
188 /// Host keyboard layout
193 /// File keyboard layout
198 /// URL keyboard layout
208 /// J2ME keyboard layout
214 /// Enumeration for the window type
216 /// <since_tizen> preview </since_tizen>
217 public enum WindowType
225 /// A normal window. Indicates a normal, top-level window. Almost every window will be created with this type.
230 /// Used for simple dialog windows.
235 /// For special desktop windows, like a background window holding desktop icons.
240 /// The window is used as a dock or panel. Usually would be kept on top of any other window by the Window Manager.
245 /// The window is used to hold a floating toolbar, or similar.
250 /// Similar to Toolbar.
255 /// A persistent utility window, like a toolbox or palette.
260 /// Splash window for a starting up application.
265 /// The window is a dropdown menu, as when an entry in a menubar is clicked.
270 /// Like DropdownMenu, but for the menu triggered by right-clicking an object.
275 /// The window is a tooltip. A short piece of explanatory text that typically appear after the mouse cursor hovers over an object for a while.
280 /// A notification window, like a warning about battery life or a new E-Mail received.
285 /// A window holding the contents of a combo box.
290 /// Used to indicate the window is a representation of an object being dragged across different windows, or even applications.
295 /// The window is rendered onto an image buffer. No actual window is created for this type, instead the window and all of its contents will be rendered to an image buffer.
296 /// This allows to have children window inside a parent one just like any other object would be, and do other things like applying Evas_Map effects to it.
301 /// The window is rendered onto an image buffer and can be shown other process's plug image object.
302 /// No actual window is created for this type, instead the window and all of its contents will be rendered to an image buffer and can be shown other process's plug image object.
307 /// This window was created using a pre-existing canvas. The window widget can be deleted, but the canvas must be managed externally.
313 /// The Window is container that contain the graphical user interface of a program.
315 /// <since_tizen> preview </since_tizen>
316 public class Window : Widget
318 SmartEvent _deleteRequest;
319 SmartEvent _rotationChanged;
320 HashSet<EvasObject> _referenceHolder = new HashSet<EvasObject>();
323 /// Creates and initializes a new instance of the Window class.
325 /// <param name="name">Window name.</param>
326 /// <since_tizen> preview </since_tizen>
327 public Window(string name) : this(null, name)
332 /// Creates and initializes a new instance of the Window class.
334 /// <param name="parent">
335 /// Parent widget which this widow created on.
337 /// <param name="name">
341 /// Window constructor.show window indicator,set callback
342 /// When closing the window in any way outside the program control,
343 /// and set callback when window rotation changed.
345 /// <since_tizen> preview </since_tizen>
346 public Window(Window parent, string name) : this(parent, name, WindowType.Basic)
351 /// Creates and initializes a new instance of the Window class.
353 /// <param name="parent">
354 /// Parent widget which this widow created on.
356 /// <param name="name">
359 /// <param name="type">
363 /// Window constructor.show window indicator,set callback
364 /// When closing the window in any way outside the program control,
365 /// and set callback when window rotation changed.
367 /// <since_tizen> preview </since_tizen>
368 public Window(Window parent, string name, WindowType type)
373 IndicatorMode = IndicatorMode.Show;
375 _deleteRequest = new SmartEvent(this, "delete,request");
376 _rotationChanged = new SmartEvent(this, "wm,rotation,changed");
377 _deleteRequest.On += (s, e) => CloseRequested?.Invoke(this, EventArgs.Empty);
378 _rotationChanged.On += (s, e) => RotationChanged?.Invoke(this, EventArgs.Empty);
382 /// Creates and initializes a new instance of the Window class.
384 /// <since_tizen> preview </since_tizen>
390 /// CloseRequested will be triggered when Window close.
392 /// <since_tizen> preview </since_tizen>
393 public event EventHandler CloseRequested;
396 /// RotationChanged will be triggered when Window do rotation.
398 /// <since_tizen> preview </since_tizen>
399 public event EventHandler RotationChanged;
402 /// Sets or gets Window name.
404 /// <since_tizen> preview </since_tizen>
405 public string Name { get; set; }
408 /// Gets the Window type.
410 /// <since_tizen> preview </since_tizen>
411 public WindowType Type { get; } = WindowType.Basic;
414 /// Gets Window size with Size value(w,h)
416 /// <since_tizen> preview </since_tizen>
417 public Size ScreenSize
422 Interop.Elementary.elm_win_screen_size_get(Handle, out x, out y, out w, out h);
423 return new Size(w, h);
428 /// Gets the screen dpi for the screen that a Window is on.
430 /// <since_tizen> preview </since_tizen>
431 public Point ScreenDpi
435 Point point = default(Point);
436 Interop.Elementary.elm_win_screen_dpi_get(Handle, out point.X, out point.Y);
442 /// Gets the rotation of the Window.The rotation of the window in degrees (0-360).
444 /// <since_tizen> preview </since_tizen>
449 return Interop.Elementary.elm_win_rotation_get(Handle);
454 /// Gets whether window manager supports window rotation or not.
456 /// <since_tizen> preview </since_tizen>
457 public bool IsRotationSupported
461 return Interop.Elementary.elm_win_wm_rotation_supported_get(Handle);
466 /// Sets or gets available rotation degree.
468 /// <since_tizen> preview </since_tizen>
469 [Obsolete("Sorry, it's error typo of AvailableRotations, please use AvailableRotations")]
470 public DisplayRotation AavailableRotations { get; set; }
473 /// Sets or gets available rotation degree.
475 /// <since_tizen> preview </since_tizen>
476 public DisplayRotation AvailableRotations
481 Interop.Elementary.elm_win_wm_rotation_available_rotations_get(Handle, out rotations);
482 if (rotations == null)
486 return ConvertToDisplayRotation(rotations);
490 Interop.Elementary.elm_win_wm_rotation_available_rotations_set(Handle, ConvertDegreeArray(value));
495 /// Sets or gets whether auto deletion function is enable.
498 /// If you enable auto deletion, the window is automatically destroyed after the signal is emitted.
499 /// If auto deletion is disabled, the window is not destroyed and the program has to handle it.
501 /// <since_tizen> preview </since_tizen>
502 public bool AutoDeletion
506 return Interop.Elementary.elm_win_autodel_get(Handle);
510 Interop.Elementary.elm_win_autodel_set(Handle, value);
515 /// Sets or gets the alpha channel state of a window.
518 /// True if the window alpha channel is enabled, false otherwise.
519 /// If alpha is true, the alpha channel of the canvas will be enabled possibly making parts of the window completely or partially transparent.
521 /// <since_tizen> preview </since_tizen>
526 return Interop.Elementary.elm_win_alpha_get(Handle);
530 Interop.Elementary.elm_win_alpha_set(Handle, value);
535 /// Sets or gets the role of the window.
538 /// The Role will be invalid if a new role is set or if the window is destroyed.
540 /// <since_tizen> preview </since_tizen>
545 return Interop.Elementary.elm_win_role_get(Handle);
549 Interop.Elementary.elm_win_role_set(Handle, value);
554 /// Sets or gets the mode of status bar.
556 /// <since_tizen> preview </since_tizen>
557 public StatusBarMode StatusBarMode
561 return (StatusBarMode)Interop.Elementary.elm_win_indicator_opacity_get(Handle);
565 Interop.Elementary.elm_win_indicator_opacity_set(Handle, (int)value);
570 /// Sets or gets the iconified state of a window.
572 /// <since_tizen> preview </since_tizen>
573 [EditorBrowsable(EditorBrowsableState.Never)]
574 public bool Iconified
578 return Interop.Elementary.elm_win_iconified_get(RealHandle);
582 Interop.Elementary.elm_win_iconified_set(RealHandle, value);
587 /// Gets or sets the window's indicator mode.
589 /// <value>The indicator mode.</value>
590 /// <since_tizen> preview </since_tizen>
591 public IndicatorMode IndicatorMode
595 return Interop.Elementary.elm_win_indicator_mode_get(RealHandle);
599 Interop.Elementary.elm_win_indicator_mode_set(RealHandle, value);
604 /// Gets or sets the aspect ratio of a window.
606 /// <since_tizen> preview </since_tizen>
611 return Interop.Elementary.elm_win_aspect_get(RealHandle);
615 Interop.Elementary.elm_win_aspect_set(RealHandle, value);
620 /// Window's autohide state.
622 /// <since_tizen> preview </since_tizen>
627 return Interop.Elementary.elm_win_autohide_get(RealHandle);
631 Interop.Elementary.elm_win_autohide_set(RealHandle, value);
636 /// Get the borderless state of a window.
637 /// This function requests the Window Manager to not draw any decoration around the window.
639 /// <since_tizen> preview </since_tizen>
640 public bool Borderless
644 return Interop.Elementary.elm_win_borderless_get(RealHandle);
648 Interop.Elementary.elm_win_borderless_set(RealHandle, value);
653 /// Gets or sets the demand attention state of a window.
655 /// <since_tizen> preview </since_tizen>
656 public bool DemandAttention
660 return Interop.Elementary.elm_win_demand_attention_get(RealHandle);
664 Interop.Elementary.elm_win_demand_attention_set(RealHandle, value);
669 /// Gets or sets the floating mode of a window.
671 /// <since_tizen> preview </since_tizen>
672 public bool FloatingMode
676 return Interop.Elementary.elm_win_floating_mode_get(RealHandle);
680 Interop.Elementary.elm_win_floating_mode_set(RealHandle, value);
685 /// Gets or sets the animate status for the focus highlight for this window.
686 /// This function will enable or disable the animation of focus highlight only for the given window, regardless of the global setting for it.
688 /// <since_tizen> preview </since_tizen>
689 public bool FocusHighlightAnimation
693 return Interop.Elementary.elm_win_focus_highlight_animate_get(RealHandle);
697 Interop.Elementary.elm_win_focus_highlight_animate_set(RealHandle, value);
702 /// Gets or sets the enabled status for the focus highlight in a window.
703 /// This function will enable or disable the focus highlight only for the given window, regardless of the global setting for it.
705 /// <since_tizen> preview </since_tizen>
706 public bool FocusHighlightEnabled
710 return Interop.Elementary.elm_win_focus_highlight_enabled_get(RealHandle);
714 Interop.Elementary.elm_win_focus_highlight_enabled_set(RealHandle, value);
719 /// Gets or sets the style for the focus highlight on this window.
720 /// Sets the style to use for theming the highlight of focused objects on the given window.If style is NULL, the default will be used.
722 /// <since_tizen> preview </since_tizen>
723 public string FocusHighlightStyle
727 return Interop.Elementary.elm_win_focus_highlight_style_get(RealHandle);
731 Interop.Elementary.elm_win_focus_highlight_style_set(RealHandle, value);
736 /// Get the keyboard mode of the window.
738 /// <since_tizen> preview </since_tizen>
739 public KeyboardMode KeyboardMode
743 return (KeyboardMode)Interop.Elementary.elm_win_keyboard_mode_get(RealHandle);
747 Interop.Elementary.elm_win_keyboard_mode_set(RealHandle, (int)value);
752 /// Gets or sets the layer of the window.
753 /// What this means exactly will depend on the underlying engine used.
754 /// In the case of X11 backed engines, the value in layer has the following meanings
755 /// less than 3 means that the window will be placed below all others,
756 /// more than 5 means that the window will be placed above all others,
757 /// and anything else means that the window will be placed in the default layer.
759 /// <since_tizen> preview </since_tizen>
760 public override int Layer
764 return Interop.Elementary.elm_win_layer_get(RealHandle);
768 Interop.Elementary.elm_win_layer_set(RealHandle, value);
773 /// Gets or sets the modal state of a window.
775 /// <since_tizen> preview </since_tizen>
780 return Interop.Elementary.elm_win_modal_get(RealHandle);
784 Interop.Elementary.elm_win_modal_set(RealHandle, value);
789 /// Gets or sets the noblank property of a window.
790 /// This is a way to request the display on which the windowis shown does not blank, screensave or otherwise hide or obscure the window.It is intended for uses such as media playback on a television where a user may not want to be interrupted by an idle screen.
791 /// The noblank property may have no effect if the window is iconified/minimized or hidden.
793 /// <since_tizen> preview </since_tizen>
798 return Interop.Elementary.elm_win_noblank_get(RealHandle);
802 Interop.Elementary.elm_win_noblank_set(RealHandle, value);
807 /// Get the profile of a window.
809 /// <since_tizen> preview </since_tizen>
810 public string Profile
814 return Interop.Elementary.elm_win_profile_get(RealHandle);
818 Interop.Elementary.elm_win_profile_set(RealHandle, value);
823 /// Get the constraints on the maximum width and height of a window relative to the width and height of its screen.
824 /// When this function returns true, obj will never resize larger than the screen.
826 /// <since_tizen> preview </since_tizen>
827 public bool ScreenConstrain
831 return Interop.Elementary.elm_win_screen_constrain_get(RealHandle);
835 Interop.Elementary.elm_win_screen_constrain_set(RealHandle, value);
840 /// Gets or sets the base size of a window.
842 /// <since_tizen> preview </since_tizen>
848 Interop.Elementary.elm_win_size_base_get(RealHandle, out w, out h);
849 return new Size(w, h);
853 Interop.Elementary.elm_win_size_base_set(RealHandle, value.Width, value.Height);
858 /// Gets or sets the step size of a window.
860 /// <since_tizen> preview </since_tizen>
866 Interop.Elementary.elm_win_size_step_get(RealHandle, out w, out h);
867 return new Size(w, h);
871 Interop.Elementary.elm_win_size_step_set(RealHandle, value.Width, value.Height);
876 /// Get the screen position X of a window.
878 /// <since_tizen> preview </since_tizen>
879 public int ScreenPositionX
884 Interop.Elementary.elm_win_screen_position_get(Handle, out x, out y);
890 /// Get the screen position Y of a window.
892 /// <since_tizen> preview </since_tizen>
893 public int ScreenPositionY
898 Interop.Elementary.elm_win_screen_position_get(Handle, out x, out y);
904 /// Gets or sets the title of the window.
906 /// <since_tizen> preview </since_tizen>
911 return Interop.Elementary.elm_win_title_get(Handle);
915 Interop.Elementary.elm_win_title_set(Handle, value);
920 /// Gets or sets the urgent state of a window.
922 /// <since_tizen> preview </since_tizen>
927 return Interop.Elementary.elm_win_urgent_get(Handle);
931 Interop.Elementary.elm_win_urgent_set(Handle, value);
936 /// Gets or sets the withdrawn state of a window.
938 /// <since_tizen> preview </since_tizen>
939 public bool Withdrawn
943 return Interop.Elementary.elm_win_urgent_get(Handle);
947 Interop.Elementary.elm_win_urgent_set(Handle, value);
952 /// Create a socket to provide the service for Plug widget.
954 /// <param name="name">A service name</param>
955 /// <param name="number">A number (any value, 0 being the common default) to differentiate multiple instances of services with the same name.</param>
956 /// <param name="systemWide">A boolean that if true, specifies to create a system-wide service all users can connect to, otherwise the service is private to the user id that created the service.</param>
957 /// <returns>If true, create successfull, otherwise false</returns>
958 /// <since_tizen> preview </since_tizen>
959 public bool CreateServiceSocket(string name, int number, bool systemWide)
961 return Interop.Elementary.elm_win_socket_listen(RealHandle, name, number, systemWide);
965 /// Set the rotation of the window.
967 /// <param name="degree">The rotation of the window, in degrees (0-360), counter-clockwise.</param>
968 /// <param name="resize">Resizes the window's contents so that they fit inside the current window geometry.</param>
969 /// <since_tizen> preview </since_tizen>
970 public void SetRotation(int degree, bool resize)
973 Interop.Elementary.elm_win_rotation_with_resize_set(RealHandle, degree);
975 Interop.Elementary.elm_win_rotation_set(RealHandle, degree);
979 /// Set the window to be skipped by focus.
980 /// This sets the window to be skipped by normal input.
981 /// This means a window manager will be asked to not focus this window as well as omit it from things like the taskbar, pager etc.
982 /// Call this and enable it on a window BEFORE you show it for the first time, otherwise it may have no effect.
983 /// Use this for windows that have only output information or might only be interacted with by the mouse or fingers, and never for typing input.
984 /// Be careful that this may have side-effects like making the window non-accessible in some cases unless the window is specially handled. Use this with care.
986 /// <since_tizen> preview </since_tizen>
987 public void FocusSkip(bool skip)
989 Interop.Elementary.elm_win_prop_focus_skip_set(Handle, skip);
993 /// Pull up the window object.
994 /// Places the window pointed by obj at the top of the stack, so that it's not covered by any other window.
996 /// <since_tizen> preview </since_tizen>
999 Interop.Elementary.elm_win_raise(Handle);
1003 /// Bring down the window object.
1004 /// Places the window pointed by obj at the bottom of the stack, so that no other window is covered by it.
1006 /// <since_tizen> preview </since_tizen>
1007 public void BringDown()
1009 Interop.Elementary.elm_win_lower(Handle);
1013 /// This function sends a request to the Windows Manager to activate the Window.
1014 /// If honored by the WM, the window receives the keyboard focus.
1017 /// This is just a request that a Window Manager may ignore, so calling this function does not ensure
1018 /// in any way that the window is going to be the active one after it.
1020 /// <since_tizen> preview </since_tizen>
1021 public void Active()
1023 Interop.Elementary.elm_win_activate(Handle);
1027 /// Delete subobj as a resize object of window obj.
1028 /// This function removes the object subobj from the resize objects of the window obj.
1029 /// It will not delete the object itself, which will be left unmanaged and should be deleted by the developer, manually handled or set as child of some other container.
1031 /// <param name="obj">Resize object.</param>
1032 /// <since_tizen> preview </since_tizen>
1033 public void DeleteResizeObject(EvasObject obj)
1035 Interop.Elementary.elm_win_resize_object_del(Handle, obj);
1039 /// Adds obj as a resize object of the Window.
1042 /// Setting an object as a resize object of the window means that the obj child's size and
1043 /// position is controlled by the window directly. That is, the obj is resized to match the window size
1044 /// and should never be moved or resized manually by the developer.In addition,
1045 /// resize objects of the window control the minimum size of it as well as whether it can or cannot be resized by the user.
1047 /// <param name="obj">
1050 /// <since_tizen> preview </since_tizen>
1051 public void AddResizeObject(EvasObject obj)
1053 Interop.Elementary.elm_win_resize_object_add(Handle, obj);
1057 /// Set keygrab value of the window.
1058 /// This function grabs the key of window using grab_mode.
1060 /// <param name="keyname">The keyname to grab.</param>
1061 /// <param name="mode">According to the grabmode, it can grab key differently</param>
1062 /// <since_tizen> preview </since_tizen>
1063 [EditorBrowsable(EditorBrowsableState.Never)]
1064 public void WinKeyGrab(string keyname, KeyGrabMode mode)
1066 Interop.Elementary.elm_win_keygrab_set(RealHandle, keyname, 0, 0, 0, mode);
1070 /// Unset keygrab value of the window.
1071 /// This function unset keygrab value.Ungrab key of window.
1073 /// <param name="keyname">The keyname to grab.</param>
1074 /// <since_tizen> preview </since_tizen>
1075 [EditorBrowsable(EditorBrowsableState.Never)]
1076 public void WinKeyUngrab(string keyname)
1078 Interop.Elementary.elm_win_keygrab_unset(RealHandle, keyname, 0, 0);
1082 /// Set the keygrab of the window.
1084 /// <param name="keyname">keyname string to set keygrab</param>
1085 /// <since_tizen> preview </since_tizen>
1086 public void KeyGrabEx(string keyname)
1088 Interop.Elementary.eext_win_keygrab_set(RealHandle, keyname);
1092 /// Unset the keygrab of the window.
1094 /// <param name="keyname">keyname string to unset keygrab</param>
1095 /// <since_tizen> preview </since_tizen>
1096 public void KeyUngrabEx(string keyname)
1098 Interop.Elementary.eext_win_keygrab_unset(RealHandle, keyname);
1102 /// Creates a widget handle.
1104 /// <param name="parent">Parent EvasObject</param>
1105 /// <returns>Handle IntPtr</returns>
1106 /// <since_tizen> preview </since_tizen>
1107 protected override IntPtr CreateHandle(EvasObject parent)
1109 Interop.Elementary.elm_config_accel_preference_set("3d");
1110 return Interop.Elementary.elm_win_add(parent != null ? parent.Handle : IntPtr.Zero, Name, (int)Type);
1113 internal void AddChild(EvasObject obj)
1115 _referenceHolder.Add(obj);
1118 internal void RemoveChild(EvasObject obj)
1120 _referenceHolder.Remove(obj);
1123 static int[] ConvertDegreeArray(DisplayRotation value)
1125 List<int> rotations = new List<int>();
1126 if (value.HasFlag(DisplayRotation.Degree_0))
1128 if (value.HasFlag(DisplayRotation.Degree_90))
1130 if (value.HasFlag(DisplayRotation.Degree_180))
1132 if (value.HasFlag(DisplayRotation.Degree_270))
1134 return rotations.ToArray();
1137 static DisplayRotation ConvertToDisplayRotation(int[] values)
1139 int orientation = 0;
1140 foreach (int v in values)
1142 orientation |= (1 << (v / 90));
1144 return (DisplayRotation)orientation;