[NUI] Delete Tizen.NUI.Components build warnings (#2674)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / RadioButton.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 Tizen.NUI.BaseComponents;
19
20 namespace Tizen.NUI.Components
21 {
22     /// <summary>
23     /// RadioButton is the Class that describe the control which can be checked, but not cleared by a user.
24     /// </summary>
25     /// <code>
26     /// RadioButton radio = new RadioButton("C_RadioButton_WhiteText");
27     /// radio.Size = new Size(200, 64, 0);
28     /// radio.Position = new Position(500, posY, 0);
29     /// radio.Text = "RadioButton";
30     /// radio.Focusable = true;
31     /// </code>
32     /// <since_tizen> 8 </since_tizen>
33     public class RadioButton : SelectButton
34     {
35         private bool selectedAgain = false;
36
37         static RadioButton() { }
38
39         /// <summary>
40         /// Creates a new instance of a RadioButton.
41         /// </summary>
42         /// <since_tizen> 8 </since_tizen>
43         public RadioButton() : base() { }
44         /// <summary>
45         /// Creates a new instance of a RadioButton with style.
46         /// </summary>
47         /// <param name="style"></param>
48         /// <since_tizen> 8 </since_tizen>
49         public RadioButton(string style) : base(style) { }
50         /// <summary>
51         /// Creates a new instance of a RadioButton with style.
52         /// </summary>
53         /// <param name="buttonStyle"></param>
54         /// <since_tizen> 8 </since_tizen>
55         public RadioButton(ButtonStyle buttonStyle) : base(buttonStyle) { }
56
57         /// <summary>
58         /// Get RadioButtonGroup to which this selections belong.
59         /// </summary>
60         /// <since_tizen> 6 </since_tizen>
61         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
62         [EditorBrowsable(EditorBrowsableState.Never)]
63         public new RadioButtonGroup ItemGroup
64         {
65             get
66             {
67                 return base.ItemGroup as RadioButtonGroup;
68             }
69             internal set
70             {
71                 base.ItemGroup = value;
72             }
73         }
74
75         /// <inheritdoc/>
76         [EditorBrowsable(EditorBrowsableState.Never)]
77         public override void ApplyStyle(ViewStyle viewStyle)
78         {
79             if (viewStyle is ButtonStyle buttonStyle)
80             {
81                 if (buttonStyle.IsSelectable == null)
82                 {
83                     buttonStyle.IsSelectable = true;
84                 }
85
86                 base.ApplyStyle(buttonStyle);
87             }
88         }
89
90         /// <inheritdoc/>
91         [EditorBrowsable(EditorBrowsableState.Never)]
92         protected override ImageView CreateIcon()
93         {
94             return new ImageView
95             {
96                 PositionUsesPivotPoint = true,
97                 ParentOrigin = NUI.ParentOrigin.Center,
98                 PivotPoint = NUI.PivotPoint.Center,
99                 WidthResizePolicy = ResizePolicyType.DimensionDependency,
100                 HeightResizePolicy = ResizePolicyType.SizeRelativeToParent,
101                 SizeModeFactor = new Vector3(1, 1, 1),
102             };
103         }
104
105         /// <inheritdoc/>
106         [EditorBrowsable(EditorBrowsableState.Never)]
107         public override bool OnKey(Key key)
108         {
109             if ((IsEnabled == false) || (key == null))
110             {
111                 return false;
112             }
113
114             if (key.State == Key.StateType.Up)
115             {
116                 if (key.KeyPressedName == "Return")
117                 {
118                     if (IsSelected == true)
119                     {
120                         selectedAgain = true;
121                     }
122                 }
123             }
124
125             bool ret = base.OnKey(key);
126
127             if (selectedAgain == true)
128             {
129                 IsSelected = true;
130                 selectedAgain = false;
131             }
132
133             return ret;
134         }
135
136         /// <inheritdoc/>
137         [EditorBrowsable(EditorBrowsableState.Never)]
138         protected override bool HandleControlStateOnTouch(Touch touch)
139         {
140             if ((IsEnabled == false) || (touch == null))
141             {
142                 return false;
143             }
144
145             PointStateType state = touch.GetState(0);
146             switch (state)
147             {
148                 case PointStateType.Up:
149                     if (IsSelected == true)
150                     {
151                         selectedAgain = true;
152                     }
153                     break;
154                 default:
155                     break;
156             }
157
158             bool ret = base.HandleControlStateOnTouch(touch);
159
160             if (selectedAgain == true)
161             {
162                 IsSelected = true;
163                 selectedAgain = false;
164             }
165
166             return ret;
167         }
168
169         /// <inheritdoc/>
170         [EditorBrowsable(EditorBrowsableState.Never)]
171         protected override void OnControlStateChanged(ControlStateChangedEventArgs info)
172         {
173             if (info.PreviousState.Contains(ControlState.Selected) != info.CurrentState.Contains(ControlState.Selected))
174             {
175                 // RadioButton does not invoke SelectedChanged if button or key
176                 // is unpressed while its state is selected.
177                 if (selectedAgain == true)
178                 {
179                     return;
180                 }
181
182                 base.OnControlStateChanged(info);
183             }
184         }
185     }
186 }