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