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.
27 public enum DisplayRotation
30 /// Rotation value of window is 0 degree
35 /// Rotation value of window is 90 degree
40 /// Rotation value of window is 180 degree
45 /// Rotation value of window is 270 degree
51 /// Enumeration for the indicator opacity
53 public enum StatusBarMode
56 /// Opacifies the status bar
61 /// Be translucent the status bar
69 /// Transparentizes the status bar
74 [EditorBrowsable(EditorBrowsableState.Never)]
75 public enum KeyGrabMode
80 OverrideExclusive = 2048,
84 /// Enumeration for the indicator mode.
86 public enum IndicatorMode
89 /// Unknown indicator state.
94 /// Hides the indicator.
99 /// Shows the indicator.
105 /// Enumeration for the keyboard mode
107 public enum KeyboardMode
110 /// Unknown keyboard state
115 /// Request to deactivate the keyboard
120 /// Enable keyboard with default layout
125 /// Alpha (a-z) keyboard layout
130 /// Numeric keyboard layout
135 /// PIN keyboard layout
140 /// Phone keyboard layout
145 /// Hexadecimal numeric keyboard layout
150 /// Full (QWERTY) keyboard layout
155 /// Password keyboard layout
160 /// IP keyboard layout
165 /// Host keyboard layout
170 /// File keyboard layout
175 /// URL keyboard layout
185 /// J2ME keyboard layout
191 /// Enumeration for the window type
193 public enum WindowType
201 /// A normal window. Indicates a normal, top-level window. Almost every window will be created with this type.
206 /// Used for simple dialog windows.
211 /// For special desktop windows, like a background window holding desktop icons.
216 /// The window is used as a dock or panel. Usually would be kept on top of any other window by the Window Manager.
221 /// The window is used to hold a floating toolbar, or similar.
226 /// Similar to Toolbar.
231 /// A persistent utility window, like a toolbox or palette.
236 /// Splash window for a starting up application.
241 /// The window is a dropdown menu, as when an entry in a menubar is clicked.
246 /// Like DropdownMenu, but for the menu triggered by right-clicking an object.
251 /// 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.
256 /// A notification window, like a warning about battery life or a new E-Mail received.
261 /// A window holding the contents of a combo box.
266 /// Used to indicate the window is a representation of an object being dragged across different windows, or even applications.
271 /// 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.
272 /// 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.
277 /// The window is rendered onto an image buffer and can be shown other process's plug image object.
278 /// 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.
283 /// This window was created using a pre-existing canvas. The window widget can be deleted, but the canvas must be managed externally.
289 /// The Window is container that contain the graphical user interface of a program.
291 public class Window : Widget
293 SmartEvent _deleteRequest;
294 SmartEvent _rotationChanged;
295 HashSet<EvasObject> _referenceHolder = new HashSet<EvasObject>();
298 /// Creates and initializes a new instance of the Window class.
300 /// <param name="name">Window name.</param>
301 public Window(string name) : this(null, name)
306 /// Creates and initializes a new instance of the Window class.
308 /// <param name="parent">
309 /// Parent widget which this widow created on.
311 /// <param name="name">
315 /// Window constructor.show window indicator,set callback
316 /// When closing the window in any way outside the program control,
317 /// and set callback when window rotation changed.
319 public Window(Window parent, string name) : this(parent, name, WindowType.Basic)
324 /// Creates and initializes a new instance of the Window class.
326 /// <param name="parent">
327 /// Parent widget which this widow created on.
329 /// <param name="name">
332 /// <param name="type">
336 /// Window constructor.show window indicator,set callback
337 /// When closing the window in any way outside the program control,
338 /// and set callback when window rotation changed.
340 public Window(Window parent, string name, WindowType type)
345 IndicatorMode = IndicatorMode.Show;
347 _deleteRequest = new SmartEvent(this, "delete,request");
348 _rotationChanged = new SmartEvent(this, "wm,rotation,changed");
349 _deleteRequest.On += (s, e) => CloseRequested?.Invoke(this, EventArgs.Empty);
350 _rotationChanged.On += (s, e) => RotationChanged?.Invoke(this, EventArgs.Empty);
358 /// CloseRequested will be triggered when Window close.
360 public event EventHandler CloseRequested;
363 /// RotationChanged will be triggered when Window do rotation.
365 public event EventHandler RotationChanged;
368 /// Sets or gets Window name.
370 public string Name { get; set; }
373 /// Gets the Window type.
375 public WindowType Type { get; } = WindowType.Basic;
378 /// Gets Window size with Size value(w,h)
380 public Size ScreenSize
385 Interop.Elementary.elm_win_screen_size_get(Handle, out x, out y, out w, out h);
386 return new Size(w, h);
391 /// Gets the screen dpi for the screen that a Window is on.
393 public Point ScreenDpi
397 Point point = default(Point);
398 Interop.Elementary.elm_win_screen_dpi_get(Handle, out point.X, out point.Y);
404 /// Gets the rotation of the Window.The rotation of the window in degrees (0-360).
410 return Interop.Elementary.elm_win_rotation_get(Handle);
415 /// Gets whether window manager supports window rotation or not.
417 public bool IsRotationSupported
421 return Interop.Elementary.elm_win_wm_rotation_supported_get(Handle);
425 [Obsolete("Sorry, it's error typo of AvailableRotations, please use AvailableRotations")]
426 public DisplayRotation AavailableRotations { get; set; }
429 /// Sets or gets available rotation degree.
431 public DisplayRotation AvailableRotations
436 Interop.Elementary.elm_win_wm_rotation_available_rotations_get(Handle, out rotations);
437 if (rotations == null)
441 return ConvertToDisplayRotation(rotations);
445 Interop.Elementary.elm_win_wm_rotation_available_rotations_set(Handle, ConvertDegreeArray(value));
450 /// Sets or gets whether auto deletion function is enable.
453 /// If you enable auto deletion, the window is automatically destroyed after the signal is emitted.
454 /// If auto deletion is disabled, the window is not destroyed and the program has to handle it.
456 public bool AutoDeletion
460 return Interop.Elementary.elm_win_autodel_get(Handle);
464 Interop.Elementary.elm_win_autodel_set(Handle, value);
469 /// Sets or gets the alpha channel state of a window.
472 /// True if the window alpha channel is enabled, false otherwise.
473 /// If alpha is true, the alpha channel of the canvas will be enabled possibly making parts of the window completely or partially transparent.
479 return Interop.Elementary.elm_win_alpha_get(Handle);
483 Interop.Elementary.elm_win_alpha_set(Handle, value);
488 /// Sets or gets the role of the window.
491 /// The Role will be invalid if a new role is set or if the window is destroyed.
497 return Interop.Elementary.elm_win_role_get(Handle);
501 Interop.Elementary.elm_win_role_set(Handle, value);
506 /// Sets or gets the mode of status bar.
508 public StatusBarMode StatusBarMode
512 return (StatusBarMode)Interop.Elementary.elm_win_indicator_opacity_get(Handle);
516 Interop.Elementary.elm_win_indicator_opacity_set(Handle, (int)value);
520 [EditorBrowsable(EditorBrowsableState.Never)]
521 public bool Iconified
525 return Interop.Elementary.elm_win_iconified_get(RealHandle);
529 Interop.Elementary.elm_win_iconified_set(RealHandle, value);
534 /// Gets or sets the window's indicator mode.
536 /// <value>The indicator mode.</value>
537 public IndicatorMode IndicatorMode
541 return Interop.Elementary.elm_win_indicator_mode_get(RealHandle);
545 Interop.Elementary.elm_win_indicator_mode_set(RealHandle, value);
550 /// Gets or sets the aspect ratio of a window.
556 return Interop.Elementary.elm_win_aspect_get(RealHandle);
560 Interop.Elementary.elm_win_aspect_set(RealHandle, value);
565 /// Window's autohide state.
571 return Interop.Elementary.elm_win_autohide_get(RealHandle);
575 Interop.Elementary.elm_win_autohide_set(RealHandle, value);
580 /// Get the borderless state of a window.
581 /// This function requests the Window Manager to not draw any decoration around the window.
583 public bool Borderless
587 return Interop.Elementary.elm_win_borderless_get(RealHandle);
591 Interop.Elementary.elm_win_borderless_set(RealHandle, value);
596 /// Gets or sets the demand attention state of a window.
598 public bool DemandAttention
602 return Interop.Elementary.elm_win_demand_attention_get(RealHandle);
606 Interop.Elementary.elm_win_demand_attention_set(RealHandle, value);
611 /// Gets or sets the floating mode of a window.
613 public bool FloatingMode
617 return Interop.Elementary.elm_win_floating_mode_get(RealHandle);
621 Interop.Elementary.elm_win_floating_mode_set(RealHandle, value);
626 /// Gets or sets the animate status for the focus highlight for this window.
627 /// This function will enable or disable the animation of focus highlight only for the given window, regardless of the global setting for it.
629 public bool FocusHighlightAnimation
633 return Interop.Elementary.elm_win_focus_highlight_animate_get(RealHandle);
637 Interop.Elementary.elm_win_focus_highlight_animate_set(RealHandle, value);
642 /// Gets or sets the enabled status for the focus highlight in a window.
643 /// This function will enable or disable the focus highlight only for the given window, regardless of the global setting for it.
645 public bool FocusHighlightEnabled
649 return Interop.Elementary.elm_win_focus_highlight_enabled_get(RealHandle);
653 Interop.Elementary.elm_win_focus_highlight_enabled_set(RealHandle, value);
658 /// Gets or sets the style for the focus highlight on this window.
659 /// 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.
661 public string FocusHighlightStyle
665 return Interop.Elementary.elm_win_focus_highlight_style_get(RealHandle);
669 Interop.Elementary.elm_win_focus_highlight_style_set(RealHandle, value);
674 /// Get the keyboard mode of the window.
676 public KeyboardMode KeyboardMode
680 return (KeyboardMode)Interop.Elementary.elm_win_keyboard_mode_get(RealHandle);
684 Interop.Elementary.elm_win_keyboard_mode_set(RealHandle, (int)value);
689 /// Gets or sets the layer of the window.
690 /// What this means exactly will depend on the underlying engine used.
691 /// In the case of X11 backed engines, the value in layer has the following meanings
692 /// less than 3 means that the window will be placed below all others,
693 /// more than 5 means that the window will be placed above all others,
694 /// and anything else means that the window will be placed in the default layer.
696 public override int Layer
700 return Interop.Elementary.elm_win_layer_get(RealHandle);
704 Interop.Elementary.elm_win_layer_set(RealHandle, value);
709 /// Gets or sets the maximized state of a window.
711 public bool Maximized
715 return Interop.Elementary.elm_win_maximized_get(RealHandle);
719 Interop.Elementary.elm_win_maximized_set(RealHandle, value);
724 /// Gets or sets the modal state of a window.
730 return Interop.Elementary.elm_win_modal_get(RealHandle);
734 Interop.Elementary.elm_win_modal_set(RealHandle, value);
739 /// Gets or sets the noblank property of a window.
740 /// 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.
741 /// The noblank property may have no effect if the window is iconified/minimized or hidden.
747 return Interop.Elementary.elm_win_noblank_get(RealHandle);
751 Interop.Elementary.elm_win_noblank_set(RealHandle, value);
756 /// Get the profile of a window.
758 public string Profile
762 return Interop.Elementary.elm_win_profile_get(RealHandle);
766 Interop.Elementary.elm_win_profile_set(RealHandle, value);
771 /// Get the constraints on the maximum width and height of a window relative to the width and height of its screen.
772 /// When this function returns true, obj will never resize larger than the screen.
774 public bool ScreenConstrain
778 return Interop.Elementary.elm_win_screen_constrain_get(RealHandle);
782 Interop.Elementary.elm_win_screen_constrain_set(RealHandle, value);
787 /// Gets or sets the base size of a window.
794 Interop.Elementary.elm_win_size_base_get(RealHandle, out w, out h);
795 return new Size(w, h);
799 Interop.Elementary.elm_win_size_base_set(RealHandle, value.Width, value.Height);
804 /// Gets or sets the step size of a window.
811 Interop.Elementary.elm_win_size_step_get(RealHandle, out w, out h);
812 return new Size(w, h);
816 Interop.Elementary.elm_win_size_step_set(RealHandle, value.Width, value.Height);
821 /// Get the screen position X of a window.
823 public int ScreenPositionX
828 Interop.Elementary.elm_win_screen_position_get(Handle, out x, out y);
834 /// Get the screen position Y of a window.
836 public int ScreenPositionY
841 Interop.Elementary.elm_win_screen_position_get(Handle, out x, out y);
847 /// Gets or sets the title of the window.
853 return Interop.Elementary.elm_win_title_get(Handle);
857 Interop.Elementary.elm_win_title_set(Handle, value);
862 /// Gets or sets the urgent state of a window.
868 return Interop.Elementary.elm_win_urgent_get(Handle);
872 Interop.Elementary.elm_win_urgent_set(Handle, value);
877 /// Gets or sets the withdrawn state of a window.
879 public bool Withdrawn
883 return Interop.Elementary.elm_win_urgent_get(Handle);
887 Interop.Elementary.elm_win_urgent_set(Handle, value);
892 /// Create a socket to provide the service for Plug widget.
894 /// <param name="name">A service name</param>
895 /// <param name="number">A number (any value, 0 being the common default) to differentiate multiple instances of services with the same name.</param>
896 /// <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>
897 /// <returns>If true, create successfull, otherwise false</returns>
898 public bool CreateServiceSocket(string name, int number, bool systemWide)
900 return Interop.Elementary.elm_win_socket_listen(RealHandle, name, number, systemWide);
904 /// Set the rotation of the window.
906 /// <param name="degree">The rotation of the window, in degrees (0-360), counter-clockwise.</param>
907 /// <param name="resize">Resizes the window's contents so that they fit inside the current window geometry.</param>
908 public void SetRotation(int degree, bool resize)
911 Interop.Elementary.elm_win_rotation_with_resize_set(RealHandle, degree);
913 Interop.Elementary.elm_win_rotation_set(RealHandle, degree);
917 /// Set the window to be skipped by focus.
918 /// This sets the window to be skipped by normal input.
919 /// 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.
920 /// Call this and enable it on a window BEFORE you show it for the first time, otherwise it may have no effect.
921 /// 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.
922 /// 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.
924 public void FocusSkip(bool skip)
926 Interop.Elementary.elm_win_prop_focus_skip_set(Handle, skip);
930 /// Pull up the window object.
931 /// Places the window pointed by obj at the top of the stack, so that it's not covered by any other window.
935 Interop.Elementary.elm_win_raise(Handle);
939 /// Bring down the window object.
940 /// Places the window pointed by obj at the bottom of the stack, so that no other window is covered by it.
942 public void BringDown()
944 Interop.Elementary.elm_win_lower(Handle);
948 /// This function sends a request to the Windows Manager to activate the Window.
949 /// If honored by the WM, the window receives the keyboard focus.
952 /// This is just a request that a Window Manager may ignore, so calling this function does not ensure
953 /// in any way that the window is going to be the active one after it.
957 Interop.Elementary.elm_win_activate(Handle);
961 /// Delete subobj as a resize object of window obj.
962 /// This function removes the object subobj from the resize objects of the window obj.
963 /// 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.
965 /// <param name="obj">Resize object.</param>
966 public void DeleteResizeObject(EvasObject obj)
968 Interop.Elementary.elm_win_resize_object_del(Handle, obj);
972 /// Adds obj as a resize object of the Window.
975 /// Setting an object as a resize object of the window means that the obj child's size and
976 /// position is controlled by the window directly. That is, the obj is resized to match the window size
977 /// and should never be moved or resized manually by the developer.In addition,
978 /// resize objects of the window control the minimum size of it as well as whether it can or cannot be resized by the user.
980 /// <param name="obj">
983 public void AddResizeObject(EvasObject obj)
985 Interop.Elementary.elm_win_resize_object_add(Handle, obj);
988 [EditorBrowsable(EditorBrowsableState.Never)]
989 public void WinKeyGrab(string keyname, KeyGrabMode mode)
991 Interop.Elementary.elm_win_keygrab_set(RealHandle, keyname, 0, 0, 0, mode);
994 [EditorBrowsable(EditorBrowsableState.Never)]
995 public void WinKeyUngrab(string keyname)
997 Interop.Elementary.elm_win_keygrab_unset(RealHandle, keyname, 0, 0);
1001 /// Set the keygrab of the window.
1003 /// <param name="keyname">keyname string to set keygrab</param>
1004 public void KeyGrabEx(string keyname)
1006 Interop.Elementary.eext_win_keygrab_set(RealHandle, keyname);
1010 /// Unset the keygrab of the window.
1012 /// <param name="keyname">keyname string to unset keygrab</param>
1013 public void KeyUngrabEx(string keyname)
1015 Interop.Elementary.eext_win_keygrab_unset(RealHandle, keyname);
1018 protected override IntPtr CreateHandle(EvasObject parent)
1020 Interop.Elementary.elm_config_accel_preference_set("3d");
1021 return Interop.Elementary.elm_win_add(parent != null ? parent.Handle : IntPtr.Zero, Name, (int)Type);
1024 internal void AddChild(EvasObject obj)
1026 _referenceHolder.Add(obj);
1029 internal void RemoveChild(EvasObject obj)
1031 _referenceHolder.Remove(obj);
1034 static int[] ConvertDegreeArray(DisplayRotation value)
1036 List<int> rotations = new List<int>();
1037 if (value.HasFlag(DisplayRotation.Degree_0))
1039 if (value.HasFlag(DisplayRotation.Degree_90))
1041 if (value.HasFlag(DisplayRotation.Degree_180))
1043 if (value.HasFlag(DisplayRotation.Degree_270))
1045 return rotations.ToArray();
1048 static DisplayRotation ConvertToDisplayRotation(int[] values)
1050 int orientation = 0;
1051 foreach (int v in values)
1053 orientation |= (1 << (v / 90));
1055 return (DisplayRotation)orientation;