[dali_2.3.24] Merge branch 'devel/master'
[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) 2022 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[in]  layer3DParentsCount The number of 3d layers in the hierarchy.
209    * @param[out] connectionList On return, the list of connected actors which require notification.
210    */
211   void RecursiveConnectToScene(ActorContainer& connectionList, uint32_t layer3DParentsCount, uint32_t depth);
212
213   /**
214    * Helper to recursively disconnect a tree of actors.
215    * This is not interrupted by user callbacks.
216    * @param[out] disconnectionList On return, the list of disconnected actors which require notification.
217    */
218   void RecursiveDisconnectFromScene(ActorContainer& disconnectionList);
219
220   /**
221    * Helper to recursively change the number of 3d layers in a tree of actors.
222    * This is not interrupted by user callbacks.
223    * @param[in] layer3DParentsCountDiff Difference valaue of 3d layers count.
224    */
225   void RecursiveChangeLayer3dCount(int32_t layer3DParentsCountDiff);
226
227   /**
228    * @brief Propagates layout direction recursively.
229    * @param[in] direction New layout direction.
230    */
231   void InheritLayoutDirectionRecursively(Dali::LayoutDirection::Type direction, bool set = false);
232
233   /**
234    * @brief Recursively emits the visibility-changed-signal on the actor tree.
235    *
236    * @param[in] visible The new visibility of the actor
237    * @param[in] type Whether the actor's visible property has changed or a parent's
238    */
239   void EmitVisibilityChangedSignalRecursively(bool                               visible,
240                                               DevelActor::VisibilityChange::Type type);
241
242   /**
243    * @brief Propagates the actor's visibility on the actor tree, and retreives actor list to emit inherited-visibility-changed-signal.
244    *
245    * @param[out] inheritedVisibilityChangedList On return, the list of actors whose inherited visibility is changed.
246    */
247   void InheritVisibilityRecursively(ActorContainer& inheritedVisibilityChangedList);
248
249 private:
250   /**
251    * @brief Emits the ChildAdded signal for this actor
252    * @param[in] child The child actor that has been added
253    */
254   void EmitChildAddedSignal(Actor& child);
255
256   /**
257    * @brief Emits the ChildRemoved signal for this actor
258    * @param[in] child The child actor that has been removed
259    */
260   void EmitChildRemovedSignal(Actor& child);
261
262   /**
263    * @brief Emit the child order changed signal, and rebuild the depth tree
264    *
265    * @param[in] child The child actor that changed order
266    */
267   void EmitOrderChangedAndRebuild(Actor& child);
268
269 private:
270   Dali::Internal::Actor&                  mOwner; ///* Owning actor
271   DevelActor::ChildChangedSignalType      mChildAddedSignal;
272   DevelActor::ChildChangedSignalType      mChildRemovedSignal;
273   DevelActor::ChildOrderChangedSignalType mChildOrderChangedSignal;
274   ActorContainer*                         mChildren{nullptr}; ///< Container of referenced actors, lazily initialized
275 };
276
277 } // namespace Internal
278
279 } // namespace Dali
280
281 #endif