Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / ElmSharp.Wearable / ElmSharp.Wearable / MoreOptionList.cs
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Text;
5
6 namespace ElmSharp.Wearable
7 {
8     class MoreOptionList : IList<MoreOptionItem>
9     {
10         MoreOption Owner { get; set; }
11
12         List<MoreOptionItem> Items { get; set; }
13
14         public int Count => Items.Count;
15
16         public bool IsReadOnly => false;
17
18         public MoreOptionItem this[int index]
19         {
20             get
21             {
22                 return Items[index];
23             }
24
25             set
26             {
27                 Items[index] = value;
28             }
29         }
30
31         public MoreOptionList(MoreOption owner)
32         {
33             Owner = owner;
34             Items = new List<MoreOptionItem>();
35         }
36
37         public void Add(MoreOptionItem item)
38         {
39             item.Handle = Interop.Eext.eext_more_option_item_append(Owner);
40             Items.Add(item);
41         }
42
43         public void AddFirst(MoreOptionItem item)
44         {
45             item.Handle = Interop.Eext.eext_more_option_item_prepend(Owner);
46             Items.Insert(0, item);
47         }
48
49         public void AddLast(MoreOptionItem item)
50         {
51             Add(item);
52         }
53
54         public int IndexOf(MoreOptionItem item)
55         {
56             return Items.IndexOf(item);
57         }
58
59         public void Insert(int index, MoreOptionItem item)
60         {
61             if (Items.Count < index + 1 || index < 0)
62                 throw new ArgumentOutOfRangeException("index is not valid in the MoreOption");
63
64             MoreOptionItem target = Items[index];
65             item.Handle = Interop.Eext.eext_more_option_item_insert_after(Owner, target.Handle);
66             Items.Insert(index, item);
67         }
68
69         public void RemoveAt(int index)
70         {
71             if (Items.Count < index + 1 || index < 0)
72                 throw new ArgumentOutOfRangeException("index is not valid in the MoreOptionList");
73
74             MoreOptionItem item = Items[index];
75             Interop.Eext.eext_more_option_item_del(item.Handle);
76             item.Handle = IntPtr.Zero;
77             Items.RemoveAt(index);
78         }
79
80         public void Clear()
81         {
82             Interop.Eext.eext_more_option_items_clear(Owner);
83             foreach (MoreOptionItem item in Items)
84             {
85                 item.Handle = IntPtr.Zero;
86             }
87             Items.Clear();
88         }
89
90         public bool Contains(MoreOptionItem item)
91         {
92             return Items.Contains(item);
93         }
94
95         public void CopyTo(MoreOptionItem[] array, int arrayIndex)
96         {
97             Items.CopyTo(array, arrayIndex);
98         }
99
100         public bool Remove(MoreOptionItem item)
101         {
102             if (Items.Contains(item))
103             {
104                 Interop.Eext.eext_more_option_item_del(item.Handle);
105                 Items.Remove(item);
106                 return true;
107             }
108             return false;
109         }
110
111         public IEnumerator<MoreOptionItem> GetEnumerator()
112         {
113             return Items.GetEnumerator();
114         }
115
116         IEnumerator IEnumerable.GetEnumerator()
117         {
118             return Items.GetEnumerator();
119         }
120     }
121 }