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;
22 public enum ContextPopupDirection
31 public class ContextPopup : Layout
33 HashSet<ContextPopupItem> _children = new HashSet<ContextPopupItem>();
34 SmartEvent _dismissed;
35 Interop.Evas.SmartCallback _onSelected;
37 public ContextPopup(EvasObject parent) : base(parent)
39 _dismissed = new SmartEvent(this, "dismissed");
40 _dismissed.On += (sender, e) =>
42 Dismissed?.Invoke(this, EventArgs.Empty);
44 _onSelected = (data, obj, info) =>
46 ContextPopupItem item = ItemObject.GetItemById((int)data) as ContextPopupItem;
51 public event EventHandler Dismissed;
53 public ContextPopupDirection Direction
57 return (ContextPopupDirection)Interop.Elementary.elm_ctxpopup_direction_get(Handle);
61 public bool IsHorizontal
65 return Interop.Elementary.elm_ctxpopup_horizontal_get(Handle);
69 Interop.Elementary.elm_ctxpopup_horizontal_set(Handle, value);
77 return !Interop.Elementary.elm_ctxpopup_auto_hide_disabled_get(Handle);
81 Interop.Elementary.elm_ctxpopup_auto_hide_disabled_set(Handle, !value);
85 public void SetDirectionPriorty(ContextPopupDirection first, ContextPopupDirection second, ContextPopupDirection third, ContextPopupDirection fourth)
87 Interop.Elementary.elm_ctxpopup_direction_priority_set(Handle, (int)first, (int)second, (int)third, (int)fourth);
90 public ContextPopupItem Append(string label)
92 return Append(label, null);
95 public ContextPopupItem Append(string label, EvasObject icon)
97 ContextPopupItem item = new ContextPopupItem(label, icon);
98 item.Handle = Interop.Elementary.elm_ctxpopup_item_append(Handle, label, icon, _onSelected, (IntPtr)item.Id);
103 public void Dismiss()
105 Interop.Elementary.elm_ctxpopup_dismiss(Handle);
108 public bool IsAvailableDirection(ContextPopupDirection direction)
110 return Interop.Elementary.elm_ctxpopup_direction_available_get(Handle, (int)direction);
113 protected override IntPtr CreateHandle(EvasObject parent)
115 return Interop.Elementary.elm_ctxpopup_add(parent.Handle);
118 void AddInternal(ContextPopupItem item)
121 item.Deleted += Item_Deleted;
124 void Item_Deleted(object sender, EventArgs e)
126 _children.Remove((ContextPopupItem)sender);