2 * Copyright(c) 2022 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.
18 using System.ComponentModel;
19 using System.Diagnostics.CodeAnalysis;
20 using Tizen.NUI.BaseComponents;
22 namespace Tizen.NUI.Components
25 /// MenuItem is a class which is used to show a list of items in Menu.
27 /// <since_tizen> 9 </since_tizen>
28 public class MenuItem : SelectButton
30 private bool selectedAgain = false;
33 /// Creates a new instance of MenuItem.
35 /// <since_tizen> 9 </since_tizen>
42 /// Creates a new instance of MenuItem.
44 /// <param name="style">Creates MenuItem by special style defined in UX.</param>
45 [EditorBrowsable(EditorBrowsableState.Never)]
46 public MenuItem(string style) : base(style)
52 /// Creates a new instance of a MenuItem with style.
54 /// <param name="style">A style applied to the newly created MenuItem.</param>
55 [EditorBrowsable(EditorBrowsableState.Never)]
56 public MenuItem(ButtonStyle style) : base(style)
62 [EditorBrowsable(EditorBrowsableState.Never)]
63 protected override void Dispose(DisposeTypes type)
70 if (type == DisposeTypes.Explicit)
78 [EditorBrowsable(EditorBrowsableState.Never)]
79 public override bool OnKey(Key key)
81 if ((IsEnabled == false) || (key == null))
86 if (key.State == Key.StateType.Up)
88 if (key.KeyPressedName == "Return")
90 if (IsSelected == true)
97 bool ret = base.OnKey(key);
99 if (selectedAgain == true)
102 selectedAgain = false;
109 [EditorBrowsable(EditorBrowsableState.Never)]
110 protected override bool HandleControlStateOnTouch(Touch touch)
112 if ((IsEnabled == false) || (touch == null))
117 PointStateType state = touch.GetState(0);
120 case PointStateType.Up:
121 if (IsSelected == true)
123 selectedAgain = true;
130 bool ret = base.HandleControlStateOnTouch(touch);
132 if (selectedAgain == true)
135 selectedAgain = false;
142 [SuppressMessage("Microsoft.Design",
143 "CA1062: Validate arguments of public methods",
144 MessageId = "controlStateChangedInfo",
145 Justification = "OnControlStateChanged is called when controlState is changed so controlStateChangedInfo cannot be null.")]
146 [EditorBrowsable(EditorBrowsableState.Never)]
147 protected override void OnControlStateChanged(ControlStateChangedEventArgs controlStateChangedInfo)
149 if (controlStateChangedInfo.PreviousState.Contains(ControlState.Selected) != controlStateChangedInfo.CurrentState.Contains(ControlState.Selected))
151 // MenuItem does not invoke SelectedChanged if button or key is
152 // unpressed while its state is selected.
153 if (selectedAgain == true)
158 base.OnControlStateChanged(controlStateChangedInfo);
162 private void Initialize()
164 Layout = new LinearLayout()
166 LinearOrientation = LinearLayout.Orientation.Horizontal,
167 HorizontalAlignment = HorizontalAlignment.Begin,
168 VerticalAlignment = VerticalAlignment.Center,
173 /// Initialize AT-SPI object.
175 [EditorBrowsable(EditorBrowsableState.Never)]
176 public override void OnInitialize()
179 AccessibilityRole = Role.MenuItem;