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