98bedb9f8469ac30784af6fa32b819552df4a368
[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/event/actors/actor-declarations.h>
23 #include <dali/internal/event/actors/actor-parent.h>
24
25 // EXTERNAL INCLUDES
26 #include <string>
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32 class Actor;
33
34 class ActorParentImpl : public ActorParent
35 {
36 public:
37   /**
38    * constructor
39    * @param[in] owner The owning actor
40    */
41   ActorParentImpl(Actor& owner);
42
43   /**
44    * destructor
45    */
46   virtual ~ActorParentImpl();
47
48   /**
49    * Adds a child Actor to this ActorParent.
50    * @pre The child actor is not the same as the parent actor.
51    * @pre The child actor does not already have a parent.
52    * @param [in] child The child.
53    * @param [in] notify Emits notification if set to true. Default is true.
54    * @post The child will be referenced by its parent.
55    */
56   void Add(Actor& child, bool notify = true);
57
58   /**
59    * Removes a child Actor from this ActorParent.
60    * @param [in] child The child.
61    * @param [in] notify Emits notification if set to true. Default is true.
62    * @post The child will be unreferenced.
63    * @note If notify is false, Add() method must be called after this method.
64    */
65   void Remove(Actor& child, bool notify = true);
66
67   /**
68    * Retrieve the number of children held by the actor.
69    * @return The number of children
70    */
71   uint32_t GetChildCount() const;
72
73   /**
74    * @copydoc Dali::Actor::GetChildAt
75    */
76   ActorPtr GetChildAt(uint32_t index) const;
77
78   /**
79    * @copydoc Dali::Actor::FindChildByName
80    */
81   ActorPtr FindChildByName(ConstString actorName) override;
82
83   /**
84    * @copydoc Dali::Actor::FindChildById
85    */
86   ActorPtr FindChildById(const uint32_t id);
87
88   /**
89    * Retrieve a reference to children.
90    * @note Not for public use.
91    * @return A reference to the container of children.
92    * @note The internal container is lazily initialized so ensure you check the child count before using this method.
93    */
94   ActorContainer& GetChildrenInternal()
95   {
96     return *mChildren;
97   }
98
99   /**
100    * @brief Unparent all the children
101    */
102   void UnparentChildren();
103
104   /**
105    * @brief Change the sibling order of the given child.
106    *
107    * @param[in] child The actor to change
108    * @param[in] order The new order for the actor
109    * @return true if order has been modified
110    */
111   void SetSiblingOrderOfChild(Actor& child, uint32_t order) override;
112
113   /**
114    * @brief Get the sibling order of the given actor.
115    *
116    * @param[in] child The actor to query
117    * @return the order in the sibling array of the actor
118    */
119   uint32_t GetSiblingOrderOfChild(const Actor& child) const override;
120
121   /**
122    * @brief Raise the actor within the siblings list by one
123
124    * @param[in] child The actor to move
125    * @return true if order has been modified
126    */
127   void RaiseChild(Actor& child) override;
128
129   /**
130    * @brief Lower the actor within the siblings list by one
131
132    * @param[in] child The actor to move
133    * @return true if order has been modified
134    */
135   void LowerChild(Actor& child) override;
136
137   /**
138    * @brief Raise the actor to the top of the siblings list.
139    *
140    * @param[in] child The actor to move
141    * @return true if order has been modified
142    */
143   void RaiseChildToTop(Actor& child) override;
144
145   /**
146    * @brief Lower the actor to the bottom of the siblings list.
147    *
148    * @param[in] child The actor to move
149    * @return true if order has been modified
150    */
151   void LowerChildToBottom(Actor& child) override;
152
153   /**
154    * @brief Raise the actor above the target actor within the siblings list.
155    *
156    * @param[in] child The actor to move
157    * @param[in] target The target actor
158    * @return true if order has been modified
159    */
160   void RaiseChildAbove(Actor& child, Actor& target) override;
161
162   /**
163    * @brief Lower the actor below the target actor within the siblings list.
164    *
165    * @param[in] child The actor to move
166    * @param[in] target The target actor
167    * @return true if order has been modified
168    */
169   void LowerChildBelow(Actor& child, Actor& target) override;
170
171   /**
172    * @copydoc DevelActor::ChildAddedSignal
173    */
174   DevelActor::ChildChangedSignalType& ChildAddedSignal()
175   {
176     return mChildAddedSignal;
177   }
178
179   /**
180    * @copydoc DevelActor::ChildRemovedSignal
181    */
182   DevelActor::ChildChangedSignalType& ChildRemovedSignal()
183   {
184     return mChildRemovedSignal;
185   }
186
187   /**
188    * @copydoc DevelActor::ChildOrderChangedSignal
189    */
190   DevelActor::ChildOrderChangedSignalType& ChildOrderChangedSignal()
191   {
192     return mChildOrderChangedSignal;
193   }
194
195 private:
196   /**
197    * @brief Emits the ChildAdded signal for this actor
198    * @param[in] child The child actor that has been added
199    */
200   void EmitChildAddedSignal(Actor& child);
201
202   /**
203    * @brief Emits the ChildRemoved signal for this actor
204    * @param[in] child The child actor that has been removed
205    */
206   void EmitChildRemovedSignal(Actor& child);
207
208   /**
209    * @brief Emit the child order changed signal, and rebuild the depth tree
210    *
211    * @param[in] child The child actor that changed order
212    */
213   void EmitOrderChangedAndRebuild(Actor& child);
214
215 private:
216   Dali::Internal::Actor&                  mOwner; ///* Owning actor
217   DevelActor::ChildChangedSignalType      mChildAddedSignal;
218   DevelActor::ChildChangedSignalType      mChildRemovedSignal;
219   DevelActor::ChildOrderChangedSignalType mChildOrderChangedSignal;
220   ActorContainer*                         mChildren{nullptr}; ///< Container of referenced actors, lazily initialized
221 };
222
223 } // namespace Internal
224
225 } // namespace Dali
226
227 #endif