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).
162 /// Since calling Show() on a popup restarts the timer controlling when it is hidden,
163 /// setting this before the popup is shown will in effect mean starting the timer when the popup is shown.
164 /// TimedOut is called afterwards which can be handled if needed.
165 /// Set a value <= 0.0 to disable a running timer.If the value > 0.0 and the popup is previously visible,
166 /// the timer will be started with this value, canceling any running timer.
168 public double Timeout
172 return Interop.Elementary.elm_popup_timeout_get(Handle);
176 Interop.Elementary.elm_popup_timeout_set(Handle, value);
181 /// Sets or gets whether events should be passed to event blocked area by a click outside.
184 /// The visible region of popup is surrounded by a translucent region called Blocked Event area.
186 public bool AllowEvents
190 return Interop.Elementary.elm_popup_allow_events_get(Handle);
194 Interop.Elementary.elm_popup_allow_events_set(Handle, value);
199 /// Sets or gets the AlignmentX in which the popup will appear in its parent.
201 public override double AlignmentX
205 return Interop.Elementary.GetPopupAlignX(Handle);
209 Interop.Elementary.SetPopupAlignX(Handle, value);
214 /// Sets or gets the AlignmentY in which the popup will appear in its parent.
216 public override double AlignmentY
220 return Interop.Elementary.GetPopupAlignY(Handle);
224 Interop.Elementary.SetPopupAlignY(Handle, value);
229 /// Gets the Opacity value of the Popup.
231 public override int Opacity
235 return Color.Default.A;
240 Console.WriteLine("Popup instance doesn't support to set Opacity.");
245 /// Adds label to a Popup widget.
247 /// <param name="label"></param>
248 /// <returns>The new PopupItem which contains label .</returns>
249 public PopupItem Append(string label)
251 return Append(label, null);
255 /// Adds Label and icon to a Popup widget.
257 /// <param name="label">The Label which will be added into a new PopupItem. </param>
258 /// <param name="icon">The icon which will be added into a new PopupItem. </param>
259 /// <returns>The new PopupItem which contains label and icon.</returns>
260 public PopupItem Append(string label, EvasObject icon)
262 PopupItem item = new PopupItem(label, icon);
263 item.Handle = Interop.Elementary.elm_popup_item_append(Handle, label, icon, null, (IntPtr)item.Id);
269 /// Uses this function to dismiss the popup in hide effect.
270 /// when the Popup is dismissed, the "dismissed" signal will be emitted.
272 public void Dismiss()
274 Interop.Elementary.elm_popup_dismiss(Handle);
277 protected override IntPtr CreateHandle(EvasObject parent)
279 return Interop.Elementary.elm_popup_add(parent.Handle);
281 void AddInternal(PopupItem item)
284 item.Deleted += Item_Deleted;
286 void Item_Deleted(object sender, EventArgs e)
288 _children.Remove((PopupItem)sender);