Add API comments
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Window.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Collections.Generic;
19
20 namespace ElmSharp
21 {
22     [Flags]
23     public enum DisplayRotation
24     {
25         Degree_0 = 1,
26         Degree_90 = 2,
27         Degree_180 = 4,
28         Degree_270 = 8
29     };
30
31     /// <summary>
32     /// Enum indicator opacity
33     /// </summary>
34     public enum StatusBarMode
35     {
36         /// <summary>
37         /// Opacifies the status bar
38         /// </summary>
39         Opaque = 1,
40
41         /// <summary>
42         /// Be translucent the status bar
43         /// </summary>
44         /// <remarks>
45         /// Not supported.
46         /// </remarks>
47         Translucent = 2,
48
49         /// <summary>
50         /// Transparentizes the status bar
51         /// </summary>
52         Transparent = 3,
53     }
54
55     /// <summary>
56     /// The Window is container that contain the graphical user interface of a program.
57     /// </summary>
58     public class Window : Widget
59     {
60         SmartEvent _deleteRequest;
61         SmartEvent _rotationChanged;
62         HashSet<EvasObject> _referenceHolder = new HashSet<EvasObject>();
63
64         /// <summary>
65         /// Creates and initializes a new instance of the Window class.
66         /// </summary>
67         /// <param name="name">Window name.</param>
68         public Window(string name) : this(null, name)
69         {
70         }
71
72         /// <summary>
73         /// Creates and initializes a new instance of the Window class.
74         /// </summary>
75         /// <param name="parent">
76         /// Parent widget which this widow created on.
77         /// </param>
78         /// <param name="name">
79         /// Window name.
80         /// </param>
81         /// <remarks>
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.
85         /// </remarks>
86         public Window(Window parent, string name)
87         {
88             Name = name;
89             Realize(parent);
90             Interop.Elementary.elm_win_indicator_mode_set(Handle, 2 /* ELM_WIN_INDICATOR_SHOW */);
91
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);
96         }
97
98         protected Window()
99         {
100         }
101
102         /// <summary>
103         /// CloseRequested will be triggered when Window close.
104         /// </summary>
105         public event EventHandler CloseRequested;
106
107         /// <summary>
108         /// RotationChanged will be triggered when Window do rotation.
109         /// </summary>
110         public event EventHandler RotationChanged;
111
112         /// <summary>
113         /// Sets or gets Window name.
114         /// </summary>
115         public string Name { get; set; }
116
117         /// <summary>
118         /// Gets Window size with Size value(w,h)
119         /// </summary>
120         public Size ScreenSize
121         {
122             get
123             {
124                 int x, y, w, h;
125                 Interop.Elementary.elm_win_screen_size_get(Handle, out x, out y, out w, out h);
126                 return new Size(w, h);
127             }
128         }
129
130         /// <summary>
131         /// Gets the screen dpi for the screen that a Window is on.
132         /// </summary>
133         public Point ScreenDpi
134         {
135             get
136             {
137                 Point point = default(Point);
138                 Interop.Elementary.elm_win_screen_dpi_get(Handle, out point.X, out point.Y);
139                 return point;
140             }
141         }
142
143         /// <summary>
144         /// Gets the rotation of the Window.The rotation of the window in degrees (0-360).
145         /// </summary>
146         public int Rotation
147         {
148             get
149             {
150                 return Interop.Elementary.elm_win_rotation_get(Handle);
151             }
152         }
153
154         /// <summary>
155         /// Sets or gets value whether rotation is supported.
156         /// </summary>
157         public bool IsRotationSupported
158         {
159             get
160             {
161                 return Interop.Elementary.elm_win_wm_rotation_supported_get(Handle);
162             }
163         }
164
165         [Obsolete("Sorry, it's error typo of AvailableRotations, please use AvailableRotations")]
166         public DisplayRotation AavailableRotations { get; set; }
167
168
169         /// <summary>
170         /// Sets or gets available rotation degree.
171         /// </summary>
172         public DisplayRotation AvailableRotations
173         {
174             get
175             {
176                 int[] rotations;
177                 Interop.Elementary.elm_win_wm_rotation_available_rotations_get(Handle, out rotations);
178                 if (rotations == null)
179                 {
180                     return 0;
181                 }
182                 return ConvertToDisplayRotation(rotations);
183             }
184             set
185             {
186                 Interop.Elementary.elm_win_wm_rotation_available_rotations_set(Handle, ConvertDegreeArray(value));
187             }
188         }
189
190         /// <summary>
191         /// Sets or gets whether auto deletion function is enable.
192         /// </summary>
193         /// <remarks>
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.
196         /// </remarks>
197         public bool AutoDeletion
198         {
199             get
200             {
201                 return Interop.Elementary.elm_win_autodel_get(Handle);
202             }
203             set
204             {
205                 Interop.Elementary.elm_win_autodel_set(Handle, value);
206             }
207         }
208
209         public bool Alpha
210         {
211             get
212             {
213                 return Interop.Elementary.elm_win_alpha_get(Handle);
214             }
215             set
216             {
217                 Interop.Elementary.elm_win_alpha_set(Handle, value);
218             }
219         }
220
221         public string Role
222         {
223             get
224             {
225                 return Interop.Elementary.elm_win_role_get(Handle);
226             }
227             set
228             {
229                 Interop.Elementary.elm_win_role_set(Handle, value);
230             }
231         }
232
233         public StatusBarMode StatusBarMode
234         {
235             get
236             {
237                 return (StatusBarMode)Interop.Elementary.elm_win_indicator_opacity_get(Handle);
238             }
239             set
240             {
241                 Interop.Elementary.elm_win_indicator_opacity_set(Handle, (int)value);
242             }
243         }
244
245         /// <summary>
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.
248         /// </summary>
249         /// <remarks>
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.
252         /// </remarks>
253         public void Active()
254         {
255             Interop.Elementary.elm_win_activate(Handle);
256         }
257
258         /// <summary>
259         /// Adds obj as a resize object of the Window.
260         /// </summary>
261         /// <remarks>
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.
266         /// </remarks>
267         /// <param name="obj">
268         /// Resize object.
269         /// </param>
270         public void AddResizeObject(EvasObject obj)
271         {
272             Interop.Elementary.elm_win_resize_object_add(Handle, obj);
273         }
274
275
276         protected override IntPtr CreateHandle(EvasObject parent)
277         {
278             Interop.Elementary.elm_config_accel_preference_set("3d");
279             return Interop.Elementary.elm_win_add(parent != null ? parent.Handle : IntPtr.Zero, Name, 0);
280         }
281
282         internal void AddChild(EvasObject obj)
283         {
284             _referenceHolder.Add(obj);
285         }
286
287         internal void RemoveChild(EvasObject obj)
288         {
289             _referenceHolder.Remove(obj);
290         }
291
292         /// </return>
293         static int[] ConvertDegreeArray(DisplayRotation value)
294         {
295             List<int> rotations = new List<int>();
296             if (value.HasFlag(DisplayRotation.Degree_0))
297                 rotations.Add(0);
298             if (value.HasFlag(DisplayRotation.Degree_90))
299                 rotations.Add(90);
300             if (value.HasFlag(DisplayRotation.Degree_180))
301                 rotations.Add(180);
302             if (value.HasFlag(DisplayRotation.Degree_270))
303                 rotations.Add(270);
304             return rotations.ToArray();
305         }
306
307         static DisplayRotation ConvertToDisplayRotation(int[] values)
308         {
309             int orientation = 0;
310             foreach (int v in values)
311             {
312                 orientation |= (1 << (v / 90));
313             }
314             return (DisplayRotation)orientation;
315         }
316
317     }
318 }