[dali_2.3.23] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / events / actor-observer.h
1 #ifndef DALI_INTERNAL_ACTOR_OBSERVER_H
2 #define DALI_INTERNAL_ACTOR_OBSERVER_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/common/object-impl.h>
23 #include <dali/public-api/signals/callback.h>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 class Actor;
30
31 /**
32  * Stores an actor pointer and connects/disconnects to any required signals appropriately when set/unset.
33  */
34 struct ActorObserver : public Object::Observer
35 {
36 public:
37   // Construction & Destruction
38
39   /**
40    * Constructor.
41    */
42   ActorObserver();
43
44   /**
45    * Constructor with a callback which is called when the observed actor is removed from the scene.
46    *
47    * The callback should have the following signature:
48    * @code
49    * void MyCallback( Actor* actor );
50    * @endcode
51    * Where actor is a pointer to the object that has been removed from the scene.
52    *
53    * @param[in]  callback  The callback to connect to.
54    *
55    * @note Ownership of callback is passed onto this class.
56    */
57   ActorObserver(CallbackBase* callback);
58
59   /**
60    * Non virtual destructor
61    */
62   ~ActorObserver() override;
63
64   // Movable
65
66   /**
67    * Move constructor.
68    *
69    * @param[in] other The object to move the data from
70    *
71    * @note The other's actor is appropriately disconnected.
72    * @note Ownership of callback is passed onto this class.
73    */
74   ActorObserver(ActorObserver&& other) noexcept;
75
76   /**
77    * Move assignment operator.
78    *
79    * @param[in] other The object to move the data from
80    *
81    * @note The other's actor is appropriately disconnected.
82    * @note Ownership of callback is passed onto this class.
83    */
84   ActorObserver& operator=(ActorObserver&& other) noexcept;
85
86   // Not copyable
87
88   ActorObserver(const ActorObserver&) = delete;            ///< Deleted copy constructor.
89   ActorObserver& operator=(const ActorObserver&) = delete; ///< Deleted copy assignment operator.
90
91   // Methods
92
93   /**
94    * Return the stored Actor pointer.
95    * @return The Actor pointer.
96    * @note Returns nullptr while the observed actor is not on the scene.
97    */
98   Actor* GetActor() const;
99
100   /**
101    * Assignment operator.
102    * This disconnects the required signals from the currently set actor and connects to the required
103    * signals for the the actor specified (if set).
104    */
105   void SetActor(Actor* actor);
106
107   /**
108    * Resets the set actor and disconnects any connected signals.
109    */
110   void ResetActor();
111
112 private:
113   /**
114    * This will be called if an actor is added to the scene.
115    * @param[in] object The object object.
116    * @see Object::Observer::SceneObjectAdded()
117    */
118   void SceneObjectAdded(Object& object) override;
119
120   /**
121    * This will be called when the actor is removed from the scene.
122    * @param[in] object The object object.
123    * @see Object::Observer::SceneObjectRemoved()
124    */
125   void SceneObjectRemoved(Object& object) override;
126
127   /**
128    * This will be called when the actor is destroyed. We should clear the actor.
129    * No need to stop observing as the object is being destroyed anyway.
130    * @see Object::Observer::ObjectDestroyed()
131    */
132   void ObjectDestroyed(Object& object) override;
133
134 private:
135   Actor*        mActor;             ///< Raw pointer to an Actor.
136   bool          mActorDisconnected; ///< Indicates whether the actor has been disconnected from the scene
137   CallbackBase* mRemoveCallback;    ///< Callback to call when the observed actor is removed from the scene
138 };
139
140 } // namespace Internal
141
142 } // namespace Dali
143
144 #endif // DALI_INTERNAL_ACTOR_OBSERVER_H