5dff2263be1added7b2f1d58e7f0c317a0165929
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / actor-parent-impl.h
1 #ifndef DALI_INTERNAL_ACTOR_PARENT_IMPL_H
2 #define DALI_INTERNAL_ACTOR_PARENT_IMPL_H
3 /*
4  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use actor file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 // INTERNAL INCLUDES
20 #include <dali/devel-api/actors/actor-devel.h>
21 #include <dali/internal/common/const-string.h>
22 #include <dali/internal/common/owner-pointer.h>
23 #include <dali/internal/event/actors/actor-declarations.h>
24 #include <dali/internal/event/actors/actor-parent.h>
25 #include <dali/internal/update/nodes/node-declarations.h>
26
27 // EXTERNAL INCLUDES
28 #include <string>
29
30 namespace Dali
31 {
32 namespace Internal
33 {
34 class Actor;
35
36 class ActorParentImpl : public ActorParent
37 {
38 public:
39   /**
40    * constructor
41    * @param[in] owner The owning actor
42    */
43   ActorParentImpl(Actor& owner);
44
45   /**
46    * destructor
47    */
48   virtual ~ActorParentImpl();
49
50   /**
51    * Adds a child Actor to this ActorParent.
52    * @pre The child actor is not the same as the parent actor.
53    * @pre The child actor does not already have a parent.
54    * @param [in] child The child.
55    * @param [in] notify Emits notification if set to true. Default is true.
56    * @post The child will be referenced by its parent.
57    */
58   void Add(Actor& child, bool notify = true);
59
60   /**
61    * Removes a child Actor from this ActorParent.
62    * @param [in] child The child.
63    * @param [in] notify Emits notification if set to true. Default is true.
64    * @post The child will be unreferenced.
65    * @note If notify is false, Add() method must be called after this method.
66    */
67   void Remove(Actor& child, bool notify = true);
68
69   /**
70    * Retrieve the number of children held by the actor.
71    * @return The number of children
72    */
73   uint32_t GetChildCount() const;
74
75   /**
76    * @copydoc Dali::Actor::GetChildAt
77    */
78   ActorPtr GetChildAt(uint32_t index) const;
79
80   /**
81    * @copydoc Dali::Actor::FindChildByName
82    */
83   ActorPtr FindChildByName(ConstString actorName) override;
84
85   /**
86    * @copydoc Dali::Actor::FindChildById
87    */
88   ActorPtr FindChildById(const uint32_t id);
89
90   /**
91    * Retrieve a reference to children.
92    * @note Not for public use.
93    * @return A reference to the container of children.
94    * @note The internal container is lazily initialized so ensure you check the child count before using this method.
95    */
96   ActorContainer& GetChildrenInternal()
97   {
98     return *mChildren;
99   }
100
101   /**
102    * @brief Unparent all the children
103    */
104   void UnparentChildren();
105
106   /**
107    * @brief Change the sibling order of the given child.
108    *
109    * @param[in] child The actor to change
110    * @param[in] order The new order for the actor
111    * @return true if order has been modified
112    */
113   void SetSiblingOrderOfChild(Actor& child, uint32_t order) override;
114
115   /**
116    * @brief Get the sibling order of the given actor.
117    *
118    * @param[in] child The actor to query
119    * @return the order in the sibling array of the actor
120    */
121   uint32_t GetSiblingOrderOfChild(const Actor& child) const override;
122
123   /**
124    * @brief Raise the actor within the siblings list by one
125
126    * @param[in] child The actor to move
127    * @return true if order has been modified
128    */
129   void RaiseChild(Actor& child) override;
130
131   /**
132    * @brief Lower the actor within the siblings list by one
133
134    * @param[in] child The actor to move
135    * @return true if order has been modified
136    */
137   void LowerChild(Actor& child) override;
138
139   /**
140    * @brief Raise the actor to the top of the siblings list.
141    *
142    * @param[in] child The actor to move
143    * @return true if order has been modified
144    */
145   void RaiseChildToTop(Actor& child) override;
146
147   /**
148    * @brief Lower the actor to the bottom of the siblings list.
149    *
150    * @param[in] child The actor to move
151    * @return true if order has been modified
152    */
153   void LowerChildToBottom(Actor& child) override;
154
155   /**
156    * @brief Raise the actor above the target actor within the siblings list.
157    *
158    * @param[in] child The actor to move
159    * @param[in] target The target actor
160    * @return true if order has been modified
161    */
162   void RaiseChildAbove(Actor& child, Actor& target) override;
163
164   /**
165    * @brief Lower the actor below the target actor within the siblings list.
166    *
167    * @param[in] child The actor to move
168    * @param[in] target The target actor
169    * @return true if order has been modified
170    */
171   void LowerChildBelow(Actor& child, Actor& target) override;
172
173   /**
174    * @copydoc DevelActor::ChildAddedSignal
175    */
176   DevelActor::ChildChangedSignalType& ChildAddedSignal()
177   {
178     return mChildAddedSignal;
179   }
180
181   /**
182    * @copydoc DevelActor::ChildRemovedSignal
183    */
184   DevelActor::ChildChangedSignalType& ChildRemovedSignal()
185   {
186     return mChildRemovedSignal;
187   }
188
189   /**
190    * @copydoc DevelActor::ChildOrderChangedSignal
191    */
192   DevelActor::ChildOrderChangedSignalType& ChildOrderChangedSignal()
193   {
194     return mChildOrderChangedSignal;
195   }
196
197   /**
198    * Traverse the actor tree, inserting actors into the depth tree in sibling order.
199    * @param[in] sceneGraphNodeDepths A vector capturing the nodes and their depth index
200    * @param[in,out] depthIndex The current depth index (traversal index)
201    */
202   void DepthTraverseActorTree(OwnerPointer<SceneGraph::NodeDepths>& sceneGraphNodeDepths, int32_t& depthIndex);
203
204   /**
205    * Helper to recursively connect a tree of actors.
206    * This is not interrupted by user callbacks
207    * @param[in]  depth The depth in the hierarchy of the actor
208    * @param[out] connectionList On return, the list of connected actors which require notification.
209    */
210   void RecursiveConnectToScene(ActorContainer& connectionList, uint32_t depth);
211
212   /**
213    * Helper to recursively disconnect a tree of actors.
214    * This is not interrupted by user callbacks.
215    * @param[out] disconnectionList On return, the list of disconnected actors which require notification.
216    */
217   void RecursiveDisconnectFromScene(ActorContainer& disconnectionList);
218
219   /**
220    * @brief Propagates layout direction recursively.
221    * @param[in] direction New layout direction.
222    */
223   void InheritLayoutDirectionRecursively(Dali::LayoutDirection::Type direction, bool set = false);
224
225   /**
226    * @brief Recursively emits the visibility-changed-signal on the actor tree.
227    *
228    * @param[in] visible The new visibility of the actor
229    * @param[in] type Whether the actor's visible property has changed or a parent's
230    */
231   void EmitVisibilityChangedSignalRecursively(bool                               visible,
232                                               DevelActor::VisibilityChange::Type type);
233
234 private:
235   /**
236    * @brief Emits the ChildAdded signal for this actor
237    * @param[in] child The child actor that has been added
238    */
239   void EmitChildAddedSignal(Actor& child);
240
241   /**
242    * @brief Emits the ChildRemoved signal for this actor
243    * @param[in] child The child actor that has been removed
244    */
245   void EmitChildRemovedSignal(Actor& child);
246
247   /**
248    * @brief Emit the child order changed signal, and rebuild the depth tree
249    *
250    * @param[in] child The child actor that changed order
251    */
252   void EmitOrderChangedAndRebuild(Actor& child);
253
254 private:
255   Dali::Internal::Actor&                  mOwner; ///* Owning actor
256   DevelActor::ChildChangedSignalType      mChildAddedSignal;
257   DevelActor::ChildChangedSignalType      mChildRemovedSignal;
258   DevelActor::ChildOrderChangedSignalType mChildOrderChangedSignal;
259   ActorContainer*                         mChildren{nullptr}; ///< Container of referenced actors, lazily initialized
260 };
261
262 } // namespace Internal
263
264 } // namespace Dali
265
266 #endif