bf3a9bc7080d6f28528f8df2e29186e18b74cb37
[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         static CheckBoxGroup() { }
38
39         /// <summary>
40         /// Construct CheckBoxGroup
41         /// </summary>
42         /// <since_tizen> 6 </since_tizen>
43         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
44         [EditorBrowsable(EditorBrowsableState.Never)]
45         public CheckBoxGroup() : base()
46         {
47         }
48
49         /// <summary>
50         /// Add CheckBox to the end of CheckBoxGroup.
51         /// </summary>
52         /// <param name="check">The CheckBox to be added to the CheckBoxGroup</param>
53         /// <since_tizen> 6 </since_tizen>
54         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
55         [EditorBrowsable(EditorBrowsableState.Never)]
56         public void Add(CheckBox check)
57         {
58             if (null == check) return;
59             base.AddSelection(check);
60             check.ItemGroup = this;
61         }
62
63         /// <summary>
64         /// Remove CheckBox from the CheckBoxGroup.
65         /// </summary>
66         /// <param name="check">The CheckBox to remove from the CheckBoxGroup</param>
67         /// <since_tizen> 6 </since_tizen>
68         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
69         [EditorBrowsable(EditorBrowsableState.Never)]
70         public void Remove(CheckBox check)
71         {
72             if (null == check) return;
73             base.RemoveSelection(check);
74             check.ItemGroup = null;
75         }
76
77         /// <summary>
78         /// Get the CheckBox object at the specified index.
79         /// </summary>
80         /// <param name="index">The item index</param>
81         /// <returns>CheckBox</returns>
82         /// <since_tizen> 6 </since_tizen>
83         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
84         [EditorBrowsable(EditorBrowsableState.Never)]
85         public CheckBox GetItem(int index)
86         {
87             return ItemGroup[index] as CheckBox;
88         }
89
90         /// <summary>
91         /// Get the index array of checked items.
92         /// </summary>
93         /// <returns>The array of index</returns>
94         /// <since_tizen> 6 </since_tizen>
95         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
96         [EditorBrowsable(EditorBrowsableState.Never)]
97         public int[] GetCheckedIndices()
98         {
99             List<int> selectedItemsList = new List<int>();
100             for (int i = 0; i < ItemGroup.Count; i++)
101             {
102                 if (ItemGroup[i].IsSelected)
103                 {
104                     selectedItemsList.Add(i);
105                 }
106             }
107
108             return selectedItemsList.ToArray();
109         }
110
111
112         /// <summary>
113         /// Get the CheckBox array of checked items.
114         /// </summary>
115         /// <returns>The array of CheckBox</returns>
116         /// <since_tizen> 6 </since_tizen>
117         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
118         [EditorBrowsable(EditorBrowsableState.Never)]
119         public CheckBox[] GetCheckedItems()
120         {
121             List<CheckBox> selectedList = new List<CheckBox>();
122
123             foreach (CheckBox check in ItemGroup)
124             {
125                 if (check.IsSelected)
126                 {
127                     selectedList.Add(check);
128                 }
129             }
130
131             return selectedList.ToArray();
132         }
133
134         /// <summary>
135         /// Determines whether every checkboxes in the CheckBoxGroup are checked
136         /// </summary>
137         /// <returns>If all of CheckBoxes are checked, return true. otherwise false</returns>
138         /// <since_tizen> 6 </since_tizen>
139         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
140         [EditorBrowsable(EditorBrowsableState.Never)]
141         public bool IsCheckedAll()
142         {
143             foreach (CheckBox cb in ItemGroup)
144             {
145                 if (!cb.IsSelected)
146                 {
147                     return false;
148                 }
149             }
150             return true;
151         }
152
153         /// <summary>
154         /// Check or Uncheck all of child checkboxes by the specified value
155         /// </summary>
156         /// <param name="state">The boolean state of the check box</param>
157         /// <since_tizen> 6 </since_tizen>
158         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
159         [EditorBrowsable(EditorBrowsableState.Never)]
160         public void CheckAll(bool state)
161         {
162             foreach (CheckBox cb in ItemGroup)
163             {
164                 cb.IsSelected = state;
165             }
166         }
167     }
168 }