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 popup orientation types.
25 /// <since_tizen> preview </since_tizen>
26 public enum PopupOrientation
29 /// Appears in the top of parent, by default.
33 /// Appears in the center of parent.
37 /// Appears in the bottom of parent.
41 /// Appears in the left of parent.
45 /// Appears in the right of parent.
49 /// Appears in the top left of parent.
53 /// Appears in the top right of parent.
57 /// Appears in the bottom left of parent.
61 /// Appears in the bottom right of parent.
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.
70 /// <since_tizen> preview </since_tizen>
71 public class Popup : Layout
73 HashSet<PopupItem> _children = new HashSet<PopupItem>();
74 SmartEvent _dismissed;
75 SmartEvent _blockClicked;
77 SmartEvent _showFinished;
80 /// Creates and initializes a new instance of the Popup class.
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)
86 _dismissed = new SmartEvent(this, "dismissed");
87 _dismissed.On += (sender, e) =>
89 Dismissed?.Invoke(this, EventArgs.Empty);
92 _blockClicked = new SmartEvent(this, "block,clicked");
93 _blockClicked.On += (sender, e) =>
95 OutsideClicked?.Invoke(this, EventArgs.Empty);
98 _timeout = new SmartEvent(this, "timeout");
99 _timeout.On += (sender, e) =>
101 TimedOut?.Invoke(this, EventArgs.Empty);
104 _showFinished = new SmartEvent(this, "show,finished");
105 _showFinished.On += (sender, e) =>
107 ShowAnimationFinished?.Invoke(this, EventArgs.Empty);
112 /// Dismissed will be triggered when the popup has been dismissed.
114 /// <since_tizen> preview </since_tizen>
115 public event EventHandler Dismissed;
118 /// OutsideClicked will be triggered when users taps on the outside of Popup.
120 /// <since_tizen> preview </since_tizen>
121 public event EventHandler OutsideClicked;
124 /// OutsideClicked will be triggered when the popup is closed as a result of timeout.
126 /// <since_tizen> preview </since_tizen>
127 public event EventHandler TimedOut;
130 /// OutsideClicked will be triggered when the popup transition has finished in showing.
132 /// <since_tizen> preview </since_tizen>
133 public event EventHandler ShowAnimationFinished;
136 /// Sets or gets the position in which the popup will appear in its parent.
138 /// <since_tizen> preview </since_tizen>
139 public PopupOrientation Orientation
143 return (PopupOrientation)Interop.Elementary.elm_popup_orient_get(Handle);
147 Interop.Elementary.elm_popup_orient_set(Handle, (int)value);
152 /// Sets or gets the wrapping type of content text packed in the content area of Popup widget.
155 /// Popup need to wrap the content text, so not allowing WrapType.None.
157 /// <since_tizen> preview </since_tizen>
158 public WrapType ContentTextWrapType
162 return (WrapType)Interop.Elementary.elm_popup_content_text_wrap_type_get(Handle);
166 Interop.Elementary.elm_popup_content_text_wrap_type_set(Handle, (int)value);
171 /// Sets or gets the timeout value set to the popup (in seconds).
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.
180 /// <since_tizen> preview </since_tizen>
181 public double Timeout
185 return Interop.Elementary.elm_popup_timeout_get(Handle);
189 Interop.Elementary.elm_popup_timeout_set(Handle, value);
194 /// Sets or gets whether events should be passed to the event blocked area by a click outside.
197 /// The visible region of the popup is surrounded by a translucent region called the Blocked event area.
199 /// <since_tizen> preview </since_tizen>
200 public bool AllowEvents
204 return Interop.Elementary.elm_popup_allow_events_get(Handle);
208 Interop.Elementary.elm_popup_allow_events_set(Handle, value);
213 /// Sets or gets the AlignmentX in which the popup will appear in its parent.
215 /// <since_tizen> preview </since_tizen>
216 public override double AlignmentX
220 return Interop.Elementary.GetPopupAlignX(Handle);
224 Interop.Elementary.SetPopupAlignX(Handle, value);
229 /// Sets or gets the AlignmentY in which the popup will appear in its parent.
231 /// <since_tizen> preview </since_tizen>
232 public override double AlignmentY
236 return Interop.Elementary.GetPopupAlignY(Handle);
240 Interop.Elementary.SetPopupAlignY(Handle, value);
245 /// Gets the opacity value of the popup.
247 /// <since_tizen> preview </since_tizen>
248 public override int Opacity
252 return Color.Default.A;
257 Console.WriteLine("Popup instance doesn't support to set Opacity.");
262 /// Adds the label to a Popup widget.
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)
269 return Append(label, null);
273 /// Adds the Label and icon to a Popup widget.
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)
281 PopupItem item = new PopupItem(label, icon, this);
282 item.Handle = Interop.Elementary.elm_popup_item_append(Handle, label, icon, null, (IntPtr)item.Id);
288 /// Uses this function to dismiss the popup in hide effect.
289 /// When the Popup is dismissed, the "dismissed" signal will be emitted.
291 /// <since_tizen> preview </since_tizen>
292 public void Dismiss()
294 Interop.Elementary.elm_popup_dismiss(Handle);
298 /// Creates a widget handle.
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)
305 return Interop.Elementary.elm_popup_add(parent.Handle);
307 void AddInternal(PopupItem item)
310 item.Deleted += Item_Deleted;
312 void Item_Deleted(object sender, EventArgs e)
314 _children.Remove((PopupItem)sender);