Merge "Add comments For EvasObject/EvasObjectEvent/FlipSelector/FlipSelectorItem...
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Popup.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     /// <summary>
23     /// Enumeration for the popup orientation type.
24     /// </summary>
25     public enum PopupOrientation
26     {
27         /// <summary>
28         /// Appears in the top of parent, default.
29         /// </summary>
30         Top,
31         /// <summary>
32         /// Appears in the center of parent.
33         /// </summary>
34         Center,
35         /// <summary>
36         /// Appears in the bottom of parent.
37         /// </summary>
38         Bottom,
39         /// <summary>
40         /// Appears in the left of parent.
41         /// </summary>
42         Left,
43         /// <summary>
44         /// Appears in the right of parent.
45         /// </summary>
46         Right,
47         /// <summary>
48         /// Appears in the top left of parent.
49         /// </summary>
50         TopLeft,
51         /// <summary>
52         /// Appears in the top right of parent.
53         /// </summary>
54         TopRight,
55         /// <summary>
56         /// Appears in the bottom left of parent.
57         /// </summary>
58         BottomLeft,
59         /// <summary>
60         /// Appears in the bottom right of parent.
61         /// </summary>
62         BottomRight
63     }
64
65     /// <summary>
66     /// The Popup is a widget that is an enhancement of Notify.
67     /// In addition to content area, there are two optional sections, namely title area and action area.
68     /// </summary>
69     public class Popup : Layout
70     {
71         HashSet<PopupItem> _children = new HashSet<PopupItem>();
72         SmartEvent _dismissed;
73         SmartEvent _blockClicked;
74         SmartEvent _timeout;
75         SmartEvent _showFinished;
76
77         /// <summary>
78         /// Creates and initializes a new instance of the Popup class.
79         /// </summary>
80         /// <param name="parent">The EvasObject to which the new Popup will be attached as a child.</param>
81         public Popup(EvasObject parent) : base(parent)
82         {
83             _dismissed = new SmartEvent(this, "dismissed");
84             _dismissed.On += (sender, e) =>
85             {
86                 Dismissed?.Invoke(this, EventArgs.Empty);
87             };
88
89             _blockClicked = new SmartEvent(this, "block,clicked");
90             _blockClicked.On += (sender, e) =>
91             {
92                 OutsideClicked?.Invoke(this, EventArgs.Empty);
93             };
94
95             _timeout = new SmartEvent(this, "timeout");
96             _timeout.On += (sender, e) =>
97             {
98                 TimedOut?.Invoke(this, EventArgs.Empty);
99             };
100
101             _showFinished = new SmartEvent(this, "show,finished");
102             _showFinished.On += (sender, e) =>
103             {
104                 ShowAnimationFinished?.Invoke(this, EventArgs.Empty);
105             };
106         }
107
108         /// <summary>
109         /// Dismissed will be triggered when Popup have been dismissed.
110         /// </summary>
111         public event EventHandler Dismissed;
112
113         /// <summary>
114         /// OutsideClicked will be triggered when users taps on the outside of Popup.
115         /// </summary>
116         public event EventHandler OutsideClicked;
117
118         /// <summary>
119         /// OutsideClicked will be triggered when Popup is closed as a result of timeout.
120         /// </summary>
121         public event EventHandler TimedOut;
122
123         /// <summary>
124         /// OutsideClicked will be triggered when the Popup transition is finished in showing.
125         /// </summary>
126         public event EventHandler ShowAnimationFinished;
127
128         /// <summary>
129         /// Sets or gets the position in which Popup will appear in its parent.
130         /// </summary>
131         public PopupOrientation Orientation
132         {
133             get
134             {
135                 return (PopupOrientation)Interop.Elementary.elm_popup_orient_get(Handle);
136             }
137             set
138             {
139                 Interop.Elementary.elm_popup_orient_set(Handle, (int)value);
140             }
141         }
142
143         /// <summary>
144         /// Sets or gets the wrapping type of content text packed in content area of Popup widget.
145         /// </summary>
146         public WrapType ContentTextWrapType
147         {
148             get
149             {
150                 return (WrapType)Interop.Elementary.elm_popup_content_text_wrap_type_get(Handle);
151             }
152             set
153             {
154                 Interop.Elementary.elm_popup_content_text_wrap_type_set(Handle, (int)value);
155             }
156         }
157
158         /// <summary>
159         /// Sets or gets the timeout value set to the Popup(in seconds).
160         /// </summary>
161         public double Timeout
162         {
163             get
164             {
165                 return Interop.Elementary.elm_popup_timeout_get(Handle);
166             }
167             set
168             {
169                 Interop.Elementary.elm_popup_timeout_set(Handle, value);
170             }
171         }
172
173         /// <summary>
174         /// Sets or gets whether events should be passed to event blocked area by a click outside.
175         /// </summary>
176         /// <remarks>
177         /// The visible region of popup is surrounded by a translucent region called Blocked Event area.
178         /// </remarks>
179         public bool AllowEvents
180         {
181             get
182             {
183                 return Interop.Elementary.elm_popup_allow_events_get(Handle);
184             }
185             set
186             {
187                 Interop.Elementary.elm_popup_allow_events_set(Handle, value);
188             }
189         }
190
191         /// <summary>
192         /// Sets or gets the AlignmentX in which the popup will appear in its parent.
193         /// </summary>
194         public override double AlignmentX
195         {
196             get
197             {
198                 return Interop.Elementary.GetPopupAlignX(Handle);
199             }
200             set
201             {
202                 Interop.Elementary.SetPopupAlignX(Handle, value);
203             }
204         }
205
206         /// <summary>
207         /// Sets or gets the AlignmentY in which the popup will appear in its parent.
208         /// </summary>
209         public override double AlignmentY
210         {
211             get
212             {
213                 return Interop.Elementary.GetPopupAlignY(Handle);
214             }
215             set
216             {
217                 Interop.Elementary.SetPopupAlignY(Handle, value);
218             }
219         }
220
221         /// <summary>
222         /// Gets the Opacity value set to the Popup(in seconds).
223         /// </summary>
224         public override int Opacity
225         {
226             get
227             {
228                 return Color.Default.A;
229             }
230
231             set
232             {
233                 Console.WriteLine("Popup instance doesn't support to set Opacity.");
234             }
235         }
236
237         /// <summary>
238         /// Adds label to a Popup widget.
239         /// </summary>
240         /// <param name="label"></param>
241         /// <returns>The new PopupItem which contains label .</returns>
242         public PopupItem Append(string label)
243         {
244             return Append(label, null);
245         }
246
247         /// <summary>
248         /// Adds Label and icon to a Popup widget.
249         /// </summary>
250         /// <param name="label">The Label which will be added into a new PopupItem. </param>
251         /// <param name="icon">The icon which will be added into a new PopupItem. </param>
252         /// <returns>The new PopupItem which contains label and icon.</returns>
253         public PopupItem Append(string label, EvasObject icon)
254         {
255             PopupItem item = new PopupItem(label, icon);
256             item.Handle = Interop.Elementary.elm_popup_item_append(Handle, label, icon, null, (IntPtr)item.Id);
257             AddInternal(item);
258             return item;
259         }
260
261         /// <summary>
262         /// Uses this function to dismiss the popup in hide effect.
263         /// when the Popup is dismissed, the "dismissed" signal will be emitted.
264         /// </summary>
265         public void Dismiss()
266         {
267             Interop.Elementary.elm_popup_dismiss(Handle);
268         }
269
270         protected override IntPtr CreateHandle(EvasObject parent)
271         {
272             return Interop.Elementary.elm_popup_add(parent.Handle);
273         }
274         void AddInternal(PopupItem item)
275         {
276             _children.Add(item);
277             item.Deleted += Item_Deleted;
278         }
279         void Item_Deleted(object sender, EventArgs e)
280         {
281             _children.Remove((PopupItem)sender);
282         }
283     }
284 }