Add FlipSelector
[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     public class FlipSelector : Layout
23     {
24         SmartEvent _selected;
25         SmartEvent _overflowed;
26         SmartEvent _underflowed;
27
28         public FlipSelector(EvasObject parent) : base(parent)
29         {
30             _selected = new SmartEvent(this, Handle, "selected");
31             _overflowed = new SmartEvent(this, Handle, "overflowed");
32             _underflowed = new SmartEvent(this, Handle, "underflowed");
33
34             _selected.On += SelectedChanged;
35             _overflowed.On += OverflowedChanged;
36             _underflowed.On += UnderflowedChanged;
37         }
38
39         public event EventHandler Selected;
40         public event EventHandler Overflowed;
41         public event EventHandler Underflowed;
42
43         public double Interval
44         {
45             get
46             {
47                 return Interop.Elementary.elm_flipselector_first_interval_get(Handle);
48             }
49             set
50             {
51                 Interop.Elementary.elm_flipselector_first_interval_set(Handle, value);
52             }
53         }
54
55         public FlipSelectorItem SelectedItem
56         {
57             get
58             {
59                 IntPtr handle = Interop.Elementary.elm_flipselector_selected_item_get(Handle);
60                 return ItemObject.GetItemByHandle(handle) as FlipSelectorItem;
61             }
62         }
63
64         public FlipSelectorItem FirstItem
65         {
66             get
67             {
68                 IntPtr handle = Interop.Elementary.elm_flipselector_first_item_get(Handle);
69                 return ItemObject.GetItemByHandle(handle) as FlipSelectorItem;
70             }
71         }
72
73         public FlipSelectorItem LastItem
74         {
75             get
76             {
77                 IntPtr handle = Interop.Elementary.elm_flipselector_last_item_get(Handle);
78                 return ItemObject.GetItemByHandle(handle) as FlipSelectorItem;
79             }
80         }
81
82         public FlipSelectorItem Append(string text)
83         {
84             FlipSelectorItem item = new FlipSelectorItem(text);
85             item.Handle = Interop.Elementary.elm_flipselector_item_append(Handle, text, null, (IntPtr)item.Id);
86             return item;
87         }
88
89         public FlipSelectorItem Prepend(string text)
90         {
91             FlipSelectorItem item = new FlipSelectorItem(text);
92             item.Handle = Interop.Elementary.elm_flipselector_item_prepend(Handle, text, null, (IntPtr)item.Id);
93             return item;
94         }
95
96         public void Remove(FlipSelectorItem item)
97         {
98             if (item as FlipSelectorItem != null)
99                 item.Delete();
100         }
101
102         public void Next()
103         {
104             Interop.Elementary.elm_flipselector_flip_next(Handle);
105         }
106
107         public void Prev()
108         {
109             Interop.Elementary.elm_flipselector_flip_prev(Handle);
110         }
111
112         protected override IntPtr CreateHandle(EvasObject parent)
113         {
114             return Interop.Elementary.elm_flipselector_add(parent.Handle);
115         }
116
117         void SelectedChanged(object sender, EventArgs e)
118         {
119             SelectedItem?.SendSelected();
120             Selected?.Invoke(this, EventArgs.Empty);
121         }
122
123         void OverflowedChanged(object sender, EventArgs e)
124         {
125             Overflowed?.Invoke(this, e);
126         }
127
128         void UnderflowedChanged(object sender, EventArgs e)
129         {
130             Underflowed?.Invoke(this, e);
131         }
132     }
133 }