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, this.RealHandle, "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(RealHandle);
61 public bool IsHorizontal
65 return Interop.Elementary.elm_ctxpopup_horizontal_get(RealHandle);
69 Interop.Elementary.elm_ctxpopup_horizontal_set(RealHandle, value);
77 return !Interop.Elementary.elm_ctxpopup_auto_hide_disabled_get(RealHandle);
81 Interop.Elementary.elm_ctxpopup_auto_hide_disabled_set(RealHandle, !value);
87 Interop.Elementary.elm_ctxpopup_clear(Handle);
90 public void SetDirectionPriorty(ContextPopupDirection first, ContextPopupDirection second, ContextPopupDirection third, ContextPopupDirection fourth)
92 Interop.Elementary.elm_ctxpopup_direction_priority_set(RealHandle, (int)first, (int)second, (int)third, (int)fourth);
95 public void GetDirectionPriority(out ContextPopupDirection first, out ContextPopupDirection second, out ContextPopupDirection third, out ContextPopupDirection fourth)
97 int firstOut, secondOut, thirdOut, fourthOut;
98 Interop.Elementary.elm_ctxpopup_direction_priority_get(Handle, out firstOut, out secondOut, out thirdOut, out fourthOut);
99 first = (ContextPopupDirection)firstOut;
100 second = (ContextPopupDirection)secondOut;
101 third = (ContextPopupDirection)thirdOut;
102 fourth = (ContextPopupDirection)fourthOut;
105 public ContextPopupItem Append(string label)
107 return Append(label, null);
110 public ContextPopupItem Append(string label, EvasObject icon)
112 ContextPopupItem item = new ContextPopupItem(label, icon);
113 item.Handle = Interop.Elementary.elm_ctxpopup_item_append(RealHandle, label, icon, _onSelected, (IntPtr)item.Id);
118 public void Dismiss()
120 Interop.Elementary.elm_ctxpopup_dismiss(RealHandle);
123 public bool IsAvailableDirection(ContextPopupDirection direction)
125 return Interop.Elementary.elm_ctxpopup_direction_available_get(RealHandle, (int)direction);
128 public override int Opacity
132 return Color.Default.A;
137 Console.WriteLine("ContextPopup instance doesn't support to set Opacity.");
141 protected override IntPtr CreateHandle(EvasObject parent)
143 return Interop.Elementary.elm_ctxpopup_add(parent.Handle);
146 void AddInternal(ContextPopupItem item)
149 item.Deleted += Item_Deleted;
152 void Item_Deleted(object sender, EventArgs e)
154 _children.Remove((ContextPopupItem)sender);