Add event pass properties in popup outside area
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Popup.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 PopupOrientation
23     {
24         Top,
25         Center,
26         Bottom,
27         Left,
28         Right,
29         TopLeft,
30         TopRight,
31         BottomLeft,
32         BottomRight
33     }
34
35     public class Popup : Layout
36     {
37         HashSet<PopupItem> _children = new HashSet<PopupItem>();
38         SmartEvent _dismissed;
39         SmartEvent _blockClicked;
40         SmartEvent _timeout;
41         SmartEvent _showFinished;
42
43         public Popup(EvasObject parent) : base(parent)
44         {
45             _dismissed = new SmartEvent(this, "dismissed");
46             _dismissed.On += (sender, e) =>
47             {
48                 Dismissed?.Invoke(this, EventArgs.Empty);
49             };
50
51             _blockClicked = new SmartEvent(this, "block,clicked");
52             _blockClicked.On += (sender, e) =>
53             {
54                 OutsideClicked?.Invoke(this, EventArgs.Empty);
55             };
56
57             _timeout = new SmartEvent(this, "timeout");
58             _timeout.On += (sender, e) =>
59             {
60                 TimedOut?.Invoke(this, EventArgs.Empty);
61             };
62
63             _showFinished = new SmartEvent(this, "show,finished");
64             _showFinished.On += (sender, e) =>
65             {
66                 ShowAnimationFinished?.Invoke(this, EventArgs.Empty);
67             };
68         }
69
70         public event EventHandler Dismissed;
71
72         public event EventHandler OutsideClicked;
73
74         public event EventHandler TimedOut;
75
76         public event EventHandler ShowAnimationFinished;
77
78         public PopupOrientation Orientation
79         {
80             get
81             {
82                 return (PopupOrientation)Interop.Elementary.elm_popup_orient_get(Handle);
83             }
84             set
85             {
86                 Interop.Elementary.elm_popup_orient_set(Handle, (int)value);
87             }
88         }
89
90         public WrapType ContentTextWrapType
91         {
92             get
93             {
94                 return (WrapType)Interop.Elementary.elm_popup_content_text_wrap_type_get(Handle);
95             }
96             set
97             {
98                 Interop.Elementary.elm_popup_content_text_wrap_type_set(Handle, (int)value);
99             }
100         }
101
102         public double Timeout
103         {
104             get
105             {
106                 return Interop.Elementary.elm_popup_timeout_get(Handle);
107             }
108             set
109             {
110                 Interop.Elementary.elm_popup_timeout_set(Handle, value);
111             }
112         }
113
114         public bool AllowEvents
115         {
116             get
117             {
118                 return Interop.Elementary.elm_popup_allow_events_get(Handle);
119             }
120             set
121             {
122                 Interop.Elementary.elm_popup_allow_events_set(Handle, value);
123             }
124         }
125
126         public override double AlignmentX
127         {
128             get
129             {
130                 return Interop.Elementary.GetPopupAlignX(Handle);
131             }
132             set
133             {
134                 Interop.Elementary.SetPopupAlignX(Handle, value);
135             }
136         }
137
138         public override double AlignmentY
139         {
140             get
141             {
142                 return Interop.Elementary.GetPopupAlignY(Handle);
143             }
144             set
145             {
146                 Interop.Elementary.SetPopupAlignY(Handle, value);
147             }
148         }
149
150         public override int Opacity
151         {
152             get
153             {
154                 return Color.Default.A;
155             }
156
157             set
158             {
159                 Console.WriteLine("Popup instance doesn't support to set Opacity.");
160             }
161         }
162
163         public PopupItem Append(string label)
164         {
165             return Append(label, null);
166         }
167
168         public PopupItem Append(string label, EvasObject icon)
169         {
170             PopupItem item = new PopupItem(label, icon);
171             item.Handle = Interop.Elementary.elm_popup_item_append(Handle, label, icon, null, (IntPtr)item.Id);
172             AddInternal(item);
173             return item;
174         }
175
176         public void Dismiss()
177         {
178             Interop.Elementary.elm_popup_dismiss(Handle);
179         }
180
181         protected override IntPtr CreateHandle(EvasObject parent)
182         {
183             return Interop.Elementary.elm_popup_add(parent.Handle);
184         }
185
186         void AddInternal(PopupItem item)
187         {
188             _children.Add(item);
189             item.Deleted += Item_Deleted;
190         }
191
192         void Item_Deleted(object sender, EventArgs e)
193         {
194             _children.Remove((PopupItem)sender);
195         }
196     }
197 }