Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / FlipSelector.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     /// <summary>
23     /// A flip selector is a widget to show a set of text items,one at a time.with the same sheet switching style as the clock widget, when one changes the current displaying sheet.
24     /// </summary>
25     public class FlipSelector : Layout
26     {
27         SmartEvent _selected;
28         SmartEvent _overflowed;
29         SmartEvent _underflowed;
30
31         /// <summary>
32         /// Creates and initializes a new instance of the FlipSelector.
33         /// </summary>
34         /// <param name="parent">Parent EvasObject </param>
35         public FlipSelector(EvasObject parent) : base(parent)
36         {
37             _selected = new SmartEvent(this, Handle, "selected");
38             _overflowed = new SmartEvent(this, Handle, "overflowed");
39             _underflowed = new SmartEvent(this, Handle, "underflowed");
40
41             _selected.On += SelectedChanged;
42             _overflowed.On += OverflowedChanged;
43             _underflowed.On += UnderflowedChanged;
44         }
45
46         /// <summary>
47         /// Selected will be triggered when be Selected
48         /// </summary>
49         public event EventHandler Selected;
50         /// <summary>
51         /// Overflowed will be triggered when Overflowed
52         /// </summary>
53         public event EventHandler Overflowed;
54         /// <summary>
55         /// Underflowed will be triggered when be Underflowed
56         /// </summary>
57         public event EventHandler Underflowed;
58
59         /// <summary>
60         ///  Sets or gets the interval on time updates for an user mouse button hold on a flip selector widget.
61         /// </summary>
62         public double Interval
63         {
64             get
65             {
66                 return Interop.Elementary.elm_flipselector_first_interval_get(Handle);
67             }
68             set
69             {
70                 Interop.Elementary.elm_flipselector_first_interval_set(Handle, value);
71             }
72         }
73
74
75         /// <summary>
76         /// Gets the currently selected item in a flip selector widget.
77         /// </summary>
78         public FlipSelectorItem SelectedItem
79         {
80             get
81             {
82                 IntPtr handle = Interop.Elementary.elm_flipselector_selected_item_get(Handle);
83                 return ItemObject.GetItemByHandle(handle) as FlipSelectorItem;
84             }
85         }
86
87         /// <summary>
88         /// Gets the first item in the given flip selector widget's list of items.
89         /// </summary>
90         public FlipSelectorItem FirstItem
91         {
92             get
93             {
94                 IntPtr handle = Interop.Elementary.elm_flipselector_first_item_get(Handle);
95                 return ItemObject.GetItemByHandle(handle) as FlipSelectorItem;
96             }
97         }
98
99         /// <summary>
100         /// Gets the last item in the given flip selector widget's list of items.
101         /// </summary>
102         public FlipSelectorItem LastItem
103         {
104             get
105             {
106                 IntPtr handle = Interop.Elementary.elm_flipselector_last_item_get(Handle);
107                 return ItemObject.GetItemByHandle(handle) as FlipSelectorItem;
108             }
109         }
110
111         /// <summary>
112         /// Appends a (text) item to a flip selector widget.
113         /// </summary>
114         /// <param name="text">text value</param>
115         /// <returns>
116         /// A handle to the item added or NULL, on errors
117         /// </returns>
118         /// <remarks>
119         /// The widget's list of labels to show will be appended with the given value. If the user wishes so, a callback function pointer can be passed, which will get called when this same item is selected.
120         /// </remarks>
121         public FlipSelectorItem Append(string text)
122         {
123             FlipSelectorItem item = new FlipSelectorItem(text);
124             item.Handle = Interop.Elementary.elm_flipselector_item_append(Handle, text, null, (IntPtr)item.Id);
125             return item;
126         }
127
128         /// <summary>
129         /// Prepend a (text) item to a flip selector widget.
130         /// </summary>
131         /// <param name="text">Prepend text</param>
132         /// <returns>A handle to the item added or NULL, on errors</returns>
133         /// <remarks>
134         /// The widget's list of labels to show will be prepended with the given value. If the user wishes so, a callback function pointer can be passed, which will get called when this same item is selected.
135         /// </remarks>
136         public FlipSelectorItem Prepend(string text)
137         {
138             FlipSelectorItem item = new FlipSelectorItem(text);
139             item.Handle = Interop.Elementary.elm_flipselector_item_prepend(Handle, text, null, (IntPtr)item.Id);
140             return item;
141         }
142
143         /// <summary>
144         /// To remove the given item.
145         /// </summary>
146         /// <param name="item">FlipSelector's item</param>
147         public void Remove(FlipSelectorItem item)
148         {
149             if (item as FlipSelectorItem != null)
150                 item.Delete();
151         }
152
153         /// <summary>
154         /// Programmatically select the next item of a flip selector widget.
155         /// </summary>
156         /// <remarks>
157         /// The selection will be animated. Also, if it reaches the beginning of its list of member items, it will continue with the last one backwards.
158         /// </remarks>
159         public void Next()
160         {
161             Interop.Elementary.elm_flipselector_flip_next(Handle);
162         }
163
164         /// <summary>
165         /// Programmatically select the previous item of a flip selector widget.
166         /// </summary>
167         public void Prev()
168         {
169             Interop.Elementary.elm_flipselector_flip_prev(Handle);
170         }
171
172         protected override IntPtr CreateHandle(EvasObject parent)
173         {
174             return Interop.Elementary.elm_flipselector_add(parent.Handle);
175         }
176
177         void SelectedChanged(object sender, EventArgs e)
178         {
179             SelectedItem?.SendSelected();
180             Selected?.Invoke(this, EventArgs.Empty);
181         }
182
183         void OverflowedChanged(object sender, EventArgs e)
184         {
185             Overflowed?.Invoke(this, e);
186         }
187
188         void UnderflowedChanged(object sender, EventArgs e)
189         {
190             Underflowed?.Invoke(this, e);
191         }
192     }
193 }