Merge "Add properties of TextLabel/Editor" into devel/master
authorJinho, Lee <jeano.lee@samsung.com>
Fri, 29 Sep 2017 04:28:48 +0000 (04:28 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Fri, 29 Sep 2017 04:28:48 +0000 (04:28 +0000)
12 files changed:
Tizen.NUI/Tizen.NUI.csproj
Tizen.NUI/TizenTVNUI.snk [new file with mode: 0755]
Tizen.NUI/src/public/BaseComponents/ImageView.cs
Tizen.NUI/src/public/BaseComponents/Scrollable.cs
Tizen.NUI/src/public/BaseComponents/View.cs
Tizen.NUI/src/public/BaseHandle.cs
Tizen.NUI/src/public/Color.cs
Tizen.NUI/src/public/Container.cs
Tizen.NUI/src/public/Layer.cs
Tizen.NUI/src/public/UIComponents/Button.cs
Tizen.NUI/src/public/VisualFactory.cs
Tizen.NUI/src/public/Window.cs

index 120e69a..d906877 100755 (executable)
@@ -18,7 +18,7 @@
     <TargetFramework>netstandard1.6</TargetFramework>\r
     <DefineConstants>$(DefineConstants);DEBUG_ON;DOT_NET_CORE</DefineConstants>\r
     <AllowUnsafeBlocks>True</AllowUnsafeBlocks>\r
-    <SignAssembly>False</SignAssembly>\r
+    <SignAssembly>true</SignAssembly>\r
     <AssemblyOriginatorKeyFile>TizenTVNUI.snk</AssemblyOriginatorKeyFile>\r
     <PublicSign Condition="'$(OS)' != 'Windows_NT'">true</PublicSign>\r
   </PropertyGroup>\r
diff --git a/Tizen.NUI/TizenTVNUI.snk b/Tizen.NUI/TizenTVNUI.snk
new file mode 100755 (executable)
index 0000000..957e8d4
Binary files /dev/null and b/Tizen.NUI/TizenTVNUI.snk differ
index ef1f2c3..5182c4f 100755 (executable)
@@ -169,11 +169,13 @@ namespace Tizen.NUI.BaseComponents
         /// <param name="url">The url of the image resource to display</param>
         public ImageView(string url) : this(NDalicPINVOKE.ImageView_New__SWIG_2(url), true)
         {
+            _url = url;
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
         }
         internal ImageView(string url, Uint16Pair size) : this(NDalicPINVOKE.ImageView_New__SWIG_3(url, Uint16Pair.getCPtr(size)), true)
         {
+            _url = url;
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
         }
@@ -192,11 +194,13 @@ namespace Tizen.NUI.BaseComponents
         /// <param name="url">The URL to the image resource to display</param>
         public void SetImage(string url)
         {
+            _url = url;
             NDalicPINVOKE.ImageView_SetImage__SWIG_1(swigCPtr, url);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
         internal void SetImage(string url, Uint16Pair size)
         {
+            _url = url;
             NDalicPINVOKE.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
index 37f26bb..3803986 100755 (executable)
@@ -53,6 +53,29 @@ namespace Tizen.NUI.BaseComponents
             //You should not access any managed member here except static instance.
             //because the execution order of Finalizes is non-deterministic.
 
+            DisConnectFromSignals();
+
+            if (swigCPtr.Handle != global::System.IntPtr.Zero)
+            {
+                if (swigCMemOwn)
+                {
+                    swigCMemOwn = false;
+                    NDalicPINVOKE.delete_Scrollable(swigCPtr);
+                }
+                swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            }
+
+            base.Dispose(type);
+        }
+
+        private void DisConnectFromSignals()
+        {
+            // Save current CPtr.
+            global::System.Runtime.InteropServices.HandleRef currentCPtr = swigCPtr;
+
+            // Use BaseHandle CPtr as current might have been deleted already in derived classes.
+            swigCPtr = GetBaseHandleCPtrHandleRef;
+
             if (_scrollableCompletedCallbackDelegate != null)
             {
                 this.ScrollCompletedSignal().Disconnect(_scrollableCompletedCallbackDelegate);
@@ -68,17 +91,9 @@ namespace Tizen.NUI.BaseComponents
                 this.ScrollStartedSignal().Disconnect(_scrollableStartedCallbackDelegate);
             }
 
-            if (swigCPtr.Handle != global::System.IntPtr.Zero)
-            {
-                if (swigCMemOwn)
-                {
-                    swigCMemOwn = false;
-                    NDalicPINVOKE.delete_Scrollable(swigCPtr);
-                }
-                swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
-            }
-
-            base.Dispose(type);
+            // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here.
+            // Restore current CPtr.
+            swigCPtr = currentCPtr;
         }
 
         public class StartedEventArgs : EventArgs
index b269e05..f18aab1 100755 (executable)
@@ -27,6 +27,7 @@ namespace Tizen.NUI.BaseComponents
     {
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
 
+
         internal View(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.View_SWIGUpcast(cPtr), cMemoryOwn)
         {
             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
@@ -50,6 +51,8 @@ namespace Tizen.NUI.BaseComponents
             NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+            Children.Add(child);
         }
 
         /// <summary>
@@ -62,6 +65,8 @@ namespace Tizen.NUI.BaseComponents
             NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child));
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+            Children.Remove(child);
         }
 
         /// <summary>
@@ -71,13 +76,14 @@ namespace Tizen.NUI.BaseComponents
         /// </seealso>
         public override View GetChildAt(uint index)
         {
-            IntPtr cPtr = NDalicPINVOKE.Actor_GetChildAt(swigCPtr, index);
-
-            View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
-
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret ?? null;
+            if (index < Children.Count)
+            {
+                return Children[Convert.ToInt32(index)];
+            }
+            else
+            {
+                return null;
+            }
         }
 
         /// <summary>
@@ -87,10 +93,7 @@ namespace Tizen.NUI.BaseComponents
         /// </seealso>
         protected override uint GetChildCount()
         {
-            uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
+            return Convert.ToUInt32(Children.Count);
         }
 
         /// <summary>
@@ -100,23 +103,14 @@ namespace Tizen.NUI.BaseComponents
 
         protected override Container GetParent()
         {
-            Container ret;
             IntPtr cPtr = NDalicPINVOKE.Actor_GetParent(swigCPtr);
 
             BaseHandle basehandle = Registry.GetManagedBaseHandleFromNativePtr(cPtr);
 
-            if(basehandle is Layer)
-            {
-                ret = basehandle as Layer;
-            }
-            else
-            {
-                ret = basehandle as View;
-            }
-
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
+
+            return basehandle as Container;
         }
 
         ///
@@ -140,6 +134,36 @@ namespace Tizen.NUI.BaseComponents
             //You should not access any managed member here except static instance.
             //because the execution order of Finalizes is non-deterministic.
 
+            DisConnectFromSignals();
+
+            if (swigCPtr.Handle != global::System.IntPtr.Zero)
+            {
+                if (swigCMemOwn)
+                {
+                    swigCMemOwn = false;
+                    NDalicPINVOKE.delete_View(swigCPtr);
+                }
+                swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            }
+
+            base.Dispose(type);
+
+            // Dispose all Children of this View.
+            foreach (View childView in Children)
+            {
+                childView?.Dispose();
+            }
+            Children.Clear();
+        }
+
+        private void DisConnectFromSignals()
+        {
+            // Save current CPtr.
+            global::System.Runtime.InteropServices.HandleRef currentCPtr = swigCPtr;
+
+            // Use BaseHandle CPtr as current might have been deleted already in derived classes.
+            swigCPtr = GetBaseHandleCPtrHandleRef;
+
             if (_onRelayoutEventCallback != null)
             {
                 this.OnRelayoutSignal().Disconnect(_onRelayoutEventCallback);
@@ -220,17 +244,9 @@ namespace Tizen.NUI.BaseComponents
                 this.KeyInputFocusGainedSignal().Disconnect(_keyInputFocusGainedCallback);
             }
 
-            if (swigCPtr.Handle != global::System.IntPtr.Zero)
-            {
-                if (swigCMemOwn)
-                {
-                    swigCMemOwn = false;
-                    NDalicPINVOKE.delete_View(swigCPtr);
-                }
-                swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
-            }
-
-            base.Dispose(type);
+            // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here.
+            // Restore current CPtr.
+            swigCPtr = currentCPtr;
         }
 
         private EventHandler _keyInputFocusGainedEventHandler;
@@ -376,15 +392,23 @@ namespace Tizen.NUI.BaseComponents
         {
             KeyEventArgs e = new KeyEventArgs();
 
+            bool result = false;
+
             e.Key = Tizen.NUI.Key.GetKeyFromPtr(keyEvent);
 
             if (_keyEventHandler != null)
             {
-                return _keyEventHandler(this, e);
+                Delegate[] delegateList = _keyEventHandler.GetInvocationList();
+
+                // Oring the result of each callback.
+                foreach ( EventHandlerWithReturnType<object, KeyEventArgs, bool> del in delegateList )
+                {
+                    result |= del( this, e );
+                }
             }
-            return false;
-        }
 
+            return result;
+        }
 
         private EventHandler _onRelayoutEventHandler;
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
@@ -2041,6 +2065,21 @@ namespace Tizen.NUI.BaseComponents
 
         internal void Raise()
         {
+            var parentChildren = Parent?.Children;
+
+            if (parentChildren != null)
+            {
+                int currentIndex = parentChildren.IndexOf(this);
+
+                // If the view is not already the last item in the list.
+                if (currentIndex != parentChildren.Count -1)
+                {
+                    View temp = parentChildren[currentIndex + 1];
+                    parentChildren[currentIndex + 1] = this;
+                    parentChildren[currentIndex] = temp;
+                }
+            }
+
             NDalicPINVOKE.Raise(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -2048,6 +2087,21 @@ namespace Tizen.NUI.BaseComponents
 
         internal void Lower()
         {
+            var parentChildren = Parent?.Children;
+
+            if (parentChildren != null)
+            {
+                int currentIndex = parentChildren.IndexOf(this);
+
+                // If the view is not already the first item in the list.
+                if (currentIndex > 0)
+                {
+                    View temp = parentChildren[currentIndex - 1];
+                    parentChildren[currentIndex - 1] = this;
+                    parentChildren[currentIndex] = temp;
+                }
+            }
+
             NDalicPINVOKE.Lower(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -2062,6 +2116,14 @@ namespace Tizen.NUI.BaseComponents
         /// </remarks>
         public void RaiseToTop()
         {
+            var parentChildren = Parent?.Children;
+
+            if (parentChildren != null)
+            {
+                parentChildren.Remove(this);
+                parentChildren.Add(this);
+            }
+
             NDalicPINVOKE.RaiseToTop(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -2076,6 +2138,14 @@ namespace Tizen.NUI.BaseComponents
         /// </remarks>
         public void LowerToBottom()
         {
+            var parentChildren = Parent?.Children;
+
+            if (parentChildren != null)
+            {
+                parentChildren.Remove(this);
+                parentChildren.Insert(0, this);
+            }
+
             NDalicPINVOKE.LowerToBottom(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -2104,6 +2174,21 @@ namespace Tizen.NUI.BaseComponents
         /// <param name="target">Will be raised above this view</param>
         internal void RaiseAbove(View target)
         {
+            var parentChildren = Parent?.Children;
+
+            if (parentChildren != null)
+            {
+                int currentIndex = parentChildren.IndexOf(this);
+                int targetIndex = parentChildren.IndexOf(target);
+
+                // If the currentIndex is less than the target index and the target has the same parent.
+                if (currentIndex < targetIndex)
+                {
+                    parentChildren.Remove(this);
+                    parentChildren.Insert(targetIndex, this);
+                }
+            }
+
             NDalicPINVOKE.RaiseAbove(swigCPtr, View.getCPtr(target));
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -2119,7 +2204,23 @@ namespace Tizen.NUI.BaseComponents
         /// <param name="target">Will be lowered below this view</param>
         internal void LowerBelow(View target)
         {
-            NDalicPINVOKE.RaiseAbove(swigCPtr, View.getCPtr(target));
+            var parentChildren = Parent?.Children;
+
+            if (parentChildren != null)
+            {
+                int currentIndex = parentChildren.IndexOf(this);
+                int targetIndex = parentChildren.IndexOf(target);
+
+                // If the currentIndex is not already the 0th index and the target has the same parent.
+                if ((currentIndex != 0) && (targetIndex != -1) &&
+                    (currentIndex > targetIndex))
+                {
+                    parentChildren.Remove(this);
+                    parentChildren.Insert(targetIndex, this);
+                }
+            }
+
+            NDalicPINVOKE.LowerBelow(swigCPtr, View.getCPtr(target));
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -2178,9 +2279,7 @@ namespace Tizen.NUI.BaseComponents
         /// <pre>The (child) View has been initialized. </pre>
         public void Unparent()
         {
-            NDalicPINVOKE.Actor_Unparent(swigCPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            GetParent()?.Remove(this);
         }
 
         /// <summary>
index e0d7ecc..6ff87e9 100755 (executable)
@@ -307,6 +307,11 @@ namespace Tizen.NUI
 
         public bool HasBody()
         {
+            if (disposed == true)
+            {
+                return false;
+            }
+
             bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
@@ -314,11 +319,24 @@ namespace Tizen.NUI
 
         public bool IsEqual(BaseHandle rhs)
         {
+            if (disposed == true)
+            {
+                return false;
+            }
+
             bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
+        internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef
+        {
+            get
+            {
+                return swigCPtr;
+            }
+        }
+
     }
 
 }
index 5a72491..1d3d55c 100755 (executable)
@@ -114,7 +114,9 @@ namespace Tizen.NUI
         /// <returns>A Color containing the result of the addition</returns>
         public static Color operator +(Color arg1, Color arg2)
         {
-            return arg1.Add(arg2);
+            Color result = arg1.Add(arg2);
+            ValueCheck(result);
+            return result;
         }
 
         /// <summary>
@@ -125,7 +127,9 @@ namespace Tizen.NUI
         /// <returns>A Color containing the result of the subtraction</returns>
         public static Color operator -(Color arg1, Color arg2)
         {
-            return arg1.Subtract(arg2);
+            Color result = arg1.Subtract(arg2);
+            ValueCheck(result);
+            return result;
         }
 
         /// <summary>
@@ -135,7 +139,9 @@ namespace Tizen.NUI
         /// <returns>A Color containg the negation</returns>
         public static Color operator -(Color arg1)
         {
-            return arg1.Subtract();
+            Color result = arg1.Subtract();
+            ValueCheck(result);
+            return result;
         }
 
         /// <summary>
@@ -146,12 +152,16 @@ namespace Tizen.NUI
         /// <returns>A Color containing the result of the multiplication</returns>
         public static Color operator *(Color arg1, Color arg2)
         {
-            return arg1.Multiply(arg2);
+            Color result = arg1.Multiply(arg2);
+            ValueCheck(result);
+            return result;
         }
 
         public static Color operator*(Color arg1, float arg2)
         {
-            return arg1.Multiply(arg2);
+            Color result = arg1.Multiply(arg2);
+            ValueCheck(result);
+            return result;
         }
 
         /// <summary>
@@ -162,12 +172,16 @@ namespace Tizen.NUI
         /// <returns>A Color containing the result of the division</returns>
         public static Color operator /(Color arg1, Color arg2)
         {
-            return arg1.Divide(arg2);
+            Color result = arg1.Divide(arg2);
+            ValueCheck(result);
+            return result;
         }
 
         public static Color operator/(Color arg1, float arg2)
         {
-            return arg1.Divide(arg2);
+            Color result = arg1.Divide(arg2);
+            ValueCheck(result);
+            return result;
         }
 
         /// <summary>
@@ -208,6 +222,10 @@ namespace Tizen.NUI
         /// <param name="a">alpha component</param>
         public Color(float r, float g, float b, float a) : this(NDalicPINVOKE.new_Vector4__SWIG_1(r, g, b, a), true)
         {
+            ValueCheck(ref r);
+            ValueCheck(ref g);
+            ValueCheck(ref b);
+            ValueCheck(ref a);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -217,6 +235,10 @@ namespace Tizen.NUI
         /// <param name="array">array Array of R,G,B,A</param>
         public Color(float[] array) : this(NDalicPINVOKE.new_Vector4__SWIG_2(array), true)
         {
+            ValueCheck(ref array[0]);
+            ValueCheck(ref array[1]);
+            ValueCheck(ref array[2]);
+            ValueCheck(ref array[3]);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -353,6 +375,7 @@ namespace Tizen.NUI
         {
             set
             {
+                ValueCheck(ref value);
                 NDalicPINVOKE.Vector4_r_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
@@ -371,6 +394,7 @@ namespace Tizen.NUI
         {
             set
             {
+                ValueCheck(ref value);
                 NDalicPINVOKE.Vector4_g_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
@@ -389,6 +413,7 @@ namespace Tizen.NUI
         {
             set
             {
+                ValueCheck(ref value);
                 NDalicPINVOKE.Vector4_b_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
@@ -407,6 +432,7 @@ namespace Tizen.NUI
         {
             set
             {
+                ValueCheck(ref value);
                 NDalicPINVOKE.Vector4_a_set(swigCPtr, value);
                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             }
@@ -481,6 +507,64 @@ namespace Tizen.NUI
             return new Color(vec.R, vec.G, vec.B, vec.A);
         }
 
+        internal static void ValueCheck(Color color)
+        {
+            if (color.R < 0.0f)
+            {
+                color.R = 0.0f;
+                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
+            }
+            else if (color.R > 1.0f)
+            {
+                color.R = 1.0f;
+                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
+            }
+            if (color.G < 0.0f)
+            {
+                color.G = 0.0f;
+                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
+            }
+            else if (color.G > 1.0f)
+            {
+                color.G = 1.0f;
+                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
+            }
+            if (color.B < 0.0f)
+            {
+                color.B = 0.0f;
+                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
+            }
+            else if (color.B > 1.0f)
+            {
+                color.B = 1.0f;
+                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
+            }
+            if (color.A < 0.0f)
+            {
+                color.A = 0.0f;
+                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
+            }
+            else if (color.A > 1.0f)
+            {
+                color.A = 1.0f;
+                Tizen.Log.Fatal("NUI", "The value of Result is invalid! Should be between [0, 1].");
+            }
+        }
+
+        internal static void ValueCheck(ref float value)
+        {
+            if (value < 0.0f)
+            {
+                value = 0.0f;
+                Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
+            }
+            else if (value > 1.0f)
+            {
+                value = 1.0f;
+                Tizen.Log.Fatal("NUI", "The value of Parameters is invalid! Should be between [0, 1].");
+            }
+        }
+
     }
 
 }
index 9a96336..a83f187 100755 (executable)
@@ -15,6 +15,7 @@
 */\r
 \r
 using System;\r
+using System.Collections.Generic;\r
 using Tizen.NUI.BaseComponents;\r
 \r
 namespace Tizen.NUI\r
@@ -29,6 +30,16 @@ namespace Tizen.NUI
     public abstract class Container : Animatable\r
     {\r
 \r
+        private List<View> _childViews = new List<View>();\r
+\r
+        public List<View> Children\r
+        {\r
+            get\r
+            {\r
+                return _childViews;\r
+            }\r
+        }\r
+\r
         internal Container(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)\r
         {\r
             // No un-managed data hence no need to store a native ptr\r
index 1e8c5af..3358325 100755 (executable)
@@ -48,6 +48,8 @@ namespace Tizen.NUI
             NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+            Children.Add(child);
         }
 
         /// <summary>
@@ -60,6 +62,8 @@ namespace Tizen.NUI
             NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child));
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+            Children.Remove(child);
         }
 
         /// <summary>
@@ -70,14 +74,14 @@ namespace Tizen.NUI
         /// <returns>The view for the given index or empty handle if children not initialized</returns>
         public override View GetChildAt(uint index)
         {
-            System.IntPtr cPtr = NDalicPINVOKE.Actor_GetChildAt(swigCPtr, index);
-
-            View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
-
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-
-            return ret ?? null;
+            if (index < Children.Count)
+            {
+                return Children[Convert.ToInt32(index)];
+            }
+            else
+            {
+                return null;
+            }
         }
 
 
@@ -88,10 +92,7 @@ namespace Tizen.NUI
 
         protected override uint GetChildCount()
         {
-            uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
+            return Convert.ToUInt32(Children.Count);
         }
 
         ///
@@ -125,6 +126,13 @@ namespace Tizen.NUI
             }
 
             base.Dispose(type);
+
+            // Dispose all Children of this Layer.
+            foreach (View childView in Children)
+            {
+                childView?.Dispose();
+            }
+            Children.Clear();
         }
 
 
index 25b6182..43eb91a 100755 (executable)
@@ -72,6 +72,29 @@ namespace Tizen.NUI.UIComponents
             //You should not access any managed member here except static instance.
             //because the execution order of Finalizes is non-deterministic.
 
+            DisConnectFromSignals();
+
+            if (swigCPtr.Handle != global::System.IntPtr.Zero)
+            {
+                if (swigCMemOwn)
+                {
+                    swigCMemOwn = false;
+                    NDalicPINVOKE.delete_Button(swigCPtr);
+                }
+                swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            }
+
+            base.Dispose(type);
+        }
+
+        private void DisConnectFromSignals()
+        {
+            // Save current CPtr.
+            global::System.Runtime.InteropServices.HandleRef currentCPtr = swigCPtr;
+
+            // Use BaseHandle CPtr as current might have been deleted already in derived classes.
+            swigCPtr = GetBaseHandleCPtrHandleRef;
+
             if (_stateChangedCallback != null)
             {
                 StateChangedSignal().Disconnect(_stateChangedCallback);
@@ -92,17 +115,9 @@ namespace Tizen.NUI.UIComponents
                 ClickedSignal().Disconnect(_clickedCallback);
             }
 
-            if (swigCPtr.Handle != global::System.IntPtr.Zero)
-            {
-                if (swigCMemOwn)
-                {
-                    swigCMemOwn = false;
-                    NDalicPINVOKE.delete_Button(swigCPtr);
-                }
-                swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
-            }
-
-            base.Dispose(type);
+            // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here.
+            // Restore current CPtr.
+            swigCPtr = currentCPtr;
         }
 
 
index 5d40948..b1e1d73 100755 (executable)
@@ -13,6 +13,7 @@
 * limitations under the License.
 *
 */
+using System;
 
 namespace Tizen.NUI
 {
@@ -66,11 +67,8 @@ namespace Tizen.NUI
         }
 
 
-        /// <summary>
-        /// Create or retrieve VisualFactory singleton.
-        /// </summary>
-        /// <returns>A handle to the VisualFactory control.</returns>
-        private static VisualFactory Get()
+        [Obsolete("Please do not use! this will be deprecated, please use VisualFactory.Instance instead")]
+        public static VisualFactory Get()
         {
             VisualFactory ret = new VisualFactory(NDalicPINVOKE.VisualFactory_Get(), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
index 69bd48e..7791990 100755 (executable)
@@ -587,14 +587,12 @@ namespace Tizen.NUI
 
         public void Add(View view)
         {
-            NDalicPINVOKE.Stage_Add(stageCPtr, View.getCPtr(view));
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            GetRootLayer()?.Add(view);
         }
 
         public void Remove(View view)
         {
-            NDalicPINVOKE.Stage_Remove(stageCPtr, View.getCPtr(view));
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            GetRootLayer()?.Remove(view);
         }
 
         internal Vector2 GetSize()
@@ -634,11 +632,13 @@ namespace Tizen.NUI
 
         internal Layer GetRootLayer()
         {
-            if (_rootLayer == null)
+            // Window.IsInstalled() is actually true only when called from event thread and
+            // Core has been initialized, not when Stage is ready.
+            if (_rootLayer == null && Window.IsInstalled())
+            {
                 _rootLayer = new Layer(NDalicPINVOKE.Stage_GetRootLayer(stageCPtr), true);
-
-
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            }
             return _rootLayer;
         }