2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 using System.ComponentModel;
18 using Tizen.NUI.BaseComponents;
20 namespace Tizen.NUI.Components
23 /// RadioButton is the Class that describe the control which can be checked, but not cleared by a user.
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;
32 /// <since_tizen> 8 </since_tizen>
33 public class RadioButton : SelectButton
35 private bool selectedAgain = false;
37 static RadioButton() { }
40 /// Creates a new instance of a RadioButton.
42 /// <since_tizen> 8 </since_tizen>
43 public RadioButton() : base() { }
45 /// Creates a new instance of a RadioButton with style.
47 /// <param name="style"></param>
48 /// <since_tizen> 8 </since_tizen>
49 public RadioButton(string style) : base(style) { }
51 /// Creates a new instance of a RadioButton with style.
53 /// <param name="buttonStyle"></param>
54 /// <since_tizen> 8 </since_tizen>
55 public RadioButton(ButtonStyle buttonStyle) : base(buttonStyle) { }
58 /// Get RadioButtonGroup to which this selections belong.
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
67 return base.ItemGroup as RadioButtonGroup;
71 base.ItemGroup = value;
76 [EditorBrowsable(EditorBrowsableState.Never)]
77 public override void ApplyStyle(ViewStyle viewStyle)
79 if (viewStyle is ButtonStyle buttonStyle)
81 if (buttonStyle.IsSelectable == null)
83 buttonStyle.IsSelectable = true;
86 base.ApplyStyle(buttonStyle);
91 [EditorBrowsable(EditorBrowsableState.Never)]
92 protected override ImageView CreateIcon()
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),
106 [EditorBrowsable(EditorBrowsableState.Never)]
107 public override bool OnKey(Key key)
109 if ((IsEnabled == false) || (key == null))
114 if (key.State == Key.StateType.Up)
116 if (key.KeyPressedName == "Return")
118 if (IsSelected == true)
120 selectedAgain = true;
125 bool ret = base.OnKey(key);
127 if (selectedAgain == true)
130 selectedAgain = false;
137 [EditorBrowsable(EditorBrowsableState.Never)]
138 protected override bool HandleControlStateOnTouch(Touch touch)
140 if ((IsEnabled == false) || (touch == null))
145 PointStateType state = touch.GetState(0);
148 case PointStateType.Up:
149 if (IsSelected == true)
151 selectedAgain = true;
158 bool ret = base.HandleControlStateOnTouch(touch);
160 if (selectedAgain == true)
163 selectedAgain = false;
170 [EditorBrowsable(EditorBrowsableState.Never)]
171 protected override void OnControlStateChanged(ControlStateChangedEventArgs info)
173 if (info.PreviousState.Contains(ControlState.Selected) != info.CurrentState.Contains(ControlState.Selected))
175 // RadioButton does not invoke SelectedChanged if button or key
176 // is unpressed while its state is selected.
177 if (selectedAgain == true)
182 base.OnControlStateChanged(info);