[NUI] Change the name of Tizen.NUI.CommonUI as Tizen.NUI.Components (#958)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / RadioButtonGroup.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
19 namespace Tizen.NUI.Components
20 {
21     /// <summary>
22     /// The RadioButtonGroup class is used to group together a set of RadioButton control
23     /// It enables the user to select exclusively single radio button of group.
24     /// </summary>
25     /// <code>
26     /// RadioButtonGroup radioGroup = new RadioButtonGroup();
27     /// RadioButton radio1 = new RadioButton();
28     /// RadioButton radio2 = new RadioButton();
29     /// radioGroup.Add(radio1);
30     /// radioGroup.Add(radio2);
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 RadioButtonGroup : SelectGroup
36     {
37         /// <summary>
38         /// Construct RadioButtonGroup
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 RadioButtonGroup() : base()
44         {
45
46         }
47
48         /// <summary>
49         /// Get the RadioButton object at the specified index.
50         /// </summary>
51         /// <param name="index">item index</param>
52         /// <returns>RadioButton</returns>
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 RadioButton GetItemByIndex(int index)
57         {
58             return itemGroup[index] as RadioButton;
59         }
60
61         /// <summary>
62         /// Add RadioButton to the end of RadioButtonGroup.
63         /// </summary>
64         /// <param name="radio">The RadioButton to be added to the RadioButtonGroup</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 Add(RadioButton radio)
69         {
70             base.AddSelection(radio);
71             radio.ItemGroup = this;
72         }
73
74
75         /// <summary>
76         /// Remove RadioButton from the RadioButtonGroup.
77         /// </summary>
78         /// <param name="radio">The RadioButton to remove from the RadioButtonGroup</param>
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 void Remove(RadioButton radio)
83         {
84             base.RemoveSelection(radio);
85             radio.ItemGroup = null;
86         }
87
88         /// <summary>
89         /// Handle user's select action. Turn on check state of selected RadioButton,
90         /// and turn out check state of other RadioButtons in RadioButtonGroup
91         /// </summary>
92         /// <param name="selection">The selection selected by user</param>
93         /// <since_tizen> 6 </since_tizen>
94         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
95         [EditorBrowsable(EditorBrowsableState.Never)]
96         protected override void SelectionHandler(SelectButton selection)
97         {
98             RadioButton radio = selection as RadioButton;
99             if (!itemGroup.Contains(radio))
100             {
101                 return;
102             }
103
104             foreach (RadioButton btn in itemGroup)
105             {
106                 if (btn != null && btn != radio && btn.IsEnabled == true)
107                 {
108                     btn.IsSelected = false;
109                 }
110             }
111         }
112     }
113 }