2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections;
19 using System.Collections.Generic;
22 namespace ElmSharp.Wearable
24 class MoreOptionList : IList<MoreOptionItem>
26 MoreOption Owner { get; set; }
28 List<MoreOptionItem> Items { get; set; }
31 /// Sets or gets the count of items.
33 public int Count => Items.Count;
36 /// Sets or gets whether it is read-only.
38 public bool IsReadOnly => false;
41 /// Sets or gets the item with the index.
43 /// <param name="index">The position of item in items.</param>
44 /// <returns>MoreOptionItem object on the index.</returns>
45 public MoreOptionItem this[int index]
59 /// Creates and initializes a new instance of the MoreOptionList class.
61 /// <param name="owner">The object of more option.</param>
62 public MoreOptionList(MoreOption owner)
65 Items = new List<MoreOptionItem>();
69 /// Appends a new item to the more option.
71 /// <param name="item">The more option item.</param>
72 public void Add(MoreOptionItem item)
74 item.Handle = Interop.Eext.eext_more_option_item_append(Owner);
79 /// Adds a new item to the more option at the first.
81 /// <param name="item">The more option item.</param>
82 public void AddFirst(MoreOptionItem item)
84 item.Handle = Interop.Eext.eext_more_option_item_prepend(Owner);
85 Items.Insert(0, item);
89 /// Adds a new item to the more option at the last.
91 /// <param name="item">The more option item.</param>
92 public void AddLast(MoreOptionItem item)
98 /// Get the index of an item.
100 /// <param name="item">The more option item.</param>
101 /// <returns>The index of an item.</returns>
102 public int IndexOf(MoreOptionItem item)
104 return Items.IndexOf(item);
108 /// Inserts a new item into the more option, after the more option item with the index.
110 /// <param name="index">The index of an item, which is inserted after.</param>
111 /// <param name="item">The more option item.</param>
112 public void Insert(int index, MoreOptionItem item)
114 if (Items.Count < index + 1 || index < 0)
115 throw new ArgumentOutOfRangeException("index is not valid in the MoreOption");
117 MoreOptionItem target = Items[index];
118 item.Handle = Interop.Eext.eext_more_option_item_insert_after(Owner, target.Handle);
119 Items.Insert(index, item);
123 /// Deletes an item, which is the given item index.
125 /// <param name="index">the item index which will be deleted</param>
126 public void RemoveAt(int index)
128 if (Items.Count < index + 1 || index < 0)
129 throw new ArgumentOutOfRangeException("index is not valid in the MoreOptionList");
131 MoreOptionItem item = Items[index];
132 Interop.Eext.eext_more_option_item_del(item.Handle);
133 item.Handle = IntPtr.Zero;
134 Items.RemoveAt(index);
138 /// Removes all the items from a given more option list object.
142 Interop.Eext.eext_more_option_items_clear(Owner);
143 foreach (MoreOptionItem item in Items)
145 item.Handle = IntPtr.Zero;
151 /// Checks the item whether it is contained.
153 /// <param name="item">The more option item.</param>
154 /// <returns>If contained return true, otherwise false.</returns>
155 public bool Contains(MoreOptionItem item)
157 return Items.Contains(item);
161 /// Copies the items.
163 /// <param name="array">The target array.</param>
164 /// <param name="arrayIndex">The index to which the item will be copied.</param>
165 public void CopyTo(MoreOptionItem[] array, int arrayIndex)
167 Items.CopyTo(array, arrayIndex);
171 /// Removes the item.
173 /// <param name="item">The item will be removed.</param>
174 /// <returns>If removed is successful return true, otherwise false.</returns>
175 public bool Remove(MoreOptionItem item)
177 if (Items.Contains(item))
179 Interop.Eext.eext_more_option_item_del(item.Handle);
187 /// Returns an enumerator that iterates through IEnumerator.
189 /// <returns></returns>
190 public IEnumerator<MoreOptionItem> GetEnumerator()
192 return Items.GetEnumerator();
195 IEnumerator IEnumerable.GetEnumerator()
197 return Items.GetEnumerator();