[NUI] Change View.ControlState setter to protected. (#1727)
authorJiyun Yang <ji.yang@samsung.com>
Mon, 22 Jun 2020 10:24:07 +0000 (19:24 +0900)
committerGitHub <noreply@github.com>
Mon, 22 Jun 2020 10:24:07 +0000 (19:24 +0900)
Setting ControlState is now allowed only in the derived class of View.

Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
src/Tizen.NUI.Components/Controls/Button.Internal.cs
src/Tizen.NUI.Components/Controls/DropDown.DropDownItemView.cs
src/Tizen.NUI.Components/Controls/DropDown.cs
src/Tizen.NUI.Components/Controls/Tab.cs
src/Tizen.NUI.Wearable/src/public/CircularProgress.cs
src/Tizen.NUI/src/public/BaseComponents/View.cs

index f1ec591..053615a 100755 (executable)
@@ -350,6 +350,34 @@ namespace Tizen.NUI.Components
             base.Dispose(type);
         }
 
+        /// <inheritdoc/>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void OnControlStateChanged(ControlStateChangedEventArgs controlStateChangedInfo)
+        {
+            base.OnControlStateChanged(controlStateChangedInfo);
+
+            var stateEnabled = !((controlStateChangedInfo.CurrentState & ControlStates.Disabled) == ControlStates.Disabled);
+
+            if (isEnabled != stateEnabled)
+            {
+                isEnabled = stateEnabled;
+            }
+
+            var stateSelected = (controlStateChangedInfo.CurrentState & ControlStates.Selected) == ControlStates.Selected;
+
+            if (isSelected != stateSelected)
+            {
+                isSelected = stateSelected;
+            }
+
+            var statePressed = (controlStateChangedInfo.CurrentState & ControlStates.Pressed) == ControlStates.Pressed;
+
+            if (isPressed != statePressed)
+            {
+                isPressed = statePressed;
+            }
+        }
+
         /// <summary>
         /// It is hijack by using protected, style copy problem when class inherited from Button.
         /// </summary>
index f580156..b9b95ab 100755 (executable)
@@ -199,10 +199,12 @@ namespace Tizen.NUI.Components
                     CreateCheckImage();
                     if (value)
                     {
+                        ControlState = ControlStates.Selected;
                         mCheck.Show();
                     }
                     else
                     {
+                        ControlState = ControlStates.Normal;
                         mCheck.Hide();
                     }
                 }
index 399e15a..b9737fe 100755 (executable)
@@ -739,7 +739,6 @@ namespace Tizen.NUI.Components
             if (selectedItemView != null)
             {
                 selectedItemView.IsSelected = false;
-                selectedItemView.ControlState = ControlStates.Normal;
                 adapter.GetData(selectedItemIndex).IsSelected = false;
             }
 
@@ -752,7 +751,6 @@ namespace Tizen.NUI.Components
 
             selectedItemIndex = (int)index;
             selectedItemView = view;
-            selectedItemView.ControlState = ControlStates.Selected;
             selectedItemView.IsSelected = true;
             adapter.GetData(selectedItemIndex).IsSelected = true;
             dropDownMenuFullList.Layout?.RequestLayout();
@@ -761,21 +759,16 @@ namespace Tizen.NUI.Components
         private bool ListItemTouchEvent(object sender, TouchEventArgs e)
         {
             PointStateType state = e.Touch.GetState(0);
-            DropDownItemView touchedView = sender as DropDownItemView;;
+            DropDownItemView touchedView = sender as DropDownItemView;
+
+            touchedView.OnTouch(e.Touch); // Handle control state change
+
             switch (state)
             {
                 case PointStateType.Down:
-                    if (touchedView != null)
-                    {
-                        touchedView.ControlState = ControlStates.Pressed;
-                    }
                     itemPressed = true;  // if matched with a Up then a click event.
                     break;
                 case PointStateType.Motion:
-                    if (touchedView != null)
-                    {
-                        touchedView.ControlState = ControlStates.Normal;
-                    }
                     itemPressed = false;
                     break;
                 case PointStateType.Up:
index 8834b37..4299c0c 100755 (executable)
@@ -599,7 +599,7 @@ namespace Tizen.NUI.Components
             LayoutChild();
             if (itemList != null && curIndex >= 0 && curIndex < itemList.Count)
             {
-                itemList[curIndex].ControlState = ControlStates.Selected;
+                itemList[curIndex].IsSelected = true;
                 UpdateUnderLinePos();
             }
             else
@@ -665,9 +665,9 @@ namespace Tizen.NUI.Components
             };
             ItemChangedEvent?.Invoke(this, e);
 
-            itemList[curIndex].ControlState = ControlStates.Normal;
+            itemList[curIndex].IsSelected = false;
             curIndex = item.Index;
-            itemList[curIndex].ControlState = ControlStates.Selected;
+            itemList[curIndex].IsSelected = true;
 
             UpdateUnderLinePos();
         }
@@ -690,6 +690,8 @@ namespace Tizen.NUI.Components
 
         internal class TabItem : View
         {
+            private bool isSelected = false;
+
             public TabItem() : base()
             {
                 TextItem = new TextLabel()
@@ -730,6 +732,19 @@ namespace Tizen.NUI.Components
                 get;
                 set;
             }
+
+            internal bool IsSelected
+            {
+                get
+                {
+                    return isSelected;
+                }
+                set
+                {
+                    ControlState = value ? ControlStates.Selected : ControlStates.Normal;
+                    isSelected = value;
+                }
+            }
         }
 
         /// <summary>
index 28304df..631b561 100755 (executable)
@@ -345,10 +345,14 @@ namespace Tizen.NUI.Wearable
                 isEnabled = value;
                 if (isEnabled)
                 {
+                    ControlState = ControlStates.Normal;
+
                     UpdateTrackVisualColor(new Color(0.0f, 0.16f, 0.30f, 1.0f)); // #002A4D
                 }
                 else
                 {
+                    ControlState = ControlStates.Disabled;
+
                     UpdateTrackVisualColor(new Color(0.25f, 0.25f, 0.25f, 1.0f)); // #404040
                 }
             }
@@ -411,6 +415,20 @@ namespace Tizen.NUI.Wearable
             return new CircularProgressStyle();
         }
 
+        /// <inheritdoc/>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override void OnControlStateChanged(ControlStateChangedEventArgs controlStateChangedInfo)
+        {
+            base.OnControlStateChanged(controlStateChangedInfo);
+
+            var stateEnabled = !((controlStateChangedInfo.CurrentState & ControlStates.Disabled) == ControlStates.Disabled);
+
+            if (isEnabled != stateEnabled)
+            {
+                isEnabled = stateEnabled;
+            }
+        }
+
 
         private void Initialize()
         {
index 3f03b17..7bd1d16 100755 (executable)
@@ -184,7 +184,7 @@ namespace Tizen.NUI.BaseComponents
             {
                 return controlStates;
             }
-            set
+            protected set
             {
                 if (controlStates == value)
                 {