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;
23 /// Enumeration for the display rotation of window.
26 public enum DisplayRotation
29 /// Rotation value of window is 0 degree
33 /// Rotation value of window is 90 degree
37 /// Rotation value of window is 180 degree
41 /// Rotation value of window is 270 degree
47 /// Enum indicator opacity
49 public enum StatusBarMode
52 /// Opacifies the status bar
57 /// Be translucent the status bar
65 /// Transparentizes the status bar
71 /// The Window is container that contain the graphical user interface of a program.
73 public class Window : Widget
75 SmartEvent _deleteRequest;
76 SmartEvent _rotationChanged;
77 HashSet<EvasObject> _referenceHolder = new HashSet<EvasObject>();
80 /// Creates and initializes a new instance of the Window class.
82 /// <param name="name">Window name.</param>
83 public Window(string name) : this(null, name)
88 /// Creates and initializes a new instance of the Window class.
90 /// <param name="parent">
91 /// Parent widget which this widow created on.
93 /// <param name="name">
97 /// Window constructor.show window indicator,set callback
98 /// When closing the window in any way outside the program control,
99 /// and set callback when window rotation changed.
101 public Window(Window parent, string name)
105 Interop.Elementary.elm_win_indicator_mode_set(Handle, 2 /* ELM_WIN_INDICATOR_SHOW */);
107 _deleteRequest = new SmartEvent(this, "delete,request");
108 _rotationChanged = new SmartEvent(this, "wm,rotation,changed");
109 _deleteRequest.On += (s, e) => CloseRequested?.Invoke(this, EventArgs.Empty);
110 _rotationChanged.On += (s, e) => RotationChanged?.Invoke(this, EventArgs.Empty);
118 /// CloseRequested will be triggered when Window close.
120 public event EventHandler CloseRequested;
123 /// RotationChanged will be triggered when Window do rotation.
125 public event EventHandler RotationChanged;
128 /// Sets or gets Window name.
130 public string Name { get; set; }
133 /// Gets Window size with Size value(w,h)
135 public Size ScreenSize
140 Interop.Elementary.elm_win_screen_size_get(Handle, out x, out y, out w, out h);
141 return new Size(w, h);
146 /// Gets the screen dpi for the screen that a Window is on.
148 public Point ScreenDpi
152 Point point = default(Point);
153 Interop.Elementary.elm_win_screen_dpi_get(Handle, out point.X, out point.Y);
159 /// Gets the rotation of the Window.The rotation of the window in degrees (0-360).
165 return Interop.Elementary.elm_win_rotation_get(Handle);
170 /// Gets whether window manager supports window rotation or not.
172 public bool IsRotationSupported
176 return Interop.Elementary.elm_win_wm_rotation_supported_get(Handle);
180 [Obsolete("Sorry, it's error typo of AvailableRotations, please use AvailableRotations")]
181 public DisplayRotation AavailableRotations { get; set; }
185 /// Sets or gets available rotation degree.
187 public DisplayRotation AvailableRotations
192 Interop.Elementary.elm_win_wm_rotation_available_rotations_get(Handle, out rotations);
193 if (rotations == null)
197 return ConvertToDisplayRotation(rotations);
201 Interop.Elementary.elm_win_wm_rotation_available_rotations_set(Handle, ConvertDegreeArray(value));
206 /// Sets or gets whether auto deletion function is enable.
209 /// If you enable auto deletion, the window is automatically destroyed after the signal is emitted.
210 /// If auto deletion is disabled, the window is not destroyed and the program has to handle it.
212 public bool AutoDeletion
216 return Interop.Elementary.elm_win_autodel_get(Handle);
220 Interop.Elementary.elm_win_autodel_set(Handle, value);
225 /// Sets or gets the alpha channel state of a window.
228 /// True if the window alpha channel is enabled, false otherwise.
229 /// If alpha is true, the alpha channel of the canvas will be enabled possibly making parts of the window completely or partially transparent.
235 return Interop.Elementary.elm_win_alpha_get(Handle);
239 Interop.Elementary.elm_win_alpha_set(Handle, value);
244 /// Sets or gets the role of the window.
247 /// The Role will be invalid if a new role is set or if the window is destroyed.
253 return Interop.Elementary.elm_win_role_get(Handle);
257 Interop.Elementary.elm_win_role_set(Handle, value);
262 /// Sets or gets the mode of status bar.
264 public StatusBarMode StatusBarMode
268 return (StatusBarMode)Interop.Elementary.elm_win_indicator_opacity_get(Handle);
272 Interop.Elementary.elm_win_indicator_opacity_set(Handle, (int)value);
277 /// This function sends a request to the Windows Manager to activate the Window.
278 /// If honored by the WM, the window receives the keyboard focus.
281 /// This is just a request that a Window Manager may ignore, so calling this function does not ensure
282 /// in any way that the window is going to be the active one after it.
286 Interop.Elementary.elm_win_activate(Handle);
290 /// Adds obj as a resize object of the Window.
293 /// Setting an object as a resize object of the window means that the obj child's size and
294 /// position is controlled by the window directly. That is, the obj is resized to match the window size
295 /// and should never be moved or resized manually by the developer.In addition,
296 /// resize objects of the window control the minimum size of it as well as whether it can or cannot be resized by the user.
298 /// <param name="obj">
301 public void AddResizeObject(EvasObject obj)
303 Interop.Elementary.elm_win_resize_object_add(Handle, obj);
308 /// Set the keygrab of the window.
310 /// <param name="keyname">keyname string to set keygrab</param>
311 public void KeyGrabEx(string keyname)
313 Interop.Elementary.eext_win_keygrab_set(RealHandle, keyname);
317 /// Unset the keygrab of the window.
319 /// <param name="keyname">keyname string to unset keygrab</param>
320 public void KeyUngrabEx(string keyname)
322 Interop.Elementary.eext_win_keygrab_unset(RealHandle, keyname);
325 protected override IntPtr CreateHandle(EvasObject parent)
327 Interop.Elementary.elm_config_accel_preference_set("3d");
328 return Interop.Elementary.elm_win_add(parent != null ? parent.Handle : IntPtr.Zero, Name, 0);
331 internal void AddChild(EvasObject obj)
333 _referenceHolder.Add(obj);
336 internal void RemoveChild(EvasObject obj)
338 _referenceHolder.Remove(obj);
341 static int[] ConvertDegreeArray(DisplayRotation value)
343 List<int> rotations = new List<int>();
344 if (value.HasFlag(DisplayRotation.Degree_0))
346 if (value.HasFlag(DisplayRotation.Degree_90))
348 if (value.HasFlag(DisplayRotation.Degree_180))
350 if (value.HasFlag(DisplayRotation.Degree_270))
352 return rotations.ToArray();
355 static DisplayRotation ConvertToDisplayRotation(int[] values)
358 foreach (int v in values)
360 orientation |= (1 << (v / 90));
362 return (DisplayRotation)orientation;