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 public enum DisplayRotation
32 /// Enum indicator opacity
34 public enum StatusBarMode
37 /// Opacifies the status bar
42 /// Be translucent the status bar
50 /// Transparentizes the status bar
56 /// The Window is container that contain the graphical user interface of a program.
58 public class Window : Widget
60 SmartEvent _deleteRequest;
61 SmartEvent _rotationChanged;
62 HashSet<EvasObject> _referenceHolder = new HashSet<EvasObject>();
65 /// Creates and initializes a new instance of the Window class.
67 /// <param name="name">Window name.</param>
68 public Window(string name) : this(null, name)
73 /// Creates and initializes a new instance of the Window class.
75 /// <param name="parent">
76 /// Parent widget which this widow created on.
78 /// <param name="name">
82 /// Window constructor.show window indicator,set callback
83 /// When closing the window in any way outside the program control,
84 /// and set callback when window rotation changed.
86 public Window(Window parent, string name)
90 Interop.Elementary.elm_win_indicator_mode_set(Handle, 2 /* ELM_WIN_INDICATOR_SHOW */);
92 _deleteRequest = new SmartEvent(this, "delete,request");
93 _rotationChanged = new SmartEvent(this, "wm,rotation,changed");
94 _deleteRequest.On += (s, e) => CloseRequested?.Invoke(this, EventArgs.Empty);
95 _rotationChanged.On += (s, e) => RotationChanged?.Invoke(this, EventArgs.Empty);
103 /// CloseRequested will be triggered when Window close.
105 public event EventHandler CloseRequested;
108 /// RotationChanged will be triggered when Window do rotation.
110 public event EventHandler RotationChanged;
113 /// Sets or gets Window name.
115 public string Name { get; set; }
118 /// Gets Window size with Size value(w,h)
120 public Size ScreenSize
125 Interop.Elementary.elm_win_screen_size_get(Handle, out x, out y, out w, out h);
126 return new Size(w, h);
131 /// Gets the screen dpi for the screen that a Window is on.
133 public Point ScreenDpi
137 Point point = default(Point);
138 Interop.Elementary.elm_win_screen_dpi_get(Handle, out point.X, out point.Y);
144 /// Gets the rotation of the Window.The rotation of the window in degrees (0-360).
150 return Interop.Elementary.elm_win_rotation_get(Handle);
155 /// Sets or gets value whether rotation is supported.
157 public bool IsRotationSupported
161 return Interop.Elementary.elm_win_wm_rotation_supported_get(Handle);
165 [Obsolete("Sorry, it's error typo of AvailableRotations, please use AvailableRotations")]
166 public DisplayRotation AavailableRotations { get; set; }
170 /// Sets or gets available rotation degree.
172 public DisplayRotation AvailableRotations
177 Interop.Elementary.elm_win_wm_rotation_available_rotations_get(Handle, out rotations);
178 if (rotations == null)
182 return ConvertToDisplayRotation(rotations);
186 Interop.Elementary.elm_win_wm_rotation_available_rotations_set(Handle, ConvertDegreeArray(value));
191 /// Sets or gets whether auto deletion function is enable.
194 /// If you enable auto deletion, the window is automatically destroyed after the signal is emitted.
195 /// If auto deletion is disabled, the window is not destroyed and the program has to handle it.
197 public bool AutoDeletion
201 return Interop.Elementary.elm_win_autodel_get(Handle);
205 Interop.Elementary.elm_win_autodel_set(Handle, value);
213 return Interop.Elementary.elm_win_alpha_get(Handle);
217 Interop.Elementary.elm_win_alpha_set(Handle, value);
225 return Interop.Elementary.elm_win_role_get(Handle);
229 Interop.Elementary.elm_win_role_set(Handle, value);
233 public StatusBarMode StatusBarMode
237 return (StatusBarMode)Interop.Elementary.elm_win_indicator_opacity_get(Handle);
241 Interop.Elementary.elm_win_indicator_opacity_set(Handle, (int)value);
246 /// This function sends a request to the Windows Manager to activate the Window.
247 /// If honored by the WM, the window receives the keyboard focus.
250 /// This is just a request that a Window Manager may ignore, so calling this function does not ensure
251 /// in any way that the window is going to be the active one after it.
255 Interop.Elementary.elm_win_activate(Handle);
259 /// Adds obj as a resize object of the Window.
262 /// Setting an object as a resize object of the window means that the obj child's size and
263 /// position is controlled by the window directly. That is, the obj is resized to match the window size
264 /// and should never be moved or resized manually by the developer.In addition,
265 /// resize objects of the window control the minimum size of it as well as whether it can or cannot be resized by the user.
267 /// <param name="obj">
270 public void AddResizeObject(EvasObject obj)
272 Interop.Elementary.elm_win_resize_object_add(Handle, obj);
276 protected override IntPtr CreateHandle(EvasObject parent)
278 Interop.Elementary.elm_config_accel_preference_set("3d");
279 return Interop.Elementary.elm_win_add(parent != null ? parent.Handle : IntPtr.Zero, Name, 0);
282 internal void AddChild(EvasObject obj)
284 _referenceHolder.Add(obj);
287 internal void RemoveChild(EvasObject obj)
289 _referenceHolder.Remove(obj);
293 static int[] ConvertDegreeArray(DisplayRotation value)
295 List<int> rotations = new List<int>();
296 if (value.HasFlag(DisplayRotation.Degree_0))
298 if (value.HasFlag(DisplayRotation.Degree_90))
300 if (value.HasFlag(DisplayRotation.Degree_180))
302 if (value.HasFlag(DisplayRotation.Degree_270))
304 return rotations.ToArray();
307 static DisplayRotation ConvertToDisplayRotation(int[] values)
310 foreach (int v in values)
312 orientation |= (1 << (v / 90));
314 return (DisplayRotation)orientation;