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 of ContextPopup direction type.
25 public enum ContextPopupDirection
28 /// ContextPopup show appear below clicked area
32 /// ContextPopup show appear to the right of the clicked area
36 /// ContextPopup show appear to the left of the clicked area
40 /// ContextPopup show appear above the clicked area
44 /// ContextPopup does not determine it's direction yet
50 /// It inherits <see cref="Layout"/>.
51 /// The ContextPopup is a widget that when it shown, pops up a list of items.
53 public class ContextPopup : Layout
55 HashSet<ContextPopupItem> _children = new HashSet<ContextPopupItem>();
56 SmartEvent _dismissed;
57 Interop.Evas.SmartCallback _onSelected;
60 /// Creates and initializes a new instance of the ContextPopup class.
62 /// <param name="parent">The parent is a given container which will be attached by ContextPopup
63 /// as a child.It's <see cref="EvasObject"/> type.</param>
64 public ContextPopup(EvasObject parent) : base(parent)
66 _dismissed = new SmartEvent(this, this.RealHandle, "dismissed");
67 _dismissed.On += (sender, e) =>
69 Dismissed?.Invoke(this, EventArgs.Empty);
71 _onSelected = (data, obj, info) =>
73 ContextPopupItem item = ItemObject.GetItemById((int)data) as ContextPopupItem;
79 /// Dismissed is raised when the ContextPopup item is dismissed.
82 /// Outside of ContextPopup was clicked or it's parent area is changed or the language is changed. and then ContextPopup is dismissed.
84 public event EventHandler Dismissed;
87 /// Gets the current direction of a ContextPopup.
90 /// Once the ContextPopup showed up, the direction would be determined.
92 public ContextPopupDirection Direction
96 return (ContextPopupDirection)Interop.Elementary.elm_ctxpopup_direction_get(RealHandle);
101 /// Gets or sets the value of current ContextPopup object's orientation.
102 /// True for horizontal mode, False for vertical mode (or errors)
104 public bool IsHorizontal
108 return Interop.Elementary.elm_ctxpopup_horizontal_get(RealHandle);
112 Interop.Elementary.elm_ctxpopup_horizontal_set(RealHandle, value);
117 /// Gets or sets whether ContextPopup hide automatically
118 /// or not when parent of ContextPopup is resized.
121 /// Default value of AutoHide is False.
127 return !Interop.Elementary.elm_ctxpopup_auto_hide_disabled_get(RealHandle);
131 Interop.Elementary.elm_ctxpopup_auto_hide_disabled_set(RealHandle, !value);
136 /// Clears all items in the given ContextPopup object.
140 Interop.Elementary.elm_ctxpopup_clear(Handle);
144 /// Sets the direction priority of a ContextPopup.
146 /// <param name="first">1st priority of direction </param>
147 /// <param name="second">2nd priority of direction </param>
148 /// <param name="third">3th priority of direction </param>
149 /// <param name="fourth">4th priority of direction</param>
150 public void SetDirectionPriorty(ContextPopupDirection first, ContextPopupDirection second, ContextPopupDirection third, ContextPopupDirection fourth)
152 Interop.Elementary.elm_ctxpopup_direction_priority_set(RealHandle, (int)first, (int)second, (int)third, (int)fourth);
156 /// Gets the direction priority of a ContextPopup.
158 /// <param name="first">1st priority of direction to be returned</param>
159 /// <param name="second">2nd priority of direction to be returned</param>
160 /// <param name="third">2nd priority of direction to be returned </param>
161 /// <param name="fourth">4th priority of direction to be returned</param>
162 public void GetDirectionPriority(out ContextPopupDirection first, out ContextPopupDirection second, out ContextPopupDirection third, out ContextPopupDirection fourth)
164 int firstOut, secondOut, thirdOut, fourthOut;
165 Interop.Elementary.elm_ctxpopup_direction_priority_get(Handle, out firstOut, out secondOut, out thirdOut, out fourthOut);
166 first = (ContextPopupDirection)firstOut;
167 second = (ContextPopupDirection)secondOut;
168 third = (ContextPopupDirection)thirdOut;
169 fourth = (ContextPopupDirection)fourthOut;
173 /// Adds a new item to a ContextPopup object with label.
175 /// <param name="label">The Label of the new item</param>
177 /// A ContextPopupItem added or NULL, on errors
179 public ContextPopupItem Append(string label)
181 return Append(label, null);
185 /// Adds a new item to a ContextPopup object with label and icon.
187 /// <param name="label">The Label of the new item</param>
188 /// <param name="icon">Icon to be set on new item</param>
189 /// <returns>A ContextPopupItem added or NULL, on errors</returns>
190 public ContextPopupItem Append(string label, EvasObject icon)
192 ContextPopupItem item = new ContextPopupItem(label, icon);
193 item.Handle = Interop.Elementary.elm_ctxpopup_item_append(RealHandle, label, icon, _onSelected, (IntPtr)item.Id);
199 /// Dismiss a ContextPopup object. The ContextPopup will be hidden and the "clicked" signal will be emitted.
201 public void Dismiss()
203 Interop.Elementary.elm_ctxpopup_dismiss(RealHandle);
207 /// Gets the possibility that the direction would be available
209 /// <param name="direction">A direction user wants to check</param>
211 /// Get false if you cannot put it in the direction. Gets true if it's possible.
213 public bool IsAvailableDirection(ContextPopupDirection direction)
215 return Interop.Elementary.elm_ctxpopup_direction_available_get(RealHandle, (int)direction);
219 /// Gets Alpha of a default Color Class.
221 public override int Opacity
225 return Color.Default.A;
230 Console.WriteLine("ContextPopup instance doesn't support to set Opacity.");
234 protected override IntPtr CreateHandle(EvasObject parent)
236 return Interop.Elementary.elm_ctxpopup_add(parent.Handle);
239 void AddInternal(ContextPopupItem item)
242 item.Deleted += Item_Deleted;
245 void Item_Deleted(object sender, EventArgs e)
247 _children.Remove((ContextPopupItem)sender);