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