Add support for Control keyboard navigation properties 97/117597/12
authorUmar <m.umar@partner.samsung.com>
Mon, 6 Mar 2017 17:38:13 +0000 (17:38 +0000)
committerRichard Huang <r.huang@samsung.com>
Thu, 9 Mar 2017 16:24:42 +0000 (08:24 -0800)
Change-Id: Ib64d170d6f6a782ff824318bc7e9852174cecaf5

dali-toolkit/devel-api/controls/control-devel.h
dali-toolkit/public-api/controls/control-impl.cpp
plugins/dali-swig/examples/dali-test.cs
plugins/dali-swig/manual/cpp/devel-property-wrap.cpp
plugins/dali-swig/manual/csharp/ManualPINVOKE.cs
plugins/dali-swig/manual/csharp/View.cs

index 306ce2d..b6ddd7e 100644 (file)
@@ -75,7 +75,35 @@ enum
    *
    * @see DevelControl::State
    */
-  SUB_STATE = BACKGROUND + 3
+  SUB_STATE = BACKGROUND + 3,
+
+  /**
+   * @brief The actor ID of the left focusable control.
+   * @details Name "leftFocusableActorId", type Property::INTEGER.
+   *
+   */
+  LEFT_FOCUSABLE_ACTOR_ID = BACKGROUND + 4,
+
+  /**
+   * @brief The actor ID of the right focusable control.
+   * @details Name "rightFocusableActorId", type Property::INTEGER.
+   *
+   */
+  RIGHT_FOCUSABLE_ACTOR_ID = BACKGROUND + 5,
+
+  /**
+   * @brief The actor ID of the up focusable control.
+   * @details Name "upFocusableActorId", type Property::INTEGER.
+   *
+   */
+  UP_FOCUSABLE_ACTOR_ID = BACKGROUND + 6,
+
+  /**
+   * @brief The actor ID of the down focusable control.
+   * @details Name "downFocusableActorId", type Property::INTEGER.
+   *
+   */
+  DOWN_FOCUSABLE_ACTOR_ID = BACKGROUND + 7
 };
 
 } // namespace Property
index d45c8dd..26e020a 100644 (file)
@@ -56,7 +56,6 @@
 
 namespace Dali
 {
-extern bool CaseInsensitiveStringCompare( const std::string& a, const std::string& b );
 
 namespace Toolkit
 {
@@ -267,6 +266,10 @@ public:
   : mControlImpl( controlImpl ),
     mState( Toolkit::DevelControl::NORMAL ),
     mSubStateName(""),
+    mLeftFocusableActorId( -1 ),
+    mRightFocusableActorId( -1 ),
+    mUpFocusableActorId( -1 ),
+    mDownFocusableActorId( -1 ),
     mStyleName(""),
     mBackgroundColor(Color::TRANSPARENT),
     mStartingPinchScale( NULL ),
@@ -370,6 +373,46 @@ public:
         }
         break;
 
+        case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
+        {
+          int focusId;
+          if( value.Get( focusId ) )
+          {
+            controlImpl.mImpl->mLeftFocusableActorId = focusId;
+          }
+        }
+        break;
+
+        case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
+        {
+          int focusId;
+          if( value.Get( focusId ) )
+          {
+            controlImpl.mImpl->mRightFocusableActorId = focusId;
+          }
+        }
+        break;
+
+        case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
+        {
+          int focusId;
+          if( value.Get( focusId ) )
+          {
+            controlImpl.mImpl->mUpFocusableActorId = focusId;
+          }
+        }
+        break;
+
+        case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
+        {
+          int focusId;
+          if( value.Get( focusId ) )
+          {
+            controlImpl.mImpl->mDownFocusableActorId = focusId;
+          }
+        }
+        break;
+
         case Toolkit::Control::Property::BACKGROUND_COLOR:
         {
           DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
@@ -486,6 +529,30 @@ public:
           break;
         }
 
+        case Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID:
+        {
+          value = controlImpl.mImpl->mLeftFocusableActorId;
+          break;
+        }
+
+        case Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID:
+        {
+          value = controlImpl.mImpl->mRightFocusableActorId;
+          break;
+        }
+
+        case Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID:
+        {
+          value = controlImpl.mImpl->mUpFocusableActorId;
+          break;
+        }
+
+        case Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID:
+        {
+          value = controlImpl.mImpl->mDownFocusableActorId;
+          break;
+        }
+
         case Toolkit::Control::Property::BACKGROUND_COLOR:
         {
           DALI_LOG_WARNING( "BACKGROUND_COLOR property is deprecated. Use BACKGROUND property instead\n" );
@@ -836,6 +903,11 @@ public:
   DevelControl::State mState;
   std::string mSubStateName;
 
+  int mLeftFocusableActorId;       ///< Actor ID of Left focusable control.
+  int mRightFocusableActorId;      ///< Actor ID of Right focusable control.
+  int mUpFocusableActorId;         ///< Actor ID of Up focusable control.
+  int mDownFocusableActorId;       ///< Actor ID of Down focusable control.
+
   RegisteredVisualContainer mVisuals; // Stores visuals needed by the control, non trivial type so std::vector used.
   std::string mStyleName;
   Vector4 mBackgroundColor;                       ///< The color of the background visual
@@ -866,17 +938,25 @@ public:
   static const PropertyRegistration PROPERTY_6;
   static const PropertyRegistration PROPERTY_7;
   static const PropertyRegistration PROPERTY_8;
+  static const PropertyRegistration PROPERTY_9;
+  static const PropertyRegistration PROPERTY_10;
+  static const PropertyRegistration PROPERTY_11;
+  static const PropertyRegistration PROPERTY_12;
 };
 
 // Properties registered without macro to use specific member variables.
-const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName",       Toolkit::Control::Property::STYLE_NAME,       Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor", Toolkit::Control::Property::BACKGROUND_COLOR, Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage", Toolkit::Control::Property::BACKGROUND_IMAGE, Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus",   Toolkit::Control::Property::KEY_INPUT_FOCUS,  Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background",      Toolkit::Control::Property::BACKGROUND,       Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "tooltip",         Toolkit::DevelControl::Property::TOOLTIP,     Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "state",           Toolkit::DevelControl::Property::STATE,       Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
-const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "subState",        Toolkit::DevelControl::Property::SUB_STATE,   Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_1( typeRegistration, "styleName",              Toolkit::Control::Property::STYLE_NAME,                   Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_2( typeRegistration, "backgroundColor",        Toolkit::Control::Property::BACKGROUND_COLOR,             Property::VECTOR4, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_3( typeRegistration, "backgroundImage",        Toolkit::Control::Property::BACKGROUND_IMAGE,             Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_4( typeRegistration, "keyInputFocus",          Toolkit::Control::Property::KEY_INPUT_FOCUS,              Property::BOOLEAN, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_5( typeRegistration, "background",             Toolkit::Control::Property::BACKGROUND,                   Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_6( typeRegistration, "tooltip",                Toolkit::DevelControl::Property::TOOLTIP,                 Property::MAP,     &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_7( typeRegistration, "state",                  Toolkit::DevelControl::Property::STATE,                   Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_8( typeRegistration, "subState",               Toolkit::DevelControl::Property::SUB_STATE,               Property::STRING,  &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_9( typeRegistration, "leftFocusableActorId",   Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_10( typeRegistration, "rightFocusableActorId", Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID,Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_11( typeRegistration, "upFocusableActorId",    Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID,   Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
+const PropertyRegistration Control::Impl::PROPERTY_12( typeRegistration, "downFocusableActorId",  Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, Property::INTEGER, &Control::Impl::SetProperty, &Control::Impl::GetProperty );
 
 Toolkit::Control Control::New()
 {
index 73b7fb3..6e106ae 100644 (file)
@@ -108,6 +108,8 @@ namespace MyCSharpExample
 
         public void Initialize(object source, NUIApplicationInitEventArgs e)
         {
+            NavigationPropertiesTests();
+
             OperatorTests();
 
             CustomViewPropertyTest();
@@ -265,6 +267,83 @@ namespace MyCSharpExample
             }
         }
 
+        public void NavigationPropertiesTests()
+        {
+            View view = new View();
+            View leftView, rightView, upView, downView, tmpView;
+
+            leftView = new View();
+            leftView.Name = "leftView";
+            rightView = new View();
+            rightView.Name = "rightView";
+            upView = new View();
+            upView.Name = "upView";
+            downView = new View();
+            downView.Name = "downView";
+
+            Stage.Instance.Add(leftView);
+            Stage.Instance.Add(rightView);
+            Stage.Instance.Add(upView);
+            Stage.Instance.Add(downView);
+
+            view.LeftFocusableView = leftView;
+            tmpView = view.LeftFocusableView;
+            if (string.Compare(tmpView.Name, "leftView") == 0)
+            {
+                Console.WriteLine("Passed: LeftFocusedView = " + tmpView.Name);
+            }
+            else
+            {
+                Console.WriteLine("Failed: LeftFocusedView = " + tmpView.Name);
+            }
+
+            view.RightFocusableView = rightView;
+            tmpView = view.RightFocusableView;
+            if (string.Compare(tmpView.Name, "rightView") == 0)
+            {
+                Console.WriteLine("Passed: RightFocusedView = " + tmpView.Name);
+            }
+            else
+            {
+                Console.WriteLine("Failed: RightFocusedView = " + tmpView.Name);
+            }
+
+            Stage.Instance.Add(view);
+
+            view.UpFocusableView = upView;
+            tmpView = view.UpFocusableView;
+            if (string.Compare(tmpView.Name, "upView") == 0)
+            {
+                Console.WriteLine("Passed: UpFocusedView = " + tmpView.Name);
+            }
+            else
+            {
+                Console.WriteLine("Failed: UpFocusedView = " + tmpView.Name);
+            }
+
+            view.DownFocusableView = downView;
+            tmpView = view.DownFocusableView;
+            if (string.Compare(tmpView.Name, "downView") == 0)
+            {
+                Console.WriteLine("Passed: DownFocusedView = " + tmpView.Name);
+            }
+            else
+            {
+                Console.WriteLine("Failed: DownFocusedView = " + tmpView.Name);
+            }
+
+            Stage.Instance.Remove(leftView);
+            tmpView = view.LeftFocusableView;
+            if (!tmpView)
+            {
+                Console.WriteLine("Passed: NULL LeftFocusedView");
+            }
+            else
+            {
+                Console.WriteLine("Failed: LeftFocusedView = " + tmpView.Name);
+            }
+        }
+
         public void OperatorTests()
         {
             Actor actor = new Actor();
index 89005b4..f4fffbd 100755 (executable)
@@ -75,6 +75,22 @@ SWIGEXPORT int SWIGSTDCALL CSharp_View_Property_SUB_STATE_get() {
   return jresult;
 }
 
+SWIGEXPORT int SWIGSTDCALL CSharp_View_Property_LEFT_FOCUSABLE_ACTOR_ID_get() {
+  return Dali::Toolkit::DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID;
+}
+
+SWIGEXPORT int SWIGSTDCALL CSharp_View_Property_RIGHT_FOCUSABLE_ACTOR_ID_get() {
+  return Dali::Toolkit::DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID;
+}
+
+SWIGEXPORT int SWIGSTDCALL CSharp_View_Property_UP_FOCUSABLE_ACTOR_ID_get() {
+  return Dali::Toolkit::DevelControl::Property::UP_FOCUSABLE_ACTOR_ID;
+}
+
+SWIGEXPORT int SWIGSTDCALL CSharp_View_Property_DOWN_FOCUSABLE_ACTOR_ID_get() {
+  return Dali::Toolkit::DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID;
+}
+
 SWIGEXPORT int SWIGSTDCALL CSharp_ItemView_Property_LAYOUT_get() {
   int jresult ;
   int result;
index b627299..f439851 100755 (executable)
@@ -205,6 +205,18 @@ namespace Dali
         [global::System.Runtime.InteropServices.DllImport("NDalic", EntryPoint="CSharp_View_Property_SUB_STATE_get")]
         public static extern int View_Property_SUB_STATE_get();
 
+        [global::System.Runtime.InteropServices.DllImport("NDalic", EntryPoint="CSharp_View_Property_LEFT_FOCUSABLE_ACTOR_ID_get")]
+        public static extern int View_Property_LEFT_FOCUSABLE_ACTOR_ID_get();
+
+        [global::System.Runtime.InteropServices.DllImport("NDalic", EntryPoint="CSharp_View_Property_RIGHT_FOCUSABLE_ACTOR_ID_get")]
+        public static extern int View_Property_RIGHT_FOCUSABLE_ACTOR_ID_get();
+
+        [global::System.Runtime.InteropServices.DllImport("NDalic", EntryPoint="CSharp_View_Property_UP_FOCUSABLE_ACTOR_ID_get")]
+        public static extern int View_Property_UP_FOCUSABLE_ACTOR_ID_get();
+
+        [global::System.Runtime.InteropServices.DllImport("NDalic", EntryPoint="CSharp_View_Property_DOWN_FOCUSABLE_ACTOR_ID_get")]
+        public static extern int View_Property_DOWN_FOCUSABLE_ACTOR_ID_get();
+
         [global::System.Runtime.InteropServices.DllImport("NDalic", EntryPoint="CSharp_ItemView_Property_LAYOUT_get")]
         public static extern int ItemView_Property_LAYOUT_get();
 
index 1b4fbec..e4b1a02 100644 (file)
@@ -910,6 +910,10 @@ public class View : CustomActor {
     public static readonly int TOOLTIP = NDalicManualPINVOKE.View_Property_TOOLTIP_get();
     public static readonly int STATE = NDalicManualPINVOKE.View_Property_STATE_get();
     public static readonly int SUB_STATE = NDalicManualPINVOKE.View_Property_SUB_STATE_get();
+    public static readonly int LEFT_FOCUSABLE_ACTOR_ID = NDalicManualPINVOKE.View_Property_LEFT_FOCUSABLE_ACTOR_ID_get();
+    public static readonly int RIGHT_FOCUSABLE_ACTOR_ID = NDalicManualPINVOKE.View_Property_RIGHT_FOCUSABLE_ACTOR_ID_get();
+    public static readonly int UP_FOCUSABLE_ACTOR_ID = NDalicManualPINVOKE.View_Property_UP_FOCUSABLE_ACTOR_ID_get();
+    public static readonly int DOWN_FOCUSABLE_ACTOR_ID = NDalicManualPINVOKE.View_Property_DOWN_FOCUSABLE_ACTOR_ID_get();
 
     public Property() : this(NDalicPINVOKE.new_View_Property(), true) {
       if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -992,6 +996,23 @@ public class View : CustomActor {
       return (T)( ViewRegistry.GetViewFromActor( actor ) );
   }
 
+  private View ConvertIdToView(uint id)
+  {
+    Actor actor = null;
+
+    if (Parent)
+    {
+      actor = Parent.FindChildById(id);
+    }
+
+    if (!actor)
+    {
+      actor = Stage.Instance.GetRootLayer().FindChildById(id);
+    }
+
+    return View.DownCast<View>(actor);
+  }
+
   public void SetKeyInputFocus() {
     NDalicPINVOKE.View_SetKeyInputFocus(swigCPtr);
     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -1228,6 +1249,62 @@ public class View : CustomActor {
     }
   }
 
+  private int LeftFocusableActorId
+  {
+    get
+    {
+      int temp = 0;
+      GetProperty( View.Property.LEFT_FOCUSABLE_ACTOR_ID).Get( ref temp );
+      return temp;
+    }
+    set
+    {
+      SetProperty( View.Property.LEFT_FOCUSABLE_ACTOR_ID, new Dali.Property.Value( value ) );
+    }
+  }
+
+  private int RightFocusableActorId
+  {
+    get
+    {
+      int temp = 0;
+      GetProperty( View.Property.RIGHT_FOCUSABLE_ACTOR_ID).Get( ref temp );
+      return temp;
+    }
+    set
+    {
+      SetProperty( View.Property.RIGHT_FOCUSABLE_ACTOR_ID, new Dali.Property.Value( value ) );
+    }
+  }
+
+  private int UpFocusableActorId
+  {
+    get
+    {
+      int temp = 0;
+      GetProperty( View.Property.UP_FOCUSABLE_ACTOR_ID).Get( ref temp );
+      return temp;
+    }
+    set
+    {
+      SetProperty( View.Property.UP_FOCUSABLE_ACTOR_ID, new Dali.Property.Value( value ) );
+    }
+  }
+
+  private int DownFocusableActorId
+  {
+    get
+    {
+      int temp = 0;
+      GetProperty( View.Property.DOWN_FOCUSABLE_ACTOR_ID).Get( ref temp );
+      return temp;
+    }
+    set
+    {
+      SetProperty( View.Property.DOWN_FOCUSABLE_ACTOR_ID, new Dali.Property.Value( value ) );
+    }
+  }
+
   public float Flex
   {
     get
@@ -1339,6 +1416,98 @@ public class View : CustomActor {
       SetProperty( TableView.ChildProperty.CELL_VERTICAL_ALIGNMENT, new Dali.Property.Value( value ) );
     }
   }
+
+  /**
+   * @brief The left focusable view.
+   * @note This will return NULL if not set.
+   * This will also return NULL if the specified left focusable view is not on stage.
+   *
+   */
+  public View LeftFocusableView
+  {
+    // As native side will be only storing IDs so need a logic to convert View to ID and vice-versa.
+    get
+    {
+      if (LeftFocusableActorId >= 0)
+      {
+        return ConvertIdToView((uint)LeftFocusableActorId);
+      }
+      return null;
+    }
+    set
+    {
+      LeftFocusableActorId = (int)value.GetId();
+    }
+  }
+
+  /**
+   * @brief The right focusable view.
+   * @note This will return NULL if not set.
+   * This will also return NULL if the specified right focusable view is not on stage.
+   *
+   */
+  public View RightFocusableView
+  {
+    // As native side will be only storing IDs so need a logic to convert View to ID and vice-versa.
+    get
+    {
+      if (RightFocusableActorId >= 0)
+      {
+        return ConvertIdToView((uint)RightFocusableActorId);
+      }
+      return null;
+    }
+    set
+    {
+      RightFocusableActorId = (int)value.GetId();
+    }
+  }
+
+  /**
+   * @brief The up focusable view.
+   * @note This will return NULL if not set.
+   * This will also return NULL if the specified up focusable view is not on stage.
+   *
+   */
+  public View UpFocusableView
+  {
+    // As native side will be only storing IDs so need a logic to convert View to ID and vice-versa.
+    get
+    {
+      if (UpFocusableActorId >= 0)
+      {
+        return ConvertIdToView((uint)UpFocusableActorId);
+      }
+      return null;
+    }
+    set
+    {
+      UpFocusableActorId = (int)value.GetId();
+    }
+  }
+
+  /**
+   * @brief The down focusable view.
+   * @note This will return NULL if not set.
+   * This will also return NULL if the specified down focusable view is not on stage.
+   *
+   */
+  public View DownFocusableView
+  {
+    // As native side will be only storing IDs so need a logic to convert View to ID and vice-versa.
+    get
+    {
+      if (DownFocusableActorId >= 0)
+      {
+        return ConvertIdToView((uint)DownFocusableActorId);
+      }
+      return null;
+    }
+    set
+    {
+      DownFocusableActorId = (int)value.GetId();
+    }
+  }
 }
 
 }