[NUI][Xaml] Fix issue that BindingContext can't be used in C# code
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / ViewPublicMethods.cs
index 1d6bd79..ba203dc 100755 (executable)
@@ -73,34 +73,49 @@ namespace Tizen.NUI.BaseComponents
         public Animation AnimateColor(string targetVisual, object destinationColor, int startTime, int endTime, AlphaFunction.BuiltinFunctions? alphaFunction = null, object initialColor = null)
         {
             Animation animation = null;
+            using (PropertyMap animator = new PropertyMap())
+            using (PropertyMap timePeriod = new PropertyMap())
+            using (PropertyValue pvDuration = new PropertyValue((endTime - startTime) / 1000.0f))
+            using (PropertyValue pvDelay = new PropertyValue(startTime / 1000.0f))
+            using (PropertyMap transition = new PropertyMap())
+            using (PropertyValue pvTarget = new PropertyValue(targetVisual))
+            using (PropertyValue pvProperty = new PropertyValue("mixColor"))
+            using (PropertyValue destValue = PropertyValue.CreateFromObject(destinationColor))
             {
-                PropertyMap _animator = new PropertyMap();
                 if (alphaFunction != null)
                 {
-                    _animator.Add("alphaFunction", new PropertyValue(AlphaFunction.BuiltinToPropertyKey(alphaFunction)));
+                    using (PropertyValue pvAlpha = new PropertyValue(AlphaFunction.BuiltinToPropertyKey(alphaFunction)))
+                    {
+                        animator.Add("alphaFunction", pvAlpha);
+                    }
                 }
 
-                PropertyMap _timePeriod = new PropertyMap();
-                _timePeriod.Add("duration", new PropertyValue((endTime - startTime) / 1000.0f));
-                _timePeriod.Add("delay", new PropertyValue(startTime / 1000.0f));
-                _animator.Add("timePeriod", new PropertyValue(_timePeriod));
-
-                PropertyMap _transition = new PropertyMap();
-                _transition.Add("animator", new PropertyValue(_animator));
-                _transition.Add("target", new PropertyValue(targetVisual));
-                _transition.Add("property", new PropertyValue("mixColor"));
+                timePeriod.Add("duration", pvDuration);
+                timePeriod.Add("delay", pvDelay);
+                using (PropertyValue pvTimePeriod = new PropertyValue(timePeriod))
+                {
+                    animator.Add("timePeriod", pvTimePeriod);
+                }
+                using (PropertyValue pvAnimator = new PropertyValue(animator))
+                {
+                    transition.Add("animator", pvAnimator);
+                }
+                transition.Add("target", pvTarget);
+                transition.Add("property", pvProperty);
 
                 if (initialColor != null)
                 {
-                    PropertyValue initValue = PropertyValue.CreateFromObject(initialColor);
-                    _transition.Add("initialValue", initValue);
+                    using (PropertyValue initValue = PropertyValue.CreateFromObject(initialColor))
+                    {
+                        transition.Add("initialValue", initValue);
+                    }
                 }
 
-                PropertyValue destValue = PropertyValue.CreateFromObject(destinationColor);
-                _transition.Add("targetValue", destValue);
-                TransitionData _transitionData = new TransitionData(_transition);
-
-                animation = new Animation(Interop.View.CreateTransition(SwigCPtr, TransitionData.getCPtr(_transitionData)), true);
+                transition.Add("targetValue", destValue);
+                using (TransitionData transitionData = new TransitionData(transition))
+                {
+                    animation = new Animation(Interop.View.CreateTransition(SwigCPtr, TransitionData.getCPtr(transitionData)), true);
+                }
                 if (NDalicPINVOKE.SWIGPendingException.Pending)
                     throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
@@ -151,7 +166,8 @@ namespace Tizen.NUI.BaseComponents
                     };
                     ChildAdded(this, e);
                 }
-                BindableObject.SetInheritedBindingContext(child, this?.BindingContext);
+
+                AddChildBindableObject(child);
             }
         }
 
@@ -160,11 +176,18 @@ namespace Tizen.NUI.BaseComponents
         /// </summary>
         /// <seealso cref="Container.Remove" />
         /// <since_tizen> 4 </since_tizen>
+        /// <exception cref="InvalidOperationException">Thrown when deleting a view that is not a child of this view</exception>
         public override void Remove(View child)
         {
             if (child == null || child.GetParent() == null) // Early out if child null.
                 return;
 
+            if (child.GetParent() != this)
+            {
+                //throw new System.InvalidOperationException("You have deleted a view that is not a child of this view.");
+                Tizen.Log.Error("NUI", "You have deleted a view that is not a child of this view.");
+            }
+
             bool hasLayout = (layout != null);
 
             // If View has a layout then do a deferred child removal
@@ -200,6 +223,7 @@ namespace Tizen.NUI.BaseComponents
         /// </summary>
         /// <seealso cref="Container.GetChildCount" />
         /// <since_tizen> 4 </since_tizen>
+        [Obsolete("Deprecated in API9, will be removed in API11. Please use ChildCount property instead!")]
         public override uint GetChildCount()
         {
             return Convert.ToUInt32(Children.Count);
@@ -230,7 +254,7 @@ namespace Tizen.NUI.BaseComponents
             }
             else
             {
-                Tizen.Log.Error("NUI", "swigCPtr of view is aleady disposed.");
+                Tizen.Log.Error("NUI", "swigCPtr of view is already disposed.");
             }
             return ret;
         }
@@ -240,6 +264,7 @@ namespace Tizen.NUI.BaseComponents
         /// </summary>
         /// <param name="styleName">A string matching a style described in a stylesheet.</param>
         /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Deprecated in API9, will be removed in API11. Please use StyleName property instead!")]
         public void SetStyleName(string styleName)
         {
             Interop.View.SetStyleName(SwigCPtr, styleName);
@@ -251,6 +276,7 @@ namespace Tizen.NUI.BaseComponents
         /// </summary>
         /// <returns>A string matching a style, or an empty string.</returns>
         /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Deprecated in API9, will be removed in API11. Please use StyleName property instead!")]
         public string GetStyleName()
         {
             string ret = Interop.View.GetStyleName(SwigCPtr);
@@ -277,6 +303,11 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 3 </since_tizen>
         public void Show()
         {
+            if ((AccessibilityCalculateStates() & AccessibilityStates.Modal) != 0)
+            {
+                RegisterPopup();
+            }
+
             SetVisible(true);
         }
 
@@ -292,6 +323,11 @@ namespace Tizen.NUI.BaseComponents
         public void Hide()
         {
             SetVisible(false);
+
+            if ((AccessibilityCalculateStates() & AccessibilityStates.Modal) != 0)
+            {
+                RemovePopup();
+            }
         }
 
         /// <summary>
@@ -444,6 +480,7 @@ namespace Tizen.NUI.BaseComponents
         /// <param name="width">The width to use.</param>
         /// <returns>The height based on the width.</returns>
         /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Deprecated in API9, will be removed in API11. Please use HeightForWidth property instead!")]
         public float GetHeightForWidth(float width)
         {
             float ret = Interop.Actor.GetHeightForWidth(SwigCPtr, width);
@@ -460,6 +497,7 @@ namespace Tizen.NUI.BaseComponents
         /// <param name="height">The height to use.</param>
         /// <returns>The width based on the height.</returns>
         /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Deprecated in API9, will be removed in API11. Please use WidthForHeight property instead!")]
         public float GetWidthForHeight(float height)
         {
             float ret = Interop.Actor.GetWidthForHeight(SwigCPtr, height);
@@ -487,6 +525,7 @@ namespace Tizen.NUI.BaseComponents
         /// </summary>
         /// <param name="padding">Padding for the view.</param>
         /// <since_tizen> 3 </since_tizen>
+        // [Obsolete("Deprecated in API9, will be removed in API11. Please use Padding property instead!")]
         public void SetPadding(PaddingType padding)
         {
             Interop.Actor.SetPadding(SwigCPtr, PaddingType.getCPtr(padding));
@@ -499,6 +538,7 @@ namespace Tizen.NUI.BaseComponents
         /// </summary>
         /// <param name="paddingOut">the value of padding for the view</param>
         /// <since_tizen> 3 </since_tizen>
+        [Obsolete("Deprecated in API9, will be removed in API11. Please use Padding property instead!")]
         public void GetPadding(PaddingType paddingOut)
         {
             Interop.Actor.GetPadding(SwigCPtr, PaddingType.getCPtr(paddingOut));
@@ -598,17 +638,6 @@ namespace Tizen.NUI.BaseComponents
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-
-
-        /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public Transition GetTransition(string transitionName)
-        {
-            Transition trans = null;
-            transDictionary.TryGetValue(transitionName, out trans);
-            return trans;
-        }
-
         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
         public void ObjectDump()
@@ -632,5 +661,21 @@ namespace Tizen.NUI.BaseComponents
                 view.ObjectDump();
             }
         }
+
+        /// <summary>
+        /// Search through this View's hierarchy for a View with the given unique ID.
+        /// The View itself is also considered in the search.
+        /// </summary>
+        /// <param name="id">The ID of the View to find</param>
+        /// <returns>A View if found or a null if not</returns>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public View FindChildByID(uint id)
+        {
+            IntPtr cPtr = Interop.Actor.FindChildById(SwigCPtr, id);
+            View ret = this.GetInstanceSafely<View>(cPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
     }
 }