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 ContextPopup direction types.
25 /// <since_tizen> preview </since_tizen>
26 public enum ContextPopupDirection
29 /// The ContextPopup appears below the clicked area.
33 /// The ContextPopup appears to the right of the clicked area.
37 /// The ContextPopup appears to the left of the clicked area.
41 /// The ContextPopup appears above the clicked area.
45 /// The ContextPopup does not determine it's direction yet.
51 /// It inherits <see cref="Layout"/>.
52 /// The ContextPopup is a widget that when shown, pops up a list of items.
54 /// <since_tizen> preview </since_tizen>
55 public class ContextPopup : Layout
57 HashSet<ContextPopupItem> _children = new HashSet<ContextPopupItem>();
58 SmartEvent _dismissed;
59 Interop.Evas.SmartCallback _onSelected;
62 /// Creates and initializes a new instance of the ContextPopup class.
64 /// <param name="parent">The parent is a given container, which will be attached by ContextPopup
65 /// as a child. It's <see cref="EvasObject"/> type.</param>
66 /// <since_tizen> preview </since_tizen>
67 public ContextPopup(EvasObject parent) : base(parent)
69 _dismissed = new SmartEvent(this, this.RealHandle, "dismissed");
70 _dismissed.On += (sender, e) =>
72 Dismissed?.Invoke(this, EventArgs.Empty);
74 _onSelected = (data, obj, info) =>
76 ContextPopupItem item = ItemObject.GetItemById((int)data) as ContextPopupItem;
82 /// Dismissed is raised when the ContextPopup item is dismissed.
85 /// Outside of ContextPopup is clicked or it's parent area is changed or the language is changed, and then ContextPopup is dismissed.
87 /// <since_tizen> preview </since_tizen>
88 public event EventHandler Dismissed;
91 /// Gets the current direction of a ContextPopup.
94 /// Once the ContextPopup shows up, the direction would be determined.
96 /// <since_tizen> preview </since_tizen>
97 public ContextPopupDirection Direction
101 return (ContextPopupDirection)Interop.Elementary.elm_ctxpopup_direction_get(RealHandle);
106 /// Gets or sets the value of the current ContextPopup object's orientation.
107 /// True for horizontal mode, False for vertical mode (or errors).
109 /// <since_tizen> preview </since_tizen>
110 public bool IsHorizontal
114 return Interop.Elementary.elm_ctxpopup_horizontal_get(RealHandle);
118 Interop.Elementary.elm_ctxpopup_horizontal_set(RealHandle, value);
123 /// Gets or sets whether the ContextPopup hides automatically
124 /// or not when the parent of the ContextPopup is resized.
127 /// Default value of AutoHide is False.
129 /// <since_tizen> preview </since_tizen>
134 return !Interop.Elementary.elm_ctxpopup_auto_hide_disabled_get(RealHandle);
138 Interop.Elementary.elm_ctxpopup_auto_hide_disabled_set(RealHandle, !value);
143 /// Clears all the items in a given ContextPopup object.
145 /// <since_tizen> preview </since_tizen>
148 Interop.Elementary.elm_ctxpopup_clear(Handle);
152 /// Sets the direction priority of a ContextPopup.
154 /// <param name="first">1st priority of the direction.</param>
155 /// <param name="second">2nd priority of the direction.</param>
156 /// <param name="third">3th priority of the direction.</param>
157 /// <param name="fourth">4th priority of the direction.</param>
158 /// <since_tizen> preview </since_tizen>
159 public void SetDirectionPriorty(ContextPopupDirection first, ContextPopupDirection second, ContextPopupDirection third, ContextPopupDirection fourth)
161 Interop.Elementary.elm_ctxpopup_direction_priority_set(RealHandle, (int)first, (int)second, (int)third, (int)fourth);
165 /// Gets the direction priority of a ContextPopup.
167 /// <param name="first">1st priority of the direction to be returned.</param>
168 /// <param name="second">2nd priority of the direction to be returned.</param>
169 /// <param name="third">2nd priority of the direction to be returned.</param>
170 /// <param name="fourth">4th priority of the direction to be returned.</param>
171 /// <since_tizen> preview </since_tizen>
172 public void GetDirectionPriority(out ContextPopupDirection first, out ContextPopupDirection second, out ContextPopupDirection third, out ContextPopupDirection fourth)
174 int firstOut, secondOut, thirdOut, fourthOut;
175 Interop.Elementary.elm_ctxpopup_direction_priority_get(Handle, out firstOut, out secondOut, out thirdOut, out fourthOut);
176 first = (ContextPopupDirection)firstOut;
177 second = (ContextPopupDirection)secondOut;
178 third = (ContextPopupDirection)thirdOut;
179 fourth = (ContextPopupDirection)fourthOut;
183 /// Adds a new item to a ContextPopup object with the label.
185 /// <param name="label">Label of the new item.</param>
187 /// A ContextPopupItem added, or null on errors.
189 /// <since_tizen> preview </since_tizen>
190 public ContextPopupItem Append(string label)
192 return Append(label, null);
196 /// Adds a new item to a ContextPopup object with the label and icon.
198 /// <param name="label">Label of the new item.</param>
199 /// <param name="icon">Icon to be set on the new item.</param>
200 /// <returns>A ContextPopupItem added, or null on errors.</returns>
201 /// <since_tizen> preview </since_tizen>
202 public ContextPopupItem Append(string label, EvasObject icon)
204 ContextPopupItem item = new ContextPopupItem(label, icon, this);
205 item.Handle = Interop.Elementary.elm_ctxpopup_item_append(RealHandle, label, icon, _onSelected, (IntPtr)item.Id);
211 /// Dismisses a ContextPopup object. The ContextPopup will be hidden and the "clicked" signal will be emitted.
213 /// <since_tizen> preview </since_tizen>
214 public void Dismiss()
216 Interop.Elementary.elm_ctxpopup_dismiss(RealHandle);
220 /// Gets the possibility that the direction would be available.
222 /// <param name="direction">A direction that the user wants to check.</param>
224 /// Get false if you cannot put it in the direction. Get true if it's possible.
226 /// <since_tizen> preview </since_tizen>
227 public bool IsAvailableDirection(ContextPopupDirection direction)
229 return Interop.Elementary.elm_ctxpopup_direction_available_get(RealHandle, (int)direction);
233 /// Gets the Alpha of a default Color class.
235 /// <since_tizen> preview </since_tizen>
236 public override int Opacity
240 return Color.Default.A;
245 Console.WriteLine("ContextPopup instance doesn't support to set Opacity.");
250 /// Creates a widget handle.
252 /// <param name="parent">Parent EvasObject.</param>
253 /// <returns>Handle IntPtr.</returns>
254 /// <since_tizen> preview </since_tizen>
255 protected override IntPtr CreateHandle(EvasObject parent)
257 return Interop.Elementary.elm_ctxpopup_add(parent.Handle);
260 void AddInternal(ContextPopupItem item)
263 item.Deleted += Item_Deleted;
266 void Item_Deleted(object sender, EventArgs e)
268 _children.Remove((ContextPopupItem)sender);