From 6a30889cb06e4368c503745a6b93a92f4c8a8db2 Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Wed, 9 Aug 2017 17:48:53 +0100 Subject: [PATCH] Adding Container base for Layer and View Change-Id: I413a9134839d0589776a39f3424ea7d4cb8f7c20 --- src/Tizen.NUI/src/public/BaseComponents/View.cs | 191 +++++++++++------------- src/Tizen.NUI/src/public/Container.cs | 114 ++++++++++++++ src/Tizen.NUI/src/public/Layer.cs | 120 +++++++-------- 3 files changed, 262 insertions(+), 163 deletions(-) create mode 100755 src/Tizen.NUI/src/public/Container.cs diff --git a/src/Tizen.NUI/src/public/BaseComponents/View.cs b/src/Tizen.NUI/src/public/BaseComponents/View.cs index 2eff066..6ae6886 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/View.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/View.cs @@ -20,12 +20,10 @@ namespace Tizen.NUI.BaseComponents using System; using System.Runtime.InteropServices; - - /// /// View is the base class for all views. /// - public class View : Animatable //CustomActor => Animatable + public class View : Container { private global::System.Runtime.InteropServices.HandleRef swigCPtr; @@ -40,6 +38,89 @@ namespace Tizen.NUI.BaseComponents return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } + // From Container Base class + + /// + /// Adds a child view to this View. + /// + /// + /// + public override void Add(View child) + { + NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child)); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Removes a child View from this View. If the view was not a child of this view, this is a no-op. + /// + /// + /// + public override void Remove(View child) + { + NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child)); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Retrieves child view by index. + /// + /// + /// + 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; + } + + /// + /// Retrieves the number of children held by the view. + /// + /// + /// + protected override uint GetChildCount() + { + uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Get the Views parent + /// + /// + + 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) { @@ -922,9 +1003,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) @@ -1771,17 +1853,6 @@ namespace Tizen.NUI.BaseComponents } } - /// - /// Retrieves the view's parent.
- ///
- public View Parent - { - get - { - return GetParent(); - } - } - public bool Visibility { get @@ -2102,32 +2173,6 @@ namespace Tizen.NUI.BaseComponents } /// - /// Adds a child view to this View. - /// - ///
This View(the parent) has been initialized. The child view has been initialized. The child view is not the same as the parent view.
- /// 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. - /// 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. - /// The child - public void Add(View child) - { - NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child)); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - } - - /// - /// Removes a child View from this View. If the view was not a child of this view, this is a no-op. - /// - ///
This View(the parent) has been initialized. The child view is not the same as the parent view.
- /// The child - public void Remove(View child) - { - NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child)); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - } - - /// /// Removes a View from its Parent View / Layer. If the View has no parent, this method does nothing. /// ///
The (child) View has been initialized. 
@@ -2139,36 +2184,6 @@ namespace Tizen.NUI.BaseComponents } /// - /// Retrieves the number of children held by the view. - /// - ///
The View has been initialized.
- /// The number of children - internal uint GetChildCount() - { - uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - - /// - /// Retrieves child view by index. - /// - ///
The View has been initialized.
- /// The index of the child to retrieve - /// The view for the given index or empty handle if children not initialized - 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; - } - - /// /// Search through this view's hierarchy for an view with the given name. /// The view itself is also considered in the search. /// @@ -2197,27 +2212,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)); @@ -3315,17 +3309,6 @@ namespace Tizen.NUI.BaseComponents } /// - /// Get the number of children held by the view. - /// - public uint ChildCount - { - get - { - return GetChildCount(); - } - } - - /// /// Gets the View's ID. /// Readonly /// diff --git a/src/Tizen.NUI/src/public/Container.cs b/src/Tizen.NUI/src/public/Container.cs new file mode 100755 index 0000000..9a96336 --- /dev/null +++ b/src/Tizen.NUI/src/public/Container.cs @@ -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 +{ + /// + /// + /// Container is an abstract class to be inherited from by classes that desire to have Views + /// added to them. + /// + /// + + 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); + } + + + /// + /// Adds a child view to this Container. + /// + ///
This Container(the parent) has been initialized. The child view has been initialized. The child view is not the same as the parent view.
+ /// 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. + /// 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. + /// The child view to add + public abstract void Add( View view ); + + /// + /// Removes a child View from this View. If the view was not a child of this view, this is a no-op. + /// + ///
This View(the parent) has been initialized. The child view is not the same as the parent view.
+ /// The child + public abstract void Remove( View view ); + + /// + /// Retrieves child view by index. + /// + ///
The View has been initialized.
+ /// The index of the child to retrieve + /// The view for the given index or empty handle if children not initialized + public abstract View GetChildAt( uint index ); + + /// + /// Get the parent of this container + /// + ///
The child container has been initialized.
+ /// The parent container + protected abstract Container GetParent(); + + /// + /// Get the number of children for this container + /// + ///
The container has been initialized.
+ /// number of children + protected abstract UInt32 GetChildCount(); + + /// + /// Get the parent Container + /// Read only + /// + ///
The child container has been initialized.
+ /// The parent container + public Container Parent + { + get + { + return GetParent(); + } + } + + /// + /// Get the number of children for this container + /// Read only + /// + ///
The container has been initialized.
+ /// number of children + public uint ChildCount + { + get + { + return GetChildCount(); + } + } + } +} // namespace Tizen.NUI \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/Layer.cs b/src/Tizen.NUI/src/public/Layer.cs index 24da1e5..1e8c5af 100755 --- a/src/Tizen.NUI/src/public/Layer.cs +++ b/src/Tizen.NUI/src/public/Layer.cs @@ -22,7 +22,7 @@ namespace Tizen.NUI /// /// Layers provide a mechanism for overlaying groups of actors on top of each other. /// - public class Layer : Animatable + public class Layer : Container { private global::System.Runtime.InteropServices.HandleRef swigCPtr; @@ -36,6 +36,66 @@ namespace Tizen.NUI return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } + /// from Container base class + + /// + /// Adds a child view to this layer. + /// + /// + /// + public override void Add(View child) + { + NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child)); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Removes a child View from this layer. If the view was not a child of this layer, this is a no-op. + /// + /// + /// + public override void Remove(View child) + { + NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child)); + if (NDalicPINVOKE.SWIGPendingException.Pending) + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Retrieves child view by index. + /// + ///
The View has been initialized.
+ /// The index of the child to retrieve + /// The view for the given index or empty handle if children not initialized + 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 +186,6 @@ namespace Tizen.NUI } /// - /// Adds a child view to this layer. - /// - ///
This layer(the parent) has been initialized. The child view has been initialized. The child view is not the same as the parent layer.
- /// 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. - /// 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. - /// The child - public void Add(View child) - { - NDalicPINVOKE.Actor_Add(swigCPtr, View.getCPtr(child)); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - } - - /// - /// Removes a child View from this layer. If the view was not a child of this layer, this is a no-op. - /// - ///
This layer(the parent) has been initialized. The child view is not the same as the parent view.
- /// The child - public void Remove(View child) - { - NDalicPINVOKE.Actor_Remove(swigCPtr, View.getCPtr(child)); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - } - - /// /// Queries the depth of the layer.
/// 0 is the bottom most layer, higher number is on top.
///
@@ -286,24 +320,6 @@ namespace Tizen.NUI } /// - /// Retrieves child view by index. - /// - ///
The View has been initialized.
- /// The index of the child to retrieve - /// The view for the given index or empty handle if children not initialized - 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; - } - - /// /// Enumeration for the behavior of the layer. /// public enum LayerBehavior @@ -415,19 +431,5 @@ namespace Tizen.NUI SetProperty(View.Property.VISIBLE, new Tizen.NUI.PropertyValue(value)); } } - - /// - /// Get the number of children held by the layer. - /// - public uint ChildCount - { - get - { - uint ret = NDalicPINVOKE.Actor_GetChildCount(swigCPtr); - if (NDalicPINVOKE.SWIGPendingException.Pending) - throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - } } } -- 2.7.4