Add missing methods to ContextPopup
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / ContextPopup.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Collections.Generic;
19
20 namespace ElmSharp
21 {
22     public enum ContextPopupDirection
23     {
24         Down,
25         Right,
26         Left,
27         Up,
28         Unknown
29     }
30
31     public class ContextPopup : Layout
32     {
33         HashSet<ContextPopupItem> _children = new HashSet<ContextPopupItem>();
34         SmartEvent _dismissed;
35         Interop.Evas.SmartCallback _onSelected;
36
37         public ContextPopup(EvasObject parent) : base(parent)
38         {
39             _dismissed = new SmartEvent(this, "dismissed");
40             _dismissed.On += (sender, e) =>
41             {
42                 Dismissed?.Invoke(this, EventArgs.Empty);
43             };
44             _onSelected = (data, obj, info) =>
45             {
46                 ContextPopupItem item = ItemObject.GetItemById((int)data) as ContextPopupItem;
47                 item?.SendSelected();
48             };
49         }
50
51         public event EventHandler Dismissed;
52
53         public ContextPopupDirection Direction
54         {
55             get
56             {
57                 return (ContextPopupDirection)Interop.Elementary.elm_ctxpopup_direction_get(Handle);
58             }
59         }
60
61         public bool IsHorizontal
62         {
63             get
64             {
65                 return Interop.Elementary.elm_ctxpopup_horizontal_get(Handle);
66             }
67             set
68             {
69                 Interop.Elementary.elm_ctxpopup_horizontal_set(Handle, value);
70             }
71         }
72
73         public bool AutoHide
74         {
75             get
76             {
77                 return !Interop.Elementary.elm_ctxpopup_auto_hide_disabled_get(Handle);
78             }
79             set
80             {
81                 Interop.Elementary.elm_ctxpopup_auto_hide_disabled_set(Handle, !value);
82             }
83         }
84
85         public void Clear()
86         {
87             Interop.Elementary.elm_ctxpopup_clear(Handle);
88         }
89
90         public void SetDirectionPriorty(ContextPopupDirection first, ContextPopupDirection second, ContextPopupDirection third, ContextPopupDirection fourth)
91         {
92             Interop.Elementary.elm_ctxpopup_direction_priority_set(Handle, (int)first, (int)second, (int)third, (int)fourth);
93         }
94
95         public void GetDirectionPriority(out ContextPopupDirection first, out ContextPopupDirection second, out ContextPopupDirection third, out ContextPopupDirection fourth)
96         {
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;
103         }
104
105         public ContextPopupItem Append(string label)
106         {
107             return Append(label, null);
108         }
109
110         public ContextPopupItem Append(string label, EvasObject icon)
111         {
112             ContextPopupItem item = new ContextPopupItem(label, icon);
113             item.Handle = Interop.Elementary.elm_ctxpopup_item_append(Handle, label, icon, _onSelected, (IntPtr)item.Id);
114             AddInternal(item);
115             return item;
116         }
117
118         public void Dismiss()
119         {
120             Interop.Elementary.elm_ctxpopup_dismiss(Handle);
121         }
122
123         public bool IsAvailableDirection(ContextPopupDirection direction)
124         {
125             return Interop.Elementary.elm_ctxpopup_direction_available_get(Handle, (int)direction);
126         }
127
128         protected override IntPtr CreateHandle(EvasObject parent)
129         {
130             return Interop.Elementary.elm_ctxpopup_add(parent.Handle);
131         }
132
133         void AddInternal(ContextPopupItem item)
134         {
135             _children.Add(item);
136             item.Deleted += Item_Deleted;
137         }
138
139         void Item_Deleted(object sender, EventArgs e)
140         {
141             _children.Remove((ContextPopupItem)sender);
142         }
143     }
144 }