[NUI] Add _parent in Container (#177)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Container.cs
1 /*
2  * Copyright(c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.Collections.Generic;
20 using Tizen.NUI.BaseComponents;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// The Container is an abstract class to be inherited from by classes that desire to have views
26     /// added to them.
27     /// </summary>
28     /// <since_tizen> 4 </since_tizen>
29     public abstract class Container : Animatable
30     {
31
32         private List<View> _childViews = new List<View>();
33         private Container _parent = null;
34
35         /// <summary>
36         /// List of children of Container.
37         /// </summary>
38         /// <since_tizen> 4 </since_tizen>
39         public List<View> Children
40         {
41             get
42             {
43                 return _childViews;
44             }
45         }
46
47         internal Container(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
48         {
49             // No un-managed data hence no need to store a native ptr
50         }
51
52         /// <summary>
53         /// Dispose.
54         /// </summary>
55         /// <since_tizen> 4 </since_tizen>
56         protected override void Dispose(DisposeTypes type)
57         {
58             if (disposed)
59             {
60                 return;
61             }
62
63             base.Dispose(type);
64         }
65
66         /// <summary>
67         /// This should be implemented in derived child classes such as View and Layer
68         /// </summary>
69         /// <returns>parent object of mine, which will be Container class</returns>
70         protected abstract Container GetParent();
71
72         /// <summary>
73         /// Adds a child view to this Container.
74         /// </summary>
75         /// <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>
76         /// <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>
77         /// <remarks>If the child already has a parent, it will be removed from the 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>
78         /// <param name="view">The child view to add.</param>
79         /// <since_tizen> 4 </since_tizen>
80         public abstract void Add( View view );
81
82         /// <summary>
83         /// Removes a child view from this view. If the view was not a child of this view, this is a no-op.
84         /// </summary>
85         /// <pre>This View(the parent) has been initialized. The child view is not the same as the parent view.</pre>
86         /// <param name="view">The view to remove</param>
87         /// <since_tizen> 4 </since_tizen>
88         public abstract void Remove( View view );
89
90         /// <summary>
91         /// Retrieves the child view by the index.
92         /// </summary>
93         /// <pre>The view has been initialized.</pre>
94         /// <param name="index">The index of the child to retrieve.</param>
95         /// <returns>The view for the given index or empty handle if children are not initialized.</returns>
96         /// <since_tizen> 4 </since_tizen>
97         public abstract View GetChildAt( uint index );
98
99         /// <summary>
100         /// Gets the number of children for this container.
101         /// </summary>
102         /// <pre>The container has been initialized.</pre>
103         /// <returns>The number of children.</returns>
104         /// <since_tizen> 4 </since_tizen>
105         public abstract UInt32 GetChildCount();
106
107         /// <summary>
108         /// Gets the parent container.
109         /// Read only
110         /// </summary>
111         /// <pre>The child container has been initialized.</pre>
112         /// <returns>The parent container.</returns>
113         /// <since_tizen> 4 </since_tizen>
114         public Container Parent
115         {
116             get
117             {
118                 return _parent;
119             }
120         }
121
122         internal void SetParent(Container parent)
123         {
124             _parent = parent;
125         }
126
127         /// <summary>
128         /// Gets the number of children for this container.
129         /// Read only
130         /// </summary>
131         /// <pre>The container has been initialized.</pre>
132         /// <returns>The number of children.</returns>
133         /// <since_tizen> 4 </since_tizen>
134         public uint ChildCount
135         {
136             get
137             {
138                 return GetChildCount();
139             }
140         }
141     }
142 } // namespace Tizen.NUI