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