[Tizen] Adding Container base for Layer and View
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Wed, 9 Aug 2017 16:48:53 +0000 (17:48 +0100)
committerdongsug.song <dongsug.song@samsung.com>
Fri, 1 Sep 2017 00:23:45 +0000 (09:23 +0900)
Conflicts:
Tizen.NUI/src/public/BaseComponents/View.cs
Tizen.NUI/src/public/Layer.cs

Change-Id: I413a9134839d0589776a39f3424ea7d4cb8f7c20

src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/Container.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/Layer.cs

index 857776f..d4a2bec 100755 (executable)
@@ -20,12 +20,10 @@ namespace Tizen.NUI.BaseComponents
     using System;
     using System.Runtime.InteropServices;
 
-
-
     /// <summary>
     /// View is the base class for all views.
     /// </summary>
-    public class View : Animatable //CustomActor => Animatable
+    public class View : Container
     {
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
 
@@ -40,6 +38,88 @@ namespace Tizen.NUI.BaseComponents
             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
         }
 
+        // From Container Base class
+
+        /// <summary>
+        /// Adds a child view to this View.
+        /// </summary>
+        /// <seealso cref="Container::Add()">
+        /// </seealso>
+        public override void Add(View child)
+        {
+            NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
+            if (NDalicPINVOKE.SWIGPendingException.Pending)
+                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// Removes a child View from this View. If the view was not a child of this view, this is a no-op.
+        /// </summary>
+        /// <seealso cref="Container::Remove()">
+        /// </seealso>
+        public override void Remove(View child)
+        {
+            NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child));
+            if (NDalicPINVOKE.SWIGPendingException.Pending)
+                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// Retrieves child view by index.
+        /// </summary>
+        /// <seealso cref="Container::GetChildAt()">
+        /// </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;
+        }
+
+        /// <summary>
+        /// Retrieves the number of children held by the view.
+        /// </summary>
+        /// <seealso cref="Container::GetChildCount()">
+        /// </seealso>
+        protected override uint GetChildCount()
+        {
+            uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending)
+                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <summary>
+        /// Get the Views parent
+        /// </summary>
+        /// <seealso cref="Container::GetParent()">
+        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;
+        }
+
+        ///
+
         // you can override it to clean-up your own resources.
         protected override void Dispose(DisposeTypes type)
         {
@@ -945,9 +1025,10 @@ namespace Tizen.NUI.BaseComponents
         {
             View view = null;
 
-            if (Parent)
+            if (Parent is View)
             {
-                view = Parent.FindChildById(id);
+                View parentView = Parent as View;
+                view = parentView.FindChildById(id);
             }
 
             if (!view)
@@ -1794,17 +1875,6 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
-        /// <summary>
-        /// Retrieves the view's parent.<br>
-        /// </summary>
-        public View Parent
-        {
-            get
-            {
-                return GetParent();
-            }
-        }
-
         [Obsolete("Please do not use! this will be deprecated. Please use Visibility instead.")]
         public bool Visible
         {
@@ -2150,32 +2220,6 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
-        /// Adds a child view to this View.
-        /// </summary>
-        /// <pre>This View(the parent) has been initialized. The child view has been initialized. The child view is not the same as the parent view.</pre>
-        /// <post>The child will be referenced by its parent. This means that the child will be kept alive, even if the handle passed into this method is reset or destroyed.</post>
-        /// <remarks>If the child already has a parent, it will be removed from old parent and reparented to this view. This may change child's position, color, scale etc as it now inherits them from this view.</remarks>
-        /// <param name="child">The child</param>
-        public void Add(View child)
-        {
-            NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-        }
-
-        /// <summary>
-        /// Removes a child View from this View. If the view was not a child of this view, this is a no-op.
-        /// </summary>
-        /// <pre>This View(the parent) has been initialized. The child view is not the same as the parent view.</pre>
-        /// <param name="child">The child</param>
-        public void Remove(View child)
-        {
-            NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child));
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-        }
-
-        /// <summary>
         /// Removes a View from its Parent View / Layer. If the View has no parent, this method does nothing.
         /// </summary>
         /// <pre>The (child) View has been initialized. </pre>
@@ -2187,36 +2231,6 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
-        /// Retrieves the number of children held by the view.
-        /// </summary>
-        /// <pre>The View has been initialized.</pre>
-        /// <returns>The number of children</returns>
-        internal uint GetChildCount()
-        {
-            uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
-        }
-
-        /// <summary>
-        /// Retrieves child view by index.
-        /// </summary>
-        /// <pre>The View has been initialized.</pre>
-        /// <param name="index">The index of the child to retrieve</param>
-        /// <returns>The view for the given index or empty handle if children not initialized</returns>
-        public 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;
-        }
-
-        /// <summary>
         /// Search through this view's hierarchy for an view with the given name.
         /// The view itself is also considered in the search.
         /// </summary>
@@ -2245,27 +2259,6 @@ namespace Tizen.NUI.BaseComponents
             return ret;
         }
 
-        internal View GetParent()
-        {
-            View ret;
-            IntPtr cPtr = NDalicPINVOKE.Actor_GetParent(swigCPtr);
-
-            BaseHandle basehandle = Registry.GetManagedBaseHandleFromNativePtr(cPtr);
-
-            if(basehandle is Layer)
-            {
-                ret = new View(cPtr,false);
-            }
-            else
-            {
-                ret = basehandle as View;
-            }
-
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
-        }
-
         internal void SetParentOrigin(Vector3 origin)
         {
             NDalicPINVOKE.Actor_SetParentOrigin(swigCPtr, Vector3.getCPtr(origin));
@@ -3968,6 +3961,32 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        [Obsolete("Please DO NOT use! This will be deprecated! Please use 'Container GetParent()' instead!")]
+        public View Parent
+        {
+            get
+            {
+                View ret;
+                IntPtr cPtr = NDalicPINVOKE.Actor_GetParent(swigCPtr);
+
+                BaseHandle basehandle = Registry.GetManagedBaseHandleFromNativePtr(cPtr);
+
+                if (basehandle is Layer)
+                {
+                    ret = new View(cPtr, false);
+                }
+                else
+                {
+                    ret = basehandle as View;
+                }
+
+                if (NDalicPINVOKE.SWIGPendingException.Pending)
+                    throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+                return ret;
+            }
+        }
+
+
 
 
 
diff --git a/src/Tizen.NUI/src/public/Container.cs b/src/Tizen.NUI/src/public/Container.cs
new file mode 100755 (executable)
index 0000000..515874e
--- /dev/null
@@ -0,0 +1,114 @@
+/** Copyright (c) 2017 Samsung Electronics Co., Ltd.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+using System;
+using Tizen.NUI.BaseComponents;
+
+namespace Tizen.NUI
+{
+    /// <summary>
+    ///
+    /// Container is an abstract class to be inherited from by classes that desire to have Views
+    /// added to them.
+    ///
+    /// </summary>
+
+    public abstract class Container : Animatable
+    {
+
+        internal Container(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+            // No un-managed data hence no need to store a native ptr
+        }
+
+        protected override void Dispose(DisposeTypes type)
+        {
+            if (disposed)
+            {
+                return;
+            }
+
+            base.Dispose(type);
+        }
+
+
+        /// <summary>
+        /// Adds a child view to this Container.
+        /// </summary>
+        /// <pre>This Container(the parent) has been initialized. The child view has been initialized. The child view is not the same as the parent view.</pre>
+        /// <post>The child will be referenced by its parent. This means that the child will be kept alive, even if the handle passed into this method is reset or destroyed.</post>
+        /// <remarks>If the child already has a parent, it will be removed from old parent and reparented to this view. This may change child's position, color, scale etc as it now inherits them from this view.</remarks>
+        /// <param name="view">The child view to add</param>
+        public abstract void Add( View view );
+
+        /// <summary>
+        /// Removes a child View from this View. If the view was not a child of this view, this is a no-op.
+        /// </summary>
+        /// <pre>This View(the parent) has been initialized. The child view is not the same as the parent view.</pre>
+        /// <param name="child">The child</param>
+        public abstract void Remove( View view );
+
+        /// <summary>
+        /// Retrieves child view by index.
+        /// </summary>
+        /// <pre>The View has been initialized.</pre>
+        /// <param name="index">The index of the child to retrieve</param>
+        /// <returns>The view for the given index or empty handle if children not initialized</returns>
+        public abstract View GetChildAt( uint index );
+
+        /// <summary>
+        /// Get the parent of this container
+        /// </summary>
+        /// <pre>The child container has been initialized.</pre>
+        /// <returns>The parent container</returns>
+        protected abstract Container GetParent();
+
+        /// <summary>
+        /// Get the number of children for this container
+        /// </summary>
+        /// <pre>The container has been initialized.</pre>
+        /// <returns>number of children</returns>
+        protected abstract UInt32 GetChildCount();
+
+        /// <summary>
+        /// Get the parent Container
+        /// Read only
+        /// </summary>
+        /// <pre>The child container has been initialized.</pre>
+        /// <returns>The parent container</returns>
+        public Container Parent
+        {
+            get
+            {
+                return GetParent();
+            }
+        }
+
+        /// <summary>
+        /// Get the number of children for this container
+        /// Read only
+        /// </summary>
+        /// <pre>The container has been initialized.</pre>
+        /// <returns>number of children</returns>
+        public uint ChildCount
+        {
+            get
+            {
+                return GetChildCount();
+            }
+        }
+    }
+} // namespace Tizen.NUI
\ No newline at end of file
index 17179f8..f4aaa35 100755 (executable)
@@ -22,7 +22,7 @@ namespace Tizen.NUI
     /// <summary>
     /// Layers provide a mechanism for overlaying groups of actors on top of each other.
     /// </summary>
-    public class Layer : Animatable
+    public class Layer : Container
     {
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
 
@@ -36,6 +36,64 @@ namespace Tizen.NUI
             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
         }
 
+        /// from Container base class
+
+        /// <summary>
+        /// Adds a child view to this layer.
+        /// </summary>
+        /// <seealso cref="Container::Add()">
+        /// </seealso>
+        public override void Add(View child)
+        {
+            NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
+            if (NDalicPINVOKE.SWIGPendingException.Pending)
+                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// Removes a child View from this layer. If the view was not a child of this layer, this is a no-op.
+        /// </summary>
+        /// <seealso cref="Container::Add()">
+        /// </seealso>
+        public override void Remove(View child)
+        {
+            NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child));
+            if (NDalicPINVOKE.SWIGPendingException.Pending)
+                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
+        /// Retrieves child view by index.
+        /// </summary>
+        /// <pre>The View has been initialized.</pre>
+        /// <param name="index">The index of the child to retrieve</param>
+        /// <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;
+        }
+
+
+        protected override Container GetParent()
+        {
+            return null;
+        }
+
+        protected override uint GetChildCount()
+        {
+            uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending)
+                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
         protected override void Dispose(DisposeTypes type)
         {
             if(disposed)
@@ -126,32 +184,6 @@ namespace Tizen.NUI
         }
 
         /// <summary>
-        /// Adds a child view to this layer.
-        /// </summary>
-        /// <pre>This layer(the parent) has been initialized. The child view has been initialized. The child view is not the same as the parent layer.</pre>
-        /// <post>The child will be referenced by its parent. This means that the child will be kept alive, even if the handle passed into this method is reset or destroyed.</post>
-        /// <remarks>If the child already has a parent, it will be removed from old parent and reparented to this layer. This may change child's position, color, scale etc as it now inherits them from this layer.</remarks>
-        /// <param name="child">The child</param>
-        public void Add(View child)
-        {
-            NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child));
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-        }
-
-        /// <summary>
-        /// Removes a child View from this layer. If the view was not a child of this layer, this is a no-op.
-        /// </summary>
-        /// <pre>This layer(the parent) has been initialized. The child view is not the same as the parent view.</pre>
-        /// <param name="child">The child</param>
-        public void Remove(View child)
-        {
-            NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child));
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-        }
-
-        /// <summary>
         /// Queries the depth of the layer.<br>
         /// 0 is the bottom most layer, higher number is on top.<br>
         /// </summary>
@@ -286,24 +318,6 @@ namespace Tizen.NUI
         }
 
         /// <summary>
-        /// Retrieves child view by index.
-        /// </summary>
-        /// <pre>The View has been initialized.</pre>
-        /// <param name="index">The index of the child to retrieve</param>
-        /// <returns>The view for the given index or empty handle if children not initialized</returns>
-        public 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;
-        }
-
-        /// <summary>
         /// Enumeration for the behavior of the layer.
         /// </summary>
         public enum LayerBehavior
@@ -459,5 +473,6 @@ namespace Tizen.NUI
             if (NDalicPINVOKE.SWIGPendingException.Pending)
                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
+
     }
 }