Release 4.0.0-preview1-00285
[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         /// <summary>
15         /// Sets or gets the count of Items
16         /// </summary>
17         public int Count => Items.Count;
18
19         /// <summary>
20         /// Sets or gets whether it is read only
21         /// </summary>
22         public bool IsReadOnly => false;
23
24         /// <summary>
25         /// Sets or gets the item with the index
26         /// </summary>
27         /// <param name="index">the position of item in items</param>
28         /// <returns></returns>
29         public MoreOptionItem this[int index]
30         {
31             get
32             {
33                 return Items[index];
34             }
35
36             set
37             {
38                 Items[index] = value;
39             }
40         }
41
42         /// <summary>
43         /// Creates and initializes a new instance of MoreOptionList class.
44         /// </summary>
45         /// <param name="owner">the object of more option</param>
46         public MoreOptionList(MoreOption owner)
47         {
48             Owner = owner;
49             Items = new List<MoreOptionItem>();
50         }
51
52         /// <summary>
53         /// Append a new item to a more option.
54         /// </summary>
55         /// <param name="item">The more option item</param>
56         public void Add(MoreOptionItem item)
57         {
58             item.Handle = Interop.Eext.eext_more_option_item_append(Owner);
59             Items.Add(item);
60         }
61
62         /// <summary>
63         /// add a new item to a more option at the first.
64         /// </summary>
65         /// <param name="item">The more option item</param>
66         public void AddFirst(MoreOptionItem item)
67         {
68             item.Handle = Interop.Eext.eext_more_option_item_prepend(Owner);
69             Items.Insert(0, item);
70         }
71
72         /// <summary>
73         /// add a new item to a more option at the last.
74         /// </summary>
75         /// <param name="item">The more option item</param>
76         public void AddLast(MoreOptionItem item)
77         {
78             Add(item);
79         }
80
81         /// <summary>
82         /// Get the index of item
83         /// </summary>
84         /// <param name="item">The more option item</param>
85         /// <returns>the index of item</returns>
86         public int IndexOf(MoreOptionItem item)
87         {
88             return Items.IndexOf(item);
89         }
90
91         /// <summary>
92         /// Insert a new item into the more option after more option item with the index.
93         /// </summary>
94         /// <param name="index">the index of item which is insert after</param>
95         /// <param name="item">The more option item</param>
96         public void Insert(int index, MoreOptionItem item)
97         {
98             if (Items.Count < index + 1 || index < 0)
99                 throw new ArgumentOutOfRangeException("index is not valid in the MoreOption");
100
101             MoreOptionItem target = Items[index];
102             item.Handle = Interop.Eext.eext_more_option_item_insert_after(Owner, target.Handle);
103             Items.Insert(index, item);
104         }
105
106         /// <summary>
107         /// Delete an item which is the given item index
108         /// </summary>
109         /// <param name="index">the item index which will be deleted</param>
110         public void RemoveAt(int index)
111         {
112             if (Items.Count < index + 1 || index < 0)
113                 throw new ArgumentOutOfRangeException("index is not valid in the MoreOptionList");
114
115             MoreOptionItem item = Items[index];
116             Interop.Eext.eext_more_option_item_del(item.Handle);
117             item.Handle = IntPtr.Zero;
118             Items.RemoveAt(index);
119         }
120
121         /// <summary>
122         /// Remove all items from a given more option list object.
123         /// </summary>
124         public void Clear()
125         {
126             Interop.Eext.eext_more_option_items_clear(Owner);
127             foreach (MoreOptionItem item in Items)
128             {
129                 item.Handle = IntPtr.Zero;
130             }
131             Items.Clear();
132         }
133
134         /// <summary>
135         /// Check the item whether is contained
136         /// </summary>
137         /// <param name="item">The more option item</param>
138         /// <returns>If contain return true, otherwise false</returns>
139         public bool Contains(MoreOptionItem item)
140         {
141             return Items.Contains(item);
142         }
143
144         /// <summary>
145         /// Copy Items
146         /// </summary>
147         /// <param name="array">the target array</param>
148         /// <param name="arrayIndex">which index the item will copy to</param>
149         public void CopyTo(MoreOptionItem[] array, int arrayIndex)
150         {
151             Items.CopyTo(array, arrayIndex);
152         }
153
154         /// <summary>
155         /// Remove a item
156         /// </summary>
157         /// <param name="item">the item will be removed</param>
158         /// <returns>if remove success return true, otherwise false</returns>
159         public bool Remove(MoreOptionItem item)
160         {
161             if (Items.Contains(item))
162             {
163                 Interop.Eext.eext_more_option_item_del(item.Handle);
164                 Items.Remove(item);
165                 return true;
166             }
167             return false;
168         }
169
170         /// <summary>
171         /// Return an enumerator that iterates through IEnumerator
172         /// </summary>
173         /// <returns></returns>
174         public IEnumerator<MoreOptionItem> GetEnumerator()
175         {
176             return Items.GetEnumerator();
177         }
178
179         IEnumerator IEnumerable.GetEnumerator()
180         {
181             return Items.GetEnumerator();
182         }
183     }
184 }