39866b8fa1f710b4418ee9243b8910cc79081e91
[platform/core/csapi/tizenfx.git] / src / ElmSharp.Wearable / ElmSharp.Wearable / RotarySelectorList.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;
19 using System.Collections.Generic;
20 using System.Text;
21
22 namespace ElmSharp.Wearable
23 {
24     class RotarySelectorList : IList<RotarySelectorItem>
25     {
26         RotarySelector _owner;
27         List<RotarySelectorItem> Items { get; set; }
28
29         public RotarySelectorList(RotarySelector owner)
30         {
31             this._owner = owner;
32             Items = new List<RotarySelectorItem>();
33         }
34
35         public RotarySelectorItem this[int index] { get => Items[index]; set => Items[index] = value; }
36
37         public int Count => Items.Count;
38
39         public bool IsReadOnly => false;
40
41         public void Add(RotarySelectorItem item)
42         {
43             item.Handle = Interop.Eext.eext_rotary_selector_item_append(_owner);
44             Items.Add(item);
45         }
46
47         public void Clear()
48         {
49             Interop.Eext.eext_rotary_selector_items_clear(_owner);
50         }
51
52         public bool Contains(RotarySelectorItem item)
53         {
54             return Items.Contains(item);
55         }
56
57         public void CopyTo(RotarySelectorItem[] array, int arrayIndex)
58         {
59             Items.CopyTo(array, arrayIndex);
60         }
61
62         public IEnumerator<RotarySelectorItem> GetEnumerator()
63         {
64             return Items.GetEnumerator();
65         }
66
67         public int IndexOf(RotarySelectorItem item)
68         {
69             return Items.IndexOf(item);
70         }
71
72         public void Insert(int index, RotarySelectorItem item)
73         {
74             if (Items.Count <= index || index < 0)
75             {
76                 throw new ArgumentOutOfRangeException("index is not valid in the RotarySelector");
77             }
78             RotarySelectorItem target = Items[index];
79             item.Handle = Interop.Eext.eext_rotary_selector_item_insert_after(_owner, target.Handle);
80             Items.Insert(index, item);
81         }
82
83         public bool Remove(RotarySelectorItem item)
84         {
85             if (Items.Contains(item))
86             {
87                 Interop.Eext.eext_rotary_selector_item_del(item.Handle);
88                 Items.Remove(item);
89                 return true;
90             }
91             return false;
92         }
93
94         public void RemoveAt(int index)
95         {
96             if (Items.Count < index + 1 || index < 0)
97             {
98                 throw new ArgumentOutOfRangeException("index is not valid in the RotarySelector");
99             }
100
101             RotarySelectorItem target = Items[index];
102             Interop.Eext.eext_rotary_selector_item_del(target.Handle);
103             target.Handle = IntPtr.Zero;
104             Items.RemoveAt(index);
105         }
106
107         IEnumerator IEnumerable.GetEnumerator()
108         {
109             return Items.GetEnumerator();
110         }
111     }
112 }