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 type.
25 public enum PopupOrientation
28 /// Appears in the top of parent, default.
32 /// Appears in the center of parent.
36 /// Appears in the bottom of parent.
40 /// Appears in the left of parent.
44 /// Appears in the right of parent.
48 /// Appears in the top left of parent.
52 /// Appears in the top right of parent.
56 /// Appears in the bottom left of parent.
60 /// Appears in the bottom right of parent.
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.
69 public class Popup : Layout
71 HashSet<PopupItem> _children = new HashSet<PopupItem>();
72 SmartEvent _dismissed;
73 SmartEvent _blockClicked;
75 SmartEvent _showFinished;
78 /// Creates and initializes a new instance of the Popup class.
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)
83 _dismissed = new SmartEvent(this, "dismissed");
84 _dismissed.On += (sender, e) =>
86 Dismissed?.Invoke(this, EventArgs.Empty);
89 _blockClicked = new SmartEvent(this, "block,clicked");
90 _blockClicked.On += (sender, e) =>
92 OutsideClicked?.Invoke(this, EventArgs.Empty);
95 _timeout = new SmartEvent(this, "timeout");
96 _timeout.On += (sender, e) =>
98 TimedOut?.Invoke(this, EventArgs.Empty);
101 _showFinished = new SmartEvent(this, "show,finished");
102 _showFinished.On += (sender, e) =>
104 ShowAnimationFinished?.Invoke(this, EventArgs.Empty);
109 /// Dismissed will be triggered when Popup have been dismissed.
111 public event EventHandler Dismissed;
114 /// OutsideClicked will be triggered when users taps on the outside of Popup.
116 public event EventHandler OutsideClicked;
119 /// OutsideClicked will be triggered when Popup is closed as a result of timeout.
121 public event EventHandler TimedOut;
124 /// OutsideClicked will be triggered when the Popup transition is finished in showing.
126 public event EventHandler ShowAnimationFinished;
129 /// Sets or gets the position in which Popup will appear in its parent.
131 public PopupOrientation Orientation
135 return (PopupOrientation)Interop.Elementary.elm_popup_orient_get(Handle);
139 Interop.Elementary.elm_popup_orient_set(Handle, (int)value);
144 /// Sets or gets the wrapping type of content text packed in content area of Popup widget.
146 public WrapType ContentTextWrapType
150 return (WrapType)Interop.Elementary.elm_popup_content_text_wrap_type_get(Handle);
154 Interop.Elementary.elm_popup_content_text_wrap_type_set(Handle, (int)value);
159 /// Sets or gets the timeout value set to the Popup(in seconds).
161 public double Timeout
165 return Interop.Elementary.elm_popup_timeout_get(Handle);
169 Interop.Elementary.elm_popup_timeout_set(Handle, value);
174 /// Sets or gets whether events should be passed to event blocked area by a click outside.
177 /// The visible region of popup is surrounded by a translucent region called Blocked Event area.
179 public bool AllowEvents
183 return Interop.Elementary.elm_popup_allow_events_get(Handle);
187 Interop.Elementary.elm_popup_allow_events_set(Handle, value);
192 /// Sets or gets the AlignmentX in which the popup will appear in its parent.
194 public override double AlignmentX
198 return Interop.Elementary.GetPopupAlignX(Handle);
202 Interop.Elementary.SetPopupAlignX(Handle, value);
207 /// Sets or gets the AlignmentY in which the popup will appear in its parent.
209 public override double AlignmentY
213 return Interop.Elementary.GetPopupAlignY(Handle);
217 Interop.Elementary.SetPopupAlignY(Handle, value);
222 /// Gets the Opacity value set to the Popup(in seconds).
224 public override int Opacity
228 return Color.Default.A;
233 Console.WriteLine("Popup instance doesn't support to set Opacity.");
238 /// Adds label to a Popup widget.
240 /// <param name="label"></param>
241 /// <returns>The new PopupItem which contains label .</returns>
242 public PopupItem Append(string label)
244 return Append(label, null);
248 /// Adds Label and icon to a Popup widget.
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)
255 PopupItem item = new PopupItem(label, icon);
256 item.Handle = Interop.Elementary.elm_popup_item_append(Handle, label, icon, null, (IntPtr)item.Id);
262 /// Uses this function to dismiss the popup in hide effect.
263 /// when the Popup is dismissed, the "dismissed" signal will be emitted.
265 public void Dismiss()
267 Interop.Elementary.elm_popup_dismiss(Handle);
270 protected override IntPtr CreateHandle(EvasObject parent)
272 return Interop.Elementary.elm_popup_add(parent.Handle);
274 void AddInternal(PopupItem item)
277 item.Deleted += Item_Deleted;
279 void Item_Deleted(object sender, EventArgs e)
281 _children.Remove((PopupItem)sender);