*
*/
using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
using Tizen.NUI.BaseComponents;
namespace Tizen.NUI.Components
[EditorBrowsable(EditorBrowsableState.Never)]
public class TabButton : SelectButton
{
+ private bool selectedAgain = false;
+
/// <summary>
/// Creates a new instance of TabButton.
/// </summary>
GridLayout.SetHorizontalStretch(this, GridLayout.StretchFlags.ExpandAndFill);
}
- /// <summary>
- /// Sets the control state of a TabButton.
- /// TabButton needs to support this API since 'View.ControlState' is protected
- /// and cannot be reached by TabButtonGroup.
- /// </summary>
+ /// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]
- internal void SetTabButtonState(ControlState controlState)
+ public override bool OnKey(Key key)
{
- base.ControlState = controlState;
+ if ((IsEnabled == false) || (key == null))
+ {
+ return false;
+ }
+
+ if (key.State == Key.StateType.Up)
+ {
+ if (key.KeyPressedName == "Return")
+ {
+ if (IsSelected == true)
+ {
+ selectedAgain = true;
+ }
+ }
+ }
+
+ bool ret = base.OnKey(key);
+
+ if (selectedAgain == true)
+ {
+ IsSelected = true;
+ selectedAgain = false;
+ }
+
+ return ret;
}
- /// <summary>
- /// Sets Button.IsSelected to true after selecting TabButton since it is
- /// set to false when re-selected according to Button's logic.
- /// </summary>
+ /// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]
- protected override void OnSelectedChanged()
+ protected override bool HandleControlStateOnTouch(Touch touch)
{
- ControlState = ControlState.Pressed;
- if (!IsSelected)
+ if ((IsEnabled == false) || (touch == null))
+ {
+ return false;
+ }
+
+ PointStateType state = touch.GetState(0);
+ switch (state)
+ {
+ case PointStateType.Up:
+ if (IsSelected == true)
+ {
+ selectedAgain = true;
+ }
+ break;
+ default:
+ break;
+ }
+
+ bool ret = base.HandleControlStateOnTouch(touch);
+
+ if (selectedAgain == true)
{
IsSelected = true;
+ selectedAgain = false;
+ }
+
+ return ret;
+ }
+
+ /// <inheritdoc/>
+ [SuppressMessage("Microsoft.Design",
+ "CA1062: Validate arguments of public methods",
+ MessageId = "controlStateChangedInfo",
+ Justification = "OnControlStateChanged is called when controlState is changed so controlStateChangedInfo cannot be null.")]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected override void OnControlStateChanged(ControlStateChangedEventArgs controlStateChangedInfo)
+ {
+ if (controlStateChangedInfo.PreviousState.Contains(ControlState.Selected) != controlStateChangedInfo.CurrentState.Contains(ControlState.Selected))
+ {
+ // TabButton does not invoke SelectedChanged if button or key is
+ // unpressed while its state is selected.
+ if (selectedAgain == true)
+ {
+ return;
+ }
+
+ base.OnControlStateChanged(controlStateChangedInfo);
}
}
}
public class TabButtonGroup : SelectGroup
{
/// <summary>
+ /// Constructs TabButtonGroup
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public TabButtonGroup() : base()
+ {
+ EnableMultiSelection = false;
+ }
+
+ /// <summary>
/// Adds a tab button to the end of TabButtonGroup.
/// </summary>
/// <param name="tabButton">A tab button to be added to the group.</param>
base.RemoveSelection(tabButton);
}
-
- /// <summary>
- /// Sets the state of the rest of tab buttons in TabButtonGroup as normal
- /// when a selection is made by a user.
- /// </summary>
- /// <param name="selection">The handler of the SelectButton selected by a user.</param>
- /// <exception cref="ArgumentNullException">Thrown when the argument selection is null.</exception>
- /// <exception cref="ArgumentException">Thrown when the argument selection does not exist in TabButtonGroup.</exception>
- [EditorBrowsable(EditorBrowsableState.Never)]
- protected override void SelectionHandler(SelectButton selection)
- {
- TabButton selectedTab = selection as TabButton;
-
- if (selectedTab == null)
- {
- throw new ArgumentNullException(nameof(selection), "selection should not be null.");
- }
-
- if (ItemGroup.Contains(selectedTab) == false)
- {
- throw new ArgumentException("selection does not exist in TabButtonGroup.", nameof(selection));
- }
-
- foreach (TabButton tabButton in ItemGroup)
- {
- if ((tabButton != null) && (tabButton != selectedTab) && (selectedTab.IsEnabled == true))
- {
- tabButton.IsSelected = false;
- tabButton.SetTabButtonState(ControlState.Normal);
- }
- }
- }
}
}