[NUI] Change the name of Tizen.NUI.CommonUI as Tizen.NUI.Components (#958)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / CheckBoxGroup.cs
1 /*
2  * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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.ComponentModel;
18 using System.Collections.Generic;
19
20 namespace Tizen.NUI.Components
21 {
22     /// <summary>
23     /// The CheckboxGroup class is used to group together a set of CheckBox control
24     /// </summary>
25     /// <code>
26     /// CheckBoxGroup checkGroup = new CheckBoxGroup();
27     /// CheckBox check1 = new CheckBox();
28     /// CheckBox check2 = new CheckBox();
29     /// checkGroup.Add(check1);
30     /// checkGroup.Add(check2);
31     /// </code>
32     /// <since_tizen> 6 </since_tizen>
33     /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
34     [EditorBrowsable(EditorBrowsableState.Never)]
35     public class CheckBoxGroup : SelectGroup
36     {
37         /// <summary>
38         /// Construct CheckBoxGroup
39         /// </summary>
40         /// <since_tizen> 6 </since_tizen>
41         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
42         [EditorBrowsable(EditorBrowsableState.Never)]
43         public CheckBoxGroup() : base()
44         {
45
46         }
47
48         /// <summary>
49         /// Add CheckBox to the end of CheckBoxGroup.
50         /// </summary>
51         /// <param name="check">The CheckBox to be added to the CheckBoxGroup</param>
52         /// <since_tizen> 6 </since_tizen>
53         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
54         [EditorBrowsable(EditorBrowsableState.Never)]
55         public void Add(CheckBox check)
56         {
57             base.AddSelection(check);
58             check.ItemGroup = this;
59         }
60
61         /// <summary>
62         /// Remove CheckBox from the CheckBoxGroup.
63         /// </summary>
64         /// <param name="check">The CheckBox to remove from the CheckBoxGroup</param>
65         /// <since_tizen> 6 </since_tizen>
66         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
67         [EditorBrowsable(EditorBrowsableState.Never)]
68         public void Remove(CheckBox check)
69         {
70             base.RemoveSelection(check);
71             check.ItemGroup = null;
72         }
73
74         /// <summary>
75         /// Get the CheckBox object at the specified index.
76         /// </summary>
77         /// <param name="index">The item index</param>
78         /// <returns>CheckBox</returns>
79         /// <since_tizen> 6 </since_tizen>
80         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
81         [EditorBrowsable(EditorBrowsableState.Never)]
82         public CheckBox GetItemByIndex(int index)
83         {
84             return itemGroup[index] as CheckBox;
85         }
86
87         /// <summary>
88         /// Get the index array of checked items.
89         /// </summary>
90         /// <returns>The array of index</returns>
91         /// <since_tizen> 6 </since_tizen>
92         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
93         [EditorBrowsable(EditorBrowsableState.Never)]
94         public int[] GetCheckedIndexArray()
95         {
96             List<int> selectedItemsList = new List<int>();
97             for (int i = 0; i < itemGroup.Count; i++)
98             {
99                 if (itemGroup[i].IsSelected)
100                 {
101                     selectedItemsList.Add(i);
102                 }
103             }
104
105             return selectedItemsList.ToArray();
106         }
107
108
109         /// <summary>
110         /// Get the CheckBox array of checked items.
111         /// </summary>
112         /// <returns>The array of CheckBox</returns>
113         /// <since_tizen> 6 </since_tizen>
114         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
115         [EditorBrowsable(EditorBrowsableState.Never)]
116         public CheckBox[] GetCheckedItemArray()
117         {
118             List<CheckBox> selectedList = new List<CheckBox>();
119
120             foreach (CheckBox check in itemGroup)
121             {
122                 if (check.IsSelected)
123                 {
124                     selectedList.Add(check);
125                 }
126             }
127
128             return selectedList.ToArray();
129         }
130
131         /// <summary>
132         /// Determines whether every checkboxes in the CheckBoxGroup are checked
133         /// </summary>
134         /// <returns>If all of CheckBoxes are checked, return true. otherwise false</returns>
135         /// <since_tizen> 6 </since_tizen>
136         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
137         [EditorBrowsable(EditorBrowsableState.Never)]
138         public bool IsCheckedAll()
139         {
140             foreach (CheckBox cb in itemGroup)
141             {
142                 if (!cb.IsSelected)
143                 {
144                     return false;
145                 }
146             }
147             return true;
148         }
149
150         /// <summary>
151         /// Check or Uncheck all of child checkboxes by the specified value
152         /// </summary>
153         /// <param name="state">The boolean state of the check box</param>
154         /// <since_tizen> 6 </since_tizen>
155         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
156         [EditorBrowsable(EditorBrowsableState.Never)]
157         public void CheckingAll(bool state)
158         {
159             foreach (CheckBox cb in itemGroup)
160             {
161                 cb.IsSelected = state;
162             }
163         }
164     }
165 }